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

$have_group = 0;

$mingid = 100;

sub group_read {
	local($_, $group, $users, $gid, $user);

	return if ($have_group);
	open(GROUP, "<$source{group}") ||
		&fatal("can't open $source{$group}: $!");
	while (<GROUP>) {
		next if (/^[-+]/o);
		chop;
		#($group, $gid, $users) = /^([^:]+)*:[^:]*:(\d*):(.*)/o;
		($group, $pass, $gid, $users) = split(/:/);
		next if ($gid < $mingid);
		$name2group{$group} = $_;
		$gid2group{$gid} = $_;
		foreach $user (split(/,/, $users)) {
			$user2groups{$user} .= "$gid,";
		}
	}
	close GROUP;
	$have_group = 1;
}

sub group_bygid {
	local($gid);

	&group_read;

	foreach $gid (keys %gid2group) {
		printf OUT "$gid\t$gid2group{$gid}\n";
	}
}

sub group_byname {
	local($name);

	&group_read;

	foreach $name (keys %name2group) {
		printf OUT "$name\t$name2group{$name}\n";
	}
}

1;
