diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-11-01 15:42:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 15:42:28 +0100 |
commit | 79619b61417ac456f82432f767dfd50eb80b6b01 (patch) | |
tree | 005f9e1f58ba6ec0fef6cfffeb45f4252c69b4d0 | |
parent | 80f10dc783b75aa6fa2a3fe490a6e94b2a78e467 (diff) | |
parent | 02575ecbbbd7311f7e16ed9f2f3a1c5809deefa8 (diff) |
Merge pull request #1236 from SaberUK/master+port
Allow classes to take a port range.
-rw-r--r-- | include/users.h | 5 | ||||
-rw-r--r-- | src/configreader.cpp | 8 | ||||
-rw-r--r-- | src/users.cpp | 13 |
3 files changed, 20 insertions, 6 deletions
diff --git a/include/users.h b/include/users.h index ae76d2eb3..fc31a8297 100644 --- a/include/users.h +++ b/include/users.h @@ -135,6 +135,11 @@ struct CoreExport ConnectClass : public refcountbase */ bool resolvehostnames; + /** + * If non-empty the server ports which this user has to be using + */ + insp::flat_set<int> ports; + /** Create a new connect class with no settings. */ ConnectClass(ConfigTag* tag, char type, const std::string& mask); diff --git a/src/configreader.cpp b/src/configreader.cpp index 7a1c8b8ce..9d327532b 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -328,6 +328,14 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) me->limit = tag->getInt("limit", me->limit); me->resolvehostnames = tag->getBool("resolvehostnames", me->resolvehostnames); + std::string ports = tag->getString("port"); + if (!ports.empty()) + { + irc::portparser portrange(ports, false); + while (int port = portrange.GetToken()) + me->ports.insert(port); + } + ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask); if (oldMask != oldBlocksByMask.end()) { diff --git a/src/users.cpp b/src/users.cpp index 5d1c12b13..498a27d58 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1096,14 +1096,14 @@ void LocalUser::SetClass(const std::string &explicit_name) } /* if it requires a port ... */ - int port = c->config->getInt("port"); - if (port) + if (!c->ports.empty()) { - ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Requires port (%d)", port); - /* and our port doesn't match, fail. */ - if (this->GetServerPort() != port) + if (!c->ports.count(this->GetServerPort())) + { + ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Requires a different port, skipping"); continue; + } } if (regdone && !c->config->getString("password").empty()) @@ -1171,7 +1171,7 @@ ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, cons softsendqmax(parent.softsendqmax), hardsendqmax(parent.hardsendqmax), recvqmax(parent.recvqmax), penaltythreshold(parent.penaltythreshold), commandrate(parent.commandrate), maxlocal(parent.maxlocal), maxglobal(parent.maxglobal), maxconnwarn(parent.maxconnwarn), maxchans(parent.maxchans), - limit(parent.limit), resolvehostnames(parent.resolvehostnames) + limit(parent.limit), resolvehostnames(parent.resolvehostnames), ports(parent.ports) { } @@ -1195,4 +1195,5 @@ void ConnectClass::Update(const ConnectClass* src) maxchans = src->maxchans; limit = src->limit; resolvehostnames = src->resolvehostnames; + ports = src->ports; } |