1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
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.
26 .\" Modified 1993-07-21 Rik Faith (faith@cs.unc.edu)
27 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
28 .\" Removed note about old kernel (pre-1.1.44) using wrong id on path.
29 .\" Modified 1996-03-18 by Martin Schulze (joey@infodrom.north.de):
30 .\" Stated more clearly how it behaves with symbolic links.
31 .\" Added correction due to Nick Duffek (nsd@bbc.com), aeb, 960426
32 .\" Modified 1996-09-07 by Michael Haardt:
33 .\" Restrictions for NFS
34 .\" Modified 1997-09-09 by Joseph S. Myers <jsm28@cam.ac.uk>
35 .\" Modified 1998-01-13 by Michael Haardt:
36 .\" Using access is often insecure
37 .\" Modified 2001-10-16 by aeb
38 .\" Modified 2002-04-23 by Roger Luethi <rl@hellgate.ch>
39 .\" Modified 2004-06-23 by Michael Kerrisk
41 .TH ACCESS 2 2004-06-23 "Linux" "Linux Programmer's Manual"
43 access \- check user's permissions for a file
46 .B #include <unistd.h>
48 .BI "int access(const char *" pathname ", int " mode );
52 checks whether the process would be allowed to read,
53 write or test for existence of the file (or other file system
58 is a symbolic link permissions of the file referred to by this
59 symbolic link are tested.
62 is a mask consisting of one or more of
63 .BR R_OK ", " W_OK ", " X_OK " and " F_OK .
65 .BR R_OK ", " W_OK " and " X_OK
66 request checking whether the file exists and has read, write and
67 execute permissions, respectively.
69 just requests checking for the existence of the file.
71 The tests depend on the permissions of the directories
72 occurring in the path to the file, as given in
74 and on the permissions of directories and files referred to by symbolic
75 links encountered on the way.
77 The check is done with the process's
79 UID and GID, rather than with the effective IDs as is done when
80 actually attempting an operation.
81 This is to allow set-user-ID programs to
82 easily determine the invoking user's authority.
84 Only access bits are checked, not the file type or contents. Therefore, if
85 a directory is found to be "writable," it probably means that files can be
86 created in the directory, and not that the directory can be written as a
87 file. Similarly, a DOS file may be found to be "executable," but the
91 If the process has appropriate privileges, an implementation may
94 even if none of the execute file permission bits are set.
96 On success (all requested permissions granted), zero is returned.
97 On error (at least one bit in
99 asked for a permission that is denied, or some other error occurred),
102 is set appropriately.
108 The requested access would be denied to the file or search permission
109 is denied for one of the directories in the path prefix of
112 .BR path_resolution (2).)
115 Too many symbolic links were encountered in resolving
123 A directory component in
125 would have been accessible but does not exist or was a dangling
129 A component used as a directory in
131 is not, in fact, a directory.
134 Write permission was requested for a file on a read-only filesystem.
141 points outside your accessible address space.
145 was incorrectly specified.
148 An I/O error occurred.
151 Insufficient kernel memory was available.
154 Write access was requested to an executable which is being
158 returns an error if any of the access types in the requested call
159 fails, even if other types might be successful.
162 may not work correctly on NFS file systems with UID mapping enabled,
163 because UID mapping is done on the server and hidden from the client,
164 which checks permissions.
168 to check if a user is authorized to e.g. open a file before actually
171 creates a security hole, because the user might exploit the short time
172 interval between checking and opening the file to manipulate it.
174 SVID, AT&T, POSIX, X/OPEN, 4.3BSD
179 .BR path_resolution (2),