]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/access.2
ffix
[thirdparty/man-pages.git] / man2 / access.2
CommitLineData
fea681da
MK
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
43access \- 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
e511ffb6 51.BR access ()
fea681da
MK
52checks whether the process would be allowed to read,
53write or test for existence of the file (or other file system
54object) whose name is
55.IR pathname .
56If
57.I pathname
58is a symbolic link permissions of the file referred to by this
59symbolic link are tested.
60
61.I mode
62is 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
66request checking whether the file exists and has read, write and
67execute permissions, respectively.
68.B F_OK
69just requests checking for the existence of the file.
70
71The tests depend on the permissions of the directories
72occurring in the path to the file, as given in
73.IR pathname ,
74and on the permissions of directories and files referred to by symbolic
75links encountered on the way.
76
77The check is done with the process's
78.I real
79UID and GID, rather than with the effective IDs as is done when
880f5b4b
MK
80actually attempting an operation.
81This is to allow set-user-ID programs to
fea681da
MK
82easily determine the invoking user's authority.
83
84Only access bits are checked, not the file type or contents. Therefore, if
85a directory is found to be "writable," it probably means that files can be
86created in the directory, and not that the directory can be written as a
87file. Similarly, a DOS file may be found to be "executable," but the
88.BR execve (2)
89call will still fail.
90
91If the process has appropriate privileges, an implementation may
92indicate success for
93.B X_OK
94even if none of the execute file permission bits are set.
95.SH "RETURN VALUE"
96On success (all requested permissions granted), zero is returned.
97On error (at least one bit in
98.I mode
99asked for a permission that is denied, or some other error occurred),
100\-1 is returned, and
101.I errno
102is set appropriately.
103.SH ERRORS
e511ffb6 104.BR access ()
fea681da
MK
105shall fail if:
106.TP
107.B EACCES
108The requested access would be denied to the file or search permission
109is 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
115Too many symbolic links were encountered in resolving
116.IR pathname .
117.TP
118.B ENAMETOOLONG
119.I pathname
120is too long.
121.TP
122.B ENOENT
123A directory component in
124.I pathname
125would have been accessible but does not exist or was a dangling
126symbolic link.
127.TP
128.B ENOTDIR
129A component used as a directory in
130.I pathname
131is not, in fact, a directory.
132.TP
133.B EROFS
134Write permission was requested for a file on a read-only filesystem.
135.PP
e511ffb6 136.BR access ()
fea681da
MK
137may fail if:
138.TP
139.B EFAULT
140.I pathname
141points outside your accessible address space.
142.TP
143.B EINVAL
144.I mode
145was incorrectly specified.
146.TP
147.B EIO
148An I/O error occurred.
149.TP
150.B ENOMEM
151Insufficient kernel memory was available.
152.TP
153.B ETXTBSY
154Write access was requested to an executable which is being
155executed.
dc0b1e23
MK
156.SH "LINUX NOTES"
157In kernels before 2.6.20,
158.BR access ()
159ignored the effect of the
160.B MS_NOEXEC
161flag if it was used to
162.BR mount (2)
163the underlying file system.
164Since kernel 2.6.20,
165.BR access ()
166honours this flag.
fea681da 167.SH RESTRICTIONS
e511ffb6 168.BR access ()
fea681da
MK
169returns an error if any of the access types in the requested call
170fails, even if other types might be successful.
171.PP
e511ffb6 172.BR access ()
fea681da
MK
173may not work correctly on NFS file systems with UID mapping enabled,
174because UID mapping is done on the server and hidden from the client,
175which checks permissions.
176.PP
177Using
e511ffb6 178.BR access ()
fea681da
MK
179to check if a user is authorized to e.g. open a file before actually
180doing so using
181.BR open (2)
182creates a security hole, because the user might exploit the short time
183interval between checking and opening the file to manipulate it.
184.SH "CONFORMING TO"
75b48e9d 185SVr4, 4.3BSD, POSIX.1-2001.
fea681da
MK
186.SH "SEE ALSO"
187.BR chmod (2),
188.BR chown (2),
22e3b8b1 189.BR faccessat (2),
fea681da
MK
190.BR open (2),
191.BR path_resolution (2),
192.BR setgid (2),
193.BR setuid (2),
194.BR stat (2)