com php-src: Added ldap_delete_ext and its test: ext/ldap/ldap.c ext/ldap/tests/ldap_delete_ext.phpt
| From: | Côme Bernigaud | Date: | Thu, 21 Sep 2017 08:05:42 +0000 |
| Subject: | com php-src: Added ldap_delete_ext and its test: ext/ldap/ldap.c ext/ldap/tests/ldap_delete_ext.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99488@lists.php.net to get a copy of this message | ||
Commit: ead53aba542eb6c848bdd73cf5f57b871e703f61
Author: Côme Chilliet <mcmic@php.net> Tue, 12 Sep 2017 11:39:00 +0200
Parents: 17e490a2e3389da09c4a656f571292f14ddefb18
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ead53aba542eb6c848bdd73cf5f57b871e703f61
Log:
Added ldap_delete_ext and its test
Changed paths:
M ext/ldap/ldap.c
A ext/ldap/tests/ldap_delete_ext.phpt
Diff:
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 666251f..046610c 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -2223,16 +2223,17 @@ PHP_FUNCTION(ldap_mod_del_ext)
}
/* }}} */
-/* {{{ proto bool ldap_delete(resource link, string dn [, array servercontrols])
- Delete an entry from a directory */
-PHP_FUNCTION(ldap_delete)
+/* {{{ php_ldap_do_delete
+ */
+static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
{
zval *serverctrls = NULL;
zval *link;
ldap_linkdata *ld;
LDAPControl **lserverctrls = NULL;
+ LDAPMessage *ldap_res;
char *dn;
- int rc;
+ int rc, msgid;
size_t dn_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|a", &link, &dn, &dn_len,
&serverctrls) != SUCCESS) {
@@ -2251,9 +2252,25 @@ PHP_FUNCTION(ldap_delete)
}
}
- if ((rc = ldap_delete_ext_s(ld->link, dn, lserverctrls, NULL)) != LDAP_SUCCESS) {
+ if (ext) {
+ rc = ldap_delete_ext(ld->link, dn, lserverctrls, NULL, &msgid);
+ } else {
+ rc = ldap_delete_ext_s(ld->link, dn, lserverctrls, NULL);
+ }
+ if (rc != LDAP_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Delete: %s", ldap_err2string(rc));
RETVAL_FALSE;
+ goto cleanup;
+ } else if (ext) {
+ rc = ldap_result(ld->link, msgid, 1 /* LDAP_MSG_ALL */, NULL, &ldap_res);
+ if (rc == -1) {
+ php_error_docref(NULL, E_WARNING, "Delete operation failed");
+ RETVAL_FALSE;
+ goto cleanup;
+ }
+
+ /* return a PHP control object */
+ RETVAL_RES(zend_register_resource(ldap_res, le_result));
} else {
RETVAL_TRUE;
}
@@ -2267,6 +2284,22 @@ cleanup:
}
/* }}} */
+/* {{{ proto bool ldap_delete(resource link, string dn [, array servercontrols])
+ Delete an entry from a directory */
+PHP_FUNCTION(ldap_delete)
+{
+ php_ldap_do_delete(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}} */
+
+/* {{{ proto resource ldap_delete_ext(resource link, string dn [, array servercontrols])
+ Delete an entry from a directory */
+PHP_FUNCTION(ldap_delete_ext)
+{
+ php_ldap_do_delete(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
/* {{{ _ldap_str_equal_to_const
*/
static size_t _ldap_str_equal_to_const(const char *str, size_t str_len, const char *cstr)
@@ -4317,6 +4350,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_delete, 0, 0, 2)
ZEND_ARG_INFO(0, servercontrols)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_delete_ext, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, servercontrols)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_modify, 0, 0, 3)
ZEND_ARG_INFO(0, link_identifier)
ZEND_ARG_INFO(0, dn)
@@ -4563,6 +4602,7 @@ const zend_function_entry ldap_functions[] = {
PHP_FE(ldap_add, arginfo_ldap_add)
PHP_FE(ldap_add_ext, arginfo_ldap_add_ext)
PHP_FE(ldap_delete, arginfo_ldap_delete)
+ PHP_FE(ldap_delete_ext, arginfo_ldap_delete_ext)
PHP_FE(ldap_modify_batch, arginfo_ldap_modify_batch)
PHP_FALIAS(ldap_modify, ldap_mod_replace, arginfo_ldap_modify)
diff --git a/ext/ldap/tests/ldap_delete_ext.phpt b/ext/ldap/tests/ldap_delete_ext.phpt
new file mode 100644
index 0000000..6f48cb2
--- /dev/null
+++ b/ext/ldap/tests/ldap_delete_ext.phpt
@@ -0,0 +1,72 @@
+--TEST--
+ldap_delete_ext() - Delete operation with controls
+--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);
+ldap_add($link, "dc=my-domain,$base", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+));
+
+var_dump(
+ $result = ldap_delete_ext($link, "dc=my-domain,$base",
+ [['oid' => LDAP_CONTROL_PRE_READ, 'iscritical' => TRUE,
'value' => ['attrs' => ['dc', 'o']]]]
+ ),
+ ldap_parse_result($link, $result, $errcode, $matcheddn, $errmsg, $referrals, $ctrls),
+ $errcode,
+ $errmsg,
+ $ctrls,
+ @ldap_search($link, "dc=my-domain,$base", "(o=my-domain)")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,$base");
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+bool(true)
+int(0)
+string(0) ""
+array(1) {
+ [0]=>
+ array(3) {
+ ["oid"]=>
+ string(14) "1.3.6.1.1.13.1"
+ ["iscritical"]=>
+ bool(false)
+ ["value"]=>
+ array(3) {
+ ["dn"]=>
+ string(%d) "dc=my-domain,%s"
+ ["dc"]=>
+ array(1) {
+ [0]=>
+ string(9) "my-domain"
+ }
+ ["o"]=>
+ array(1) {
+ [0]=>
+ string(9) "my-domain"
+ }
+ }
+ }
+}
+bool(false)
+===DONE===