3 # Create userdb database
7 # $Id: makeuserdb.in,v 1.13 2006/03/25 13:31:21 mrsam Exp $
9 # Copyright 1998 - 2006 Double Precision, Inc. See COPYING for
10 # distribution information.
15 $exec_prefix="@exec_prefix@";
18 $ENV{'PATH'}="@bindir@:/usr/bin:/usr/local/bin:/bin";
30 $datfile=$dbfile.".dat";
31 # XXX the lock file here is etc/userdb.lock but the userdb command uses etc/.lock.userdb
32 $lockfile=$dbfile.".lock";
33 $shadowfile=$dbfile."shadow.dat";
34 $tmpdatfile=$dbfile.".tmp";
35 $tmpshadowfile=$dbfile."shadow.tmp";
37 $mode=(stat($dbfile))[2];
38 die "$dbfile: not found.\n" unless defined $mode;
40 die "$dbfile: MAY NOT HAVE GROUP OR WORLD PERMISSIONS!!\n"
44 die "SYMLINK\n" if -l $dbfile;
47 die "ERROR: Wrong makeuserdb command.\n ($dbfile is a symbolic link)\n"
51 die "SYMLINK\n" if -l $datfile;
54 die "ERROR: Wrong makeuserdb command.\n ($datfile is a symbolic link)\n"
58 die "SYMLINK\n" if -l $shadowfile;
61 die "ERROR: Wrong makeuserdb command.\n ($shadowfile is a symbolic link)\n"
65 open(LOCK, ">$lockfile") or die "Can't open $lockfile: $!";
66 flock(LOCK,LOCK_EX) || die "Can't lock $lockfile: $!";
68 open (DBPIPE, "| ${makedat} - $tmpdatfile $datfile") || die "$!\n";
70 open (SHADOWPIPE, "| ${makedat} - $tmpshadowfile $shadowfile")
84 opendir(DIR, $dir) || die "$!\n";
85 while ( defined($filename=readdir(DIR)))
87 next if $filename =~ /^\./;
88 if ( -d "$dir/$filename" )
90 push @dirs, "$dir/$filename";
94 push @files, "$dir/$filename";
100 while (defined ($filename=shift @files))
102 &do_file( $filename );
110 print DBPIPE ".\n" || die "$!\n";
111 print SHADOWPIPE ".\n" || die "$!\n";
121 close(DBPIPE) || die "$!\n";
123 close(SHADOWPIPE) || die "$!\n";
131 my (@nonshadow, @shadow);
133 my $location=substr($filename, length("@userdb@"));
135 $location =~ s/^\///;
136 $location =~ s/\/$//;
137 $location .= "/" if $location ne "";
139 open (F, $filename) || die "$filename: $!\n";
142 if ( /^[\n#]/ || ! /^([^\t]*)\t(.*)/ )
148 ($addr,$fields)=($1,$2);
152 foreach ( split (/\|/, $fields ) )
164 push @nonshadow, "_=$location";
165 ( print DBPIPE "$addr\t" . join("|", @nonshadow) . "\n"
166 || die "$!\n" ) if $#nonshadow >= 0;
167 ( print SHADOWPIPE "$addr\t" . join("|", @shadow) . "\n"
168 || die "$!\n" ) if $#shadow >= 0;
171 print SHADOWPIPE "\n";