diff src/dnsbl.cpp @ 134:f9917ce924a3

all dns lookups fully qualified, my_read() bug fix
author carl
date Wed, 02 Aug 2006 21:06:05 -0700
parents ae9daf43d8eb
children f4746d8a12a3
line wrap: on
line diff
--- a/src/dnsbl.cpp	Tue Aug 01 15:28:13 2006 -0700
+++ b/src/dnsbl.cpp	Wed Aug 02 21:06:05 2006 -0700
@@ -346,7 +346,7 @@
 int mlfiPriv::my_read(char *buf, int len) {
 	if (err) return 0;
 	int rs = 0;
-	while (len > 1) {
+	while (len) {
 		int ws = read(fd, buf, len);
 		if (ws > 0) {
 			rs	+= ws;
@@ -504,7 +504,21 @@
 	// milter thread is talking over its own socket to a separate resolver
 	// process, which does the actual dns resolution.
 	if (priv.err) return 0; // cannot ask more questions on this socket.
-	priv.my_write(question, strlen(question)+1);   // write the question including the null terminator
+	if (maybe_ip) {
+		// might be a bare ip address, try this first to avoid dns lookups that may not be needed
+		in_addr ip;
+		if (inet_aton(question, &ip)) {
+			return (int)ip.s_addr;
+		}
+	}
+	int n = strlen(question);
+	if (question[n-1] == '.') {
+		priv.my_write(question, n+1);	// write the question including the null terminator
+	}
+	else {
+		priv.my_write(question, n); 	// write the question
+		priv.my_write(".", 2);          // and the fully qualified . terminator and null string terminator
+	}
 	glommer glom;
 	char *buf = (char *)&glom;
 	priv.my_read(buf, sizeof(glom.length));
@@ -586,13 +600,6 @@
 				}
 			}
 		}
-		if (maybe_ip && !ret_address) {
-			// might be a bare ip address
-			in_addr ip;
-			if (inet_aton(question, &ip)) {
-				ret_address = ip.s_addr;
-			}
-		}
 	pthread_mutex_unlock(&resolve_mutex);
 	return ret_address;
 #else
@@ -658,7 +665,7 @@
 
 
 ////////////////////////////////////////////////
-//	lookup the domain name part of a hostname on two lists
+//	lookup the domain name part of a hostname on the uribl
 //
 //	if we find part of the hostname on the uribl, return
 //	true and point found to the part of the hostname that we found.