1.\" $NetBSD: access.2,v 1.26 2010/05/03 05:53:56 jruoho 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. 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. 17.\" 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 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)access.2 8.2 (Berkeley) 4/1/94 31.\" 32.Dd May 3, 2010 33.Dt ACCESS 2 34.Os 35.Sh NAME 36.Nm access 37.Nd check access permissions of a file or pathname 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.In unistd.h 42.Ft int 43.Fn access "const char *path" "int mode" 44.Sh DESCRIPTION 45The 46.Fn access 47function checks the accessibility of the 48file named by 49.Fa path 50for the access permissions indicated by 51.Fa mode . 52The value of 53.Fa mode 54is the bitwise inclusive OR of the access permissions to be 55checked 56.Pf ( Dv R_OK 57for read permission, 58.Dv W_OK 59for write permission and 60.Dv X_OK 61for execute/search permission) or the existence test, 62.Dv F_OK . 63All components of the pathname 64.Fa path 65are checked for access permissions (including 66.Dv F_OK ) . 67.Pp 68The real user ID is used in place of the effective user ID 69and the real group access list 70(including the real group ID) are 71used in place of the effective ID for verifying permission. 72.Pp 73If a process has super-user privileges and indicates success for 74.Dv R_OK 75or 76.Dv W_OK , 77the file may not actually have read or write permission bits set. 78If a process has super-user privileges and indicates success for 79.Dv X_OK , 80at least one of the user, group, or other execute bits is set. 81(However, the file may still not be executable. 82See 83.Xr execve 2 . ) 84.Sh RETURN VALUES 85If 86.Fa path 87cannot be found or if any of the desired access modes would 88not be granted, then a \-1 value is returned; otherwise 89a 0 value is returned. 90.Sh ERRORS 91Access to the file is denied if: 92.Bl -tag -width Er 93.It Bq Er EACCES 94Permission bits of the file mode do not permit the requested 95access, or search permission is denied on a component of the 96path prefix. 97The owner of a file has permission checked with respect to the 98.Dq owner 99read, write, and execute mode bits, members of the file's group 100other than the owner have permission checked with respect to the 101.Dq group 102mode bits, and all others have permissions checked with respect to 103the 104.Dq other 105mode bits. 106.It Bq Er EFAULT 107.Fa path 108points outside the process's allocated address space. 109.It Bq Er EIO 110An I/O error occurred while reading from or writing to the file system. 111.It Bq Er ELOOP 112Too many symbolic links were encountered in translating the pathname. 113.It Bq Er ENAMETOOLONG 114A component of a pathname exceeded 115.Brq Dv NAME_MAX 116characters, or an entire path name exceeded 117.Brq Dv PATH_MAX 118characters. 119.It Bq Er ENOENT 120The named file does not exist. 121.It Bq Er ENOTDIR 122A component of the path prefix is not a directory. 123.It Bq Er EROFS 124Write access is requested for a file on a read-only file system. 125.It Bq Er ETXTBSY 126Write access is requested for a pure procedure (shared text) 127file presently being executed. 128.El 129.Sh SEE ALSO 130.Xr chmod 2 , 131.Xr execve 2 , 132.Xr stat 2 , 133.Xr secure_path 3 134.Sh STANDARDS 135The 136.Fn access 137function conforms to 138.St -p1003.1-90 . 139.Sh SECURITY CONSIDERATIONS 140The 141.Fn access 142system call is a potential security hole due to race conditions. 143It should never be used. 144Set-user-ID and set-group-ID applications should restore the 145effective user or group ID, and perform actions directly rather than use 146.Fn access 147to simulate access checks for the real user or group ID. 148.Pp 149The 150.Fn access 151system call may however have some value in providing clues to users as to 152whether certain operations make sense for a particular filesystem object. 153Arguably it also allows a cheaper file existence test than 154.Xr stat 2 . 155