2005-03-08 23:58:09 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use Danga::DNS;
|
2002-07-08 04:30:11 +02:00
|
|
|
|
|
|
|
sub register {
|
2005-03-08 23:58:09 +01:00
|
|
|
my ($self) = @_;
|
|
|
|
$self->register_hook("mail", "mail_handler");
|
|
|
|
$self->register_hook("rcpt", "rcpt_handler");
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub mail_handler {
|
2005-03-08 23:58:09 +01:00
|
|
|
my ($self, $transaction, $sender) = @_;
|
|
|
|
|
|
|
|
$sender->format ne "<>" and $self->check_dns($sender->host);
|
|
|
|
|
|
|
|
return DECLINED;
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub check_dns {
|
2005-03-08 23:58:09 +01:00
|
|
|
my ($self, $host) = @_;
|
|
|
|
|
|
|
|
# for stuff where we can't even parse a hostname out of the address
|
|
|
|
return unless $host;
|
|
|
|
|
|
|
|
return $self->transaction->notes('resolvable', 1)
|
|
|
|
if $host =~ m/^\[(\d{1,3}\.){3}\d{1,3}\]$/;
|
|
|
|
|
|
|
|
Danga::DNS->new(
|
|
|
|
callback => sub { $self->dns_result(@_) },
|
|
|
|
host => $host,
|
|
|
|
type => "MX",
|
|
|
|
client => $self->argh->input_sock,
|
|
|
|
);
|
|
|
|
Danga::DNS->new(
|
|
|
|
callback => sub { $self->dns_result(@_) },
|
|
|
|
host => $host,
|
|
|
|
client => $self->argh->input_sock,
|
|
|
|
);
|
|
|
|
}
|
2002-07-08 04:30:11 +02:00
|
|
|
|
2005-03-08 23:58:09 +01:00
|
|
|
sub dns_result {
|
|
|
|
my ($self, $result, $query) = @_;
|
|
|
|
|
|
|
|
if ($result =~ /^[A-Z]+$/) {
|
|
|
|
# probably an error
|
|
|
|
$self->log(LOGDEBUG, "DNS error: $result looking up $query");
|
|
|
|
return;
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
2005-03-08 23:58:09 +01:00
|
|
|
|
|
|
|
$self->log(LOGDEBUG, "DNS lookup $query returned: $result");
|
|
|
|
$self->transaction->notes('resolvable', 1);
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
|
|
|
|
2005-03-08 23:58:09 +01:00
|
|
|
sub rcpt_handler {
|
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
if (!$transaction->notes('resolvable')) {
|
|
|
|
my $sender = $transaction->sender;
|
|
|
|
return (DENYSOFT,
|
|
|
|
($sender->host
|
|
|
|
? "Could not resolve ". $sender->host
|
|
|
|
: "FQDN required in the envelope sender"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return DECLINED;
|
|
|
|
}
|