]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sasl.cpp
Add 906, sasl aborted
[user/henk/code/inspircd.git] / src / modules / m_sasl.cpp
index fda574fb258f180aeb78147bf594ed17fe38b55c..48da83aaded67039cacf290c1706768b8ca33581 100644 (file)
@@ -30,17 +30,21 @@ class CommandAuthenticate : public Command
        {
                if (user->registered != REG_ALL)
                {
-                       /* Only allow AUTHENTICATE on unregistered clients */
-                       std::deque<std::string> params;
-                       params.push_back("*");
-                       params.push_back("AUTHENTICATE");
-                       params.push_back(user->uuid);
+                       /* Only act if theyve enabled CAP REQ sasl */
+                       if (user->GetExt("sasl"))
+                       {
+                               /* Only allow AUTHENTICATE on unregistered clients */
+                               std::deque<std::string> params;
+                               params.push_back("*");
+                               params.push_back("AUTHENTICATE");
+                               params.push_back(user->uuid);
 
-                       for (int i = 0; i < pcnt; ++i)
-                               params.push_back(parameters[i]);
+                               for (int i = 0; i < pcnt; ++i)
+                                       params.push_back(parameters[i]);
 
-                       Event e((char*)&params, Creator, "send_encap");
-                       e.Send(ServerInstance);
+                               Event e((char*)&params, Creator, "send_encap");
+                               e.Send(ServerInstance);
+                       }
                }
                return CMD_FAILURE;
        }
@@ -55,8 +59,8 @@ class ModuleSASL : public Module
        ModuleSASL(InspIRCd* Me)
                : Module(Me)
        {
-               Implementation eventlist[] = { I_OnEvent };
-               ServerInstance->Modules->Attach(eventlist, this, 1);
+               Implementation eventlist[] = { I_OnEvent, I_OnUserRegister };
+               ServerInstance->Modules->Attach(eventlist, this, 2);
 
                sasl = new CommandAuthenticate(ServerInstance, this);
                ServerInstance->AddCommand(sasl);
@@ -65,6 +69,14 @@ class ModuleSASL : public Module
                        ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!");
        }
 
+       virtual int OnUserRegister(User *user)
+       {
+               if (user->GetExt("sasl"))
+               {
+                       user->WriteServ("906 %s :SASL authentication aborted", user->nick);
+                       user->Shrink("sasl");
+               }
+       }
 
        virtual ~ModuleSASL()
        {
@@ -97,7 +109,12 @@ class ModuleSASL : public Module
                else if (ev->GetEventID() == "account_login")
                {
                        AccountData* ac = (AccountData*)ev->GetData();
-                       ac->user->WriteServ("903 %s :SASL authentication successful", ac->user->nick);
+
+                       if (ac->user->GetExt("sasl"))
+                       {
+                               ac->user->WriteServ("903 %s :SASL authentication successful", ac->user->nick);
+                               ac->user->Shrink("sasl");
+                       }
                }
        }
 };