]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
Remove check that very rarely equates to true
[user/henk/code/inspircd.git] / src / dns.cpp
index ea88c21bcfbc71d9dd1811ab1509472d3fefa029..0436095b6bd30afc315837138fd0f7402a4c1891 100644 (file)
@@ -257,6 +257,17 @@ DNS::DNS()
        if (insp_aton(Config->DNSServer,&addr) > 0)
        {
                memcpy(&myserver,&addr,sizeof(insp_inaddr));
+               if ((strstr(Config->DNSServer,"::ffff:") == (char*)&Config->DNSServer) ||  (strstr(Config->DNSServer,"::FFFF:") == (char*)&Config->DNSServer))
+               {
+                       /* These dont come back looking like they did when they went in.
+                        * We're forced to turn some checks off.
+                        * If anyone knows how to fix this, let me know. --Brain
+                        */
+                       log(DEFAULT,"WARNING: Using IPv4 addresses over IPv6 forces some DNS checks to be disabled.");
+                       log(DEFAULT,"         This should not cause a problem, however it is recommended you migrate");
+                       log(DEFAULT,"         to a true IPv6 environment.");
+                       this->ip6munge = true;
+               }
                log(DEBUG,"Added nameserver '%s'",Config->DNSServer);
        }
        else
@@ -442,7 +453,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp)
        DNSHeader h;
        int id;
        int length;
-
+#ifdef SUPPORT_IP6LINKS
        if (fp == PROTOCOL_IPV6)
        {
                in6_addr i;
@@ -455,6 +466,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp)
                        return -1;
        }
        else
+#endif
        {
                in_addr i;
                if (inet_aton(ip, &i))
@@ -482,6 +494,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp)
 
 void DNS::MakeIP6Int(char* query, const in6_addr *ip)
 {
+#ifdef SUPPORT_IP6LINKS
        const char* hex = "0123456789abcdef";
        for (int index = 31; index >= 0; index--) /* for() loop steps twice per byte */
        {
@@ -494,6 +507,9 @@ void DNS::MakeIP6Int(char* query, const in6_addr *ip)
                *query++ = '.'; /* Seperator */
        }
        strcpy(query,"ip6.arpa"); /* Suffix the string */
+#else
+       *query = 0;
+#endif
 }
 
 /* Return the next id which is ready, and the result attached to it */
@@ -515,8 +531,11 @@ DNSResult DNS::GetResult()
 
        /* Did we get the whole header? */
        if (length < 12)
+       {
                /* Nope - something screwed up. */
+               log(DEBUG,"Whole header not read!");
                return std::make_pair(-1,"");
+       }
 
        /* Check wether the reply came from a different DNS
         * server to the one we sent it to, or the source-port
@@ -535,8 +554,17 @@ DNSResult DNS::GetResult()
        port_from = ntohs(((sockaddr_in*)&from)->sin_port);
 #endif
 
-       if ((port_from != DNS::QUERY_PORT) || (strcasecmp(ipaddr_from, Config->DNSServer)))
-               return std::make_pair(-1,"");
+       /* We cant perform this security check if you're using 4in6.
+        * Tough luck to you, choose one or't other!
+        */
+       if (!ip6munge)
+       {
+               if ((port_from != DNS::QUERY_PORT) || (strcasecmp(ipaddr_from, Config->DNSServer)))
+               {
+                       log(DEBUG,"port %d is not 53, or %s is not %s",port_from, ipaddr_from, Config->DNSServer);
+                       return std::make_pair(-1,"");
+               }
+       }
 
        /* Put the read header info into a header class */
        DNS::FillHeader(&header,buffer,length - 12);
@@ -617,6 +645,14 @@ DNSResult DNS::GetResult()
                                                memmove(formatted,formatted + 1, strlen(formatted + 1) + 1);
                                }
                                resultstr = formatted;
+
+                               /* Special case. Sending ::1 around between servers
+                                * and to clients is dangerous, because the : on the
+                                * start makes the client or server interpret the IP
+                                * as the last parameter on the line with a value ":1".
+                                */
+                               if (*formatted == ':')
+                                       resultstr = "0" + resultstr;
                        }
                        break;