Perhaps you do not wish to go this route but I use:
system(escapeshellcmd("smbpasswd -a -m $username"));
In our ldap, we have people who are in the following objectclasses