1.\" Copyright (c) 1980, 1991 Regents of the University of California. 2.\" 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.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)chown.2 6.7 (Berkeley) 3/10/91 33.\" $Id: chown.2,v 1.8 1994/04/22 00:13:30 jtc Exp $ 34.\" 35.Dd March 10, 1991 36.Dt CHOWN 2 37.Os BSD 4 38.Sh NAME 39.Nm chown , 40.Nm fchown 41.Nd change owner and group of a file 42.Sh SYNOPSIS 43.Fd #include <sys/types.h> 44.Fd #include <unistd.h> 45.Ft int 46.Fn chown "const char *path" "uid_t owner" "gid_t group" 47.Ft int 48.Fn fchown "int fd" "uid_t owner" "gid_t group" 49.Sh DESCRIPTION 50The owner ID and group ID of the file 51named by 52.Fa path 53or referenced by 54.Fa fd 55is changed as specified by the arguments 56.Fa owner 57and 58.Fa group . 59The owner of a file may change the 60.Fa group 61to a group of which 62he or she is a member, 63but the change 64.Fa owner 65capability is restricted to the super-user. 66.Pp 67.Fn Chown 68clears the set-user-id and set-group-id bits 69on the file 70to prevent accidental or mischievous creation of 71set-user-id and set-group-id programs. 72.Pp 73.Fn Fchown 74is particularly useful when used in conjunction 75with the file locking primitives (see 76.Xr flock 2 ) . 77.Pp 78One of the owner or group id's 79may be left unchanged by specifying it as -1. 80.Pp 81If the final component of 82.Fa path 83is a symbolic link, 84the ownership and group of the symbolic link is changed, 85not the ownership and group of the file or directory to which it points. 86.Sh RETURN VALUES 87Zero is returned if the operation was successful; 88-1 is returned if an error occurs, with a more specific 89error code being placed in the global variable 90.Va errno . 91.Sh ERRORS 92.Fn Chown 93will fail and the file will be unchanged if: 94.Bl -tag -width Er 95.It Bq Er ENOTDIR 96A component of the path prefix is not a directory. 97.It Bq Er ENAMETOOLONG 98A component of a pathname exceeded 99.Dv {NAME_MAX} 100characters, or an entire path name exceeded 101.Dv {PATH_MAX} 102characters. 103.It Bq Er ENOENT 104The named file does not exist. 105.It Bq Er EACCES 106Search permission is denied for a component of the path prefix. 107.It Bq Er ELOOP 108Too many symbolic links were encountered in translating the pathname. 109.It Bq Er EPERM 110The effective user ID is not the super-user. 111.It Bq Er EROFS 112The named file resides on a read-only file system. 113.It Bq Er EFAULT 114.Fa Path 115points outside the process's allocated address space. 116.It Bq Er EIO 117An I/O error occurred while reading from or writing to the file system. 118.El 119.Pp 120.Fn Fchown 121will fail if: 122.Bl -tag -width Er 123.It Bq Er EBADF 124.Fa Fd 125does not refer to a valid descriptor. 126.It Bq Er EINVAL 127.Fa Fd 128refers to a socket, not a file. 129.It Bq Er EPERM 130The effective user ID is not the super-user. 131.It Bq Er EROFS 132The named file resides on a read-only file system. 133.It Bq Er EIO 134An I/O error occurred while reading from or writing to the file system. 135.El 136.Sh SEE ALSO 137.Xr chown 8 , 138.Xr chgrp 1 , 139.Xr chmod 2 , 140.Xr flock 2 141.Sh STANDARDS 142The 143.Fn chown 144function is expected to conform to 145.St -p1003.1-88 . 146.Sh HISTORY 147The 148.Fn fchown 149function call appeared in 150.Bx 4.2 . 151