2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2012-04-08 02:11:16 +02:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
rcpt_ok
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
this plugin checks the standard rcpthosts config
|
|
|
|
|
2012-05-11 07:50:04 +02:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Check the recipient hostname and determine if we accept mail to that host.
|
|
|
|
|
|
|
|
This is functionally identical to qmail's rcpthosts implementation, consulting
|
|
|
|
both rcpthosts and morercpthosts.cdb.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
2012-04-08 02:11:16 +02:00
|
|
|
It should be configured to be run _LAST_!
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2012-05-11 07:50:04 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
2006-01-25 03:59:31 +01:00
|
|
|
use Qpsmtpd::DSN;
|
2004-09-22 18:01:16 +02:00
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_rcpt {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $transaction, $recipient, %param) = @_;
|
2004-09-22 18:01:16 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
# 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 $host = $self->get_rcpt_host($recipient) or return (OK);
|
2012-05-11 07:50:04 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
return (OK) if $self->is_in_rcpthosts($host);
|
|
|
|
return (OK) if $self->is_in_morercpthosts($host);
|
|
|
|
return (OK) if $self->qp->connection->relay_client; # failsafe
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
# default of relaying_denied is obviously DENY,
|
2006-01-25 03:59:31 +01:00
|
|
|
# we use the default "Relaying denied" message...
|
|
|
|
return Qpsmtpd::DSN->relaying_denied();
|
2004-09-22 18:01:16 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
sub is_in_rcpthosts {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $host) = @_;
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
my @rcpt_hosts = ($self->qp->config('me'), $self->qp->config('rcpthosts'));
|
|
|
|
|
|
|
|
# Check if this recipient host is allowed
|
|
|
|
for my $allowed (@rcpt_hosts) {
|
|
|
|
$allowed =~ s/^\s*(\S+)/$1/;
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($host eq lc $allowed) {
|
|
|
|
$self->log(LOGINFO, "pass: $host in rcpthosts");
|
2012-05-11 07:50:04 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (substr($allowed, 0, 1) eq '.' and $host =~ m/\Q$allowed\E$/i) {
|
|
|
|
$self->log(LOGINFO, "pass: $host in rcpthosts as $allowed");
|
2012-05-11 07:50:04 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
sub is_in_morercpthosts {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $host) = @_;
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
my $more_rcpt_hosts = $self->qp->config('morercpthosts', 'map');
|
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (exists $more_rcpt_hosts->{$host}) {
|
|
|
|
$self->log(LOGINFO, "pass: $host found in morercpthosts");
|
2012-05-11 07:50:04 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
$self->log(LOGINFO, "fail: $host not in morercpthosts");
|
2012-05-11 07:50:04 +02:00
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
sub get_rcpt_host {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $recipient) = @_;
|
2012-05-11 07:50:04 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
return if !$recipient; # Qpsmtpd::Address couldn't parse the recipient
|
2012-05-11 07:50:04 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($recipient->host) {
|
2012-05-11 07:50:04 +02:00
|
|
|
return lc $recipient->host;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
# no host portion exists
|
|
|
|
my $user = $recipient->user or return;
|
2013-04-21 06:50:39 +02:00
|
|
|
if (lc $user eq 'postmaster' || lc $user eq 'abuse') {
|
2012-05-11 07:50:04 +02:00
|
|
|
return $self->qp->config('me');
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|