#!/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<config-file>] [<host> ...]
# 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
$configfile= $';
} elsif (m/^-n$/) {
$no_act= 1;
+ $display= 0;
+ } elsif (m/^-q$/) {
+ $no_act= 1;
+ $display= 1;
} else {
die "unknown option $_\n";
}
$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) = @_;
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 "<DUPLICATE>" if $displaydone{$lu}++;
+ }
+ return;
+ }
+
+ $diagstr= "user $lu from $ch_name!$ru";
+
#print STDERR "syncuser($lu,$ru) doing\n";
fetchpasswd();
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)) {
} 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 $@;