]> granicus.if.org Git - php/commitdiff
Fixed ldap_exop_passwd and added tests for it
authorCôme Chilliet <mcmic@php.net>
Tue, 20 Jun 2017 13:18:16 +0000 (15:18 +0200)
committerCôme Chilliet <mcmic@php.net>
Mon, 3 Jul 2017 08:58:12 +0000 (10:58 +0200)
ext/ldap/ldap.c
ext/ldap/tests/connect.inc
ext/ldap/tests/ldap_exop_passwd.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_exop_passwd_error.phpt [new file with mode: 0644]

index 15dcee20fd3512c2a80e3a33da489a0a3b3fae9c..c5a80f9680f252780de60e133202e221b527219e 100644 (file)
@@ -3405,7 +3405,7 @@ PHP_FUNCTION(ldap_exop_passwd)
        LDAPMessage *ldap_res;
        int rc, msgid, myargcount = ZEND_NUM_ARGS();
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|zzzz", &link, &user, &oldpw, &newpw, &newpasswd) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|zzzz/", &link, &user, &oldpw, &newpw, &newpasswd) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
 
@@ -3439,7 +3439,6 @@ PHP_FUNCTION(ldap_exop_passwd)
                /* synchronous call */
                rc = ldap_passwd_s(ld->link, &luser,
                        loldpw.bv_len > 0 ? &loldpw : NULL,
-                       /* loldpw.bv_len > 0 ? &loldpw : NULL, */
                        lnewpw.bv_len > 0 ? &lnewpw : NULL,
                        &lnewpasswd, NULL, NULL);
                if (rc != LDAP_SUCCESS ) {
@@ -3887,9 +3886,9 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop_passwd, 0, 0, 5)
        ZEND_ARG_INFO(0, link)
-       ZEND_ARG_INFO(1, user)
-       ZEND_ARG_INFO(1, oldpw)
-       ZEND_ARG_INFO(1, newpw)
+       ZEND_ARG_INFO(0, user)
+       ZEND_ARG_INFO(0, oldpw)
+       ZEND_ARG_INFO(0, newpw)
        ZEND_ARG_INFO(1, newpasswd)
 ZEND_END_ARG_INFO()
 
@@ -3903,7 +3902,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_refresh, 0, 0, 4)
        ZEND_ARG_INFO(0, link)
        ZEND_ARG_INFO(0, dn)
-       ZEND_ARG_INFO(1, ttl)
+       ZEND_ARG_INFO(0, ttl)
        ZEND_ARG_INFO(0, newttl)
 ZEND_END_ARG_INFO()
 #endif
index f7379ac95421636e53ad0586ad72c15e0cb93524..1c2205056eb3878e679a2e70ffffa1e4562c499c 100644 (file)
@@ -21,6 +21,12 @@ function ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version)
        return $link;
 }
 
+function test_bind($host, $port, $user, $passwd, $protocol_version) {
+       $link = ldap_connect($host, $port);
+       ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+       return ldap_bind($link, $user, $passwd);
+}
+
 function insert_dummy_data($link, $base) {
        // Create root if not there
        $testBase = ldap_read($link, $base, '(objectClass=*)', array('objectClass'));
diff --git a/ext/ldap/tests/ldap_exop_passwd.phpt b/ext/ldap/tests/ldap_exop_passwd.phpt
new file mode 100644 (file)
index 0000000..5ab926e
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+ldap_exop_passwd() - Changing password through EXOP
+--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);
+insert_dummy_data($link, $base);
+
+// ldap_exop_passwd() allows to pass the DN, OLD and NEW passwords,
+// and optionally returns the NEW password if none was passed.
+// ldap_exop_passwd(resource link [, string user [, string oldpw [, string newpw [, string newpasswd ]]]])
+var_dump(
+  ldap_exop_passwd($link, "cn=userA,$base", "oops", "", $genpw),
+  $genpw,
+  test_bind($host, $port, "cn=userA,$base", $genpw, $protocol_version),
+  ldap_exop_passwd($link, "cn=userA,$base", $genpw, "newPassword"),
+  test_bind($host, $port, "cn=userA,$base", "newPassword", $protocol_version)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link, $base);
+?>
+--EXPECTF--
+bool(true)
+string(%d) "%s"
+bool(true)
+bool(true)
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_exop_passwd_error.phpt b/ext/ldap/tests/ldap_exop_passwd_error.phpt
new file mode 100644 (file)
index 0000000..0476cb5
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+ldap_exop_passwd() - Giving wrong value for old password
+--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);
+insert_dummy_data($link, $base);
+
+var_dump(ldap_exop_passwd($link, "cn=userA,$base", "wrongPassword", "newPassword"));
+var_dump(test_bind($host, $port, "cn=userA,$base", "newPassword", $protocol_version));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link, $base);
+?>
+--EXPECTF--
+Warning: ldap_exop_passwd(): Passwd modify extended operation failed: Server is unwilling to perform (53) in %s on line %d
+bool(false)
+
+Warning: ldap_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+===DONE===