Crivaledaz / Mattermost-LDAP

This module provides an external LDAP authentication in Mattermost for the Team Edition (free).
MIT License
359 stars 71 forks source link

Unable to bind to server: Protocol error #14

Closed Rudloff closed 6 years ago

Rudloff commented 6 years ago

Hello,

I get this error when trying to login:

[Tue Nov 14 17:07:50.858965 2017] [:error] [pid 8201] [client 2a01:e35:2428:cf30:59ad:a05:3756:46c2:45036] PHP Warning:  ldap_bind(): Unable to bind to server: Protocol error in /home/tools/Mattermost-LDAP/oauth/LDAP/LDAP.php on line 98, referer: https://tools.animafac.net/mattermost-ldap/oauth/index.php

This fixes the issue:

diff --git a/oauth/LDAP/LDAP.php b/oauth/LDAP/LDAP.php
index f1e3fbc..777d3dd 100755
--- a/oauth/LDAP/LDAP.php
+++ b/oauth/LDAP/LDAP.php
@@ -39,6 +39,7 @@ class LDAP implements LDAPInterface
                or die("Unable to connect to the ldap server : $ldaphost ! Please check your configuration.");

         $this->ldap_server = $ldap;
+        ldap_set_option($this->ldap_server, LDAP_OPT_PROTOCOL_VERSION, 3);
     }

      /**

I'm not sure if it applies to every LDAP server, maybe it needs to be added as an option.

Crivaledaz commented 6 years ago

Hi,

According to the documentation, the LDAP_OPT_PROTOCOL_VERSION option is used to specify the LDAP version of your LDAP server. Thus, the line you have added set the version to 3, but there is many companies which still use LDAP V2.

So, your issue is interesting and certainly this will help some user who encounter this error, but for this moment, I don't think I will add this line in the LDAP class. If many user alert me about this problem, I will reconsider your patch.

I will see if I can create an option in the ldap configuration file, but currently I am a little bit busy. Feel free to suggest a pull request ;).

Thank you very much for your contribution, I hope you succeeded to set up Mattermost-LDAP.

Regards

Crivaledaz commented 6 years ago

Hi,

Finally change my mind. I have included a version option in the last version. Thus, you can precise the version in config_ldap.php file and the LDAP class set the LDAP_OPT_PROTOCOL_VERSION automatically after ldap_connect. I hope this feature will help.

Thank you for your contribution.