[svn:qpsmtpd] r683 - branches/0.3x/plugins

[email protected] Sat, 16 Dec 2006 01:46:13 -0800 (PST)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
Author: hjp
Date: Sat Dec 16 01:46:12 2006
New Revision: 683

Modified:
   branches/0.3x/plugins/dnsbl

Log:
Check if the domain name in a DNS response packet matches one of the
domain names we queried.
See the thread "dnsbl or spamhaus occassionally blocks wrong IP" 
starting at 14 Mar 2006 for details.


Modified: branches/0.3x/plugins/dnsbl
==============================================================================
--- branches/0.3x/plugins/dnsbl	(original)
+++ branches/0.3x/plugins/dnsbl	Sat Dec 16 01:46:12 2006
@@ -57,8 +57,10 @@
 
   my $sel = IO::Select->new();
 
+  my $dom;
   for my $dnsbl (keys %dnsbl_zones) {
     # fix to find A records, if the dnsbl_zones line has a second field 20/1/04 ++msp
+    $dom->{"$reversed_ip.$dnsbl"} = 1;
     if (defined($dnsbl_zones{$dnsbl})) {
       $self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for A record in the background");
       $sel->add($res->bgsend("$reversed_ip.$dnsbl"));
@@ -69,6 +71,7 @@
   }
 
   $self->qp->connection->notes('dnsbl_sockets', $sel);
+  $self->qp->connection->notes('dnsbl_domains', $dom);
 
   return DECLINED;
 }
@@ -88,6 +91,7 @@
   $res->udp_timeout(30);
 
   my $sel = $conn->notes('dnsbl_sockets') or return "";
+  my $dom = $conn->notes('dnsbl_domains');
   my $remote_ip = $self->qp->connection->remote_ip;
 
   my $result; 
@@ -110,11 +114,13 @@
     if ($query) {
       my $a_record = 0;
       foreach my $rr ($query->answer) {
-	$a_record = 1 if $rr->type eq "A";
 	my $name = $rr->name;
+	$self->log(LOGDEBUG, "name $name");
+	next unless $dom->{$name};
+	$self->log(LOGDEBUG, "name $name was queried");
+	$a_record = 1 if $rr->type eq "A";
 	($dnsbl) = ($name =~ m/(?:\d+\.){4}(.*)/) unless $dnsbl;
 	$dnsbl = $name unless $dnsbl;
-	$self->log(LOGDEBUG, "name ", $rr->name);
 	next unless $rr->type eq "TXT";
 	$self->log(LOGDEBUG, "got txt record");
 	$result = $rr->txtdata and last;