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

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


Okay:

#!/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 most easily 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
#
# Also:
#
# http://lists.openafs.org/pipermail/openafs-info/2006-December/024589.html
#
#   "There's no guarantee there's no groupname associated. It's just
#    that for most sites that's true. The math in curpag() is the only
#    way to ensure it's true."
#
# See: src/auth/ktc.c for the fun that is curpag() if you need to
# go that route.

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;
}