xref: /PHP-8.4/ext/ldap/tests/ldap_exop.phpt (revision 682c2366)
1--TEST--
2ldap_exop() and ldap_parse_exop() - EXOP operations
3--CREDITS--
4Côme Chilliet <mcmic@php.net>
5--EXTENSIONS--
6ldap
7--SKIPIF--
8<?php require_once('skipifbindfailure.inc'); ?>
9--FILE--
10<?php
11require "connect.inc";
12
13$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
14insert_dummy_data($link, $base);
15
16function build_reqdata_passwd($user, $oldpw, $newpw)
17{
18    // This is basic and will only work for small strings
19    $hex = '';
20    if (!empty($user)) {
21        $hex .= '80'.sprintf("%'.02x", strlen($user)).bin2hex($user);
22    }
23    if (!empty($oldpw)) {
24        $hex .= '81'.sprintf("%'.02x", strlen($oldpw)).bin2hex($oldpw);
25    }
26    if (!empty($newpw)) {
27        $hex .= '82'.sprintf("%'.02x", strlen($newpw)).bin2hex($newpw);
28    }
29    return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
30}
31
32function extract_genpw($retdata)
33{
34    // Only works for small strings as well
35    return hex2bin(substr(bin2hex($retdata), 4*2));
36}
37
38$userAPassword = "oops";
39
40var_dump(
41    ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, NULL, $retdata, $retoid),
42    $retdata,
43    $retoid,
44    ldap_exop_sync($link, LDAP_EXOP_WHO_AM_I, NULL, NULL, $retdata, $retoid),
45    $retdata,
46    $retoid,
47    ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, [['oid' => LDAP_CONTROL_PROXY_AUTHZ, 'value' => "dn:cn=userA,$base"]], $retdata),
48    $retdata,
49    ldap_exop_sync($link, LDAP_EXOP_WHO_AM_I, NULL, [['oid' => LDAP_CONTROL_PROXY_AUTHZ, 'value' => "dn:cn=userA,$base"]], $retdata),
50    $retdata,
51    $r = ldap_exop($link, LDAP_EXOP_WHO_AM_I),
52    ldap_parse_exop($link, $r, $retdata2),
53    $retdata2,
54    test_bind($uri, "cn=userA,$base", $userAPassword, $protocol_version),
55    $r = ldap_exop($link, LDAP_EXOP_MODIFY_PASSWD, build_reqdata_passwd("cn=userA,$base", $userAPassword, "")),
56    ldap_parse_exop($link, $r, $retpwdata, $retpwoid),
57    $genpw = extract_genpw($retpwdata),
58    $retpwoid,
59    test_bind($uri, "cn=userA,$base", $genpw, $protocol_version)
60);
61?>
62--CLEAN--
63<?php
64require "connect.inc";
65
66$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
67
68remove_dummy_data($link, $base);
69?>
70--EXPECTF--
71Deprecated: Calling ldap_exop() with more than 4 arguments is deprecated, use ldap_exop_sync() instead in %s on line %d
72
73Deprecated: Calling ldap_exop() with more than 4 arguments is deprecated, use ldap_exop_sync() instead in %s on line %d
74bool(true)
75string(%d) "dn:%s"
76string(0) ""
77bool(true)
78string(%d) "dn:%s"
79string(0) ""
80bool(true)
81string(%d) "dn:cn=user%s"
82bool(true)
83string(%d) "dn:cn=user%s"
84object(LDAP\Result)#%d (0) {
85}
86bool(true)
87string(%d) "dn:%s"
88bool(true)
89object(LDAP\Result)#%d (0) {
90}
91bool(true)
92string(%d) "%s"
93string(0) ""
94bool(true)
95