com php-src: Improved ldap_exop test to encode&decode a passwd EXOP to test sending/recieving data: ext/ldap/tests/ldap_exop.phpt
| From: | Côme Bernigaud | Date: | Mon, 03 Jul 2017 08:58:13 +0000 |
| Subject: | com php-src: Improved ldap_exop test to encode&decode a passwd EXOP to test sending/recieving data: ext/ldap/tests/ldap_exop.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98383@lists.php.net to get a copy of this message | ||
Commit: 5020325a6f5a05df32e1142809b57bed6522b52f
Author: Côme Chilliet <mcmic@php.net> Tue, 27 Jun 2017 16:15:39 +0200
Parents: 413e9c84f6ed57ee16e2f413a4acb06a3ff899c0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5020325a6f5a05df32e1142809b57bed6522b52f
Log:
Improved ldap_exop test to encode&decode a passwd EXOP to test sending/recieving data
Changed paths:
M ext/ldap/tests/ldap_exop.phpt
Diff:
diff --git a/ext/ldap/tests/ldap_exop.phpt b/ext/ldap/tests/ldap_exop.phpt
index 5f93a02..0158944 100644
--- a/ext/ldap/tests/ldap_exop.phpt
+++ b/ext/ldap/tests/ldap_exop..phpt
@@ -12,14 +12,30 @@ require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link, $base);
-function ber_encode($string) {
- $null_padded_string = '';
- for($i = 0; $i<strlen($string); $i++) {
- $null_padded_string .= substr($string,$i,1)."\0";
+function build_reqdata_passwd($user, $oldpw, $newpw)
+{
+ // This is basic and will only work for small strings
+ $hex = '';
+ if (!empty($user)) {
+ $hex .= '80'.sprintf("%'.02x", strlen($user)).bin2hex($user);
}
- return base64_encode($null_padded_string);
+ if (!empty($oldpw)) {
+ $hex .= '81'.sprintf("%'.02x", strlen($oldpw)).bin2hex($oldpw);
+ }
+ if (!empty($newpw)) {
+ $hex .= '82'.sprintf("%'.02x", strlen($newpw)).bin2hex($newpw);
+ }
+ return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
}
+function extract_genpw($retdata)
+{
+ // Only works for small strings as well
+ return hex2bin(substr(bin2hex($retdata), 4*2));
+}
+
+$userAPassword = "oops";
+
// ldap_exop(resource link, string reqoid [, string reqdata [, string retoid [, string retdata]]])
// bool ldap_parse_exop(resource link, resource result [, string retoid [, string retdata]])
var_dump(
@@ -29,7 +45,13 @@ var_dump(
$r = ldap_exop($link, LDAP_EXOP_WHO_AM_I),
ldap_parse_exop($link, $r, $retoid2, $retdata2),
$retdata2,
- $retoid2
+ $retoid2,
+ test_bind($host, $port, "cn=userA,$base", $userAPassword, $protocol_version),
+ $r = ldap_exop($link, LDAP_EXOP_MODIFY_PASSWD, build_reqdata_passwd("cn=userA,$base",
$userAPassword, "")),
+ ldap_parse_exop($link, $r, $retpwoid, $retpwdata),
+ $genpw = extract_genpw($retpwdata),
+ $retpwoid,
+ test_bind($host, $port, "cn=userA,$base", $genpw, $protocol_version)
);
?>
===DONE===
@@ -49,4 +71,10 @@ resource(%d) of type (ldap result)
bool(true)
string(%d) "dn:%s"
string(0) ""
+bool(true)
+resource(%d) of type (ldap result)
+bool(true)
+string(%d) "%s"
+string(0) ""
+bool(true)
===DONE===