develooper Front page | perl.cvs.qpsmtpd | Postings from March 2006

[svn:qpsmtpd] r625 - in branches/0.3x: . plugins

From:
jpeacock
Date:
March 1, 2006 08:44
Subject:
[svn:qpsmtpd] r625 - in branches/0.3x: . plugins
Message ID:
20060301164420.E56DDCBA2B@x12.develooper.com
Author: jpeacock
Date: Wed Mar  1 08:44:20 2006
New Revision: 625

Modified:
   branches/0.3x/plugins/tls
   branches/0.3x/qpsmtpd-forkserver

Log:
Improve support for listening to multiple ports and/or multiple IP addresses.
Document using plugins/tls to handle SMTPS (port 465).

Modified: branches/0.3x/plugins/tls
==============================================================================
--- branches/0.3x/plugins/tls	(original)
+++ branches/0.3x/plugins/tls	Wed Mar  1 08:44:20 2006
@@ -12,7 +12,15 @@
 
 =head1 DESCRIPTION
 
-This plugin implements basic TLS support.
+This plugin implements basic TLS support.  It can also be used to support
+port 465 (SMTP over SSL), but only with qpsmtpd-forkserver.  In this case,
+be sure to load plugins/tls before any other connect plugins and start
+qpsmtpd like this:
+
+  qpsmtpd-forkserver --port 25 --port 465
+
+You can also specify multiple --listen-address options as well; see the help
+for qpsmtpd-forkserver for more details.
 
 If TLS is successfully negotiated then the C<tls_enabled> field in the
 Connection notes is set. If you wish to make TLS mandatory you should check

Modified: branches/0.3x/qpsmtpd-forkserver
==============================================================================
--- branches/0.3x/qpsmtpd-forkserver	(original)
+++ branches/0.3x/qpsmtpd-forkserver	Wed Mar  1 08:44:20 2006
@@ -19,7 +19,7 @@
 
 # Configuration
 my $MAXCONN   = 15;                  # max simultaneous connections
-my $PORT      = 2525;                # port number
+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
@@ -31,8 +31,9 @@
 usage: qpsmtpd-forkserver [ options ]
  -l, --listen-address addr : listen on specific address(es); can be specified
                              multiple times for multiple bindings.  Default is
-			     0.0.0.0 (all interfaces).
- -p, --port P              : listen on a specific port; default 2525
+        		     0.0.0.0 (all interfaces).
+ -p, --port P              : listen on a specific port; default 2525; can be
+                             specified multiple times for multiple bindings.
  -c, --limit-connections N : limit concurrent connections to N; default 15
  -u, --user U              : run as a particular user (default 'smtpd')
  -m, --max-from-ip M       : limit connections from a single IP; default 5
@@ -46,22 +47,36 @@
            'l|listen-address=s' => \@LOCALADDR,
            'c|limit-connections=i' => \$MAXCONN,
            'm|max-from-ip=i' => \$MAXCONNIP,
-           'p|port=i' => \$PORT,
+           'p|port=s' => \@PORT,
            'u|user=s' => \$USER,
            'pid-file=s' => \$PID_FILE,
            'd|detach' => \$DETACH,
-	  ) || &usage;
+          ) || &usage;
 
 # detaint the commandline
-if ($PORT =~ /^(\d+)$/) { $PORT = $1 } else { &usage }
 @LOCALADDR = ( '0.0.0.0' ) if !@LOCALADDR;
+@PORT = ( 2525 ) if !@PORT;
+
+my @LISTENADDR;
 for (0..$#LOCALADDR) {
   if ($LOCALADDR[$_] =~ /^([\d\w\-.]+)(?::(\d+))?$/) {
-    $LOCALADDR[$_] = { 'addr' => $1, 'port' => $2 || $PORT };
+    if ( defined $2 ) {
+      push @LISTENADDR, { 'addr' => $1, 'port' => $2 };
+    } else {
+      my $addr = $1;
+      for (0..$#PORT) {
+        if ( $PORT[$_] =~ /^(\d+)$/ ) {
+          push @LISTENADDR, { 'addr' => $addr, 'port' => $1 };
+        } else {
+          &usage;
+        }
+      }
+    }
   } else {
     &usage;
   }
 }
+
 if ($USER =~ /^([\w\-]+)$/) { $USER = $1 } else { &usage }
 if ($MAXCONN =~ /^(\d+)$/) { $MAXCONN = $1 } else { &usage }
 
@@ -93,7 +108,7 @@
 my $select = new IO::Select;
 
 # establish SERVER socket(s), bind and listen.
-for my $listen_addr (@LOCALADDR) {
+for my $listen_addr (@LISTENADDR) {
   my $server = IO::Socket::INET->new(LocalPort => $listen_addr->{'port'},
                                      LocalAddr => $listen_addr->{'addr'},
                                      Proto     => 'tcp',
@@ -137,7 +152,7 @@
 while (my ($name,$passwd,$gid,$members) = getgrent()) {
     my @m = split(/ /, $members);
     if (grep {$_ eq $USER} @m) {
-	$groups .= " $gid";
+        $groups .= " $gid";
     }
 }
 $) = $groups;
@@ -149,13 +164,13 @@
 
 $qpsmtpd->load_plugins;
 
-foreach my $local_addr ( @LOCALADDR ) {
-    ::log(LOGINFO,"Listening on $local_addr->{'addr'}:$local_addr->{'port'}");
+foreach my $listen_addr ( @LISTENADDR ) {
+    ::log(LOGINFO,"Listening on $listen_addr->{'addr'}:$listen_addr->{'port'}");
 }
 ::log(LOGINFO, 'Running as user '.
-	(getpwuid($>) || $>) .
-	', group '.
-	(getgrgid($)) || $)));
+        (getpwuid($>) || $>) .
+        ', group '.
+        (getgrgid($)) || $)));
 
 if ($DETACH) {
   open STDIN, '/dev/null' or die "/dev/null: $!";
@@ -225,8 +240,8 @@
     my $pid = safe_fork();
     if ($pid) {
       # parent
-      $childstatus{$pid} = $iaddr;	# add to table
-      # $childstatus{$pid} = 1;	# add to table
+      $childstatus{$pid} = $iaddr;        # add to table
+      # $childstatus{$pid} = 1;        # add to table
       $running++;
       close($client);
       next;



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