2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2007-09-03 17:47:08 +02:00
|
|
|
|
2003-08-31 10:24:06 +02:00
|
|
|
=head1 NAME
|
|
|
|
|
2006-12-18 11:45:25 +01:00
|
|
|
check_badmailfrom - checks the badmailfrom config, with per-line reasons
|
2003-08-31 10:24:06 +02:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Reads the "badmailfrom" configuration like qmail-smtpd does. From the
|
|
|
|
qmail-smtpd docs:
|
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
"Unacceptable envelope sender addresses. qmail-smtpd will reject every
|
2003-08-31 10:24:06 +02:00
|
|
|
recipient address for a message if the envelope sender address is
|
2012-04-26 10:52:21 +02:00
|
|
|
listed in badmailfrom. A line in badmailfrom may be of the form
|
2003-08-31 10:24:06 +02:00
|
|
|
@host, meaning every address at host."
|
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
You may include an optional message after the sender address (leave a space),
|
|
|
|
to be used when rejecting the sender.
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
=head2 reject
|
|
|
|
|
|
|
|
badmailfrom reject [ 0 | 1 | naughty ]
|
|
|
|
|
|
|
|
I<0> will not reject any connections.
|
|
|
|
|
|
|
|
I<1> will reject naughty senders.
|
|
|
|
|
|
|
|
I<connect> is the most efficient setting. It's also the default.
|
|
|
|
|
|
|
|
To reject at any other connection hook, use the I<naughty> setting and the
|
|
|
|
B<naughty> plugin.
|
2012-04-26 10:52:21 +02:00
|
|
|
|
|
|
|
=head1 PATTERNS
|
|
|
|
|
|
|
|
This plugin also supports regular expression matches. This allows
|
|
|
|
special patterns to be denied (e.g. FQDN-VERP, percent hack, bangs,
|
|
|
|
double ats).
|
|
|
|
|
|
|
|
Patterns are stored in the format pattern(\s+)response, where pattern
|
|
|
|
is a Perl pattern expression. Don't forget to anchor the pattern
|
|
|
|
(front ^ and back $) if you want to restrict it from matching
|
|
|
|
anywhere in the string.
|
|
|
|
|
|
|
|
^streamsendbouncer@.*\.mailengine1\.com$ Your right-hand side VERP doesn't fool me
|
2013-03-25 06:46:34 +01:00
|
|
|
^return.*@.*\.pidplate\.biz$ I don't want it regardless of subdomain
|
2012-04-26 10:52:21 +02:00
|
|
|
^admin.*\.ppoonn400\.com$
|
|
|
|
|
2006-12-18 11:45:25 +01:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
=head1 AUTHORS
|
2009-06-24 07:28:37 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
2002 - Jim Winstead - initial author of badmailfrom
|
2003-08-31 10:24:06 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
2010 - Johan Almqvist <johan-qpsmtpd@almqvist.net> - pattern matching plugin
|
2002-09-10 19:17:15 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
2012 - Matt Simerson - merging of the two and plugin tests
|
2002-09-10 19:17:15 +02:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
=cut
|
2002-09-10 19:17:15 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
sub register {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $qp) = (shift, shift);
|
|
|
|
$self->{_args} = {@_};
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
$self->{_args}{reject} = 1 if !defined $self->{_args}{reject};
|
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
sub hook_mail {
|
|
|
|
my ($self, $transaction, $sender, %param) = @_;
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
return DECLINED if $self->is_immune();
|
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
my @badmailfrom = $self->qp->config('badmailfrom');
|
2013-04-21 06:50:39 +02:00
|
|
|
if (defined $self->{_badmailfrom_config}) { # testing
|
2012-04-26 10:52:21 +02:00
|
|
|
@badmailfrom = @{$self->{_badmailfrom_config}};
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
|
|
|
return DECLINED if $self->is_immune_sender($sender, \@badmailfrom);
|
2012-04-26 10:52:21 +02:00
|
|
|
|
|
|
|
my $host = lc $sender->host;
|
|
|
|
my $from = lc($sender->user) . '@' . $host;
|
|
|
|
|
|
|
|
for my $config (@badmailfrom) {
|
2013-04-21 06:50:39 +02:00
|
|
|
$config =~ s/^\s+//g; # trim leading whitespace
|
2012-04-26 10:52:21 +02:00
|
|
|
my ($bad, $reason) = split /\s+/, $config, 2;
|
|
|
|
next unless $bad;
|
2013-04-21 06:50:39 +02:00
|
|
|
next unless $self->is_match($from, $bad, $host);
|
2012-04-26 10:52:21 +02:00
|
|
|
$reason ||= "Your envelope sender is in my badmailfrom list";
|
2013-04-21 06:50:39 +02:00
|
|
|
$self->adjust_karma(-1);
|
|
|
|
return $self->get_reject($reason);
|
2012-04-26 10:52:21 +02:00
|
|
|
}
|
2012-06-23 02:03:47 +02:00
|
|
|
|
|
|
|
$self->log(LOGINFO, "pass");
|
2012-04-26 10:52:21 +02:00
|
|
|
return DECLINED;
|
2002-09-10 13:00:31 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
sub is_match {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $from, $bad, $host) = @_;
|
2012-04-26 10:52:21 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($bad =~ /[\/\^\$\*\+\!\%\?\\]/) { # it's a regexp
|
|
|
|
if ($from =~ /$bad/) {
|
2012-06-23 02:03:47 +02:00
|
|
|
$self->log(LOGDEBUG, "badmailfrom pattern ($bad) match for $from");
|
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-04-26 10:52:21 +02:00
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-04-26 10:52:21 +02:00
|
|
|
|
|
|
|
$bad = lc $bad;
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($bad !~ m/\@/) {
|
2012-04-26 10:52:21 +02:00
|
|
|
$self->log(LOGWARN, "badmailfrom: bad config: no \@ sign in $bad");
|
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
|
|
|
if (substr($bad, 0, 1) eq '@') {
|
2012-04-26 10:52:21 +02:00
|
|
|
return 1 if $bad eq "\@$host";
|
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-04-26 10:52:21 +02:00
|
|
|
return if $bad ne $from;
|
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-04-26 10:52:21 +02:00
|
|
|
|
2012-06-03 03:44:46 +02:00
|
|
|
sub is_immune_sender {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $sender, $badmf) = @_;
|
2012-05-05 06:27:16 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!scalar @$badmf) {
|
2012-06-23 02:03:47 +02:00
|
|
|
$self->log(LOGDEBUG, 'skip, empty list');
|
2012-05-05 06:27:16 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-05 06:27:16 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!$sender || $sender->format eq '<>') {
|
2012-06-23 02:03:47 +02:00
|
|
|
$self->log(LOGDEBUG, 'skip, null sender');
|
2012-05-05 06:27:16 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-05 06:27:16 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!$sender->host || !$sender->user) {
|
2012-06-23 02:03:47 +02:00
|
|
|
$self->log(LOGDEBUG, 'skip, missing user or host');
|
2012-05-05 06:27:16 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-05 06:27:16 +02:00
|
|
|
|
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|