Mail-Milter-Authentication
view release on metacpan or search on metacpan
lib/Mail/Milter/Authentication.pm view on Meta::CPAN
my $listen_backlog = $config->{'listen_backlog'} || 20;
my $max_children = $config->{'max_children'} || 100;
my $max_requests_per_child = $config->{'max_requests_per_child'} || 200;
my $min_children = $config->{'min_children'} || 20;
my $max_spare_children = $config->{'max_spare_children'} || 20;
my $min_spare_children = $config->{'min_spare_children'} || 10;
my %srvargs;
$srvargs{'no_client_stdout'} = 1;
if ( $args->{'daemon'} ) {
if ( $EUID == 0 ) {
_warn(
join( ' ',
'daemonize',
"servers=$min_children/$max_children",
"spares=$min_spare_children/$max_spare_children",
"requests=$max_requests_per_child",
)
);
$srvargs{'background'} = 1;
$srvargs{'setsid'} = 1;
}
else {
_warn("Not running as root, daemonize ignored!");
}
}
$srvargs{'pid_file'} = $pid_file;
$srvargs{'max_servers'} = $max_children;
$srvargs{'max_requests'} = $max_requests_per_child;
$srvargs{'min_servers'} = $min_children;
$srvargs{'min_spare_servers'} = $min_spare_children;
$srvargs{'max_spare_servers'} = $max_spare_children;
$srvargs{'log_file'} = 'Sys::Syslog';
$srvargs{'syslog_facility'} = LOG_MAIL;
$srvargs{'syslog_ident'} = $Mail::Milter::Authentication::Config::IDENT;
$srvargs{'syslog_logopt'} = 'pid';
$srvargs{'syslog_logsock'} = 'native';
if ( $EUID == 0 ) {
my $user = $config->{'runas'};
my $group = $config->{'rungroup'};
if ( $user && $group ) {
_warn("run as user=$user group=$group");
$srvargs{'user'} = $user;
$srvargs{'group'} = $group;
}
else {
_warn("No runas details supplied, could not drop privs - be careful!");
}
# Note, Chroot requires a chroot environment which is out of scope at present
if ( $config->{'error_log'} ) {
if ( ! -e $config->{'error_log'} ) {
open my $outf, '>', $config->{'error_log'} || die "Could not create error log: $!\n";;
close $outf;
}
if ( $user ) {
my ($login,$pass,$uid,$gid) = getpwnam($user);
chown $uid, $gid, $config->{'error_log'};
}
}
if ( exists( $config->{'chroot'} ) ) {
_warn('Chroot to ' . $config->{'chroot'});
$srvargs{'chroot'} = $config->{'chroot'};
}
}
else {
_warn("Not running as root, could not drop privs - be careful!");
}
my $connections = {};
if ( exists $config->{'connections'} ) {
$connections = $config->{'connections'};
}
$connections->{'default'} = {
'connection' => $default_connection,
'umask' => $config->{'umask'},
};
my @ports;
foreach my $key ( keys %$connections ) {
my $connection = $connections->{$key}->{'connection'};
my $umask = $connections->{$key}->{'umask'};
$connection =~ /^([^:]+):([^:@]+)(?:@([^:@]+|\[[0-9a-f:\.]+\]))?$/;
my $type = $1;
my $path = $2;
my $host = $3 || q{};
if ( $type eq 'inet' ) {
_warn(
join( ' ',
'listening on inet',
"host=$host",
"port=$path",
"backlog=$listen_backlog",
)
);
push @ports, {
'host' => $host,
'port' => $path,
'ipv' => '*',
'proto' => 'tcp',
};
}
elsif ( $type eq 'unix' ) {
_warn(
join( ' ',
'listening on unix',
"socket=$path",
"backlog=$listen_backlog",
)
);
push @ports, {
'port' => $path,
'proto' => 'unix',
};
( run in 1.175 second using v1.01-cache-2.11-cpan-524268b4103 )