summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2021-03-22 14:43:05 +0000
committerSadie Powell <sadie@witchery.services>2021-03-30 09:02:47 +0100
commit8c3c4f8e8274a598b4ba573f9eabfd0940d2e88d (patch)
tree7a4ac6b6b5c2724954573f9b6f4536144814ac97 /src
parente2b0f3dc9ef4d56c71d7abda13e6139ca092e387 (diff)
Add support for matching multiple hosts in <connect:{allow,deny}>.
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp4
-rw-r--r--src/users.cpp17
2 files changed, 16 insertions, 5 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 2cd17e844..381d28d1b 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -242,9 +242,9 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
std::string mask;
char type;
- if (tag->readString("allow", mask, false))
+ if (tag->readString("allow", mask, false) && !mask.empty())
type = CC_ALLOW;
- else if (tag->readString("deny", mask, false))
+ else if (tag->readString("deny", mask, false) && !mask.empty())
type = CC_DENY;
else if (!name.empty())
{
diff --git a/src/users.cpp b/src/users.cpp
index 7029accc0..8ea0de6bc 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1159,9 +1159,16 @@ void LocalUser::SetClass(const std::string &explicit_name)
continue;
}
- /* check if host matches.. */
- if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
- !InspIRCd::MatchCIDR(this->GetRealHost(), c->GetHost(), NULL))
+ bool hostmatches = false;
+ for (std::vector<std::string>::const_iterator host = c->GetHosts().begin(); host != c->GetHosts().end(); ++host)
+ {
+ if (InspIRCd::MatchCIDR(this->GetIPString(), *host) || InspIRCd::MatchCIDR(this->GetRealHost(), *host))
+ {
+ hostmatches = true;
+ break;
+ }
+ }
+ if (!hostmatches)
{
ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "The %s connect class is not suitable as neither the host (%s) nor the IP (%s) matches %s",
c->GetName().c_str(), this->GetRealHost().c_str(), this->GetIPString().c_str(), c->GetHost().c_str());
@@ -1266,6 +1273,9 @@ ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)
, limit(0)
, resolvehostnames(true)
{
+ irc::spacesepstream hoststream(host);
+ for (std::string hostentry; hoststream.GetToken(hostentry); )
+ hosts.push_back(hostentry);
}
ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, const ConnectClass& parent)
@@ -1309,6 +1319,7 @@ void ConnectClass::Update(const ConnectClass* src)
name = src->name;
registration_timeout = src->registration_timeout;
host = src->host;
+ hosts = src->hosts;
pingtime = src->pingtime;
softsendqmax = src->softsendqmax;
hardsendqmax = src->hardsendqmax;