cvs commit: qpsmtpd qpsmtpd-forkserver

[email protected] (Devin Carraway)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     04/06/27 20:05:03

  Modified:    .        qpsmtpd-forkserver
  Log:
  - Enable taint checking
  - Allow most operating parameters (bind address, port, etc) to be overriden
    on the commandline
  - Drop an unused scalar
  - Minor logging improvements
  
  Revision  Changes    Path
  1.5       +32 -4     qpsmtpd/qpsmtpd-forkserver
  
  Index: qpsmtpd-forkserver
  ===================================================================
  RCS file: /cvs/public/qpsmtpd/qpsmtpd-forkserver,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- qpsmtpd-forkserver	16 Jun 2004 20:27:51 -0000	1.4
  +++ qpsmtpd-forkserver	28 Jun 2004 03:05:03 -0000	1.5
  @@ -1,4 +1,4 @@
  -#!/usr/bin/perl -w
  +#!/usr/bin/perl -Tw
   # Copyright (c) 2001 Ask Bjoern Hansen. See the LICENSE file for details.
   # The "command dispatch" system is taken from colobus - http://trainedmonkey.com/colobus/
   #
  @@ -11,6 +11,7 @@
   use Qpsmtpd::Constants;
   use IO::Socket;
   use Socket;
  +use Getopt::Long;
   use POSIX qw(:sys_wait_h :errno_h :signal_h);
   use strict;
   $| = 1;
  @@ -21,6 +22,29 @@
   my $LOCALADDR = '0.0.0.0';		# ip address to bind to
   my $USER      = 'smtpd';		# user to suid to
   
  +sub usage {
  +        print <<"EOT";
  +usage: qpsmtpd-forkserver [ options ]
  + -l, --listen-address addr : listen on a specific address; default 0.0.0.0
  + -p, --port P              : listen on a specific port; default 25
  + -c, --limit-connections N : limit concurrent connections to N; default 15
  + -u, --user U              : run as a particular user (defualt 'smtpd')
  +EOT
  +        exit 0;
  +}
  +
  +GetOptions('h|help' => \&usage,
  +           'l|listen-address=s' => \$LOCALADDR,
  +           'c|limit-connections=i' => \$MAXCONN,
  +           'p|port=i' => \$PORT,
  +           'u|user=s' => \$USER) || &usage;
  +
  +# detaint the commandline
  +if ($PORT =~ /^(\d+)$/) { $PORT = $1 } else { &usage }
  +if ($LOCALADDR =~ /^([\d\w\-.]+)$/) { $LOCALADDR = $1 } else { &usage }
  +if ($USER =~ /^([\w\-]+)$/) { $USER = $1 } else { &usage }
  +if ($MAXCONN =~ /^(\d+)$/) { $MAXCONN = $1 } else { &usage }
  +
   delete $ENV{ENV};
   $ENV{PATH} = '/bin:/usr/bin:/var/qmail/bin';
   
  @@ -51,10 +75,10 @@
                                      Proto     => 'tcp',
                                      Reuse     => 1,
                                      Listen    => SOMAXCONN )
  -  or die "making socket: $@\n";
  +  or die "Creating TCP socket $LOCALADDR:$PORT: $!\n";
  +::log(LOGINFO,"Listening on port $PORT");
   
   # Drop priviledges
  -my $user = 'mailfw';
   my (undef, undef, $quid, $qgid) = getpwnam $USER or
         die "unable to determine uid/gid for $USER\n";
   $) = "";
  @@ -64,11 +88,15 @@
         die "unable to change uid: $!\n";
   $> = $quid;
   
  +::log(LOGINFO, 'Running as user '.
  +	(getpwuid($>) || $>) .
  +	', group '.
  +	(getgrgid($)) || $)));
  +
   # Load plugins here
   my $plugin_loader = Qpsmtpd::TcpServer->new();
   $plugin_loader->load_plugins;
   
  -::log(LOGINFO,"Listening on port $PORT\n");
   
   while (1) {
     my $running = scalar keys %childstatus;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.