added syslog
This commit is contained in:
parent
4e93ecb202
commit
7c0d769fa9
1 changed files with 19 additions and 13 deletions
|
|
@ -5,6 +5,7 @@ use warnings;
|
|||
use Config;
|
||||
use IO::Socket;
|
||||
use IO::Select;
|
||||
use Sys::Syslog qw(:standard :macros);
|
||||
use IPC::Run qw(start finish);
|
||||
|
||||
# Configs
|
||||
|
|
@ -26,8 +27,8 @@ sub read_timeout {
|
|||
}
|
||||
|
||||
my ($r_uid,$r_gid) = (getpwnam("root"))[2,3];
|
||||
my $s_gid = (getpwnam($smtp_group))[3] or die "group '$smtp_group' not found: $!";
|
||||
my $w_gid = (getpwnam($www_group))[3] or die "group '$www_group' not found: $!";
|
||||
my $s_gid = (getpwnam($smtp_group))[3] or die "group '${smtp_group}' not found: $!";
|
||||
my $w_gid = (getpwnam($www_group))[3] or die "group '${www_group}' not found: $!";
|
||||
my $authfiletmp = "${authfile}.tmp";
|
||||
|
||||
if ($Config{osname} eq "openbsd") {
|
||||
|
|
@ -42,8 +43,9 @@ if ($Config{osname} eq "openbsd") {
|
|||
pledge("rpath wpath cpath fattr chown unix proc exec prot_exec") or die "Unable to pledge: $!";
|
||||
}
|
||||
|
||||
openlog("smtp_auth_sync", "ndelay,pid", LOG_AUDIT) or die "Could not open syslog: $!";
|
||||
if (-e $sfile) {
|
||||
unlink $sfile or die "Could not delete socket file '$sfile': $!";
|
||||
unlink $sfile or die "Could not delete socket file '${sfile}': $!";
|
||||
}
|
||||
my $sock = IO::Socket::UNIX->new(
|
||||
Type => SOCK_STREAM(),
|
||||
|
|
@ -62,8 +64,8 @@ sub cleanup {
|
|||
$SIG{INT} = \&cleanup;
|
||||
$SIG{TERM} = \&cleanup;
|
||||
|
||||
my $enc = "$smtpctl encrypt";
|
||||
my $update = "$smtpctl update table secrets";
|
||||
my @enc = (${smtpctl}, "encrypt");
|
||||
my @update = (${smtpctl}, "update", "table", "secrets");
|
||||
while (my $conn = $sock->accept()) {
|
||||
my $user;
|
||||
my $pass;
|
||||
|
|
@ -80,6 +82,7 @@ while (my $conn = $sock->accept()) {
|
|||
my $h = start(\@enc, \<<IN, \$hash);
|
||||
$pass
|
||||
IN
|
||||
finish $h or next;
|
||||
chomp($hash);
|
||||
if ($hash eq "") {
|
||||
next;
|
||||
|
|
@ -88,31 +91,34 @@ IN
|
|||
open(my $auth, ">", $authfile) or next;
|
||||
chown($r_uid, $s_gid, $authfile);
|
||||
chmod(0640, $authfile);
|
||||
print $auth "$user $hash\n";
|
||||
print $auth "${user} ${hash}\n";
|
||||
close($auth);
|
||||
next;
|
||||
}
|
||||
my $found = 0;
|
||||
open(my $auth, "<", $authfile) or do { print "Could not open file '$authfile': $!"; next; };
|
||||
open(my $auth, "<", $authfile) or do { print "Could not open file '${authfile}': $!"; next; };
|
||||
chown($r_uid, $s_gid, $authfile);
|
||||
chmod(0640, $authfile);
|
||||
open(my $authtmp, ">", $authfiletmp) or do { print "Could not open file '$authfiletmp': $!"; next; };
|
||||
open(my $authtmp, ">", $authfiletmp) or do { print "Could not open file '${authfiletmp}': $!"; next; };
|
||||
chown($r_uid, $s_gid, $authfiletmp);
|
||||
chmod(0640, $authfiletmp);
|
||||
while (<$auth>) {
|
||||
my $line = $_;
|
||||
if ($line =~ /$user/) {
|
||||
print $authtmp "$user $hash\n";
|
||||
print $authtmp "${user} ${hash}\n";
|
||||
$found = 1;
|
||||
} else {
|
||||
print $authtmp "$line";
|
||||
print $authtmp "${line}";
|
||||
}
|
||||
}
|
||||
if ($found == 0) {
|
||||
print $authtmp "$user $hash\n";
|
||||
print $authtmp "${user} ${hash}\n";
|
||||
}
|
||||
close($auth);
|
||||
close($authtmp);
|
||||
rename($authfiletmp, $authfile);
|
||||
system("$update >/dev/null");
|
||||
my $out;
|
||||
my $u = start(\@update, \undef, \$out);
|
||||
finish $u or next;
|
||||
syslog(LOG_INFO, "updated password of user ${user}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue