]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ldapauth.cpp
Add initial query support to m_mysql [patch by Athenon]
[user/henk/code/inspircd.git] / src / modules / extra / m_ldapauth.cpp
index b95d32b18ed82effd4f2ec996333b25ddea95c31..8ffccd8632e3d6d873e6644074f5c04987578e08 100644 (file)
@@ -111,20 +111,20 @@ public:
                return true;
        }
 
-       virtual int OnUserRegister(User* user)
+       virtual ModResult OnUserRegister(User* user)
        {
                if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern)))
                {
                        user->Extend("ldapauthed");
-                       return 0;
+                       return MOD_RES_PASSTHRU;
                }
 
                if (!CheckCredentials(user))
                {
                        ServerInstance->Users->QuitUser(user, killreason);
-                       return 1;
+                       return MOD_RES_DENY;
                }
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 
        bool CheckCredentials(User* user)
@@ -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);
 
@@ -205,9 +217,9 @@ public:
                user->Shrink("ldapauth_failed");
        }
 
-       virtual bool OnCheckReady(User* user)
+       virtual ModResult OnCheckReady(User* user)
        {
-               return user->GetExt("ldapauthed");
+               return user->GetExt("ldapauthed") ? MOD_RES_PASSTHRU : MOD_RES_DENY;
        }
 
        virtual Version GetVersion()