com php-src: Added controls support to ldap_parse_result and ldap_exop_passwd: ext/ldap/config.m4 ext/ld ap/config.w32 ext/ldap/ldap.c
ext/ldap/tests/ldap _exop_passwd.phpt ext/ldap/tests/ldap_exop_passwd _error.phpt ext/ldap/tests/ldap_get_option_controls .phpt
ext/ldap/tests/ldap_get_option_variation.phpt ext/ldap/tests/ldap_parse_result_controls.phpt ext /ldap/tests/ldap_set_option_variation.phpt

From: Date: Thu, 21 Sep 2017 08:05:40 +0000
Subject: com php-src: Added controls support to ldap_parse_result and ldap_exop_passwd: ext/ldap/config.m4 ext/ld ap/config.w32 ext/ldap/ldap.c
ext/ldap/tests/ldap _exop_passwd.phpt ext/ldap/tests/ldap_exop_passwd _error.phpt ext/ldap/tests/ldap_get_option_controls .phpt
ext/ldap/tests/ldap_get_option_variation.phpt ext/ldap/tests/ldap_parse_result_controls.phpt ext /ldap/tests/ldap_set_option_variation.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-99501@lists.php.net to get a copy of this message
Commit: 5ccb31e49ee117808bed4775dc40521f418b783b Author: Côme Chilliet <mcmic@php.net> Thu, 20 Jul 2017 12:17:59 +0200 Parents: 471d2bb0aebca4188180f96e7d1325bdf688e458 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5ccb31e49ee117808bed4775dc40521f418b783b Log: Added controls support to ldap_parse_result and ldap_exop_passwd Known controls are parsed to and from associative arrays. Only ppolicy and paged results are implemented for now. Changed paths: M ext/ldap/config.m4 M ext/ldap/config.w32 M ext/ldap/ldap.c M ext/ldap/tests/ldap_exop_passwd.phpt M ext/ldap/tests/ldap_exop_passwd_error.phpt M ext/ldap/tests/ldap_get_option_controls.phpt M ext/ldap/tests/ldap_get_option_variation.phpt A ext/ldap/tests/ldap_parse_result_controls.phpt M ext/ldap/tests/ldap_set_option_variation.phpt

