add missing file from change#1943
[p5sagit/p5-mst-13.2.git] / lib / filetest.pm
1 package filetest;
2
3 =head1 NAME
4
5 filetest - Perl pragma to control the filetest permission operators
6
7 =head1 SYNOPSIS
8     
9     $can_perhaps_read = -r "file";      # use the mode bits
10     {
11         use filetest 'access';          # intuit harder
12         $can_really_read = -r "file";
13     }
14     $can_perhaps_read = -r "file";      # use the mode bits again
15
16 =head1 DESCRIPTION
17
18 This pragma tells the compiler to change the behaviour of the filetest
19 permissions operators, the -r -w -x -R -W -X (see L<perlfunc>).
20
21 The default behaviour to use the mode bits as returned by the stat()
22 family of calls.  This, however, may not be the right thing to do if
23 for example various ACL (access control lists) schemes are in use.
24 For such environments, C<use filetest> may help the permission
25 operators to return results more consistent with other tools.
26
27 Each "use filetest" or "no filetest" affects statements to the end of
28 the enclosing block.
29
30 There may be a slight performance decrease in the filetests
31 when C<use filetest> is in effect, because in some systems
32 the extended functionality needs to be emulated.
33
34 B<NOTE>: using the file tests is a lost case from the start: there is
35 a window open for race conditions (who is to say that the permissions
36 will not change between the test and the real operation?).  Therefore
37 if you are serious about security, just try the real operation and
38 test for its success.  Think atomicity.
39
40 =head2 subpragma access
41
42 Currently only one subpragma, C<access> is implemented.  It enables
43 (or disables) the use of access() or similar system calls.  This
44 extended filetest functionality is used only when the argument of the
45 operators is a filename, not when it is a filehandle.
46
47 =cut
48
49 sub import {
50     if ( $_[1] eq 'access' ) {
51         $^H |= 0x00400000;
52     } else {
53         die "filetest: the only implemented subpragma is 'access'.\n";
54     }
55 }
56
57 sub unimport {
58     if ( $_[1] eq 'access' ) {
59         $^H &= ~0x00400000;
60     } else {
61         die "filetest: the only implemented subpragma is 'access'.\n";
62     }
63 }
64
65 1;