+ return SASL_OK;
+ }
+
+ /* checks for and deals with a state change. */
+ SaslState ProcessInboundMessage(const std::vector<std::string> &msg)
+ {
+ switch (this->state)
+ {
+ case SASL_INIT:
+ this->agent = msg[0];
+ this->state = SASL_COMM;
+ /* fall through */
+ case SASL_COMM:
+ if (msg[0] != this->agent)
+ return this->state;
+
+ if (msg[2] == "C")
+ this->user->Write("AUTHENTICATE %s", msg[3].c_str());
+ else if (msg[2] == "D")
+ {
+ this->state = SASL_DONE;
+ this->result = this->GetSaslResult(msg[3]);
+ }
+ else if (msg[2] == "M")
+ this->user->WriteNumeric(908, "%s %s :are available SASL mechanisms", this->user->nick.c_str(), msg[3].c_str());
+ else
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Services sent an unknown SASL message \"%s\" \"%s\"", msg[2].c_str(), msg[3].c_str());
+
+ break;
+ case SASL_DONE:
+ break;
+ default:
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "WTF: SaslState is not a known state (%d)", this->state);
+ break;
+ }
+
+ return this->state;
+ }
+
+ void Abort(void)
+ {
+ this->state = SASL_DONE;
+ this->result = SASL_ABORT;
+ }
+
+ bool SendClientMessage(const std::vector<std::string>& parameters)
+ {
+ if (this->state != SASL_COMM)
+ return true;
+
+ parameterlist params;
+ 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, ":SASL authentication successful");
+ break;
+ case SASL_ABORT:
+ this->user->WriteNumeric(906, ":SASL authentication aborted");
+ break;
+ case SASL_FAIL:
+ this->user->WriteNumeric(904, ":SASL authentication failed");
+ break;
+ default:
+ break;
+ }
+
+ this->state_announced = true;
+ }
+};