]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/access.2
0ca6bf54936511787598220855fde6497e0fa4f7
[thirdparty/man-pages.git] / man2 / access.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
5 .\"
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.
9 .\"
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.
14 .\"
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
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
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
40 .\"
41 .TH ACCESS 2 2004-06-23 "Linux" "Linux Programmer's Manual"
42 .SH NAME
43 access \- check user's permissions for a file
44 .SH SYNOPSIS
45 .nf
46 .B #include <unistd.h>
47 .sp
48 .BI "int access(const char *" pathname ", int " mode );
49 .fi
50 .SH DESCRIPTION
51 .B access
52 checks whether the process would be allowed to read,
53 write or test for existence of the file (or other file system
54 object) whose name is
55 .IR pathname .
56 If
57 .I pathname
58 is a symbolic link permissions of the file referred to by this
59 symbolic link are tested.
60
61 .I mode
62 is a mask consisting of one or more of
63 .BR R_OK ", " W_OK ", " X_OK " and " F_OK .
64
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.
68 .B F_OK
69 just requests checking for the existence of the file.
70
71 The tests depend on the permissions of the directories
72 occurring in the path to the file, as given in
73 .IR pathname ,
74 and on the permissions of directories and files referred to by symbolic
75 links encountered on the way.
76
77 The check is done with the process's
78 .I real
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.
83
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
88 .BR execve (2)
89 call will still fail.
90
91 If the process has appropriate privileges, an implementation may
92 indicate success for
93 .B X_OK
94 even if none of the execute file permission bits are set.
95 .SH "RETURN VALUE"
96 On success (all requested permissions granted), zero is returned.
97 On error (at least one bit in
98 .I mode
99 asked for a permission that is denied, or some other error occurred),
100 \-1 is returned, and
101 .I errno
102 is set appropriately.
103 .SH ERRORS
104 .B access
105 shall fail if:
106 .TP
107 .B EACCES
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
110 .IR pathname .
111 (See also
112 .BR path_resolution (2).)
113 .TP
114 .B ELOOP
115 Too many symbolic links were encountered in resolving
116 .IR pathname .
117 .TP
118 .B ENAMETOOLONG
119 .I pathname
120 is too long.
121 .TP
122 .B ENOENT
123 A directory component in
124 .I pathname
125 would have been accessible but does not exist or was a dangling
126 symbolic link.
127 .TP
128 .B ENOTDIR
129 A component used as a directory in
130 .I pathname
131 is not, in fact, a directory.
132 .TP
133 .B EROFS
134 Write permission was requested for a file on a read-only filesystem.
135 .PP
136 .B access
137 may fail if:
138 .TP
139 .B EFAULT
140 .I pathname
141 points outside your accessible address space.
142 .TP
143 .B EINVAL
144 .I mode
145 was incorrectly specified.
146 .TP
147 .B EIO
148 An I/O error occurred.
149 .TP
150 .B ENOMEM
151 Insufficient kernel memory was available.
152 .TP
153 .B ETXTBSY
154 Write access was requested to an executable which is being
155 executed.
156 .SH RESTRICTIONS
157 .B access
158 returns an error if any of the access types in the requested call
159 fails, even if other types might be successful.
160 .PP
161 .B access
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.
165 .PP
166 Using
167 .B access
168 to check if a user is authorized to e.g. open a file before actually
169 doing so using
170 .BR open (2)
171 creates a security hole, because the user might exploit the short time
172 interval between checking and opening the file to manipulate it.
173 .SH "CONFORMING TO"
174 SVID, AT&T, POSIX, X/OPEN, 4.3BSD
175 .SH "SEE ALSO"
176 .BR chmod (2),
177 .BR chown (2),
178 .BR open (2),
179 .BR path_resolution (2),
180 .BR setgid (2),
181 .BR setuid (2),
182 .BR stat (2)