com php-src: Fixed ldap_exop_passwd and added tests for it: ext/ldap/ldap.c ext/ldap/tests/connect.i nc ext/ldap/tests/ldap_exop_passwd.phpt
ext/ldap/test s/ldap_exop_passwd_error.phpt

From: Date: Mon, 03 Jul 2017 08:58:12 +0000
Subject: com php-src: Fixed ldap_exop_passwd and added tests for it: ext/ldap/ldap.c ext/ldap/tests/connect.i nc ext/ldap/tests/ldap_exop_passwd.phpt
ext/ldap/test s/ldap_exop_passwd_error.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98387@lists.php.net to get a copy of this message
Commit: ae76c8ba2c41a3883672f3ddc6d93fd65aaa3b4e Author: Côme Chilliet <mcmic@php.net> Tue, 20 Jun 2017 15:18:16 +0200 Parents: def09c7cab2f30fbe8e7a34c978284eedd8bf3ad Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ae76c8ba2c41a3883672f3ddc6d93fd65aaa3b4e Log: Fixed ldap_exop_passwd and added tests for it Changed paths: M ext/ldap/ldap.c M ext/ldap/tests/connect.inc A ext/ldap/tests/ldap_exop_passwd.phpt A ext/ldap/tests/ldap_exop_passwd_error.phpt Diff: diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 15dcee2..c5a80f9 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -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 diff --git a/ext/ldap/tests/connect.inc b/ext/ldap/tests/connect.inc index f7379ac..1c22050 100644 --- a/ext/ldap/tests/connect.inc +++ b/ext/ldap/tests/connect..inc @@ -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 index 0000000..5ab926e --- /dev/null +++ b/ext/ldap/tests/ldap_exop_passwd.phpt @@ -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 index 0000000..0476cb5 --- /dev/null +++ b/ext/ldap/tests/ldap_exop_passwd_error.phpt @@ -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===

« previous php.cvs (#98387) next »