diff src/dnsbl.cpp @ 119:d9d2f8699621

uribl patch from Jeff Evans <jeffe@tricab.com>
author carl
date Sun, 12 Mar 2006 12:38:43 -0800
parents aa07452e641b
children 1d9e6c1b8872
line wrap: on
line diff
--- a/src/dnsbl.cpp	Sun Mar 12 10:20:59 2006 -0800
+++ b/src/dnsbl.cpp	Sun Mar 12 12:38:43 2006 -0800
@@ -232,6 +232,8 @@
 	scanner 			= NULL;
 	content_suffix		= NULL;
 	content_message 	= NULL;
+	uribl_suffix		= NULL;
+	uribl_message		= NULL;
 	content_host_ignore = NULL;
 }
 
@@ -259,6 +261,8 @@
 		scanner 			= NULL;
 		content_suffix		= NULL;
 		content_message 	= NULL;
+		uribl_suffix		= NULL;
+		uribl_message		= NULL;
 		content_host_ignore = NULL;
 	}
 }
@@ -369,6 +373,8 @@
 		scanner 	  = new url_scanner(memory);
 		content_suffix		= con.get_content_suffix();
 		content_message 	= con.get_content_message();
+		uribl_suffix		= con.get_uribl_suffix();
+		uribl_message		= con.get_uribl_message();
 		content_host_ignore = &con.get_content_host_ignore();
 	}
 }
@@ -669,14 +675,14 @@
 		if (x) hostname = x+1;
 		*top = '.';
 	}
-	for (int i=0; i<2; i++) {
-		snprintf(buf, sizeof(buf), "%s.%s", hostname, uriblname[i]);
+	snprintf(buf, sizeof(buf), "%s.%s", hostname, priv.uribl_suffix);
+	if (dns_interface(priv, buf, false, NULL)) {
 		if (debug_syslog > 2) {
 			char tmp[maxlen];
-			snprintf(tmp, sizeof(tmp), "Looking up %s on %s", hostname, uriblname[i]);
+			snprintf(tmp, sizeof(tmp), "found %s on %s", hostname, priv.uribl_suffix);
 			my_syslog(tmp);
 		}
-		if (dns_interface(priv, buf, false, NULL)) return true;
+		return true;
 	}
 	return false;
 }
@@ -727,14 +733,14 @@
 
 
 ////////////////////////////////////////////////
-//	check the hosts from the body against the content dnsbl
+//	check the hosts from the body against the content filter and uribl dnsbls
 //
-bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int &ip);
-bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int &ip) {
+bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip);
+bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip) {
+	if (!priv.content_suffix && !priv.uribl_suffix) return false;	// nothing to check
 	CONFIG	   &dc	   = *priv.pc;
 	string_set &hosts  = priv.memory->get_hosts();
 	string_set &ignore = *priv.content_host_ignore;
-	char	   *suffix = priv.content_suffix;
 
 	int count = 0;
 	int   cnt = hosts.size();	// number of hosts we could look at
@@ -779,19 +785,22 @@
 			if (i == ips.end()) {
 				// we haven't looked this up yet
 				ips.insert(ip);
-				if (check_single(priv, ip, suffix)) return true;
+				if (check_single(priv, ip, priv.content_suffix)) {
+					msg = priv.content_message;
+					return true;
+				}
 				// Check uribl & surbl
-				if (check_uribl(priv, host)) return true;
+				if (check_uribl(priv, host)) {
+					msg = priv.uribl_message;
+					return true;
+				}
 			}
 		}
 	}
 	limit *= 4;   // allow average of 3 ns per host name
 	for (ns_mapper::iterator i=nameservers.ns_ip.begin(); i!=nameservers.ns_ip.end(); i++) {
 		count++;
-		if ((count > limit) && (limit > 0)) {
-			if (random) continue; // don't complain
-			return true;
-		}
+		if ((count > limit) && (limit > 0)) return false;	// too many name servers to check them all
 		host = (*i).first;	// a transient reference that needs to be replaced before we return it
 		ip	 = (*i).second;
 		if (!ip) ip = dns_interface(priv, host, false, NULL);
@@ -812,7 +821,8 @@
 			int_set::iterator i = ips.find(ip);
 			if (i == ips.end()) {
 				ips.insert(ip);
-				if (check_single(priv, ip, suffix)) {
+				if (check_single(priv, ip, priv.content_suffix)) {
+					msg = priv.content_message;
 					string_map::iterator j = nameservers.ns_host.find(host);
 					if (j != nameservers.ns_host.end()) {
 						char *refer = (*j).second;
@@ -985,11 +995,12 @@
 		}
 		bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content()
 		if (!rejecting) {
-			if (check_hosts(priv, random, limit, host, ip)) {
+			char *msg;
+			if (check_hosts(priv, random, limit, msg, host, ip)) {
 				char adr[sizeof "255.255.255.255"];
 				adr[0] = '\0';
 				inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
-				snprintf(buf, sizeof(buf), priv.content_message, host, adr);
+				snprintf(buf, sizeof(buf), msg, host, adr);
 				msg = buf;
 				rejecting = true;
 			}