NobGit
public nobgit read

NobMail

Based on mailcow: dockerized

Languages

Repository composition by tracked source files.

PHP
PHP 49% JavaScript 35% HTML 9% CSS 4% Shell 2% Python 1% Lua 0% Perl 0% Ruby 0% SCSS 0%
Create file Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git

Commit

Use DN instead of DistinguishedName for LDAP login

fa3c453d
FreddleSpl0it <[email protected]> 1 year, 11 months ago
data/web/inc/functions.auth.inc.php | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

Diff

diff --git a/data/web/inc/functions.auth.inc.php b/data/web/inc/functions.auth.inc.php
index f93eb54c..943bb164 100644
--- a/data/web/inc/functions.auth.inc.php
+++ b/data/web/inc/functions.auth.inc.php
@@ -498,7 +498,7 @@ function ldap_mbox_login($user, $pass, $iam_settings, $extra = null){
       $ldap_query = $ldap_query->rawFilter($iam_settings['filter']);
     }
     $ldap_query = $ldap_query->where($iam_settings['username_field'], '=', $user)
-      ->select([$iam_settings['username_field'], $iam_settings['attribute_field'], 'displayname', 'distinguishedname', 'cn']);
+      ->select([$iam_settings['username_field'], $iam_settings['attribute_field'], 'displayname', 'distinguishedname', 'dn']);
 
     $user_res = $ldap_query->firstOrFail();
   } catch (Exception $e) {
@@ -506,29 +506,26 @@ function ldap_mbox_login($user, $pass, $iam_settings, $extra = null){
     $_SESSION['return'] = array();
     $_SESSION['return'][] =  array(
       'type' => 'danger',
-      'log' => array(__FUNCTION__, $user, '*'),
+      'log' => array(__FUNCTION__, $user, '*', $e->getMessage()),
       'msg' => 'ldap_error'
     );
     return false;
   }
   try {
-    if (!$iam_provider->auth()->attempt($user_res['distinguishedname'][0], $pass)) {
-      // fallback to cn
-      if (!$iam_provider->auth()->attempt($user_res['cn'][0], $pass)) {
-        $_SESSION['return'][] =  array(
-          'type' => 'danger',
-          'log' => array(__FUNCTION__, $user, '*', $user_res),
-          'msg' => 'ldap_auth_failed'
-        );
-        return false;
-      }
+    if (!$iam_provider->auth()->attempt($user_res['dn'], $pass)) {
+      $_SESSION['return'][] =  array(
+        'type' => 'danger',
+        'log' => array(__FUNCTION__, $user, '*', $user_res),
+        'msg' => 'ldap_auth_failed'
+      );
+      return false;
     }
   } catch (Exception $e) {
     // clear $_SESSION['return'] to not leak data
     $_SESSION['return'] = array();
     $_SESSION['return'][] =  array(
       'type' => 'danger',
-      'log' => array(__FUNCTION__, $user, '*'),
+      'log' => array(__FUNCTION__, $user, '*', $e->getMessage()),
       'msg' => 'ldap_error'
     );
     return false;