Debian Codegraph @

upstream/debian-unstable/man3/filetest.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "filetest 3perl"
58 .TH filetest 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 filetest \- Perl pragma to control the filetest permission operators
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 6
68 \& $can_perhaps_read = \-r "file"; # use the mode bits
69 \& {
70 \& use filetest \*(Aqaccess\*(Aq; # intuit harder
71 \& $can_really_read = \-r "file";
72 \& }
73 \& $can_perhaps_read = \-r "file"; # use the mode bits again
74 .Ve
75 .SH DESCRIPTION
76 .IX Header "DESCRIPTION"
77 This pragma tells the compiler to change the behaviour of the filetest
78 permission operators, \f(CW\*(C`\-r\*(C'\fR \f(CW\*(C`\-w\*(C'\fR \f(CW\*(C`\-x\*(C'\fR \f(CW\*(C`\-R\*(C'\fR \f(CW\*(C`\-W\*(C'\fR \f(CW\*(C`\-X\*(C'\fR
79 (see perlfunc).
80 .PP
81 The default behaviour of file test operators is to use the simple
82 mode bits as returned by the \fBstat()\fR family of system calls. However,
83 many operating systems have additional features to define more complex
84 access rights, for example ACLs (Access Control Lists).
85 For such environments, \f(CW\*(C`use filetest\*(C'\fR may help the permission
86 operators to return results more consistent with other tools.
87 .PP
88 The \f(CW\*(C`use filetest\*(C'\fR or \f(CW\*(C`no filetest\*(C'\fR statements affect file tests defined in
89 their block, up to the end of the closest enclosing block (they are lexically
90 block-scoped).
91 .PP
92 Currently, only the \f(CW\*(C`access\*(C'\fR sub-pragma is implemented. It enables (or
93 disables) the use of \fBaccess()\fR when available, that is, on most UNIX systems and
94 other POSIX environments. See details below.
95 .SS "Consider this carefully"
96 .IX Subsection "Consider this carefully"
97 The \fBstat()\fR mode bits are probably right for most of the files and
98 directories found on your system, because few people want to use the
99 additional features offered by \fBaccess()\fR. But you may encounter surprises
100 if your program runs on a system that uses ACLs, since the \fBstat()\fR
101 information won't reflect the actual permissions.
102 .PP
103 There may be a slight performance decrease in the filetest operations
104 when the filetest pragma is in effect, because checking bits is very
105 cheap.
106 .PP
107 Also, note that using the file tests for security purposes is a lost cause
108 from the start: there is a window open for race conditions (who is to
109 say that the permissions will not change between the test and the real
110 operation?). Therefore if you are serious about security, just try
111 the real operation and test for its success \- think in terms of atomic
112 operations. Filetests are more useful for filesystem administrative
113 tasks, when you have no need for the content of the elements on disk.
114 .SS "The ""access"" sub-pragma"
115 .IX Subsection "The ""access"" sub-pragma"
116 UNIX and POSIX systems provide an abstract \fBaccess()\fR operating system call,
117 which should be used to query the read, write, and execute rights. This
118 function hides various distinct approaches in additional operating system
119 specific security features, like Access Control Lists (ACLs)
120 .PP
121 The extended filetest functionality is used by Perl only when the argument
122 of the operators is a filename, not when it is a filehandle.
123 .ie n .SS "Limitation with regard to ""_"""
124 .el .SS "Limitation with regard to \f(CW_\fP"
125 .IX Subsection "Limitation with regard to _"
126 Because \fBaccess()\fR does not invoke \fBstat()\fR (at least not in a way visible
127 to Perl), \fBthe stat result cache "_" is not set\fR. This means that the
128 outcome of the following two tests is different. The first has the stat
129 bits of \fI/etc/passwd\fR in \f(CW\*(C`_\*(C'\fR, and in the second case this still
130 contains the bits of \f(CW\*(C`/etc\*(C'\fR.
131 .PP
132 .Vb 4
133 \& { \-d \*(Aq/etc\*(Aq;
134 \& \-w \*(Aq/etc/passwd\*(Aq;
135 \& print \-f _ ? \*(AqYes\*(Aq : \*(AqNo\*(Aq; # Yes
136 \& }
137 \&
138 \& { use filetest \*(Aqaccess\*(Aq;
139 \& \-d \*(Aq/etc\*(Aq;
140 \& \-w \*(Aq/etc/passwd\*(Aq;
141 \& print \-f _ ? \*(AqYes\*(Aq : \*(AqNo\*(Aq; # No
142 \& }
143 .Ve
144 .PP
145 Of course, unless your OS does not implement \fBaccess()\fR, in which case the
146 pragma is simply ignored. Best not to use \f(CW\*(C`_\*(C'\fR at all in a file where
147 the filetest pragma is active!
148 .PP
149 As a side effect, as \f(CW\*(C`_\*(C'\fR doesn't work, stacked filetest operators
150 (\f(CW\*(C`\-f \-w $file\*(C'\fR) won't work either.
151 .PP
152 This limitation might be removed in a future version of perl.