From 3bcb041dc67f9335c9543d89ba144e43d0274a81 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 2 Oct 2016 13:07:51 -0400 Subject: Implement support for SASL 3.2 mechanism lists. --- modules/protocol/inspircd20.cpp | 9 +++++++++ modules/sasl.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) (limited to 'modules') diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 3444c4412..f4dfcb12f 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -401,6 +401,15 @@ class InspIRCd20Proto : public IRCDProto Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), ""); } + void SendSASLMechanisms(std::vector &mechanisms) override + { + Anope::string mechlist; + for (unsigned i = 0; i < mechanisms.size(); ++i) + mechlist += "," + mechanisms[i]; + + Uplink::Send(Me, "METADATA", "*", "saslmechlist", mechlist.empty() ? "" : mechlist.substr(1)); + } + void SendSASLMessage(const SASL::Message &message) override { if (!message.ext.empty()) diff --git a/modules/sasl.cpp b/modules/sasl.cpp index d5a3acf6f..42d3bd9f3 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -321,14 +321,38 @@ void IdentifyRequestListener::OnFail(NickServ::IdentifyRequest *req) } class ModuleSASL : public Module + , public EventHook + , public EventHook + , public EventHook { SASLService sasl; Plain plain; External *external = nullptr; + std::vector mechs; + + void CheckMechs() + { + std::vector names; + for (Mechanism *mech : ServiceManager::Get()->FindServices()) + names.push_back(mech->GetName()); + + if (mechs == names) + return; + + mechs = names; + + // If we are connected to the network then broadcast the mechlist. + if (Me && Me->IsSynced()) + IRCD->SendSASLMechanisms(mechs); + } + public: ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) + , EventHook(this) + , EventHook(this) , sasl(this) , plain(&sasl, this) { @@ -337,12 +361,30 @@ class ModuleSASL : public Module external = new External(&sasl, this); } catch (ModuleException &) { } + + CheckMechs(); } ~ModuleSASL() { delete external; } + + void OnModuleLoad(User *, Module *) override + { + CheckMechs(); + } + + void OnModuleUnload(User *, Module *) override + { + CheckMechs(); + } + + void OnPreUplinkSync(Server *) override + { + // We have not yet sent a mechanism list so always do it here. + IRCD->SendSASLMechanisms(mechs); + } }; MODULE_INIT(ModuleSASL) -- cgit