Applied patch from issue #5: qpsmtpd-forkserver 0.32 patches
git-svn-id: https://svn.perl.org/qpsmtpd/trunk@739 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
fff01d4a66
commit
2db48784fe
@ -12,7 +12,7 @@ use Qpsmtpd::Constants;
|
|||||||
use IO::Socket;
|
use IO::Socket;
|
||||||
use IO::Select;
|
use IO::Select;
|
||||||
use Socket;
|
use Socket;
|
||||||
use Getopt::Long;
|
use Getopt::Long qw(:config no_ignore_case);
|
||||||
use POSIX qw(:sys_wait_h :errno_h :signal_h);
|
use POSIX qw(:sys_wait_h :errno_h :signal_h);
|
||||||
use Net::DNS::Header;
|
use Net::DNS::Header;
|
||||||
use strict;
|
use strict;
|
||||||
@ -28,10 +28,13 @@ if ($has_ipv6) {
|
|||||||
my $MAXCONN = 15; # max simultaneous connections
|
my $MAXCONN = 15; # max simultaneous connections
|
||||||
my @PORT; # port number(s)
|
my @PORT; # port number(s)
|
||||||
my @LOCALADDR; # ip address(es) to bind to
|
my @LOCALADDR; # ip address(es) to bind 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 = '';
|
||||||
my $DETACH; # daemonize on startup
|
my $DETACH; # daemonize on startup
|
||||||
|
my $NORDNS;
|
||||||
|
|
||||||
|
my $USER = (getpwuid $>)[0]; # user to suid to
|
||||||
|
$USER = "smtpd" if $USER eq "root";
|
||||||
|
|
||||||
sub usage {
|
sub usage {
|
||||||
print <<"EOT";
|
print <<"EOT";
|
||||||
@ -46,6 +49,7 @@ usage: qpsmtpd-forkserver [ options ]
|
|||||||
-m, --max-from-ip M : limit connections from a single IP; default 5
|
-m, --max-from-ip M : limit connections from a single IP; default 5
|
||||||
--pid-file P : print main servers PID to file P
|
--pid-file P : print main servers PID to file P
|
||||||
-d, --detach : detach from controlling terminal (daemonize)
|
-d, --detach : detach from controlling terminal (daemonize)
|
||||||
|
-H, --no-rdns : don't perform reverse DNS lookups
|
||||||
EOT
|
EOT
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
@ -58,6 +62,7 @@ GetOptions('h|help' => \&usage,
|
|||||||
'u|user=s' => \$USER,
|
'u|user=s' => \$USER,
|
||||||
'pid-file=s' => \$PID_FILE,
|
'pid-file=s' => \$PID_FILE,
|
||||||
'd|detach' => \$DETACH,
|
'd|detach' => \$DETACH,
|
||||||
|
'H|no-rdns' => \$NORDNS,
|
||||||
) || &usage;
|
) || &usage;
|
||||||
|
|
||||||
# detaint the commandline
|
# detaint the commandline
|
||||||
@ -175,6 +180,7 @@ while (my ($name,$passwd,$gid,$members) = getgrent()) {
|
|||||||
$groups .= " $gid";
|
$groups .= " $gid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
endgrent;
|
||||||
$) = $groups;
|
$) = $groups;
|
||||||
POSIX::setgid($qgid) or
|
POSIX::setgid($qgid) or
|
||||||
die "unable to change gid: $!\n";
|
die "unable to change gid: $!\n";
|
||||||
@ -279,7 +285,7 @@ while (1) {
|
|||||||
Net::DNS::Header::nextid();
|
Net::DNS::Header::nextid();
|
||||||
}
|
}
|
||||||
|
|
||||||
close($server);
|
close $_ for $select->handles;
|
||||||
|
|
||||||
$SIG{$_} = 'DEFAULT' for keys %SIG;
|
$SIG{$_} = 'DEFAULT' for keys %SIG;
|
||||||
$SIG{ALRM} = sub {
|
$SIG{ALRM} = sub {
|
||||||
@ -291,6 +297,13 @@ while (1) {
|
|||||||
# my ($port, $iaddr) = sockaddr_in($hisaddr);
|
# my ($port, $iaddr) = sockaddr_in($hisaddr);
|
||||||
$ENV{TCPREMOTEIP} = $nto_iaddr;
|
$ENV{TCPREMOTEIP} = $nto_iaddr;
|
||||||
|
|
||||||
|
if ($NORDNS) {
|
||||||
|
$ENV{TCPREMOTEHOST} = $ENV{TCPREMOTEIP} ? "[$ENV{TCPREMOTEIP}]" : "[noip!]";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $zero = $0;
|
||||||
|
$0 = "$zero (gethostbyname $ENV{TCPREMOTEIP})";
|
||||||
|
|
||||||
if ($server->sockdomain == AF_INET) {
|
if ($server->sockdomain == AF_INET) {
|
||||||
$ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown";
|
$ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown";
|
||||||
}
|
}
|
||||||
@ -299,6 +312,9 @@ while (1) {
|
|||||||
$ENV{TCPREMOTEHOST} = $canonname || "Unknown";
|
$ENV{TCPREMOTEHOST} = $canonname || "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0 = $zero;
|
||||||
|
}
|
||||||
|
|
||||||
# don't do this!
|
# don't do this!
|
||||||
#$0 = "qpsmtpd-forkserver: $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}";
|
#$0 = "qpsmtpd-forkserver: $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}";
|
||||||
|
|
||||||
@ -307,6 +323,7 @@ while (1) {
|
|||||||
# 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);
|
||||||
|
close $client;
|
||||||
|
|
||||||
$qpsmtpd->start_connection
|
$qpsmtpd->start_connection
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user