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.
|
|
|
|
|
|
|
|
|
|
|
|
=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
|
|
|
|
^return.*@.*\.pidplate\.biz$ I don' want it regardless of subdomain
|
|
|
|
^admin.*\.ppoonn400\.com$
|
|
|
|
|
2006-12-18 11:45:25 +01:00
|
|
|
|
2004-11-27 19:40:54 +01:00
|
|
|
=head1 NOTES
|
|
|
|
|
|
|
|
According to the SMTP protocol, we can't reject until after the RCPT
|
|
|
|
stage, so store it until later.
|
|
|
|
|
2002-09-10 13:00:31 +02:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
=head1 AUTHORS
|
2009-06-24 07:28:37 +02:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
initial author of badmailfrom - Jim Winstead
|
2003-08-31 10:24:06 +02:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
pattern matching plugin - Johan Almqvist <johan-qpsmtpd@almqvist.net>
|
2002-09-10 19:17:15 +02:00
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
merging of the two and plugin tests - Matt Simerson <matt@tnpi.net>
|
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-04-26 10:52:21 +02:00
|
|
|
sub hook_mail {
|
|
|
|
my ($self, $transaction, $sender, %param) = @_;
|
|
|
|
|
|
|
|
my @badmailfrom = $self->qp->config('badmailfrom');
|
|
|
|
if ( defined $self->{_badmailfrom_config} ) { # testing
|
|
|
|
@badmailfrom = @{$self->{_badmailfrom_config}};
|
|
|
|
};
|
|
|
|
|
|
|
|
return DECLINED if ! scalar @badmailfrom;
|
|
|
|
return DECLINED if $sender->format eq '<>';
|
|
|
|
return DECLINED if ! $sender->host || ! $sender->user;
|
|
|
|
|
|
|
|
my $host = lc $sender->host;
|
|
|
|
my $from = lc($sender->user) . '@' . $host;
|
|
|
|
|
|
|
|
for my $config (@badmailfrom) {
|
|
|
|
$config =~ s/^\s+//g; # trim any leading whitespace
|
|
|
|
my ($bad, $reason) = split /\s+/, $config, 2;
|
|
|
|
next unless $bad;
|
|
|
|
next unless $self->is_match( $from, $bad, $host );
|
|
|
|
$reason ||= "Your envelope sender is in my badmailfrom list";
|
|
|
|
$transaction->notes('badmailfrom', $reason);
|
|
|
|
}
|
|
|
|
return DECLINED;
|
2002-09-10 13:00:31 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
sub is_match {
|
|
|
|
my ( $self, $from, $bad, $host ) = @_;
|
|
|
|
|
|
|
|
if ( $bad =~ /[\/\^\$\*\+]/ ) { # it's a regexp
|
|
|
|
$self->log(LOGDEBUG, "badmailfrom pattern ($bad) match for $from");
|
|
|
|
return 1 if $from =~ /$bad/;
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
$bad = lc $bad;
|
|
|
|
if ( $bad !~ m/\@/ ) {
|
|
|
|
$self->log(LOGWARN, "badmailfrom: bad config: no \@ sign in $bad");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
if ( substr($bad,0,1) eq '@' ) {
|
|
|
|
return 1 if $bad eq "\@$host";
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
return if $bad ne $from;
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_rcpt {
|
2012-04-26 10:52:21 +02:00
|
|
|
my ($self, $transaction, $rcpt, %param) = @_;
|
|
|
|
my $note = $transaction->notes('badmailfrom') or return (DECLINED);
|
|
|
|
|
2004-11-27 19:40:54 +01:00
|
|
|
$self->log(LOGINFO, $note);
|
|
|
|
return (DENY, $note);
|
2002-09-10 13:00:31 +02:00
|
|
|
}
|