pw2userdb.in
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:2k
- #! @PERL@
- #
- # Convert /etc/passwd and /etc/shadow to userdb format.
- #
- # $Id: pw2userdb.in,v 1.4 2000/02/16 01:12:13 mrsam Exp $
- #
- # Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
- # distribution information.
- use Getopt::Long;
- #
- # Some undocumented options here (for vchkpw2userdb)
- #
- die "Invalid options.n" unless
- GetOptions("passwd=s" => $passwd, "shadow=s" => $shadow,
- "noshadow" => $noshadow, "nouid" => $nouid,
- "domain=s" => $domain, "vpopuid" => $vpopuid );
- ($dummy, $dummy, $fixed_uid, $fixed_gid)=getpwnam("vpopmail")
- if $vpopuid;
- $passwd="/etc/passwd" unless $passwd =~ /./;
- $shadow="/etc/shadow" unless $shadow =~ /./;
- $domain="" unless $domain =~ /./;
- $domain="@$domain" if $domain =~ /./;
- open(PASSWD, $passwd) || die "$!n";
- while (<PASSWD>)
- {
- chop if /n$/;
- ($acct,$passwd,$uid,$gid,$name,$home,$shell)=split( /:/ );
- ($uid,$gid)=($fixed_uid,$fixed_gid) if $vpopuid;
- $PASSWORD{$acct}=$passwd if $passwd ne "x";
- $UID{$acct}=$uid;
- $GID{$acct}=$gid;
- $HOME{$acct}=$home;
- $SHELL{$acct}=$shell;
- $name =~ s/|/./g; # Just in case
- $GECOS{$acct}=$name;
- }
- close (PASSWD);
- if ( -f $shadow && ! $noshadow)
- {
- open (SHADOW, $shadow) || die "$!n";
- while (<SHADOW>)
- {
- ($acct,$passwd,$dummy)=split(/:/);
- $PASSWORD{$acct}=$passwd;
- }
- close (SHADOW);
- }
- while ( defined ($key=each %UID))
- {
- print "$key$domaintuid=$UID{$key}|gid=$GID{$key}|home=$HOME{$key}" .
- ( $SHELL{$key} =~ /./ ? "|shell=$SHELL{$key}":"") .
- ( $PASSWORD{$key} =~ /./ ? "|systempw=$PASSWORD{$key}":"") .
- ( $GECOS{$key} =~ /./ ? "|gecos=$GECOS{$key}":"") .
- "n";
- print "$UID{$key}=t$keyn" unless $nouid;
- }