git-svn-id: https://svn.perl.org/qpsmtpd/trunk@920 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Radu Greab 2008-06-02 15:41:30 +00:00 committed by Ask Bjørn Hansen
parent d63102cd7e
commit 7f07f16a44

View File

@ -18,10 +18,13 @@ sub hook_connect {
my $remote_ip = $self->connection->remote_ip; my $remote_ip = $self->connection->remote_ip;
my $allow = grep { s/\.?$/./; $_ eq substr($remote_ip . '.', 0, length $_) } $self->qp->config('dnsbl_allow'); my $allow =
grep { s/\.?$/./; $_ eq substr($remote_ip . '.', 0, length $_) }
$self->qp->config('dnsbl_allow');
return DECLINED if $allow; return DECLINED if $allow;
my %dnsbl_zones = map { (split /:/, $_, 2)[0,1] } $self->qp->config('dnsbl_zones'); my %dnsbl_zones =
map { (split /:/, $_, 2)[0, 1] } $self->qp->config('dnsbl_zones');
return DECLINED unless %dnsbl_zones; return DECLINED unless %dnsbl_zones;
my $reversed_ip = join(".", reverse(split(/\./, $remote_ip))); my $reversed_ip = join(".", reverse(split(/\./, $remote_ip)));
@ -29,18 +32,25 @@ sub hook_connect {
my $total_zones = keys %dnsbl_zones; my $total_zones = keys %dnsbl_zones;
my $qp = $self->qp; my $qp = $self->qp;
for my $dnsbl (keys %dnsbl_zones) { for my $dnsbl (keys %dnsbl_zones) {
# fix to find A records, if the dnsbl_zones line has a second field 20/1/04 ++msp # fix to find A records, if the dnsbl_zones line has a second field 20/1/04 ++msp
if (defined($dnsbl_zones{$dnsbl})) { if (defined($dnsbl_zones{$dnsbl})) {
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for A record in the background"); $self->log(LOGDEBUG,
"Checking $reversed_ip.$dnsbl for A record in the background");
ParaDNS->new( ParaDNS->new(
callback => sub { process_a_result($qp, $dnsbl_zones{$dnsbl}, @_) }, callback => sub {
process_a_result($qp, $dnsbl_zones{$dnsbl}, @_);
},
finished => sub { $total_zones--; finished($qp, $total_zones) }, finished => sub { $total_zones--; finished($qp, $total_zones) },
host => "$reversed_ip.$dnsbl", host => "$reversed_ip.$dnsbl",
type => 'A', type => 'A',
client => $self->qp->input_sock, client => $self->qp->input_sock,
); );
} else { }
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for TXT record in the background"); else {
$self->log(LOGDEBUG,
"Checking $reversed_ip.$dnsbl for TXT record in the background"
);
ParaDNS->new( ParaDNS->new(
callback => sub { process_txt_result($qp, @_) }, callback => sub { process_txt_result($qp, @_) },
finished => sub { $total_zones--; finished($qp, $total_zones) }, finished => sub { $total_zones--; finished($qp, $total_zones) },
@ -65,6 +75,7 @@ sub process_a_result {
$qp->log(LOGINFO, "Result for A $query: $result"); $qp->log(LOGINFO, "Result for A $query: $result");
if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) { if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) {
# NXDOMAIN or ERROR possibly... # NXDOMAIN or ERROR possibly...
return; return;
} }
@ -80,6 +91,7 @@ sub process_txt_result {
$qp->log(LOGINFO, "Result for TXT $query: $result"); $qp->log(LOGINFO, "Result for TXT $query: $result");
if ($result !~ /[a-z]/) { if ($result !~ /[a-z]/) {
# NXDOMAIN or ERROR probably... # NXDOMAIN or ERROR probably...
return; return;
} }