summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-04-25 13:23:29 +0200
committerAttila Molnar <attilamolnar@hush.com>2016-04-25 13:23:29 +0200
commit2595b35cc2191d33a625d041f31c41ab23156185 (patch)
treea3fcc4e0b4f3c0d8b5448c08a863c5a842b55baa /src
parentafefc6bfe9e184086247fc305a41ef1c21cb136b (diff)
m_sasl Add ServerTracker class for tracking sasl_target
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_sasl.cpp66
1 files changed, 65 insertions, 1 deletions
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<SaslAuthenticator> 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