1.\" $NetBSD: chown.2,v 1.11 1997/04/30 19:35:33 kleink Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993, 1994 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.\" @(#)chown.2 8.4 (Berkeley) 4/19/94 35.\" 36.Dd April 19, 1994 37.Dt CHOWN 2 38.Os BSD 4 39.Sh NAME 40.Nm chown , 41.Nm fchown 42.Nd change owner and group of a file 43.Sh SYNOPSIS 44.Fd #include <sys/types.h> 45.Fd #include <unistd.h> 46.Ft int 47.Fn chown "const char *path" "uid_t owner" "gid_t group" 48.Ft int 49.Fn fchown "int fd" "uid_t owner" "gid_t group" 50.Sh DESCRIPTION 51The owner ID and group ID of the file 52named by 53.Fa path 54or referenced by 55.Fa fd 56is changed as specified by the arguments 57.Fa owner 58and 59.Fa group . 60The owner of a file may change the 61.Fa group 62to a group of which 63he or she is a member, 64but the change 65.Fa owner 66capability is restricted to the super-user. 67.Pp 68.Fn Chown 69and 70.Fn fchown 71clear the set-user-id and set-group-id bits 72on the file 73to prevent accidental or mischievous creation of 74set-user-id and set-group-id programs. 75.Pp 76.Fn Fchown 77is particularly useful when used in conjunction 78with the file locking primitives (see 79.Xr flock 2 ) . 80.Pp 81One of the owner or group id's 82may be left unchanged by specifying it as -1. 83.Sh RETURN VALUES 84Zero is returned if the operation was successful; 85-1 is returned if an error occurs, with a more specific 86error code being placed in the global variable 87.Va errno . 88.Sh ERRORS 89.Fn Chown 90will fail and the file will be unchanged if: 91.Bl -tag -width Er 92.It Bq Er ENOTDIR 93A component of the path prefix is not a directory. 94.It Bq Er ENAMETOOLONG 95A component of a pathname exceeded 96.Dv {NAME_MAX} 97characters, or an entire path name exceeded 98.Dv {PATH_MAX} 99characters. 100.It Bq Er ENOENT 101The named file does not exist. 102.It Bq Er EACCES 103Search permission is denied for a component of the path prefix. 104.It Bq Er ELOOP 105Too many symbolic links were encountered in translating the pathname. 106.It Bq Er EPERM 107The effective user ID is not the super-user. 108.It Bq Er EROFS 109The named file resides on a read-only file system. 110.It Bq Er EFAULT 111.Fa Path 112points outside the process's allocated address space. 113.It Bq Er EIO 114An I/O error occurred while reading from or writing to the file system. 115.El 116.Pp 117.Fn Fchown 118will fail if: 119.Bl -tag -width Er 120.It Bq Er EBADF 121.Fa Fd 122does not refer to a valid descriptor. 123.It Bq Er EINVAL 124.Fa Fd 125refers to a socket, not a file. 126.It Bq Er EPERM 127The effective user ID is not the super-user. 128.It Bq Er EROFS 129The named file resides on a read-only file system. 130.It Bq Er EIO 131An I/O error occurred while reading from or writing to the file system. 132.El 133.Sh SEE ALSO 134.Xr chown 8 , 135.Xr chgrp 1 , 136.Xr chmod 2 , 137.Xr flock 2 138.Sh STANDARDS 139The 140.Fn chown 141function conforms to 142.St -p1003.1-88 . 143.Sh HISTORY 144The 145.Fn fchown 146function call appeared in 147.Bx 4.2 . 148.Pp 149The 150.Fn chown 151and 152.Fn fchown 153functions were changed to follow symbolic links in 154.Bx 4.4 . 155