]> 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 87d87d9782f10ddebe8888a1b49ba6a5ca98476c..48da83aaded67039cacf290c1706768b8ca33581 100644 (file)
@@ -19,8 +19,9 @@
 
 class CommandAuthenticate : public Command
 {
+       Module* Creator;
  public:
-       CommandAuthenticate (InspIRCd* Instance) : Command(Instance,"AUTHENTICATE", 0, 1)
+       CommandAuthenticate (InspIRCd* Instance, Module* creator) : Command(Instance,"AUTHENTICATE", 0, 1, true), Creator(creator)
        {
                this->source = "m_sasl.so";
        }
@@ -29,11 +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("*");
-                       for (int i = 0; i < pcnt; ++i)
-                               params.push_back(parameters[0]);
+                       /* 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]);
+
+                               Event e((char*)&params, Creator, "send_encap");
+                               e.Send(ServerInstance);
+                       }
                }
                return CMD_FAILURE;
        }
@@ -43,18 +54,29 @@ class CommandAuthenticate : public Command
 class ModuleSASL : public Module
 {
        CommandAuthenticate* sasl;
-
  public:
        
        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);
 
-               sasl = new CommandAuthenticate(ServerInstance);
+               if (!ServerInstance->Modules->Find("m_services_account.so") || !ServerInstance->Modules->Find("m_cap.so"))
+                       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()
        {
@@ -87,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");
+                       }
                }
        }
 };