3 # Create userdb database
8 # Copyright 1998 - 2006 Double Precision, Inc. See COPYING for
9 # distribution information.
14 $exec_prefix="@exec_prefix@";
17 $ENV{'PATH'}="@bindir@:/usr/bin:/usr/local/bin:/bin";
29 $datfile=$dbfile.".dat";
30 # XXX the lock file here is etc/userdb.lock but the userdb command uses etc/.lock.userdb
31 $lockfile=$dbfile.".lock";
32 $shadowfile=$dbfile."shadow.dat";
33 $tmpdatfile=$dbfile.".tmp";
34 $tmpshadowfile=$dbfile."shadow.tmp";
36 $mode=(stat($dbfile))[2];
37 die "$dbfile: not found.\n" unless defined $mode;
39 die "$dbfile: MAY NOT HAVE GROUP OR WORLD PERMISSIONS!!\n"
43 die "SYMLINK\n" if -l $dbfile;
46 die "ERROR: Wrong makeuserdb command.\n ($dbfile is a symbolic link)\n"
50 die "SYMLINK\n" if -l $datfile;
53 die "ERROR: Wrong makeuserdb command.\n ($datfile is a symbolic link)\n"
57 die "SYMLINK\n" if -l $shadowfile;
60 die "ERROR: Wrong makeuserdb command.\n ($shadowfile is a symbolic link)\n"
64 open(LOCK, ">$lockfile") or die "Can't open $lockfile: $!";
65 flock(LOCK,LOCK_EX) || die "Can't lock $lockfile: $!";
67 open (DBPIPE, "| ${makedat} - $tmpdatfile $datfile") || die "$!\n";
69 open (SHADOWPIPE, "| ${makedat} - $tmpshadowfile $shadowfile")
83 opendir(DIR, $dir) || die "$!\n";
84 while ( defined($filename=readdir(DIR)))
86 next if $filename =~ /^\./;
87 if ( -d "$dir/$filename" )
89 push @dirs, "$dir/$filename";
93 push @files, "$dir/$filename";
99 while (defined ($filename=shift @files))
101 &do_file( $filename );
109 print DBPIPE ".\n" || die "$!\n";
110 print SHADOWPIPE ".\n" || die "$!\n";
120 close(DBPIPE) || die "$!\n";
122 close(SHADOWPIPE) || die "$!\n";
130 my (@nonshadow, @shadow);
132 my $location=substr($filename, length("@userdb@"));
134 $location =~ s/^\///;
135 $location =~ s/\/$//;
136 $location .= "/" if $location ne "";
138 open (F, $filename) || die "$filename: $!\n";
141 if ( /^[\n#]/ || ! /^([^\t]*)\t(.*)/ )
147 ($addr,$fields)=($1,$2);
151 foreach ( split (/\|/, $fields ) )
163 push @nonshadow, "_=$location";
164 ( print DBPIPE "$addr\t" . join("|", @nonshadow) . "\n"
165 || die "$!\n" ) if $#nonshadow >= 0;
166 ( print SHADOWPIPE "$addr\t" . join("|", @shadow) . "\n"
167 || die "$!\n" ) if $#shadow >= 0;
170 print SHADOWPIPE "\n";