com php-src: Added support for controls in ldap_modify_batc h: ext/ldap/ldap.c ext/ldap/tests/ldap_modify_batch _error.phpt
| From: | Côme Bernigaud | Date: | Thu, 21 Sep 2017 08:05:41 +0000 |
| Subject: | com php-src: Added support for controls in ldap_modify_batc h: ext/ldap/ldap.c ext/ldap/tests/ldap_modify_batch _error.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99496@lists.php.net to get a copy of this message | ||
Commit: 81b27abac01e8241467d608b38ac17f3d1161e69
Author: Côme Chilliet <mcmic@php.net> Thu, 7 Sep 2017 14:42:34 +0200
Parents: 2b52cb74da92a2cc9b355a4b422168a1069ab321
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=81b27abac01e8241467d608b38ac17f3d1161e69
Log:
Added support for controls in ldap_modify_batch
Changed paths:
M ext/ldap/ldap.c
M ext/ldap/tests/ldap_modify_batch_error.phpt
Diff:
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 9c0d598..3b5bac8 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -2083,10 +2083,11 @@ static void _ldap_hash_fetch(zval *hashTbl, const char *key, zval **out)
}
/* }}} */
-/* {{{ proto bool ldap_modify_batch(resource link, string dn, array modifs)
+/* {{{ proto bool ldap_modify_batch(resource link, string dn, array modifs [, array servercontrols
[, array clientcontrols]])
Perform multiple modifications as part of one operation */
PHP_FUNCTION(ldap_modify_batch)
{
+ zval *serverctrls = NULL, *clientctrls = NULL;
ldap_linkdata *ld;
zval *link, *mods, *mod, *modinfo, *modval;
zval *attrib, *modtype, *vals;
@@ -2096,6 +2097,7 @@ PHP_FUNCTION(ldap_modify_batch)
int i, j, k;
int num_mods, num_modprops, num_modvals;
LDAPMod **ldap_mods;
+ LDAPControl **lserverctrls = NULL, **lclientctrls = NULL;
uint32_t oper;
/*
@@ -2122,7 +2124,7 @@ PHP_FUNCTION(ldap_modify_batch)
);
*/
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/", &link, &dn, &dn_len,
&mods) != SUCCESS) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|aa", &link, &dn, &dn_len,
&mods, &serverctrls, &clientctrls) != SUCCESS) {
return;
}
@@ -2350,8 +2352,23 @@ PHP_FUNCTION(ldap_modify_batch)
/* NULL-terminate modifications */
ldap_mods[num_mods] = NULL;
+ if (serverctrls) {
+ lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls);
+ if (lserverctrls == NULL) {
+ RETVAL_FALSE;
+ goto cleanup;
+ }
+ }
+ if (clientctrls) {
+ lclientctrls = _php_ldap_controls_from_array(ld->link, clientctrls);
+ if (lclientctrls == NULL) {
+ RETVAL_FALSE;
+ goto cleanup;
+ }
+ }
+
/* perform (finally) */
- if ((i = ldap_modify_ext_s(ld->link, dn, ldap_mods, NULL, NULL)) != LDAP_SUCCESS) {
+ if ((i = ldap_modify_ext_s(ld->link, dn, ldap_mods, lserverctrls, lclientctrls)) !=
LDAP_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Batch Modify: %s", ldap_err2string(i));
RETVAL_FALSE;
} else RETVAL_TRUE;
@@ -2382,6 +2399,13 @@ PHP_FUNCTION(ldap_modify_batch)
/* the modifications array */
efree(ldap_mods);
+
+ if (lserverctrls) {
+ _php_ldap_controls_free(&lserverctrls);
+ }
+ if (lclientctrls) {
+ _php_ldap_controls_free(&lclientctrls);
+ }
}
}
/* }}} */
@@ -4100,6 +4124,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_modify_batch, 0, 0, 3)
ZEND_ARG_INFO(0, link_identifier)
ZEND_ARG_INFO(0, dn)
ZEND_ARG_ARRAY_INFO(0, modifications_info, 0)
+ ZEND_ARG_INFO(0, servercontrols)
+ ZEND_ARG_INFO(0, clientcontrols)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_mod_add, 0, 0, 3)
diff --git a/ext/ldap/tests/ldap_modify_batch_error.phpt
b/ext/ldap/tests/ldap_modify_batch_error.phpt
index 2d72d49..3a1030f 100644
--- a/ext/ldap/tests/ldap_modify_batch_error.phpt
+++ b/ext/ldap/tests/ldap_modify_batch_error.phpt
@@ -26,7 +26,7 @@ var_dump(ldap_modify_batch($link));
var_dump(ldap_modify_batch($link, "$base"));
// Too many parameters
-var_dump(ldap_modify_batch($link, "$base", $addGivenName, "Invalid additional
parameter"));
+var_dump(ldap_modify_batch($link, "$base", $addGivenName, [], [], "Invalid
additional parameter"));
// DN not found
var_dump(ldap_modify_batch($link, "cn=not-found,$base", $addGivenName));
@@ -78,16 +78,16 @@ $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,$base");
?>
--EXPECTF--
-Warning: ldap_modify_batch() expects exactly 3 parameters, 0 given in %s on line %d
+Warning: ldap_modify_batch() expects at least 3 parameters, 0 given in %s on line %d
NULL
-Warning: ldap_modify_batch() expects exactly 3 parameters, 1 given in %s on line %d
+Warning: ldap_modify_batch() expects at least 3 parameters, 1 given in %s on line %d
NULL
-Warning: ldap_modify_batch() expects exactly 3 parameters, 2 given in %s on line %d
+Warning: ldap_modify_batch() expects at least 3 parameters, 2 given in %s on line %d
NULL
-Warning: ldap_modify_batch() expects exactly 3 parameters, 4 given in %s on line %d
+Warning: ldap_modify_batch() expects at most 5 parameters, 6 given in %s on line %d
NULL
Warning: ldap_modify_batch(): Batch Modify: No such object in %s on line %d