From 550a4f2fa89c3d3bc858aa81c62dbfa0f59f0e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 1 Oct 2020 10:11:43 +0200 Subject: Remove deprecated functions from php-ldap Remove ldap_control_paged_result and ldap_control_paged_result_response which have been deprecated in PHP 7.4, in favor of new $controls parameters for ldap request functions. --- UPGRADING | 2 + ext/ldap/ldap.c | 189 --------------------- ext/ldap/ldap.stub.php | 18 -- ext/ldap/ldap_arginfo.h | 32 +--- .../ldap_control_paged_results_variation1.phpt | 55 ------ .../ldap_control_paged_results_variation2.phpt | 71 -------- .../ldap_control_paged_results_variation3.phpt | 103 ----------- ext/ldap/tests/ldap_parse_result_controls.phpt | 6 +- 8 files changed, 5 insertions(+), 471 deletions(-) delete mode 100644 ext/ldap/tests/ldap_control_paged_results_variation1.phpt delete mode 100644 ext/ldap/tests/ldap_control_paged_results_variation2.phpt delete mode 100644 ext/ldap/tests/ldap_control_paged_results_variation3.phpt diff --git a/UPGRADING b/UPGRADING index 2d49f1043b..05c8eef1e9 100644 --- a/UPGRADING +++ b/UPGRADING @@ -341,6 +341,8 @@ PHP 8.0 UPGRADE NOTES - LDAP: . The deprecated function ldap_sort has been removed. + . The deprecated function ldap_control_paged_result has been removed. + . The deprecated function ldap_control_paged_result_response has been removed. . The interface of ldap_set_rebind_proc has changed; the $callback parameter does not accept empty string anymore; null value shall be used instead. diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 13ea7647fc..489984ba81 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -3879,195 +3879,6 @@ PHP_FUNCTION(ldap_8859_to_t61) /* }}} */ #endif -#ifdef LDAP_CONTROL_PAGEDRESULTS -/* {{{ Inject paged results control*/ -PHP_FUNCTION(ldap_control_paged_result) -{ - zend_long pagesize; - zend_bool iscritical; - zval *link; - char *cookie = NULL; - size_t cookie_len = 0; - struct berval lcookie = { 0L, NULL }; - ldap_linkdata *ld; - LDAP *ldap; - BerElement *ber = NULL; - LDAPControl ctrl, *ctrlsp[2]; - int rc, myargcount = ZEND_NUM_ARGS(); - - if (zend_parse_parameters(myargcount, "rl|bs", &link, &pagesize, &iscritical, &cookie, &cookie_len) != SUCCESS) { - RETURN_THROWS(); - } - - if (Z_TYPE_P(link) == IS_NULL) { - ldap = NULL; - } else { - if ((ld = (ldap_linkdata *)zend_fetch_resource_ex(link, "ldap link", le_link)) == NULL) { - RETURN_THROWS(); - } - ldap = ld->link; - } - - ber = ber_alloc_t(LBER_USE_DER); - if (ber == NULL) { - php_error_docref(NULL, E_WARNING, "Unable to alloc BER encoding resources for paged results control"); - RETURN_FALSE; - } - - ctrl.ldctl_iscritical = 0; - - switch (myargcount) { - case 4: - lcookie.bv_val = cookie; - lcookie.bv_len = cookie_len; - /* fallthru */ - case 3: - ctrl.ldctl_iscritical = (int)iscritical; - /* fallthru */ - } - - if (ber_printf(ber, "{iO}", (int)pagesize, &lcookie) == LBER_ERROR) { - php_error_docref(NULL, E_WARNING, "Unable to BER printf paged results control"); - RETVAL_FALSE; - goto lcpr_error_out; - } - rc = ber_flatten2(ber, &ctrl.ldctl_value, 0); - if (rc == LBER_ERROR) { - php_error_docref(NULL, E_WARNING, "Unable to BER encode paged results control"); - RETVAL_FALSE; - goto lcpr_error_out; - } - - ctrl.ldctl_oid = LDAP_CONTROL_PAGEDRESULTS; - - if (ldap) { - /* directly set the option */ - ctrlsp[0] = &ctrl; - ctrlsp[1] = NULL; - - rc = ldap_set_option(ldap, LDAP_OPT_SERVER_CONTROLS, ctrlsp); - if (rc != LDAP_SUCCESS) { - php_error_docref(NULL, E_WARNING, "Unable to set paged results control: %s (%d)", ldap_err2string(rc), rc); - RETVAL_FALSE; - goto lcpr_error_out; - } - RETVAL_TRUE; - } else { - /* return a PHP control object */ - array_init(return_value); - - add_assoc_string(return_value, "oid", ctrl.ldctl_oid); - if (ctrl.ldctl_value.bv_len) { - add_assoc_stringl(return_value, "value", ctrl.ldctl_value.bv_val, ctrl.ldctl_value.bv_len); - } - if (ctrl.ldctl_iscritical) { - add_assoc_bool(return_value, "iscritical", ctrl.ldctl_iscritical); - } - } - -lcpr_error_out: - if (ber != NULL) { - ber_free(ber, 1); - } - return; -} -/* }}} */ - -/* {{{ Extract paged results control response */ -PHP_FUNCTION(ldap_control_paged_result_response) -{ - zval *link, *result, *cookie, *estimated; - struct berval lcookie; - int lestimated; - ldap_linkdata *ld; - LDAPMessage *ldap_result; - LDAPControl **lserverctrls, *lctrl; - BerElement *ber; - ber_tag_t tag; - int rc, lerrcode, myargcount = ZEND_NUM_ARGS(); - - if (zend_parse_parameters(myargcount, "rr|zz", &link, &result, &cookie, &estimated) != SUCCESS) { - RETURN_THROWS(); - } - - if ((ld = (ldap_linkdata *)zend_fetch_resource(Z_RES_P(link), "ldap link", le_link)) == NULL) { - RETURN_THROWS(); - } - - if ((ldap_result = (LDAPMessage *)zend_fetch_resource(Z_RES_P(result), "ldap result", le_result)) == NULL) { - RETURN_THROWS(); - } - - rc = ldap_parse_result(ld->link, - ldap_result, - &lerrcode, - NULL, /* matcheddn */ - NULL, /* errmsg */ - NULL, /* referrals */ - &lserverctrls, - 0); - - if (rc != LDAP_SUCCESS) { - php_error_docref(NULL, E_WARNING, "Unable to parse result: %s (%d)", ldap_err2string(rc), rc); - RETURN_FALSE; - } - - if (lerrcode != LDAP_SUCCESS) { - php_error_docref(NULL, E_WARNING, "Result is: %s (%d)", ldap_err2string(lerrcode), lerrcode); - RETURN_FALSE; - } - - if (lserverctrls == NULL) { - php_error_docref(NULL, E_WARNING, "No server controls in result"); - RETURN_FALSE; - } - - lctrl = ldap_control_find(LDAP_CONTROL_PAGEDRESULTS, lserverctrls, NULL); - if (lctrl == NULL) { - ldap_controls_free(lserverctrls); - php_error_docref(NULL, E_WARNING, "No paged results control response in result"); - RETURN_FALSE; - } - - ber = ber_init(&lctrl->ldctl_value); - if (ber == NULL) { - ldap_controls_free(lserverctrls); - php_error_docref(NULL, E_WARNING, "Unable to alloc BER decoding resources for paged results control response"); - RETURN_FALSE; - } - - tag = ber_scanf(ber, "{io}", &lestimated, &lcookie); - (void)ber_free(ber, 1); - - if (tag == LBER_ERROR) { - ldap_controls_free(lserverctrls); - php_error_docref(NULL, E_WARNING, "Unable to decode paged results control response"); - RETURN_FALSE; - } - - if (lestimated < 0) { - ldap_controls_free(lserverctrls); - php_error_docref(NULL, E_WARNING, "Invalid paged results control response value"); - RETURN_FALSE; - } - - ldap_controls_free(lserverctrls); - if (myargcount == 4) { - ZEND_TRY_ASSIGN_REF_LONG(estimated, lestimated); - } - - if (lcookie.bv_len == 0) { - ZEND_TRY_ASSIGN_REF_EMPTY_STRING(cookie); - } else { - ZEND_TRY_ASSIGN_REF_STRINGL(cookie, lcookie.bv_val, lcookie.bv_len); - } - ldap_memfree(lcookie.bv_val); - - RETURN_TRUE; -} -/* }}} */ -#endif - /* {{{ Extended operations, Pierangelo Masarati */ #ifdef HAVE_LDAP_EXTENDED_OPERATION_S /* {{{ Extended operation */ diff --git a/ext/ldap/ldap.stub.php b/ext/ldap/ldap.stub.php index df973b933c..0aad23a165 100644 --- a/ext/ldap/ldap.stub.php +++ b/ext/ldap/ldap.stub.php @@ -187,24 +187,6 @@ function ldap_err2str(int $errno): string {} /** @param resource $ldap */ function ldap_compare($ldap, string $dn, string $attribute, string $value, array $controls = []): bool|int {} - -#ifdef LDAP_CONTROL_PAGEDRESULTS -/** - * @param resource $ldap - * @deprecated since 7.4 - */ -function ldap_control_paged_result($ldap, int $pagesize, bool $iscritical = false, string $cookie = ""): bool {} - -/** - * @param resource $ldap - * @param resource $result - * @param string $cookie - * @param int $estimated - * @deprecated since 7.4 - */ -function ldap_control_paged_result_response($ldap, $result, &$cookie = null, &$estimated = null): bool {} -#endif - #if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP) /** @param resource $ldap */ function ldap_rename($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, array $controls = []): bool {} diff --git a/ext/ldap/ldap_arginfo.h b/ext/ldap/ldap_arginfo.h index 4b73b68d8f..a0b5890cad 100644 --- a/ext/ldap/ldap_arginfo.h +++ b/ext/ldap/ldap_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0c721a3272fef9d1a06a8cb4163eeb219661fb00 */ + * Stub hash: 42f7118d8380424cd4178759cae6cb47b6d9b44f */ #if defined(HAVE_ORALDAP) ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0) @@ -183,24 +183,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ldap_compare, 0, 4, MAY_BE_BOOL| ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -#if defined(LDAP_CONTROL_PAGEDRESULTS) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_control_paged_result, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ldap) - ZEND_ARG_TYPE_INFO(0, pagesize, IS_LONG, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, iscritical, _IS_BOOL, 0, "false") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cookie, IS_STRING, 0, "\"\"") -ZEND_END_ARG_INFO() -#endif - -#if defined(LDAP_CONTROL_PAGEDRESULTS) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_control_paged_result_response, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ldap) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, cookie, "null") - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, estimated, "null") -ZEND_END_ARG_INFO() -#endif - #if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_rename, 0, 5, _IS_BOOL, 0) ZEND_ARG_INFO(0, ldap) @@ -396,12 +378,6 @@ ZEND_FUNCTION(ldap_errno); ZEND_FUNCTION(ldap_error); ZEND_FUNCTION(ldap_err2str); ZEND_FUNCTION(ldap_compare); -#if defined(LDAP_CONTROL_PAGEDRESULTS) -ZEND_FUNCTION(ldap_control_paged_result); -#endif -#if defined(LDAP_CONTROL_PAGEDRESULTS) -ZEND_FUNCTION(ldap_control_paged_result_response); -#endif #if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP) ZEND_FUNCTION(ldap_rename); #endif @@ -505,12 +481,6 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(ldap_error, arginfo_ldap_error) ZEND_FE(ldap_err2str, arginfo_ldap_err2str) ZEND_FE(ldap_compare, arginfo_ldap_compare) -#if defined(LDAP_CONTROL_PAGEDRESULTS) - ZEND_DEP_FE(ldap_control_paged_result, arginfo_ldap_control_paged_result) -#endif -#if defined(LDAP_CONTROL_PAGEDRESULTS) - ZEND_DEP_FE(ldap_control_paged_result_response, arginfo_ldap_control_paged_result_response) -#endif #if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP) ZEND_FE(ldap_rename, arginfo_ldap_rename) #endif diff --git a/ext/ldap/tests/ldap_control_paged_results_variation1.phpt b/ext/ldap/tests/ldap_control_paged_results_variation1.phpt deleted file mode 100644 index 75d147e0be..0000000000 --- a/ext/ldap/tests/ldap_control_paged_results_variation1.phpt +++ /dev/null @@ -1,55 +0,0 @@ ---TEST-- -ldap_ldap_control_paged_result() test (fetching the first page) ---CREDITS-- -Jean-Sebastien Hedde ---SKIPIF-- - ---FILE-- - ---CLEAN-- - ---EXPECTF-- -Deprecated: Function ldap_control_paged_result() is deprecated in %s.php on line %d -bool(true) -resource(%d) of type (ldap result) -array(2) { - ["count"]=> - int(1) - [0]=> - array(4) { - ["cn"]=> - array(2) { - ["count"]=> - int(1) - [0]=> - string(5) "userA" - } - [0]=> - string(2) "cn" - ["count"]=> - int(1) - ["dn"]=> - string(%d) "cn=userA,%s" - } -} diff --git a/ext/ldap/tests/ldap_control_paged_results_variation2.phpt b/ext/ldap/tests/ldap_control_paged_results_variation2.phpt deleted file mode 100644 index b0b6e62aff..0000000000 --- a/ext/ldap/tests/ldap_control_paged_results_variation2.phpt +++ /dev/null @@ -1,71 +0,0 @@ ---TEST-- -ldap_ldap_control_paged_result() test (fetching the first page with a pagesize=2) ---CREDITS-- -Jean-Sebastien Hedde ---SKIPIF-- - ---FILE-- - ---CLEAN-- - ---EXPECTF-- -Deprecated: Function ldap_control_paged_result() is deprecated in %s.php on line %d -bool(true) -resource(%d) of type (ldap result) -array(3) { - ["count"]=> - int(2) - [0]=> - array(4) { - ["cn"]=> - array(2) { - ["count"]=> - int(1) - [0]=> - string(5) "userA" - } - [0]=> - string(2) "cn" - ["count"]=> - int(1) - ["dn"]=> - string(%d) "cn=userA,%s" - } - [1]=> - array(4) { - ["cn"]=> - array(2) { - ["count"]=> - int(1) - [0]=> - string(5) "userB" - } - [0]=> - string(2) "cn" - ["count"]=> - int(1) - ["dn"]=> - string(%d) "cn=userB,%s" - } -} diff --git a/ext/ldap/tests/ldap_control_paged_results_variation3.phpt b/ext/ldap/tests/ldap_control_paged_results_variation3.phpt deleted file mode 100644 index de904f051f..0000000000 --- a/ext/ldap/tests/ldap_control_paged_results_variation3.phpt +++ /dev/null @@ -1,103 +0,0 @@ ---TEST-- -ldap_ldap_control_paged_result() test (fetching the first page then the next final page) ---CREDITS-- -Jean-Sebastien Hedde ---SKIPIF-- - ---FILE-- - ---CLEAN-- - ---EXPECTF-- -Deprecated: Function ldap_control_paged_result() is deprecated in %s.php on line %d - -Deprecated: Function ldap_control_paged_result_response() is deprecated in %s.php on line %d - -Deprecated: Function ldap_control_paged_result() is deprecated in %s.php on line %d -bool(true) -resource(%d) of type (ldap result) -array(3) { - ["count"]=> - int(2) - [0]=> - array(4) { - ["cn"]=> - array(2) { - ["count"]=> - int(1) - [0]=> - string(5) "userA" - } - [0]=> - string(2) "cn" - ["count"]=> - int(1) - ["dn"]=> - string(%d) "cn=userA,%s" - } - [1]=> - array(4) { - ["cn"]=> - array(2) { - ["count"]=> - int(1) - [0]=> - string(5) "userB" - } - [0]=> - string(2) "cn" - ["count"]=> - int(1) - ["dn"]=> - string(%d) "cn=userB,%s" - } -} -bool(true) -bool(true) -resource(%d) of type (ldap result) -array(2) { - ["count"]=> - int(1) - [0]=> - array(4) { - ["cn"]=> - array(2) { - ["count"]=> - int(1) - [0]=> - string(5) "userC" - } - [0]=> - string(2) "cn" - ["count"]=> - int(1) - ["dn"]=> - string(%d) "cn=userC,cn=userB,%s" - } -} diff --git a/ext/ldap/tests/ldap_parse_result_controls.phpt b/ext/ldap/tests/ldap_parse_result_controls.phpt index 63ef9e69d7..2a5f7e1d3b 100644 --- a/ext/ldap/tests/ldap_parse_result_controls.phpt +++ b/ext/ldap/tests/ldap_parse_result_controls.phpt @@ -19,8 +19,8 @@ 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')), + $result = ldap_search($link, $dn, $filter, array('cn'), 0, 0, 0, LDAP_DEREF_NEVER, + [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'iscritical' => TRUE, 'value' => ['size' => 1]]]), ldap_parse_result($link, $result, $errcode, $dn, $errmsg, $refs, $ctrls), $ctrls[LDAP_CONTROL_PAGEDRESULTS]['oid'], $ctrls[LDAP_CONTROL_PAGEDRESULTS]['value']['size'], @@ -36,8 +36,6 @@ $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); remove_dummy_data($link, $base); ?> --EXPECTF-- -Deprecated: Function ldap_control_paged_result() is deprecated in %s.php on line %d -bool(true) resource(%d) of type (ldap result) bool(true) string(22) "1.2.840.113556.1.4.319" -- cgit v1.2.1