diff options
author | Sadie Powell <sadie@witchery.services> | 2024-10-04 13:01:29 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-10-04 13:01:29 +0100 |
commit | 4cdbf560e196af86935b1b730af84412c8b25ecb (patch) | |
tree | 582e033909dbc3a48ab4b57ff2d9b597a6f27d4a | |
parent | cbccc79d37b2ca015c65e1a641dc46ed2bdca80d (diff) |
Fix matching extended bans in services.
Extended bans are stored without their prefix. Therefore, we should
not try to strip their prefix before matching.
Closes #288.
Co-authored-by: k4be <k4be@pirc.pl>
-rw-r--r-- | modules/protocol/inspircd.cpp | 35 | ||||
-rw-r--r-- | modules/protocol/unrealircd.cpp | 39 | ||||
-rw-r--r-- | src/modes.cpp | 3 |
3 files changed, 19 insertions, 58 deletions
diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index 8f88e6f89..b3e44b464 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -761,10 +761,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - - return Entry(this->name, real_mask).Matches(u); + return Entry(this->name, e->GetMask()).Matches(u); } }; @@ -779,10 +776,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - - Anope::string channel = mask.substr(2); - + auto channel = e->GetMask(); ChannelMode *cm = NULL; if (channel[0] != '#') { @@ -817,10 +811,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - - return u->IsIdentified() && real_mask.equals_ci(u->Account()->display); + return u->IsIdentified() && e->GetMask().equals_ci(u->Account()->display); } }; @@ -835,9 +826,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - return Anope::Match(u->realname, real_mask); + return Anope::Match(u->realname, e->GetMask()); } }; @@ -852,9 +841,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - return Anope::Match(u->server->GetName(), real_mask); + return Anope::Match(u->server->GetName(), e->GetMask()); } }; @@ -869,9 +856,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask); + return !u->fingerprint.empty() && Anope::Match(u->fingerprint, e->GetMask()); } }; @@ -886,9 +871,7 @@ namespace InspIRCdExtBan bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - return !u->Account() && Entry("BAN", real_mask).Matches(u); + return !u->Account() && Entry("BAN", e->GetMask()).Matches(u); } }; @@ -907,9 +890,7 @@ namespace InspIRCdExtBan if (!opertype) return false; // Not an operator. - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(2); - return Anope::Match(opertype->replace_all_cs(' ', '_'), real_mask); + return Anope::Match(opertype->replace_all_cs(' ', '_'), e->GetMask()); } }; } diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index 83cac4dc6..674ba6f82 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -485,9 +485,7 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string channel = mask.substr(3); - + auto channel = e->GetMask(); ChannelMode *cm = NULL; if (channel[0] != '#') { @@ -521,10 +519,7 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - - return Entry(this->name, real_mask).Matches(u); + return Entry(this->name, e->GetMask()).Matches(u); } }; @@ -538,10 +533,7 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - - return Anope::Match(u->realname, real_mask); + return Anope::Match(u->realname, e->GetMask()); } }; @@ -555,8 +547,7 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - return u->HasMode("REGISTERED") && mask.equals_ci(u->nick); + return u->HasMode("REGISTERED") && e->GetMask().equals_ci(u->nick); } }; @@ -570,13 +561,10 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - - if (real_mask == "0" && !u->Account()) /* ~a:0 is special and matches all unauthenticated users */ + if (e->GetMask() == "0" && !u->Account()) /* ~a:0 is special and matches all unauthenticated users */ return true; - return u->Account() && Anope::Match(u->Account()->display, real_mask); + return u->Account() && Anope::Match(u->Account()->display, e->GetMask()); } }; @@ -590,9 +578,7 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask); + return !u->fingerprint.empty() && Anope::Match(u->fingerprint, e->GetMask()); } }; @@ -606,10 +592,8 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); ModData *moddata = u->GetExt<ModData>("ClientModData"); - return moddata != NULL && moddata->find("operclass") != moddata->end() && Anope::Match((*moddata)["operclass"], real_mask); + return moddata != NULL && moddata->find("operclass") != moddata->end() && Anope::Match((*moddata)["operclass"], e->GetMask()); } }; @@ -624,8 +608,7 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { /* strip down the time (~t:1234:) and call other matchers */ - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); + auto real_mask = e->GetMask(); real_mask = real_mask.substr(real_mask.find(":") + 1); return Entry("BAN", real_mask).Matches(u); } @@ -641,8 +624,6 @@ namespace UnrealExtban bool Matches(User *u, const Entry *e) override { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); ModData *moddata = u->GetExt<ModData>("ClientModData"); if (moddata == NULL || moddata->find("geoip") == moddata->end()) return false; @@ -652,7 +633,7 @@ namespace UnrealExtban while (sep.GetToken(tokenbuf)) { if (tokenbuf.rfind("cc=", 0) == 0) - return (tokenbuf.substr(3, 2) == real_mask); + return (tokenbuf.substr(3, 2) == e->GetMask()); } return false; } diff --git a/src/modes.cpp b/src/modes.cpp index b0fbf9cca..57d8806e1 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -835,8 +835,7 @@ bool Entry::Matches(User *u, bool full) const if (cm != NULL && cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast<ChannelModeList *>(cm); - if (cml->Matches(u, this)) - return true; + return cml->Matches(u, this); } } |