Re: Bug #2809: ldap_get_entries returns no values when only retrieving DN

From: Date: Fri, 26 Nov 1999 21:03:17 +0000
Subject: Re: Bug #2809: ldap_get_entries returns no values when only retrieving DN
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-13157@lists.php.net to get a copy of this message
Hi I've looked through the code and found the bug, see below. > > From: robert.everett@wcom.com > Operating system: Solaris 2.6 > PHP version: 3.0.12 > PHP Bug Type: LDAP related > Bug description: ldap_get_entries returns no values when only retrieving DN > > PHP 3.0.12 > Apache 1.3.9 > Netscape LDAP 4.11 > Solaris 2.6 > > ldap_get_entries() returns false when only retrieving DN. It will also fail > if requesting attributes whose values are all empty. > > -- Sometimes OK (CN & DN) -- > > $ld = ldap_connect("ldap.foobar.com", 389); > > $base = "o=Foobar,c=US"; > $attrs = array("cn"); > $filter = "(uid=testuser)"; > > $sr = ldap_search($ld, $base, $filter, $attrs); > $info = ldap_get_entries($ld, $sr); > > // OK as long as "cn" contains a value; otherwise $info is empty > echo $info[0]["dn"]."<br>"; > echo $info[0]["cn"][0]."<br>"; > > ldap_unbind($ld); > > -- Always Fails (DN only) -- > > $ld = ldap_connect("ldap.foobar.com", 389); > > $base = "o=Foobar,c=US"; > $attrs = array("dn"); > $filter = "(uid=testuser)"; > > $sr = ldap_search($ld, $base, $filter, $attrs); > $info = ldap_get_entries($ld, $sr); > > // fails; $info is always empty > echo $info[0]["dn"]."<br>"; > > ldap_unbind($ld); In php3_ldap_get_entries() we have the following code: num_attrib = 0; attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); if (attribute == NULL) RETURN_FALSE; while (attribute != NULL) { num_attrib++; attribute = ldap_next_attribute(ldap, ldap_result_entry, ber); } array_init(&tmp1); attr_count = 0; attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); while (attribute != NULL) { and so on. What happens is that it runs through all attributes for an entry to set num_attrib and if one entry has none of the requested attributes, the function returns false, which is pretty bad. Another interesting thing is that when the attributes are looped through the second time to do the real work, there is another variable attr_count which as far as I can see, will have the same value as num_attrib, so to me it looks like we can remove the 7 first lines above, and replace num_attrib with attr_count in the line add_assoc_long(&tmp1, "count", num_attrib); Unless anyone tells me no, I will commit these changes to the CVS tree. Stig

« previous php.dev (#13157) next »