Surprisingly, there is little easy to find information available for how to generate samba passwords, suitable for ldap, from within php5. The answer, though simple, should make any reasonable sysadmin burst into tears.
1. convert the string to unicode
2. run it through pack
3. mhash it (MD4 of all things)
4. bin2hex it.
function GenSambaPass($pass) {
$uni = '';
for ($i = 0; $i < strlen($pass); $i++) {
$a = ord($pass{$i}) << 8;
$uni .= sprintf("%X", $a);
}
return bin2hex(mhash(MHASH_MD4,pack('H*', $uni)));
}