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
=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<perlfunc>).
+permissions operators, the C<-r> C<-w> C<-x> C<-R> C<-W> C<-X>
+(see L<perlfunc>).
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
when C<use filetest> is in effect, because in some systems
the extended functionality needs to be emulated.
-B<NOTE>: 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<NOTE>: 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
=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";
}
sub unimport {
if ( $_[1] eq 'access' ) {
- $^H &= ~0x00400000;
+ $^H &= ~$filetest::hint_bits;
} else {
die "filetest: the only implemented subpragma is 'access'.\n";
}