+ bool SendClientMessage(const std::vector<std::string>& parameters)
+ {
+ if (this->state != SASL_COMM)
+ return true;
+
+ parameterlist params;
+ params.push_back(sasl_target);
+ params.push_back("SASL");
+ params.push_back(this->user->uuid);
+ params.push_back(this->agent);
+ params.push_back("C");
+
+ params.insert(params.end(), parameters.begin(), parameters.end());
+
+ SendSASL(params);
+
+ if (parameters[0][0] == '*')
+ {
+ this->Abort();
+ return false;
+ }
+
+ return true;
+ }
+
+ void AnnounceState(void)
+ {
+ if (this->state_announced)
+ return;
+
+ switch (this->result)
+ {
+ case SASL_OK:
+ this->user->WriteNumeric(903, "%s :SASL authentication successful", this->user->nick.c_str());
+ break;
+ case SASL_ABORT:
+ this->user->WriteNumeric(906, "%s :SASL authentication aborted", this->user->nick.c_str());
+ break;
+ case SASL_FAIL:
+ this->user->WriteNumeric(904, "%s :SASL authentication failed", this->user->nick.c_str());
+ break;
+ default:
+ break;
+ }
+
+ this->state_announced = true;
+ }
+};
+
+class CommandAuthenticate : public Command
+{
+ public:
+ SimpleExtItem<SaslAuthenticator>& authExt;
+ GenericCap& cap;
+ CommandAuthenticate(Module* Creator, SimpleExtItem<SaslAuthenticator>& ext, GenericCap& Cap)
+ : Command(Creator, "AUTHENTICATE", 1), authExt(ext), cap(Cap)
+ {
+ works_before_reg = true;
+ }
+
+ CmdResult Handle (const std::vector<std::string>& parameters, User *user)
+ {
+ /* Only allow AUTHENTICATE on unregistered clients */
+ if (user->registered != REG_ALL)
+ {
+ if (!cap.ext.get(user))
+ return CMD_FAILURE;
+
+ SaslAuthenticator *sasl = authExt.get(user);
+ if (!sasl)
+ authExt.set(user, new SaslAuthenticator(user, parameters[0], creator));
+ else if (sasl->SendClientMessage(parameters) == false) // IAL abort extension --nenolod
+ {
+ sasl->AnnounceState();
+ authExt.unset(user);