#include "modules/account.h"
#include "modules/sasl.h"
#include "modules/ssl.h"
-#include "modules/spanningtree.h"
+#include "modules/server.h"
enum
{
static std::string sasl_target;
-class ServerTracker : public SpanningTreeEventListener
+class ServerTracker : public ServerEventListener
{
bool online;
public:
ServerTracker(Module* mod)
- : SpanningTreeEventListener(mod)
+ : ServerEventListener(mod)
{
Reset();
}
static Events::ModuleEventProvider* saslevprov;
-static void SendSASL(const parameterlist& params)
+static void SendSASL(LocalUser* user, const std::string& agent, char mode, const std::vector<std::string>& parameters)
{
+ CommandBase::Params params;
+ params.push_back(user->uuid);
+ params.push_back(agent);
+ params.push_back(ConvToStr(mode));
+ params.insert(params.end(), parameters.begin(), parameters.end());
+
if (!ServerInstance->PI->SendEncapsulatedData(sasl_target, "SASL", params))
{
FOREACH_MOD_CUSTOM(*saslevprov, SASLEventListener, OnSASLAuth, (params));
}
}
+static ClientProtocol::EventProvider* g_protoev;
+
/**
* Tracks SASL authentication state like charybdis does. --nenolod
*/
SaslResult result;
bool state_announced;
- void SendHostIP()
+ void SendHostIP(UserCertificateAPI& sslapi)
{
- parameterlist params;
- params.push_back(sasl_target);
- params.push_back("SASL");
- params.push_back(user->uuid);
- params.push_back("*");
- params.push_back("H");
- params.push_back(user->host);
+ std::vector<std::string> params;
+ params.push_back(user->GetRealHost());
params.push_back(user->GetIPString());
+ params.push_back(sslapi && sslapi->GetCertificate(user) ? "S" : "P");
- SendSASL(params);
+ SendSASL(user, "*", 'H', params);
}
public:
- SaslAuthenticator(LocalUser* user_, const std::string& method)
- : user(user_), state(SASL_INIT), state_announced(false)
+ SaslAuthenticator(LocalUser* user_, const std::string& method, UserCertificateAPI& sslapi)
+ : user(user_)
+ , state(SASL_INIT)
+ , state_announced(false)
{
- SendHostIP();
+ SendHostIP(sslapi);
- parameterlist params;
- params.push_back(user->uuid);
- params.push_back("*");
- params.push_back("S");
+ std::vector<std::string> params;
params.push_back(method);
- const std::string fp = SSLClientCert::GetFingerprint(&user->eh);
+ const std::string fp = sslapi ? sslapi->GetFingerprint(user) : "";
if (fp.size())
params.push_back(fp);
- SendSASL(params);
+ SendSASL(user, "*", 'S', params);
}
SaslResult GetSaslResult(const std::string &result_)
}
/* checks for and deals with a state change. */
- SaslState ProcessInboundMessage(const std::vector<std::string> &msg)
+ SaslState ProcessInboundMessage(const CommandBase::Params& msg)
{
switch (this->state)
{
return this->state;
if (msg[2] == "C")
- this->user->Write("AUTHENTICATE %s", msg[3].c_str());
+ {
+ ClientProtocol::Message authmsg("AUTHENTICATE");
+ authmsg.PushParamRef(msg[3]);
+
+ ClientProtocol::Event authevent(*g_protoev, authmsg);
+ LocalUser* const localuser = IS_LOCAL(user);
+ if (localuser)
+ localuser->Send(authevent);
+ }
else if (msg[2] == "D")
{
this->state = SASL_DONE;
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);
+ SendSASL(this->user, this->agent, 'C', parameters);
if (parameters[0].c_str()[0] == '*')
{
public:
SimpleExtItem<SaslAuthenticator>& authExt;
Cap::Capability& cap;
+ UserCertificateAPI sslapi;
+
CommandAuthenticate(Module* Creator, SimpleExtItem<SaslAuthenticator>& ext, Cap::Capability& Cap)
: SplitCommand(Creator, "AUTHENTICATE", 1)
, authExt(ext)
, cap(Cap)
+ , sslapi(Creator)
{
works_before_reg = true;
allow_empty_last_param = false;
}
- CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
+ CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
{
{
if (!cap.get(user))
SaslAuthenticator *sasl = authExt.get(user);
if (!sasl)
- authExt.set(user, new SaslAuthenticator(user, parameters[0]));
+ authExt.set(user, new SaslAuthenticator(user, parameters[0], sslapi));
else if (sasl->SendClientMessage(parameters) == false) // IAL abort extension --nenolod
{
sasl->AnnounceState();
this->flags_needed = FLAG_SERVERONLY; // should not be called by users
}
- CmdResult Handle(const std::vector<std::string>& parameters, User *user)
+ CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
{
User* target = ServerInstance->FindUUID(parameters[1]);
if (!target)
return CMD_SUCCESS;
}
- RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+ RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
{
return ROUTE_BROADCAST;
}
CommandAuthenticate auth;
CommandSASL sasl;
Events::ModuleEventProvider sasleventprov;
+ ClientProtocol::EventProvider protoev;
public:
ModuleSASL()
, auth(this, authExt, cap)
, sasl(this, authExt)
, sasleventprov(this, "event/sasl")
+ , protoev(this, auth.name)
{
saslevprov = &sasleventprov;
+ g_protoev = &protoev;
}
void init() CXX11_OVERRIDE
void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
{
- sasl_target = ServerInstance->Config->ConfValue("sasl")->getString("target", "*");
+ std::string target = ServerInstance->Config->ConfValue("sasl")->getString("target");
+ if (target.empty())
+ throw ModuleException("<sasl:target> must be set to the name of your services server!");
+
+ sasl_target = target;
servertracker.Reset();
}