From 7fdaf9d95c522475f091fee854eb6a39fcfbbfc7 Mon Sep 17 00:00:00 2001 From: hjp Date: Thu, 13 Feb 2003 14:38:27 +0000 Subject: [PATCH] *** empty log message *** --- grouptools/grouplist | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 grouptools/grouplist diff --git a/grouptools/grouplist b/grouptools/grouplist new file mode 100755 index 0000000..cb0e828 --- /dev/null +++ b/grouptools/grouplist @@ -0,0 +1,85 @@ +#!/usr/local/bin/perl -w + +=head1 NAME + +groulist - list all members of a group + +=head1 SYNOPSIS + +grouplist [--fullname] group + +=head1 DESCRIPTION + +This script lists all members of a group. +For each user, the loginname, whether this is the primary or a supplemental group +of the user, and optionally the full name (from the GECOS field) is printed. + +=head2 Options + +=over 4 + +=item --fullname + +Print the GECOS field. + +=item --debug + +Prints some debug output to stderr. + +=back + +=head1 AUTHOR + +Peter J. Holzer + +=head1 SEE ALSO + +id(1) + +=cut + +use strict; +use Getopt::Long; + +my $debug = 0; +my $fullname = 0; +GetOptions("debug" => \$debug, + "fullname" => \$fullname); + + +my $u = {}; + +my @gr; +@gr = getgrnam($ARGV[0]); +unless (@gr) { + print STDERR "$0: Group $ARGV[0] not found\n"; + exit(1); +} + +my ($name,$passwd,$gid,$members) = @gr; +for my $i (split(/ /, $members)) { + print STDERR "getgrent: $gid: $i\n" if($debug); + $u->{$i}{s} = 1; +} + +while (my @pw = getpwent()) { + my ($name,$passwd,$uid,$ugid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw; + print STDERR "getpwent: $ugid: $name\n" if($debug); + if ($ugid == $gid) { + $u->{$name}{p} = 1; + $u->{$name}{fn} = $gcos; + } +} + +for my $i (keys %$u) { + printf("%-10s %1s%1s", $i, $u->{$i}{p} ? "p" : " ", $u->{$i}{s} ? "s" : " "); + if ($fullname) { + if (!$u->{$i}{fn}) { + my @pw = getpwnam($i); + my ($name,$passwd,$uid,$ugid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw; + $u->{$i}{fn} = $gcos; + } + printf(" %s", $u->{$i}{fn}); + } + print "\n"; +}