]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sasl.cpp
Bah
[user/henk/code/inspircd.git] / src / modules / m_sasl.cpp
index 89e8a379e14e593014f950f2c2c13e4ffdd74084..a035c8ec6341222a0c9263e33f813d0d5f363574 100644 (file)
@@ -23,7 +23,7 @@ enum SaslResult { SASL_OK, SASL_FAIL, SASL_ABORT };
 /**
  * Tracks SASL authentication state like charybdis does. --nenolod
  */
-class SaslAuthenticator
+class SaslAuthenticator : public classbase
 {
  private:
        InspIRCd *ServerInstance;
@@ -96,6 +96,12 @@ class SaslAuthenticator
                return this->state;
        }
 
+       void Abort(void)
+       {
+               this->state = SASL_DONE;
+               this->result = SASL_ABORT;
+       }
+
        bool SendClientMessage(const char* const* parameters, int pcnt)
        {
                if (this->state != SASL_COMM)
@@ -116,9 +122,7 @@ class SaslAuthenticator
 
                if (*parameters[0] == '*')
                {
-                       this->state = SASL_DONE;
-                       this->result = SASL_ABORT;
-
+                       this->Abort();
                        return false;
                }
 
@@ -133,13 +137,13 @@ class SaslAuthenticator
                switch (this->result)
                {
                 case SASL_OK:
-                       this->user->WriteServ("903 %s :SASL authentication successful", this->user->nick);
+                       this->user->WriteNumeric(903, "%s :SASL authentication successful", this->user->nick);
                        break;
                 case SASL_ABORT:
-                       this->user->WriteServ("906 %s :SASL authentication aborted", this->user->nick);
+                       this->user->WriteNumeric(906, "%s :SASL authentication aborted", this->user->nick);
                        break;
                 case SASL_FAIL:
-                       this->user->WriteServ("904 %s :SASL authentication failed", this->user->nick);
+                       this->user->WriteNumeric(904, "%s :SASL authentication failed", this->user->nick);
                        break;
                 default:
                        break;
@@ -191,8 +195,8 @@ class ModuleSASL : public Module
        ModuleSASL(InspIRCd* Me)
                : Module(Me)
        {
-               Implementation eventlist[] = { I_OnEvent, I_OnUserRegister, I_OnPostConnect };
-               ServerInstance->Modules->Attach(eventlist, this, 3);
+               Implementation eventlist[] = { I_OnEvent, I_OnUserRegister, I_OnPostConnect, I_OnUserDisconnect, I_OnCleanup };
+               ServerInstance->Modules->Attach(eventlist, this, 5);
 
                sasl = new CommandAuthenticate(ServerInstance, this);
                ServerInstance->AddCommand(sasl);
@@ -203,15 +207,33 @@ class ModuleSASL : public Module
 
        virtual int OnUserRegister(User *user)
        {
-               if (user->GetExt("sasl"))
+               SaslAuthenticator *sasl_;
+               if (user->GetExt("sasl_authenticator", sasl_))
                {
-                       user->WriteServ("906 %s :SASL authentication aborted", user->nick);
-                       user->Shrink("sasl");
+                       sasl_->Abort();
+                       delete sasl_;
+                       user->Shrink("sasl_authenticator");
                }
 
                return 0;
        }
 
+       virtual void OnCleanup(int target_type, void *item)
+       {
+               if (target_type == TYPE_USER)
+                       OnUserDisconnect((User*)item);
+       }
+
+       virtual void OnUserDisconnect(User *user)
+       {
+               SaslAuthenticator *sasl_;
+               if (user->GetExt("sasl_authenticator", sasl_))
+               {
+                       delete sasl_;
+                       user->Shrink("sasl_authenticator");
+               }
+       }
+
        virtual void OnPostConnect(User* user)
        {
                if (!IS_LOCAL(user))
@@ -266,7 +288,7 @@ class ModuleSASL : public Module
                        if (state == SASL_DONE)
                        {
                                delete sasl_;
-                               user->Shrink("sasl");
+                               target->Shrink("sasl");
                        }
                }
        }