Build courier-authlib 0.60.2-0hcoop1.
[hcoop/debian/courier-authlib.git] / userdb / pw2userdb.in
CommitLineData
d9898ee8 1#! @PERL@
2#
3# Convert /etc/passwd and /etc/shadow to userdb format.
4#
5# $Id: pw2userdb.in,v 1.5 2000/07/19 11:55:15 mrsam Exp $
6#
7# Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
8# distribution information.
9
10use Getopt::Long;
11
12#
13# Some undocumented options here (for vchkpw2userdb)
14#
15
16die "Invalid options.\n" unless
17 GetOptions("passwd=s" => \$passwd, "shadow=s" => \$shadow,
18 "noshadow" => \$noshadow, "nouid" => \$nouid,
19 "domain=s" => \$domain, "vpopuid" => \$vpopuid );
20
21($dummy, $dummy, $fixed_uid, $fixed_gid)=getpwnam("vpopmail")
22 if $vpopuid;
23
24$passwd="/etc/passwd" unless $passwd =~ /./;
25$shadow="/etc/shadow" unless $shadow =~ /./;
26
27$domain="" unless $domain =~ /./;
28$domain="\@$domain" if $domain =~ /./;
29
30open(PASSWD, $passwd) || die "$!\n";
31
32while (<PASSWD>)
33{
34 chop if /\n$/;
35 next if /^#/;
36 ($acct,$passwd,$uid,$gid,$name,$home,$shell)=split( /:/ );
37
38 ($uid,$gid)=($fixed_uid,$fixed_gid) if $vpopuid;
39
40 $PASSWORD{$acct}=$passwd if $passwd ne "x";
41 $UID{$acct}=$uid;
42 $GID{$acct}=$gid;
43 $HOME{$acct}=$home;
44 $SHELL{$acct}=$shell;
45
46 $name =~ s/\|/./g; # Just in case
47 $GECOS{$acct}=$name;
48}
49close (PASSWD);
50
51if ( -f $shadow && ! $noshadow)
52{
53 open (SHADOW, $shadow) || die "$!\n";
54 while (<SHADOW>)
55 {
56 next if /^#/;
57 ($acct,$passwd,$dummy)=split(/:/);
58 $PASSWORD{$acct}=$passwd;
59 }
60 close (SHADOW);
61}
62
63while ( defined ($key=each %UID))
64{
65 print "$key$domain\tuid=$UID{$key}|gid=$GID{$key}|home=$HOME{$key}" .
66 ( $SHELL{$key} =~ /./ ? "|shell=$SHELL{$key}":"") .
67 ( $PASSWORD{$key} =~ /./ ? "|systempw=$PASSWORD{$key}":"") .
68 ( $GECOS{$key} =~ /./ ? "|gecos=$GECOS{$key}":"") .
69 "\n";
70 print "$UID{$key}=\t$key\n" unless $nouid;
71}