Patch to fix BUG: ldap_search: sizelimit exceeded, but no results returned.

From: Date: Mon, 17 Jul 2000 15:33:40 +0000
Subject: Patch to fix BUG: ldap_search: sizelimit exceeded, but no results returned.
Groups: php.dev 
Request: Send a blank email to php-dev+get-24778@lists.php.net to get a copy of this message
Included patch fixes this problem: When doing ldap-searches which extend beyond the (server) sizelimit, there were no partial results (for example 50 first) returned at all. And some of the compile warnings are nuked with this too. I hope I got this right.. Question: ========= How do you add an optional parameter for php-function? And in this case, how do you add TWO optional parameters?? Like this is: /* {{{ proto int ldap_search(int link, string base_dn, string filter [,array attributes]) Search LDAP tree under base_dn */ And should be: /* {{{ proto int ldap_search(int link, string base_dn, string filter [,int sizelimit [, int timelimit [,array attributes]]]) Search LDAP tree under base_dn */ --Jani p.s. Almost forgot the patch..=) Index: ext/ldap/ldap.c =================================================================== RCS file: /repository/php4/ext/ldap/ldap.c,v retrieving revision 1.46 diff -u -r1.46 ldap.c --- ext/ldap/ldap.c 2000/06/27 09:28:05 1.46 +++ ext/ldap/ldap.c 2000/07/17 15:19:49 @@ -454,7 +454,7 @@ char *ldap_base_dn, *ldap_filter; LDAP *ldap; char **ldap_attrs = NULL; - int attrsonly; + int attrsonly, errno; LDAPMessage *ldap_result; int num_attribs=0, i; LDAPLS_FETCH(); @@ -493,15 +493,12 @@ if ((ldap_attrs = emalloc((num_attribs+1) * sizeof(char *))) == NULL) { php_error(E_WARNING, "LDAP: Could not allocate memory"); RETURN_FALSE; - return; } for(i=0; i<num_attribs; i++) { - if(zend_hash_index_find((*attrs)->value.ht, i, (void **) &attr) == FAILURE) -{ + if(zend_hash_index_find((*attrs)->value.ht, i, (void **) &attr) == FAILURE) { php_error(E_WARNING, "LDAP: Array initialization wrong"); RETURN_FALSE; - return; } SEPARATE_ZVAL(attr); convert_to_string_ex(attr); @@ -527,18 +524,25 @@ /* Is it useful to only get the attributes ? */ attrsonly = 0; - /* We can possibly add the timeout value also */ + /* Timelimit & Sizelimit, these should be as optional parameters passed to functions + /* ldap_search() and ldap_list(). Are there other? */ + /* ldap->ld_timelimit = 60; */ + /* ldap->ld_sizelimit = 50; */ - if (ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, attrsonly, &ldap_result) != LDAP_SUCCESS) { + errno = ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, attrsonly, &ldap_result); + if (errno != LDAP_SUCCESS && errno != LDAP_SIZELIMIT_EXCEEDED) { #if !HAVE_NSLDAP #if LDAP_API_VERSION > 2000 - php_error(E_WARNING,"LDAP: Unable to perform the search: %s",ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); + php_error(E_WARNING,"LDAP: Unable to perform the search: %s",ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); #else php_error(E_WARNING, "LDAP: Unable to perform the search: %s", ldap_err2string(ldap->ld_errno)); #endif #endif - RETVAL_FALSE; - } else { + RETVAL_FALSE; + } else { + if (errno == LDAP_SIZELIMIT_EXCEEDED) { + php_error(E_WARNING,"LDAP: Partial search results returned: Sizelimit exceeded."); + } RETVAL_LONG(zend_list_insert(ldap_result, le_result)); } @@ -1292,7 +1296,6 @@ #else RETURN_LONG( ldap_get_lderrno(ldap, NULL, NULL) ); #endif - RETURN_LONG(0); } /* }}} */

« previous php.dev (#24778) next »