]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libc/sys/access.2
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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 .\" 4. 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 11, 2008
32 .Dt ACCESS 2
33 .Os
34 .Sh NAME
35 .Nm access , eaccess
36 .Nd check accessibility of a file
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In unistd.h
41 .Ft int
42 .Fn access "const char *path" "int mode"
43 .Ft int
44 .Fn eaccess "const char *path" "int mode"
45 .Sh DESCRIPTION
46 The
47 .Fn access
48 and
49 .Fn eaccess
50 system calls check the accessibility of the
51 file named by
52 the
53 .Fa path
54 argument
55 for the access permissions indicated by
56 the
57 .Fa mode
58 argument.
59 The value of
60 .Fa mode
61 is either the bitwise-inclusive OR of the access permissions to be
62 checked
63 .Dv ( R_OK
64 for read permission,
65 .Dv W_OK
66 for write permission, and
67 .Dv X_OK
68 for execute/search permission),
69 or the existence test
70 .Pq Dv F_OK .
71 .Pp
72 For additional information, see the
73 .Sx "File Access Permission"
74 section of
75 .Xr intro 2 .
76 .Pp
77 The
78 .Fn eaccess
79 system call uses
80 the effective user ID and the group access list
81 to authorize the request;
82 the
83 .Fn access
84 system call uses
85 the real user ID in place of the effective user ID,
86 the real group ID in place of the effective group ID,
87 and the rest of the group access list.
88 .Pp
89 Even if a process's real or effective user has appropriate privileges
90 and indicates success for
91 .Dv X_OK ,
92 the file may not actually have execute permission bits set.
93 Likewise for
94 .Dv R_OK
95 and
96 .Dv W_OK .
97 .Sh RETURN VALUES
98 .Rv -std
99 .Sh ERRORS
100 Access to the file is denied if:
101 .Bl -tag -width Er
102 .It Bq Er ENOTDIR
103 A component of the path prefix is not a directory.
104 .It Bq Er ENAMETOOLONG
105 A component of a pathname exceeded 255 characters,
106 or an entire path name exceeded 1023 characters.
107 .It Bq Er ENOENT
108 The named file does not exist.
109 .It Bq Er ELOOP
110 Too many symbolic links were encountered in translating the pathname.
111 .It Bq Er EROFS
112 Write access is requested for a file on a read-only file system.
113 .It Bq Er ETXTBSY
114 Write access is requested for a pure procedure (shared text)
115 file presently being executed.
116 .It Bq Er EACCES
117 Permission bits of the file mode do not permit the requested
118 access, or search permission is denied on a component of the
119 path prefix.
120 .It Bq Er EFAULT
121 The
122 .Fa path
123 argument
124 points outside the process's allocated address space.
125 .It Bq Er EIO
126 An I/O error occurred while reading from or writing to the file system.
127 .El
128 .Sh SECURITY CONSIDERATIONS
129 The
130 .Fn access
131 system call
132 is a potential security hole due to race conditions and
133 should never be used.
134 Set-user-ID and set-group-ID applications should restore the
135 effective user or group ID,
136 and perform actions directly rather than use
137 .Fn access
138 to simulate access checks for the real user or group ID.
139 The
140 .Fn eaccess
141 system call
142 likewise may be subject to races if used inappropriately.
143 .Pp
144 .Fn access
145 remains useful for providing clues to users as to whether operations
146 make sense for particular filesystem objects (e.g. 'delete' menu
147 item only highlighted in a writable folder ... avoiding interpretation
148 of the st_mode bits that the application might not understand --
149 e.g. in the case of AFS).
150 It also allows a cheaper file existence test than
151 .Xr stat 2 .
152 .Sh SEE ALSO
153 .Xr chmod 2 ,
154 .Xr intro 2 ,
155 .Xr stat 2
156 .Sh STANDARDS
157 The
158 .Fn access
159 system call is expected to conform to
160 .St -p1003.1-90 .
161 .Sh HISTORY
162 The
163 .Fn access
164 function appeared in
165 .At v7 .