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, or mode is F_OK and the
34       file exists), zero is returned.  On error (at least  one  bit  in  mode
35       asked  for  a  permission  that is denied, or mode is F_OK and the file
36       does not exist, or some other error  occurred),  -1  is  returned,  and
37       errno is set appropriately.
38

ERRORS

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

CONFORMING TO

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

NOTES

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

BUGS

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

SEE ALSO

129       chmod(2),   chown(2),   faccessat(2),  open(2),  setgid(2),  setuid(2),
130       stat(2), euidaccess(3), credentials(7), path_resolution(7)
131

COLOPHON

133       This page is part of release 3.53 of the Linux  man-pages  project.   A
134       description  of  the project, and information about reporting bugs, can
135       be found at http://www.kernel.org/doc/man-pages/.
136
137
138
139Linux                             2013-04-16                         ACCESS(2)
Impressum