X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=sync-accounts%2Fsync-accounts;h=50f7e33e174dd742ccec7e03bf66684542f61508;hp=1f48714c991a4b610bd8d26a08e1e304ce594e0d;hb=db8e92be30a7cee18371b629abbd942ffbf49c95;hpb=239b1a05002b535e163e8838f41bee3a56b2ca9e diff --git a/sync-accounts/sync-accounts b/sync-accounts/sync-accounts index 1f48714..50f7e33 100755 --- a/sync-accounts/sync-accounts +++ b/sync-accounts/sync-accounts @@ -1,24 +1,25 @@ #!/usr/bin/perl -# $Id: sync-accounts,v 1.10 1999-01-03 02:16:49 ian Exp $ +# $Id: sync-accounts,v 1.15 1999-01-03 17:45:15 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 +# host(s) may not be specified with -q # # The config file consists of directives, one per line. Leading and # trailing whitespace, blank lines and lines starting # are ignored. # # Some config file directives apply globally and should appear first: # -# lockpasswd -# lockgroup +# lockpasswd [mandatory] +# lockgroup [usu. mandatory] # Specifies the lockfile suffix or pathname to use when editing # the passwd and group files. The value is a suffix if it does # not start with `/'. If set to /dev/null no locking is done. # -# logfile +# logfile [default=stdout] # Append log messages to instead of stdout. # Errors still go to stderr. # @@ -26,24 +27,24 @@ # different points in the file. The most-recently-seen value is used # at each point: # -# uidmin -# uidmax -# homebase +# uidmin [no default] +# uidmax [no default] +# homebase [default=/home] # When an account is to be created, a uid/gid will be chosen # which is one higher than the highest currently in use (except # that ids outside the range - are ignored and will # never be used). The default home directory location is # /. # -# sameuid -# nosameuid +# sameuid [this or uidmin/max req'd for creation] +# nosameuid [default] # Specifies whether uids are supposed to match. The default is # nosameuid. When sameuid is on, it is an error for the uid or # gid of a local account not to match the corresponding remote # account, and new local accounts will get the remote accounts' # ids. # -# usergroups +# usergroups [default] # nousergroups # defaultgid # Specifies whether local accounts are supposed to have @@ -62,8 +63,8 @@ # is `usergroups'. # # createuser -# createuser -# nocreateuser +# createuser [=`createuser sync-accounts-createuser'] +# nocreateuser [default] # Specifies whether accounts found on the remote host should be # created if necessary, and what command to run to do the # creation (eg, setup of home directory). The default is @@ -89,7 +90,7 @@ # the account will not be created after all. # # group -# nogroup +# nogroup [default=`nogroup *'] # Specifies that the membership of the local groups specified # should be adjusted or not adjusted whenever account data for a # particular user is copied, so that the account will be a member @@ -98,24 +99,29 @@ # glob-pattern for a particular group takes effect. The default # is `nogroups *'. # +# defaultshell [default=/bin/sh] +# If, when creating an account, the remote account's shell is not +# available on the local system, this value will be used. The +# default is /bin/sh. +# # Some config file directives are per-host, and should appear before # any directives which actually modify accounts: # -# host +# host [required] # Starts a host's section. This resets the per-host parameters # to the defaults. The shorthostname need not be the host's # official name in any sense. If sync-accounts is invoked with # host names on the command line they are compared with the # shorthostnames. # -# getpasswd -# getgroup +# getpasswd [required] +# getgroup [required for group sync.] # Commands to run on the local host to get the passwd, shadow and # group data for the host in question. getpasswd must be # specified if user data is to be transferred; getgroup must be # specified if group data is to be transferred. # -# getshadow +# getshadow [optional] # Specifies that shadow file data is to be used (by default, # password information is found from the output of getpasswd). # The command should emit shadow data in the format specified by @@ -161,6 +167,7 @@ use POSIX; $configfile= '/etc/sync-accounts'; $def_createuser= 'sync-accounts-createuser'; $ch_homebase= '/home'; +$ch_defaultshell= '/bin/sh'; $defaultgid= -1; # -1 => usergroups; -2 => nousergroups @groupglobs= [ '.*', 0 ]; regroupglobs(); @@ -192,6 +199,8 @@ while ($ARGV[0] =~ m/^-/) { } } +die "hosts must not be specified with -q\n" if @ARGV && $display; + for $h (@ARGV) { $wanthost{$h}= 1; } open CF,"< $configfile" or die "$configfile: $!"; @@ -356,8 +365,8 @@ sub syncuser ($$) { my ($lu,$ru) = @_; #print STDERR "syncuser($lu,$ru)\n"; - next unless $ch_doinghost; return if $doneuser{$lu}++; + next unless $ch_doinghost; return if !length $ru; fetchown(); @@ -409,7 +418,7 @@ sub syncuser ($$) { } @newpwent= ($lu,'x',$useuid,$usegid,$rempasswd{$ru}->[4], - "$ch_homebase/$lu",$rempasswd{$ru}->[6]); + "$ch_homebase/$lu",$ch_defaultshell); defined($c= open CU,"-|") or die $!; if (!$c) { @@ -469,7 +478,11 @@ sub syncuser ($$) { copyfield('passwd',$lu,1, $rempasswd{$ru}->[1]); } copyfield('passwd',$lu,4, $rempasswd{$ru}->[4]); # comment - copyfield('passwd',$lu,6, $rempasswd{$ru}->[6]); # shell + + $newsh= $rempasswd{$ru}->[6]; + $oksh= $checkedshell{$newsh}; + if (!length $oksh) { $checkedshell{$newsh}= $oksh= (-x $newsh) ? 1 : 0; } + copyfield('passwd',$lu,6, $newsh) if $oksh; if (!$nogroups) { for $e (@owngroup) { @@ -540,14 +553,14 @@ sub finish () { die $file unless $fetched; banner(); $newfile= $no_act ? "$file.new" : "/etc/$file.new"; - open NF,"> $newfile"; + open NF,"> $newfile" or die "$newfile: $!"; for $e (@$data_ref) { print NF join(':',@$e),"\n" or die $!; } close NF or die $!; system "diff -U0 /etc/$file $newfile"; $?==256 or die $?; if (!$no_act) { - (@stats= stat $file) or die "$file: $!"; + (@stats= stat "/etc/$file") or die "$file: $!"; chown $stats[4],$stats[5], $newfile or die $!; chmod $stats[2] & 07777, $newfile or die $!; rename $newfile, "/etc/$file" or die $!; @@ -577,7 +590,7 @@ while () { eval "\$ch_$1= \$2; 1;" or die $@; } elsif (m/^(lockpasswd|lockgroup)\s+(\S+)$/) { eval "\$ch_$1= \$2; 1;" or die $@; - } elsif (m,^(homebase)\s+(/\S+)$,) { + } elsif (m,^(homebase|defaultshell)\s+(/\S+)$,) { eval "\$ch_$1= \$2; 1;" or die $@; } elsif (m/^(uidmin|uidmax)\s+(\d+)$/ && $2>0) { eval "\$ch_$1= \$2; 1;" or die $@;