1.\" $NetBSD: access.2,v 1.17 2002/10/01 18:10:43 wiz Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 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. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)access.2 8.2 (Berkeley) 4/1/94 35.\" 36.Dd April 1, 1994 37.Dt ACCESS 2 38.Os 39.Sh NAME 40.Nm access 41.Nd check access permissions of a file or pathname 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.Fd #include \*[Lt]unistd.h\*[Gt] 46.Ft int 47.Fn access "const char *path" "int mode" 48.Sh DESCRIPTION 49The 50.Fn access 51function checks the accessibility of the 52file named by 53.Fa path 54for the access permissions indicated by 55.Fa mode . 56The value of 57.Fa mode 58is the bitwise inclusive OR of the access permissions to be 59checked 60.Pf ( Dv R_OK 61for read permission, 62.Dv W_OK 63for write permission and 64.Dv X_OK 65for execute/search permission) or the existence test, 66.Dv F_OK . 67All components of the pathname 68.Fa path 69are checked for access permissions (including 70.Dv F_OK ) . 71.Pp 72The real user ID is used in place of the effective user ID 73and the real group access list 74(including the real group ID) are 75used in place of the effective ID for verifying permission. 76.Pp 77If a process has super-user privileges and indicates success for 78.Dv R_OK 79or 80.Dv W_OK . 81the file may not actually have read or write permission bits set. 82If a process has super-user privileges and indicates success for 83.Dv X_OK , 84at least one of the user, group, or other execute bits is set. 85(However, the file may still not be executable. 86See 87.Xr execve 2 . ) 88.Sh RETURN VALUES 89If 90.Fa path 91cannot be found or if any of the desired access modes would 92not be granted, then a -1 value is returned; otherwise 93a 0 value is returned. 94.Sh ERRORS 95Access to the file is denied if: 96.Bl -tag -width Er 97.It Bq Er ENOTDIR 98A component of the path prefix is not a directory. 99.It Bq Er ENAMETOOLONG 100A component of a pathname exceeded 101.Dv {NAME_MAX} 102characters, or an entire path name exceeded 103.Dv {PATH_MAX} 104characters. 105.It Bq Er ENOENT 106The named file does not exist. 107.It Bq Er ELOOP 108Too many symbolic links were encountered in translating the pathname. 109.It Bq Er EROFS 110Write access is requested for a file on a read-only file system. 111.It Bq Er ETXTBSY 112Write access is requested for a pure procedure (shared text) 113file presently being executed. 114.It Bq Er EACCES 115Permission bits of the file mode do not permit the requested 116access, or search permission is denied on a component of the 117path prefix. 118The owner of a file has permission checked with 119respect to the ``owner'' read, write, and execute mode bits, 120members of the file's group other than the owner have permission 121checked with respect to the ``group'' mode bits, and all 122others have permissions checked with respect to the ``other'' 123mode bits. 124.It Bq Er EFAULT 125.Fa path 126points outside the process's allocated address space. 127.It Bq Er EIO 128An I/O error occurred while reading from or writing to the file system. 129.El 130.Sh SEE ALSO 131.Xr chmod 2 , 132.Xr execve 2 , 133.Xr stat 2 134.Sh STANDARDS 135The 136.Fn access 137function conforms to 138.St -p1003.1-90 . 139.Sh BUGS 140.Fn access 141is a potential security hole and 142should never be used. 143