Re: PHP 4.0 Bug #5433 Updated: LDAP "Decoding error" when requesting non-existent attributes in a search op.

From: Date: Tue, 25 Jul 2000 00:28:56 +0000
Subject: Re: PHP 4.0 Bug #5433 Updated: LDAP "Decoding error" when requesting non-existent attributes in a search op.
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-25915@lists.php.net to get a copy of this message
On Mon, 24 Jul 2000, Stig Venaas wrote: >> Description: LDAP "Decoding error" when requesting non-existent attributes in a >> search op. >> >> In the manual for ldap_get_entries it says: >> >> Returns a complete result information in a multi-dimenasional array on success and false on >> *error*. >> >> In PHP4 false is returned when no entry in the search result contain one of the requested >> attributes. In PHP3 true was >> returned in this case, and you could pick out the PHP-appended "dn" array value >> for each entry (even if no other >> attribute was present). Johan: ====== If search/read/list fails, there is no result to get entries from. And this was/is the case for PHP3 too. It's just how openldap's ldap_search_s()-function behaves. But for the dn-case: add an fifth parameter to ldap_read() / ldap_search() / ldap_list() Like this: $sr = ldap_search($ds, $dn, $filter, array(), 1); This will get only the attributes types + dn. Maybe this is what you really wanted ? ;) NOTE: above works for the latest CVS only! I added those optional parameters just few days ago. But please test attached patch (below) too.. >Yes, I remember I made PHP3 do that, I think PHP4 should too, I'll have a >look later perhaps, been coding for 12 hours straight now... Stig: ===== You removed these lines: <-- CUT -> 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); } <-- END CUT --> AND they were mysteriously returned in the PHP4-tree.. I removed them. Thank god for CVS!! ;-) And there was similar construct in ldap_get_attributes(). I nuked that too. >> Then the "decoding error" issue. It occurs more often than I thought (always?), >> when retrieving entries using an ldap_get_xxxx function (even if the >Have you tried the same query with the ldap_search program? Could the >decoding error have something to do with referrals? One can get decoding >error with ldap_search too. The 'Decoding error' is normal. It happens everytime ldap_next_attribute/entry is used beyond the actual number of attributes/entries. And this is true when using ldap_get_entries() / ldap_get_attributes(). --Jani p.s. Here is the patch to fix problems in ldap_get_entries() and ldap_get_attributes(). Please test this. If it works, please inform me and I'll close that bug and commit this patch. Index: ldap.c =================================================================== RCS file: /repository/php4/ext/ldap/ldap.c,v retrieving revision 1.49 diff -u -r1.49 ldap.c --- ldap.c 2000/07/23 21:32:02 1.49 +++ ldap.c 2000/07/25 00:21:11 @@ -16,6 +16,7 @@ | Eric Warnke <ericw@albany.edu> | | Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Gerrit Thomson <334647@swin.edu.au> | + | Jani Taskinen <sniper@iki.fi> | | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ @@ -718,7 +719,6 @@ pval *tmp1, *tmp2; LDAP *ldap; int num_entries, num_attrib, num_values, i; - int attr_count, entry_count; BerElement *ber; char *attribute; size_t attr_len; @@ -736,32 +736,22 @@ if (ldap_result == NULL) RETURN_FALSE; num_entries = ldap_count_entries(ldap, ldap_result); + if (num_entries == 0) RETURN_FALSE; array_init(return_value); - add_assoc_long(return_value, "count", num_entries); - - if (num_entries == 0) return; + num_entries = 0; ldap_result_entry = ldap_first_entry(ldap, ldap_result); if (ldap_result_entry == NULL) RETURN_FALSE; - - entry_count = 0; while(ldap_result_entry != NULL) { - 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); - } - MAKE_STD_ZVAL(tmp1); array_init(tmp1); - attr_count = 0; + num_attrib = 0; attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); + while (attribute != NULL) { ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute); num_values = ldap_count_values(ldap_value); @@ -769,16 +759,16 @@ MAKE_STD_ZVAL(tmp2); array_init(tmp2); add_assoc_long(tmp2, "count", num_values); - for(i=0; i<num_values; i++) { + for(i=0; i < num_values; i++) { add_index_string(tmp2, i, ldap_value[i], 1); } ldap_value_free(ldap_value); attr_len = strlen(attribute); zend_hash_update(tmp1->value.ht, php_strtolower(attribute, attr_len), attr_len+1, (void *) &tmp2, sizeof(pval *), NULL); - add_index_string(tmp1, attr_count, attribute, 1); + add_index_string(tmp1, num_attrib, attribute, 1); - attr_count++; + num_attrib++; attribute = ldap_next_attribute(ldap, ldap_result_entry, ber); } @@ -786,13 +776,14 @@ dn = ldap_get_dn(ldap, ldap_result_entry); add_assoc_string(tmp1, "dn", dn, 1); - zend_hash_index_update(return_value->value.ht, entry_count, (void *) &tmp1, sizeof(pval *), NULL); + zend_hash_index_update(return_value->value.ht, num_entries, (void *) &tmp1, sizeof(pval *), NULL); - entry_count++; + num_entries++; ldap_result_entry = ldap_next_entry(ldap, ldap_result_entry); } add_assoc_long(return_value, "count", num_entries); + } /* }}} */ @@ -878,7 +869,7 @@ LDAPMessage *ldap_result_entry; char *attribute; char **ldap_value; - int i, count, num_values, num_attrib; + int i, num_values, num_attrib; BerElement *ber; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &link, &result_entry) == FAILURE) { @@ -891,17 +882,9 @@ ldap_result_entry = _get_ldap_result_entry(result_entry); if (ldap_result_entry == NULL) RETURN_FALSE; + array_init(return_value); 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(return_value); - - count=0; attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); while (attribute != NULL) { ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute); @@ -916,9 +899,9 @@ ldap_value_free(ldap_value); zend_hash_update(return_value->value.ht, attribute, strlen(attribute)+1, (void *) &tmp, sizeof(pval *), NULL); - add_index_string(return_value, count, attribute, 1); + add_index_string(return_value, num_attrib, attribute, 1); - count++; + num_attrib++; attribute = ldap_next_attribute(ldap, ldap_result_entry, ber); }

« previous php.dev (#25915) next »