diff options
Diffstat (limited to 'gnu/usr.sbin/sendmail/contrib/buildvirtuser')
-rw-r--r-- | gnu/usr.sbin/sendmail/contrib/buildvirtuser | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/gnu/usr.sbin/sendmail/contrib/buildvirtuser b/gnu/usr.sbin/sendmail/contrib/buildvirtuser index 3a81d81584e..3adb6fb651a 100644 --- a/gnu/usr.sbin/sendmail/contrib/buildvirtuser +++ b/gnu/usr.sbin/sendmail/contrib/buildvirtuser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -# Copyright (c) 1999-2003 Gregory Neil Shapiro. All Rights Reserved. +# Copyright (c) 1999-2004, 2007 Gregory Neil Shapiro. All Rights Reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -27,7 +27,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -# $Sendmail: buildvirtuser,v 1.6 2003/03/15 23:30:09 gshapiro Exp $ +# $Sendmail: buildvirtuser,v 1.8 2007/10/08 18:44:15 gshapiro Exp $ =head1 NAME @@ -70,30 +70,21 @@ to take affect. =head1 EXAMPLES -Here are some example files from the /etc/mail/virtusers/ directory: +Here is an example file from the /etc/mail/virtusers/ directory: -=head2 /etc/mail/virtusers/bsdunix.org: +=head2 /etc/mail/virtusers/example.org: # Services - MAILER-DAEMON gshapiro+bounce.$DOMAIN@gshapiro.net - postmaster gshapiro+$LHS.$DOMAIN@gshapiro.net - webmaster gshapiro+$LHS.$DOMAIN@gshapiro.net + MAILER-DAEMON gshapiro+bounce.$DOMAIN@example.net + postmaster gshapiro+$LHS.$DOMAIN@example.net + webmaster gshapiro+$LHS.$DOMAIN@example.net # Defaults error:nouser No such user # Users - gshapiro gshapiro+$DOMAIN@gshapiro.net - bob robert@smtp.org - -=head2 /etc/mail/virtusers/smtp.org: - - # Defaults - gshapiro+$DOMAIN@gshapiro.net - - # Users - john john@wookie.org - nancy n@milter.com + gshapiro gshapiro+$DOMAIN@example.net + zoe zoe@example.com =head1 AUTHOR @@ -102,6 +93,7 @@ Gregory Neil Shapiro E<lt>F<gshapiro@gshapiro.net>E<gt> =cut use strict; +use File::stat; use Getopt::Std; my $makemap = "/usr/sbin/makemap"; @@ -117,6 +109,18 @@ my $newest = 0; my ($lhs, $domain, $key, $value); my $opts = {}; +sub preserve_perms ($$) +{ + my $old = shift; + my $new = shift; + my $st; + + $st = stat($old); + return if (!defined($st)); + chmod($st->mode, $new) || warn "Could not chmod($st->mode, $new): $!\n"; + chown($st->uid, $st->gid, $new) || warn "Could not chmod($st->uid, $st->gid, $new): $!\n"; +} + getopts('ft', $opts) || die "Usage: $0 [-f] [-t]\n"; if ($opts->{t}) @@ -131,9 +135,12 @@ closedir(VIRTS) || die "Could not close directory $virts: $!\n"; foreach $domain (@virts) { + next if ($domain =~ m/^\./); open(DOMAIN, "$virts/$domain") || die "Could not open file $virts/$domain: $!\n"; my $line = 0; - my $mtime = (stat(DOMAIN))[9] || 0; + my $mtime = 0; + my $st = stat("$virts/$domain"); + $mtime = $st->mtime if (defined($st)); if ($mtime > $newest) { $newest = $mtime; @@ -160,7 +167,7 @@ LINE: while (<DOMAIN>) } else { - die "Bogus line $line in $virts/$domain\n"; + warn "Bogus line $line in $virts/$domain\n"; } # Variable subsitution @@ -172,7 +179,9 @@ LINE: while (<DOMAIN>) close(DOMAIN) || die "Could not close $virts/$domain: $!\n"; } -my $virtmtime = (stat($virt))[9] || 0; +my $virtmtime = 0; +my $st = stat($virt); +$virtmtime = $st->mtime if (defined($st)); if ($opts->{f} || $virtmtime < $newest) { print STDOUT "Rebuilding $virt\n"; @@ -191,14 +200,17 @@ if ($opts->{f} || $virtmtime < $newest) print MAKEMAP "$key\t\t$virt{$key}\n"; } close(MAKEMAP) || die "Could not close makemap ($?): $!\n"; + preserve_perms($virt, $newvirt); rename($newvirt, $virt) || die "Could not rename $newvirt to $virt: $!\n"; open(VIRTHOST, ">$newvirthosts") || die "Could not open file $newvirthosts: $!\n"; foreach $domain (sort @virts) { + next if ($domain =~ m/^\./); print VIRTHOST "$domain\n"; } close(VIRTHOST) || die "Could not close $newvirthosts: $!\n"; + preserve_perms($virthosts, $newvirthosts); rename($newvirthosts, $virthosts) || die "Could not rename $newvirthosts to $virthosts: $!\n"; } exit 0; |