/**
* Tracks SASL authentication state like charybdis does. --nenolod
*/
-class SaslAuthenticator
+class SaslAuthenticator : public classbase
{
private:
InspIRCd *ServerInstance;
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)
if (*parameters[0] == '*')
{
- this->state = SASL_DONE;
- this->result = SASL_ABORT;
-
+ this->Abort();
return false;
}
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;
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);
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))
if (state == SASL_DONE)
{
delete sasl_;
- user->Shrink("sasl");
+ target->Shrink("sasl");
}
}
}