php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch php_ldap_do_search.patch for LDAP related Bug #61853Patch version 2012-04-25 20:38 UTC Return to Bug #61853 | Download this patchThis patch is obsolete Obsoleted by patches:
Developer: etienne@lamaisondebarbie.ch--- ldap.orig.c 2012-04-25 21:34:54.011391743 +0200 +++ ldap.c 2012-04-25 22:07:42.061150869 +0200 @@ -546,19 +546,8 @@ /* {{{ php_set_opts */ -static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, int *old_sizelimit, int *old_timelimit, int *old_deref) +static void php_set_opts(LDAP *ldap, int timelimit, int deref, int *old_timelimit, int *old_deref) { - /* sizelimit */ - if (sizelimit > -1) { -#if (LDAP_API_VERSION >= 2004) || HAVE_NSLDAP || HAVE_ORALDAP_10 - ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_sizelimit); - ldap_set_option(ldap, LDAP_OPT_SIZELIMIT, &sizelimit); -#else - *old_sizelimit = ldap->ld_sizelimit; - ldap->ld_sizelimit = sizelimit; -#endif - } - /* timelimit */ if (timelimit > -1) { #if (LDAP_API_VERSION >= 2004) || HAVE_NSLDAP || HAVE_ORALDAP_10 @@ -592,6 +581,7 @@ char *ldap_base_dn = NULL, *ldap_filter = NULL, **ldap_attrs = NULL; ldap_linkdata *ld = NULL; LDAPMessage *ldap_res; + LDAPControl **clientctrl = NULL, ** serverctrl = NULL; int ldap_attrsonly = 0, ldap_sizelimit = -1, ldap_timelimit = -1, ldap_deref = -1; int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1; int num_attribs = 0, ret = 1, i, errno, argcount = ZEND_NUM_ARGS(); @@ -706,11 +696,42 @@ ldap_filter = Z_STRVAL_PP(entry); } - php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref, &old_ldap_sizelimit, &old_ldap_timelimit, &old_ldap_deref); + php_set_opts(ld->link, ldap_timelimit, ldap_deref, &old_ldap_timelimit, &old_ldap_deref); + + /* Fill controls. + Discouraged by documentation but there's no way to pass + controls yet. Better than nothing + */ + if(LDAP_OPT_SUCCESS != ldap_get_option( + ld->link, + LDAP_OPT_CLIENT_CONTROLS, + &clientctrl)) { + clientctrl = NULL; + } + if(LDAP_OPT_SUCCESS != ldap_get_option( + ld->link, + LDAP_OPT_SERVER_CONTROLS, + &serverctrl)) { + serverctrl = NULL; + } /* Run the actual search */ - rcs[i] = ldap_search(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly); + if(LDAP_OPT_SUCCESS != ldap_search_ext( + ld->link, + ldap_base_dn, + scope, + ldap_filter, + ldap_attrs, + ldap_attrsonly, + serverctrl, + clientctrl, + NULL, /* timeval not defined, see ldap.h */ + ldap_sizelimit, + &(rcs[i]))) { + rcs[i] = -1; + } lds[i] = ld; + zend_hash_move_forward(Z_ARRVAL_P(link)); } @@ -748,10 +769,39 @@ goto cleanup; } - php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref, &old_ldap_sizelimit, &old_ldap_timelimit, &old_ldap_deref); + php_set_opts(ld->link, ldap_timelimit, ldap_deref, &old_ldap_timelimit, &old_ldap_deref); + + /* Fill controls. + Discouraged by documentation but there's no way to pass + controls yet. Better than nothing + */ + if(LDAP_OPT_SUCCESS != ldap_get_option( + ld->link, + LDAP_OPT_CLIENT_CONTROLS, + &clientctrl)) { + clientctrl = NULL; + } + if(LDAP_OPT_SUCCESS != ldap_get_option( + ld->link, + LDAP_OPT_SERVER_CONTROLS, + &serverctrl)) { + serverctrl = NULL; + } /* Run the actual search */ - errno = ldap_search_s(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res); + errno = ldap_search_ext_s( + ld->link, + ldap_base_dn, + scope, + ldap_filter, + ldap_attrs, + ldap_attrsonly, + serverctrl, + clientctrl, + NULL, /* timeval not defined, see ldap.h */ + ldap_sizelimit, + &ldap_res); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed ldap_search_ext_s"); if (errno != LDAP_SUCCESS && errno != LDAP_SIZELIMIT_EXCEEDED @@ -779,9 +829,20 @@ } cleanup: + /* Free controls */ + if(clientctrl != NULL) { + ldap_controls_free(clientctrl); + clientctrl = NULL; + } + if(serverctrl != NULL) { + ldap_controls_free(serverctrl); + serverctrl = NULL; + } + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed ldap_controls_free"); + if (ld) { /* Restoring previous options */ - php_set_opts(ld->link, old_ldap_sizelimit, old_ldap_timelimit, old_ldap_deref, &ldap_sizelimit, &ldap_timelimit, &ldap_deref); + php_set_opts(ld->link, old_ldap_timelimit, old_ldap_deref, &ldap_timelimit, &ldap_deref); } if (ldap_attrs != NULL) { efree(ldap_attrs); |
Copyright © 2001-2025 The PHP Group All rights reserved. |
Last updated: Wed Feb 05 16:01:30 2025 UTC |