diff options
| author | 2022-04-16 11:48:08 +0100 | |
|---|---|---|
| committer | 2022-04-16 12:01:59 +0100 | |
| commit | c0bc5bf7981e30229bdabfdf51a289635fe8be76 (patch) | |
| tree | 9ccf09d595b797e4dcffe0c43c0ad7eb70260f39 /src | |
| parent | Add a class that wraps a dynamic reference to the extban manager. (diff) | |
Add ListModeBase::CanonicalizeParam, fix cleaning extban masks.
Diffstat (limited to 'src')
| -rw-r--r-- | src/coremods/core_channel/core_channel.h | 4 | ||||
| -rw-r--r-- | src/coremods/core_channel/extban.cpp | 20 | ||||
| -rw-r--r-- | src/coremods/core_channel/modes.cpp | 10 | ||||
| -rw-r--r-- | src/listmode.cpp | 14 | ||||
| -rw-r--r-- | src/mode.cpp | 3 | ||||
| -rw-r--r-- | src/modules/m_autoop.cpp | 3 | ||||
| -rw-r--r-- | src/modules/m_banexception.cpp | 13 | ||||
| -rw-r--r-- | src/modules/m_chanfilter.cpp | 2 | ||||
| -rw-r--r-- | src/modules/m_exemptchanops.cpp | 2 | ||||
| -rw-r--r-- | src/modules/m_inviteexception.cpp | 14 |
10 files changed, 71 insertions, 14 deletions
diff --git a/src/coremods/core_channel/core_channel.h b/src/coremods/core_channel/core_channel.h index d7b8f4bb0..b9c3bbf75 100644 --- a/src/coremods/core_channel/core_channel.h +++ b/src/coremods/core_channel/core_channel.h @@ -128,8 +128,11 @@ public: class ModeChannelBan final : public ListModeBase { +private: + ExtBan::ManagerRef extbanmgr; public: ModeChannelBan(Module* Creator); + bool CanonicalizeParam(LocalUser* user, Channel* channel, std::string& parameter) override; }; class ModeChannelKey final @@ -186,6 +189,7 @@ public: } void AddExtBan(ExtBan::Base* extban) override; + bool Canonicalize(std::string& text) const override; void DelExtBan(ExtBan::Base* extban) override; const LetterMap& GetLetterMap() const override { return byletter; } const NameMap& GetNameMap() const override { return byname; } diff --git a/src/coremods/core_channel/extban.cpp b/src/coremods/core_channel/extban.cpp index 255c8bbdc..376b6febe 100644 --- a/src/coremods/core_channel/extban.cpp +++ b/src/coremods/core_channel/extban.cpp @@ -26,6 +26,26 @@ void ExtBanManager::AddExtBan(ExtBan::Base* extban) byname.emplace(extban->GetName(), extban); } +bool ExtBanManager::Canonicalize(std::string& text) const +{ + bool inverted; // Intentionally unused + std::string xbname, xbvalue; + if (!ExtBan::Parse(text, xbname, xbvalue, inverted)) + return false; // Not an extban. + + ExtBan::Base* extban = nullptr; + if (xbname.size() == 1) + extban = FindLetter(xbname[0]); + else + extban = FindName(xbname); + + if (!extban) + return false; // Looks like an extban but it isn't. + + extban->Canonicalize(xbvalue); + return true; +} + void ExtBanManager::BuildISupport(std::string& out) { for (const LetterMap::value_type& extban : byletter) diff --git a/src/coremods/core_channel/modes.cpp b/src/coremods/core_channel/modes.cpp index 937efc21c..69cdb55dd 100644 --- a/src/coremods/core_channel/modes.cpp +++ b/src/coremods/core_channel/modes.cpp @@ -21,11 +21,19 @@ #include "core_channel.h" ModeChannelBan::ModeChannelBan(Module* Creator) - : ListModeBase(Creator, "ban", 'b', RPL_BANLIST, RPL_ENDOFBANLIST, true) + : ListModeBase(Creator, "ban", 'b', RPL_BANLIST, RPL_ENDOFBANLIST) + , extbanmgr(Creator) { syntax = "<mask>"; } +bool ModeChannelBan::CanonicalizeParam(LocalUser* user, Channel* channel, std::string& parameter) +{ + if (!extbanmgr || !extbanmgr->Canonicalize(parameter)) + ModeParser::CleanMask(parameter); + return true; +} + ModeChannelLimit::ModeChannelLimit(Module* Creator) : ParamMode<ModeChannelLimit, IntExtItem>(Creator, "limit", 'l') { diff --git a/src/listmode.cpp b/src/listmode.cpp index 48fe52b80..e224f1168 100644 --- a/src/listmode.cpp +++ b/src/listmode.cpp @@ -22,11 +22,10 @@ #include "inspircd.h" #include "listmode.h" -ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, unsigned int lnum, unsigned int eolnum, bool autotidy) +ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, unsigned int lnum, unsigned int eolnum) : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_LIST) , listnumeric(lnum) , endoflistnumeric(eolnum) - , tidy(autotidy) , extItem(Creator, "list-mode-" + name, ExtensionType::CHANNEL) { list = true; @@ -156,8 +155,10 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, Mod if (change.adding) { - if (tidy) - ModeParser::CleanMask(change.param); + // Try to canonicalise the parameter locally. + LocalUser* lsource = IS_LOCAL(source); + if (lsource && !CanonicalizeParam(lsource, channel, change.param)) + return MODEACTION_DENY; // If there was no list if (!cd) @@ -230,6 +231,11 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, Mod } } +bool ListModeBase::CanonicalizeParam(LocalUser* user, Channel* channel, std::string& parameter) +{ + return true; +} + bool ListModeBase::ValidateParam(User* user, Channel* channel, const std::string& parameter) { return true; diff --git a/src/mode.cpp b/src/mode.cpp index 3b3779e97..bbe0b2042 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -526,9 +526,6 @@ void ModeParser::CleanMask(std::string &mask) std::string::size_type pos_of_dot = mask.find_first_of('.'); std::string::size_type pos_of_colons = mask.find("::"); /* Because ipv6 addresses are colon delimited -- double so it treats extban as nick */ - if (mask.length() >= 2 && mask[1] == ':') - return; // if it's an extban, don't even try guess how it needs to be formed. - if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos)) { /* Just a nick, or just a host - or clearly ipv6 (starting with :) */ diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp index ee287e3d6..23b4b9c0d 100644 --- a/src/modules/m_autoop.cpp +++ b/src/modules/m_autoop.cpp @@ -36,11 +36,10 @@ class AutoOpList final { public: AutoOpList(Module* Creator) - : ListModeBase(Creator, "autoop", 'w', RPL_ACCESSLIST, RPL_ENDOFACCESSLIST, true) + : ListModeBase(Creator, "autoop", 'w', RPL_ACCESSLIST, RPL_ENDOFACCESSLIST) { ranktoset = ranktounset = OP_VALUE; syntax = "<prefix>:<mask>"; - tidy = false; } PrefixMode* FindMode(const std::string& mid) diff --git a/src/modules/m_banexception.cpp b/src/modules/m_banexception.cpp index b81a67b5a..b975ab7c9 100644 --- a/src/modules/m_banexception.cpp +++ b/src/modules/m_banexception.cpp @@ -39,12 +39,23 @@ enum class BanException final : public ListModeBase { +private: + ExtBan::ManagerRef extbanmgr; + public: BanException(Module* Creator) - : ListModeBase(Creator, "banexception", 'e', RPL_EXCEPTLIST, RPL_ENDOFEXCEPTLIST, true) + : ListModeBase(Creator, "banexception", 'e', RPL_EXCEPTLIST, RPL_ENDOFEXCEPTLIST) + , extbanmgr(Creator) { syntax = "<mask>"; } + + bool CanonicalizeParam(LocalUser* user, Channel* channel, std::string& parameter) override + { + if (!extbanmgr || !extbanmgr->Canonicalize(parameter)) + ModeParser::CleanMask(parameter); + return true; + } }; class ModuleBanException final diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp index bf5a2e1ab..c399be68a 100644 --- a/src/modules/m_chanfilter.cpp +++ b/src/modules/m_chanfilter.cpp @@ -42,7 +42,7 @@ public: unsigned long maxlen; ChanFilter(Module* Creator) - : ListModeBase(Creator, "filter", 'g', RPL_SPAMFILTER, RPL_ENDOFSPAMFILTER, false) + : ListModeBase(Creator, "filter", 'g', RPL_SPAMFILTER, RPL_ENDOFSPAMFILTER) { syntax = "<pattern>"; } diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp index 9fa9fa92f..89c1688fc 100644 --- a/src/modules/m_exemptchanops.cpp +++ b/src/modules/m_exemptchanops.cpp @@ -36,7 +36,7 @@ class ExemptChanOps final { public: ExemptChanOps(Module* Creator) - : ListModeBase(Creator, "exemptchanops", 'X', RPL_EXEMPTIONLIST, RPL_ENDOFEXEMPTIONLIST, false) + : ListModeBase(Creator, "exemptchanops", 'X', RPL_EXEMPTIONLIST, RPL_ENDOFEXEMPTIONLIST) { syntax = "<restriction>:<prefix>"; } diff --git a/src/modules/m_inviteexception.cpp b/src/modules/m_inviteexception.cpp index 565bb4bf9..8db100230 100644 --- a/src/modules/m_inviteexception.cpp +++ b/src/modules/m_inviteexception.cpp @@ -24,6 +24,7 @@ #include "inspircd.h" #include "listmode.h" +#include "modules/extban.h" #include "modules/isupport.h" enum @@ -36,12 +37,23 @@ enum class InviteException final : public ListModeBase { +private: + ExtBan::ManagerRef extbanmgr; + public: InviteException(Module* Creator) - : ListModeBase(Creator, "invex", 'I', RPL_INVEXLIST, RPL_ENDOFINVEXLIST, true) + : ListModeBase(Creator, "invex", 'I', RPL_INVEXLIST, RPL_ENDOFINVEXLIST) + , extbanmgr(Creator) { syntax = "<mask>"; } + + bool CanonicalizeParam(LocalUser* user, Channel* channel, std::string& parameter) override + { + if (!extbanmgr || !extbanmgr->Canonicalize(parameter)) + ModeParser::CleanMask(parameter); + return true; + } }; class ModuleInviteException final |
