xref: /PHP-8.0/ext/ldap/tests/ldap_exop.phpt (revision f8d79582)
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--CLEAN--
59<?php
60require "connect.inc";
61
62$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
63
64remove_dummy_data($link, $base);
65?>
66--EXPECTF--
67bool(true)
68string(%d) "dn:%s"
69string(0) ""
70bool(true)
71string(%d) "dn:cn=user%s"
72resource(%d) of type (ldap result)
73bool(true)
74string(%d) "dn:%s"
75bool(true)
76resource(%d) of type (ldap result)
77bool(true)
78string(%d) "%s"
79string(0) ""
80bool(true)
81