ldap_exop.phpt 2.1 KB

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