]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
LDAP - Force protocol LDAPv3 1428/head
authorArthurHoaro <arthur.hoareau@wizacha.com>
Thu, 25 Jun 2020 14:18:25 +0000 (16:18 +0200)
committerArthurHoaro <arthur.hoareau@wizacha.com>
Thu, 25 Jun 2020 14:18:25 +0000 (16:18 +0200)
On Linux, php-ldap seems to rely on a library which still uses deprecated LDAPv2 as default version,
causing authentication issues.

See: https://stackoverflow.com/a/48238224/1484919

application/security/LoginManager.php

index 5f395a8717ad567f404947adb6f82b9fb369afea..39ec9b2e7fffa92688ab29dbc3e2a551a9b5967b 100644 (file)
@@ -204,12 +204,20 @@ class LoginManager
      */
     public function checkCredentialsFromLdap($login, $password, $connect = null, $bind = null)
     {
-        $connect = $connect ?? function($host) { return ldap_connect($host); };
-        $bind = $bind ?? function($handle, $dn, $password) { return ldap_bind($handle, $dn, $password); };
+        $connect = $connect ?? function($host) {
+            $resource = ldap_connect($host);
+
+            ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
+
+            return $resource;
+        };
+        $bind = $bind ?? function($handle, $dn, $password) {
+            return ldap_bind($handle, $dn, $password);
+        };
 
         return $bind(
             $connect($this->configManager->get('ldap.host')),
-            sprintf($this->configManager->get('ldap.dn'), $login), 
+            sprintf($this->configManager->get('ldap.dn'), $login),
             $password
         );
     }