1 .\" $NetBSD: access.2,v 1.26 2010/05/03 05:53:56 jruoho Exp $
3 .\" Copyright (c) 1980, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)access.2 8.2 (Berkeley) 4/1/94
37 .Nd check access permissions of a file or pathname
43 .Fn access "const char *path" "int mode"
47 function checks the accessibility of the
50 for the access permissions indicated by
54 is the bitwise inclusive OR of the access permissions to be
59 for write permission and
61 for execute/search permission) or the existence test,
63 All components of the pathname
65 are checked for access permissions (including
68 The real user ID is used in place of the effective user ID
69 and the real group access list
70 (including the real group ID) are
71 used in place of the effective ID for verifying permission.
73 If a process has super-user privileges and indicates success for
77 the file may not actually have read or write permission bits set.
78 If a process has super-user privileges and indicates success for
80 at least one of the user, group, or other execute bits is set.
81 (However, the file may still not be executable.
87 cannot be found or if any of the desired access modes would
88 not be granted, then a \-1 value is returned; otherwise
89 a 0 value is returned.
91 Access to the file is denied if:
94 Permission bits of the file mode do not permit the requested
95 access, or search permission is denied on a component of the
97 The owner of a file has permission checked with respect to the
99 read, write, and execute mode bits, members of the file's group
100 other than the owner have permission checked with respect to the
102 mode bits, and all others have permissions checked with respect to
108 points outside the process's allocated address space.
110 An I/O error occurred while reading from or writing to the file system.
112 Too many symbolic links were encountered in translating the pathname.
113 .It Bq Er ENAMETOOLONG
114 A component of a pathname exceeded
116 characters, or an entire path name exceeded
120 The named file does not exist.
122 A component of the path prefix is not a directory.
124 Write access is requested for a file on a read-only file system.
126 Write access is requested for a pure procedure (shared text)
127 file presently being executed.
139 .Sh SECURITY CONSIDERATIONS
142 system call is a potential security hole due to race conditions.
143 It should never be used.
144 Set-user-ID and set-group-ID applications should restore the
145 effective user or group ID, and perform actions directly rather than use
147 to simulate access checks for the real user or group ID.
151 system call may however have some value in providing clues to users as to
152 whether certain operations make sense for a particular filesystem object.
153 Arguably it also allows a cheaper file existence test than