From 657fcc1f6bcb025e7659577b13afdf4d88cce8a5 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 25 Apr 2016 13:15:06 +0200 Subject: m_spanningtree Call the OnServerSplit hook from the OnUnloadModule() handler on unload --- src/modules/m_spanningtree/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 5b3f9c0bb..0b9bb65df 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -25,6 +25,7 @@ #include "socket.h" #include "xline.h" #include "iohook.h" +#include "modules/spanningtree.h" #include "resolvers.h" #include "main.h" @@ -613,6 +614,21 @@ void ModuleSpanningTree::OnUnloadModule(Module* mod) return; ServerInstance->PI->SendMetaData("modules", "-" + mod->ModuleSourceFile); + if (mod == this) + { + // We are being unloaded, inform modules about all servers splitting which cannot be done later when the servers are actually disconnected + const server_hash& servers = Utils->serverlist; + for (server_hash::const_iterator i = servers.begin(); i != servers.end(); ++i) + { + TreeServer* server = i->second; + if (!server->IsRoot()) + FOREACH_MOD_CUSTOM(GetEventProvider(), SpanningTreeEventListener, OnServerSplit, (server)); + } + return; + } + + // Some other module is being unloaded. If it provides an IOHook we use, we must close that server connection now. + restart: // Close all connections which use an IO hook provided by this module const TreeServer::ChildServers& list = Utils->TreeRoot->GetChildren(); -- cgit v1.2.3 From 70ac122cba5c6a1df2b3ee29305d9a48098e7940 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 25 Apr 2016 13:16:40 +0200 Subject: m_spanningtree Call the OnServerSplit hook from TreeServer::SQuitInternal() so it runs for all lost servers --- src/modules/m_spanningtree/treeserver.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 1fc9455b0..b3430e1ab 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -159,8 +159,6 @@ void TreeServer::FinishBurst() void TreeServer::SQuitChild(TreeServer* server, const std::string& reason) { - if (!Utils->Creator->dying) - FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), SpanningTreeEventListener, OnServerSplit, (server)); stdalgo::erase(Children, server); if (IsRoot()) @@ -205,6 +203,9 @@ void TreeServer::SQuitInternal(unsigned int& num_lost_servers) isdead = true; num_lost_servers++; RemoveHash(); + + if (!Utils->Creator->dying) + FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), SpanningTreeEventListener, OnServerSplit, (this)); } unsigned int TreeServer::QuitUsers(const std::string& reason) -- cgit v1.2.3 From afefc6bfe9e184086247fc305a41ef1c21cb136b Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 25 Apr 2016 13:18:02 +0200 Subject: m_spanningtree Call the OnServerLink hook from TreeServer constructor --- src/modules/m_spanningtree/treeserver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index b3430e1ab..b29bea134 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -115,6 +115,8 @@ TreeServer::TreeServer(const std::string& Name, const std::string& Desc, const s this->AddHashEntry(); Parent->Children.push_back(this); + + FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), SpanningTreeEventListener, OnServerLink, (this)); } void TreeServer::BeginBurst(uint64_t startms) @@ -151,7 +153,6 @@ void TreeServer::FinishBurst() unsigned long bursttime = ts - this->StartBurst; ServerInstance->SNO->WriteToSnoMask(Parent == Utils->TreeRoot ? 'l' : 'L', "Received end of netburst from \2%s\2 (burst time: %lu %s)", GetName().c_str(), (bursttime > 10000 ? bursttime / 1000 : bursttime), (bursttime > 10000 ? "secs" : "msecs")); - FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), SpanningTreeEventListener, OnServerLink, (this)); StartBurst = 0; FinishBurstInternal(); -- cgit v1.2.3 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') 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 From 72501adb5c721ac7b8d148c53305457e2c5a5921 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 25 Apr 2016 13:24:40 +0200 Subject: m_sasl Advertise the sasl capability only if the target server is online Issue #812 --- src/modules/m_sasl.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index a6edb8b70..02a302c11 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -89,6 +89,7 @@ class ServerTracker : public SpanningTreeEventListener class SASLCap : public Cap::Capability { std::string mechlist; + const ServerTracker& servertracker; bool OnRequest(LocalUser* user, bool adding) CXX11_OVERRIDE { @@ -100,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) { } @@ -351,7 +358,7 @@ class ModuleSASL : public Module ModuleSASL() : authExt("sasl_auth", ExtensionItem::EXT_USER, this) , servertracker(this) - , cap(this) + , cap(this, servertracker) , auth(this, authExt, cap) , sasl(this, authExt) , sasleventprov(this, "event/sasl") -- cgit v1.2.3