diff --git a/inc/inc.ClassLdapAuthentication.php b/inc/inc.ClassLdapAuthentication.php index 64995f8e6..8f4928d7d 100644 --- a/inc/inc.ClassLdapAuthentication.php +++ b/inc/inc.ClassLdapAuthentication.php @@ -115,35 +115,54 @@ class SeedDMS_LdapAuthentication extends SeedDMS_Authentication { $dn = $tmpDN; } - /* Now do the actual authentication of the user */ - $bind = @ldap_bind($ds, $dn, $password); + /* Check if user already exists in the database. Return with an error + * only if the sql statements fails, but not if no user was found. + */ $user = $dms->getUserByLogin($username); if($user === false) { ldap_close($ds); return false; } - if ($bind) { - // Successfully authenticated. Now check to see if the user exists within - // the database. If not, add them in if _restricted is not set, - // but do not add their password. - if (is_null($user) && !$settings->_restricted) { - // Retrieve the user's LDAP information. - if (isset($settings->_ldapFilter) && strlen($settings->_ldapFilter) > 0) { - $search = ldap_search($ds, $settings->_ldapBaseDN, "(&(".$ldapSearchAttribut.$username.")".$settings->_ldapFilter.")"); - } else { - $search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut.$username); - } - if (!is_bool($search)) { - $info = ldap_get_entries($ds, $search); + /* Now do the actual authentication of the user */ + $bind = @ldap_bind($ds, $dn, $password); + if (!$bind) { + ldap_close($ds); + return false; + } +<<<<<<< Updated upstream if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) { $user = $dms->addUser($username, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "", 0); +======= + // Successfully authenticated. Now check to see if the user exists within + // the database. If not, add them in if _restricted is not set, + // but do not add their password. + if (!$settings->_restricted) { + // Retrieve the user's LDAP information. + if (isset($settings->_ldapFilter) && strlen($settings->_ldapFilter) > 0) { + $search = ldap_search($ds, $settings->_ldapBaseDN, "(&(".$ldapSearchAttribut.$username.")".$settings->_ldapFilter.")"); + } else { + $search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut.$username); + } + + if (!is_bool($search)) { + $info = ldap_get_entries($ds, $search); + + if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) { + if (is_null($user)) { + $user = $dms->addUser($username, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "", 3); + } else { + if(isset($info[0]['cn'][0]) && ($info[0]['cn'][0] != $user->getFullName())) { + $user->setFullName($info[0]['cn'][0]); + } + if(isset($info[0]['mail'][0]) && ($info[0]['mail'][0] != $user->getEmail())) { + $user->setEmail($info[0]['mail'][0]); + } +>>>>>>> Stashed changes } } } - } elseif($user) { - $user = false; } ldap_close($ds);