Added controls support to ldap_rename

This commit is contained in:
Côme Chilliet 2017-09-07 11:57:13 +02:00
parent 437c75abcb
commit 82cc72a3ba
3 changed files with 43 additions and 7 deletions

View File

@ -3112,18 +3112,20 @@ PHP_FUNCTION(ldap_parse_reference)
/* }}} */
#endif
/* {{{ proto bool ldap_rename(resource link, string dn, string newrdn, string newparent, bool deleteoldrdn)
/* {{{ proto bool ldap_rename(resource link, string dn, string newrdn, string newparent, bool deleteoldrdn [, array servercontrols [, array clientcontrols]])
Modify the name of an entry */
PHP_FUNCTION(ldap_rename)
{
zval *serverctrls = NULL, *clientctrls = NULL;
zval *link;
ldap_linkdata *ld;
LDAPControl **lserverctrls = NULL, **lclientctrls = NULL;
int rc;
char *dn, *newrdn, *newparent;
size_t dn_len, newrdn_len, newparent_len;
zend_bool deleteoldrdn;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsssb", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsssb|aa", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &serverctrls, &clientctrls) != SUCCESS) {
return;
}
@ -3136,20 +3138,50 @@ PHP_FUNCTION(ldap_rename)
}
#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP
rc = ldap_rename_s(ld->link, dn, newrdn, newparent, deleteoldrdn, NULL, 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;
}
}
rc = ldap_rename_s(ld->link, dn, newrdn, newparent, deleteoldrdn, lserverctrls, lclientctrls);
#else
if (newparent_len != 0) {
php_error_docref(NULL, E_WARNING, "You are using old LDAP API, newparent must be the empty string, can only modify RDN");
RETURN_FALSE;
}
if (serverctrls || clientctrls) {
php_error_docref(NULL, E_WARNING, "You are using old LDAP API, controls are not supported");
RETURN_FALSE;
}
/* could support old APIs but need check for ldap_modrdn2()/ldap_modrdn() */
rc = ldap_modrdn2_s(ld->link, dn, newrdn, deleteoldrdn);
#endif
if (rc == LDAP_SUCCESS) {
RETURN_TRUE;
RETVAL_TRUE;
} else {
RETVAL_FALSE;
}
RETURN_FALSE;
cleanup:
if (lserverctrls) {
_php_ldap_controls_free(&lserverctrls);
}
if (lclientctrls) {
_php_ldap_controls_free(&lclientctrls);
}
return;
}
/* }}} */
@ -4106,6 +4138,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_rename, 0, 0, 5)
ZEND_ARG_INFO(0, newrdn)
ZEND_ARG_INFO(0, newparent)
ZEND_ARG_INFO(0, deleteoldrdn)
ZEND_ARG_INFO(0, servercontrols)
ZEND_ARG_INFO(0, clientcontrols)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_option, 0, 0, 3)

View File

@ -31,7 +31,8 @@ var_dump(
ldap_get_entries($link, $result),
ldap_delete($link, "o=test,$base", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
ldap_errno($link),
ldap_error($link)
ldap_error($link),
ldap_rename($link, "o=test,$base", "o=test2", "", TRUE, [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]])
);
?>
===DONE===
@ -117,4 +118,5 @@ array(2) {
bool(false)
int(122)
string(16) "Assertion Failed"
bool(false)
===DONE===

View File

@ -15,7 +15,7 @@ var_dump(ldap_rename($link, "cn=userNotFound,$base", "cn=userZ", "$base", true))
?>
===DONE===
--EXPECTF--
Warning: ldap_rename() expects exactly 5 parameters, 1 given in %s on line %d
Warning: ldap_rename() expects at least 5 parameters, 1 given in %s on line %d
NULL
bool(false)
===DONE===