]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added forward lookup sanity checks to single threaded dns
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 2 Dec 2005 10:29:00 +0000 (10:29 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 2 Dec 2005 10:29:00 +0000 (10:29 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2111 e03df62e-2008-0410-955e-edbf42e46eb7

src/dnsqueue.cpp
src/inspircd.cpp

index 1b91a831069f989b1446e30542927a58801b4cab..5562b2299bfaa1acac15e13839bc83d068df6c4d 100644 (file)
@@ -87,10 +87,14 @@ long max_fd_alloc = 0;
 
 extern time_t TIME;
 
+//enum LookupState { reverse, forward };
+
 class Lookup {
 private:
-       DNS resolver;
+       DNS resolver1;
+       DNS resolver2;
        char u[NICKMAX];
+       std::string hostname;
 public:
        Lookup()
        {
@@ -108,12 +112,13 @@ public:
 
        bool DoLookup(std::string nick)
        {
+               hostname = "";
                userrec* usr = Find(nick);
                if (usr)
                {
                        log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
-                       resolver.SetNS(std::string(DNSServer));
-                       if (!resolver.ReverseLookup(std::string(usr->host)))
+                       resolver1.SetNS(std::string(DNSServer));
+                       if (!resolver1.ReverseLookup(std::string(usr->host)))
                                return false;
                        strlcpy(u,nick.c_str(),NICKMAX);
                        return true;
@@ -123,39 +128,72 @@ public:
 
        bool Done()
        {
-               userrec* usr = NULL;
-               if (resolver.HasResult())
+               if (hostname != "")
                {
-                       if (resolver.GetFD() != 0)
+                       // doing forward lookup
+                       userrec* usr = NULL;
+                       if (resolver2.HasResult())
                        {
-                               std::string hostname = resolver.GetResult();
-                               log(DEBUG,"RESULT! %s",hostname.c_str());
-                               usr = Find(u);
-                               if (usr)
+                               if (resolver2.GetFD() != 0)
                                {
-                                       if (usr->registered > 3)
+                                       std::string ip = resolver2.GetResultIP();
+                                       log(DEBUG,"FORWARD RESULT! %s",ip.c_str());
+
+                                       usr = Find(u);
+                                       if (usr)
                                        {
-                                               usr->dns_done = true;
-                                               return true;
+                                               if (usr->registered > 3)
+                                               {
+                                                       usr->dns_done = true;
+                                                       return true;
+                                               }
+                                               if ((hostname != "") && (usr->registered != 7))
+                                               {
+                                                       if (std::string(usr->ip) == ip)
+                                                       {
+                                                               strlcpy(usr->host,hostname.c_str(),MAXBUF);
+                                                               strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
+                                                               log(DEBUG,"Forward and reverse match, assigning hostname");
+                                                       }
+                                                       else
+                                                       {
+                                                               log(DEBUG,"AWOOGA! Forward lookup doesn't match reverse: R='%s',F='%s',IP='%s'",hostname.c_str(),ip.c_str(),usr->ip);
+                                                       }
+                                                       usr->dns_done = true;
+                                                       return true;
+                                               }
                                        }
-                                       if ((hostname != "") && (usr->registered != 7))
-                                       {
-                                               strlcpy(usr->host,hostname.c_str(),MAXBUF);
-                                               strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
-                                               WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str());
+                               }
+                               else
+                               {
+                                       usr = Find(u);
+                                       if (usr)
                                                usr->dns_done = true;
-                                               return true;
-                                       }
-                                       usr->dns_done = true;
                                        return true;
                                }
                        }
-                       else
+               }
+               else
+               {
+                       // doing reverse lookup
+                       userrec* usr = NULL;
+                       if (resolver1.HasResult())
                        {
-                               usr = Find(u);
-                               if (usr)
-                                       usr->dns_done = true;
-                               return true;
+                               if (resolver1.GetFD() != 0)
+                               {
+                                       hostname = resolver1.GetResult();
+                                       log(DEBUG,"REVERSE RESULT! %s",hostname.c_str());
+                                       usr = Find(u);
+                                       if (usr)
+                                       {
+                                               if (usr->registered > 3)
+                                               {
+                                                       usr->dns_done = true;
+                                                       return true;
+                                               }
+                                       }
+                                       resolver2.ForwardLookup(hostname);
+                               }
                        }
                }
                return false;
index 271332f70e9b0b6a2e29aee4b3fb35d4ed4f5773..0ab72bf21cf62ba7b828c4e2321dc55dc8e46ce9 100644 (file)
@@ -1367,6 +1367,7 @@ void* dns_task(void* arg)
                                        {
                                                log(DEBUG,"DNS Step 5");
                                                strcpy(u->host,host.c_str());
+                                               strcpy(u->dhost,host.c_str());
                                        }
                                }
                        }
@@ -2447,7 +2448,9 @@ int InspIRCd(char** argv, int argc)
                OLDTIME = TIME;
                TIME = time(NULL);
 
+#ifndef THREADED_DNS
                dns_poll();
+#endif
 
                unsigned int numsockets = module_sockets.size();
                for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)