Clean up whitespace (mainloop had a swath of 4-space indentation, while everything else used 2-space; also removed some tabs towards the beginning.)

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@465 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Devin Carraway 2005-07-06 07:53:41 +00:00
parent 1fbfe5156b
commit 1e68345cf2

View File

@ -18,11 +18,11 @@ use strict;
$| = 1; $| = 1;
# Configuration # Configuration
my $MAXCONN = 15; # max simultaneous connections my $MAXCONN = 15; # max simultaneous connections
my $PORT = 2525; # port number my $PORT = 2525; # port number
my @LOCALADDR; # ip address to bind to my @LOCALADDR; # ip address(es) to bind to
my $USER = 'smtpd'; # user to suid to my $USER = 'smtpd'; # user to suid to
my $MAXCONNIP = 5; # max simultaneous connections from one IP my $MAXCONNIP = 5; # max simultaneous connections from one IP
my $PID_FILE = ''; my $PID_FILE = '';
sub usage { sub usage {
@ -163,77 +163,77 @@ while (1) {
my ($client, $hisaddr) = $server->accept; my ($client, $hisaddr) = $server->accept;
if (!$hisaddr) { if (!$hisaddr) {
# possible something condition... # possible something condition...
next; next;
}
IO::Handle::blocking($client, 1);
my ($port, $iaddr) = sockaddr_in($hisaddr);
if ($MAXCONNIP) {
my $num_conn = 1; # seed with current value
foreach my $rip (values %childstatus) {
++$num_conn if (defined $rip && $rip eq $iaddr);
} }
IO::Handle::blocking($client, 1);
my ($port, $iaddr) = sockaddr_in($hisaddr);
if ($MAXCONNIP) {
my $num_conn = 1; # seed with current value
foreach my $rip (values %childstatus) { if ($num_conn > $MAXCONNIP) {
++$num_conn if (defined $rip && $rip eq $iaddr); my $rem_ip = inet_ntoa($iaddr);
} ::log(LOGINFO,"Too many connections from $rem_ip: "
."$num_conn > $MAXCONNIP. Denying connection.");
if ($num_conn > $MAXCONNIP) { $client->autoflush(1);
my $rem_ip = inet_ntoa($iaddr); print $client "451 Sorry, too many connections from $rem_ip, try again later\r\n";
::log(LOGINFO,"Too many connections from $rem_ip: " close $client;
."$num_conn > $MAXCONNIP. Denying connection."); next;
$client->autoflush(1);
print $client "451 Sorry, too many connections from $rem_ip, try again later\r\n";
close $client;
next;
}
} }
my $pid = safe_fork(); }
if ($pid) { my $pid = safe_fork();
# parent if ($pid) {
$childstatus{$pid} = $iaddr; # add to table # parent
# $childstatus{$pid} = 1; # add to table $childstatus{$pid} = $iaddr; # add to table
$running++; # $childstatus{$pid} = 1; # add to table
close($client); $running++;
next; close($client);
} next;
# otherwise child }
# otherwise child
# all children should have different seeds, to prevent conflicts # all children should have different seeds, to prevent conflicts
srand( time ^ ($$ + ($$ << 15)) ); srand( time ^ ($$ + ($$ << 15)) );
close($server); close($server);
$SIG{$_} = 'DEFAULT' for keys %SIG; $SIG{$_} = 'DEFAULT' for keys %SIG;
$SIG{ALRM} = sub { $SIG{ALRM} = sub {
print $client "421 Connection Timed Out\n"; print $client "421 Connection Timed Out\n";
::log(LOGINFO, "Connection Timed Out"); ::log(LOGINFO, "Connection Timed Out");
exit; }; exit; };
my $localsockaddr = getsockname($client); my $localsockaddr = getsockname($client);
my ($lport, $laddr) = sockaddr_in($localsockaddr); my ($lport, $laddr) = sockaddr_in($localsockaddr);
$ENV{TCPLOCALIP} = inet_ntoa($laddr); $ENV{TCPLOCALIP} = inet_ntoa($laddr);
# my ($port, $iaddr) = sockaddr_in($hisaddr); # my ($port, $iaddr) = sockaddr_in($hisaddr);
$ENV{TCPREMOTEIP} = inet_ntoa($iaddr); $ENV{TCPREMOTEIP} = inet_ntoa($iaddr);
$ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown"; $ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown";
# don't do this! # don't do this!
#$0 = "qpsmtpd-forkserver: $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}"; #$0 = "qpsmtpd-forkserver: $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}";
::log(LOGINFO, "Accepted connection $running/$MAXCONN from $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}"); ::log(LOGINFO, "Accepted connection $running/$MAXCONN from $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}");
# dup to STDIN/STDOUT # dup to STDIN/STDOUT
POSIX::dup2(fileno($client), 0); POSIX::dup2(fileno($client), 0);
POSIX::dup2(fileno($client), 1); POSIX::dup2(fileno($client), 1);
$qpsmtpd->start_connection $qpsmtpd->start_connection
( (
local_ip => $ENV{TCPLOCALIP}, local_ip => $ENV{TCPLOCALIP},
local_port => $lport, local_port => $lport,
remote_ip => $ENV{TCPREMOTEIP}, remote_ip => $ENV{TCPREMOTEIP},
remote_port => $port, remote_port => $port,
); );
$qpsmtpd->run(); $qpsmtpd->run();
exit; # child leaves exit; # child leaves
} }
sub log { sub log {