From 2595b35cc2191d33a625d041f31c41ab23156185 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 25 Apr 2016 13:23:29 +0200 Subject: m_sasl Add ServerTracker class for tracking sasl_target --- src/modules/m_sasl.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 639fe6778..a6edb8b70 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -23,6 +23,68 @@ #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 { @@ -62,7 +124,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) @@ -280,6 +341,7 @@ class CommandSASL : public Command class ModuleSASL : public Module { SimpleExtItem authExt; + ServerTracker servertracker; SASLCap cap; CommandAuthenticate auth; CommandSASL sasl; @@ -288,6 +350,7 @@ class ModuleSASL : public Module public: ModuleSASL() : authExt("sasl_auth", ExtensionItem::EXT_USER, this) + , servertracker(this) , cap(this) , auth(this, authExt, cap) , sasl(this, authExt) @@ -305,6 +368,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 -- cgit v1.2.3