diff src/dnsbl.cpp @ 124:ea6f9c812faa stable-5-16

put hostname in smtp message for uribl style lookups
author carl
date Thu, 16 Mar 2006 15:20:37 -0800
parents ecd97e7eb1f0
children 05ae49d37896
line wrap: on
line diff
--- a/src/dnsbl.cpp	Wed Mar 15 08:21:51 2006 -0800
+++ b/src/dnsbl.cpp	Thu Mar 16 15:20:37 2006 -0800
@@ -658,16 +658,17 @@
 ////////////////////////////////////////////////
 //	lookup the domain name part of a hostname on two lists
 //
-bool uriblookup(mlfiPriv &priv ,char *hostname, char *top) ;
-bool uriblookup(mlfiPriv &priv, char *hostname, char *top) {
+//	if we find part of the hostname on the uribl, return
+//	true and point found to the part of the hostname that we found.
+//	otherwise, return false and preserve the value of found.
+//
+bool uriblookup(mlfiPriv &priv ,char *hostname, char *top, char *&found) ;
+bool uriblookup(mlfiPriv &priv, char *hostname, char *top, char *&found) {
 	// top is pointer to '.' char at end of base domain, or null for ip address form
 	// so for hostname of www.fred.mydomain.co.uk
 	// top points to-----------------------^
 	// and we end up looking at only mydomain.co.uk, ignoring the www.fred stuff
 	char buf[maxlen];
-	char buf2[maxlen];
-	const char *uriblname[2] = { "multi.surbl.org", "multi.uribl.com" };
-
 	if (top) {
 		// add one more component
 		*top = '\0';
@@ -682,6 +683,7 @@
 			snprintf(tmp, sizeof(tmp), "found %s on %s", hostname, priv.uribl_suffix);
 			my_syslog(tmp);
 		}
+		found = hostname;
 		return true;
 	}
 	return false;
@@ -694,14 +696,19 @@
 // hostname MUST not have a trailing dot
 // If tld, two level lookup.
 // Else, look up three level domain.
-bool check_uribl(mlfiPriv &priv, char *hostname) ;
-bool check_uribl(mlfiPriv &priv, char *hostname) {
+//
+//	if we find part of the hostname on the uribl, return
+//	true and point found to the part of the hostname that we found.
+//	otherwise, return false and preserve the value of found.
+//
+bool check_uribl(mlfiPriv &priv, char *hostname, char *&found) ;
+bool check_uribl(mlfiPriv &priv, char *hostname, char *&found) {
 	in_addr ip;
 	if (inet_aton(hostname, &ip)) {
 		const u_char *src = (const u_char *)&ip.s_addr;
-		char adr[sizeof "255.255.255.255"];
+		static char adr[sizeof "255.255.255.255"];
 		snprintf(adr, sizeof(adr), "%u.%u.%u.%u", src[3], src[2], src[1], src[0]);
-		return (uriblookup(priv, adr, NULL));
+		return (uriblookup(priv, adr, NULL, found));
 	}
 
 	char *top, *top2, *top3;
@@ -715,18 +722,18 @@
 			string_set::iterator i = priv.memory->get_cctlds()->find(top2+1);
 			string_set::iterator x = priv.memory->get_cctlds()->end();
 			// if we have a 2-level-cctld, just look at top three levels of the name
-			if (i != x) return uriblookup(priv, hostname, top2);
+			if (i != x) return uriblookup(priv, hostname, top2, found);
 
 			*top2 = '\0';
 			top3 = strrchr(hostname, '.');
 			*top2 = '.';
 
 			// if we have more than 3 levels in the name, look at the top three levels of the name
-			if (top3 && uriblookup(priv, hostname, top2)) return true;
+			if (top3 && uriblookup(priv, hostname, top2, found)) return true;
 			// if that was not found, fall thru to looking at the top two levels
 		}
 		// look at the top two levels of the name
-		return uriblookup(priv, hostname, top);
+		return uriblookup(priv, hostname, top, found);
 	}
 	return false;
 }
@@ -735,8 +742,10 @@
 ////////////////////////////////////////////////
 //	check the hosts from the body against the content filter and uribl dnsbls
 //
-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) {
+//
+bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip, char *&found);
+bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip, char *&found) {
+	found = NULL;	// normally ip address style
 	if (!priv.content_suffix && !priv.uribl_suffix) return false;	// nothing to check
 	CONFIG	   &dc	   = *priv.pc;
 	string_set &hosts  = priv.memory->get_hosts();
@@ -785,12 +794,13 @@
 			if (i == ips.end()) {
 				// we haven't looked this up yet
 				ips.insert(ip);
-				if (check_single(priv, ip, priv.content_suffix)) {
+				// check dnsbl style list
+				if (priv.content_suffix && check_single(priv, ip, priv.content_suffix)) {
 					msg = priv.content_message;
 					return true;
 				}
-				// Check uribl & surbl
-				if (check_uribl(priv, host)) {
+				// Check uribl & surbl style list
+				if (priv.uribl_suffix && check_uribl(priv, host, found)) {
 					msg = priv.uribl_message;
 					return true;
 				}
@@ -995,12 +1005,19 @@
 		}
 		bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content()
 		if (!rejecting) {
-			char *fmt;
-			if (check_hosts(priv, random, limit, fmt, host, ip)) {
+			char *fmt, *found;
+			if (check_hosts(priv, random, limit, fmt, host, ip, found)) {
+				if (found) {
+					// uribl style
+					snprintf(buf, sizeof(buf), fmt, host, found);
+				}
+				else {
+					// dnsbl style
 				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), fmt, host, adr);
+				}
 				msg = buf;
 				rejecting = true;
 			}