From 6259c9f49cd5bd3c9aa83aa80d78e88b810a4f92 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 3 Jan 1999 00:53:07 +0000 Subject: [PATCH] New -q mode. --- sync-accounts/sync-accounts | 60 +++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/sync-accounts/sync-accounts b/sync-accounts/sync-accounts index 70a9e76..5bd7a39 100755 --- a/sync-accounts/sync-accounts +++ b/sync-accounts/sync-accounts @@ -1,9 +1,10 @@ #!/usr/bin/perl -# $Id: sync-accounts,v 1.4 1999-01-03 00:14:07 ian Exp $ +# $Id: sync-accounts,v 1.5 1999-01-03 00:53:07 ian Exp $ # usage: sync-accounts [-n] [-C] [ ...] # options: # -n do not really do anything # -C alternative config file (default is /etc/sync-accounts) +# -q display accounts synched, not synched, etc. # if no host(s) specified, does all # # The config file consists of directives, one per line. Leading and @@ -160,6 +161,10 @@ while ($ARGV[0] =~ m/^-/) { $configfile= $'; } elsif (m/^-n$/) { $no_act= 1; + $display= 0; + } elsif (m/^-q$/) { + $no_act= 1; + $display= 1; } else { die "unknown option $_\n"; } @@ -316,7 +321,15 @@ sub syncusergroup ($$) { $modifiedgroup= 1; return 1; } - + +sub hosthead ($) { + my ($th) = @_; + return if $hostheaddone eq $th; + print "\n\n" or die $! if length $hostheaddone; + print "==== $th ====\n" or die $!; + $hostheaddone= $th; +} + sub syncuser ($$) { my ($lu,$ru) = @_; @@ -324,9 +337,21 @@ sub syncuser ($$) { next unless $ch_doinghost; return if $doneuser{$lu}++; return if !length $ru; - $diagstr= "user $lu from $ch_name!$ru"; fetchown(); + + if ($display) { + for $e (@ownpasswd) { + next unless $e->[0] eq $lu; + hosthead("from $ch_name"); + print ($lu eq $ru ? " $lu" : " $lu($ru)") or die $!; + print "" if $displaydone{$lu}++; + } + return; + } + + $diagstr= "user $lu from $ch_name!$ru"; + #print STDERR "syncuser($lu,$ru) doing\n"; fetchpasswd(); @@ -458,6 +483,29 @@ sub finish () { for $h (keys %wanthost) { die "host $h not in config file\n" if $wanthost{$h}; } + + if ($display) { + for $pw (1,-1,0) { +#print STDERR "\n\nfinish display=$display pw=$pw\n\n"; + for $e (@ownpasswd) { + $tu= $e->[0]; + next if $displaydone{$tu}; + $tpw= $e->[1]; + for $e2 (@ownshadow) { + next unless $e2->[0] eq $tu; + $tpw= $e2->[1]; last; + } + $tpw= length($tpw)==13 ? 1 : length($tpw) ? -1 : 0; + next unless $pw == $tpw; + hosthead($pw == 1 ? "unsynched normal account" : + $pw == 0 ? "unsynched, passwordless" : + "unsynched, no logins"); + print " $e->[0]" or die $!; + } + } + print "\n\n" or die $! if $hostheaddone; + exit 0; + } umask 077; for $file (qw(passwd shadow group)) { @@ -519,10 +567,10 @@ while () { } elsif (m/^createuser\s+(\S+)$/) { $opt_createuser= $1; } elsif (m/^logfile\s+(.*\S)$/) { - if ($no_act) { - print "would log to $1\n" or die $!; - } else { + if (!$no_act) { open STDOUT,">> $1" or die "$1: $!"; $|=1; + } elsif (!$display) { + print "would log to $1\n" or die $!; } } elsif (m/^(no|)(sameuid|usergroups)$/) { eval "\$opt_$2= ".($1 eq 'no' ? 0 : 1)."; 1;" or die $@; -- 2.30.2