develooper Front page | perl.cvs.qpsmtpd | Postings from May 2007

[svn:qpsmtpd] r739 - trunk

From:
msergeant
Date:
May 17, 2007 15:09
Subject:
[svn:qpsmtpd] r739 - trunk
Message ID:
20070517220934.58CA8CB9B8@x12.develooper.com
Author: msergeant
Date: Thu May 17 15:09:33 2007
New Revision: 739

Modified:
   trunk/qpsmtpd-forkserver

Log:
Applied patch from issue #5: qpsmtpd-forkserver 0.32 patches


Modified: trunk/qpsmtpd-forkserver
==============================================================================
--- trunk/qpsmtpd-forkserver	(original)
+++ trunk/qpsmtpd-forkserver	Thu May 17 15:09:33 2007
@@ -12,7 +12,7 @@
 use IO::Socket;
 use IO::Select;
 use Socket;
-use Getopt::Long;
+use Getopt::Long qw(:config no_ignore_case);
 use POSIX qw(:sys_wait_h :errno_h :signal_h);
 use Net::DNS::Header;
 use strict;
@@ -28,10 +28,13 @@
 my $MAXCONN   = 15;                  # max simultaneous connections
 my @PORT;                            # port number(s)
 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 $PID_FILE   = '';
 my $DETACH;                          # daemonize on startup
+my $NORDNS;
+
+my $USER = (getpwuid $>)[0];         # user to suid to
+$USER = "smtpd" if $USER eq "root";
 
 sub usage {
         print <<"EOT";
@@ -46,6 +49,7 @@
  -m, --max-from-ip M       : limit connections from a single IP; default 5
      --pid-file P          : print main servers PID to file P
  -d, --detach              : detach from controlling terminal (daemonize)
+ -H, --no-rdns             : don't perform reverse DNS lookups
 EOT
         exit 0;
 }
@@ -58,6 +62,7 @@
            'u|user=s' => \$USER,
            'pid-file=s' => \$PID_FILE,
            'd|detach' => \$DETACH,
+	   'H|no-rdns' => \$NORDNS,
           ) || &usage;
 
 # detaint the commandline
@@ -175,6 +180,7 @@
         $groups .= " $gid";
     }
 }
+endgrent;
 $) = $groups;
 POSIX::setgid($qgid) or
       die "unable to change gid: $!\n";
@@ -279,7 +285,7 @@
 	Net::DNS::Header::nextid();
     }
   
-    close($server);
+    close $_ for $select->handles;
   
     $SIG{$_} = 'DEFAULT' for keys %SIG;
     $SIG{ALRM} = sub { 
@@ -291,6 +297,13 @@
     # my ($port, $iaddr) = sockaddr_in($hisaddr);
     $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) {
       $ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown";
     }
@@ -299,6 +312,9 @@
       $ENV{TCPREMOTEHOST} = $canonname || "Unknown";
     }
 
+      $0 = $zero;
+    }
+
     # don't do this!
     #$0 = "qpsmtpd-forkserver: $ENV{TCPREMOTEIP} / $ENV{TCPREMOTEHOST}";
   
@@ -307,6 +323,7 @@
     # dup to STDIN/STDOUT
     POSIX::dup2(fileno($client), 0);
     POSIX::dup2(fileno($client), 1);
+    close $client;
     
     $qpsmtpd->start_connection
       (



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About