mirror of
https://github.com/php/php-src.git
synced 2025-08-17 22:48:57 +02:00
MFH: Refactoring that will help fixing #48441
This commit is contained in:
parent
60223d6a6d
commit
91a8fd7f7e
1 changed files with 60 additions and 70 deletions
130
ext/ldap/ldap.c
130
ext/ldap/ldap.c
|
@ -592,6 +592,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
int num_attribs = 0;
|
int num_attribs = 0;
|
||||||
int i, errno;
|
int i, errno;
|
||||||
int myargcount = ZEND_NUM_ARGS();
|
int myargcount = ZEND_NUM_ARGS();
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
if (zend_parse_parameters(myargcount TSRMLS_CC, "ZZZ|ZZZZZ", &link, &base_dn, &filter, &attrs, &attrsonly,
|
if (zend_parse_parameters(myargcount TSRMLS_CC, "ZZZ|ZZZZZ", &link, &base_dn, &filter, &attrs, &attrsonly,
|
||||||
&sizelimit, &timelimit, &deref) == FAILURE) {
|
&sizelimit, &timelimit, &deref) == FAILURE) {
|
||||||
|
@ -619,7 +620,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
case 4 :
|
case 4 :
|
||||||
if (Z_TYPE_PP(attrs) != IS_ARRAY) {
|
if (Z_TYPE_PP(attrs) != IS_ARRAY) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected Array as last element");
|
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));
|
num_attribs = zend_hash_num_elements(Z_ARRVAL_PP(attrs));
|
||||||
|
@ -628,8 +630,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
for (i = 0; i<num_attribs; i++) {
|
for (i = 0; i<num_attribs; i++) {
|
||||||
if (zend_hash_index_find(Z_ARRVAL_PP(attrs), i, (void **) &attr) != SUCCESS) {
|
if (zend_hash_index_find(Z_ARRVAL_PP(attrs), i, (void **) &attr) != SUCCESS) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array initialization wrong");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array initialization wrong");
|
||||||
efree(ldap_attrs);
|
ret = 0;
|
||||||
RETURN_FALSE;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEPARATE_ZVAL(attr);
|
SEPARATE_ZVAL(attr);
|
||||||
|
@ -639,16 +641,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
ldap_attrs[num_attribs] = NULL;
|
ldap_attrs[num_attribs] = NULL;
|
||||||
|
|
||||||
case 3 :
|
case 3 :
|
||||||
/* parallel search? */
|
|
||||||
if (Z_TYPE_PP(link) != IS_ARRAY) {
|
|
||||||
convert_to_string_ex(filter);
|
|
||||||
ldap_filter = Z_STRVAL_PP(filter);
|
|
||||||
|
|
||||||
/* If anything else than string is passed, ldap_base_dn = NULL */
|
|
||||||
if (Z_TYPE_PP(base_dn) == IS_STRING) {
|
|
||||||
ldap_base_dn = Z_STRVAL_PP(base_dn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -665,20 +658,16 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
nlinks = zend_hash_num_elements(Z_ARRVAL_PP(link));
|
nlinks = zend_hash_num_elements(Z_ARRVAL_PP(link));
|
||||||
if (nlinks == 0) {
|
if (nlinks == 0) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No links in link array");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No links in link array");
|
||||||
if (ldap_attrs != NULL) {
|
ret = 0;
|
||||||
efree(ldap_attrs);
|
goto cleanup;
|
||||||
}
|
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Z_TYPE_PP(base_dn) == IS_ARRAY) {
|
if (Z_TYPE_PP(base_dn) == IS_ARRAY) {
|
||||||
nbases = zend_hash_num_elements(Z_ARRVAL_PP(base_dn));
|
nbases = zend_hash_num_elements(Z_ARRVAL_PP(base_dn));
|
||||||
if (nbases != nlinks) {
|
if (nbases != nlinks) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Base must either be a string, or an array with the same number of elements as the links array");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Base must either be a string, or an array with the same number of elements as the links array");
|
||||||
if (ldap_attrs != NULL) {
|
ret = 0;
|
||||||
efree(ldap_attrs);
|
goto cleanup;
|
||||||
}
|
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(base_dn));
|
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(base_dn));
|
||||||
} else {
|
} else {
|
||||||
|
@ -695,10 +684,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
nfilters = zend_hash_num_elements(Z_ARRVAL_PP(filter));
|
nfilters = zend_hash_num_elements(Z_ARRVAL_PP(filter));
|
||||||
if (nfilters != nlinks) {
|
if (nfilters != nlinks) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filter must either be a string, or an array with the same number of elements as the links array");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filter must either be a string, or an array with the same number of elements as the links array");
|
||||||
if (ldap_attrs != NULL) {
|
ret = 0;
|
||||||
efree(ldap_attrs);
|
goto cleanup;
|
||||||
}
|
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(filter));
|
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(filter));
|
||||||
} else {
|
} else {
|
||||||
|
@ -716,12 +703,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
|
|
||||||
ld = (ldap_linkdata *) zend_fetch_resource(entry TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
|
ld = (ldap_linkdata *) zend_fetch_resource(entry TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
|
||||||
if (ld == NULL) {
|
if (ld == NULL) {
|
||||||
efree(lds);
|
ret = 0;
|
||||||
efree(rcs);
|
goto cleanup_parallel;
|
||||||
if (ldap_attrs != NULL) {
|
|
||||||
efree(ldap_attrs);
|
|
||||||
}
|
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
if (nbases != 0) { /* base_dn an array? */
|
if (nbases != 0) { /* base_dn an array? */
|
||||||
zend_hash_get_current_data(Z_ARRVAL_PP(base_dn), (void **)&entry);
|
zend_hash_get_current_data(Z_ARRVAL_PP(base_dn), (void **)&entry);
|
||||||
|
@ -749,10 +732,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
zend_hash_move_forward(Z_ARRVAL_PP(link));
|
zend_hash_move_forward(Z_ARRVAL_PP(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ldap_attrs != NULL) {
|
|
||||||
efree(ldap_attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
|
|
||||||
/* Collect results from the searches */
|
/* Collect results from the searches */
|
||||||
|
@ -768,50 +747,61 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
|
||||||
add_next_index_bool(return_value, 0);
|
add_next_index_bool(return_value, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup_parallel:
|
||||||
efree(lds);
|
efree(lds);
|
||||||
efree(rcs);
|
efree(rcs);
|
||||||
return;
|
} else {
|
||||||
}
|
convert_to_string_ex(filter);
|
||||||
|
ldap_filter = Z_STRVAL_PP(filter);
|
||||||
|
|
||||||
ld = (ldap_linkdata *) zend_fetch_resource(link TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
|
/* If anything else than string is passed, ldap_base_dn = NULL */
|
||||||
if (ld == NULL) {
|
if (Z_TYPE_PP(base_dn) == IS_STRING) {
|
||||||
if (ldap_attrs != NULL) {
|
ldap_base_dn = Z_STRVAL_PP(base_dn);
|
||||||
efree(ldap_attrs);
|
}
|
||||||
|
|
||||||
|
ld = (ldap_linkdata *) zend_fetch_resource(link TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
|
||||||
|
if (ld == NULL) {
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
php_set_opts(ld->link, 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);
|
||||||
|
|
||||||
|
if (errno != LDAP_SUCCESS
|
||||||
|
&& errno != LDAP_SIZELIMIT_EXCEEDED
|
||||||
|
#ifdef LDAP_ADMINLIMIT_EXCEEDED
|
||||||
|
&& errno != LDAP_ADMINLIMIT_EXCEEDED
|
||||||
|
#endif
|
||||||
|
#ifdef LDAP_REFERRAL
|
||||||
|
&& errno != LDAP_REFERRAL
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ZEND_REGISTER_RESOURCE(return_value, ldap_res, le_result);
|
||||||
}
|
}
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref);
|
cleanup:
|
||||||
|
|
||||||
/* Run the actual search */
|
|
||||||
errno = ldap_search_s(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res);
|
|
||||||
|
|
||||||
if (ldap_attrs != NULL) {
|
if (ldap_attrs != NULL) {
|
||||||
efree(ldap_attrs);
|
efree(ldap_attrs);
|
||||||
}
|
}
|
||||||
|
if (!ret) {
|
||||||
if (errno != LDAP_SUCCESS
|
RETVAL_BOOL(ret);
|
||||||
&& errno != LDAP_SIZELIMIT_EXCEEDED
|
|
||||||
#ifdef LDAP_ADMINLIMIT_EXCEEDED
|
|
||||||
&& errno != LDAP_ADMINLIMIT_EXCEEDED
|
|
||||||
#endif
|
|
||||||
#ifdef 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");
|
|
||||||
}
|
|
||||||
#ifdef LDAP_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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue