Re: Question regarding file stat setgid determination.

2011-10-31 Thread Igor Dovgiy
Hi Daniel,

There's no such thing as boolean literals [true/false] in Perl. ) Remember
these weird '1's at the end of .pm files? ) Or constructs like while(1)? )

And frankly speaking, I don't think there's a big need for these literals.
Every value (scalar or list, doesn't matter) can be well and happily
evaluated in boolean context, with little (if any) surprises in this
evaluation.

So, if you really need to return 1 from this function, just put !! before
booleaned value, like this. )
  my $isItSet =  !! ( $mode  Fcntl::S_ISGID )

... but then again, notice the word 'really'. ) And be aware that 'print
!!0' line will print you an empty string, not zero.

-- iD

2011/10/29 Daniel Patrick Sullivan dansulli...@gmail.com

 HI, All,

 I am banging my head against the wall on an issue that I think would
 be pretty simple; I'm trying to determine whether or not the current
 running script has the SetGUID file mode set on it and it is proving
 much more challenging than I had originally anticipated.  I am using
 OSX version 10.6 and perl version v5.10.0.

 Basically my function looks like this:

 use Fcntl;
 sub isCurrentFileSetGID() {
my $currentFile = $0;
my $mode = (stat($currentFile))[2];
print Mode:  . $mode . \n;
my $MyMask = Fcntl::S_ISGID;
print MyMask:  . Fcntl::S_ISGID . \n;
my $isItSet =  $mode  Fcntl::S_ISGID;
print iSItSet =  . $isItSet . \n;
return $isItSet;
 }

 For some reason, the S_ISGID constant is being interpreted as 1024,
 however I am uncertain why.  It appears as 0002000 in
 /usr/include/sys/fcntl.h:

 #define S_ISGID 0002000 /* [XSI] set group id on execution
 */

 When I execute the script, I am getting 1024 as the output for both
 the mask and the operation between the mask and the file mode.  Am I
 missing something here?  I would expect this to return 1.  Can
 somebody help me shed some light on this?  The output of my execution
 against a perl script with the setgid bit set is found below.

 wireless-s1-so-150-57-199:Perl dsullivan2$ ls -l
 total 8
 -rwx--x--x  1 dsullivan2  staff  731 Oct 29 05:55 pw7.pl
 wireless-s1-so-150-57-199:Perl dsullivan2$ chmod 2711 pw7.pl
 wireless-s1-so-150-57-199:Perl dsullivan2$ ls -l
 total 8
 -rwx--s--x  1 dsullivan2  staff  731 Oct 29 05:55 pw7.pl
 wireless-s1-so-150-57-199:Perl dsullivan2$ ./pw7.pl
 Mode: 34249
 MyMask: 1024
 iSItSet = 1024
 wireless-s1-so-150-57-199:Perl dsullivan2$

 Thank-you,

 Dan Sullivan
 312-607-3702

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/





Question regarding file stat setgid determination.

2011-10-29 Thread Daniel Patrick Sullivan
HI, All,

I am banging my head against the wall on an issue that I think would
be pretty simple; I'm trying to determine whether or not the current
running script has the SetGUID file mode set on it and it is proving
much more challenging than I had originally anticipated.  I am using
OSX version 10.6 and perl version v5.10.0.

Basically my function looks like this:

use Fcntl;
sub isCurrentFileSetGID() {
my $currentFile = $0;
my $mode = (stat($currentFile))[2];
print Mode:  . $mode . \n;
my $MyMask = Fcntl::S_ISGID;
print MyMask:  . Fcntl::S_ISGID . \n;
my $isItSet =  $mode  Fcntl::S_ISGID;
print iSItSet =  . $isItSet . \n;
return $isItSet;
}

For some reason, the S_ISGID constant is being interpreted as 1024,
however I am uncertain why.  It appears as 0002000 in
/usr/include/sys/fcntl.h:

#define S_ISGID 0002000 /* [XSI] set group id on execution */

When I execute the script, I am getting 1024 as the output for both
the mask and the operation between the mask and the file mode.  Am I
missing something here?  I would expect this to return 1.  Can
somebody help me shed some light on this?  The output of my execution
against a perl script with the setgid bit set is found below.

wireless-s1-so-150-57-199:Perl dsullivan2$ ls -l
total 8
-rwx--x--x  1 dsullivan2  staff  731 Oct 29 05:55 pw7.pl
wireless-s1-so-150-57-199:Perl dsullivan2$ chmod 2711 pw7.pl
wireless-s1-so-150-57-199:Perl dsullivan2$ ls -l
total 8
-rwx--s--x  1 dsullivan2  staff  731 Oct 29 05:55 pw7.pl
wireless-s1-so-150-57-199:Perl dsullivan2$ ./pw7.pl
Mode: 34249
MyMask: 1024
iSItSet = 1024
wireless-s1-so-150-57-199:Perl dsullivan2$

Thank-you,

Dan Sullivan
312-607-3702

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Question regarding file stat setgid determination.

2011-10-29 Thread Anneli Cuss
Two comments:

02000 is 1024 in base 8; the leading 0 indicates octal much as leading 0x
indicates hex.

$a  $b returns the number with bits in common, so we expect 1024  1024 to
equal 1024 (or 02000  02755, the latter being a realistic file mode; note
these are in octal). This will be true in boolean context.

Hope this helps;

Anne
2011. 10. 29. 오후 10:07에 Daniel Patrick Sullivan dansulli...@gmail.com님이
작성:

 HI, All,

 I am banging my head against the wall on an issue that I think would
 be pretty simple; I'm trying to determine whether or not the current
 running script has the SetGUID file mode set on it and it is proving
 much more challenging than I had originally anticipated.  I am using
 OSX version 10.6 and perl version v5.10.0.

 Basically my function looks like this:

 use Fcntl;
 sub isCurrentFileSetGID() {
my $currentFile = $0;
my $mode = (stat($currentFile))[2];
print Mode:  . $mode . \n;
my $MyMask = Fcntl::S_ISGID;
print MyMask:  . Fcntl::S_ISGID . \n;
my $isItSet =  $mode  Fcntl::S_ISGID;
print iSItSet =  . $isItSet . \n;
return $isItSet;
 }

 For some reason, the S_ISGID constant is being interpreted as 1024,
 however I am uncertain why.  It appears as 0002000 in
 /usr/include/sys/fcntl.h:

 #define S_ISGID 0002000 /* [XSI] set group id on execution
 */

 When I execute the script, I am getting 1024 as the output for both
 the mask and the operation between the mask and the file mode.  Am I
 missing something here?  I would expect this to return 1.  Can
 somebody help me shed some light on this?  The output of my execution
 against a perl script with the setgid bit set is found below.

 wireless-s1-so-150-57-199:Perl dsullivan2$ ls -l
 total 8
 -rwx--x--x  1 dsullivan2  staff  731 Oct 29 05:55 pw7.pl
 wireless-s1-so-150-57-199:Perl dsullivan2$ chmod 2711 pw7.pl
 wireless-s1-so-150-57-199:Perl dsullivan2$ ls -l
 total 8
 -rwx--s--x  1 dsullivan2  staff  731 Oct 29 05:55 pw7.pl
 wireless-s1-so-150-57-199:Perl dsullivan2$ ./pw7.pl
 Mode: 34249
 MyMask: 1024
 iSItSet = 1024
 wireless-s1-so-150-57-199:Perl dsullivan2$

 Thank-you,

 Dan Sullivan
 312-607-3702

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/