2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2012-04-08 02:11:16 +02:00
|
|
|
|
2003-04-15 19:39:03 +02:00
|
|
|
=head1 NAME
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
count_unrecognized_commands - and disconnect after too many
|
2003-04-15 19:39:03 +02:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Disconnect the client if it sends too many unrecognized commands.
|
|
|
|
Good for rejecting spam sent through open HTTP proxies.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Takes one parameter, the number of allowed unrecognized commands
|
|
|
|
before we disconnect the client. Defaults to 4.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2012-05-21 05:04:37 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
2003-04-15 19:39:03 +02:00
|
|
|
sub register {
|
2012-05-21 05:04:37 +02:00
|
|
|
my ($self, $qp ) = shift, shift;
|
2003-04-15 19:39:03 +02:00
|
|
|
|
2012-05-21 05:04:37 +02:00
|
|
|
$self->{_unrec_cmd_max} = shift || 4;
|
2003-04-15 19:39:03 +02:00
|
|
|
|
2012-05-21 05:04:37 +02:00
|
|
|
if ( scalar @_ ) {
|
|
|
|
$self->log(LOGWARN, "Ignoring additional arguments.");
|
|
|
|
}
|
2006-09-14 21:48:37 +02:00
|
|
|
}
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_unrecognized_command {
|
2004-03-04 05:14:09 +01:00
|
|
|
my ($self, $cmd) = @_[0,2];
|
2003-04-15 19:39:03 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
my $count = $self->connection->notes('unrec_cmd_count') || 0;
|
|
|
|
$count = $count + 1;
|
|
|
|
$self->connection->notes('unrec_cmd_count', $count);
|
2003-04-15 19:39:03 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
if ( $count < $self->{_unrec_cmd_max} ) {
|
|
|
|
$self->log(LOGINFO, "'$cmd', ($count)");
|
|
|
|
return DECLINED;
|
|
|
|
};
|
2003-04-15 19:39:03 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGINFO, "fail, '$cmd' ($count)");
|
|
|
|
return (DENY_DISCONNECT, "Closing connection, $count unrecognized commands. Perhaps you should read RFC 2821?" );
|
2003-04-15 19:39:03 +02:00
|
|
|
}
|
|
|
|
|