From 03220cb04a4607ad359847839b143dcf7b20149a Mon Sep 17 00:00:00 2001 From: Patrick Allaert Date: Mon, 15 Jun 2009 15:03:31 +0000 Subject: [PATCH] Refactoring that will help fixing #48441 --- ext/ldap/ldap.c | 122 ++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 66 deletions(-) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 20867fea32..c93ed8cdad 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -603,6 +603,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) int num_attribs = 0; int i, errno; int myargcount = ZEND_NUM_ARGS(); + int ret = 1; if (zend_parse_parameters(myargcount TSRMLS_CC, "ZZZ|ZZZZZ", &link, &base_dn, &filter, &attrs, &attrsonly, &sizelimit, &timelimit, &deref) == FAILURE) { @@ -630,7 +631,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) case 4 : if (Z_TYPE_PP(attrs) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected Array as last element"); - RETURN_FALSE; + ret = 0; + goto cleanup; } num_attribs = zend_hash_num_elements(Z_ARRVAL_PP(attrs)); @@ -639,8 +641,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) for (i = 0; ilink, ldap_sizelimit, ldap_timelimit, ldap_deref); - /* Run the actual search */ - errno = ldap_search_s(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res); + ld = (ldap_linkdata *) zend_fetch_resource(link TSRMLS_CC, -1, "ldap link", NULL, 1, le_link); + if (ld == NULL) { + ret = 0; + goto cleanup; + } - if (ldap_attrs != NULL) { - efree(ldap_attrs); - } + php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref); - if (errno != LDAP_SUCCESS - && errno != LDAP_SIZELIMIT_EXCEEDED + /* Run the actual search */ + errno = ldap_search_s(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res); + + if (errno != LDAP_SUCCESS + && errno != LDAP_SIZELIMIT_EXCEEDED #ifdef LDAP_ADMINLIMIT_EXCEEDED - && errno != LDAP_ADMINLIMIT_EXCEEDED + && errno != LDAP_ADMINLIMIT_EXCEEDED #endif #ifdef LDAP_REFERRAL - && errno != LDAP_REFERRAL + && errno != LDAP_REFERRAL #endif - ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Search: %s", ldap_err2string(errno)); - RETVAL_FALSE; - } else { - if (errno == LDAP_SIZELIMIT_EXCEEDED) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Sizelimit exceeded"); - } + ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Search: %s", ldap_err2string(errno)); + ret = 0; + } else { + if (errno == LDAP_SIZELIMIT_EXCEEDED) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Sizelimit exceeded"); + } #ifdef LDAP_ADMINLIMIT_EXCEEDED - else if (errno == LDAP_ADMINLIMIT_EXCEEDED) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Adminlimit exceeded"); - } + else if (errno == LDAP_ADMINLIMIT_EXCEEDED) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Adminlimit exceeded"); + } #endif - - ZEND_REGISTER_RESOURCE(return_value, ldap_res, le_result); + + ZEND_REGISTER_RESOURCE(return_value, ldap_res, le_result); + } + } + +cleanup: + if (ldap_attrs != NULL) { + efree(ldap_attrs); + } + if (!ret) { + RETVAL_BOOL(ret); } } /* }}} */ -- 2.40.0