a23d4b3da9
Exclude some tests with dependencies. Remove -T from perl line in plugins This makes it harder to test with PERL5LIB/perlbrew etc
56 lines
1.3 KiB
Perl
56 lines
1.3 KiB
Perl
#!perl -w
|
|
|
|
=head1 NAME
|
|
|
|
count_unrecognized_commands - Count unrecognized commands and disconnect when we have too many
|
|
|
|
=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
|
|
|
|
sub register {
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
if (@args > 0) {
|
|
$self->{_unrec_cmd_max} = $args[0];
|
|
$self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 1);
|
|
} else {
|
|
$self->{_unrec_cmd_max} = 4;
|
|
}
|
|
|
|
}
|
|
|
|
sub hook_connect {
|
|
my ($self, $transaction) = @_;
|
|
|
|
$self->qp->connection->notes('unrec_cmd_count', 0);
|
|
return DECLINED;
|
|
}
|
|
|
|
sub hook_unrecognized_command {
|
|
my ($self, $cmd) = @_[0,2];
|
|
|
|
$self->log(LOGINFO, "Unrecognized command '$cmd'");
|
|
|
|
my $badcmdcount =
|
|
$self->qp->connection->notes( 'unrec_cmd_count',
|
|
($self->qp->connection->notes('unrec_cmd_count') || 0) + 1
|
|
);
|
|
|
|
if ($badcmdcount >= $self->{_unrec_cmd_max}) {
|
|
$self->log(LOGINFO, "Closing connection. Too many unrecognized commands.");
|
|
return (DENY_DISCONNECT, "Closing connection. $badcmdcount unrecognized commands. Perhaps you should read RFC 2821?");
|
|
}
|
|
|
|
return DECLINED;
|
|
}
|
|
|