1.\" $OpenBSD: chroot.2,v 1.11 2003/06/02 20:18:39 millert Exp $ 2.\" $NetBSD: chroot.2,v 1.7 1995/02/27 12:32:12 cgd Exp $ 3.\" 4.\" Copyright (c) 1983, 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.\" @(#)chroot.2 8.1 (Berkeley) 6/4/93 32.\" 33.Dd June 4, 1993 34.Dt CHROOT 2 35.Os 36.Sh NAME 37.Nm chroot 38.Nd change root directory 39.Sh SYNOPSIS 40.Fd #include <unistd.h> 41.Ft int 42.Fn chroot "const char *dirname" 43.Sh DESCRIPTION 44.Fa dirname 45is the address of the pathname of a directory, terminated by an 46.Tn ASCII 47NUL. 48.Fn chroot 49causes 50.Fa dirname 51to become the root directory, that is, the starting point for path 52searches of pathnames beginning with 53.Ql / . 54.Pp 55In order for a directory to become the root directory 56a process must have execute (search) access for that directory. 57.Pp 58If the program is not currently running with an altered root directory, 59it should be noted that 60.Fn chroot 61has no effect on the process's current directory. 62.Pp 63If the program is already running with an altered root directory, the 64process's current directory is changed to the same new root directory. 65This prevents the current directory from being further up the directory 66tree than the altered root directory. 67.Pp 68This call is restricted to the superuser. 69.Sh RETURN VALUES 70Upon successful completion, a value of 0 is returned. 71Otherwise, a value of \-1 is returned and 72.Va errno 73is set to indicate an error. 74.Sh ERRORS 75.Fn chroot 76will fail and the root directory will be unchanged if: 77.Bl -tag -width Er 78.It Bq Er ENOTDIR 79A component of the path name is not a directory. 80.It Bq Er ENAMETOOLONG 81A component of a pathname exceeded 82.Dv {NAME_MAX} 83characters, or an entire path name exceeded 84.Dv {PATH_MAX} 85characters. 86.It Bq Er ENOENT 87The named directory does not exist. 88.It Bq Er EACCES 89Search permission is denied for any component of the path name. 90.It Bq Er ELOOP 91Too many symbolic links were encountered in translating the pathname. 92.It Bq Er EFAULT 93.Fa dirname 94points outside the process's allocated address space. 95.It Bq Er EIO 96An I/O error occurred while reading from or writing to the file system. 97.El 98.Sh SEE ALSO 99.Xr chdir 2 100.Sh WARNINGS 101There are ways for a root process to escape from the chroot jail. 102.Sh HISTORY 103The 104.Fn chroot 105function call appeared in 106.Bx 4.2 . 107