2 # $Id: sync-accounts,v 1.16 2001-03-06 18:34:36 ian Exp $
4 # Copyright (C)1999 Ian Jackson <ian@davenant.greenend.org.uk>
6 # This is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2, or (at your option) any later
11 # This is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # You should already have a copy of the GNU General Public License.
17 # If not, write to the Free Software Foundation, Inc., 59 Temple
18 # Place - Suite 330, Boston, MA 02111-1307, USA.
20 # usage: sync-accounts [-n] [-C<config-file>] [<host> ...]
22 # -n do not really do anything
23 # -C alternative config file (default is /etc/sync-accounts)
24 # -q display accounts synched, not synched, etc.
25 # if no host(s) specified, does all
26 # host(s) may not be specified with -q
28 # The config file consists of directives, one per line. Leading and
29 # trailing whitespace, blank lines and lines starting # are ignored.
31 # Some config file directives apply globally and should appear first:
33 # lockpasswd link <suffix/filename>
34 # lockgroup link <suffix/filename>
35 # Specifies the lockfile suffix or pathname to use when editing
36 # the passwd and group files. The value is a suffix if it does
37 # not start with `/'. If set to /dev/null no locking is done.
39 # lockpasswd runvia <program>
40 # lockgroup runvia <program>
41 # Lock by reinvoking ourselves via a program as EDITOR.
42 # (<program> would typically be vipw or vigr.)
49 # Append log messages to <filename> instead of stdout.
50 # Errors still go to stderr.
53 # Specifies the local password file is in the relevant format:
54 # `std' is the standard V7 password file (with a SysV- style
55 # /etc/shadow if one is detected at run-time); `bsd' is the weird
56 # BSD4.4 master.passwd format, and should be used only with
57 # `lockpasswd runvia vipw'. The default is `std'.
59 # Some config file directives set options which may be different at
60 # different points in the file. The most-recently-seen value is used
66 # When an account is to be created, a uid/gid will be chosen
67 # which is one higher than the highest currently in use (except
68 # that ids outside the range <min>-<max> are ignored and will
69 # never be used). The default home directory location is
70 # <pathname>/<username>.
74 # Specifies whether uids are supposed to match. The default is
75 # nosameuid. When sameuid is on, it is an error for the uid or
76 # gid of a local account not to match the corresponding remote
77 # account, and new local accounts will get the remote accounts'
83 # Specifies whether local accounts are supposed to have
84 # corresponding groups, or all be part of a particular group. If
85 # usergroups is set, when a new account is created, the
86 # corresponding per-user group will be created as well, and
87 # per-user groups are created for existing accounts if necessary
88 # (if account creation is enabled). If the gid or group name for
89 # a per-user group is already taken for a different group name or
90 # gid this will be logged, and processing of that account will be
91 # inhibited, but it is not a fatal error. If defaultgid is used,
92 # then newly-created accounts will be made a part of that group,
93 # and the groups of existing accounts will be left alone. If
94 # nousergroups is specified then no new accounts can be created,
95 # and existing accounts' groups will be left alone. The default
99 # createuser <commandname>
101 # Specifies whether accounts found on the remote host should be
102 # created if necessary, and what command to run to do the
103 # creation (eg, setup of home directory). The default is
104 # nocreateuser. If createuser is specified without a commandname
105 # then sync-accounts-createuser is used. The command is found on
106 # the PATH if necessary. Either sameuid, or both uidmin and
107 # uidmax, must be specified, if accounts are to be created.
109 # The command (which will be run with sh -c) must at least create
110 # the new account's home directory. The passwd and group entries
111 # will not have been set up. The following environment variables
112 # will be set, giving details about the account to be created:
113 # SYNCUSER_CREATE_USER
114 # SYNCUSER_CREATE_UID
115 # SYNCUSER_CREATE_GID
116 # SYNCUSER_CREATE_COMMENT
117 # SYNCUSER_CREATE_HOME
118 # SYNCUSER_CREATE_SHELL
119 # If it chooses, the script may modify the password entry which
120 # will be added to the system, by outputting a replacement
121 # password file entry. (The password field of that is ignored.)
122 # If the script outputs a line which does not contain a : then
123 # the account will not be created after all.
125 # group <glob-pattern>
126 # nogroup <glob-pattern>
127 # Specifies that the membership of the local groups specified
128 # should be adjusted or not adjusted whenever account data for a
129 # particular user is copied, so that the account will be a member
130 # of the affected group locally iff it is a member of the same
131 # group on the remote host. The most recently-encountered
132 # glob-pattern for a particular group takes effect. The default
135 # defaultshell <pathname>
136 # If, when creating an account, the remote account's shell is not
137 # available on the local system, this value will be used. The
138 # default is /bin/sh.
140 # Some config file directives are per-host, and should appear before
141 # any directives which actually modify accounts:
143 # host <shorthostname>
144 # Starts a host's section. This resets the per-host parameters
145 # to the defaults. The shorthostname need not be the host's
146 # official name in any sense. If sync-accounts is invoked with
147 # host names on the command line they are compared with the
150 # getpasswd <command>
152 # Commands to run on the local host to get the passwd, shadow and
153 # group data for the host in question. getpasswd must be
154 # specified if user data is to be transferred; getgroup must be
155 # specified if group data is to be transferred.
157 # getshadow <command>
158 # Specifies that shadow file data is to be used (by default,
159 # password information is found from the output of getpasswd).
160 # The command should emit shadow data in the format specified by
161 # shadow(5) on Linux. getshadow should not be specified without
164 # remoteformat std|bsd
165 # Specifies the format of the output of `getpasswd'. `std' is
166 # standard V7 passwd file format (optionally augmented by the use
167 # of a shadow file fetched with getshadow). `bsd' is the weird
168 # BSD4.4 master.passwd format (and getshadow should not normally
169 # be used with `remoteformat bsd'). The default is `std'.
171 # Some configuration file directives specify that account data is to
172 # transferred from the current host. They should appear as the last
173 # thing(s) in a host section:
175 # user <username> [remote=<remoteusername>]
176 # Specifies that account data should be copied for local user
177 # <username> from the remote account <remoteusername> (assumed to
178 # be the same as <username> if not specified). The account
179 # password, comment field, and shell will be copied
180 # unconditionally. If sameuid is specified the uid will be
183 # users <ruidmin>-<ruidmax>
184 # Specifies that all remote users whose uid is in the given range
185 # are to be copied to corresponding local user accounts.
188 # Specifies that data for <username> is _not_ to be copied, even
189 # if subsequent user or users directives suggest that it should
192 # (A note is made when a `user', `users' or `nouser' directive is
193 # encountered for a particular account, and no subsequent directives
194 # for that account will take effect.)
197 # This directive has no effect on `sync-accounts'. However, it
198 # is used as a placeholder by `grab-account': new accounts for
199 # creation are inserted just before `addhere'.
201 # Finally, the config file must finish with:
207 $configfile= '/etc/sync-accounts';
208 $def_createuser= 'sync-accounts-createuser';
209 $ch_homebase= '/home';
210 $ch_defaultshell= '/bin/sh';
211 $defaultgid= -1; # -1 => usergroups; -2 => nousergroups
212 @groupglobs= [ '.*', 0 ];
215 $file{'passwd','std'}= 'passwd';
216 $file{'shadow','std'}= 'shadow';
217 $file{'group','std'}= 'group';
219 $file{'passwd','bsd'}= 'master.passwd';
220 $file{'shadow','bsd'}= 'shadow-non-existent';
221 $file{'group','bsd'}= 'group';
223 @fields_pw_std= qw(USER PW UID GID COMMENT HOME SHELL);
224 @fields_pw_bsd= qw(USER PW UID GID CLASS CHANGE EXPIRE COMMENT HOME SHELL);
225 fields_fmt('PW','std');
226 fields('GR',qw(GROUP PW GID USERS));
227 fields('SP',qw(USER PW DAYSCHGD DAYSFIX DAYSEXP DAYSWARN DAYSEXPDIS DAYSDISD RESERVED));
228 # The name field had better always be field 0 !
231 foreach $x (@unlocks) {
232 ($fn, $style, $arg) = @$x;
233 &{ "unlock_$style" } ( $fn,$arg );
240 foreach $v (@l) { $vn= "${pfx}_$v"; $$vn = $i++; }
241 $vn= "${pfx}_fields"; $$vn= $i;
244 sub fields_fmt ($$) {
247 $vn= "fields_pw_$fmt";
248 die "unknown format $fmt\n" unless defined @$vn;
250 $vn= "${pfx}_format";
255 my ($pfx,$name,@field_val_list) = @_;
256 my (@rv, $vn, $fn, $v, $i);
258 $vn= "${pfx}_fields";
259 for ($i=0; $i<$$vn; $i++) { $rv[$i]= ''; }
260 die "@field_val_list ?" if @field_val_list % 2;
262 while (@field_val_list) {
263 ($fn,$v,@field_val_list) = @field_val_list;
265 #print STDERR ">$fn|$v|$vn|$$vn<\n";
272 $cdays= int(time/86400);
274 @envs_createuser= qw(USER UID GID COMMENT HOME SHELL);
276 if (@ARGV == 1 && length $ENV{'SYNC_ACCOUNTS_RUNVIA_INFO'}) {
278 s/\%([0-9a-f][0-9a-f])/ pack("C", hex $1) /ge;
280 } split(/\:/, $ENV{'SYNC_ACCOUNTS_RUNVIA_INFO'});
281 delete $ENV{'SYNC_ACCOUNTS_RUNVIA_INFO'};
283 $ENV{"SYNC_ACCOUNTS_RUNVIA_LOCKEDGOT_$ta"} = $ARGV[0];
289 while ($ARGV[0] =~ m/^-/) {
301 die "unknown option $_\n";
305 die "hosts must not be specified with -q\n" if @ARGV && $display;
307 for $h (@ARGV) { $wanthost{$h}= 1; }
309 open CF,"< $configfile" or die "$configfile: $!";
311 sub fetchfile (\%$) {
312 my ($ary_ref,$get_str) = @_;
315 open G,"$get_str" or die "$get_str: $!";
318 m/^([^:]+)\:/ or die "$ch_name: $get_str:$.: $_ ?\n";
319 $ary_ref->{$1}= [ split(/\:/,$_,-1) ];
321 close G; $? and die "$ch_name: $get_str: exit code $?\n";
324 sub lockstyle_ ($$) {
327 die "$configfile:$.: locking mechanism for $fn not".
328 " defined (use lockpasswd/lockgroup)\n";
335 $lock= "$fn$lock" unless $lock =~ m,^/,;
339 sub lock_none ($$) { return (abslock(@_))[0]; }
340 sub unlock_none ($$) { }
343 my ($fn,$lock) = abslock(@_);
344 link $fn,$lock or die "cannot lock $fn by creating $lock: $!\n";
347 sub unlock_link ($$) {
348 my ($fn,$lock) = abslock(@_);
349 unlink $lock or warn "unable to unlock by removing $lock: $!\n";
352 sub lock_runvia ($$) {
355 $evn= "SYNC_ACCOUNTS_RUNVIA_LOCKEDGOT_$fn";
356 return $ENV{$evn} if exists $ENV{$evn};
359 s/\W/ sprintf("%%%02x", unpack("C", $&)) /ge;
362 $ENV{'SYNC_ACCOUNTS_RUNVIA_INFO'}= join(":", @na);
364 delete $ENV{'VISUAL'};
365 exec $lock; die "cannot lock $fn by executing $lock: $!\n";
367 sub unlock_runvia ($$) { }
369 sub fetchownfile (\@$$$$) {
370 my ($ary_ref,$fn_str,$nfields,$style,$lock_arg) = @_;
371 my ($fn_use, $record, $fn_emsg);
374 $fn_use= &{ "lock_$style" } ($fn_str, $lock_arg);
375 push @unlocks, [ $fn_str, $style, $lock_arg ];
376 $savebackto{$fn_str}= $fn_use;
378 $fn_use= $fn_emsg= "/etc/".$file{$fn_str,$PW_format};
380 open O,"$fn_use" or die "$fn_use ($fn_str): $!";
383 $record= [ split(/\:/,$_,-1) ];
384 die "$fn_emsg:$.:wrong number of fields:\`$_'\n"
385 unless @$record == $nfields;
386 push @$ary_ref, $record;
388 close O or die "$fn_use ($fn_str): $!";
392 print "$diagstr: $_[0]\n" or die $!;
395 sub regroupglobs () {
396 $nogroups= (@groupglobs == 1 &&
397 $groupglobs[0]->[0] eq '.*' &&
398 !$groupglobs[0]->[1]);
399 $ggfunc= "sub wantsyncgroup {\n \$_= \$_[0];\n return\n";
400 for $g (@groupglobs) { $ggfunc.= " m/^$g->[0]\$/ ? $g->[1] :\n"; }
401 $ggfunc.= " die;\n};\n1;\n";
402 #print STDERR "$ggfunc\n";
403 eval $ggfunc or die "$ggfunc // $@";
407 if (!$own_fetchedpasswd) {
408 #print STDERR ">$PW_fields<\n";
409 fetchownfile(@ownpasswd,'passwd',
410 $PW_fields, $ch_lockstyle_passwd, $ch_lock_passwd);
411 $shadowfile= $file{'shadow',$PW_format};
412 if (stat("/etc/$shadowfile")) {
414 $own_fetchedshadow= 1;
415 fetchownfile(@ownshadow,'shadow',$SP_fields,'none','');
416 } elsif ($! == &ENOENT) {
419 die "unable to check for /etc/$shadowfile: $!\n";
421 $own_fetchedpasswd= 1;
423 if (!$own_fetchedgroup) {
424 fetchownfile(@owngroup,'group',$GR_fields,
425 $ch_lockstyle_group, $ch_lock_group);
426 $own_fetchedgroup= 1;
428 #print STDERR "fetchown() -> $#ownpasswd $#owngroup\n";
432 my ($useuid,$foruser) = @_;
433 for $e (@ownpasswd) {
434 if ($e->[$PW_USER] ne $foruser && $e->[$PW_UID] == $useuid) {
435 diag("uid clash with $e->[$PW_USER] (uid $e->[$PW_UID])");
442 sub copyfield ($$$$) {
443 my ($file,$entry,$field,$value) = @_;
444 eval "\$ary_ref= \\\@own$file; 1;" or die $@;
445 #print STDERR "copyfield($file,$entry,$field,$value)\n";
447 #print STDERR "copyfield($file,$entry,$field,$value) $e->[0] $e->[field] ".join(':',@$e)."\n";
448 next unless $e->[0] eq $entry;
449 next if $e->[$field] eq $value;
450 $e->[$field]= $value;
451 eval "\$modified$file= 1; 1;" or die $@;
456 return if $ch_fetchedpasswd;
457 die "$configfile:$.: getpasswd not specified for host $ch_name\n"
458 unless length $ch_getpasswd;
460 fetchfile(%rempasswd,"$ch_getpasswd |");
461 if (length $ch_getshadow) {
462 fetchfile(%remshadow,"$ch_getshadow |");
463 for $k (keys %rempasswd) {
464 $rempasswd{$k}->[$REM_PW]= 'xx' unless length $rempasswd{$k}->[$REM_PW];
466 for $k (keys %remshadow) {
467 next unless exists $rempasswd{$k};
468 $rempasswd{$k}->[$REM_PW]= $remshadow{$k}->[$SP_PW];
471 $ch_fetchedpasswd= 1;
475 return if $ch_fetchedgroup;
476 die "$configfile:$.: getgroup not specified for host $ch_name\n"
477 unless length $ch_getgroup;
478 fetchfile(%remgroup,"$ch_getgroup |");
482 sub syncusergroup ($$) {
485 return 1 if $defaultgid != -1;
486 #print STDERR "syncusergroup($lu,$luid)\n";
490 $samename= $e->[$GR_GROUP] eq $lu;
491 $sameid= $e->[$GR_GID] eq $luid;
492 next unless $samename || $sameid;
493 if (!$samename || !$sameid) {
494 diag("local group $e->[$GR_GROUP] ($e->[$GR_GID]) mismatch vs.".
495 " local user $lu ($luid)");
499 diag("per-user group $lu ($luid) duplicated");
505 return 1 if $ugfound;
507 if (!length $opt_createuser) {
508 diag("account creation not enabled, not creating per-user group");
511 push @owngroup, [ newentry('GR', $lu,
520 return if $hostheaddone eq $th;
521 print "\n\n" or die $! if length $hostheaddone;
522 print "==== $th ====\n" or die $!;
530 #print STDERR "syncuser($lu,$ru)\n";
531 return if $doneuser{$lu}++;
532 next unless $ch_doinghost;
533 return if !length $ru;
538 for $e (@ownpasswd) {
539 next unless $e->[$PW_USER] eq $lu;
540 hosthead("from $ch_name");
541 print ($lu eq $ru ? " $lu" : " $lu($ru)") or die $!;
542 print "<DUPLICATE>" if $displaydone{$lu}++;
547 $diagstr= "user $lu from $ch_name!$ru";
549 #print STDERR "syncuser($lu,$ru) doing\n";
552 if (!$rempasswd{$ru}) { diag("no remote entry"); return; }
553 if (length $ch_getshadow && exists $remshadow{$ru} &&
554 length $remshadow{$ru}->[$SP_DAYSDISD]) {
555 diag("remote account disabled in shadow");
559 if (!grep($_->[$PW_USER] eq $lu, @ownpasswd)) {
560 if (!length $opt_createuser) { diag("account creation not enabled"); return; }
561 if ($no_act) { diag("-n specified; not creating account"); return; }
564 $useuid= $rempasswd{$ru}->[$REM_UID];
565 $usegid= $rempasswd{$ru}->[$REM_GID];
567 die "nousergroups specified, cannot create users\n" if $defaultgid==-2;
568 length $ch_uidmin or die "no uidmin specified, cannot create users\n";
569 length $ch_uidmax or die "no uidmax specified, cannot create users\n";
570 $ch_uidmin<$ch_uidmax or die "uidmin>=uidmax, cannot create users\n";
573 for $e ($defaultgid==-1 ? (@ownpasswd, @owngroup) : (@ownpasswd)) {
574 $tuid= $e->[$PW_UID]; next if $tuid<$useuid || $tuid>$ch_uidmax;
575 if ($tuid==$ch_uidmax) {
576 diag("uid (or gid?) $ch_uidmax used, cannot create users");
581 $usegid= $defaultgid==-1 ? $useuid : $defaultgid;
584 @newpwent= newentry('PW', $lu,
588 'COMMENT', $rempasswd{$ru}->[$REM_COMMENT],
589 'HOME', "$ch_homebase/$lu",
590 'SHELL', $ch_defaultshell);
592 defined($c= open CU,"-|") or die $!;
595 defined($c2= open STDIN,"-|") or die $!;
597 print STDOUT join(':',@newpwent),"\n" or die $!;
600 for ($i=0; $i<@envs_createuser; $i++) {
601 $vn= "PW_$envs_createuser[$i]";
602 #print STDERR ">$i|$vn|$$vn|$newpwent[$$vn]<\n";
603 $ENV{"SYNCUSER_CREATE_$envs_createuser[$i]"}= $newpwent[$$vn];
605 exec $opt_createuser; die "$configfile:$.: ($lu): $opt_createuser: $!\n";
608 close CU; $? and die "$configfile:$.: ($lu): $opt_createuser: code $?\n";
610 if (length $newpwent) {
611 if ($newpwent !~ m/\:/) { diag("creation script demurred"); return; }
612 @newpwent= split(/\:/,$newpwent,-1);
614 die "$opt_createuser: bad result: \`".join(':',@newpwent)."\'\n"
615 if @newpwent != $PW_fields or $newpwent[$PW_USER] ne $lu;
616 checkuid($newpwent[$PW_UID],$lu) or return;
617 if ($own_haveshadow) {
618 push @ownshadow, [ newentry('SP', $lu,
626 syncusergroup($lu,$newpwent[$PW_UID]) or return;
627 push @ownpasswd,[ @newpwent ];
631 for $e (@ownpasswd) {
632 next unless $e->[$PW_USER] eq $lu;
633 syncusergroup($lu,$e->[$PW_UID]) or return;
636 $ruid= $rempasswd{$ru}->[$REM_UID];
637 $rgid= $rempasswd{$ru}->[$REM_GID];
638 if ($opt_sameuid && checkuid($ruid,$lu)) {
639 for $e (@ownpasswd) {
640 next unless $e->[$PW_USER] eq $lu;
641 $luid= $e->[$PW_UID]; $lgid= $e->[$PW_GID];
642 die "$diagstr: local uid $luid, remote uid $ruid\n" if $luid ne $ruid;
643 die "$diagstr: local gid $lgid, remote gid $rgid\n" if $lgid ne $rgid;
647 #print STDERR "syncuser($lu,$ru) exists $own_haveshadow\n";
648 if ($own_haveshadow && grep($_->[$PW_USER] eq $lu, @ownshadow)) {
649 #print STDERR "syncuser($lu,$ru) shadow $rempasswd{$ru}->[$REM_PW]\n";
650 copyfield('shadow',$lu,$SP_PW, $rempasswd{$ru}->[$REM_PW]);
652 #print STDERR "syncuser($lu,$ru) passwd $rempasswd{$ru}->[$REM_PW]\n";
653 copyfield('passwd',$lu,$PW_PW, $rempasswd{$ru}->[$REM_PW]);
655 copyfield('passwd',$lu,$PW_COMMENT, $rempasswd{$ru}->[$REM_COMMENT]);
657 $newsh= $rempasswd{$ru}->[$REM_SHELL];
658 $oksh= $checkedshell{$newsh};
659 if (!length $oksh) { $checkedshell{$newsh}= $oksh= (-x $newsh) ? 1 : 0; }
660 copyfield('passwd',$lu,$PW_SHELL, $newsh) if $oksh;
664 $tgroup= $e->[$GR_GROUP];
665 #print STDERR "syncuser($lu,$ru) group $tgroup\n";
666 next unless &wantsyncgroup($tgroup);
667 #print STDERR "syncuser($lu,$ru) group $tgroup yes\n";
669 if (!exists $remgroup{$tgroup}) {
670 diag("group $tgroup: not on remote host");
673 $inremote= grep($_ eq $ru, split(/\,/,$remgroup{$tgroup}->[$GR_USERS]));
674 $cusers= $e->[$GR_USERS]; $inlocal= grep($_ eq $lu, split(/\,/,$cusers));
675 if ($inremote && !$inlocal) {
676 $cusers.= ',' if length $cusers;
678 } elsif ($inlocal && !$inremote) {
679 $cusers= join(',', grep($_ ne $lu, split(/\,/, $cusers)));
683 $e->[$GR_USERS]= $cusers;
690 return if $bannerdone;
691 print "\n" or die $!; system 'date'; $? and die $?;
696 for $h (keys %wanthost) {
697 die "host $h not in config file\n" if $wanthost{$h};
701 #print STDERR "\n\nfinish display=$display pw=$pw\n\n";
702 for $e (@ownpasswd) {
704 $tuid= $e->[$PW_UID];
705 next if $displaydone{$tu};
707 #print STDERR ">$tu|$tpw<\n";
708 for $e2 (@ownshadow) {
709 next unless $e2->[$SP_USER] eq $tu;
710 $tpw= $e2->[$SP_PW]; last;
712 $tpw= length($tpw)>=13 ? 1 : length($tpw) ? -1 : 0;
713 $head= ($tpw == 1 ? "unsynched" :
714 $tpw == 0 ? "unsynched, passwordless" :
715 "unsynched, no-logins").
716 ($tuid < 100 ? " system account" : " normal user");
717 $unsynch_type{$head} .= " $e->[$PW_USER]";
719 foreach $head (sort keys %unsynch_type) {
721 print $unsynch_type{$head} or die $!;
723 print "\n\n" or die $!;
728 for $file (qw(passwd shadow group)) {
729 $realfile= $file{$file,$PW_format};
730 eval "\$modified= \$modified$file; \$data_ref= \\\@own$file;".
731 " \$fetched= \$own_fetched$file; 1;" or die $@;
733 die $file unless $fetched;
736 $newfileinst= "/etc/$realfile";
737 $newfile= "$realfile.new";
739 $newfileinst= $savebackto{$file};
740 $newfile= "$newfileinst.new";
742 open NF,"> $newfile" or die "$newfile: $!";
743 for $e (@$data_ref) {
744 print NF join(':',@$e),"\n" or die $!;
747 system 'diff','-U0','--label',$realfile,$newfileinst,
748 '--label',"$realfile.new",$newfile;
751 (@stats= stat $newfileinst) or die "$file: $!";
752 chown $stats[4],$stats[5], $newfile or die $!;
753 chmod $stats[2] & 07777, $newfile or die $!;
754 rename $newfile, $newfileinst or die $!;
762 next if m/^\#/ || !m/\S/;
764 finish() if m/^end$/;
765 if (m/^host\s+(\S+)$/) {
767 $ch_getpasswd= $ch_getgroup= $ch_getshadow= '';
768 $ch_fetchedpasswd= $ch_fetchedgroup;
771 } elsif (exists $wanthost{$ch_name}) {
772 $wanthost{$ch_name}= 0;
777 fields_fmt('REM','std');
778 } elsif (m/^(getpasswd|getshadow|getgroup)\s+(.*\S)$/) {
779 eval "\$ch_$1= \$2; 1;" or die $@;
780 } elsif (m/^(local|remote)format\s+(\w+)$/) {
781 fields_fmt($1 eq 'local' ? 'PW' :
782 $1 eq 'remote' ? 'REM' : die,
784 } elsif (m/^lock(passwd|group)\s+(runvia|link)\s+(\S+)$/) {
785 eval "\$ch_lock_$1= \$3; \$ch_lockstyle_$1= \$2; 1;" or die $@;
786 } elsif (m/^lock(passwd|group)\s+(none)$/) {
787 eval "\$ch_lockstyle_$1= \$2; 1;" or die $@;
788 } elsif (m,^(homebase|defaultshell)\s+(/\S+)$,) {
789 eval "\$ch_$1= \$2; 1;" or die $@;
790 } elsif (m/^(uidmin|uidmax)\s+(\d+)$/ && $2>0) {
791 eval "\$ch_$1= \$2; 1;" or die $@;
792 } elsif (m/^createuser$/) {
793 $opt_createuser= $def_createuser;
794 } elsif (m/^nocreateuser$/) {
796 } elsif (m/^createuser\s+(\S+)$/) {
798 } elsif (m/^logfile\s+(.*\S)$/) {
800 open STDOUT,">> $1" or die "$1: $!"; $|=1;
801 $!=0; system 'date'; $? and die "date: $! $?\n";
802 } elsif (!$display) {
803 print "would log to $1\n" or die $!;
805 } elsif (m/^(no|)(sameuid)$/) {
806 eval "\$opt_$2= ".($1 eq 'no' ? 0 : 1)."; 1;" or die $@;
807 } elsif (m/^usergroups$/) {
809 } elsif (m/^nousergroups$/) {
811 } elsif (m/^defaultgid\s+(\d+)$/) {
813 } elsif (m/^(no|)group\s+([-+.0-9a-zA-Z*?]+)$/) {
814 $yes= $1 eq 'no' ? 0 : 1;
816 @groupglobs=() if $_ eq '*';
820 unshift @groupglobs, [ $_, $yes ];
822 } elsif (m/^user\s+(\S+)$/) {
824 } elsif (m/^user\s+(\S+)\s+remote\=(\S+)$/) {
826 } elsif (m/^nouser\s+(\S+)$/) {
828 } elsif (m/^users\s+(\d+)\-(\d+)$/) {
829 $tmin= $1; $tmax= $2; $except= $3;
831 for $k (keys %rempasswd) {
832 $tuid= $rempasswd{$k}->[2];
833 next if $tuid<$1 or $tuid>$2;
836 } elsif (m/^addhere$/) {
838 die "$configfile:$.: unknown directive\n";
842 die "$configfile:$.: missing \`end', or read error\n";