X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Ffiletest.pm;h=21252f35a6fc1322eda6f7f32d76d773ed4a6744;hb=e2be6f076cc59730d8ec4f9a3cbe716348da62de;hp=cc14e82817cc6eac8e8e4504ff254a7c4e7d0cfd;hpb=5ff3f7a4e03a6b103d9e628865398e498e9a7968;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/filetest.pm b/lib/filetest.pm index cc14e82..21252f3 100644 --- a/lib/filetest.pm +++ b/lib/filetest.pm @@ -1,11 +1,13 @@ package filetest; +our $VERSION = '1.00'; + =head1 NAME filetest - Perl pragma to control the filetest permission operators =head1 SYNOPSIS - + $can_perhaps_read = -r "file"; # use the mode bits { use filetest 'access'; # intuit harder @@ -16,7 +18,8 @@ filetest - Perl pragma to control the filetest permission operators =head1 DESCRIPTION This pragma tells the compiler to change the behaviour of the filetest -permissions operators, the -r -w -x -R -W -X (see L). +permissions operators, the C<-r> C<-w> C<-x> C<-R> C<-W> C<-X> +(see L). The default behaviour to use the mode bits as returned by the stat() family of calls. This, however, may not be the right thing to do if @@ -31,11 +34,11 @@ There may be a slight performance decrease in the filetests when C is in effect, because in some systems the extended functionality needs to be emulated. -B: using the file tests is a lost case from the start: there is -a window open for race conditions (who is to say that the permissions -will not change between the test and the real operation?). Therefore -if you are serious about security, just try the real operation and -test for its success. Think atomicity. +B: using the file tests for security purposes is a lost cause +from the start: there is a window open for race conditions (who is to +say that the permissions will not change between the test and the real +operation?). Therefore if you are serious about security, just try +the real operation and test for its success. Think atomicity. =head2 subpragma access @@ -46,9 +49,11 @@ operators is a filename, not when it is a filehandle. =cut +$filetest::hint_bits = 0x00400000; + sub import { if ( $_[1] eq 'access' ) { - $^H |= 0x00400000; + $^H |= $filetest::hint_bits; } else { die "filetest: the only implemented subpragma is 'access'.\n"; } @@ -56,7 +61,7 @@ sub import { sub unimport { if ( $_[1] eq 'access' ) { - $^H &= ~0x00400000; + $^H &= ~$filetest::hint_bits; } else { die "filetest: the only implemented subpragma is 'access'.\n"; }