cvs commit: qpsmtpd qpsmtpd-forkserver

[email protected] (Matt Sergeant)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     04/07/05 12:20:15

  Modified:    .        qpsmtpd-forkserver
  Log:
  Support per-IP throttling (Hanno Hecker <[email protected]>)
  
  Revision  Changes    Path
  1.6       +23 -2     qpsmtpd/qpsmtpd-forkserver
  
  Index: qpsmtpd-forkserver
  ===================================================================
  RCS file: /cvs/public/qpsmtpd/qpsmtpd-forkserver,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- qpsmtpd-forkserver	28 Jun 2004 03:05:03 -0000	1.5
  +++ qpsmtpd-forkserver	5 Jul 2004 19:20:15 -0000	1.6
  @@ -21,6 +21,7 @@
   my $PORT      = 25;				# port number
   my $LOCALADDR = '0.0.0.0';		# ip address to bind to
   my $USER      = 'smtpd';		# user to suid to
  +my $MAXCONNIP = 5;              # max simultaneous connections from one IP
   
   sub usage {
           print <<"EOT";
  @@ -110,10 +111,30 @@
           # possible something condition...
           next;
       }
  +    my ($port, $iaddr) = sockaddr_in($hisaddr);
  +    if ($MAXCONNIP) {
  +        my $num_conn = 0;
  +        foreach my $rip (values %childstatus) {
  +            if ($rip eq $iaddr) {
  +                ++$num_conn;
  +            }
  +        }
  +        ++$num_conn; # count this connection, too :)
  +        if ($num_conn > $MAXCONNIP) {
  +            my $rem_ip = inet_ntoa($iaddr);
  +            ::log(LOGINFO,"Too many connections from $rem_ip: "
  +                         ."$num_conn > $MAXCONNIP. Denying connection.");
  +            $client->autoflush(1);
  +            print $client "451 Sorry, too many connections from $rem_ip, try again later\r\n";
  +            close $client;
  +            next;
  +        }
  +    }
       my $pid = fork;
       if ($pid) {
           # parent
  -        $childstatus{$pid} = 1;	# add to table
  +        $childstatus{$pid} = $iaddr;	# add to table
  +        # $childstatus{$pid} = 1;	# add to table
           $running++;
           close($client);
           next;
  @@ -128,7 +149,7 @@
       my $localsockaddr = getsockname($client);
       my ($lport, $laddr) = sockaddr_in($localsockaddr);
       $ENV{TCPLOCALIP} = inet_ntoa($laddr);
  -    my ($port, $iaddr) = sockaddr_in($hisaddr);
  +    # my ($port, $iaddr) = sockaddr_in($hisaddr);
       $ENV{TCPREMOTEIP} = inet_ntoa($iaddr);
       $ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown";
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.