riesco a creare un utente ldap da php, ma lo crea in stato "disabilitato" su ldap, non riesco a trovare l'attributo da settare per creare un utente "abilitato", qualcuno sa aiutarmi?
questo è il codice che sto usando:
Codice PHP:
try { add_ldap_user ();} catch(Exception $e) { echo "errore add_ldap_user: ".$e->getMessage();}
function add_ldap_user () { $msg = null; // config $ldapserver = 'MIOSERVER.LOCAL'; $ldapuser = 'adminuser'; $ldappass = 'adminpassword'; $branch = "cn=Users,dc=MIODOMINIO,dc=LOCAL";
$ldapconn=ldap_connect($ldapserver); // must be a valid LDAP server!
if (!$ldapconn) { $msg = "Unable to connect to LDAP server"; throw new Exception($msg); } ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 1) ;
if (!ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3)) { $msg = "Failed to set protocol version to 3"; throw new Exception($msg); } if (!ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 1)) { $msg = "Failed to set LDAP_OPT_REFERRALS to 1"; throw new Exception($msg); } $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
if (!$ldapbind) { $msg = "Unable to bind: "; $msg .= ldap_error($ldapconn); throw new Exception($msg); } echo "connessione a ldap ok3";
$base_dn = "cn=John,cn=Users,dc=MIODOMINIO,dc=LOCAL"; $entry = array(); $entry["cn"] = "John3"; $entry["objectclass"] = "person"; $entry["samaccountname"] = "prova1"; $entry["mail"] = "test1@test.it"; $entry["objectCategory"] ='CN=Person,CN=Schema,CN=Configuration,dc=MIODOMINIO,dc=LOCAL'; $newuser_plaintext_password = "Elettra77"; $r = ldap_add($ldapconn, 'CN=John12,'.$branch, array( 'cn' => 'John12', 'name' => 'Smith', 'sn' => 'asd', 'instanceType' => '4', 'objectCategory'=> 'CN=Person,CN=Schema,CN=Configuration,dc=MIODOMINIO,dc=LOCAL', 'mail' => 'john12@miodominio.it', 'objectclass'=>array( 'top', 'user', 'person', 'organizationalPerson' ), 'userPassword' => '{MD5}' . base64_encode(pack('H*',md5($newuser_plaintext_password))),
'samaccountname' => 'dddddd', 'displayname' => 'John12' ));
if ($r) { echo 'Success'; } else { $msg = "unable to ldap_add: "; echo $msg; echo "LDAP-Error: " . ldap_error($ldapconn) . "<br />\n"; echo ldap_errno($ldapconn) ; } ldap_close($ldapconn); }