summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2013/man3p/access.3p
blob: 955556dae3ccc888299ca7551d6802a019a8691d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
'\" et
.TH ACCESS "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.

.SH NAME
access, faccessat
\(em determine accessibility of a file relative to directory file
descriptor
.SH SYNOPSIS
.LP
.nf
#include <unistd.h>
.P
int access(const char *\fIpath\fP, int \fIamode\fP);
int faccessat(int \fIfd\fP, const char *\fIpath\fP, int \fIamode\fP, int \fIflag\fP);
.fi
.SH DESCRIPTION
The
\fIaccess\fR()
function shall check the file named by the pathname pointed to by the
.IR path
argument for accessibility according to the bit pattern contained in
.IR amode ,
using the real user ID in place of the effective user ID and the real
group ID in place of the effective group ID.
.P
The value of
.IR amode
is either the bitwise-inclusive OR of the access permissions to be
checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
.P
If any access permissions are checked, each shall be checked
individually, as described in the Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 4.4" ", " "File Access Permissions",
except that where that description refers to execute permission for
a process with appropriate privileges, an implementation may indicate
success for X_OK even if execute permission is not granted to any user.
.P
The
\fIfaccessat\fR()
function shall be equivalent to the
\fIaccess\fR()
function, except in the case where
.IR path
specifies a relative path. In this case the file whose accessibility is
to be determined shall be located relative to the directory associated
with the file descriptor
.IR fd
instead of the current working directory. If the file descriptor was
opened without O_SEARCH, the function shall check whether directory
searches are permitted using the current permissions of the directory
underlying the file descriptor. If the file descriptor was opened with
O_SEARCH, the function shall not perform the check.
.P
If
\fIfaccessat\fR()
is passed the special value AT_FDCWD in the
.IR fd
parameter, the current working directory shall be used and the behavior
shall be identical to a call to
\fIaccess\fR().
.P
Values for
.IR flag
are constructed by a bitwise-inclusive OR of flags from the following
list, defined in
.IR <fcntl.h> :
.IP AT_EACCESS 12
The checks for accessibility are performed using the effective user and
group IDs instead of the real user and group ID as required in a call
to
\fIaccess\fR().
.SH "RETURN VALUE"
Upon successful completion, these functions shall return 0. Otherwise,
these functions shall return \(mi1 and set
.IR errno
to indicate the error.
.SH ERRORS
These functions shall fail if:
.TP
.BR EACCES
Permission bits of the file mode do not permit the requested access, or
search permission is denied on a component of the path prefix.
.TP
.BR ELOOP
A loop exists in symbolic links encountered during resolution of the
.IR path
argument.
.TP
.BR ENAMETOOLONG
.br
The length of a component of a pathname is longer than
{NAME_MAX}.
.TP
.BR ENOENT
A component of
.IR path
does not name an existing file or
.IR path
is an empty string.
.TP
.BR ENOTDIR
A component of the path prefix names an existing file that is neither
a directory nor a symbolic link to a directory, or the
.IR path
argument contains at least one non-\c
<slash>
character and ends with one or more trailing
<slash>
characters and the last pathname component names an existing file
that is neither a directory nor a symbolic link to a directory.
.TP
.BR EROFS
Write access is requested for a file on a read-only file system.
.P
The
\fIfaccessat\fR()
function shall fail if:
.TP
.BR EACCES
.IR fd
was not opened with O_SEARCH and the permissions of the directory
underlying
.IR fd
do not permit directory searches.
.TP
.BR EBADF
The
.IR path
argument does not specify an absolute path and the
.IR fd
argument is neither AT_FDCWD nor a valid file descriptor open
for reading or searching.
.TP
.BR ENOTDIR
The
.IR path
argument is not an absolute path and
.IR fd
is a file descriptor associated with a non-directory file.
.P
These functions may fail if:
.TP
.BR EINVAL
The value of the \fIamode\fP argument is invalid.
.TP
.BR ELOOP
More than
{SYMLOOP_MAX}
symbolic links were encountered during resolution of the
.IR path
argument.
.TP
.BR ENAMETOOLONG
.br
The length of a pathname exceeds
{PATH_MAX},
or pathname resolution of a symbolic link produced an intermediate
result with a length that exceeds
{PATH_MAX}.
.TP
.BR ETXTBSY
Write access is requested for a pure procedure (shared text) file that
is being executed.
.P
The
\fIfaccessat\fR()
function may fail if:
.TP
.BR EINVAL
The value of the
.IR flag
argument is not valid.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
.SS "Testing for the Existence of a File"
.P
The following example tests whether a file named
.BR myfile
exists in the
.BR /tmp
directory.
.sp
.RS 4
.nf
\fB
#include <unistd.h>
\&...
int result;
const char *pathname = "/tmp/myfile";
.P
result = access (pathname, F_OK);
.fi \fR
.P
.RE
.SH "APPLICATION USAGE"
Additional values of
.IR amode
other than the set defined in the description may be valid; for
example, if a system has extended access controls.
.P
The use of the AT_EACCESS value for
.IR flag
enables functionality not available in
\fIaccess\fR().
.SH RATIONALE
In early proposals, some inadequacies in the
\fIaccess\fR()
function led to the creation of an
\fIeaccess\fR()
function because:
.IP " 1." 4
Historical implementations of
\fIaccess\fR()
do not test file access correctly when the process'
real user ID is
superuser. In particular, they always return zero when testing execute
permissions without regard to whether the file is executable.
.IP " 2." 4
The superuser has complete access to all files on a system. As a
consequence, programs started by the superuser and switched to the
effective user ID
with lesser privileges cannot use
\fIaccess\fR()
to test their file access permissions.
.P
However, the historical model of
\fIeaccess\fR()
does not resolve problem (1), so this volume of POSIX.1\(hy2008 now allows
\fIaccess\fR()
to behave in the desired way because several implementations have
corrected the problem. It was also argued that problem (2) is more
easily solved by using
\fIopen\fR(),
\fIchdir\fR(),
or one of the
.IR exec
functions as appropriate and responding to the error, rather than
creating a new function that would not be as reliable. Therefore,
\fIeaccess\fR()
is not included in this volume of POSIX.1\(hy2008.
.P
The sentence concerning appropriate privileges and execute permission
bits
reflects the two possibilities implemented by historical
implementations when checking superuser access for X_OK.
.P
New implementations are discouraged from returning X_OK unless at least
one execution permission bit is set.
.P
The purpose of the
\fIfaccessat\fR()
function is to enable the checking of the accessibility of files in
directories other than the current working directory without exposure
to race conditions. Any part of the path of a file could be changed in
parallel to a call to
\fIaccess\fR(),
resulting in unspecified behavior. By opening a file descriptor for
the target directory and using the
\fIfaccessat\fR()
function it can be guaranteed that the file tested for accessibility is
located relative to the desired directory.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIchmod\fR\^(\|)",
.IR "\fIfstatat\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 4.4" ", " "File Access Permissions",
.IR "\fB<fcntl.h>\fP",
.IR "\fB<unistd.h>\fP"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.unix.org/online.html .

Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .