1ACCESS(2) Linux Programmer's Manual ACCESS(2)
2
3
4
6 access - check user's permissions for a file
7
9 #include <unistd.h>
10
11 int access(const char *pathname, int mode);
12
14 access() checks whether the process would be allowed to read, write or
15 test for existence of the file (or other file system object) whose name
16 is pathname. If pathname is a symbolic link permissions of the file
17 referred to by this symbolic link are tested.
18
19 mode is a mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.
20
21 R_OK, W_OK and X_OK request checking whether the file exists and has
22 read, write and execute permissions, respectively. F_OK just requests
23 checking for the existence of the file.
24
25 The tests depend on the permissions of the directories occurring in the
26 path to the file, as given in pathname, and on the permissions of
27 directories and files referred to by symbolic links encountered on the
28 way.
29
30 The check is done with the process's real UID and GID, rather than with
31 the effective IDs as is done when actually attempting an operation.
32 This is to allow set-user-ID programs to easily determine the invoking
33 user's authority.
34
35 Only access bits are checked, not the file type or contents. There‐
36 fore, if a directory is found to be "writable," it probably means that
37 files can be created in the directory, and not that the directory can
38 be written as a file. Similarly, a DOS file may be found to be "exe‐
39 cutable," but the execve(2) call will still fail.
40
41 If the process has appropriate privileges, an implementation may indi‐
42 cate success for X_OK even if none of the execute file permission bits
43 are set.
44
46 On success (all requested permissions granted), zero is returned. On
47 error (at least one bit in mode asked for a permission that is denied,
48 or some other error occurred), -1 is returned, and errno is set appro‐
49 priately.
50
52 access() shall fail if:
53
54 EACCES The requested access would be denied to the file or search per‐
55 mission is denied for one of the directories in the path prefix
56 of pathname. (See also path_resolution(2).)
57
58 ELOOP Too many symbolic links were encountered in resolving pathname.
59
60 ENAMETOOLONG
61 pathname is too long.
62
63 ENOENT A component of pathname does not exist or is a dangling symbolic
64 link.
65
66 ENOTDIR
67 A component used as a directory in pathname is not, in fact, a
68 directory.
69
70 EROFS Write permission was requested for a file on a read-only
71 filesystem.
72
73 access() may fail if:
74
75 EFAULT pathname points outside your accessible address space.
76
77 EINVAL mode was incorrectly specified.
78
79 EIO An I/O error occurred.
80
81 ENOMEM Insufficient kernel memory was available.
82
83 ETXTBSY
84 Write access was requested to an executable which is being exe‐
85 cuted.
86
88 In kernels before 2.6.20, access() ignored the effect of the MS_NOEXEC
89 flag if it was used to mount(2) the underlying file system. Since ker‐
90 nel 2.6.20, access() honours this flag.
91
93 access() returns an error if any of the access types in the requested
94 call fails, even if other types might be successful.
95
96 access() may not work correctly on NFS file systems with UID mapping
97 enabled, because UID mapping is done on the server and hidden from the
98 client, which checks permissions.
99
100 Using access() to check if a user is authorized to e.g. open a file
101 before actually doing so using open(2) creates a security hole, because
102 the user might exploit the short time interval between checking and
103 opening the file to manipulate it.
104
106 SVr4, 4.3BSD, POSIX.1-2001.
107
109 chmod(2), chown(2), faccessat(2), open(2), path_resolution(2), set‐
110 gid(2), setuid(2), stat(2)
111
112
113
114Linux 2004-06-23 ACCESS(2)