1c10c16deSRichard Lowe'\" te 2c10c16deSRichard Lowe.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved. 3c10c16deSRichard Lowe.\" Copyright 1989 AT&T 4*fc1e9305SRobert Mustacchi.\" Copyright 2021 Oxide Computer Company 5c10c16deSRichard Lowe.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. 6c10c16deSRichard Lowe.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. 7c10c16deSRichard Lowe.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 8*fc1e9305SRobert Mustacchi.Dd March 13, 2021 9*fc1e9305SRobert Mustacchi.Dt CHOWN 2 10*fc1e9305SRobert Mustacchi.Os 11*fc1e9305SRobert Mustacchi.Sh NAME 12*fc1e9305SRobert Mustacchi.Nm chown , 13*fc1e9305SRobert Mustacchi.Nm lchown , 14*fc1e9305SRobert Mustacchi.Nm fchown , 15*fc1e9305SRobert Mustacchi.Nm fchownat 16*fc1e9305SRobert Mustacchi.Nd change owner and group of a file 17*fc1e9305SRobert Mustacchi.Sh SYNOPSIS 18*fc1e9305SRobert Mustacchi.In unistd.h 19*fc1e9305SRobert Mustacchi.In sys/types.h 20*fc1e9305SRobert Mustacchi.Ft int 21*fc1e9305SRobert Mustacchi.Fo chown 22*fc1e9305SRobert Mustacchi.Fa "const char *path" 23*fc1e9305SRobert Mustacchi.Fa "uid_t owner" 24*fc1e9305SRobert Mustacchi.Fa "gid_t group" 25*fc1e9305SRobert Mustacchi.Fc 26*fc1e9305SRobert Mustacchi.Ft int 27*fc1e9305SRobert Mustacchi.Fo lchown 28*fc1e9305SRobert Mustacchi.Fa "const char *path" 29*fc1e9305SRobert Mustacchi.Fa "uid_t owner" 30*fc1e9305SRobert Mustacchi.Fa "gid_t group" 31*fc1e9305SRobert Mustacchi.Fc 32*fc1e9305SRobert Mustacchi.Ft int 33*fc1e9305SRobert Mustacchi.Fo fchown 34*fc1e9305SRobert Mustacchi.Fa "int fildes" 35*fc1e9305SRobert Mustacchi.Fa "uid_t owner" 36*fc1e9305SRobert Mustacchi.Fa "gid_t group" 37*fc1e9305SRobert Mustacchi.Fc 38*fc1e9305SRobert Mustacchi.Ft int 39*fc1e9305SRobert Mustacchi.Fo fchownat 40*fc1e9305SRobert Mustacchi.Fa "int fildes" 41*fc1e9305SRobert Mustacchi.Fa "const char *path" 42*fc1e9305SRobert Mustacchi.Fa "uid_t owner" 43*fc1e9305SRobert Mustacchi.Fa "gid_t group" 44*fc1e9305SRobert Mustacchi.Fa "int flag" 45*fc1e9305SRobert Mustacchi.Fc 46*fc1e9305SRobert Mustacchi.Sh DESCRIPTION 47*fc1e9305SRobert MustacchiThe 48*fc1e9305SRobert Mustacchi.Fn chown 49*fc1e9305SRobert Mustacchiand 50*fc1e9305SRobert Mustacchi.Fn fchown 51*fc1e9305SRobert Mustacchifunctions set the owner 52*fc1e9305SRobert Mustacchi.Sy ID 53*fc1e9305SRobert Mustacchiand group 54*fc1e9305SRobert Mustacchi.Sy ID 55*fc1e9305SRobert Mustacchiof the file specified by 56*fc1e9305SRobert Mustacchi.Fa path 57*fc1e9305SRobert Mustacchior referenced by the open file descriptor 58*fc1e9305SRobert Mustacchi.Fa fildes 59*fc1e9305SRobert Mustacchito 60*fc1e9305SRobert Mustacchi.Fa owner 61*fc1e9305SRobert Mustacchiand 62*fc1e9305SRobert Mustacchi.Fa group 63*fc1e9305SRobert Mustacchirespectively. 64*fc1e9305SRobert MustacchiIf 65*fc1e9305SRobert Mustacchi.Fa owner 66*fc1e9305SRobert Mustacchior 67*fc1e9305SRobert Mustacchi.Fa group 68*fc1e9305SRobert Mustacchiis specified as -1, 69*fc1e9305SRobert Mustacchi.Fn chown 70*fc1e9305SRobert Mustacchiand 71*fc1e9305SRobert Mustacchi.Fn fchown 72*fc1e9305SRobert Mustacchido not change the corresponding 73*fc1e9305SRobert Mustacchi.Sy ID 74*fc1e9305SRobert Mustacchiof the file. 75*fc1e9305SRobert Mustacchi.Pp 76*fc1e9305SRobert MustacchiThe 77*fc1e9305SRobert Mustacchi.Fn lchown 78*fc1e9305SRobert Mustacchifunction sets the owner 79*fc1e9305SRobert Mustacchi.Sy ID 80*fc1e9305SRobert Mustacchiand group 81*fc1e9305SRobert Mustacchi.Sy ID 82*fc1e9305SRobert Mustacchiof the named file in the same manner as 83*fc1e9305SRobert Mustacchi.Fn chown , 84*fc1e9305SRobert Mustacchiunless the named file is a symbolic link. 85*fc1e9305SRobert MustacchiIn this case, 86*fc1e9305SRobert Mustacchi.Fn lchown 87*fc1e9305SRobert Mustacchichanges the ownership of the symbolic link file itself, while 88*fc1e9305SRobert Mustacchi.Fn chown 89*fc1e9305SRobert Mustacchichanges the ownership of the file or directory to which the symbolic link 90*fc1e9305SRobert Mustacchirefers. 91*fc1e9305SRobert Mustacchi.Pp 92*fc1e9305SRobert MustacchiThe 93*fc1e9305SRobert Mustacchi.Fn fchownat 94*fc1e9305SRobert Mustacchifunction sets the owner ID and group ID of the named file 95*fc1e9305SRobert Mustacchiin the same manner as 96*fc1e9305SRobert Mustacchi.Fn chown . 97*fc1e9305SRobert MustacchiIf, however, the 98*fc1e9305SRobert Mustacchi.Fa path 99*fc1e9305SRobert Mustacchiargument is relative 100*fc1e9305SRobert Mustacchi.Po 101*fc1e9305SRobert Mustacchidoes not start with a 102*fc1e9305SRobert Mustacchi.Qq / 103*fc1e9305SRobert Mustacchi.Pc , 104*fc1e9305SRobert Mustacchithe path is resolved relative to the 105*fc1e9305SRobert Mustacchi.Fa fildes 106*fc1e9305SRobert Mustacchiargument rather than the current working directory. 107*fc1e9305SRobert MustacchiIf the 108*fc1e9305SRobert Mustacchi.Fa fildes 109*fc1e9305SRobert Mustacchiargument has the special value 110*fc1e9305SRobert Mustacchi.Dv AT_FDCWD , 111*fc1e9305SRobert Mustacchithe path resolution reverts back to current working directory relative. 112*fc1e9305SRobert MustacchiIf the 113*fc1e9305SRobert Mustacchi.Fa flag 114*fc1e9305SRobert Mustacchiargument is set to 115*fc1e9305SRobert Mustacchi.Dv AT_SYMLINK_NOFOLLOW , 116*fc1e9305SRobert Mustacchithe function behaves like 117*fc1e9305SRobert Mustacchi.Fn lchown 118*fc1e9305SRobert Mustacchiwith respect to symbolic links. 119*fc1e9305SRobert MustacchiIf the 120*fc1e9305SRobert Mustacchi.Fa path 121*fc1e9305SRobert Mustacchiargument is absolute, the 122*fc1e9305SRobert Mustacchi.Fa fildes 123*fc1e9305SRobert Mustacchiargument is ignored. 124*fc1e9305SRobert MustacchiIf the 125*fc1e9305SRobert Mustacchi.Fa path 126*fc1e9305SRobert Mustacchiargument is a null pointer, the function behaves like 127*fc1e9305SRobert Mustacchi.Fn fchown . 128*fc1e9305SRobert Mustacchi.Pp 129*fc1e9305SRobert MustacchiIf 130*fc1e9305SRobert Mustacchi.Fn chown , 131*fc1e9305SRobert Mustacchi.Fn lchown , 132*fc1e9305SRobert Mustacchi.Fn fchown , 133*fc1e9305SRobert Mustacchior 134*fc1e9305SRobert Mustacchi.Fn fchownat 135*fc1e9305SRobert Mustacchiis invoked by a process that does not have 136*fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_SETID 137*fc1e9305SRobert Mustacchiasserted in its effective set, the set-user-ID and set-group-ID bits of the 138*fc1e9305SRobert Mustacchifile mode, 139*fc1e9305SRobert Mustacchi.Dv S_ISUID 140*fc1e9305SRobert Mustacchiand 141*fc1e9305SRobert Mustacchi.Dv S_ISGID 142*fc1e9305SRobert Mustacchirespectively, are cleared 143*fc1e9305SRobert Mustacchi.Po 144*fc1e9305SRobert Mustacchisee 145*fc1e9305SRobert Mustacchi.Xr chmod 2 146*fc1e9305SRobert Mustacchi.Pc . 147*fc1e9305SRobert MustacchiAdditional restrictions apply when changing the ownership to uid 0. 148*fc1e9305SRobert Mustacchi.Pp 149c10c16deSRichard LoweThe operating system defines several privileges to override restrictions on the 150*fc1e9305SRobert Mustacchi.Fn chown 151*fc1e9305SRobert Mustacchifamily of functions. 152*fc1e9305SRobert MustacchiWhen the 153*fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN 154*fc1e9305SRobert Mustacchiprivilege is asserted in the effective set of the current process, there are no 155c10c16deSRichard Lowerestrictions except in the special circumstances of changing ownership to or 156*fc1e9305SRobert Mustacchifrom uid 0. 157*fc1e9305SRobert MustacchiWhen the 158*fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN_SELF 159*fc1e9305SRobert Mustacchiprivilege is asserted, ownership changes are restricted to the files of which 160*fc1e9305SRobert Mustacchithe ownership matches the effective user ID of the current process. 161*fc1e9305SRobert MustacchiIf neither privilege is asserted in the effective set of the calling process, 162*fc1e9305SRobert Mustacchiownership changes are limited to changes of the group of the file to the list of 163*fc1e9305SRobert Mustacchisupplementary group IDs and the effective group ID. 164*fc1e9305SRobert Mustacchi.Pp 165c10c16deSRichard LoweThe operating system provides a configuration option, 166*fc1e9305SRobert Mustacchi.Brq Dv _POSIX_CHOWN_RESTRICTED , 167*fc1e9305SRobert Mustacchito control the default behavior of processes and the behavior of the NFS server. 168*fc1e9305SRobert MustacchiIf 169*fc1e9305SRobert Mustacchi.Brq Dv B_POSIX_CHOWN_RESTRICTED 170*fc1e9305SRobert Mustacchiis not in effect, the privilege 171*fc1e9305SRobert Mustacchi.Brq PRIV_FILE_CHOWN_SELF 172*fc1e9305SRobert Mustacchiis asserted in the inheritable set of all processes unless overridden by 173*fc1e9305SRobert Mustacchi.Xr policy.conf 4 174*fc1e9305SRobert Mustacchior 175*fc1e9305SRobert Mustacchi.Xr user_attr 4 . 176*fc1e9305SRobert MustacchiTo set this configuration option, include the following 177*fc1e9305SRobert Mustacchiline in 178*fc1e9305SRobert Mustacchi.Pa /etc/system : 179*fc1e9305SRobert Mustacchi.Bd -literal -offset indent 180c10c16deSRichard Loweset rstchown = 1 181*fc1e9305SRobert Mustacchi.Ed 182*fc1e9305SRobert Mustacchi.Pp 183*fc1e9305SRobert MustacchiTo disable this option, include the following line in 184*fc1e9305SRobert Mustacchi.Pa /etc/system : 185*fc1e9305SRobert Mustacchi.Bd -literal -offset indent 186c10c16deSRichard Loweset rstchown = 0 187*fc1e9305SRobert Mustacchi.Ed 188*fc1e9305SRobert Mustacchi.Pp 189*fc1e9305SRobert MustacchiSee 190*fc1e9305SRobert Mustacchi.Xr system 4 191*fc1e9305SRobert Mustacchiand 192*fc1e9305SRobert Mustacchi.Xr fpathconf 2 . 193*fc1e9305SRobert Mustacchi.Pp 194*fc1e9305SRobert MustacchiUpon successful completion, 195*fc1e9305SRobert Mustacchi.Fn chown , 196*fc1e9305SRobert Mustacchi.Fn fchown , 197*fc1e9305SRobert Mustacchi.Fn lchown , 198*fc1e9305SRobert Mustacchiand 199*fc1e9305SRobert Mustacchi.Fn fchownat 200*fc1e9305SRobert Mustacchimark for update the 201*fc1e9305SRobert Mustacchi.Fa st_ctime 202*fc1e9305SRobert Mustacchifield of the file. 203*fc1e9305SRobert Mustacchi.Sh RETURN VALUES 204*fc1e9305SRobert MustacchiUpon successful completion, 205*fc1e9305SRobert Mustacchi.Sy 0 206*fc1e9305SRobert Mustacchiis returned. 207*fc1e9305SRobert MustacchiOtherwise, 208*fc1e9305SRobert Mustacchi.Sy -1 209*fc1e9305SRobert Mustacchiis returned, the owner and group of the named file remain unchanged, and 210*fc1e9305SRobert Mustacchi.Va errno 211*fc1e9305SRobert Mustacchiis set to indicate the error. 212*fc1e9305SRobert Mustacchi.Sh ERRORS 213c10c16deSRichard LoweAll of these functions will fail if: 214*fc1e9305SRobert Mustacchi.Bl -tag -width Er 215*fc1e9305SRobert Mustacchi.It Er EPERM 216c10c16deSRichard LoweThe effective user ID does not match the owner of the file and the 217*fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN 218*fc1e9305SRobert Mustacchiprivilege is not asserted in the effective set of the calling process, or the 219*fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN_SELF 220*fc1e9305SRobert Mustacchiprivilege is not asserted in the effective set of the calling process. 221*fc1e9305SRobert Mustacchi.El 222*fc1e9305SRobert Mustacchi.Pp 223*fc1e9305SRobert MustacchiThe 224*fc1e9305SRobert Mustacchi.Fn chown , 225*fc1e9305SRobert Mustacchi.Fn lchown , 226*fc1e9305SRobert Mustacchiand 227*fc1e9305SRobert Mustacchi.Fn fchownat 228*fc1e9305SRobert Mustacchifunctions will fail if: 229*fc1e9305SRobert Mustacchi.Bl -tag -width Er 230*fc1e9305SRobert Mustacchi.It Er EACCES 231*fc1e9305SRobert MustacchiSearch permission is denied on a component of the path prefix of 232*fc1e9305SRobert Mustacchi.Fa path . 233*fc1e9305SRobert Mustacchi.It Er EFAULT 234*fc1e9305SRobert MustacchiThe 235*fc1e9305SRobert Mustacchi.Fa path 236*fc1e9305SRobert Mustacchiargument points to an illegal address and for 237*fc1e9305SRobert Mustacchi.Fn fchownat , 238*fc1e9305SRobert Mustacchithe file descriptor has the value 239*fc1e9305SRobert Mustacchi.Dv AT_FDCWD . 240*fc1e9305SRobert Mustacchi.It Er EINTR 241*fc1e9305SRobert MustacchiA signal was caught during the execution of the 242*fc1e9305SRobert Mustacchi.Fn chown 243*fc1e9305SRobert Mustacchior 244*fc1e9305SRobert Mustacchi.Fn lchown 245c10c16deSRichard Lowefunction. 246*fc1e9305SRobert Mustacchi.It Er EINVAL 247*fc1e9305SRobert MustacchiThe 248*fc1e9305SRobert Mustacchi.Fa group 249*fc1e9305SRobert Mustacchior 250*fc1e9305SRobert Mustacchi.Fa owner 251*fc1e9305SRobert Mustacchiargument is out of range. 252*fc1e9305SRobert Mustacchi.It Er EIO 253c10c16deSRichard LoweAn I/O error occurred while reading from or writing to the file system. 254*fc1e9305SRobert Mustacchi.It Er ELOOP 255*fc1e9305SRobert MustacchiToo many symbolic links were encountered in translating 256*fc1e9305SRobert Mustacchi.Fa path . 257*fc1e9305SRobert Mustacchi.It Er ENAMETOOLONG 258*fc1e9305SRobert MustacchiThe length of the 259*fc1e9305SRobert Mustacchi.Fa path 260*fc1e9305SRobert Mustacchiargument exceeds 261*fc1e9305SRobert Mustacchi.Brq Dv PATH_MAX , 262*fc1e9305SRobert Mustacchior the length of a 263*fc1e9305SRobert Mustacchi.Fa path 264*fc1e9305SRobert Mustacchicomponent exceeds 265*fc1e9305SRobert Mustacchi.Brq Dv NAME_MAX 266*fc1e9305SRobert Mustacchiwhile 267*fc1e9305SRobert Mustacchi.Brq Dv _POSIX_NO_TRUNC 268*fc1e9305SRobert Mustacchiis in effect. 269*fc1e9305SRobert Mustacchi.It Er ENOLINK 270*fc1e9305SRobert MustacchiThe 271*fc1e9305SRobert Mustacchi.Fa path 272*fc1e9305SRobert Mustacchiargument points to a remote machine and the link to that machine is no longer 273*fc1e9305SRobert Mustacchiactive. 274*fc1e9305SRobert Mustacchi.It Er ENOENT 275*fc1e9305SRobert MustacchiEither a component of the path prefix or the file referred to by 276*fc1e9305SRobert Mustacchi.Fa path 277c10c16deSRichard Lowedoes not exist or is a null pathname. 278*fc1e9305SRobert Mustacchi.It Er ENOTDIR 279*fc1e9305SRobert MustacchiA component of the path prefix of 280*fc1e9305SRobert Mustacchi.Fa path 281*fc1e9305SRobert Mustacchiis not a directory, or the path supplied to 282*fc1e9305SRobert Mustacchi.Fn fchownat 283*fc1e9305SRobert Mustacchiis relative and the file descriptor provided does not refer to a valid 284*fc1e9305SRobert Mustacchidirectory. 285*fc1e9305SRobert Mustacchi.It Er EROFS 286c10c16deSRichard LoweThe named file resides on a read-only file system. 287*fc1e9305SRobert Mustacchi.El 288*fc1e9305SRobert Mustacchi.Pp 289*fc1e9305SRobert MustacchiThe 290*fc1e9305SRobert Mustacchi.Fn chown 291*fc1e9305SRobert Mustacchiand 292*fc1e9305SRobert Mustacchi.Fn fchownat 293*fc1e9305SRobert Mustacchifunctions will fail if: 294*fc1e9305SRobert Mustacchi.Bl -tag -width Er 295*fc1e9305SRobert Mustacchi.It Er EBADF 296*fc1e9305SRobert MustacchiFor 297*fc1e9305SRobert Mustacchi.Fn fchown , 298*fc1e9305SRobert Mustacchithe 299*fc1e9305SRobert Mustacchi.Fa fildes 300*fc1e9305SRobert Mustacchiargument is not an open file descriptor. 301*fc1e9305SRobert Mustacchi.Pp 302*fc1e9305SRobert MustacchiFor 303*fc1e9305SRobert Mustacchi.Fn fchownat , 304*fc1e9305SRobert Mustacchithe 305*fc1e9305SRobert Mustacchi.Fa path 306*fc1e9305SRobert Mustacchiargument is not absolute and the fildes argument is neither 307*fc1e9305SRobert Mustacchi.Dv AT_FDCWD , 308*fc1e9305SRobert Mustacchinor an open file descriptor. 309*fc1e9305SRobert Mustacchi.It Er EIO 310c10c16deSRichard LoweAn I/O error occurred while reading from or writing to the file system. 311*fc1e9305SRobert Mustacchi.It Er EINTR 312c10c16deSRichard LoweA signal was caught during execution of the function. 313*fc1e9305SRobert Mustacchi.It Er ENOLINK 314*fc1e9305SRobert MustacchiThe 315*fc1e9305SRobert Mustacchi.Fa fildes 316*fc1e9305SRobert Mustacchiargument points to a remote machine and the link to that machine is no longer 317*fc1e9305SRobert Mustacchiactive. 318*fc1e9305SRobert Mustacchi.It Er EINVAL 319*fc1e9305SRobert MustacchiThe 320*fc1e9305SRobert Mustacchi.Fa group 321*fc1e9305SRobert Mustacchior 322*fc1e9305SRobert Mustacchi.Fa owner 323*fc1e9305SRobert Mustacchiargument is out of range. 324*fc1e9305SRobert Mustacchi.It Er EROFS 325*fc1e9305SRobert MustacchiThe named file referred to by 326*fc1e9305SRobert Mustacchi.Fa fildes 327*fc1e9305SRobert Mustacchiresides on a read-only file system. 328*fc1e9305SRobert Mustacchi.El 329*fc1e9305SRobert Mustacchi.Sh INTERFACE STABILITY 330*fc1e9305SRobert Mustacchi.Sy Committed 331*fc1e9305SRobert Mustacchi.Sh MT-LEVEL 332*fc1e9305SRobert Mustacchi.Sy Async-Signal-Safe 333*fc1e9305SRobert Mustacchi.Sh SEE ALSO 334*fc1e9305SRobert Mustacchi.Xr chgrp 1 , 335*fc1e9305SRobert Mustacchi.Xr chown 1 , 336*fc1e9305SRobert Mustacchi.Xr chmod 2 , 337*fc1e9305SRobert Mustacchi.Xr fpathconf 2 , 338*fc1e9305SRobert Mustacchi.Xr system 4 , 339*fc1e9305SRobert Mustacchi.Xr attributes 5 , 340*fc1e9305SRobert Mustacchi.Xr standards 5 341