Debian Codegraph @

plugins/count_unrecognized_commands

raw
1 #!perl -w
2
3 =head1 NAME
4
5 count_unrecognized_commands - and disconnect after too many
6
7 =head1 DESCRIPTION
8
9 Disconnect the client if it sends too many unrecognized commands.
10 Good for rejecting spam sent through open HTTP proxies.
11
12 =head1 CONFIGURATION
13
14 Takes one parameter, the number of allowed unrecognized commands
15 before we disconnect the client. Defaults to 4.
16
17 =cut
18
19 use strict;
20 use warnings;
21
22 use Qpsmtpd::Constants;
23
24 sub register {
25 my ($self, $qp) = (shift, shift);
26
27 $self->{_unrec_cmd_max} = shift || 4;
28
29 if (scalar @_) {
30 $self->log(LOGWARN, "Ignoring additional arguments.");
31 }
32 }
33
34 sub hook_unrecognized_command {
35 my ($self, $cmd) = @_[0, 2];
36
37 my $count = $self->connection->notes('unrec_cmd_count') || 0;
38 $count = $count + 1;
39 $self->connection->notes('unrec_cmd_count', $count);
40
41 if ($count < $self->{_unrec_cmd_max}) {
42 $self->log(LOGINFO, "'$cmd', ($count)");
43 return DECLINED;
44 }
45
46 $self->log(LOGINFO, "fail, '$cmd' ($count)");
47 return (DENY_DISCONNECT,
48 "Closing connection, $count unrecognized commands. Perhaps you should read RFC 2821?"
49 );
50 }
51