xref: /freebsd-13.1/lib/libc/sys/access.2 (revision dfd1ff19)
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. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)access.2	8.2 (Berkeley) 4/1/94
33.\" $FreeBSD$
34.\"
35.Dd September 21, 2001
36.Dt ACCESS 2
37.Os
38.Sh NAME
39.Nm access , eaccess
40.Nd check accessibility of a file
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.In unistd.h
45.Ft int
46.Fn access "const char *path" "int mode"
47.Ft int
48.Fn eaccess "const char *path" "int mode"
49.Sh DESCRIPTION
50The
51.Fn access
52and
53.Fn eaccess
54system calls check the accessibility of the
55file named by
56the
57.Fa path
58argument
59for the access permissions indicated by
60the
61.Fa mode
62argument.
63The value of
64.Fa mode
65is either the bitwise-inclusive OR of the access permissions to be
66checked
67.Dv ( R_OK
68for read permission,
69.Dv W_OK
70for write permission, and
71.Dv X_OK
72for execute/search permission),
73or the existence test
74.Pq Dv F_OK .
75.Pp
76For additional information, see the
77.Sx "File Access Permission"
78section of
79.Xr intro 2 .
80.Pp
81The
82.Fn eaccess
83system call uses
84the effective user ID and the group access list
85to authorize the request;
86the
87.Fn access
88system call uses
89the real user ID in place of the effective user ID,
90the real group ID in place of the effective group ID,
91and the rest of the group access list.
92.Pp
93Even if a process's real or effective user has appropriate privileges
94and indicates success for
95.Dv X_OK ,
96the file may not actually have execute permission bits set.
97Likewise for
98.Dv R_OK
99and
100.Dv W_OK .
101.Sh RETURN VALUES
102.Rv -std
103.Sh ERRORS
104Access to the file is denied if:
105.Bl -tag -width Er
106.It Bq Er ENOTDIR
107A component of the path prefix is not a directory.
108.It Bq Er ENAMETOOLONG
109A component of a pathname exceeded 255 characters,
110or an entire path name exceeded 1023 characters.
111.It Bq Er ENOENT
112The named file does not exist.
113.It Bq Er ELOOP
114Too many symbolic links were encountered in translating the pathname.
115.It Bq Er EROFS
116Write access is requested for a file on a read-only file system.
117.It Bq Er ETXTBSY
118Write access is requested for a pure procedure (shared text)
119file presently being executed.
120.It Bq Er EACCES
121Permission bits of the file mode do not permit the requested
122access, or search permission is denied on a component of the
123path prefix.
124.It Bq Er EFAULT
125The
126.Fa path
127argument
128points outside the process's allocated address space.
129.It Bq Er EIO
130An I/O error occurred while reading from or writing to the file system.
131.El
132.Sh SECURITY CONSIDERATIONS
133The
134.Fn access
135system call
136is a potential security hole due to race conditions and
137should never be used.
138Set-user-ID and set-group-ID applications should restore the
139effective user or group ID,
140and perform actions directly rather than use
141.Fn access
142to simulate access checks for the real user or group ID.
143The
144.Fn eaccess
145system call
146likewise may be subject to races if used inappropriately.
147.Sh SEE ALSO
148.Xr chmod 2 ,
149.Xr intro 2 ,
150.Xr stat 2
151.Sh STANDARDS
152The
153.Fn access
154system call is expected to conform to
155.St -p1003.1-90 .
156.Sh HISTORY
157The
158.Fn access
159function appeared in
160.At v7 .
161