Re: UPDATED: Patch to fix BUG: ldap_search: sizelimit exceeded, no result..

From: Date: Fri, 21 Jul 2000 18:31:35 +0000
Subject: Re: UPDATED: Patch to fix BUG: ldap_search: sizelimit exceeded, no result..
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-25373@lists.php.net to get a copy of this message
I have mailed with Stig and we decided that I'll do the commit. I'll just have to read that README.CVS-RULES file for a couple of times more.. =) --Jani On Fri, 21 Jul 2000, Rasmus Lerdorf wrote: >Tested on an LDAP site I have here. No backward compatibility >problems. Didn't test the new features. Go for it. > >-Rasmus > >On Fri, 21 Jul 2000, Stig Venaas wrote: > >> Great work. Unless Rasmus or anyone is against it, I'll add it in a >> few hours. >> >> Stig >> >> On Thu, Jul 20, 2000 at 07:03:51PM +0300, jtaskine@hit.fi wrote: >> > On Thu, 20 Jul 2000, Stig Venaas wrote: >> > >> > >Wouldn't it be better if we changed ldap_search into >> > >int ldap_search (int link_identifier, string base_dn, string filter [, array >> > >attributes, int attrsonly, int sizelimit, int timelimit, int deref]) >> > > >> > >Unless anyone else does, I'll apply your patch and possible additions in >> > >a day or two, I'm a bit busy right now. >> > >> > Here's the patch. I tested this with my existing ldap-things and they >> > worked fine (no modifications needed to them). >> > >> > I could verify also that attrsonly and sizelimit parameters work. >> > Dunno about timelimit and deref. >> > >> > --Jani >> > >> > Index: ldap.c >> > =================================================================== >> > RCS file: /repository/php4/ext/ldap/ldap.c,v >> > retrieving revision 1.46 >> > diff -u -r1.46 ldap.c >> > --- ldap.c 2000/06/27 09:28:05 1.46 >> > +++ ldap.c 2000/07/20 15:50:10 >> > @@ -450,70 +450,76 @@ >> > >> > static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) >> > { >> > - pval **link, **base_dn, **filter, **attrs, **attr; >> > + pval **link, **base_dn, **filter, **attrs, **attr, **attrsonly, **sizelimit, >> > **timelimit, **deref; >> > char *ldap_base_dn, *ldap_filter; >> > LDAP *ldap; >> > char **ldap_attrs = NULL; >> > - int attrsonly; >> > + int ldap_attrsonly = 0; /* 0 = types & values , 1 = only attributes types */ >> > + int ldap_sizelimit = 0; /* LDAP_NO_LIMIT 0 */ >> > + int ldap_timelimit = 0; /* 0 = no timelimit? */ >> > + int ldap_deref = 0; /* LDAP_DEREF_NEVER 0, LDAP_DEREF_SEARCHING 1, >> > LDAP_DEREF_FINDING 2, LDAP_DEREF_ALWAYS 3 */ >> > LDAPMessage *ldap_result; >> > - int num_attribs=0, i; >> > + int num_attribs = 0; >> > + int i, errno; >> > + int myargcount = ZEND_NUM_ARGS(); >> > LDAPLS_FETCH(); >> > + >> > + if (myargcount < 3 || myargcount > 8 || zend_get_parameters_ex(myargcount, >> > &link, &base_dn, &filter, &attrs, &attrsonly, &sizelimit, &timelimit, >> > &deref) == FAILURE) { >> > + WRONG_PARAM_COUNT; >> > + } >> > >> > - switch(ZEND_NUM_ARGS()) { >> > - case 3 : >> > - if (zend_get_parameters_ex(3, &link, &base_dn,&filter) == FAILURE) { >> > - WRONG_PARAM_COUNT; >> > - } >> > + /* Reverse -> fall through */ >> > + switch(myargcount) { >> > + case 8 : >> > + convert_to_long_ex(deref); >> > + ldap_deref = (*deref)->value.lval; >> > >> > - convert_to_string_ex(base_dn); >> > - convert_to_string_ex(filter); >> > + case 7 : >> > + convert_to_long_ex(timelimit); >> > + ldap_timelimit = (*timelimit)->value.lval; >> > >> > - ldap_base_dn = (*base_dn)->value.str.val; >> > - ldap_filter = (*filter)->value.str.val; >> > + case 6 : >> > + convert_to_long_ex(sizelimit); >> > + ldap_sizelimit = (*sizelimit)->value.lval; >> > >> > - break; >> > + case 5 : >> > + convert_to_long_ex(attrsonly); >> > + ldap_attrsonly = (*attrsonly)->value.lval; >> > >> > case 4 : >> > - if (zend_get_parameters_ex(4, &link, &base_dn,&filter, &attrs) == >> > FAILURE) { >> > - WRONG_PARAM_COUNT; >> > - } >> > - >> > if ((*attrs)->type != IS_ARRAY) { >> > php_error(E_WARNING, "LDAP: Expected Array as last element"); >> > RETURN_FALSE; >> > } >> > >> > - convert_to_string_ex(base_dn); >> > - convert_to_string_ex(filter); >> > - >> > - ldap_base_dn = (*base_dn)->value.str.val; >> > - ldap_filter = (*filter)->value.str.val; >> > - >> > num_attribs = zend_hash_num_elements((*attrs)->value.ht); >> > 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); >> > ldap_attrs[i] = (*attr)->value.str.val; >> > } >> > ldap_attrs[num_attribs] = NULL; >> > - >> > - break; >> > + >> > + case 3 : >> > + convert_to_string_ex(base_dn); >> > + convert_to_string_ex(filter); >> > + ldap_base_dn = (*base_dn)->value.str.val; >> > + ldap_filter = (*filter)->value.str.val; >> > + break; >> > >> > default: >> > WRONG_PARAM_COUNT; >> > - break; >> > + break; >> > } >> > >> > /* fix to make null base_dn's work */ >> > @@ -523,33 +529,48 @@ >> > >> > ldap = _get_ldap_link(link); >> > if (ldap == NULL) RETURN_FALSE; >> > + >> > + /* sizelimit */ >> > + if(ldap_sizelimit > 0) { >> > + ldap->ld_sizelimit = ldap_sizelimit; >> > + } >> > >> > - /* Is it useful to only get the attributes ? */ >> > - attrsonly = 0; >> > + /* timelimit */ >> > + if(ldap_timelimit > 0) { >> > + ldap->ld_timelimit = ldap_timelimit; >> > + } >> > >> > - /* We can possibly add the timeout value also */ >> > + /* deref */ >> > + if(ldap_deref > 0) { >> > + ldap->ld_deref = ldap_deref; >> > + } >> > + >> > + /* Run the actual search */ >> > + errno = ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, >> > ldap_attrsonly, &ldap_result); >> > + >> > + if (ldap_attrs != NULL) { >> > + efree(ldap_attrs); >> > + } >> > >> > - if (ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, attrsonly, >> > &ldap_result) != LDAP_SUCCESS) { >> > + 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)); >> > } >> > - >> > - if (ldap_attrs != NULL) { >> > - /* for(i=0; i<num_attribs; i++) efree(ldap_attrs[i]); */ >> > - efree(ldap_attrs); >> > - } >> > - return; >> > } >> > + >> > >> > -/* {{{ proto int ldap_read(int link, string base_dn, string filter [, array >> > attributes]) >> > +/* {{{ proto int ldap_read(int link, string base_dn, string filter [, array attrs [, >> > int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]] ) >> > Read an entry */ >> > PHP_FUNCTION(ldap_read) >> > { >> > @@ -557,7 +578,8 @@ >> > } >> > /* }}} */ >> > >> > -/* {{{ proto int ldap_list(int link, string base_dn, string filter [, array >> > attributes]) >> > + >> > +/* {{{ proto int ldap_list(int link, string base_dn, string filter [, array attrs [, >> > int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]] ) >> > Single-level search */ >> > PHP_FUNCTION(ldap_list) >> > { >> > @@ -566,7 +588,7 @@ >> > /* }}} */ >> > >> > >> > -/* {{{ proto int ldap_search(int link, string base_dn, string filter [, array >> > attributes]) >> > +/* {{{ proto int ldap_search(int link, string base_dn, string filter [, array attrs >> > [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]] ) >> > Search LDAP tree under base_dn */ >> > PHP_FUNCTION(ldap_search) >> > { >> > @@ -574,6 +596,7 @@ >> > } >> > /* }}} */ >> > >> > + >> > /* {{{ proto int ldap_free_result(int result) >> > Free result memory */ >> > PHP_FUNCTION(ldap_free_result) >> > @@ -1292,7 +1315,6 @@ >> > #else >> > RETURN_LONG( ldap_get_lderrno(ldap, NULL, NULL) ); >> > #endif >> > - RETURN_LONG(0); >> > } >> > /* }}} */ >> > >> > >> >> > -- Joo.

« previous php.dev (#25373) next »