]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add support for matching multiple hosts in <connect:{allow,deny}>.
authorSadie Powell <sadie@witchery.services>
Mon, 22 Mar 2021 14:43:05 +0000 (14:43 +0000)
committerSadie Powell <sadie@witchery.services>
Tue, 30 Mar 2021 08:02:47 +0000 (09:02 +0100)
include/users.h
src/configreader.cpp
src/users.cpp

index b9092b678fce7fc415b61bb0f57db523140ed121..136874bab29fa48edd0b0a0f4d50b9c9b5cbfe09 100644 (file)
@@ -91,10 +91,12 @@ struct CoreExport ConnectClass : public refcountbase
         */
        unsigned int registration_timeout;
 
-       /** Host mask for this line
-        */
+       /** Hosts that this user can connect from as a string. */
        std::string host;
 
+       /** Hosts that this user can connect from as a vector. */
+       std::vector<std::string> hosts;
+
        /** Number of seconds between pings for this line
         */
        unsigned int pingtime;
@@ -166,8 +168,9 @@ struct CoreExport ConnectClass : public refcountbase
        /** Update the settings in this block to match the given block */
        void Update(const ConnectClass* newSettings);
 
-       const std::string& GetName() { return name; }
-       const std::string& GetHost() { return host; }
+       const std::string& GetName() const { return name; }
+       const std::string& GetHost() const { return host; }
+       const std::vector<std::string>& GetHosts() const { return hosts; }
 
        /** Returns the registration timeout
         */
index 2cd17e844bcd0b62e7f42281395ac1fd1f0d8461..381d28d1b37aef135ebba3ceacf2283c7d2a19bf 100644 (file)
@@ -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())
                        {
index 7029accc052a6c38ae6ee23cafb5f943c59d2671..8ea0de6bc61d5e04698e3b6527a3c53f1c4c7950 100644 (file)
@@ -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;