ldap_get_option_controls.phpt 2.5 KB

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