1 |
--- lib/Qpsmtpd/TcpServer.pm.xinetd Wed Oct 4 15:49:49 2006 |
2 |
+++ lib/Qpsmtpd/TcpServer.pm Sun Nov 5 16:20:44 2006 |
3 |
@@ -1,6 +1,7 @@ |
4 |
package Qpsmtpd::TcpServer; |
5 |
use Qpsmtpd::SMTP; |
6 |
use Qpsmtpd::Constants; |
7 |
+use Socket; |
8 |
|
9 |
@ISA = qw(Qpsmtpd::SMTP); |
10 |
use strict; |
11 |
@@ -12,12 +13,25 @@ |
12 |
sub start_connection { |
13 |
my $self = shift; |
14 |
|
15 |
- die "Qpsmtpd::TcpServer must be started by tcpserver\n" |
16 |
- unless $ENV{TCPREMOTEIP}; |
17 |
+ my ($remote_host, $remote_info, $remote_ip); |
18 |
|
19 |
- my $remote_host = $ENV{TCPREMOTEHOST} || ( $ENV{TCPREMOTEIP} ? "[$ENV{TCPREMOTEIP}]" : "[noip!]"); |
20 |
- my $remote_info = $ENV{TCPREMOTEINFO} ? "$ENV{TCPREMOTEINFO}\@$remote_host" : $remote_host; |
21 |
- my $remote_ip = $ENV{TCPREMOTEIP}; |
22 |
+ if ($ENV{TCPREMOTEIP}) { |
23 |
+ # started from tcpserver (or some other superserver which |
24 |
+ # exports the TCPREMOTE* variables. |
25 |
+ $remote_ip = $ENV{TCPREMOTEIP}; |
26 |
+ $remote_host = $ENV{TCPREMOTEHOST} || "[$remote_ip]"; |
27 |
+ $remote_info = $ENV{TCPREMOTEINFO} ? "$ENV{TCPREMOTEINFO}\@$remote_host" : $remote_host; |
28 |
+ } else { |
29 |
+ # Started from inetd or similar. |
30 |
+ # get info on the remote host from the socket. |
31 |
+ # ignore ident/tap/... |
32 |
+ my $hersockaddr = getpeername(STDIN) |
33 |
+ or die "getpeername failed: $0 must be called from tcpserver, (x)inetd or a similar program which passes a socket to stdin"; |
34 |
+ my ($port, $iaddr) = sockaddr_in($hersockaddr); |
35 |
+ $remote_ip = inet_ntoa($iaddr); |
36 |
+ $remote_host = gethostbyaddr($iaddr, AF_INET) || "[$remote_ip]"; |
37 |
+ $remote_info = $remote_host; |
38 |
+ } |
39 |
$self->log(LOGNOTICE, "Connection from $remote_info [$remote_ip]"); |
40 |
|
41 |
# if the local dns resolver doesn't filter it out we might get |