]> granicus.if.org Git - php/commitdiff
Added ldap_delete_ext and its test
authorCôme Chilliet <mcmic@php.net>
Tue, 12 Sep 2017 09:39:00 +0000 (11:39 +0200)
committerCôme Chilliet <mcmic@php.net>
Thu, 21 Sep 2017 08:05:42 +0000 (10:05 +0200)
ext/ldap/ldap.c
ext/ldap/tests/ldap_delete_ext.phpt [new file with mode: 0644]

index 666251fae1df2adb030acda2d6f15c7d3ec50c72..046610c92b3bbe6a0093a1d0cff72f502e50e7df 100644 (file)
@@ -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 (file)
index 0000000..6f48cb2
--- /dev/null
@@ -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===