xref: /PHP-7.4/ext/ldap/tests/ldap_exop.phpt (revision d377edb8)
1--TEST--
2ldap_exop() and ldap_parse_exop() - EXOP operations
3--CREDITS--
4Côme Chilliet <mcmic@php.net>
5--SKIPIF--
6<?php require_once('skipif.inc'); ?>
7<?php require_once('skipifbindfailure.inc'); ?>
8--FILE--
9<?php
10require "connect.inc";
11
12$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
13insert_dummy_data($link, $base);
14
15function build_reqdata_passwd($user, $oldpw, $newpw)
16{
17	// This is basic and will only work for small strings
18	$hex = '';
19	if (!empty($user)) {
20		$hex .= '80'.sprintf("%'.02x", strlen($user)).bin2hex($user);
21	}
22	if (!empty($oldpw)) {
23		$hex .= '81'.sprintf("%'.02x", strlen($oldpw)).bin2hex($oldpw);
24	}
25	if (!empty($newpw)) {
26		$hex .= '82'.sprintf("%'.02x", strlen($newpw)).bin2hex($newpw);
27	}
28	return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
29}
30
31function extract_genpw($retdata)
32{
33	// Only works for small strings as well
34	return hex2bin(substr(bin2hex($retdata), 4*2));
35}
36
37$userAPassword = "oops";
38
39// ldap_exop(resource link, string reqoid [, string reqdata [, array servercontrols [, string &retdata [, string &retoid]]]])
40// bool ldap_parse_exop(resource link, resource result [, string &retdata [, string &retoid]])
41var_dump(
42	ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, NULL, $retdata, $retoid),
43	$retdata,
44	$retoid,
45	ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, [['oid' => LDAP_CONTROL_PROXY_AUTHZ, 'value' => "dn:cn=userA,$base"]], $retdata),
46	$retdata,
47	$r = ldap_exop($link, LDAP_EXOP_WHO_AM_I),
48	ldap_parse_exop($link, $r, $retdata2),
49	$retdata2,
50	test_bind($host, $port, "cn=userA,$base", $userAPassword, $protocol_version),
51	$r = ldap_exop($link, LDAP_EXOP_MODIFY_PASSWD, build_reqdata_passwd("cn=userA,$base", $userAPassword, "")),
52	ldap_parse_exop($link, $r, $retpwdata, $retpwoid),
53	$genpw = extract_genpw($retpwdata),
54	$retpwoid,
55	test_bind($host, $port, "cn=userA,$base", $genpw, $protocol_version)
56);
57?>
58===DONE===
59--CLEAN--
60<?php
61require "connect.inc";
62
63$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
64
65remove_dummy_data($link, $base);
66?>
67--EXPECTF--
68bool(true)
69string(%d) "dn:%s"
70string(0) ""
71bool(true)
72string(%d) "dn:cn=user%s"
73resource(%d) of type (ldap result)
74bool(true)
75string(%d) "dn:%s"
76bool(true)
77resource(%d) of type (ldap result)
78bool(true)
79string(%d) "%s"
80string(0) ""
81bool(true)
82===DONE===
83