]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dnsbl.cpp
Switch from the Ubuntu 16.04 image to the 18.04 Ubuntu image.
[user/henk/code/inspircd.git] / src / modules / m_dnsbl.cpp
index 9ad3b05e7e543529e447af284e8fb9d30aa51240..dc43dda3f0c6f2045580a47ce77a51855693aa13 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Copyright (C) 2018-2020 Matt Schatz <genius3000@g3k.solutions>
  *   Copyright (C) 2018-2019 linuxdaemon <linuxdaemon.irc@gmail.com>
- *   Copyright (C) 2013, 2016-2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013, 2017-2021 Sadie Powell <sadie@witchery.services>
  *   Copyright (C) 2013, 2015-2016 Adam <Adam@anope.org>
  *   Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
  *   Copyright (C) 2012, 2018 Robby <robby@chatbelgie.be>
@@ -42,12 +42,14 @@ class DNSBLConfEntry : public refcountbase
                EnumType type;
                unsigned long duration;
                unsigned int bitmask;
+               unsigned int timeout;
                unsigned char records[256];
                unsigned long stats_hits, stats_misses, stats_errors;
                DNSBLConfEntry()
                        : type(A_BITMASK)
                        , duration(86400)
                        , bitmask(0)
+                       , timeout(0)
                        , stats_hits(0)
                        , stats_misses(0)
                        , stats_errors(0)
@@ -69,7 +71,7 @@ class DNSBLResolver : public DNS::Request
 
  public:
        DNSBLResolver(DNS::Manager *mgr, Module *me, LocalStringExt& match, LocalIntExt& ctr, const std::string &hostname, LocalUser* u, reference<DNSBLConfEntry> conf)
-               : DNS::Request(mgr, me, hostname, DNS::QUERY_A, true)
+               : DNS::Request(mgr, me, hostname, DNS::QUERY_A, true, conf->timeout)
                , theirsa(u->client_sa)
                , theiruid(u->uuid)
                , nameExt(match)
@@ -84,7 +86,10 @@ class DNSBLResolver : public DNS::Request
                /* Check the user still exists */
                LocalUser* them = IS_LOCAL(ServerInstance->FindUUID(theiruid));
                if (!them || them->client_sa != theirsa)
+               {
+                       ConfEntry->stats_misses++;
                        return;
+               }
 
                int i = countExt.get(them);
                if (i)
@@ -242,6 +247,20 @@ class DNSBLResolver : public DNS::Request
 
        void OnError(const DNS::Query *q) CXX11_OVERRIDE
        {
+               bool is_miss = true;
+               switch (q->error)
+               {
+                       case DNS::ERROR_NO_RECORDS:
+                       case DNS::ERROR_DOMAIN_NOT_FOUND:
+                               ConfEntry->stats_misses++;
+                               break;
+
+                       default:
+                               ConfEntry->stats_errors++;
+                               is_miss = false;
+                               break;
+               }
+
                LocalUser* them = IS_LOCAL(ServerInstance->FindUUID(theiruid));
                if (!them || them->client_sa != theirsa)
                        return;
@@ -250,13 +269,9 @@ class DNSBLResolver : public DNS::Request
                if (i)
                        countExt.set(them, i - 1);
 
-               if (q->error == DNS::ERROR_NO_RECORDS || q->error == DNS::ERROR_DOMAIN_NOT_FOUND)
-               {
-                       ConfEntry->stats_misses++;
+               if (is_miss)
                        return;
-               }
 
-               ConfEntry->stats_errors++;
                ServerInstance->SNO->WriteGlobalSno('d', "An error occurred whilst checking whether %s (%s) is on the '%s' DNS blacklist: %s",
                        them->GetFullRealHost().c_str(), them->GetIPString().c_str(), ConfEntry->name.c_str(), this->manager->GetErrorStr(q->error).c_str());
        }
@@ -330,6 +345,7 @@ class ModuleDNSBL : public Module, public Stats::EventListener
                        e->host = tag->getString("host");
                        e->reason = tag->getString("reason", "Your IP has been blacklisted.", 1);
                        e->domain = tag->getString("domain");
+                       e->timeout = tag->getDuration("timeout", 0);
 
                        if (stdalgo::string::equalsci(tag->getString("type"), "bitmask"))
                        {