cvs commit: qpsmtpd/plugins count_unrecognized_commands

[email protected] (Ask Bjoern Hansen)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     03/04/15 10:39:03

  Added:       plugins  count_unrecognized_commands
  Log:
  unrecognized_command hook and a count_unrecognized_commands
    plugin. (Rasjid Wilcox)
  
  Revision  Changes    Path
  1.1                  qpsmtpd/plugins/count_unrecognized_commands
  
  Index: count_unrecognized_commands
  ===================================================================
  =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) = @_;
    $self->register_hook("unrecognized_command", "check_unrec_cmd");
  
    if (@args > 0) {
      $self->{_unrec_cmd_max} = $args[0];
      $self->log(1, "WARNING: Ignoring additional arguments.") if (@args > 1);
    } else {
      $self->{_unrec_cmd_max} = 4;
    }
  
    $self->{_unrec_cmd_count} = 0;
  }
  
  sub check_unrec_cmd {
    my ($self, $transaction, $cmd) = @_;
    
    $self->log(5, "Unrecognized command '$cmd'");
  
    $self->{_unrec_cmd_count}++;
  
    my $badcmdcount = $self->{_unrec_cmd_count};
  
    if ($badcmdcount >= $self->{_unrec_cmd_max}) {
      $self->log(5, "Closing connection. Too many unrecognized commands.");
      return (DENY, "Closing connection. $badcmdcount unrecognized commands.  Perhaps you should read RFC 2821?");
    }
  
    return DECLINED;
  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.