Implement multiple IP:PORT listen in forkserver (Devin Carraway).
Add support in plugins/tls to use SMTPS (John Peacock). git-svn-id: https://svn.perl.org/qpsmtpd/branches/0.3x@624 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
a07ed2ca77
commit
2c683f22ef
38
plugins/tls
38
plugins/tls
@ -93,6 +93,33 @@ sub hook_unrecognized_command {
|
|||||||
# OK, now we setup TLS
|
# OK, now we setup TLS
|
||||||
$self->qp->respond (220, "Go ahead with TLS");
|
$self->qp->respond (220, "Go ahead with TLS");
|
||||||
|
|
||||||
|
unless ( _convert_to_ssl($self) ) {
|
||||||
|
# SSL setup failed. Now we must respond to every command with 5XX
|
||||||
|
warn("TLS failed: $@\n");
|
||||||
|
$transaction->notes('ssl_failed', 1);
|
||||||
|
return DENY, "TLS Negotiation Failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->log(LOGWARN, "TLS setup returning");
|
||||||
|
return DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub hook_connect {
|
||||||
|
my ($self, $transaction) = @_;
|
||||||
|
|
||||||
|
my $local_port = $self->qp->connection->local_port;
|
||||||
|
return DECLINED unless $local_port == 465; # SMTPS
|
||||||
|
|
||||||
|
unless ( _convert_to_ssl($self) ) {
|
||||||
|
return (DENY_DISCONNECT, "Cannot establish SSL session");
|
||||||
|
}
|
||||||
|
$self->log(LOGWARN, "Connected via SMTPS");
|
||||||
|
return DECLINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _convert_to_ssl {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
my $tlssocket = IO::Socket::SSL->new_from_fd(
|
my $tlssocket = IO::Socket::SSL->new_from_fd(
|
||||||
fileno(STDIN), '+>',
|
fileno(STDIN), '+>',
|
||||||
@ -112,14 +139,11 @@ sub hook_unrecognized_command {
|
|||||||
$self->connection->notes('tls_enabled', 1);
|
$self->connection->notes('tls_enabled', 1);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
# SSL setup failed. Now we must respond to every command with 5XX
|
return 0;
|
||||||
warn("TLS failed: $@\n");
|
}
|
||||||
$transaction->notes('ssl_failed', 1);
|
else {
|
||||||
return DENY, "TLS Negotiation Failed";
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->log(LOGWARN, "TLS setup returning");
|
|
||||||
return DONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub can_do_tls {
|
sub can_do_tls {
|
||||||
|
@ -56,8 +56,8 @@ GetOptions('h|help' => \&usage,
|
|||||||
if ($PORT =~ /^(\d+)$/) { $PORT = $1 } else { &usage }
|
if ($PORT =~ /^(\d+)$/) { $PORT = $1 } else { &usage }
|
||||||
@LOCALADDR = ( '0.0.0.0' ) if !@LOCALADDR;
|
@LOCALADDR = ( '0.0.0.0' ) if !@LOCALADDR;
|
||||||
for (0..$#LOCALADDR) {
|
for (0..$#LOCALADDR) {
|
||||||
if ($LOCALADDR[$_] =~ /^([\d\w\-.]+)$/) {
|
if ($LOCALADDR[$_] =~ /^([\d\w\-.]+)(?::(\d+))?$/) {
|
||||||
$LOCALADDR[$_] = $1;
|
$LOCALADDR[$_] = { 'addr' => $1, 'port' => $2 || $PORT };
|
||||||
} else {
|
} else {
|
||||||
&usage;
|
&usage;
|
||||||
}
|
}
|
||||||
@ -94,13 +94,13 @@ my $select = new IO::Select;
|
|||||||
|
|
||||||
# establish SERVER socket(s), bind and listen.
|
# establish SERVER socket(s), bind and listen.
|
||||||
for my $listen_addr (@LOCALADDR) {
|
for my $listen_addr (@LOCALADDR) {
|
||||||
my $server = IO::Socket::INET->new(LocalPort => $PORT,
|
my $server = IO::Socket::INET->new(LocalPort => $listen_addr->{'port'},
|
||||||
LocalAddr => $listen_addr,
|
LocalAddr => $listen_addr->{'addr'},
|
||||||
Proto => 'tcp',
|
Proto => 'tcp',
|
||||||
Reuse => 1,
|
Reuse => 1,
|
||||||
Blocking => 0,
|
Blocking => 0,
|
||||||
Listen => SOMAXCONN )
|
Listen => SOMAXCONN )
|
||||||
or die "Creating TCP socket $listen_addr:$PORT: $!\n";
|
or die "Creating TCP socket $listen_addr->{'addr'}:$listen_addr->{'port'}: $!\n";
|
||||||
IO::Handle::blocking($server, 0);
|
IO::Handle::blocking($server, 0);
|
||||||
$select->add($server);
|
$select->add($server);
|
||||||
}
|
}
|
||||||
@ -149,7 +149,9 @@ $> = $quid;
|
|||||||
|
|
||||||
$qpsmtpd->load_plugins;
|
$qpsmtpd->load_plugins;
|
||||||
|
|
||||||
::log(LOGINFO,"Listening on port $PORT");
|
foreach my $local_addr ( @LOCALADDR ) {
|
||||||
|
::log(LOGINFO,"Listening on $local_addr->{'addr'}:$local_addr->{'port'}");
|
||||||
|
}
|
||||||
::log(LOGINFO, 'Running as user '.
|
::log(LOGINFO, 'Running as user '.
|
||||||
(getpwuid($>) || $>) .
|
(getpwuid($>) || $>) .
|
||||||
', group '.
|
', group '.
|
||||||
|
Loading…
Reference in New Issue
Block a user