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