diff --git a/htdocs/admin/ldap.php b/htdocs/admin/ldap.php index 22aa0346940..30932ecadd0 100644 --- a/htdocs/admin/ldap.php +++ b/htdocs/admin/ldap.php @@ -48,7 +48,7 @@ if ($action == 'setvalue' && $user->admin) $db->begin(); if (! dolibarr_set_const($db, 'LDAP_SERVER_TYPE',GETPOST("type"),'chaine',0,'',$conf->entity)) $error++; - if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',GETPOST("version"),'chaine',0,'',$conf->entity)) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',GETPOST("LDAP_SERVER_PROTOCOLVERSION"),'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST',GETPOST("host"),'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST_SLAVE',GETPOST("slave"),'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_SERVER_PORT',GETPOST("port"),'chaine',0,'',$conf->entity)) $error++; @@ -169,7 +169,7 @@ print ''.$langs->trans("Version").''; $arraylist=array(); $arraylist['3']='Version 3'; $arraylist['2']='Version 2'; -print $form->selectarray('version',$arraylist,$conf->global->LDAP_SERVER_PROTOCOLVERSION); +print $form->selectarray('LDAP_SERVER_PROTOCOLVERSION',$arraylist,$conf->global->LDAP_SERVER_PROTOCOLVERSION); print ''.$langs->trans("LDAPServerProtocolVersion").''; // Serveur primaire diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index de270b12964..03929787560 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -207,7 +207,7 @@ class Ldap $this->connection = ldap_connect($host,$this->serverPort); } - if ($this->connection) + if (is_resource($this->connection)) { $this->setVersion(); @@ -274,9 +274,9 @@ class Ldap } else { - $this->error='Failed to connect to LDAP'; + $this->error='Failed to connect to LDAP'.($this->error?': '.$this->error:''); $return=-1; - dol_syslog("Ldap::connect_bind return=".$return, LOG_WARNING); + dol_syslog("Ldap::connect_bind return=".$return.' - '.$this->error, LOG_WARNING); } return $return; } diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php index bf216533e17..e3137a8afa6 100644 --- a/htdocs/core/login/functions_ldap.php +++ b/htdocs/core/login/functions_ldap.php @@ -85,8 +85,8 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) { dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType); dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword); - print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."\n"; - print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."\n"; + print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."
\n"; + print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."
\n"; } $resultFetchLdapUser=0; @@ -104,7 +104,7 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) if ($ldapadminlogin) { $result=$ldap->connect_bind(); - if ($result) + if ($result > 0) { $resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter); //dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser); @@ -119,6 +119,10 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) return ''; } } + else + { + if ($ldapdebug) print "DEBUG: ".$ldap->error."
\n"; + } $ldap->close(); } @@ -191,11 +195,11 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) ** 53 - Account inactive (manually locked out by administrator) */ dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'"); - if ($this->connection) // If connection ok but bind ko + if (is_resource($ldap->connection)) // If connection ok but bind ko { - $this->ldapErrorCode = ldap_errno($this->connection); - $this->ldapErrorText = ldap_error($this->connection); - dol_syslog("unctions_ldap::check_user_password_ldap ".$this->ldapErrorText); + $ldap->ldapErrorCode = ldap_errno($ldap->connection); + $ldap->ldapErrorText = ldap_error($ldap->connection); + dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorText); } sleep(1); $langs->load('main'); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 1e51ed10c9d..d9af596911e 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1882,8 +1882,10 @@ class User extends CommonObject $this->ref = 'SPECIMEN'; $this->specimen=1; - $this->nom='DOLIBARR'; - $this->prenom='SPECIMEN'; + $this->nom='DOLIBARR'; // deprecated + $this->prenom='SPECIMEN'; // deprecated + $this->lastname='DOLIBARR'; + $this->firstname='SPECIMEN'; $this->note='This is a note'; $this->email='email@specimen.com'; $this->office_phone='0999999999'; diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 64e458f21cc..3453f4fa379 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -683,19 +683,18 @@ class UserGroup extends CommonObject if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS) { $valueofldapfield=array(); - foreach($this->members as $key=>$val) + foreach($this->members as $key=>$val) // This is array of users for group into dolibarr database. { $muser=new User($this->db); - $muser->fetch($val); - - $ldapuserid=$muser->login; - // TODO ldapuserid should depends on value $conf->global->LDAP_KEY_USERS; + $muser->fetch($val->id); + if ($conf->global->LDAP_KEY_USERS == 'cn') $ldapuserid=$muser->getFullName($langs); + elseif ($conf->global->LDAP_KEY_USERS == 'sn') $ldapuserid=$muser->lastname; + elseif ($conf->global->LDAP_KEY_USERS == 'uid') $ldapuserid=$muser->login; $valueofldapfield[] = $conf->global->LDAP_KEY_USERS.'='.$ldapuserid.','.$conf->global->LDAP_USER_DN; } $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield)?$valueofldapfield:''); } - return $info; } diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php index 69d21031574..5bfc3b6a9af 100644 --- a/htdocs/user/group/ldap.php +++ b/htdocs/user/group/ldap.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2006-2012 Laurent Destailleur * Copyright (C) 2006-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -179,7 +179,7 @@ if ($result > 0) //var_dump($records); // Affichage arbre - if (count($records) && (! isset($records['count']) || $records['count'] > 0)) + if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0)) { if (! is_array($records)) {