]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dnsbl.cpp
Update wiki links to use HTTPS and point to the correct pages.
[user/henk/code/inspircd.git] / src / modules / m_dnsbl.cpp
index 5e02dd0a5dadc5cea64d99375285f24a5a8bb5e6..3dea080cee59dd99474510ae5fe5567f4eda3b44 100644 (file)
@@ -27,7 +27,7 @@
 /* $ModDesc: Provides handling of DNS blacklists */
 
 /* Class holding data for a single entry */
-class DNSBLConfEntry
+class DNSBLConfEntry : public refcountbase
 {
        public:
                enum EnumBanaction { I_UNKNOWN, I_KILL, I_ZLINE, I_KLINE, I_GLINE, I_MARK };
@@ -51,11 +51,11 @@ class DNSBLResolver : public Resolver
        std::string theiruid;
        LocalStringExt& nameExt;
        LocalIntExt& countExt;
-       DNSBLConfEntry *ConfEntry;
+       reference<DNSBLConfEntry> ConfEntry;
 
  public:
 
-       DNSBLResolver(Module *me, LocalStringExt& match, LocalIntExt& ctr, const std::string &hostname, LocalUser* u, DNSBLConfEntry *conf, bool &cached)
+       DNSBLResolver(Module *me, LocalStringExt& match, LocalIntExt& ctr, const std::string &hostname, LocalUser* u, reference<DNSBLConfEntry> conf, bool &cached)
                : Resolver(hostname, DNS_QUERY_A, cached, me), theiruid(u->uuid), nameExt(match), countExt(ctr), ConfEntry(conf)
        {
        }
@@ -70,8 +70,8 @@ class DNSBLResolver : public Resolver
                        int i = countExt.get(them);
                        if (i)
                                countExt.set(them, i - 1);
-                       // Now we calculate the bitmask: 256*(256*(256*a+b)+c)+d
-                       if(result.length())
+                       // All replies should be in 127.0.0.0/8
+                       if (result.compare(0, 4, "127.") == 0)
                        {
                                unsigned int bitmask = 0, record = 0;
                                bool match = false;
@@ -82,6 +82,7 @@ class DNSBLResolver : public Resolver
                                switch (ConfEntry->type)
                                {
                                        case DNSBLConfEntry::A_BITMASK:
+                                               // Now we calculate the bitmask: 256*(256*(256*a+b)+c)+d
                                                bitmask = resultip.s_addr >> 24; /* Last octet (network byte order) */
                                                bitmask &= ConfEntry->bitmask;
                                                match = (bitmask != 0);
@@ -141,7 +142,10 @@ class DNSBLResolver : public Resolver
                                                                ServerInstance->XLines->ApplyLines();
                                                        }
                                                        else
+                                                       {
                                                                delete kl;
+                                                               return;
+                                                       }
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_GLINE:
@@ -156,7 +160,10 @@ class DNSBLResolver : public Resolver
                                                                ServerInstance->XLines->ApplyLines();
                                                        }
                                                        else
+                                                       {
                                                                delete gl;
+                                                               return;
+                                                       }
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_ZLINE:
@@ -171,7 +178,10 @@ class DNSBLResolver : public Resolver
                                                                ServerInstance->XLines->ApplyLines();
                                                        }
                                                        else
+                                                       {
                                                                delete zl;
+                                                               return;
+                                                       }
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_UNKNOWN:
@@ -187,7 +197,11 @@ class DNSBLResolver : public Resolver
                                        ConfEntry->stats_misses++;
                        }
                        else
+                       {
+                               if (!result.empty())
+                                       ServerInstance->SNO->WriteGlobalSno('a', "DNSBL: %s returned address outside of acceptable subnet 127.0.0.0/8: %s", ConfEntry->domain.c_str(), result.c_str());
                                ConfEntry->stats_misses++;
+                       }
                }
        }
 
@@ -209,7 +223,7 @@ class DNSBLResolver : public Resolver
 
 class ModuleDNSBL : public Module
 {
-       std::vector<DNSBLConfEntry *> DNSBLConfEntries;
+       std::vector<reference<DNSBLConfEntry> > DNSBLConfEntries;
        LocalStringExt nameExt;
        LocalIntExt countExt;
 
@@ -243,36 +257,22 @@ class ModuleDNSBL : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleDNSBL()
-       {
-               ClearEntries();
-       }
-
        Version GetVersion()
        {
                return Version("Provides handling of DNS blacklists", VF_VENDOR);
        }
 
-       /** Clear entries and free the mem it was using
-        */
-       void ClearEntries()
-       {
-               for (std::vector<DNSBLConfEntry *>::iterator i = DNSBLConfEntries.begin(); i != DNSBLConfEntries.end(); i++)
-                       delete *i;
-               DNSBLConfEntries.clear();
-       }
-
        /** Fill our conf vector with data
         */
        void ReadConf()
        {
-               ClearEntries();
+               DNSBLConfEntries.clear();
 
                ConfigTagList dnsbls = ServerInstance->Config->ConfTags("dnsbl");
                for(ConfigIter i = dnsbls.first; i != dnsbls.second; ++i)
                {
                        ConfigTag* tag = i->second;
-                       DNSBLConfEntry *e = new DNSBLConfEntry();
+                       reference<DNSBLConfEntry> e = new DNSBLConfEntry();
 
                        e->name = tag->getString("name");
                        e->ident = tag->getString("ident");
@@ -337,11 +337,7 @@ class ModuleDNSBL : public Module
 
                                /* add it, all is ok */
                                DNSBLConfEntries.push_back(e);
-                               continue;
                        }
-
-                       /* delete and drop it, error somewhere */
-                       delete e;
                }
        }
 
@@ -420,7 +416,7 @@ class ModuleDNSBL : public Module
 
                unsigned long total_hits = 0, total_misses = 0;
 
-               for (std::vector<DNSBLConfEntry*>::iterator i = DNSBLConfEntries.begin(); i != DNSBLConfEntries.end(); i++)
+               for (std::vector<reference<DNSBLConfEntry> >::const_iterator i = DNSBLConfEntries.begin(); i != DNSBLConfEntries.end(); ++i)
                {
                        total_hits += (*i)->stats_hits;
                        total_misses += (*i)->stats_misses;