OSDN Git Service

Revert the following change to correct the mail address of the committer
[linuxjm/jm.git] / manual / LDP_man-pages / original / man2 / access.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1993-07-21 Rik Faith (faith@cs.unc.edu)
28 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
29 .\"   Removed note about old kernel (pre-1.1.44) using wrong id on path.
30 .\" Modified 1996-03-18 by Martin Schulze (joey@infodrom.north.de):
31 .\"   Stated more clearly how it behaves with symbolic links.
32 .\" Added correction due to Nick Duffek (nsd@bbc.com), aeb, 960426
33 .\" Modified 1996-09-07 by Michael Haardt:
34 .\"   Restrictions for NFS
35 .\" Modified 1997-09-09 by Joseph S. Myers <jsm28@cam.ac.uk>
36 .\" Modified 1998-01-13 by Michael Haardt:
37 .\"   Using access is often insecure
38 .\" Modified 2001-10-16 by aeb
39 .\" Modified 2002-04-23 by Roger Luethi <rl@hellgate.ch>
40 .\" Modified 2004-06-23 by Michael Kerrisk
41 .\" 2007-06-10, mtk, various parts rewritten, and added BUGS section.
42 .\"
43 .TH ACCESS 2 2013-04-16 "Linux" "Linux Programmer's Manual"
44 .SH NAME
45 access \- check real user's permissions for a file
46 .SH SYNOPSIS
47 .nf
48 .B #include <unistd.h>
49 .sp
50 .BI "int access(const char *" pathname ", int " mode );
51 .fi
52 .SH DESCRIPTION
53 .BR access ()
54 checks whether the calling process can access the file
55 .IR pathname .
56 If
57 .I pathname
58 is a symbolic link, it is dereferenced.
59
60 The
61 .I mode
62 specifies the accessibility check(s) to be performed,
63 and is either the value
64 .BR F_OK ,
65 .\" F_OK is defined as 0 on every system that I know of.
66 or a mask consisting of the bitwise OR of one or more of
67 .BR R_OK ", " W_OK ", and " X_OK .
68 .B F_OK
69 tests for the existence of the file.
70 .BR R_OK ", " W_OK ", and " X_OK
71 test whether the file exists and grants read, write, and
72 execute permissions, respectively.
73
74 The check is done using the calling process's
75 .I real
76 UID and GID, rather than the effective IDs as is done when
77 actually attempting an operation (e.g.,
78 .BR open (2))
79 on the file.
80 This allows set-user-ID programs to
81 easily determine the invoking user's authority.
82
83 If the calling process is privileged (i.e., its real UID is zero),
84 then an
85 .B X_OK
86 check is successful for a regular file if execute permission
87 is enabled for any of the file owner, group, or other.
88 .SH "RETURN VALUE"
89 On success (all requested permissions granted, or
90 .I mode
91 is
92 .B F_OK
93 and the file exists), zero is returned.
94 On error (at least one bit in
95 .I mode
96 asked for a permission that is denied, or
97 .I mode
98 is
99 .B F_OK
100 and the file does not exist, or some other error occurred),
101 \-1 is returned, and
102 .I errno
103 is set appropriately.
104 .SH ERRORS
105 .BR access ()
106 shall fail if:
107 .TP
108 .B EACCES
109 The requested access would be denied to the file, or search permission
110 is denied for one of the directories in the path prefix of
111 .IR pathname .
112 (See also
113 .BR path_resolution (7).)
114 .TP
115 .B ELOOP
116 Too many symbolic links were encountered in resolving
117 .IR pathname .
118 .TP
119 .B ENAMETOOLONG
120 .I pathname
121 is too long.
122 .TP
123 .B ENOENT
124 A component of
125 .I pathname
126 does not exist or is a dangling 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 file system.
135 .PP
136 .BR 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 "CONFORMING TO"
157 SVr4, 4.3BSD, POSIX.1-2001.
158 .SH NOTES
159 .PP
160 .BR Warning :
161 Using
162 .BR access ()
163 to check if a user is authorized to, for example,
164 open a file before actually doing so using
165 .BR open (2)
166 creates a security hole, because the user might exploit the short time
167 interval between checking and opening the file to manipulate it.
168 .BR "For this reason, the use of this system call should be avoided" .
169 (In the example just described,
170 a safer alternative would be to temporarily switch the process's
171 effective user ID to the real ID and then call
172 .BR open (2).)
173 .PP
174 .BR access ()
175 always dereferences symbolic links.
176 If you need to check the permissions on a symbolic link, use
177 .BR faccessat (2)
178 with the flag
179 .BR AT_SYMLINK_NOFOLLOW .
180 .PP
181 .BR access ()
182 returns an error if any of the access types in
183 .I mode
184 is denied, even if some of the other access types in
185 .I mode
186 are permitted.
187 .PP
188 If the calling process has appropriate privileges (i.e., is superuser),
189 POSIX.1-2001 permits an implementation to indicate success for an
190 .B X_OK
191 check even if none of the execute file permission bits are set.
192 .\" HPU-UX 11 and Tru64 5.1 do this.
193 Linux does not do this.
194 .PP
195 A file is accessible only if the permissions on each of the
196 directories in the path prefix of
197 .I pathname
198 grant search (i.e., execute) access.
199 If any directory is inaccessible, then the
200 .BR access ()
201 call will fail, regardless of the permissions on the file itself.
202 .PP
203 Only access bits are checked, not the file type or contents.
204 Therefore, if a directory is found to be writable,
205 it probably means that files can be created in the directory,
206 and not that the directory can be written as a file.
207 Similarly, a DOS file may be found to be "executable," but the
208 .BR execve (2)
209 call will still fail.
210 .PP
211 .BR access ()
212 may not work correctly on NFS file systems with UID mapping enabled,
213 because UID mapping is done on the server and hidden from the client,
214 which checks permissions.
215 Similar problems can occur to FUSE mounts.
216 .SH BUGS
217 In kernel 2.4 (and earlier) there is some strangeness in the handling of
218 .B X_OK
219 tests for superuser.
220 If all categories of execute permission are disabled
221 for a nondirectory file, then the only
222 .BR access ()
223 test that returns \-1 is when
224 .I mode
225 is specified as just
226 .BR X_OK ;
227 if
228 .B R_OK
229 or
230 .B W_OK
231 is also specified in
232 .IR mode ,
233 then
234 .BR access ()
235 returns 0 for such files.
236 .\" This behavior appears to have been an implementation accident.
237 Early 2.6 kernels (up to and including 2.6.3)
238 also behaved in the same way as kernel 2.4.
239
240 In kernels before 2.6.20,
241 .BR access ()
242 ignored the effect of the
243 .B MS_NOEXEC
244 flag if it was used to
245 .BR mount (2)
246 the underlying file system.
247 Since kernel 2.6.20,
248 .BR access ()
249 honors this flag.
250 .SH "SEE ALSO"
251 .BR chmod (2),
252 .BR chown (2),
253 .BR faccessat (2),
254 .BR open (2),
255 .BR setgid (2),
256 .BR setuid (2),
257 .BR stat (2),
258 .BR euidaccess (3),
259 .BR credentials (7),
260 .BR path_resolution (7)