Debian Codegraph @

upstream/opensuse-tumbleweed/man3/filetest.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "filetest 3pm"
61 .TH filetest 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 filetest \- Perl pragma to control the filetest permission operators
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 6
71 \& $can_perhaps_read = \-r "file"; # use the mode bits
72 \& {
73 \& use filetest \*(Aqaccess\*(Aq; # intuit harder
74 \& $can_really_read = \-r "file";
75 \& }
76 \& $can_perhaps_read = \-r "file"; # use the mode bits again
77 .Ve
78 .SH DESCRIPTION
79 .IX Header "DESCRIPTION"
80 This pragma tells the compiler to change the behaviour of the filetest
81 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
82 (see perlfunc).
83 .PP
84 The default behaviour of file test operators is to use the simple
85 mode bits as returned by the \fBstat()\fR family of system calls. However,
86 many operating systems have additional features to define more complex
87 access rights, for example ACLs (Access Control Lists).
88 For such environments, \f(CW\*(C`use filetest\*(C'\fR may help the permission
89 operators to return results more consistent with other tools.
90 .PP
91 The \f(CW\*(C`use filetest\*(C'\fR or \f(CW\*(C`no filetest\*(C'\fR statements affect file tests defined in
92 their block, up to the end of the closest enclosing block (they are lexically
93 block\-scoped).
94 .PP
95 Currently, only the \f(CW\*(C`access\*(C'\fR sub\-pragma is implemented. It enables (or
96 disables) the use of \fBaccess()\fR when available, that is, on most UNIX systems and
97 other POSIX environments. See details below.
98 .SS "Consider this carefully"
99 .IX Subsection "Consider this carefully"
100 The \fBstat()\fR mode bits are probably right for most of the files and
101 directories found on your system, because few people want to use the
102 additional features offered by \fBaccess()\fR. But you may encounter surprises
103 if your program runs on a system that uses ACLs, since the \fBstat()\fR
104 information won\*(Aqt reflect the actual permissions.
105 .PP
106 There may be a slight performance decrease in the filetest operations
107 when the filetest pragma is in effect, because checking bits is very
108 cheap.
109 .PP
110 Also, note that using the file tests for security purposes is a lost cause
111 from the start: there is a window open for race conditions (who is to
112 say that the permissions will not change between the test and the real
113 operation?). Therefore if you are serious about security, just try
114 the real operation and test for its success \- think in terms of atomic
115 operations. Filetests are more useful for filesystem administrative
116 tasks, when you have no need for the content of the elements on disk.
117 .SS "The ""access"" sub\-pragma"
118 .IX Subsection "The ""access"" sub-pragma"
119 UNIX and POSIX systems provide an abstract \fBaccess()\fR operating system call,
120 which should be used to query the read, write, and execute rights. This
121 function hides various distinct approaches in additional operating system
122 specific security features, like Access Control Lists (ACLs)
123 .PP
124 The extended filetest functionality is used by Perl only when the argument
125 of the operators is a filename, not when it is a filehandle.
126 .ie n .SS "Limitation with regard to ""_"""
127 .el .SS "Limitation with regard to \f(CW_\fP"
128 .IX Subsection "Limitation with regard to _"
129 Because \fBaccess()\fR does not invoke \fBstat()\fR (at least not in a way visible
130 to Perl), \fBthe stat result cache "_" is not set\fR. This means that the
131 outcome of the following two tests is different. The first has the stat
132 bits of \fI/etc/passwd\fR in \f(CW\*(C`_\*(C'\fR, and in the second case this still
133 contains the bits of \f(CW\*(C`/etc\*(C'\fR.
134 .PP
135 .Vb 4
136 \& { \-d \*(Aq/etc\*(Aq;
137 \& \-w \*(Aq/etc/passwd\*(Aq;
138 \& print \-f _ ? \*(AqYes\*(Aq : \*(AqNo\*(Aq; # Yes
139 \& }
140 \&
141 \& { use filetest \*(Aqaccess\*(Aq;
142 \& \-d \*(Aq/etc\*(Aq;
143 \& \-w \*(Aq/etc/passwd\*(Aq;
144 \& print \-f _ ? \*(AqYes\*(Aq : \*(AqNo\*(Aq; # No
145 \& }
146 .Ve
147 .PP
148 Of course, unless your OS does not implement \fBaccess()\fR, in which case the
149 pragma is simply ignored. Best not to use \f(CW\*(C`_\*(C'\fR at all in a file where
150 the filetest pragma is active!
151 .PP
152 As a side effect, as \f(CW\*(C`_\*(C'\fR doesn\*(Aqt work, stacked filetest operators
153 (\f(CW\*(C`\-f \-w $file\*(C'\fR) won\*(Aqt work either.
154 .PP
155 This limitation might be removed in a future version of perl.