]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/access.2
open(2): Remove O_BENEATH and AT_BENEATH
[FreeBSD/FreeBSD.git] / lib / libc / sys / access.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)access.2    8.2 (Berkeley) 4/1/94
29 .\" $FreeBSD$
30 .\"
31 .Dd February 23, 2021
32 .Dt ACCESS 2
33 .Os
34 .Sh NAME
35 .Nm access ,
36 .Nm eaccess ,
37 .Nm faccessat
38 .Nd check accessibility of a file
39 .Sh LIBRARY
40 .Lb libc
41 .Sh SYNOPSIS
42 .In unistd.h
43 .Ft int
44 .Fn access "const char *path" "int mode"
45 .Ft int
46 .Fn eaccess "const char *path" "int mode"
47 .Ft int
48 .Fn faccessat "int fd" "const char *path" "int mode" "int flag"
49 .Sh DESCRIPTION
50 The
51 .Fn access
52 and
53 .Fn eaccess
54 system calls check the accessibility of the
55 file named by
56 the
57 .Fa path
58 argument
59 for the access permissions indicated by
60 the
61 .Fa mode
62 argument.
63 The value of
64 .Fa mode
65 is either the bitwise-inclusive OR of the access permissions to be
66 checked
67 .Dv ( R_OK
68 for read permission,
69 .Dv W_OK
70 for write permission, and
71 .Dv X_OK
72 for execute/search permission),
73 or the existence test
74 .Pq Dv F_OK .
75 .Pp
76 For additional information, see the
77 .Sx "File Access Permission"
78 section of
79 .Xr intro 2 .
80 .Pp
81 The
82 .Fn eaccess
83 system call uses
84 the effective user ID and the group access list
85 to authorize the request;
86 the
87 .Fn access
88 system call uses
89 the real user ID in place of the effective user ID,
90 the real group ID in place of the effective group ID,
91 and the rest of the group access list.
92 .Pp
93 The
94 .Fn faccessat
95 system call is equivalent to
96 .Fn access
97 except in the case where
98 .Fa path
99 specifies a relative path.
100 In this case the file whose accessibility is to be determined is
101 located relative to the directory associated with the file descriptor
102 .Fa fd
103 instead of the current working directory.
104 If
105 .Fn faccessat
106 is passed the special value
107 .Dv AT_FDCWD
108 in the
109 .Fa fd
110 parameter, the current working directory is used and the behavior is
111 identical to a call to
112 .Fn access .
113 Values for
114 .Fa flag
115 are constructed by a bitwise-inclusive OR of flags from the following
116 list, defined in
117 .In fcntl.h :
118 .Bl -tag -width indent
119 .It Dv AT_EACCESS
120 The checks for accessibility are performed using the effective user and group
121 IDs instead of the real user and group ID as required in a call to
122 .Fn access .
123 .It Dv AT_RESOLVE_BENEATH
124 Only walk paths below the directory specified by the
125 .Ar fd
126 descriptor.
127 See the description of the
128 .Dv O_RESOLVE_BENEATH
129 flag in the
130 .Xr open 2
131 manual page.
132 .El
133 .Pp
134 Even if a process's real or effective user has appropriate privileges
135 and indicates success for
136 .Dv X_OK ,
137 the file may not actually have execute permission bits set.
138 Likewise for
139 .Dv R_OK
140 and
141 .Dv W_OK .
142 .Sh RETURN VALUES
143 .Rv -std
144 .Sh ERRORS
145 .Fn access ,
146 .Fn eaccess ,
147 or
148 .Fn faccessat
149 will fail if:
150 .Bl -tag -width Er
151 .It Bq Er EINVAL
152 The value of the
153 .Fa mode
154 argument is invalid.
155 .It Bq Er ENOTDIR
156 A component of the path prefix is not a directory.
157 .It Bq Er ENAMETOOLONG
158 A component of a pathname exceeded 255 characters,
159 or an entire path name exceeded 1023 characters.
160 .It Bq Er ENOENT
161 The named file does not exist.
162 .It Bq Er ELOOP
163 Too many symbolic links were encountered in translating the pathname.
164 .It Bq Er EROFS
165 Write access is requested for a file on a read-only file system.
166 .It Bq Er ETXTBSY
167 Write access is requested for a pure procedure (shared text)
168 file presently being executed.
169 .It Bq Er EACCES
170 Permission bits of the file mode do not permit the requested
171 access, or search permission is denied on a component of the
172 path prefix.
173 .It Bq Er EFAULT
174 The
175 .Fa path
176 argument
177 points outside the process's allocated address space.
178 .It Bq Er EIO
179 An I/O error occurred while reading from or writing to the file system.
180 .It Bq Er EINTEGRITY
181 Corrupted data was detected while reading from the file system.
182 .El
183 .Pp
184 Also, the
185 .Fn faccessat
186 system call may fail if:
187 .Bl -tag -width Er
188 .It Bq Er EBADF
189 The
190 .Fa path
191 argument does not specify an absolute path and the
192 .Fa fd
193 argument is
194 neither
195 .Dv AT_FDCWD
196 nor a valid file descriptor.
197 .It Bq Er EINVAL
198 The value of the
199 .Fa flag
200 argument is not valid.
201 .It Bq Er ENOTDIR
202 The
203 .Fa path
204 argument is not an absolute path and
205 .Fa fd
206 is neither
207 .Dv AT_FDCWD
208 nor a file descriptor associated with a directory.
209 .It Bq Er ENOTCAPABLE
210 .Fa path
211 is an absolute path,
212 or contained a ".." component leading to a
213 directory outside of the directory hierarchy specified by
214 .Fa fd ,
215 and the process is in capability mode.
216 .El
217 .Sh SEE ALSO
218 .Xr chmod 2 ,
219 .Xr intro 2 ,
220 .Xr stat 2
221 .Sh STANDARDS
222 The
223 .Fn access
224 system call is expected to conform to
225 .St -p1003.1-90 .
226 The
227 .Fn faccessat
228 system call follows The Open Group Extended API Set 2 specification.
229 .Sh HISTORY
230 The
231 .Fn access
232 function appeared in
233 .At v7 .
234 The
235 .Fn faccessat
236 system call appeared in
237 .Fx 8.0 .
238 .Sh SECURITY CONSIDERATIONS
239 The
240 .Fn access
241 system call
242 is a potential security hole due to race conditions and
243 should never be used.
244 Set-user-ID and set-group-ID applications should restore the
245 effective user or group ID,
246 and perform actions directly rather than use
247 .Fn access
248 to simulate access checks for the real user or group ID.
249 The
250 .Fn eaccess
251 system call
252 likewise may be subject to races if used inappropriately.
253 .Pp
254 .Fn access
255 remains useful for providing clues to users as to whether operations
256 make sense for particular filesystem objects (e.g. 'delete' menu
257 item only highlighted in a writable folder ... avoiding interpretation
258 of the st_mode bits that the application might not understand --
259 e.g. in the case of AFS).
260 It also allows a cheaper file existence test than
261 .Xr stat 2 .