]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ldapauth.cpp
Add Module* creator to Command and ModeHandler
[user/henk/code/inspircd.git] / src / modules / extra / m_ldapauth.cpp
index c4f04ee4a70c4b050ec60863b1ebe469c99f3b11..94c0df469386416028ab87f299dab45ebccb6b13 100644 (file)
@@ -52,7 +52,7 @@ public:
                conn = NULL;
                Implementation eventlist[] = { I_OnUserDisconnect, I_OnCheckReady, I_OnRehash, I_OnUserRegister };
                ServerInstance->Modules->Attach(eventlist, this, 4);
-               OnRehash(NULL,"");
+               OnRehash(NULL);
        }
 
        virtual ~ModuleLDAPAuth()
@@ -61,7 +61,7 @@ public:
                        ldap_unbind_ext(conn, NULL, NULL);
        }
 
-       virtual void OnRehash(User* user, const std::string &parameter)
+       virtual void OnRehash(User* user)
        {
                ConfigReader Conf(ServerInstance);
 
@@ -142,12 +142,24 @@ public:
 
                if ((res = ldap_sasl_bind_s(conn, username.c_str(), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL)) != LDAP_SUCCESS)
                {
-                       free(authpass);
-                       if (verbose)
-                               ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (LDAP bind failed: %s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), ldap_err2string(res));
-                       ldap_unbind_ext(conn, NULL, NULL);
-                       conn = NULL;
-                       return false;
+                       if (res == LDAP_SERVER_DOWN)
+                       {
+                               // Attempt to reconnect if the connection dropped
+                               if (verbose)
+                                       ServerInstance->SNO->WriteToSnoMask('a', "LDAP server has gone away - reconnecting...");
+                               Connect();
+                               res = ldap_sasl_bind_s(conn, username.c_str(), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
+                       }
+
+                       if (res != LDAP_SUCCESS)
+                       {
+                               if (verbose)
+                                       ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (LDAP bind failed: %s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), ldap_err2string(res));
+                               free(authpass);
+                               ldap_unbind_ext(conn, NULL, NULL);
+                               conn = NULL;
+                               return false;
+                       }
                }
                free(authpass);