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