1ACCESS(2)                  Linux Programmer's Manual                 ACCESS(2)
2
3
4

NAME

6       access - check real user's permissions for a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int access(const char *pathname, int mode);
12

DESCRIPTION

14       access()  checks  whether the calling process can access the file path‐
15       name.  If pathname is a symbolic link, it is dereferenced.
16
17       The mode specifies the accessibility check(s) to be performed,  and  is
18       either the value F_OK, or a mask consisting of the bitwise OR of one or
19       more of R_OK, W_OK, and X_OK.  F_OK tests  for  the  existence  of  the
20       file.   R_OK,  W_OK,  and  X_OK test whether the file exists and grants
21       read, write, and execute permissions, respectively.
22
23       The check is done using the calling process's real UID and GID,  rather
24       than the effective IDs as is done when actually attempting an operation
25       (e.g., open(2)) on the file.  This allows set-user-ID programs to  eas‐
26       ily determine the invoking user's authority.
27
28       If the calling process is privileged (i.e., its real UID is zero), then
29       an X_OK check is successful for a regular file if execute permission is
30       enabled for any of the file owner, group, or other.
31

RETURN VALUE

33       On  success  (all requested permissions granted), zero is returned.  On
34       error (at least one bit in mode asked for a permission that is  denied,
35       or  some other error occurred), -1 is returned, and errno is set appro‐
36       priately.
37

ERRORS

39       access() shall fail if:
40
41       EACCES The requested access would be denied to the file, or search per‐
42              mission  is denied for one of the directories in the path prefix
43              of pathname.  (See also path_resolution(7).)
44
45       ELOOP  Too many symbolic links were encountered in resolving pathname.
46
47       ENAMETOOLONG
48              pathname is too long.
49
50       ENOENT A component of pathname does not exist or is a dangling symbolic
51              link.
52
53       ENOTDIR
54              A  component  used as a directory in pathname is not, in fact, a
55              directory.
56
57       EROFS  Write permission was requested for a file on  a  read-only  file
58              system.
59
60       access() may fail if:
61
62       EFAULT pathname points outside your accessible address space.
63
64       EINVAL mode was incorrectly specified.
65
66       EIO    An I/O error occurred.
67
68       ENOMEM Insufficient kernel memory was available.
69
70       ETXTBSY
71              Write  access was requested to an executable which is being exe‐
72              cuted.
73

CONFORMING TO

75       SVr4, 4.3BSD, POSIX.1-2001.
76

NOTES

78       Warning: Using access() to check if a user is authorized to, for  exam‐
79       ple, open a file before actually doing so using open(2) creates a secu‐
80       rity hole, because the user  might  exploit  the  short  time  interval
81       between  checking and opening the file to manipulate it.  For this rea‐
82       son, the use of this system call should be avoided.
83
84       access() returns an error if any of the access types in mode is denied,
85       even if some of the other access types in mode are permitted.
86
87       If the calling process has appropriate privileges (i.e., is superuser),
88       POSIX.1-2001 permits implementation to indicate  success  for  an  X_OK
89       check  even if none of the execute file permission bits are set.  Linux
90       does not do this.
91
92       A file is only accessible if the permissions on each of the directories
93       in the path prefix of pathname grant search (i.e., execute) access.  If
94       any directory is  inaccessible,  then  the  access()  call  will  fail,
95       regardless of the permissions on the file itself.
96
97       Only  access  bits  are checked, not the file type or contents.  There‐
98       fore, if a directory is found to be writable, it  probably  means  that
99       files  can  be created in the directory, and not that the directory can
100       be written as a file.  Similarly, a DOS file may be found to  be  "exe‐
101       cutable," but the execve(2) call will still fail.
102
103       access()  may  not  work correctly on NFS file systems with UID mapping
104       enabled, because UID mapping is done on the server and hidden from  the
105       client, which checks permissions.
106

BUGS

108       In  kernel  2.4 (and earlier) there is some strangeness in the handling
109       of X_OK tests for superuser.  If all categories of  execute  permission
110       are  disabled for a nondirectory file, then the only access() test that
111       returns -1 is when mode is specified as just X_OK; if R_OK or  W_OK  is
112       also  specified in mode, then access() returns 0 for such files.  Early
113       2.6 kernels (up to and including 2.6.3) also behaved in the same way as
114       kernel 2.4.
115
116       In  kernels before 2.6.20, access() ignored the effect of the MS_NOEXEC
117       flag if it was used to mount(2) the underlying file system.  Since ker‐
118       nel 2.6.20, access() honors this flag.
119

SEE ALSO

121       chmod(2),   chown(2),   faccessat(2),  open(2),  setgid(2),  setuid(2),
122       stat(2), euidaccess(3), credentials(7), path_resolution(7)
123

COLOPHON

125       This page is part of release 3.25 of the Linux  man-pages  project.   A
126       description  of  the project, and information about reporting bugs, can
127       be found at http://www.kernel.org/doc/man-pages/.
128
129
130
131Linux                             2007-07-10                         ACCESS(2)
Impressum