2003-04-15 19:39:27 +02:00
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
check_earlytalker - Check that the client doesn't talk before we send the SMTP banner
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2004-08-01 09:08:07 +02:00
|
|
|
Checks to see if the remote host starts talking before we've issued a 2xx
|
|
|
|
greeting. If so, we're likely looking at a direct-to-MX spam agent which
|
|
|
|
pipelines its entire SMTP conversation, and will happily dump an entire spam
|
|
|
|
into our mail log even if later tests deny acceptance.
|
2003-04-15 19:39:27 +02:00
|
|
|
|
2004-08-01 09:08:07 +02:00
|
|
|
Depending on configuration, clients which behave in this way are either
|
|
|
|
immediately disconnected with a deny or denysoft code, or else are issued this
|
|
|
|
on all mail/rcpt commands in the transaction.
|
2003-04-15 19:39:27 +02:00
|
|
|
|
2004-08-01 09:08:07 +02:00
|
|
|
=head1 CONFIGURATION
|
2003-04-15 19:39:27 +02:00
|
|
|
|
2004-08-01 09:08:07 +02:00
|
|
|
=over 4
|
2003-04-15 19:39:27 +02:00
|
|
|
|
2004-08-01 09:08:07 +02:00
|
|
|
=item wait [integer]
|
|
|
|
|
|
|
|
The number of seconds to delay the initial greeting to see if the connecting
|
2005-07-30 09:19:17 +02:00
|
|
|
host speaks first. The default is 1. Do not select a value that is too high,
|
|
|
|
or you may be unable to receive mail from MTAs with short SMTP connect or
|
|
|
|
greeting timeouts -- these are known to range as low as 30 seconds, and may
|
|
|
|
in some cases be configured lower by mailserver admins. Network transit time
|
|
|
|
must also be allowed for.
|
2004-08-01 09:08:07 +02:00
|
|
|
|
|
|
|
=item action [string: deny, denysoft, log]
|
|
|
|
|
|
|
|
What to do when matching an early-talker -- the options are I<deny>,
|
|
|
|
I<denysoft> or I<log>.
|
|
|
|
|
|
|
|
If I<log> is specified, the connection will be allowed to proceed as normal,
|
|
|
|
and only a warning will be logged.
|
|
|
|
|
|
|
|
The default is I<denysoft>.
|
|
|
|
|
|
|
|
=item defer-reject [boolean]
|
|
|
|
|
|
|
|
When an early-talker is detected, if this option is set to a true value, the
|
|
|
|
SMTP greeting will be issued as usual, but all RCPT/MAIL commands will be
|
|
|
|
issued a deny or denysoft (depending on the value of I<action>). The default
|
|
|
|
is to react at the SMTP greeting stage by issuing the apropriate response code
|
|
|
|
and terminating the SMTP connection.
|
|
|
|
|
|
|
|
=back
|
2003-04-15 19:39:27 +02:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2005-07-11 21:10:49 +02:00
|
|
|
my $MSG = 'Connecting host started transmitting before SMTP greeting';
|
2004-08-01 09:08:07 +02:00
|
|
|
|
2003-04-15 19:39:27 +02:00
|
|
|
sub register {
|
2004-08-01 09:08:07 +02:00
|
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
|
|
|
|
if (@args % 2) {
|
2005-03-08 23:58:09 +01:00
|
|
|
$self->log(LOGERROR, "Unrecognized/mismatched arguments");
|
|
|
|
return undef;
|
2004-08-01 09:08:07 +02:00
|
|
|
}
|
|
|
|
$self->{_args} = {
|
2005-03-08 23:58:09 +01:00
|
|
|
'wait' => 1,
|
|
|
|
'action' => 'denysoft',
|
|
|
|
'defer-reject' => 0,
|
|
|
|
@args,
|
2004-08-01 09:08:07 +02:00
|
|
|
};
|
2005-07-18 14:50:35 +02:00
|
|
|
if ($qp->isa('Qpsmtpd::Apache')) {
|
2005-06-20 20:46:38 +02:00
|
|
|
require APR::Const;
|
|
|
|
APR::Const->import(qw(POLLIN SUCCESS));
|
2005-07-11 21:10:49 +02:00
|
|
|
$self->register_hook('connect', 'hook_connect_apr');
|
2005-06-20 20:46:38 +02:00
|
|
|
}
|
|
|
|
else {
|
2005-07-11 21:10:49 +02:00
|
|
|
$self->register_hook('connect', 'hook_connect');
|
2005-06-20 20:46:38 +02:00
|
|
|
}
|
2005-07-11 21:10:49 +02:00
|
|
|
$self->register_hook('connect', 'hook_connect_post');
|
|
|
|
$self->register_hook('mail', 'hook_mail')
|
2004-08-01 09:08:07 +02:00
|
|
|
if $self->{_args}->{'defer-reject'};
|
|
|
|
1;
|
2003-04-15 19:39:27 +02:00
|
|
|
}
|
|
|
|
|
2005-07-11 21:10:49 +02:00
|
|
|
sub hook_connect_apr {
|
2005-06-20 20:46:38 +02:00
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
return DECLINED if ($self->qp->connection->notes('whitelistclient'));
|
|
|
|
my $ip = $self->qp->connection->remote_ip;
|
|
|
|
|
|
|
|
my $c = $self->qp->{conn};
|
|
|
|
my $socket = $c->client_socket;
|
|
|
|
my $timeout = $self->{_args}->{'wait'} * 1_000_000;
|
|
|
|
|
|
|
|
my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN());
|
|
|
|
if ($rc == APR::Const::SUCCESS()) {
|
|
|
|
$self->log(LOGNOTICE, "remote host started talking before we said hello [$ip]");
|
|
|
|
if ($self->{_args}->{'defer-reject'}) {
|
|
|
|
$self->qp->connection->notes('earlytalker', 1);
|
|
|
|
}
|
|
|
|
else {
|
2005-07-11 21:10:49 +02:00
|
|
|
return (DENY,$MSG) if $self->{_args}->{'action'} eq 'deny';
|
|
|
|
return (DENYSOFT,$MSG) if $self->{_args}->{'action'} eq 'denysoft';
|
2005-06-20 20:46:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->log(LOGINFO, "remote host said nothing spontaneous, proceeding");
|
|
|
|
}
|
2005-07-11 21:10:49 +02:00
|
|
|
return DECLINED;
|
2005-06-20 20:46:38 +02:00
|
|
|
}
|
|
|
|
|
2005-07-11 21:10:49 +02:00
|
|
|
sub hook_connect {
|
2003-04-15 19:39:27 +02:00
|
|
|
my ($self, $transaction) = @_;
|
2005-05-09 15:43:40 +02:00
|
|
|
|
2005-06-21 22:02:14 +02:00
|
|
|
my $qp = $self->qp;
|
|
|
|
my $conn = $qp->connection;
|
|
|
|
$qp->AddTimer($self->{_args}{'wait'}, sub { read_now($qp, $conn) });
|
|
|
|
return CONTINUATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_now {
|
|
|
|
my ($qp, $conn) = @_;
|
|
|
|
|
|
|
|
if (my $data = $qp->read(1024)) {
|
|
|
|
if (length($$data)) {
|
|
|
|
$qp->log(LOGNOTICE, 'remote host started talking before we said hello');
|
|
|
|
$qp->push_back_read($data);
|
|
|
|
$conn->notes('earlytalker', 1);
|
2004-08-01 09:08:07 +02:00
|
|
|
}
|
2003-04-15 19:39:27 +02:00
|
|
|
}
|
2005-06-21 22:02:14 +02:00
|
|
|
$qp->finish_continuation;
|
|
|
|
}
|
|
|
|
|
2005-07-11 21:10:49 +02:00
|
|
|
sub hook_connect_post {
|
2005-06-21 22:02:14 +02:00
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
my $conn = $self->qp->connection;
|
|
|
|
return DECLINED unless $conn->notes('earlytalker');
|
|
|
|
return DECLINED if $self->{'defer-reject'};
|
2005-07-11 21:10:49 +02:00
|
|
|
return (DENY,$MSG) if $self->{_args}->{'action'} eq 'deny';
|
|
|
|
return (DENYSOFT,$MSG) if $self->{_args}->{'action'} eq 'denysoft';
|
2005-06-21 22:02:14 +02:00
|
|
|
return DECLINED; # assume action eq 'log'
|
2003-04-15 19:39:27 +02:00
|
|
|
}
|
2004-08-01 09:08:07 +02:00
|
|
|
|
2005-07-11 21:10:49 +02:00
|
|
|
sub hook_mail {
|
2004-08-01 09:08:07 +02:00
|
|
|
my ($self, $txn) = @_;
|
|
|
|
|
2005-03-08 23:58:09 +01:00
|
|
|
return DECLINED unless $self->connection->notes('earlytalker');
|
2005-07-11 21:10:49 +02:00
|
|
|
return (DENY,$MSG) if $self->{_args}->{'action'} eq 'deny';
|
|
|
|
return (DENYSOFT,$MSG) if $self->{_args}->{'action'} eq 'denysoft';
|
2004-08-01 09:08:07 +02:00
|
|
|
return DECLINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
|
|
|
|