forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldap_get_option_controls.phpt
72 lines (68 loc) · 1.84 KB
/
ldap_get_option_controls.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--TEST--
ldap_get_option() and ldap_set_option() tests related to ldap controls
--CREDITS--
Côme Chilliet <[email protected]>
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link, $base);
function build_ctrl_paged_value($int, $cookie)
{
// This is basic and will only work for small values
$hex = '';
if (!empty($int)) {
$str = sprintf("%'.02x", $int);
$hex .= '02'.sprintf("%'.02x%s", strlen($str)/2, $str);
}
$hex .= '04'.sprintf("%'.02x", strlen($cookie)).bin2hex($cookie);
return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
}
$controls_set = array(
array(
'oid' => LDAP_CONTROL_PAGEDRESULTS,
'iscritical' => TRUE,
'value' => build_ctrl_paged_value(1, '')
)
);
var_dump(
bin2hex($controls_set[0]['value']),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
count($controls_get),
$controls_get[0]['oid'],
$controls_get[0]['iscritical'],
bin2hex($controls_get[0]['value']),
$result = ldap_search($link, $base, "(objectClass=person)", array('cn')),
ldap_get_entries($link, $result)['count'],
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array()),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link, $base);
?>
--EXPECTF--
string(14) "30050201010400"
bool(false)
bool(true)
bool(true)
int(1)
string(22) "1.2.840.113556.1.4.319"
bool(true)
string(14) "30050201010400"
resource(%d) of type (ldap result)
int(1)
bool(true)
bool(false)
===DONE===