chiark / gitweb /
Run sync-accounts only on relevant host.
[chiark-utils.git] / sync-accounts / sync-accounts
1 #!/usr/bin/perl
2 # $Id: sync-accounts,v 1.12 1999-01-03 02:40:50 ian Exp $
3 # usage: sync-accounts [-n] [-C<config-file>] [<host> ...]
4 # options:
5 #   -n     do not really do anything
6 #   -C     alternative config file (default is /etc/sync-accounts)
7 #   -q     display accounts synched, not synched, etc.
8 # if no host(s) specified, does all
9 #
10 # The config file consists of directives, one per line.  Leading and
11 # trailing whitespace, blank lines and lines starting # are ignored.
12 #
13 # Some config file directives apply globally and should appear first:
14 #
15 #  lockpasswd <suffix/filename>
16 #  lockgroup <suffix/filename>
17 #      Specifies the lockfile suffix or pathname to use when editing
18 #      the passwd and group files.  The value is a suffix if it does
19 #      not start with `/'.  If set to /dev/null no locking is done.
20 #
21 #  logfile <filename>
22 #      Append log messages to <filename> instead of stdout.
23 #      Errors still go to stderr.
24 #
25 # Some config file directives set options which may be different at
26 # different points in the file.  The most-recently-seen value is used
27 # at each point:
28 #
29 #  uidmin <min>
30 #  uidmax <max>
31 #  homebase <pathname>
32 #      When an account is to be created, a uid/gid will be chosen
33 #      which is one higher than the highest currently in use (except
34 #      that ids outside the range <min>-<max> are ignored and will
35 #      never be used).  The default home directory location is
36 #      <pathname>/<username>.
37 #
38 #  sameuid
39 #  nosameuid
40 #      Specifies whether uids are supposed to match.  The default is
41 #      nosameuid.  When sameuid is on, it is an error for the uid or
42 #      gid of a local account not to match the corresponding remote
43 #      account, and new local accounts will get the remote accounts'
44 #      ids.
45 #
46 #  usergroups
47 #  nousergroups
48 #  defaultgid <gid>
49 #      Specifies whether local accounts are supposed to have
50 #      corresponding groups, or all be part of a particular group.  If
51 #      usergroups is set, when a new account is created, the
52 #      corresponding per-user group will be created as well, and
53 #      per-user groups are created for existing accounts if necessary
54 #      (if account creation is enabled).  If the gid or group name for
55 #      a per-user group is already taken for a different group name or
56 #      gid this will be logged, and processing of that account will be
57 #      inhibited, but it is not a fatal error.  If defaultgid is used,
58 #      then newly-created accounts will be made a part of that group,
59 #      and the groups of existing accounts will be left alone.  If
60 #      nousergroups is specified then no new accounts can be created,
61 #      and existing accounts' groups will be left alone.  The default
62 #      is `usergroups'.
63 #
64 #  createuser
65 #  createuser <commandname>
66 #  nocreateuser
67 #      Specifies whether accounts found on the remote host should be
68 #      created if necessary, and what command to run to do the
69 #      creation (eg, setup of home directory).  The default is
70 #      nocreateuser.  If createuser is specified without a commandname
71 #      then sync-accounts-createuser is used.  The command is found on
72 #      the PATH if necessary.  Either sameuid, or both uidmin and
73 #      uidmax, must be specified, if accounts are to be created.
74 #
75 #      The command (which will be run with sh -c) must at least create
76 #      the new account's home directory.  The passwd and group entries
77 #      will not have been set up.  The following environment variables
78 #      will be set, giving details about the account to be created:
79 #        SYNCACCOUNT_CREATE_USER
80 #        SYNCACCOUNT_CREATE_UID
81 #        SYNCACCOUNT_CREATE_GID
82 #        SYNCACCOUNT_CREATE_COMMENT
83 #        SYNCACCOUNT_CREATE_HOME
84 #        SYNCACCOUNT_CREATE_SHELL
85 #      If it chooses, the script may modify the password entry which
86 #      will be added to the system, by outputting a replacement
87 #      password file entry.  (The password field of that is ignored.)
88 #      If the script outputs a line which does not contain a : then
89 #      the account will not be created after all.
90 #
91 #  group <glob-pattern>
92 #  nogroup <glob-pattern>
93 #      Specifies that the membership of the local groups specified
94 #      should be adjusted or not adjusted whenever account data for a
95 #      particular user is copied, so that the account will be a member
96 #      of the affected group locally iff it is a member of the same
97 #      group on the remote host.  The most recently-encountered
98 #      glob-pattern for a particular group takes effect.  The default
99 #      is `nogroups *'.
100 #
101 #  defaultshell <pathname>
102 #      If, when creating an account, the remote account's shell is not
103 #      available on the local system, this value will be used.  The
104 #      default is /bin/sh.
105 #
106 # Some config file directives are per-host, and should appear before
107 # any directives which actually modify accounts:
108 #
109 #  host <shorthostname>
110 #      Starts a host's section.  This resets the per-host parameters
111 #      to the defaults.  The shorthostname need not be the host's
112 #      official name in any sense.  If sync-accounts is invoked with
113 #      host names on the command line they are compared with the
114 #      shorthostnames.
115 #
116 #  getpasswd <command>
117 #  getgroup <command>
118 #      Commands to run on the local host to get the passwd, shadow and
119 #      group data for the host in question.  getpasswd must be
120 #      specified if user data is to be transferred; getgroup must be
121 #      specified if group data is to be transferred.
122 #
123 #  getshadow <command>
124 #      Specifies that shadow file data is to be used (by default,
125 #      password information is found from the output of getpasswd).
126 #      The command should emit shadow data in the format specified by
127 #      shadow(5) on Linux.  getshadow should not be specified without
128 #      getpasswd.
129 #
130 # Some configuration file directives specify that account data is to
131 # transferred from the current host.  They should appear as the last
132 # thing(s) in a host section:
133 #
134 #  user <username> [remote=<remoteusername>]
135 #      Specifies that account data should be copied for local user
136 #      <username> from the remote account <remoteusername> (assumed to
137 #      be the same as <username> if not specified).  The account
138 #      password, comment field, and shell will be copied
139 #      unconditionally.  If sameuid is specified the uid will be
140 #      checked.
141 #
142 #  users <ruidmin>-<ruidmax>
143 #      Specifies that all remote users whose uid is in the given range
144 #      are to be copied to corresponding local user accounts.
145 #
146 #  nouser <username>
147 #      Specifies that data for <username> is _not_ to be copied, even
148 #      if subsequent user or users directives suggest that it should
149 #      be.
150 #
151 #   (A note is made when a `user', `users' or `nouser' directive is
152 #   encountered for a particular account, and no subsequent directives
153 #   for that account will take effect.)
154 #
155 #  addhere
156 #      This directive has no effect on `sync-accounts'.  However, it
157 #      is used as a placeholder by `grab-account': new accounts for
158 #      creation are inserted just before `addhere'.
159 #
160 # Finally, the config file must finish with:
161
162 #  end
163
164 use POSIX;
165
166 $configfile= '/etc/sync-accounts';
167 $def_createuser= 'sync-accounts-createuser';
168 $ch_homebase= '/home';
169 $ch_defaultshell= '/bin/sh';
170 $defaultgid= -1; # -1 => usergroups; -2 => nousergroups
171 @groupglobs= [ '.*', 0 ];
172 regroupglobs();
173
174 END {
175     for $x (@unlocks) {
176         unlink $x or warn "unable to unlock by removing $x: $!\n";
177     }
178 }
179
180 $|=1;
181 $cdays= int(time/86400);
182
183 @envs_passwd= qw(USER x UID GID COMMENT HOME SHELL);
184
185 while ($ARGV[0] =~ m/^-/) {
186     $_= shift @ARGV;
187     last if m/^--$/;
188     if (m/^-C/) {
189         $configfile= $';
190     } elsif (m/^-n$/) {
191         $no_act= 1;
192         $display= 0;
193     } elsif (m/^-q$/) {
194         $no_act= 1;
195         $display= 1;
196     } else {
197         die "unknown option $_\n";
198     }
199 }
200
201 for $h (@ARGV) { $wanthost{$h}= 1; }    
202
203 open CF,"< $configfile" or die "$configfile: $!";
204
205 sub fetchfile (\%$) {
206     my ($ary_ref,$get_str) = @_;
207
208     undef %$ary_ref;
209     open G,"$get_str" or die "$get_str: $!";
210     while (<G>) {
211         chomp;
212         m/^([^:]+)\:/ or die "$ch_name: $get_str:$.: $_ ?\n";
213         $ary_ref->{$1}= [ split(/\:/,$_,-1) ];
214     }
215     close G; $? and die "$ch_name: $get_str: exit code $?\n";
216 }
217
218 sub fetchownfile (\@$$) {
219     my ($ary_ref,$fn_str,$lock_str) = @_;
220     die "$configfile:$.: lockfile name for $fn_str not".
221         " defined (use lockpasswd/lockgroup)\n" unless length $lock_str;
222     if ($lock_str ne '/dev/null' && !$no_act) {
223         $lock_str= "$fn_str$lock_str" unless $lock_str =~ m,^/,;
224         link $fn_str,$lock_str or die "cannot lock $fn_str by creating $lock_str: $!\n";
225         push @unlocks,$lock_str;
226     }
227     open O,"$fn_str" or die "$fn_str: $!";
228     while (<O>) {
229         chomp;
230         push @$ary_ref, [ split(/\:/,$_,-1) ];
231     }
232     close O or die "$fn_str: $!";
233 }
234
235 sub diag ($) {
236     print "$diagstr: $_[0]\n" or die $!;
237 }
238
239 sub regroupglobs () {
240     $nogroups= (@groupglobs == 1 &&
241                 $groupglobs[0]->[0] eq '.*' &&
242                 !$groupglobs[0]->[1]);
243     $ggfunc= "sub wantsyncgroup {\n  \$_= \$_[0];\n  return\n";
244     for $e (@groupglobs) { $ggfunc.= "    m/^$e->[0]\$/ ? $e->[1] :\n"; }
245     $ggfunc.= "    die;\n};\n1;\n";
246 #print STDERR "$ggfunc\n";
247     eval $ggfunc or die "$ggfunc // $@";
248 }
249
250 sub fetchown () {
251     if (!$own_fetchedpasswd) {
252         fetchownfile(@ownpasswd,'/etc/passwd',$ch_lockpasswd);
253         if (defined stat('/etc/shadow')) {
254             $own_haveshadow= 1;
255             $own_fetchedshadow= 1;
256             fetchownfile(@ownshadow,'/etc/shadow','/dev/null');
257         } elsif ($! == &ENOENT) {
258             $own_haveshadow= 0;
259         } else {
260             die "unable to check for /etc/shadow: $!\n";
261         }
262         $own_fetchedpasswd= 1;
263     }
264     if (!$own_fetchedgroup) {
265         fetchownfile(@owngroup,'/etc/group',$ch_lockgroup);
266         $own_fetchedgroup= 1;
267     }   
268 #print STDERR "fetchown() -> $#ownpasswd $#owngroup\n";
269 }
270
271 sub checkuid ($$) {
272     my ($useuid,$foruser) = @_;
273     for $e (@ownpasswd) {
274         if ($e->[0] ne $foruser && $e->[2] == $useuid) {
275             diag("uid clash with $e->[0] (uid $e->[2])");
276             return 0;
277         }
278     }
279     return 1;
280 }
281
282 sub copyfield ($$$$) {
283     my ($file,$entry,$field,$value) = @_;
284     eval "\$ary_ref= \\\@own$file; 1;" or die $@;
285 #print STDERR "copyfield($file,$entry,$field,$value)\n";
286     for $e (@$ary_ref) {
287 #print STDERR "copyfield($file,$entry,$field,$value) $e->[0] $e->[field] ".join(':',@$e)."\n";
288         next unless $e->[0] eq $entry;
289         next if $e->[$field] eq $value;
290         $e->[$field]= $value;
291         eval "\$modified$file= 1; 1;" or die $@;
292     }
293 }
294
295 sub fetchpasswd () {
296     return if $ch_fetchedpasswd;
297     die "$configfile:$.: getpasswd not specified for host $ch_name\n"
298         unless length $ch_getpasswd;
299     undef %remshadow;
300     fetchfile(%rempasswd,"$ch_getpasswd |");
301     if (length $ch_getshadow) {
302         fetchfile(%remshadow,"$ch_getshadow |");
303         for $k (keys %rempasswd) {
304             $rempasswd{$k}->[1]= 'xx' unless length $rempasswd{$k}->[1];
305         }
306         for $k (keys %remshadow) {
307             next unless exists $rempasswd{$k};
308             $rempasswd{$k}->[1]= $remshadow{$k}->[1];
309         }
310     }
311 }
312
313 sub fetchgroup () {
314     return if $ch_fetchedgroup;
315     die "$configfile:$.: getgroup not specified for host $ch_name\n"
316         unless length $ch_getgroup;
317     fetchfile(%remgroup,"$ch_getgroup |");
318 }
319
320 sub syncusergroup ($$) {
321     my ($lu,$luid) = @_;
322
323     return 1 if $defaultgid != -1;
324 #print STDERR "syncusergroup($lu,$luid)\n";
325     $ugfound=0;
326     
327     for $e (@owngroup) {
328         $samename= $e->[0] eq $lu;
329         $sameid= $e->[2] eq $luid;
330         next unless $samename || $sameid;
331         if (!$samename || !$sameid) {
332             diag("local group $e->[0] ($e->[2]) mismatch vs. local user $lu ($luid)");
333             return 0;
334         }
335         if ($ugfound) {
336             diag("per-user group $lu ($luid) duplicated");
337             return 0;
338         }
339         $ugfound=1;
340     }
341
342     return 1 if $ugfound;
343
344     if (!length $opt_createuser) {
345         diag("account creation not enabled, not creating per-user group");
346         return 0;
347     }
348     push @owngroup, [ $lu,'x',$luid,'' ];
349     $modifiedgroup= 1;
350     return 1;
351 }
352
353 sub hosthead ($) {
354     my ($th) = @_;
355     return if $hostheaddone eq $th;
356     print "\n\n" or die $! if length $hostheaddone;
357     print "==== $th ====\n" or die $!;
358     $hostheaddone= $th;
359 }
360
361 sub syncuser ($$) {
362     my ($lu,$ru) = @_;
363
364 #print STDERR "syncuser($lu,$ru)\n";
365     next unless $ch_doinghost;
366     return if $doneuser{$lu}++;
367     return if !length $ru;
368
369     fetchown();
370
371     if ($display) {
372         for $e (@ownpasswd) {
373             next unless $e->[0] eq $lu;
374             hosthead("from $ch_name");
375             print ($lu eq $ru ? " $lu" : " $lu($ru)") or die $!;
376             print "<DUPLICATE>" if $displaydone{$lu}++;
377         }
378         return;
379     }
380     
381     $diagstr= "user $lu from $ch_name!$ru";
382
383 #print STDERR "syncuser($lu,$ru) doing\n";
384     fetchpasswd();
385
386     if (!$rempasswd{$ru}) { diag("no remote entry"); return; }
387     if (length $ch_getshadow && exists $remshadow{$ru} && length $remshadow{$ru}->[7]) {
388         diag("remote account disabled in shadow");
389         return;
390     }
391
392     if (!grep($_->[0] eq $lu, @ownpasswd)) {
393         if (!length $opt_createuser) { diag("account creation not enabled"); return; }
394         if ($no_act) { diag("-n specified; not creating account"); return; }
395
396         if ($opt_sameuid) {
397             $useuid= $rempasswd{$ru}->[2];
398             $usegid= $rempasswd{$ru}->[3];
399         } else {
400             die "nousergroups specified, cannot create users\n" if $defaultgid==-2;
401             length $ch_uidmin or die "no uidmin specified, cannot create users\n";
402             length $ch_uidmax or die "no uidmax specified, cannot create users\n";
403             $ch_uidmin<$ch_uidmax or die "uidmin>=uidmax, cannot create users\n";
404         
405             $useuid= $ch_uidmin;
406             for $e ($defaultgid==-1 ? (@ownpasswd, @owngroup) : (@ownpasswd)) {
407                 $tuid= $e->[2]; next if $tuid<$useuid || $tuid>$ch_uidmax;
408                 if ($tuid==$ch_uidmax) {
409                     diag("uid (or gid?) $ch_uidmax used, cannot create users");
410                     return;
411                 }
412                 $useuid= $tuid+1;
413             }
414             $usegid= $defaultgid==-1 ? $useuid : $defaultgid;
415         }
416         
417         @newpwent= ($lu,'x',$useuid,$usegid,$rempasswd{$ru}->[4],
418                     "$ch_homebase/$lu",$ch_defaultshell);
419         
420         defined($c= open CU,"-|") or die $!;
421         if (!$c) {
422             @unlocks= ();
423             defined($c2= open STDIN,"-|") or die $!;
424             if (!$c2) {
425                 print STDOUT join(':',@newpwent),"\n" or die $!;
426                 exit 0;
427             }
428             for ($i=0; $i<@envs_passwd; $i++) {
429                 next if $envs_passwd[$i] eq 'x';
430                 $ENV{"SYNCUSER_CREATE_$envs_passwd[$i]"}= $newpwent[$i];
431             }
432             exec $opt_createuser; die "$configfile:$.: ($lu): $opt_createuser: $!\n";
433         }
434         $newpwent= <CU>;
435         close CU; $? and die "$configfile:$.: ($lu): $opt_createuser: code $?\n";
436         chomp $newpwent;
437         if (length $newpwent) {
438             if ($newpwent !~ m/\:/) { diag("creation script demurred"); return; }
439             @newpwent= split(/\:/,$newpwent,-1);
440         }
441         die "$opt_createuser: bad output: $_\n" if @newpwent!=7 or $newpwent[0] ne $lu;
442         checkuid($newpwent[2],$lu) or return;
443         if ($own_haveshadow) {
444             push(@ownshadow,[ $lu, $newpwent[1], $cdays, 0,99999,7,'','','' ]);
445             $newpwent[1]= 'x';
446             $modifiedshadow= 1;
447         }
448         syncusergroup($lu,$newpwent[2]) or return;
449         push @ownpasswd,[ @newpwent ];
450         $modifiedpasswd= 1;
451     }
452
453     for $e (@ownpasswd) {
454         next unless $e->[0] eq $lu;
455         syncusergroup($lu,$e->[2]) or return;
456     }
457
458     $ruid= $rempasswd{$ru}->[2];
459     $rgid= $rempasswd{$ru}->[3];
460     if ($opt_sameuid && checkuid($ruid,$lu)) {
461         for $e (@ownpasswd) {
462             next unless $e->[0] eq $lu;
463             $luid= $e->[2]; $lgid= $e->[3];
464             die "$diagstr: local uid $luid, remote uid $ruid\n" if $luid ne $ruid;
465             die "$diagstr: local gid $lgid, remote gid $rgid\n" if $lgid ne $rgid;
466         }
467     }
468
469 #print STDERR "syncuser($lu,$ru) exists $own_haveshadow\n";
470     if ($own_haveshadow && grep($_->[0] eq $lu, @ownshadow)) {
471 #print STDERR "syncuser($lu,$ru) shadow $rempasswd{$ru}->[1]\n";
472         copyfield('shadow',$lu,1, $rempasswd{$ru}->[1]);
473     } else {
474 #print STDERR "syncuser($lu,$ru) passwd $rempasswd{$ru}->[1]\n";
475         copyfield('passwd',$lu,1, $rempasswd{$ru}->[1]);
476     }
477     copyfield('passwd',$lu,4, $rempasswd{$ru}->[4]); # comment
478
479     $newsh= $rempasswd{$ru}->[6];
480     $oksh= $checkedshell{$newsh};
481     if (!length $oksh) { $checkedshell{$newsh}= $oksh= (-x $newsh) ? 1 : 0; }
482     copyfield('passwd',$lu,6, $newsh) if $oksh;
483
484     if (!$nogroups) {
485         for $e (@owngroup) {
486             $tgroup= $e->[0];
487 #print STDERR "syncuser($lu,$ru) group $tgroup\n";
488             next unless &wantsyncgroup($tgroup);
489 #print STDERR "syncuser($lu,$ru) group $tgroup yes\n";
490             fetchgroup();
491             if (!exists $remgroup{$tgroup}) {
492                 diag("group $tgroup: not on remote host");
493                 next;
494             }
495             $inremote= grep($_ eq $ru, split(/\,/,$remgroup{$tgroup}->[3]));
496             $cusers= $e->[3]; $inlocal= grep($_ eq $lu, split(/\,/,$cusers));
497             if ($inremote && !$inlocal) {
498                 $cusers.= ',' if length $cusers;
499                 $cusers.= $lu;
500             } elsif ($inlocal && !$inremote) {
501                 $cusers= join(',', grep($_ ne $lu, split(/\,/, $cusers)));
502             } else {
503                 next;
504             }
505             $e->[3]= $cusers;
506             $modifiedgroup= 1;
507         }
508     }
509 }
510
511 sub banner () {
512     return if $bannerdone;
513     print "\n" or die $!; system 'date'; $? and die $?;
514     $bannerdone= 1;
515 }
516
517 sub finish () {
518     for $h (keys %wanthost) {
519         die "host $h not in config file\n" if $wanthost{$h};
520     }
521
522     if ($display) {
523         for $pw (1,-1,0) {
524 #print STDERR "\n\nfinish display=$display pw=$pw\n\n";
525             for $e (@ownpasswd) {
526                 $tu= $e->[0];
527                 next if $displaydone{$tu};
528                 $tpw= $e->[1];
529                 for $e2 (@ownshadow) {
530                     next unless $e2->[0] eq $tu;
531                     $tpw= $e2->[1]; last;
532                 }
533                 $tpw= length($tpw)==13 ? 1 : length($tpw) ? -1 : 0;
534                 next unless $pw == $tpw;
535                 hosthead($pw == 1 ? "unsynched normal account" :
536                          $pw == 0 ? "unsynched, passwordless" :
537                          "unsynched, no logins");
538                 print " $e->[0]" or die $!;
539             }
540         }
541         print "\n\n" or die $! if $hostheaddone;
542         exit 0;
543     }
544     
545     umask 077;
546     for $file (qw(passwd shadow group)) {
547         eval "\$modified= \$modified$file; \$data_ref= \\\@own$file;".
548             " \$fetched= \$own_fetched$file; 1;" or die $@;
549         next if !$modified;
550         die $file unless $fetched;
551         banner();
552         $newfile= $no_act ? "$file.new" : "/etc/$file.new";
553         open NF,"> $newfile";
554         for $e (@$data_ref) {
555             print NF join(':',@$e),"\n" or die $!;
556         }
557         close NF or die $!;
558         system "diff -U0 /etc/$file $newfile"; $?==256 or die $?;
559         if (!$no_act) {
560             (@stats= stat "/etc/$file") or die "$file: $!";
561             chown $stats[4],$stats[5], $newfile or die $!;
562             chmod $stats[2] & 07777, $newfile or die $!;
563             rename $newfile, "/etc/$file" or die $!;
564         }
565     }
566     exit 0;
567 }
568
569 while (<CF>) {
570     chomp;
571     next if m/^\#/ || !m/\S/;
572     s/^\s*//; s/\s*$//;
573     finish() if m/^end$/;
574     if (m/^host\s+(\S+)$/) {
575         $ch_name= $1;
576         $ch_getpasswd= $ch_getgroup= $ch_getshadow= '';
577         $ch_fetchedpasswd= $ch_fetchedgroup;
578         if (!@ARGV) {
579             $ch_doinghost= 1;
580         } elsif (exists $wanthost{$ch_name}) {
581             $wanthost{$ch_name}= 0;
582             $ch_doinghost= 1;
583         } else {
584             $ch_doinghost= 0;
585         }
586     } elsif (m/^(getpasswd|getshadow|getgroup)\s+(.*\S)$/) {
587         eval "\$ch_$1= \$2; 1;" or die $@;
588     } elsif (m/^(lockpasswd|lockgroup)\s+(\S+)$/) {
589         eval "\$ch_$1= \$2; 1;" or die $@;
590     } elsif (m,^(homebase|defaultshell)\s+(/\S+)$,) {
591         eval "\$ch_$1= \$2; 1;" or die $@;
592     } elsif (m/^(uidmin|uidmax)\s+(\d+)$/ && $2>0) {
593         eval "\$ch_$1= \$2; 1;" or die $@;
594     } elsif (m/^createuser$/) {
595         $opt_createuser= $def_createuser;
596     } elsif (m/^nocreateuser$/) {
597         $opt_createuser= '';
598     } elsif (m/^createuser\s+(\S+)$/) {
599         $opt_createuser= $1;
600     } elsif (m/^logfile\s+(.*\S)$/) {
601         if (!$no_act) {
602             open STDOUT,">> $1" or die "$1: $!"; $|=1;
603         } elsif (!$display) {
604             print "would log to $1\n" or die $!;
605         }
606     } elsif (m/^(no|)(sameuid)$/) {
607         eval "\$opt_$2= ".($1 eq 'no' ? 0 : 1)."; 1;" or die $@;
608     } elsif (m/^usergroups$/) {
609         $defaultgid= -1;
610     } elsif (m/^nousergroups$/) {
611         $defaultgid= -2;
612     } elsif (m/^defaultgid\s+(\d+)$/) {
613         $defaultgid= $1;
614     } elsif (m/^(no|)group\s+([-+.0-9a-zA-Z*?]+)$/) {
615         $yes= $1 eq 'no' ? 0 : 1;
616         $_= $2;
617         @groupglobs=() if $_ eq '*';
618         s/[-+._]/\\$1/g;
619         s/\*/\.\*/g;
620         s/\?/\./g;
621         unshift @groupglobs, [ $_, $yes ];
622         regroupglobs();
623     } elsif (m/^user\s+(\S+)$/) {
624         syncuser($1,$1);
625     } elsif (m/^user\s+(\S+)\s+remote\=(\S+)$/) {
626         syncuser($1,$2);
627     } elsif (m/^nouser\s+(\S+)$/) {
628         syncuser($1,'');
629     } elsif (m/^users\s+(\d+)\-(\d+)$/) {
630         $tmin= $1; $tmax= $2; $except= $3;
631         fetchpasswd();
632         for $k (keys %rempasswd) {
633             $tuid= $rempasswd{$k}->[2];
634             next if $tuid<$1 or $tuid>$2;
635             syncuser($k,$k);
636         }
637     } elsif (m/^addhere$/) {
638     } else {
639         die "$configfile:$.: unknown directive\n";
640     }
641 }
642
643 die "$configfile:$.: missing \`end', or read error\n";