diff --git a/ext/ldap/config.m4 b/ext/ldap/config.m4 index f77ff5a..59af421 100644 --- a/ext/ldap/config.m4 +++ b/ext/ldap/config.m4 @@ -204,7 +204,7 @@ if test "$PHP_LDAP" != "no"; then dnl Solaris 2.8 claims to be 2004 API, but doesn't have dnl ldap_parse_reference() nor ldap_start_tls_s() - AC_CHECK_FUNCS([ldap_parse_result ldap_parse_reference ldap_start_tls_s ldap_control_find ldap_parse_extended_result ldap_extended_operation ldap_extended_operation_s ldap_passwd_s ldap_whoami_s ldap_refresh_s]) + AC_CHECK_FUNCS([ldap_parse_result ldap_parse_reference ldap_start_tls_s ldap_control_find ldap_parse_extended_result ldap_extended_operation ldap_extended_operation_s ldap_passwd ldap_whoami_s ldap_refresh_s]) dnl dnl SASL check diff --git a/ext/ldap/config.w32 b/ext/ldap/config.w32 index 6263755..a608ff7 100644 --- a/ext/ldap/config.w32 +++ b/ext/ldap/config.w32 @@ -23,7 +23,7 @@ if (PHP_LDAP != "no") { AC_DEFINE('HAVE_LDAP_CONTROL_FIND', 1); AC_DEFINE('HAVE_LDAP_PARSE_EXTENDED_RESULT', 1); AC_DEFINE('HAVE_LDAP_EXTENDED_OPERATION_S', 1); - AC_DEFINE('HAVE_LDAP_PASSWD_S', 1); + AC_DEFINE('HAVE_LDAP_PASSWD', 1); AC_DEFINE('HAVE_LDAP_WHOAMI_S', 1); AC_DEFINE('HAVE_LDAP_REFRESH_S', 1); AC_DEFINE('HAVE_LDAP_EXTENDED_OPERATION', 1); diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 9740bad..a1843ee 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -19,6 +19,7 @@ | Jani Taskinen <sniper@iki.fi> | | Stig Venaas <venaas@uninett.no> | | Doug Goldstein <cardoe@cardoe.com> | + | Côme Chilliet <mcmic@php.net> | | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ @@ -135,6 +136,196 @@ static void _free_ldap_result_entry(zend_resource *rsrc) /* {{{ */ } /* }}} */ +/* {{{ Parse controls from and to arrays */ +static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array) +{ + array_init(array); + + add_assoc_string(array, "oid", ctrl->ldctl_oid); + add_assoc_bool(array, "iscritical", (ctrl->ldctl_iscritical != 0)); + + // If it is a known oid, parse to values + if (strcmp(ctrl->ldctl_oid, LDAP_CONTROL_PASSWORDPOLICYRESPONSE) == 0) { + int expire = 0, grace = 0, rc; + LDAPPasswordPolicyError pperr; + zval value; + + rc = ldap_parse_passwordpolicy_control(ld, ctrl, &expire, &grace, &pperr); + if ( rc == LDAP_SUCCESS ) { + array_init(&value); + add_assoc_long(&value, "expire", expire); + add_assoc_long(&value, "grace", grace); + + if ( pperr != PP_noError ) { + add_assoc_long(&value, "error", pperr); + } + add_assoc_zval(array, "value", &value); + } else { + add_assoc_null(array, "value"); + } + } else if (strcmp(ctrl->ldctl_oid, LDAP_CONTROL_PAGEDRESULTS) == 0) { + int lestimated, rc; + struct berval lcookie; + zval value; + + if (ctrl->ldctl_value.bv_len) { + rc = ldap_parse_pageresponse_control(ld, ctrl, &lestimated, &lcookie); + } else { + /* ldap_parse_pageresponse_control will crash if value is empty */ + rc = -1; + } + if ( rc == LDAP_SUCCESS ) { + array_init(&value); + add_assoc_long(&value, "size", lestimated); + add_assoc_stringl(&value, "cookie", lcookie.bv_val, lcookie.bv_len); + add_assoc_zval(array, "value", &value); + } else { + add_assoc_null(array, "value"); + } + } else { + if (ctrl->ldctl_value.bv_len) { + add_assoc_stringl(array, "value", ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len); + } else { + add_assoc_null(array, "value"); + } + } +} + +static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* array) +{ + zval* val; + char * control_oid = NULL; + int control_iscritical = 0, rc; + + if ((val = zend_hash_str_find(Z_ARRVAL_P(array), "oid", sizeof("oid") - 1)) == NULL) { + php_error_docref(NULL, E_WARNING, "Control must have an oid key"); + return -1; + } + convert_to_string_ex(val); + control_oid = Z_STRVAL_P(val); + + if ((val = zend_hash_str_find(Z_ARRVAL_P(array), "iscritical", sizeof("iscritical") - 1)) != NULL) { + convert_to_boolean_ex(val); + control_iscritical = (Z_TYPE_P(val) == IS_TRUE); + } else { + control_iscritical = 0; + } + + struct berval *control_value = NULL; + + if ((val = zend_hash_str_find(Z_ARRVAL_P(array), "value", sizeof("value") - 1)) != NULL) { + if (Z_TYPE_P(val) != IS_ARRAY) { + convert_to_string_ex(val); + control_value = ber_memalloc(sizeof * control_value); + if (control_value != NULL) { + control_value->bv_val = Z_STRVAL_P(val); + control_value->bv_len = Z_STRLEN_P(val); + } + } else if (strcmp(control_oid, LDAP_CONTROL_PAGEDRESULTS) == 0) { + zval* tmp; + int pagesize = 1; + struct berval *cookie = NULL; + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "size", sizeof("size") - 1)) != NULL) { + convert_to_long_ex(tmp); + pagesize = Z_LVAL_P(tmp); + } + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "cookie", sizeof("cookie") - 1)) != NULL) { + convert_to_string_ex(tmp); + cookie = ber_memalloc(sizeof * cookie); + if (cookie != NULL) { + cookie->bv_val = Z_STRVAL_P(tmp); + cookie->bv_len = Z_STRLEN_P(tmp); + } + } + control_value = ber_memalloc(sizeof * control_value); + if (control_value != NULL) { + rc = ldap_create_page_control_value(ld, pagesize, cookie, control_value); + if (rc != LDAP_SUCCESS) { + php_error_docref(NULL, E_WARNING, "Failed to create paged result control value: %s (%d)", ldap_err2string(rc), rc); + control_value = NULL; + } + } + } else { + php_error_docref(NULL, E_WARNING, "Control OID %s does not expect an array as value", control_oid); + } + } + + rc = ldap_control_create(control_oid, control_iscritical, control_value, 1, ctrl); + + if (control_value != NULL) { + ber_memfree(control_value); + control_value = NULL; + } + + if (rc == LDAP_SUCCESS) { + return LDAP_SUCCESS; + } + + // Failed + *ctrl = NULL; + return -1; +} + +static void _php_ldap_controls_to_array(LDAP *ld, LDAPControl** ctrls, zval* array) +{ + zval tmp1; + LDAPControl **ctrlp; + + array_init(array); + if (ctrls == NULL) { + return; + } + ctrlp = ctrls; + while (*ctrlp != NULL) { + _php_ldap_control_to_array(ld, *ctrlp, &tmp1); + add_next_index_zval(array, &tmp1); + ctrlp++; + } + ldap_controls_free(ctrls); +} + +static LDAPControl** _php_ldap_controls_from_array(LDAP *ld, zval* array) +{ + int ncontrols; + LDAPControl** ctrlp, **ctrls = NULL; + zval* ctrlarray; + int error = 0; + + ncontrols = zend_hash_num_elements(Z_ARRVAL_P(array)); + ctrls = safe_emalloc((1 + ncontrols), sizeof(*ctrls), 0); + *ctrls = NULL; + ctrlp = ctrls; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) { + if (Z_TYPE_P(ctrlarray) != IS_ARRAY) { + php_error_docref(NULL, E_WARNING, "The array value must contain only arrays, where each array is a control"); + error = 1; + break; + } + + if (_php_ldap_control_from_array(ld, ctrlp, ctrlarray) == LDAP_SUCCESS) { + ++ctrlp; + } else { + error = 1; + break; + } + + *ctrlp = NULL; + } ZEND_HASH_FOREACH_END(); + + if (error) { + ctrlp = ctrls; + while (*ctrlp) { + ldap_control_free(*ctrlp); + ctrlp++; + } + efree(ctrls); + ctrls = NULL; + } + + return ctrls; +} +/* }}} */ + /* {{{ PHP_INI_BEGIN */ PHP_INI_BEGIN() @@ -2346,9 +2537,7 @@ PHP_FUNCTION(ldap_get_option) case LDAP_OPT_SERVER_CONTROLS: case LDAP_OPT_CLIENT_CONTROLS: { - zval tmp1; - int num_entries; - LDAPControl **ctrls = NULL, **ctrlp; + LDAPControl **ctrls = NULL; if (ldap_get_option(ld->link, option, &ctrls) || ctrls == NULL) { if (ctrls) { @@ -2356,24 +2545,7 @@ PHP_FUNCTION(ldap_get_option) } RETURN_FALSE; } - - zval_ptr_dtor(retval); - array_init(retval); - num_entries = 0; - ctrlp = ctrls; - while (*ctrlp != NULL) - { - array_init(&tmp1); - add_assoc_string(&tmp1, "oid", (*ctrlp)->ldctl_oid); - add_assoc_bool(&tmp1, "iscritical", ((*ctrlp)->ldctl_iscritical != 0)); - if ((*ctrlp)->ldctl_value.bv_len) { - add_assoc_stringl(&tmp1, "value", (*ctrlp)->ldctl_value.bv_val, (*ctrlp)->ldctl_value.bv_len); - } - zend_hash_index_update(Z_ARRVAL_P(retval), num_entries, &tmp1); - num_entries++; - ctrlp++; - } - ldap_controls_free(ctrls); + _php_ldap_controls_to_array(ld->link, ctrls, retval); } break; /* options not implemented case LDAP_OPT_API_INFO: @@ -2539,62 +2711,29 @@ PHP_FUNCTION(ldap_set_option) case LDAP_OPT_SERVER_CONTROLS: case LDAP_OPT_CLIENT_CONTROLS: { - LDAPControl *ctrl, **ctrls, **ctrlp; - zval *ctrlval, *val; - int ncontrols; - char error=0; + LDAPControl **ctrls, **ctrlp; + int rc; if (Z_TYPE_P(newval) != IS_ARRAY) { php_error_docref(NULL, E_WARNING, "Expected array value for this option"); RETURN_FALSE; } - ncontrols = zend_hash_num_elements(Z_ARRVAL_P(newval)); - ctrls = safe_emalloc((1 + ncontrols), sizeof(*ctrls), 0); - *ctrls = NULL; - ctrlp = ctrls; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(newval), ctrlval) { - if (Z_TYPE_P(ctrlval) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "The array value must contain only arrays, where each array is a control"); - error = 1; - break; - } - if ((val = zend_hash_str_find(Z_ARRVAL_P(ctrlval), "oid", sizeof("oid") - 1)) == NULL) { - php_error_docref(NULL, E_WARNING, "Control must have an oid key"); - error = 1; - break; - } - ctrl = *ctrlp = emalloc(sizeof(**ctrlp)); - convert_to_string_ex(val); - ctrl->ldctl_oid = Z_STRVAL_P(val); - if ((val = zend_hash_str_find(Z_ARRVAL_P(ctrlval), "value", sizeof("value") - 1)) != NULL) { - convert_to_string_ex(val); - ctrl->ldctl_value.bv_val = Z_STRVAL_P(val); - ctrl->ldctl_value.bv_len = Z_STRLEN_P(val); - } else { - ctrl->ldctl_value.bv_val = NULL; - ctrl->ldctl_value.bv_len = 0; - } - if ((val = zend_hash_str_find(Z_ARRVAL_P(ctrlval), "iscritical", sizeof("iscritical") - 1)) != NULL) { - convert_to_boolean_ex(val); - ctrl->ldctl_iscritical = Z_TYPE_P(val) == IS_TRUE; - } else { - ctrl->ldctl_iscritical = 0; - } - ++ctrlp; - *ctrlp = NULL; - } ZEND_HASH_FOREACH_END(); - if (!error) { - error = ldap_set_option(ldap, option, ctrls); - } - ctrlp = ctrls; - while (*ctrlp) { - efree(*ctrlp); - ctrlp++; - } - efree(ctrls); - if (error) { + ctrls = _php_ldap_controls_from_array(ldap, newval); + + if (ctrls == NULL) { RETURN_FALSE; + } else { + rc = ldap_set_option(ldap, option, ctrls); + ctrlp = ctrls; + while (*ctrlp) { + ldap_control_free(*ctrlp); + ctrlp++; + } + efree(ctrls); + if (rc != LDAP_SUCCESS) { + RETURN_FALSE; + } } } break; default: @@ -2609,14 +2748,16 @@ PHP_FUNCTION(ldap_set_option) Extract information from result */ PHP_FUNCTION(ldap_parse_result) { - zval *link, *result, *errcode, *matcheddn, *errmsg, *referrals; + zval *link, *result, *errcode, *matcheddn, *errmsg, *referrals, *serverctrls; + zval ctrl, php_ber; ldap_linkdata *ld; LDAPMessage *ldap_result; + LDAPControl **lserverctrls = NULL, **ctrlp = NULL; char **lreferrals, **refp; char *lmatcheddn, *lerrmsg; - int rc, lerrcode, myargcount = ZEND_NUM_ARGS(); + int rc, lerrcode, myargcount = ZEND_NUM_ARGS(), ber_decode_error_count = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrz/|z/z/z/", &link, &result, &errcode, &matcheddn, &errmsg, &referrals) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrz/|z/z/z/z/", &link, &result, &errcode, &matcheddn, &errmsg, &referrals, &serverctrls) != SUCCESS) { return; } @@ -2632,7 +2773,7 @@ PHP_FUNCTION(ldap_parse_result) myargcount > 3 ? &lmatcheddn : NULL, myargcount > 4 ? &lerrmsg : NULL, myargcount > 5 ? &lreferrals : NULL, - NULL /* &serverctrls */, + myargcount > 6 ? &lserverctrls : NULL, 0); if (rc != LDAP_SUCCESS) { php_error_docref(NULL, E_WARNING, "Unable to parse result: %s", ldap_err2string(rc)); @@ -2644,6 +2785,8 @@ PHP_FUNCTION(ldap_parse_result) /* Reverse -> fall through */ switch (myargcount) { + case 7: + _php_ldap_controls_to_array(ld->link, lserverctrls, serverctrls); case 6: zval_ptr_dtor(referrals); array_init(referrals); @@ -3410,17 +3553,21 @@ PHP_FUNCTION(ldap_exop) /* }}} */ #endif -#ifdef HAVE_LDAP_PASSWD_S -/* {{{ proto bool|string ldap_exop_passwd(resource link [, string user [, string oldpw [, string newpw ]]]) +#ifdef HAVE_LDAP_PASSWD +/* {{{ proto bool|string ldap_exop_passwd(resource link [, string user [, string oldpw [, string newpw [, array ctrls]]]]) Passwd modify extended operation */ PHP_FUNCTION(ldap_exop_passwd) { - zval *link, *user, *newpw, *oldpw; + zval *link, *user, *newpw, *oldpw, *serverctrls; struct berval luser, loldpw, lnewpw, lgenpasswd; + LDAPControl **lserverctrls = NULL, **requestctrls = NULL; + LDAPControl *ctrl, **ctrlp; + LDAPMessage* ldap_res; ldap_linkdata *ld; - int rc, myargcount = ZEND_NUM_ARGS(); + int rc, myargcount = ZEND_NUM_ARGS(), msgid, err; + char* errmsg; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|zzz", &link, &user, &oldpw, &newpw) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|zzzz/", &link, &user, &oldpw, &newpw, &serverctrls) == FAILURE) { WRONG_PARAM_COUNT; } @@ -3433,6 +3580,17 @@ PHP_FUNCTION(ldap_exop_passwd) lnewpw.bv_len = 0; switch (myargcount) { + case 5: + requestctrls = safe_emalloc(2, sizeof(*requestctrls), 0); + *requestctrls = NULL; + ctrlp = requestctrls; + + if (ldap_create_passwordpolicy_control(ld->link, &ctrl) == LDAP_SUCCESS) { + *ctrlp = ctrl; + ++ctrlp; + } + + *ctrlp = NULL; case 4: convert_to_string_ex(newpw); lnewpw.bv_val = Z_STRVAL_P(newpw); @@ -3449,24 +3607,52 @@ PHP_FUNCTION(ldap_exop_passwd) luser.bv_len = Z_STRLEN_P(user); } - /* synchronous call */ - rc = ldap_passwd_s(ld->link, &luser, + /* asynchronous call to get result and controls */ + rc = ldap_passwd(ld->link, &luser, loldpw.bv_len > 0 ? &loldpw : NULL, lnewpw.bv_len > 0 ? &lnewpw : NULL, - &lgenpasswd, NULL, NULL); + requestctrls, + NULL, &msgid); if (rc != LDAP_SUCCESS ) { php_error_docref(NULL, E_WARNING, "Passwd modify extended operation failed: %s (%d)", ldap_err2string(rc), rc); RETURN_FALSE; } + rc = ldap_result(ld->link, msgid, 1 /* LDAP_MSG_ALL */, NULL, &ldap_res); + if ((rc < 0) || !ldap_res) { + rc = _get_lderrno(ld->link); + php_error_docref(NULL, E_WARNING, "Passwd modify extended operation failed: %s (%d)", ldap_err2string(rc), rc); + RETURN_FALSE; + } + + rc = ldap_parse_passwd(ld->link, ldap_res, &lgenpasswd); + if( rc != LDAP_SUCCESS ) { + php_error_docref(NULL, E_WARNING, "Passwd modify extended operation failed: %s (%d)", ldap_err2string(rc), rc); + ldap_msgfree(ldap_res); + RETURN_FALSE; + } + + rc = ldap_parse_result(ld->link, ldap_res, &err, NULL, &errmsg, NULL, (myargcount > 4 ? &lserverctrls : NULL), 1); + if( rc != LDAP_SUCCESS ) { + php_error_docref(NULL, E_WARNING, "Passwd modify extended operation failed: %s (%d)", ldap_err2string(rc), rc); + RETURN_FALSE; + } + if (lnewpw.bv_len == 0) { if (lgenpasswd.bv_len == 0) { RETVAL_EMPTY_STRING(); } else { RETVAL_STRINGL(lgenpasswd.bv_val, lgenpasswd.bv_len); } + } else if (err == LDAP_SUCCESS) { + RETVAL_TRUE; } else { - RETURN_TRUE; + php_error_docref(NULL, E_WARNING, "Passwd modify extended operation failed: %s (%d)", errmsg, err); + RETVAL_FALSE; + } + + if (myargcount > 4) { + _php_ldap_controls_to_array(ld->link, lserverctrls, serverctrls); } ldap_memfree(lgenpasswd.bv_val); @@ -3799,6 +3985,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_parse_result, 0, 0, 3) ZEND_ARG_INFO(1, matcheddn) ZEND_ARG_INFO(1, errmsg) ZEND_ARG_INFO(1, referrals) + ZEND_ARG_INFO(1, serverctrls) ZEND_END_ARG_INFO() #endif #endif @@ -3837,12 +4024,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop, 0, 0, 2) ZEND_END_ARG_INFO() #endif -#ifdef HAVE_LDAP_PASSWD_S -ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop_passwd, 0, 0, 4) +#ifdef HAVE_LDAP_PASSWD +ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop_passwd, 0, 0, 1) ZEND_ARG_INFO(0, link) ZEND_ARG_INFO(0, user) ZEND_ARG_INFO(0, oldpw) ZEND_ARG_INFO(0, newpw) + ZEND_ARG_INFO(1, serverctrls) ZEND_END_ARG_INFO() #endif @@ -3935,7 +4123,7 @@ const zend_function_entry ldap_functions[] = { #ifdef HAVE_LDAP_EXTENDED_OPERATION_S PHP_FE(ldap_exop, arginfo_ldap_exop) #endif -#ifdef HAVE_LDAP_PASSWD_S +#ifdef HAVE_LDAP_PASSWD PHP_FE(ldap_exop_passwd, arginfo_ldap_exop_passwd) #endif #ifdef HAVE_LDAP_WHOAMI_S diff --git a/ext/ldap/tests/ldap_exop_passwd.phpt b/ext/ldap/tests/ldap_exop_passwd.phpt index 2f0d4cb..e50b307 100644 --- a/ext/ldap/tests/ldap_exop_passwd.phpt +++ b/ext/ldap/tests/ldap_exop_passwd.phpt @@ -16,7 +16,8 @@ insert_dummy_data($link, $base); // and optionally returns the NEW password if none was passed. // ldap_exop_passwd(resource link [, string user [, string oldpw [, string newpw [, string newpasswd ]]]]) var_dump( - $genpw = ldap_exop_passwd($link, "cn=userA,$base", "oops", ""), + $genpw = ldap_exop_passwd($link, "cn=userA,$base", "oops", "", $ctrls), + $ctrls, $genpw = ldap_exop_passwd($link, "cn=userA,$base"), test_bind($host, $port, "cn=userA,$base", $genpw, $protocol_version), ldap_exop_passwd($link, "cn=userA,$base", $genpw, "newPassword"), @@ -34,6 +35,8 @@ remove_dummy_data($link, $base); ?> --EXPECTF-- string(%d) "%s" +array(0) { +} string(%d) "%s" bool(true) bool(true) diff --git a/ext/ldap/tests/ldap_exop_passwd_error.phpt b/ext/ldap/tests/ldap_exop_passwd_error.phpt index d858bd4..bfb0cbc 100644 --- a/ext/ldap/tests/ldap_exop_passwd_error.phpt +++ b/ext/ldap/tests/ldap_exop_passwd_error.phpt @@ -12,7 +12,8 @@ require "connect.inc"; $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); insert_dummy_data($link, $base); -var_dump(ldap_exop_passwd($link, "cn=userA,$base", "wrongPassword", "newPassword")); +var_dump(ldap_exop_passwd($link, "cn=userA,$base", "wrongPassword", "newPassword", $ctrls)); +var_dump($ctrls); var_dump(ldap_error($link)); var_dump(ldap_errno($link)); var_dump(test_bind($host, $port, "cn=userA,$base", "newPassword", $protocol_version)); @@ -27,8 +28,10 @@ $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); remove_dummy_data($link, $base); ?> --EXPECTF-- -Warning: ldap_exop_passwd(): Passwd modify extended operation failed: Server is unwilling to perform (53) in %s on line %d +Warning: ldap_exop_passwd(): Passwd modify extended operation failed: %s (53) in %s on line %d bool(false) +array(0) { +} string(30) "Server is unwilling to perform" int(53) diff --git a/ext/ldap/tests/ldap_get_option_controls.phpt b/ext/ldap/tests/ldap_get_option_controls.phpt index 3b55685..ea42532 100644 --- a/ext/ldap/tests/ldap_get_option_controls.phpt +++ b/ext/ldap/tests/ldap_get_option_controls.phpt @@ -30,7 +30,17 @@ $controls_set = array( array( 'oid' => LDAP_CONTROL_PAGEDRESULTS, 'iscritical' => TRUE, - 'value' => build_ctrl_paged_value(1, '') + 'value' => build_ctrl_paged_value(1, 'opaque') + ) +); +$controls_set2 = array( + array( + 'oid' => LDAP_CONTROL_PAGEDRESULTS, + 'iscritical' => TRUE, + 'value' => array( + 'size' => 1, + 'cookie' => '', + ) ) ); var_dump( @@ -38,10 +48,10 @@ var_dump( ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get), ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set), ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get), - count($controls_get), - $controls_get[0]['oid'], - $controls_get[0]['iscritical'], - bin2hex($controls_get[0]['value']), + $controls_get, + ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set2), + ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get), + $controls_get, $result = ldap_search($link, $base, "(objectClass=person)", array('cn')), ldap_get_entries($link, $result)['count'], ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array()), @@ -57,14 +67,44 @@ $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); remove_dummy_data($link, $base); ?> --EXPECTF-- -string(14) "30050201010400" +string(26) "300b02010104066f7061717565" bool(false) bool(true) bool(true) -int(1) -string(22) "1.2.840.113556.1.4.319" +array(1) { + [0]=> + array(3) { + ["oid"]=> + string(22) "1.2.840.113556.1.4.319" + ["iscritical"]=> + bool(true) + ["value"]=> + array(2) { + ["size"]=> + int(1) + ["cookie"]=> + string(6) "opaque" + } + } +} bool(true) -string(14) "30050201010400" +bool(true) +array(1) { + [0]=> + array(3) { + ["oid"]=> + string(22) "1.2.840.113556.1.4.319" + ["iscritical"]=> + bool(true) + ["value"]=> + array(2) { + ["size"]=> + int(1) + ["cookie"]=> + string(0) "" + } + } +} resource(%d) of type (ldap result) int(1) bool(true) diff --git a/ext/ldap/tests/ldap_get_option_variation.phpt b/ext/ldap/tests/ldap_get_option_variation.phpt index 759936e..d980350 100644 --- a/ext/ldap/tests/ldap_get_option_variation.phpt +++ b/ext/ldap/tests/ldap_get_option_variation.phpt @@ -67,11 +67,13 @@ int(0) bool(true) array(2) { [0]=> - array(2) { + array(3) { ["oid"]=> string(15) "1.2.752.58.10.1" ["iscritical"]=> bool(true) + ["value"]=> + NULL } [1]=> array(3) { @@ -86,11 +88,13 @@ array(2) { bool(true) array(2) { [0]=> - array(2) { + array(3) { ["oid"]=> string(15) "1.2.752.58.10.1" ["iscritical"]=> bool(true) + ["value"]=> + NULL } [1]=> array(3) { diff --git a/ext/ldap/tests/ldap_parse_result_controls.phpt b/ext/ldap/tests/ldap_parse_result_controls.phpt new file mode 100644 index 0000000..ef1dca8 --- /dev/null +++ b/ext/ldap/tests/ldap_parse_result_controls.phpt @@ -0,0 +1,45 @@ +--TEST-- +ldap_parse_result() - Test the parsing of controls from result object +--CREDITS-- +Côme Chilliet <mcmic@php.net> +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +<?php require_once('skipifbindfailure.inc'); ?> +--FILE-- +<?php +require "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +insert_dummy_data($link, $base); + +$dn = "$base"; +$filter = "(cn=user*)"; +var_dump( + ldap_control_paged_result($link, 1), + $result = ldap_search($link, $dn, $filter, array('cn')), + ldap_parse_result($link, $result, $errcode, $dn, $errmsg, $refs, $ctrls), + $ctrls[0]['oid'], + $ctrls[0]['iscritical'], + $ctrls[0]['value']['size'], + bin2hex($ctrls[0]['value']['cookie']), + ldap_get_entries($link, $result)['count'] +); +?> +===DONE=== +--CLEAN-- +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +remove_dummy_data($link, $base); +?> +--EXPECTF-- +bool(true) +resource(%d) of type (ldap result) +bool(true) +string(22) "1.2.840.113556.1.4.319" +bool(false) +int(%d) +string(%d) "%s" +int(1) +===DONE=== diff --git a/ext/ldap/tests/ldap_set_option_variation.phpt b/ext/ldap/tests/ldap_set_option_variation.phpt index bb8a3f1..b496bb1 100644 --- a/ext/ldap/tests/ldap_set_option_variation.phpt +++ b/ext/ldap/tests/ldap_set_option_variation.phpt @@ -78,11 +78,13 @@ bool(false) bool(true) array(2) { [0]=> - array(2) { + array(3) { ["oid"]=> string(15) "1.2.752.58.10.1" ["iscritical"]=> bool(true) + ["value"]=> + NULL } [1]=> array(3) { @@ -97,11 +99,13 @@ array(2) { bool(true) array(2) { [0]=> - array(2) { + array(3) { ["oid"]=> string(15) "1.2.752.58.10.1" ["iscritical"]=> bool(true) + ["value"]=> + NULL } [1]=> array(3) {
« previous php.cvs (#99501) next »