ldap_exop.phpt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. ldap_exop() and ldap_parse_exop() - EXOP operations
  3. --CREDITS--
  4. Côme Chilliet <mcmic@php.net>
  5. --SKIPIF--
  6. <?php require_once('skipif.inc'); ?>
  7. <?php require_once('skipifbindfailure.inc'); ?>
  8. --FILE--
  9. <?php
  10. require "connect.inc";
  11. $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
  12. insert_dummy_data($link, $base);
  13. function build_reqdata_passwd($user, $oldpw, $newpw)
  14. {
  15. // This is basic and will only work for small strings
  16. $hex = '';
  17. if (!empty($user)) {
  18. $hex .= '80'.sprintf("%'.02x", strlen($user)).bin2hex($user);
  19. }
  20. if (!empty($oldpw)) {
  21. $hex .= '81'.sprintf("%'.02x", strlen($oldpw)).bin2hex($oldpw);
  22. }
  23. if (!empty($newpw)) {
  24. $hex .= '82'.sprintf("%'.02x", strlen($newpw)).bin2hex($newpw);
  25. }
  26. return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
  27. }
  28. function extract_genpw($retdata)
  29. {
  30. // Only works for small strings as well
  31. return hex2bin(substr(bin2hex($retdata), 4*2));
  32. }
  33. $userAPassword = "oops";
  34. // ldap_exop(resource link, string reqoid [, string reqdata [, array servercontrols [, string &retdata [, string &retoid]]]])
  35. // bool ldap_parse_exop(resource link, resource result [, string &retdata [, string &retoid]])
  36. var_dump(
  37. ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, NULL, $retdata, $retoid),
  38. $retdata,
  39. $retoid,
  40. ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, [['oid' => LDAP_CONTROL_PROXY_AUTHZ, 'value' => "dn:cn=userA,$base"]], $retdata),
  41. $retdata,
  42. $r = ldap_exop($link, LDAP_EXOP_WHO_AM_I),
  43. ldap_parse_exop($link, $r, $retdata2),
  44. $retdata2,
  45. test_bind($host, $port, "cn=userA,$base", $userAPassword, $protocol_version),
  46. $r = ldap_exop($link, LDAP_EXOP_MODIFY_PASSWD, build_reqdata_passwd("cn=userA,$base", $userAPassword, "")),
  47. ldap_parse_exop($link, $r, $retpwdata, $retpwoid),
  48. $genpw = extract_genpw($retpwdata),
  49. $retpwoid,
  50. test_bind($host, $port, "cn=userA,$base", $genpw, $protocol_version)
  51. );
  52. ?>
  53. ===DONE===
  54. --CLEAN--
  55. <?php
  56. require "connect.inc";
  57. $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
  58. remove_dummy_data($link, $base);
  59. ?>
  60. --EXPECTF--
  61. bool(true)
  62. string(%d) "dn:%s"
  63. string(0) ""
  64. bool(true)
  65. string(%d) "dn:cn=user%s"
  66. resource(%d) of type (ldap result)
  67. bool(true)
  68. string(%d) "dn:%s"
  69. bool(true)
  70. resource(%d) of type (ldap result)
  71. bool(true)
  72. string(%d) "%s"
  73. string(0) ""
  74. bool(true)
  75. ===DONE===