diff options
author | Sadie Powell <sadie@witchery.services> | 2025-03-03 21:45:59 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-03-03 21:45:59 +0000 |
commit | 5828cdba45bbcf27349c62f13d341d31fcf01853 (patch) | |
tree | 264cef2cd928b9c0ce60627a75f1668598118a2d | |
parent | 4526fbed960085e3996fcd70195887f462c430d8 (diff) |
Move SASL protocol messages to the SASL header.
-rw-r--r-- | include/modules/sasl.h | 30 | ||||
-rw-r--r-- | include/protocol.h | 4 | ||||
-rw-r--r-- | modules/protocol/inspircd.cpp | 6 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 5 | ||||
-rw-r--r-- | modules/protocol/solanum.cpp | 6 | ||||
-rw-r--r-- | modules/protocol/unrealircd.cpp | 2 | ||||
-rw-r--r-- | modules/sasl.cpp | 14 |
7 files changed, 54 insertions, 13 deletions
diff --git a/include/modules/sasl.h b/include/modules/sasl.h index 5f8d0e9c3..2bed96cbd 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -158,4 +158,34 @@ namespace SASL Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << GetUserInfo() << " failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL"; } }; + + /** Sends IRCd messages used by the SASL module. */ + class CoreExport ProtocolInterface + : public ::Service + { + protected: + ProtocolInterface(Module *o) + : ::Service(o, "SASL::ProtocolInterface", "sasl") + { + } + + public: + /** Sends the list of SASL mechanisms to the IRCd + * @param mechs The list of SASL mechanisms. + */ + virtual void SendSASLMechanisms(std::vector<Anope::string> &mechs) { }; + + /** Sends a SASL message to the IRCd. + * @param message The SASL message to send. + */ + virtual void SendSASLMessage(const SASL::Message &message) = 0; + + /** Sends a login or logout for \p uid to \p na. + * @param uid The uid of the user to log in. + * @param na The nick alias to log the user in as or logout if nullptr. + */ + virtual void SendSVSLogin(const Anope::string &uid, NickAlias *na) = 0; + }; + + static ServiceReference<SASL::ProtocolInterface> protocol_interface("SASL::ProtocolInterface", "sasl"); } diff --git a/include/protocol.h b/include/protocol.h index c92939be6..b4db070d0 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -306,10 +306,6 @@ public: virtual void SendClearBans(const MessageSource &user, Channel *c, User* u) { } - virtual void SendSASLMechanisms(std::vector<Anope::string> &) { } - virtual void SendSASLMessage(const SASL::Message &) { } - virtual void SendSVSLogin(const Anope::string &uid, NickAlias *na) { } - virtual bool IsNickValid(const Anope::string &); virtual bool IsChannelValid(const Anope::string &); virtual bool IsIdentValid(const Anope::string &); diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index 538a27a37..3f84adc28 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -101,6 +101,7 @@ namespace class InspIRCdProto final : public IRCDProto + , public SASL::ProtocolInterface { private: static Anope::string GetAccountNicks(NickAlias* na) @@ -155,7 +156,10 @@ private: public: PrimitiveExtensibleItem<ListLimits> maxlist; - InspIRCdProto(Module *creator) : IRCDProto(creator, "InspIRCd 3+"), maxlist(creator, "maxlist") + InspIRCdProto(Module *creator) + : IRCDProto(creator, "InspIRCd 3+") + , SASL::ProtocolInterface(creator) + , maxlist(creator, "maxlist") { DefaultPseudoclientModes = "+oI"; CanSVSNick = true; diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 252134470..7bfcd4948 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -18,9 +18,12 @@ static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid"); class PlexusProto final : public IRCDProto + , SASL::ProtocolInterface { public: - PlexusProto(Module *creator) : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1") + PlexusProto(Module *creator) + : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1") + , SASL::ProtocolInterface(creator) { DefaultPseudoclientModes = "+iU"; CanSVSNick = true; diff --git a/modules/protocol/solanum.cpp b/modules/protocol/solanum.cpp index fa05daf46..ab2d71b25 100644 --- a/modules/protocol/solanum.cpp +++ b/modules/protocol/solanum.cpp @@ -32,10 +32,12 @@ public: class SolanumProto final : public IRCDProto + , public SASL::ProtocolInterface { public: - - SolanumProto(Module *creator) : IRCDProto(creator, "Solanum") + SolanumProto(Module *creator) + : IRCDProto(creator, "Solanum") + , SASL::ProtocolInterface(creator) { DefaultPseudoclientModes = "+oiS"; CanCertFP = true; diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index aed578c3e..35df271d7 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -36,6 +36,7 @@ namespace class UnrealIRCdProto final : public IRCDProto + , public SASL::ProtocolInterface { public: PrimitiveExtensibleItem<ModData> ClientModData; @@ -43,6 +44,7 @@ public: UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 6+") + , SASL::ProtocolInterface(creator) , ClientModData(creator, "ClientModData") , ChannelModData(creator, "ChannelModData") { diff --git a/modules/sasl.cpp b/modules/sasl.cpp index 795a76bf3..bbbdda696 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -292,7 +292,7 @@ public: msg.type = mtype; msg.data.push_back(data); - IRCD->SendSASLMessage(msg); + protocol_interface->SendSASLMessage(msg); } void Succeed(Session *session, NickCore *nc) override @@ -310,7 +310,7 @@ public: } else { - IRCD->SendSVSLogin(session->uid, na); + protocol_interface->SendSVSLogin(session->uid, na); } this->SendMessage(session, "D", "S"); } @@ -397,20 +397,23 @@ class ModuleSASL final void CheckMechs() { std::vector<Anope::string> newmechs = ::Service::GetServiceKeys("SASL::Mechanism"); - if (newmechs == mechs) + if (newmechs == mechs || !protocol_interface) return; mechs = newmechs; // If we are connected to the network then broadcast the mechlist. if (Me && Me->IsSynced()) - IRCD->SendSASLMechanisms(mechs); + protocol_interface->SendSASLMechanisms(mechs); } public: ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), sasl(this), anonymous(this), plain(this) { + if (!protocol_interface) + throw ModuleException("Your IRCd does not support SASL"); + try { external = new External(this); @@ -437,7 +440,8 @@ public: void OnPreUplinkSync(Server *) override { // We have not yet sent a mechanism list so always do it here. - IRCD->SendSASLMechanisms(mechs); + if (!protocol_interface) + protocol_interface->SendSASLMechanisms(mechs); } }; |