X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_sasl.cpp;h=02a302c11cacd46d1d660a792745fcffc9efdf04;hb=f9fd78c01623514a060c607534fc52cb73140200;hp=d7c97c835b0f8579c6d741a030e0c7cb2676c5e1;hpb=6352a6f9c9685c32ec17a7d6f9f89df0e3ec3054;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index d7c97c835..02a302c11 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -23,10 +23,73 @@ #include "modules/account.h" #include "modules/sasl.h" #include "modules/ssl.h" +#include "modules/spanningtree.h" + +static std::string sasl_target; + +class ServerTracker : public SpanningTreeEventListener +{ + bool online; + + void Update(const Server* server, bool linked) + { + if (sasl_target == "*") + return; + + if (InspIRCd::Match(server->GetName(), sasl_target)) + { + ServerInstance->Logs->Log(MODNAME, LOG_VERBOSE, "SASL target server \"%s\" %s", sasl_target.c_str(), (linked ? "came online" : "went offline")); + online = linked; + } + } + + void OnServerLink(const Server* server) CXX11_OVERRIDE + { + Update(server, true); + } + + void OnServerSplit(const Server* server) CXX11_OVERRIDE + { + Update(server, false); + } + + public: + ServerTracker(Module* mod) + : SpanningTreeEventListener(mod) + { + Reset(); + } + + void Reset() + { + if (sasl_target == "*") + { + online = true; + return; + } + + online = false; + + ProtocolInterface::ServerList servers; + ServerInstance->PI->GetServerList(servers); + for (ProtocolInterface::ServerList::const_iterator i = servers.begin(); i != servers.end(); ++i) + { + const ProtocolInterface::ServerInfo& server = *i; + if (InspIRCd::Match(server.servername, sasl_target)) + { + online = true; + break; + } + } + } + + bool IsOnline() const { return online; } +}; class SASLCap : public Cap::Capability { std::string mechlist; + const ServerTracker& servertracker; bool OnRequest(LocalUser* user, bool adding) CXX11_OVERRIDE { @@ -38,14 +101,20 @@ class SASLCap : public Cap::Capability return (user->registered != REG_ALL); } + bool OnList(LocalUser* user) CXX11_OVERRIDE + { + return servertracker.IsOnline(); + } + const std::string* GetValue(LocalUser* user) const CXX11_OVERRIDE { return &mechlist; } public: - SASLCap(Module* mod) + SASLCap(Module* mod, const ServerTracker& tracker) : Cap::Capability(mod, "sasl") + , servertracker(tracker) { } @@ -62,7 +131,6 @@ class SASLCap : public Cap::Capability enum SaslState { SASL_INIT, SASL_COMM, SASL_DONE }; enum SaslResult { SASL_OK, SASL_FAIL, SASL_ABORT }; -static std::string sasl_target = "*"; static Events::ModuleEventProvider* saslevprov; static void SendSASL(const parameterlist& params) @@ -142,7 +210,7 @@ class SaslAuthenticator 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()); + this->user->WriteNumeric(908, msg[3], "are available SASL mechanisms"); else ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Services sent an unknown SASL message \"%s\" \"%s\"", msg[2].c_str(), msg[3].c_str()); @@ -194,13 +262,13 @@ class SaslAuthenticator switch (this->result) { case SASL_OK: - this->user->WriteNumeric(903, ":SASL authentication successful"); + this->user->WriteNumeric(903, "SASL authentication successful"); break; case SASL_ABORT: - this->user->WriteNumeric(906, ":SASL authentication aborted"); + this->user->WriteNumeric(906, "SASL authentication aborted"); break; case SASL_FAIL: - this->user->WriteNumeric(904, ":SASL authentication failed"); + this->user->WriteNumeric(904, "SASL authentication failed"); break; default: break; @@ -223,8 +291,6 @@ class CommandAuthenticate : public Command CmdResult Handle (const std::vector& parameters, User *user) { - /* Only allow AUTHENTICATE on unregistered clients */ - if (user->registered != REG_ALL) { if (!cap.get(user)) return CMD_FAILURE; @@ -282,6 +348,7 @@ class CommandSASL : public Command class ModuleSASL : public Module { SimpleExtItem authExt; + ServerTracker servertracker; SASLCap cap; CommandAuthenticate auth; CommandSASL sasl; @@ -290,7 +357,8 @@ class ModuleSASL : public Module public: ModuleSASL() : authExt("sasl_auth", ExtensionItem::EXT_USER, this) - , cap(this) + , servertracker(this) + , cap(this, servertracker) , auth(this, authExt, cap) , sasl(this, authExt) , sasleventprov(this, "event/sasl") @@ -307,6 +375,7 @@ class ModuleSASL : public Module void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { sasl_target = ServerInstance->Config->ConfValue("sasl")->getString("target", "*"); + servertracker.Reset(); } ModResult OnUserRegister(LocalUser *user) CXX11_OVERRIDE