1--TEST--
2ldap_get_option() and ldap_set_option() tests related to ldap controls
3--CREDITS--
4Côme Chilliet <mcmic@php.net>
5--EXTENSIONS--
6ldap
7--SKIPIF--
8<?php
9require_once('skipifbindfailure.inc');
10?>
11--FILE--
12<?php
13include "connect.inc";
14
15$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
16insert_dummy_data($link, $base);
17
18function build_ctrl_paged_value($int, $cookie)
19{
20    // This is basic and will only work for small values
21    $hex = '';
22    if (!empty($int)) {
23        $str = sprintf("%'.02x", $int);
24        $hex .= '02'.sprintf("%'.02x%s", strlen($str)/2, $str);
25    }
26    $hex .= '04'.sprintf("%'.02x", strlen($cookie)).bin2hex($cookie);
27    return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
28}
29
30$controls_set = array(
31    array(
32        'oid' => LDAP_CONTROL_PAGEDRESULTS,
33        'iscritical' => TRUE,
34        'value' => build_ctrl_paged_value(1, 'opaque')
35    )
36);
37$controls_set2 = array(
38    array(
39        'oid' => LDAP_CONTROL_PAGEDRESULTS,
40        'iscritical' => TRUE,
41        'value' => array(
42            'size' => 1,
43            'cookie' => '',
44        )
45    )
46);
47var_dump(
48    bin2hex($controls_set[0]['value']),
49    ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
50    ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set),
51    ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
52    $controls_get,
53    ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set2),
54    ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
55    $controls_get,
56    $result = ldap_search($link, $base, "(objectClass=person)", array('cn')),
57    ldap_get_entries($link, $result)['count'],
58    ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array()),
59    ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get)
60);
61?>
62--CLEAN--
63<?php
64include "connect.inc";
65
66$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
67remove_dummy_data($link, $base);
68?>
69--EXPECTF--
70string(26) "300b02010104066f7061717565"
71bool(false)
72bool(true)
73bool(true)
74array(1) {
75  ["1.2.840.113556.1.4.319"]=>
76  array(3) {
77    ["oid"]=>
78    string(22) "1.2.840.113556.1.4.319"
79    ["iscritical"]=>
80    bool(true)
81    ["value"]=>
82    array(2) {
83      ["size"]=>
84      int(1)
85      ["cookie"]=>
86      string(6) "opaque"
87    }
88  }
89}
90bool(true)
91bool(true)
92array(1) {
93  ["1.2.840.113556.1.4.319"]=>
94  array(3) {
95    ["oid"]=>
96    string(22) "1.2.840.113556.1.4.319"
97    ["iscritical"]=>
98    bool(true)
99    ["value"]=>
100    array(2) {
101      ["size"]=>
102      int(1)
103      ["cookie"]=>
104      string(0) ""
105    }
106  }
107}
108object(LDAP\Result)#%d (0) {
109}
110int(1)
111bool(true)
112bool(false)
113