]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add <dns:enabled>; allows disabling DNS lookups entirely.
authorSadie Powell <sadie@witchery.services>
Tue, 19 Jan 2021 08:42:44 +0000 (08:42 +0000)
committerSadie Powell <sadie@witchery.services>
Tue, 19 Jan 2021 08:42:44 +0000 (08:42 +0000)
Ref: #1839.

include/modules/dns.h
src/coremods/core_dns.cpp

index 8ac90f7deb12a24cab248ba710101039416b1588..6e7527a55c6ab75672aeec72f1e714c7b948712e 100644 (file)
@@ -57,6 +57,7 @@ namespace DNS
        enum Error
        {
                ERROR_NONE,
+               ERROR_DISABLED,
                ERROR_UNKNOWN,
                ERROR_UNLOADED,
                ERROR_TIMEDOUT,
index aec4132074cf8d9c50c3eb86994e2eb7b0feec2a..dbfb0b5828efa4d0b4cacdeb3edf970c4d38ac0a 100644 (file)
@@ -409,19 +409,6 @@ class MyManager : public Manager, public Timer, public EventHandler
                this->cache[r.question] = r;
        }
 
-       void Close()
-       {
-               // Shutdown the socket if it exists.
-               if (HasFd())
-               {
-                       SocketEngine::Shutdown(this, 2);
-                       SocketEngine::Close(this);
-               }
-
-               // Remove all entries from the cache.
-               cache.clear();
-       }
-
  public:
        DNS::Request* requests[MAX_REQUEST_ID+1];
 
@@ -453,11 +440,32 @@ class MyManager : public Manager, public Timer, public EventHandler
                }
        }
 
+       void Close()
+       {
+               // Shutdown the socket if it exists.
+               if (HasFd())
+               {
+                       SocketEngine::Shutdown(this, 2);
+                       SocketEngine::Close(this);
+               }
+
+               // Remove all entries from the cache.
+               cache.clear();
+       }
+
        void Process(DNS::Request* req) CXX11_OVERRIDE
        {
                if ((unloading) || (req->creator->dying))
                        throw Exception("Module is being unloaded");
 
+               if (!HasFd())
+               {
+                       Query rr(req->question);
+                       rr.error = ERROR_DISABLED;
+                       req->OnError(&rr);
+                       return;
+               }
+
                ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Processing request to lookup " + req->question.name + " of type " + ConvToStr(req->question.type) + " to " + this->myserver.addr());
 
                /* Create an id */
@@ -547,6 +555,8 @@ class MyManager : public Manager, public Timer, public EventHandler
                        case ERROR_DOMAIN_NOT_FOUND:
                        case ERROR_NO_RECORDS:
                                return "Domain not found";
+                       case ERROR_DISABLED:
+                               return "DNS lookups are disabled";
                        case ERROR_NONE:
                        case ERROR_UNKNOWN:
                        default:
@@ -838,13 +848,25 @@ class ModuleDNS : public Module
 
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
-               std::string oldserver = DNSServer;
-               const std::string oldip = SourceIP;
-               const unsigned int oldport = SourcePort;
-
                ConfigTag* tag = ServerInstance->Config->ConfValue("dns");
+               if (!tag->getBool("enabled", true))
+               {
+                       // Clear these so they get reset if DNS is enabled again.
+                       DNSServer.clear();
+                       SourceIP.clear();
+                       SourcePort = 0;
+
+                       this->manager.Close();
+                       return;
+               }
+
+               const std::string oldserver = DNSServer;
                DNSServer = tag->getString("server");
+
+               const std::string oldip = SourceIP;
                SourceIP = tag->getString("sourceip");
+
+               const unsigned int oldport = SourcePort;
                SourcePort = tag->getUInt("sourceport", 0, 0, UINT16_MAX);
 
                if (DNSServer.empty())