CDash icon indicating copy to clipboard operation
CDash copied to clipboard

please add uid and email based LDAP login

Open szjozsef opened this issue 6 years ago • 0 comments

Hello with this small change you can enable both email and user based LDAP authentication at the same time.

include/login_functions.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/login_functions.php b/include/login_functions.php
index 7a156efa..c2744246 100644
--- a/include/login_functions.php
+++ b/include/login_functions.php
@@ -175,7 +175,7 @@ function ldapAuthenticate($email, $password, $SessionCachePolicy, $rememberme)
     if (isset($ldap) && $ldap != '') {
         /* search for pid dn */
         $result = ldap_search($ldap, $config->get('CDASH_LDAP_BASEDN'),
-            '(&(mail=' . $email . ')' . $config->get('CDASH_LDAP_FILTER') . ')', array('dn', 'cn'));
+            '(&(|(mail=' . $email . ')(uid=' . $email . '))' . $config->get('CDASH_LDAP_FILTER') . ')', array('dn', 'cn', 'mail'));
         if ($result != 0) {
             $entries = ldap_get_entries($ldap, $result);
             @$principal = $entries[0]['dn'];
@@ -183,6 +183,7 @@ function ldapAuthenticate($email, $password, $SessionCachePolicy, $rememberme)
                 // bind as this user
                 if (@ldap_bind($ldap, $principal, $password) and strlen(trim($password)) != 0) {
                     $user = new User();
+                    $email = $entries[0]['mail'][0];
                     $userid = $user->GetIdFromEmail($email);
 
                     // If the user doesn't exist we add it

Thanks !

szjozsef avatar Apr 11 '19 05:04 szjozsef