[OpenAFS] Perl - Determine if the shell is in a PAG
FB
fbo2@gmx.net
Wed, 6 Dec 2006 10:48:18 +0100
Hi,
On Tue, Dec 05, 2006 at 03:46:26PM -0500, Derrick J Brashear wrote:
> On Tue, 5 Dec 2006, Jeff Blaine wrote:
>
> >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.
>
> There's no guarantee there's no groupname associated. It's jut that for most sites that's true. The
> math in curpag() is the only way to ensure it's true. For you, it's probably true that the comment
> above works.
This is my perl method to determine PAGness:
sub is_pag_linux {
my @groups=split(' ',$( );
my $g0=0;my $g1=0;
my $h=0;my $l=0;my $ret=0;
if ( @groups < 2 ) { return 0 };
$g0 = $groups[$#groups] & 0xffff;
$g1 = $groups[$#groups-1] & 0xffff;
$g0 -= 0x3f00;
$g1 -= 0x3f00;
if ( ( $g0 < 0xc000 ) && ( $g1 < 0xc000 ) ) {
$l = (($g0 & 0x3fff) << 14) | ($g1 & 0x3fff);
$h = ($g0 >> 14);
$h = ($g1 >> 14) + 3*$h;
$ret = (($h << 28) | $l);
if ((($ret >> 24) & 0xff) == 65) {
return 1;
}
}
return 0;
}
It returns 1 or 0 depending on if the process runs in a PAG or not.
Regards,
Frank