2002-07-08 04:30:11 +02:00
|
|
|
# this plugin checks the standard rcpthosts config and
|
|
|
|
# $ENV{RELAYCLIENT} to see if relaying is allowed.
|
|
|
|
#
|
|
|
|
# It should be configured to be run _LAST_!
|
|
|
|
#
|
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $qp) = @_;
|
|
|
|
$self->register_hook("rcpt", "check_relay");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_relay {
|
|
|
|
my ($self, $transaction, $recipient) = @_;
|
|
|
|
my $host = lc $recipient->host;
|
2003-01-20 12:03:15 +01:00
|
|
|
|
|
|
|
my @rcpt_hosts = ($self->qp->config("me"), $self->qp->config("rcpthosts"));
|
|
|
|
|
|
|
|
# Allow 'no @' addresses for 'postmaster' and 'abuse'
|
|
|
|
# qmail-smtpd will do this for all users without a domain, but we'll
|
|
|
|
# be a bit more picky. Maybe that's a bad idea.
|
|
|
|
my $user = $recipient->user;
|
|
|
|
$host = $self->qp->config("me")
|
|
|
|
if ($host eq "" && (lc $user eq "postmaster" || lc $user eq "abuse"));
|
|
|
|
|
2003-11-02 12:14:44 +01:00
|
|
|
# Check if this IP is allowed to relay
|
|
|
|
my @relay_clients = $self->qp->config("relayclients");
|
|
|
|
my $more_relay_clients = $self->qp->config("morerelayclients", "map");
|
|
|
|
my %relay_clients = map { $_ => 1 } @relay_clients;
|
|
|
|
my $client_ip = $self->qp->connection->remote_ip;
|
|
|
|
while ($client_ip) {
|
2004-06-16 22:28:57 +02:00
|
|
|
if (exists($ENV{RELAYCLIENT}) or
|
|
|
|
exists($relay_clients{$client_ip}) or
|
|
|
|
exists($more_relay_clients->{$client_ip}))
|
|
|
|
{
|
|
|
|
$transaction->relaying(1);
|
|
|
|
return (OK);
|
|
|
|
}
|
2003-11-02 12:14:44 +01:00
|
|
|
$client_ip =~ s/\d+\.?$//; # strip off another 8 bits
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if this recipient host is allowed
|
2002-07-08 04:30:11 +02:00
|
|
|
for my $allowed (@rcpt_hosts) {
|
|
|
|
$allowed =~ s/^\s*(\S+)/$1/;
|
|
|
|
return (OK) if $host eq lc $allowed;
|
|
|
|
return (OK) if substr($allowed,0,1) eq "." and $host =~ m/\Q$allowed\E$/i;
|
|
|
|
}
|
2003-03-25 13:50:07 +01:00
|
|
|
|
|
|
|
my $more_rcpt_hosts = $self->qp->config('morercpthosts', 'map');
|
|
|
|
return (OK) if exists $more_rcpt_hosts->{$host};
|
|
|
|
|
2002-07-08 04:30:11 +02:00
|
|
|
return (DENY);
|
|
|
|
}
|