1*8269e767SBrooks Davis.\" Copyright (c) 1980, 1991, 1993, 1994 2*8269e767SBrooks Davis.\" The Regents of the University of California. All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 11*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors 13*8269e767SBrooks Davis.\" may be used to endorse or promote products derived from this software 14*8269e767SBrooks Davis.\" without specific prior written permission. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8269e767SBrooks Davis.\" SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd March 30, 2021 29*8269e767SBrooks Davis.Dt CHOWN 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm chown , 33*8269e767SBrooks Davis.Nm fchown , 34*8269e767SBrooks Davis.Nm lchown , 35*8269e767SBrooks Davis.Nm fchownat 36*8269e767SBrooks Davis.Nd change owner and group of a file 37*8269e767SBrooks Davis.Sh LIBRARY 38*8269e767SBrooks Davis.Lb libc 39*8269e767SBrooks Davis.Sh SYNOPSIS 40*8269e767SBrooks Davis.In unistd.h 41*8269e767SBrooks Davis.Ft int 42*8269e767SBrooks Davis.Fn chown "const char *path" "uid_t owner" "gid_t group" 43*8269e767SBrooks Davis.Ft int 44*8269e767SBrooks Davis.Fn fchown "int fd" "uid_t owner" "gid_t group" 45*8269e767SBrooks Davis.Ft int 46*8269e767SBrooks Davis.Fn lchown "const char *path" "uid_t owner" "gid_t group" 47*8269e767SBrooks Davis.Ft int 48*8269e767SBrooks Davis.Fn fchownat "int fd" "const char *path" "uid_t owner" "gid_t group" "int flag" 49*8269e767SBrooks Davis.Sh DESCRIPTION 50*8269e767SBrooks DavisThe owner ID and group ID of the file 51*8269e767SBrooks Davisnamed by 52*8269e767SBrooks Davis.Fa path 53*8269e767SBrooks Davisor referenced by 54*8269e767SBrooks Davis.Fa fd 55*8269e767SBrooks Davisis changed as specified by the arguments 56*8269e767SBrooks Davis.Fa owner 57*8269e767SBrooks Davisand 58*8269e767SBrooks Davis.Fa group . 59*8269e767SBrooks DavisThe owner of a file may change the 60*8269e767SBrooks Davis.Fa group 61*8269e767SBrooks Davisto a group of which 62*8269e767SBrooks Davishe or she is a member, 63*8269e767SBrooks Davisbut the change 64*8269e767SBrooks Davis.Fa owner 65*8269e767SBrooks Daviscapability is restricted to the super-user. 66*8269e767SBrooks Davis.Pp 67*8269e767SBrooks DavisThe 68*8269e767SBrooks Davis.Fn chown 69*8269e767SBrooks Davissystem call 70*8269e767SBrooks Davisclears the set-user-id and set-group-id bits 71*8269e767SBrooks Davison the file 72*8269e767SBrooks Davisto prevent accidental or mischievous creation of 73*8269e767SBrooks Davisset-user-id and set-group-id programs if not executed 74*8269e767SBrooks Davisby the super-user. 75*8269e767SBrooks DavisThe 76*8269e767SBrooks Davis.Fn chown 77*8269e767SBrooks Davissystem call 78*8269e767SBrooks Davisfollows symbolic links to operate on the target of the link 79*8269e767SBrooks Davisrather than the link itself. 80*8269e767SBrooks Davis.Pp 81*8269e767SBrooks DavisThe 82*8269e767SBrooks Davis.Fn fchown 83*8269e767SBrooks Davissystem call 84*8269e767SBrooks Davisis particularly useful when used in conjunction 85*8269e767SBrooks Daviswith the file locking primitives (see 86*8269e767SBrooks Davis.Xr flock 2 ) . 87*8269e767SBrooks Davis.Pp 88*8269e767SBrooks DavisThe 89*8269e767SBrooks Davis.Fn lchown 90*8269e767SBrooks Davissystem call is similar to 91*8269e767SBrooks Davis.Fn chown 92*8269e767SBrooks Davisbut does not follow symbolic links. 93*8269e767SBrooks Davis.Pp 94*8269e767SBrooks DavisThe 95*8269e767SBrooks Davis.Fn fchownat 96*8269e767SBrooks Davissystem call is equivalent to the 97*8269e767SBrooks Davis.Fn chown 98*8269e767SBrooks Davisand 99*8269e767SBrooks Davis.Fn lchown 100*8269e767SBrooks Davisexcept in the case where 101*8269e767SBrooks Davis.Fa path 102*8269e767SBrooks Davisspecifies a relative path. 103*8269e767SBrooks DavisIn this case the file to be changed is determined relative to the directory 104*8269e767SBrooks Davisassociated with the file descriptor 105*8269e767SBrooks Davis.Fa fd 106*8269e767SBrooks Davisinstead of the current working directory. 107*8269e767SBrooks Davis.Pp 108*8269e767SBrooks DavisValues for 109*8269e767SBrooks Davis.Fa flag 110*8269e767SBrooks Davisare constructed by a bitwise-inclusive OR of flags from the following 111*8269e767SBrooks Davislist, defined in 112*8269e767SBrooks Davis.In fcntl.h : 113*8269e767SBrooks Davis.Bl -tag -width indent 114*8269e767SBrooks Davis.It Dv AT_SYMLINK_NOFOLLOW 115*8269e767SBrooks DavisIf 116*8269e767SBrooks Davis.Fa path 117*8269e767SBrooks Davisnames a symbolic link, ownership of the symbolic link is changed. 118*8269e767SBrooks Davis.It Dv AT_RESOLVE_BENEATH 119*8269e767SBrooks DavisOnly walk paths below the directory specified by the 120*8269e767SBrooks Davis.Ar fd 121*8269e767SBrooks Davisdescriptor. 122*8269e767SBrooks DavisSee the description of the 123*8269e767SBrooks Davis.Dv O_RESOLVE_BENEATH 124*8269e767SBrooks Davisflag in the 125*8269e767SBrooks Davis.Xr open 2 126*8269e767SBrooks Davismanual page. 127*8269e767SBrooks Davis.It Dv AT_EMPTY_PATH 128*8269e767SBrooks DavisIf the 129*8269e767SBrooks Davis.Fa path 130*8269e767SBrooks Davisargument is an empty string, operate on the file or directory 131*8269e767SBrooks Davisreferenced by the descriptor 132*8269e767SBrooks Davis.Fa fd . 133*8269e767SBrooks DavisIf 134*8269e767SBrooks Davis.Fa fd 135*8269e767SBrooks Davisis equal to 136*8269e767SBrooks Davis.Dv AT_FDCWD , 137*8269e767SBrooks Davisoperate on the current working directory. 138*8269e767SBrooks Davis.El 139*8269e767SBrooks Davis.Pp 140*8269e767SBrooks DavisIf 141*8269e767SBrooks Davis.Fn fchownat 142*8269e767SBrooks Davisis passed the special value 143*8269e767SBrooks Davis.Dv AT_FDCWD 144*8269e767SBrooks Davisin the 145*8269e767SBrooks Davis.Fa fd 146*8269e767SBrooks Davisparameter, the current working directory is used and the behavior is identical 147*8269e767SBrooks Davisto a call to 148*8269e767SBrooks Davis.Fn chown 149*8269e767SBrooks Davisor 150*8269e767SBrooks Davis.Fn lchown 151*8269e767SBrooks Davisrespectively, depending on whether or not the 152*8269e767SBrooks Davis.Dv AT_SYMLINK_NOFOLLOW 153*8269e767SBrooks Davisbit is set in the 154*8269e767SBrooks Davis.Fa flag 155*8269e767SBrooks Davisargument. 156*8269e767SBrooks Davis.Pp 157*8269e767SBrooks DavisOne of the owner or group id's 158*8269e767SBrooks Davismay be left unchanged by specifying it as -1. 159*8269e767SBrooks Davis.Sh RETURN VALUES 160*8269e767SBrooks Davis.Rv -std 161*8269e767SBrooks Davis.Sh ERRORS 162*8269e767SBrooks DavisThe 163*8269e767SBrooks Davis.Fn chown 164*8269e767SBrooks Davisand 165*8269e767SBrooks Davis.Fn lchown 166*8269e767SBrooks Daviswill fail and the file will be unchanged if: 167*8269e767SBrooks Davis.Bl -tag -width Er 168*8269e767SBrooks Davis.It Bq Er ENOTDIR 169*8269e767SBrooks DavisA component of the path prefix is not a directory. 170*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG 171*8269e767SBrooks DavisA component of a pathname exceeded 255 characters, 172*8269e767SBrooks Davisor an entire path name exceeded 1023 characters. 173*8269e767SBrooks Davis.It Bq Er ENOENT 174*8269e767SBrooks DavisThe named file does not exist. 175*8269e767SBrooks Davis.It Bq Er EACCES 176*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix. 177*8269e767SBrooks Davis.It Bq Er ELOOP 178*8269e767SBrooks DavisToo many symbolic links were encountered in translating the pathname. 179*8269e767SBrooks Davis.It Bq Er EPERM 180*8269e767SBrooks DavisThe operation would change the ownership, but the effective user ID is not the 181*8269e767SBrooks Davissuper-user. 182*8269e767SBrooks Davis.It Bq Er EPERM 183*8269e767SBrooks DavisThe named file has its immutable or append-only flag set, see the 184*8269e767SBrooks Davis.Xr chflags 2 185*8269e767SBrooks Davismanual page for more information. 186*8269e767SBrooks Davis.It Bq Er EROFS 187*8269e767SBrooks DavisThe named file resides on a read-only file system. 188*8269e767SBrooks Davis.It Bq Er EFAULT 189*8269e767SBrooks DavisThe 190*8269e767SBrooks Davis.Fa path 191*8269e767SBrooks Davisargument 192*8269e767SBrooks Davispoints outside the process's allocated address space. 193*8269e767SBrooks Davis.It Bq Er EIO 194*8269e767SBrooks DavisAn I/O error occurred while reading from or writing to the file system. 195*8269e767SBrooks Davis.It Bq Er EINTEGRITY 196*8269e767SBrooks DavisCorrupted data was detected while reading from the file system. 197*8269e767SBrooks Davis.El 198*8269e767SBrooks Davis.Pp 199*8269e767SBrooks DavisThe 200*8269e767SBrooks Davis.Fn fchown 201*8269e767SBrooks Davissystem call will fail if: 202*8269e767SBrooks Davis.Bl -tag -width Er 203*8269e767SBrooks Davis.It Bq Er EBADF 204*8269e767SBrooks DavisThe 205*8269e767SBrooks Davis.Fa fd 206*8269e767SBrooks Davisargument 207*8269e767SBrooks Davisdoes not refer to a valid descriptor. 208*8269e767SBrooks Davis.It Bq Er EINVAL 209*8269e767SBrooks DavisThe 210*8269e767SBrooks Davis.Fa fd 211*8269e767SBrooks Davisargument 212*8269e767SBrooks Davisrefers to a socket, not a file. 213*8269e767SBrooks Davis.It Bq Er EPERM 214*8269e767SBrooks DavisThe effective user ID is not the super-user. 215*8269e767SBrooks Davis.It Bq Er EROFS 216*8269e767SBrooks DavisThe named file resides on a read-only file system. 217*8269e767SBrooks Davis.It Bq Er EIO 218*8269e767SBrooks DavisAn I/O error occurred while reading from or writing to the file system. 219*8269e767SBrooks Davis.It Bq Er EINTEGRITY 220*8269e767SBrooks DavisCorrupted data was detected while reading from the file system. 221*8269e767SBrooks Davis.El 222*8269e767SBrooks Davis.Pp 223*8269e767SBrooks DavisIn addition to the errors specified for 224*8269e767SBrooks Davis.Fn chown 225*8269e767SBrooks Davisand 226*8269e767SBrooks Davis.Fn lchown , 227*8269e767SBrooks Davisthe 228*8269e767SBrooks Davis.Fn fchownat 229*8269e767SBrooks Davissystem call may fail if: 230*8269e767SBrooks Davis.Bl -tag -width Er 231*8269e767SBrooks Davis.It Bq Er EBADF 232*8269e767SBrooks DavisThe 233*8269e767SBrooks Davis.Fa path 234*8269e767SBrooks Davisargument does not specify an absolute path and the 235*8269e767SBrooks Davis.Fa fd 236*8269e767SBrooks Davisargument is neither 237*8269e767SBrooks Davis.Dv AT_FDCWD 238*8269e767SBrooks Davisnor a valid file descriptor open for searching. 239*8269e767SBrooks Davis.It Bq Er EINVAL 240*8269e767SBrooks DavisThe value of the 241*8269e767SBrooks Davis.Fa flag 242*8269e767SBrooks Davisargument is not valid. 243*8269e767SBrooks Davis.It Bq Er ENOTDIR 244*8269e767SBrooks DavisThe 245*8269e767SBrooks Davis.Fa path 246*8269e767SBrooks Davisargument is not an absolute path and 247*8269e767SBrooks Davis.Fa fd 248*8269e767SBrooks Davisis neither 249*8269e767SBrooks Davis.Dv AT_FDCWD 250*8269e767SBrooks Davisnor a file descriptor associated with a directory. 251*8269e767SBrooks Davis.It Bq Er ENOTCAPABLE 252*8269e767SBrooks Davis.Fa path 253*8269e767SBrooks Davisis an absolute path, 254*8269e767SBrooks Davisor contained a ".." component leading to a 255*8269e767SBrooks Davisdirectory outside of the directory hierarchy specified by 256*8269e767SBrooks Davis.Fa fd , 257*8269e767SBrooks Davisand the process is in capability mode or the 258*8269e767SBrooks Davis.Dv AT_RESOLVE_BENEATH 259*8269e767SBrooks Davisflag was specified. 260*8269e767SBrooks Davis.El 261*8269e767SBrooks Davis.Sh SEE ALSO 262*8269e767SBrooks Davis.Xr chgrp 1 , 263*8269e767SBrooks Davis.Xr chflags 2 , 264*8269e767SBrooks Davis.Xr chmod 2 , 265*8269e767SBrooks Davis.Xr flock 2 , 266*8269e767SBrooks Davis.Xr chown 8 267*8269e767SBrooks Davis.Sh STANDARDS 268*8269e767SBrooks DavisThe 269*8269e767SBrooks Davis.Fn chown 270*8269e767SBrooks Davissystem call is expected to conform to 271*8269e767SBrooks Davis.St -p1003.1-90 . 272*8269e767SBrooks DavisThe 273*8269e767SBrooks Davis.Fn fchownat 274*8269e767SBrooks Davissystem call follows The Open Group Extended API Set 2 specification. 275*8269e767SBrooks Davis.Sh HISTORY 276*8269e767SBrooks DavisThe 277*8269e767SBrooks Davis.Fn chown 278*8269e767SBrooks Davisfunction appeared in 279*8269e767SBrooks Davis.At v1 . 280*8269e767SBrooks DavisThe 281*8269e767SBrooks Davis.Fn fchown 282*8269e767SBrooks Davissystem call appeared in 283*8269e767SBrooks Davis.Bx 4.2 . 284*8269e767SBrooks Davis.Pp 285*8269e767SBrooks DavisThe 286*8269e767SBrooks Davis.Fn chown 287*8269e767SBrooks Davissystem call was changed to follow symbolic links in 288*8269e767SBrooks Davis.Bx 4.4 . 289*8269e767SBrooks DavisThe 290*8269e767SBrooks Davis.Fn lchown 291*8269e767SBrooks Davissystem call was added in 292*8269e767SBrooks Davis.Fx 3.0 293*8269e767SBrooks Davisto compensate for the loss of functionality. 294*8269e767SBrooks Davis.Pp 295*8269e767SBrooks DavisThe 296*8269e767SBrooks Davis.Fn fchownat 297*8269e767SBrooks Davissystem call appeared in 298*8269e767SBrooks Davis.Fx 8.0 . 299