[OpenAFS] Perl - Determine if the shell is in a PAG

Jeff Blaine jblaine@mitre.org
Tue, 05 Dec 2006 15:44:01 -0500


For the next person to want to do this.  The first non-Python code
I've written in many many years.

#!/usr/bin/perl
#
# Determine if we're in a PAG.  Exit with 0 if we are, 1 if we're not.
#
# As of 12/5/2006, PAG membership can be determined by examining one's
# groups.  The existence of 2 groups with GIDs greater than 30000 and
# with no associated group names means the current shell is in a PAG.
#
# See thread:
#
# http://lists.openafs.org/pipermail/openafs-info/2006-December/024579.html
#

use POSIX;

@groups = POSIX::getgroups();
@nonamegroups = ();
foreach (@groups) {
     $id = $_;
     if ($id gt 30000) {
         $name = getgrgid($id);
         if ($name lt 0) {
             push(@nonamegroups, $id);
         }
     }
}
$nngsize = @nonamegroups;
if ($nngsize eq 2) {
     exit 0;
} else {
     exit 1;
}