From: brain Date: Fri, 2 Dec 2005 10:29:00 +0000 (+0000) Subject: Added forward lookup sanity checks to single threaded dns X-Git-Tag: v2.0.23~9913 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=c07db3cfd25e4432a8a4450b7cb1f7bd715ca8ab;p=user%2Fhenk%2Fcode%2Finspircd.git Added forward lookup sanity checks to single threaded dns git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2111 e03df62e-2008-0410-955e-edbf42e46eb7 --- diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 1b91a8310..5562b2299 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -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; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 271332f70..0ab72bf21 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -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::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)