#
# passwd handling routines
#
# Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>

$have_passwd = 0;

$minuid = 100;

sub passwd_read {
	local($_, $user, $uid, $gid);

	return if ($have_passwd);
	open(PASSWD, "<$source{passwd}") ||
		&fatal("can't open $source{passwd}: $!");
	while (<PASSWD>) {
		next if (/^[-+]/o);
		chop;
		($user, $passwd, $uid, $gid) = split(/:/, $_, 5);
		next if ($uid < $minuid);
		#print STDERR "\$user2uid{$user} = $uid\n";
		#print STDERR "\$user2gid{$user} = $gid\n";
		$passwdline{$user} = $_;
		$user2uid{$user} = $uid;
		$user2gid{$user} = $gid;
	}
	close PASSWD;
	$have_passwd = 1;
}

sub passwd_byuid {
	local($user);

	&passwd_read;

	foreach $user (keys %passwdline) {
		printf OUT "$user2uid{$user}\t$passwdline{$user}\n";
	}
}

sub passwd_byname {

	&passwd_read;

	foreach $user (keys %user2uid) {
		printf OUT "$user\t$passwdline{$user}\n";
	}
}

1;
