2012-06-22 11:38:01 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use Qpsmtpd::Plugin::Async::DNSBLBase;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my ($self, $qp, %args) = @_;
|
|
|
|
my $class = ref $self;
|
|
|
|
|
|
|
|
$self->isa_plugin("uribl");
|
|
|
|
{
|
|
|
|
no strict 'refs';
|
|
|
|
push @{"${class}::ISA"}, 'Qpsmtpd::Plugin::Async::DNSBLBase';
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->SUPER::init($qp, %args);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub register {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->register_hook('data_post', 'start_data_post');
|
|
|
|
$self->register_hook('data_post', 'finish_data_post');
|
|
|
|
}
|
|
|
|
|
|
|
|
sub start_data_post {
|
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
my $class = ref $self;
|
|
|
|
|
|
|
|
my @names;
|
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
my $queries = $self->lookup_start(
|
|
|
|
$transaction,
|
|
|
|
sub {
|
|
|
|
my ($self, $name) = @_;
|
|
|
|
push @names, $name;
|
|
|
|
}
|
|
|
|
);
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
my @hosts;
|
|
|
|
foreach my $z (keys %{$self->{uribl_zones}}) {
|
|
|
|
push @hosts, map { "$_.$z" } @names;
|
|
|
|
}
|
|
|
|
|
|
|
|
$transaction->notes(uribl_results => {});
|
2013-04-21 06:50:39 +02:00
|
|
|
$transaction->notes(uribl_zones => $self->{uribl_zones});
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
return DECLINED
|
2013-04-21 06:50:39 +02:00
|
|
|
unless @hosts && $class->lookup($self->qp, [@hosts], [@hosts]);
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
return YIELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub finish_data_post {
|
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
my $matches = $self->collect_results($transaction);
|
|
|
|
for (@$matches) {
|
|
|
|
$self->log(LOGWARN, $_->{desc});
|
|
|
|
if ($_->{action} eq 'add-header') {
|
|
|
|
$transaction->header->add('X-URIBL-Match', $_->{desc});
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
|
|
|
elsif ($_->{action} eq 'deny') {
|
2012-06-22 11:38:01 +02:00
|
|
|
return (DENY, $_->{desc});
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
|
|
|
elsif ($_->{action} eq 'denysoft') {
|
2012-06-22 11:38:01 +02:00
|
|
|
return (DENYSOFT, $_->{desc});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DECLINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub init_resolver { }
|
|
|
|
|
|
|
|
sub process_a_result {
|
|
|
|
my ($class, $qp, $result, $query) = @_;
|
|
|
|
|
|
|
|
my $transaction = $qp->transaction;
|
2013-04-21 06:50:39 +02:00
|
|
|
my $results = $transaction->notes('uribl_results');
|
|
|
|
my $zones = $transaction->notes('uribl_zones');
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
foreach my $z (keys %$zones) {
|
|
|
|
if ($query =~ /^(.*)\.$z$/) {
|
|
|
|
my $name = $1;
|
|
|
|
$results->{$z}->{$name}->{a} = $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_txt_result {
|
|
|
|
my ($class, $qp, $result, $query) = @_;
|
|
|
|
|
|
|
|
my $transaction = $qp->transaction;
|
2013-04-21 06:50:39 +02:00
|
|
|
my $results = $transaction->notes('uribl_results');
|
|
|
|
my $zones = $transaction->notes('uribl_zones');
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
foreach my $z (keys %$zones) {
|
|
|
|
if ($query =~ /^(.*)\.$z$/) {
|
|
|
|
my $name = $1;
|
|
|
|
$results->{$z}->{$name}->{txt} = $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub collect_results {
|
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
my $results = $transaction->notes('uribl_results');
|
|
|
|
|
|
|
|
my @matches;
|
|
|
|
foreach my $z (keys %$results) {
|
|
|
|
foreach my $n (keys %{$results->{$z}}) {
|
|
|
|
if (exists $results->{$z}->{$n}->{a}) {
|
|
|
|
if ($self->evaluate($z, $results->{$z}->{$n}->{a})) {
|
|
|
|
$self->log(LOGDEBUG, "match $n in $z");
|
2013-04-21 06:50:39 +02:00
|
|
|
push @matches,
|
|
|
|
{
|
2012-06-22 11:38:01 +02:00
|
|
|
action => $self->{uribl_zones}->{$z}->{action},
|
2013-04-21 06:50:39 +02:00
|
|
|
desc => "$n in $z: "
|
|
|
|
. (
|
|
|
|
$results->{$z}->{$n}->{txt}
|
|
|
|
|| $results->{$z}->{$n}->{a}
|
|
|
|
),
|
|
|
|
};
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return \@matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
uribl - URIBL blocking plugin for qpsmtpd
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This plugin implements DNSBL lookups for URIs found in spam, such as that
|
|
|
|
implemented by SURBL (see E<lt>http://surbl.org/E<gt>). Incoming messages are
|
|
|
|
scanned for URIs, which are then checked against one or more URIBLs in a
|
|
|
|
fashion similar to DNSBL systems.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
See the documentation of the non-async version. The timeout config option is
|
|
|
|
ignored, the ParaDNS timeout is used instead.
|
|
|
|
|
|
|
|
=cut
|