diff src/dnsbl.cpp @ 23:06de5ab6a232

add url decoding stage, allow http:/ single / in yahoo redirector, allow ip address hostnames
author carl
date Wed, 12 May 2004 13:23:22 -0700
parents c21b888cc175
children 2e23b7184d2b
line wrap: on
line diff
--- a/src/dnsbl.cpp	Sat May 01 07:44:51 2004 -0700
+++ b/src/dnsbl.cpp	Wed May 12 13:23:22 2004 -0700
@@ -359,16 +359,16 @@
 //  caller must ensure thread safety.
 //
 //
-static int dns_interface(char *question);
-static int dns_interface(char *question) {
+static int dns_interface(char *question, bool maybe_ip);
+static int dns_interface(char *question, bool maybe_ip) {
 #ifdef NS_PACKETSZ
     u_char answer[NS_PACKETSZ];
     int length = res_search(question, ns_c_in, ns_t_a, answer, sizeof(answer));
-    if (length < 0) return 0;   // error in getting answer
+    if (length >= 0) {  // no error yet
     // parse the answer
     ns_msg handle;
     ns_rr  rr;
-    if (ns_initparse(answer, length, &handle) != 0) return 0;
+        if (ns_initparse(answer, length, &handle) == 0) {
     int rrnum = 0;
     while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) {
         if (ns_rr_type(rr) == ns_t_a) {
@@ -377,6 +377,15 @@
             return address;
         }
     }
+        }
+    }
+    if (maybe_ip) {
+        // might be a bare ip address
+        in_addr ip;
+        if (inet_aton(question, &ip)) {
+            return ip.s_addr;
+        }
+    }
     return 0;
 #else
     struct hostent *host = gethostbyname(question);
@@ -388,11 +397,11 @@
 #endif
 }
 
-static int protected_dns_interface(char *question);
-static int protected_dns_interface(char *question) {
+static int protected_dns_interface(char *question, bool maybe_ip);
+static int protected_dns_interface(char *question, bool maybe_ip) {
     int ans;
     pthread_mutex_lock(&resolve_mutex);
-        ans = dns_interface(question);
+        ans = dns_interface(question, maybe_ip);
     pthread_mutex_unlock(&resolve_mutex);
     return ans;
 
@@ -413,7 +422,7 @@
 #endif
     snprintf(question, sizeof(question), "%u.%u.%u.%u.%s.", src[3], src[2], src[1], src[0], suffix);
     // ask the question, if we get an A record it implies a blacklisted ip address
-    return (protected_dns_interface(question)) ? reject : oksofar;
+    return (protected_dns_interface(question, false)) ? reject : oksofar;
 }
 
 
@@ -471,7 +480,7 @@
             snprintf(buf, sizeof(buf), "looking for host %s", host);
             my_syslog(buf);
         }
-        ip  = protected_dns_interface(host);
+        ip  = protected_dns_interface(host, true);
         if (ip) {
             if (debug_syslog) {
                 char adr[sizeof "255.255.255.255"];