File: access.2

package info (click to toggle)
manpages 1.29-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,796 kB
  • ctags: 5
  • sloc: sh: 79; makefile: 61
file content (161 lines) | stat: -rw-r--r-- 5,219 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
.\"                               1993 Michael Haardt, Ian Jackson.
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\" 
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\" 
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified Wed Jul 21 19:36:29 1993, Rik Faith (faith@cs.unc.edu)
.\" Modified 21 Aug 1994 by Michael Chastain (mec@shell.portal.com):
.\"   Removed note about old kernel (pre-1.1.44) using wrong id on path.
.\" Modified 18 Mar 1996 by Martin Schulze (joey@infodrom.north.de):
.\"   Stated more clearly how it behaves with symbolic links.
.\" Added correction due to Nick Duffek (nsd@bbc.com), aeb, 960426
.\" Modified Sat Sep 07 18:17:26 MET DST 1996 by Michael Haardt:
.\"   Restrictions for NFS
.\" Modified by Joseph S. Myers <jsm28@cam.ac.uk>, 970909
.\" Modified Tue Jan 13 21:21:03 MET 1998 by Michael Haardt:
.\"   Using access is often insecure
.\"
.TH ACCESS 2 "January 13, 1998" "Linux" "System calls"
.SH NAME
access \- check user's permissions for a file
.SH SYNOPSIS
.nf
.B #include <unistd.h>
.sp
.BI "int access(const char *" pathname ", int " mode );
.fi
.SH DESCRIPTION
.B access
checks whether the process would be allowed to read,
write or test for existence of the file (or other file system
object) whose name is
.IR pathname .
If
.I pathname
is a symbolic link permissions of the file referred to by this
symbolic link are tested.

.I mode
is a mask consisting of one or more of
.BR R_OK ", " W_OK ", " X_OK " and " F_OK .

.BR R_OK ", " W_OK " and " X_OK
request checking whether the file exists and has read, write and
execute permissions, respectively.
.B F_OK
just requests checking for the existence of the file.

The tests depend on the permissions of the directories
occurring in the path to the file, as given in
.IR pathname ,
and on the permissions of directories and files referred to by symbolic
links encountered on the way.

The check is done with the process's
.I real
uid and gid, rather than with the effective ids as is done when
actually attempting an operation.  This is to allow set-UID programs to
easily determine the invoking user's authority.

Only access bits are checked, not the file type or contents.  Therefore, if
a directory is found to be "writable," it probably means that files can be
created in the directory, and not that the directory can be written as a
file.  Similarly, a DOS file may be found to be "executable," but the
.BR execve (2)
call will still fail.
.SH "RETURN VALUE"
On success (all requested permissions granted), zero is returned.
On error (at least one bit in
.I mode
asked for a permission that is denied, or some other error occurred),
\-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EACCES
The requested access would be denied to the file or search permission
is denied to one of the directories in
.IR pathname .
.TP
.B EROFS
Write permission was requested for a file on a read-only filesystem.
.TP
.B EFAULT
.I pathname
points outside your accessible address space.
.TP
.B EINVAL
.I mode
was incorrectly specified.
.TP
.B ENAMETOOLONG
.I pathname
is too long.
.TP
.B ENOENT
A directory component in
.I pathname
would have been accessible but does not exist or was a dangling
symbolic link.
.TP
.B ENOTDIR
A component used as a directory in
.I pathname
is not, in fact, a directory.
.TP
.B ENOMEM
Insufficient kernel memory was available.
.TP
.B ELOOP
Too many symbolic links were encountered in resolving
.IR pathname .
.TP
.B EIO
An I/O error occurred.
.SH RESTRICTIONS
.B access
returns an error if any of the access types in the requested call
fails, even if other types might be successful.
.PP
.B access
may not work correctly on NFS file systems with UID mapping enabled,
because UID mapping is done on the server and hidden from the client,
which checks permissions.
.PP
Using
.B access
to check if a user is authorized to e.g. open a file before actually
doing so using
.BR open (2)
creates a security hole, because the user might exploit the short time
interval between checking and opening the file to manipulate it.
.SH "CONFORMING TO"
SVID, AT&T, POSIX, X/OPEN, BSD 4.3
.SH "SEE ALSO"
.BR stat (2),
.BR open (2),
.BR chmod (2),
.BR chown (2),
.BR setuid (2),
.BR setgid (2)