From 15a3eca3efb16d4db092268aeaa6c72ab0cc480c Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Thu, 15 Oct 2020 11:46:44 +0200 Subject: [PATCH] Change $controls parameter to default to null in ext/ldap It appeared that not passing $controls and passing [] caused different behaviors, when not passing it the controls set through ldap_set_option would be used, when passing [] they would not. So, this parameter is now nullable and defaults to null to have a consistent behavior. --- ext/ldap/ldap.c | 18 +++++++++--------- ext/ldap/ldap.stub.php | 40 ++++++++++++++++++++-------------------- ext/ldap/ldap_arginfo.h | 24 ++++++++++++------------ 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 489984ba81..dde62b3810 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -1175,7 +1175,7 @@ PHP_FUNCTION(ldap_bind_ext) LDAPMessage *ldap_res; int rc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!a", &link, &ldap_bind_dn, &ldap_bind_dnlen, &ldap_bind_pw, &ldap_bind_pwlen, &serverctrls) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!a!", &link, &ldap_bind_dn, &ldap_bind_dnlen, &ldap_bind_pw, &ldap_bind_pwlen, &serverctrls) != SUCCESS) { RETURN_THROWS(); } @@ -1446,7 +1446,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) Z_PARAM_LONG(sizelimit) Z_PARAM_LONG(timelimit) Z_PARAM_LONG(deref) - Z_PARAM_ARRAY_EX(serverctrls, 0, 1) + Z_PARAM_ARRAY_EX(serverctrls, 1, 1) ZEND_PARSE_PARAMETERS_END(); /* Reverse -> fall through */ @@ -1557,7 +1557,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) } } - if (argcount > 8) { + if (serverctrls) { /* We have to parse controls again for each link as they use it */ _php_ldap_controls_free(&lserverctrls); lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9); @@ -1610,7 +1610,7 @@ cleanup_parallel: } ldap_filter = zend_string_copy(filter_str); - if (argcount > 8) { + if (serverctrls) { lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9); if (lserverctrls == NULL) { ret = 0; @@ -2183,7 +2183,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext) zend_ulong index; int is_full_add=0; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a", &link, &dn, &dn_len, &entry, &serverctrls) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a!", &link, &dn, &dn_len, &entry, &serverctrls) != SUCCESS) { RETURN_THROWS(); } @@ -2414,7 +2414,7 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext) int rc, msgid; size_t dn_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|a", &link, &dn, &dn_len, &serverctrls) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|a!", &link, &dn, &dn_len, &serverctrls) != SUCCESS) { RETURN_THROWS(); } @@ -2557,7 +2557,7 @@ PHP_FUNCTION(ldap_modify_batch) ); */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a", &link, &dn, &dn_len, &mods, &serverctrls) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a!", &link, &dn, &dn_len, &mods, &serverctrls) != SUCCESS) { RETURN_THROWS(); } @@ -2897,7 +2897,7 @@ PHP_FUNCTION(ldap_compare) int errno; struct berval lvalue; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss|a", &link, &dn, &dn_len, &attr, &attr_len, &value, &value_len, &serverctrls) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss|a!", &link, &dn, &dn_len, &attr, &attr_len, &value, &value_len, &serverctrls) != SUCCESS) { RETURN_THROWS(); } @@ -3565,7 +3565,7 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext) size_t dn_len, newrdn_len, newparent_len; zend_bool deleteoldrdn; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsssb|a", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &serverctrls) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsssb|a!", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &serverctrls) != SUCCESS) { RETURN_THROWS(); } diff --git a/ext/ldap/ldap.stub.php b/ext/ldap/ldap.stub.php index b49472f954..eb790d483f 100644 --- a/ext/ldap/ldap.stub.php +++ b/ext/ldap/ldap.stub.php @@ -26,7 +26,7 @@ function ldap_bind($ldap, ?string $dn = null, ?string $password = null): bool {} * @param resource $ldap * @return resource|false */ -function ldap_bind_ext($ldap, ?string $dn = null, ?string $password = null, array $controls = []) {} +function ldap_bind_ext($ldap, ?string $dn = null, ?string $password = null, ?array $controls = null) {} #ifdef HAVE_LDAP_SASL /** @param resource $ldap */ @@ -37,19 +37,19 @@ function ldap_sasl_bind($ldap, ?string $dn = null, ?string $password = null, ?st * @param resource|array $ldap * @return resource|false */ -function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {} +function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null) {} /** * @param resource|array $ldap * @return resource|false */ -function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {} +function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null) {} /** * @param resource|array $ldap * @return resource|false */ -function ldap_search($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {} +function ldap_search($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null) {} /** @param resource $ldap */ function ldap_free_result($ldap): bool {} @@ -123,58 +123,58 @@ function ldap_explode_dn(string $dn, int $with_attrib): array|false {} function ldap_dn2ufn(string $dn): string|false {} /** @param resource $ldap */ -function ldap_add($ldap, string $dn, array $entry, array $controls = []): bool {} +function ldap_add($ldap, string $dn, array $entry, ?array $controls = null): bool {} /** * @param resource $ldap * @return resource|false */ -function ldap_add_ext($ldap, string $dn, array $entry, array $controls = []) {} +function ldap_add_ext($ldap, string $dn, array $entry, ?array $controls = null) {} /** @param resource $ldap */ -function ldap_delete($ldap, string $dn, array $controls = []): bool {} +function ldap_delete($ldap, string $dn, ?array $controls = null): bool {} /** * @param resource $ldap * @return resource|false */ -function ldap_delete_ext($ldap, string $dn, array $controls = []) {} +function ldap_delete_ext($ldap, string $dn, ?array $controls = null) {} /** @param resource $ldap */ -function ldap_modify_batch($ldap, string $dn, array $modifications_info, array $controls = []): bool {} +function ldap_modify_batch($ldap, string $dn, array $modifications_info, ?array $controls = null): bool {} /** @param resource $ldap */ -function ldap_mod_add($ldap, string $dn, array $entry, array $controls = []): bool {} +function ldap_mod_add($ldap, string $dn, array $entry, ?array $controls = null): bool {} /** * @param resource $ldap * @return resource|false */ -function ldap_mod_add_ext($ldap, string $dn, array $entry, array $controls = []) {} +function ldap_mod_add_ext($ldap, string $dn, array $entry, ?array $controls = null) {} /** @param resource $ldap */ -function ldap_mod_replace($ldap, string $dn, array $entry, array $controls = []): bool {} +function ldap_mod_replace($ldap, string $dn, array $entry, ?array $controls = null): bool {} /** * @param resource $ldap * @alias ldap_mod_replace */ -function ldap_modify($ldap, string $dn, array $entry, array $controls = []): bool {} +function ldap_modify($ldap, string $dn, array $entry, ?array $controls = null): bool {} /** * @param resource $ldap * @return resource|false */ -function ldap_mod_replace_ext($ldap, string $dn, array $entry, array $controls = []) {} +function ldap_mod_replace_ext($ldap, string $dn, array $entry, ?array $controls = null) {} /** @param resource $ldap */ -function ldap_mod_del($ldap, string $dn, array $entry, array $controls = []): bool {} +function ldap_mod_del($ldap, string $dn, array $entry, ?array $controls = null): bool {} /** * @param resource $ldap * @return resource|false */ -function ldap_mod_del_ext($ldap, string $dn, array $entry, array $controls = []) {} +function ldap_mod_del_ext($ldap, string $dn, array $entry, ?array $controls = null) {} /** @param resource $ldap */ function ldap_errno($ldap): int {} @@ -185,17 +185,17 @@ function ldap_error($ldap): string {} function ldap_err2str(int $errno): string {} /** @param resource $ldap */ -function ldap_compare($ldap, string $dn, string $attribute, string $value, array $controls = []): bool|int {} +function ldap_compare($ldap, string $dn, string $attribute, string $value, ?array $controls = null): bool|int {} #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 {} +function ldap_rename($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, ?array $controls = null): bool {} /** * @param resource $ldap * @return resource|false */ -function ldap_rename_ext($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, array $controls = []) {} +function ldap_rename_ext($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, ?array $controls = null) {} /** @@ -279,7 +279,7 @@ function ldap_8859_to_t61(string $value): string|false {} * @param string $response_oid * @return resource|bool */ -function ldap_exop($ldap, string $request_oid, ?string $request_data = null, ?array $controls = [], &$response_data = UNKNOWN, &$response_oid = null) {} +function ldap_exop($ldap, string $request_oid, ?string $request_data = null, ?array $controls = NULL, &$response_data = UNKNOWN, &$response_oid = null) {} #endif #ifdef HAVE_LDAP_PASSWD diff --git a/ext/ldap/ldap_arginfo.h b/ext/ldap/ldap_arginfo.h index 3c02df966d..c7aef8ae22 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: 0c02f5e91a47e9664c8c41332bf8040e93592753 */ + * Stub hash: 980ee25422e1b026259d63e7a61adea699751b86 */ #if defined(HAVE_ORALDAP) ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0) @@ -34,7 +34,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_bind_ext, 0, 0, 1) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, dn, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() #if defined(HAVE_LDAP_SASL) @@ -59,7 +59,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_read, 0, 0, 3) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sizelimit, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timelimit, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, deref, IS_LONG, 0, "LDAP_DEREF_NEVER") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() #define arginfo_ldap_list arginfo_ldap_read @@ -120,33 +120,33 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_add, 0, 3, _IS_BOOL, 0) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, entry, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_add_ext, 0, 0, 3) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, entry, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_delete, 0, 2, _IS_BOOL, 0) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_delete_ext, 0, 0, 2) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_modify_batch, 0, 3, _IS_BOOL, 0) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, modifications_info, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() #define arginfo_ldap_mod_add arginfo_ldap_add @@ -180,7 +180,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ldap_compare, 0, 4, MAY_BE_BOOL| ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, attribute, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() #if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP) @@ -190,7 +190,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_rename, 0, 5, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, new_rdn, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, new_parent, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, delete_old_rdn, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() #endif @@ -201,7 +201,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_rename_ext, 0, 0, 5) ZEND_ARG_TYPE_INFO(0, new_rdn, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, new_parent, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, delete_old_rdn, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() #endif @@ -296,7 +296,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop, 0, 0, 2) ZEND_ARG_INFO(0, ldap) ZEND_ARG_TYPE_INFO(0, request_oid, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, request_data, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "NULL") ZEND_ARG_INFO(1, response_data) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, response_oid, "null") ZEND_END_ARG_INFO() -- 2.40.0