2005-03-08 23:58:09 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use Danga::DNS;
|
|
|
|
|
2005-12-22 22:30:53 +01:00
|
|
|
sub hook_mail {
|
2002-07-08 04:30:11 +02:00
|
|
|
my ($self, $transaction, $sender) = @_;
|
2004-08-01 03:54:16 +02:00
|
|
|
|
|
|
|
my %rhsbl_zones_map = ();
|
|
|
|
|
|
|
|
# Perform any RHS lookups in the background. We just send the query packets here
|
|
|
|
# and pick up any results in the RCPT handler.
|
2002-07-15 14:16:10 +02:00
|
|
|
# MTAs gets confused when you reject mail during MAIL FROM:
|
2004-08-01 03:54:16 +02:00
|
|
|
|
2005-03-08 23:58:09 +01:00
|
|
|
my %rhsbl_zones = map { (split /\s+/, $_, 2)[0,1] } $self->config('rhsbl_zones');
|
2004-08-01 03:54:16 +02:00
|
|
|
|
|
|
|
if ($sender->format ne '<>' and %rhsbl_zones) {
|
2005-03-08 23:58:09 +01:00
|
|
|
my $helo = $self->connection->hello_host;
|
2004-08-01 03:54:16 +02:00
|
|
|
push(my @hosts, $sender->host);
|
|
|
|
push(@hosts, $helo) if $helo && $helo ne $sender->host;
|
|
|
|
for my $host (@hosts) {
|
2005-03-08 23:58:09 +01:00
|
|
|
for my $rhsbl (keys %rhsbl_zones) {
|
2004-08-01 03:54:16 +02:00
|
|
|
$self->log(LOGDEBUG, "Checking $host.$rhsbl for A record in the background");
|
2005-03-08 23:58:09 +01:00
|
|
|
Danga::DNS->new(
|
|
|
|
callback => sub { $self->process_result($host, $rhsbl_zones{$rhsbl}, @_) },
|
|
|
|
host => "$host.$rhsbl",
|
2005-03-09 00:34:51 +01:00
|
|
|
client => $self->qp->input_sock,
|
2005-03-08 23:58:09 +01:00
|
|
|
);
|
|
|
|
}
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
2004-08-01 03:54:16 +02:00
|
|
|
} else {
|
|
|
|
$self->log(LOGDEBUG, 'no RHS checks necessary');
|
|
|
|
}
|
|
|
|
|
2002-09-08 16:15:21 +02:00
|
|
|
return DECLINED;
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
|
|
|
|
2005-03-08 23:58:09 +01:00
|
|
|
sub process_result {
|
|
|
|
my ($self, $host, $template, $result, $query) = @_;
|
|
|
|
|
|
|
|
if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) {
|
|
|
|
# NXDOMAIN or error
|
|
|
|
return;
|
2004-08-01 03:54:16 +02:00
|
|
|
}
|
2005-03-08 23:58:09 +01:00
|
|
|
|
|
|
|
my $tran = $self->transaction;
|
|
|
|
return if $tran->notes('rhsbl');
|
|
|
|
if ($host eq $tran->sender->host) {
|
|
|
|
$tran->notes('rhsbl', "Mail from $host rejected because it $template");
|
2004-08-01 03:54:16 +02:00
|
|
|
}
|
2005-03-08 23:58:09 +01:00
|
|
|
else {
|
|
|
|
$tran->notes('rhsbl', "Mail from HELO $host rejected because it $template");
|
2004-08-01 03:54:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-22 22:30:53 +01:00
|
|
|
sub hook_rcpt {
|
2005-03-08 23:58:09 +01:00
|
|
|
my ($self, $transaction, $rcpt) = @_;
|
2004-08-01 03:54:16 +02:00
|
|
|
|
2005-03-08 23:58:09 +01:00
|
|
|
my $result = $transaction->notes('rhsbl');
|
|
|
|
return (DENY, $result) if $result;
|
2004-08-01 03:54:16 +02:00
|
|
|
return DECLINED;
|
|
|
|
}
|