xref: /openbsd-src/lib/libc/sys/access.2 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: access.2,v 1.15 2008/06/10 16:37:57 otto Exp $
2.\"	$NetBSD: access.2,v 1.7 1995/02/27 12:31:44 cgd Exp $
3.\"
4.\" Copyright (c) 1980, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)access.2	8.2 (Berkeley) 4/1/94
32.\"
33.Dd $Mdocdate: June 10 2008 $
34.Dt ACCESS 2
35.Os
36.Sh NAME
37.Nm access
38.Nd check access permissions of a file or pathname
39.Sh SYNOPSIS
40.Fd #include <unistd.h>
41.Ft int
42.Fn access "const char *path" "int mode"
43.Sh DESCRIPTION
44The
45.Fn access
46function checks the accessibility of the file named by
47.Fa path
48for the access permissions indicated by
49.Fa mode .
50The value of
51.Fa mode
52is the bitwise inclusive
53.Tn OR
54of the access permissions to be checked
55.Pf ( Dv R_OK
56for read permission,
57.Dv W_OK
58for write permission, and
59.Dv X_OK
60for execute/search permission) or the existence test,
61.Dv F_OK .
62All components of the pathname
63.Fa path
64are checked for access permissions (including
65.Dv F_OK ) .
66.Pp
67The real user ID is used in place of the effective user ID
68and the real group access list
69(including the real group ID) is
70used in place of the effective ID for verifying permission.
71.Pp
72If the invoking process has superuser privileges,
73.Fn access
74will always indicate success for
75.Dv R_OK
76and
77.Dv W_OK ,
78regardless of the actual file permission bits.
79Likewise, for
80.Dv X_OK ,
81if the file has any of the execute bits set and
82.Fa path
83is not a directory,
84.Fn access
85will indicate success.
86.Sh RETURN VALUES
87If
88.Fa path
89cannot be found or if any of the desired access modes would not be granted,
90then a \-1 value is returned; otherwise a 0 value is returned.
91.Sh ERRORS
92Access to the file is denied if:
93.Bl -tag -width Er
94.It Bq Er ENOTDIR
95A component of the path prefix is not a directory.
96.It Bq Er ENAMETOOLONG
97A component of a pathname exceeded
98.Dv {NAME_MAX}
99characters, or an entire path name exceeded
100.Dv {PATH_MAX}
101characters.
102.It Bq Er ENOENT
103The named file does not exist.
104.It Bq Er ELOOP
105Too many symbolic links were encountered in translating the pathname.
106.It Bq Er EROFS
107Write access is requested for a file on a read-only file system.
108.It Bq Er ETXTBSY
109Write access is requested for a pure procedure (shared text)
110file presently being executed.
111.It Bq Er EACCES
112Permission bits of the file mode do not permit the requested access,
113or search permission is denied on a component of the path prefix.
114The owner of a file has permission checked with respect to the
115.Dq owner
116read, write, and execute mode bits, members of the file's group other
117than the owner have permission checked with respect to the
118.Dq group
119mode bits, and all others have permissions checked with respect to the
120.Dq other
121mode bits.
122.It Bq Er EPERM
123Write access has been requested and the named file has its immutable
124flag set (see
125.Xr chflags 2 ) .
126.It Bq Er EFAULT
127.Fa path
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.It Bq Er EINVAL
132An invalid value was specified for
133.Ar mode .
134.El
135.Sh SEE ALSO
136.Xr chmod 2 ,
137.Xr stat 2
138.Sh STANDARDS
139The
140.Fn access
141function conforms to
142.St -p1003.1-90 .
143.Sh CAVEATS
144.Fn access
145should never be used for actual access control.
146Doing so can result in a time of check vs. time of use security hole.
147