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