1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2004, 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" Modified 1993-07-21 Rik Faith (faith@cs.unc.edu)
28 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
29 .\" Removed note about old kernel (pre-1.1.44) using wrong id on path.
30 .\" Modified 1996-03-18 by Martin Schulze (joey@infodrom.north.de):
31 .\" Stated more clearly how it behaves with symbolic links.
32 .\" Added correction due to Nick Duffek (nsd@bbc.com), aeb, 960426
33 .\" Modified 1996-09-07 by Michael Haardt:
34 .\" Restrictions for NFS
35 .\" Modified 1997-09-09 by Joseph S. Myers <jsm28@cam.ac.uk>
36 .\" Modified 1998-01-13 by Michael Haardt:
37 .\" Using access is often insecure
38 .\" Modified 2001-10-16 by aeb
39 .\" Modified 2002-04-23 by Roger Luethi <rl@hellgate.ch>
40 .\" Modified 2004-06-23 by Michael Kerrisk
41 .\" 2007-06-10, mtk, various parts rewritten, and added BUGS section.
43 .TH ACCESS 2 2016-03-15 "Linux" "Linux Programmer's Manual"
45 access, faccessat \- check user's permissions for a file
48 .B #include <unistd.h>
50 .BI "int access(const char *" pathname ", int " mode );
52 .BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
53 .B #include <unistd.h>
55 .BI "int faccessat(int " dirfd ", const char *" pathname ", int " \
56 mode ", int " flags );
60 Feature Test Macro Requirements for glibc (see
61 .BR feature_test_macros (7)):
70 _POSIX_C_SOURCE\ >=\ 200809L
79 checks whether the calling process can access the file
83 is a symbolic link, it is dereferenced.
87 specifies the accessibility check(s) to be performed,
88 and is either the value
90 .\" F_OK is defined as 0 on every system that I know of.
91 or a mask consisting of the bitwise OR of one or more of
92 .BR R_OK ", " W_OK ", and " X_OK .
94 tests for the existence of the file.
95 .BR R_OK ", " W_OK ", and " X_OK
96 test whether the file exists and grants read, write, and
97 execute permissions, respectively.
99 The check is done using the calling process's
101 UID and GID, rather than the effective IDs as is done when
102 actually attempting an operation (e.g.,
105 Similarly, for the root user, the check uses the set of
106 permitted capabilities rather than the set of effective
107 capabilities; and for non-root users, the check uses an empty set
110 This allows set-user-ID programs and capability-endowed programs
111 to easily determine the invoking user's authority.
114 does not answer the "can I read/write/execute this file?" question.
115 It answers a slightly different question:
116 "(assuming I'm a setuid binary) can
117 .I the user who invoked me
118 read/write/execute this file?",
119 which gives set-user-ID programs the possibility to
120 prevent malicious users from causing them to read files
121 which users shouldn't be able to read.
123 If the calling process is privileged (i.e., its real UID is zero),
126 check is successful for a regular file if execute permission
127 is enabled for any of the file owner, group, or other.
131 system call operates in exactly the same way as
133 except for the differences described here.
135 If the pathname given in
137 is relative, then it is interpreted relative to the directory
138 referred to by the file descriptor
140 (rather than relative to the current working directory of
141 the calling process, as is done by
143 for a relative pathname).
153 is interpreted relative to the current working
154 directory of the calling process (like
164 is constructed by ORing together zero or more of the following values:
167 Perform access checks using the effective user and group IDs.
170 uses the real IDs (like
173 .B AT_SYMLINK_NOFOLLOW
176 is a symbolic link, do not dereference it:
177 instead return information about the link itself.
181 for an explanation of the need for
184 On success (all requested permissions granted, or
188 and the file exists), zero is returned.
189 On error (at least one bit in
191 asked for a permission that is denied, or
195 and the file does not exist, or some other error occurred),
198 is set appropriately.
206 The requested access would be denied to the file, or search permission
207 is denied for one of the directories in the path prefix of
210 .BR path_resolution (7).)
213 Too many symbolic links were encountered in resolving
223 does not exist or is a dangling symbolic link.
226 A component used as a directory in
228 is not, in fact, a directory.
231 Write permission was requested for a file on a read-only filesystem.
240 points outside your accessible address space.
244 was incorrectly specified.
247 An I/O error occurred.
250 Insufficient kernel memory was available.
253 Write access was requested to an executable which is being
256 The following additional errors can occur for
261 is not a valid file descriptor.
264 Invalid flag specified in
271 is a file descriptor referring to a file other than a directory.
274 was added to Linux in kernel 2.6.16;
275 library support was added to glibc in version 2.4.
278 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
285 Using these calls to check if a user is authorized to, for example,
286 open a file before actually doing so using
288 creates a security hole, because the user might exploit the short time
289 interval between checking and opening the file to manipulate it.
290 .BR "For this reason, the use of this system call should be avoided" .
291 (In the example just described,
292 a safer alternative would be to temporarily switch the process's
293 effective user ID to the real ID and then call
297 always dereferences symbolic links.
298 If you need to check the permissions on a symbolic link, use
301 .BR AT_SYMLINK_NOFOLLOW .
303 These calls return an error if any of the access types in
305 is denied, even if some of the other access types in
309 If the calling process has appropriate privileges (i.e., is superuser),
310 POSIX.1-2001 permits an implementation to indicate success for an
312 check even if none of the execute file permission bits are set.
313 .\" HPU-UX 11 and Tru64 5.1 do this.
314 Linux does not do this.
316 A file is accessible only if the permissions on each of the
317 directories in the path prefix of
319 grant search (i.e., execute) access.
320 If any directory is inaccessible, then the
322 call fails, regardless of the permissions on the file itself.
324 Only access bits are checked, not the file type or contents.
325 Therefore, if a directory is found to be writable,
326 it probably means that files can be created in the directory,
327 and not that the directory can be written as a file.
328 Similarly, a DOS file may be found to be "executable," but the
330 call will still fail.
333 may not work correctly on NFSv2 filesystems with UID mapping enabled,
334 because UID mapping is done on the server and hidden from the client,
335 which checks permissions. (NFS versions 3 and higher perform the check on
337 Similar problems can occur to FUSE mounts.
340 .SS C library/kernel differences
343 system call takes only the first three arguments.
347 .B AT_SYMLINK_NOFOLLOW
348 flags are actually implemented within the glibc wrapper function for
350 If either of these flags is specified, then the wrapper function employs
352 to determine access permissions.
354 On older kernels where
356 is unavailable (and when the
359 .B AT_SYMLINK_NOFOLLOW
360 flags are not specified),
361 the glibc wrapper function falls back to the use of
365 is a relative pathname,
366 glibc constructs a pathname based on the symbolic link in
368 that corresponds to the
372 In kernel 2.4 (and earlier) there is some strangeness in the handling of
375 If all categories of execute permission are disabled
376 for a nondirectory file, then the only
378 test that returns \-1 is when
390 returns 0 for such files.
391 .\" This behavior appears to have been an implementation accident.
392 Early 2.6 kernels (up to and including 2.6.3)
393 also behaved in the same way as kernel 2.4.
395 In kernels before 2.6.20,
396 these calls ignored the effect of the
398 flag if it was used to
400 the underlying filesystem.
401 Since kernel 2.6.20, the
413 .BR path_resolution (7),