xref: /csrg-svn/lib/libc/sys/chmod.2 (revision 61181)
1*61181Sbostic.\" Copyright (c) 1980, 1991, 1993
2*61181Sbostic.\"	The Regents of the University of California.  All rights reserved.
320014Smckusick.\"
447208Scael.\" %sccs.include.redist.man%
520014Smckusick.\"
6*61181Sbostic.\"     @(#)chmod.2	8.1 (Berkeley) 06/04/93
747208Scael.\"
847208Scael.Dd
947208Scael.Dt CHMOD 2
1047208Scael.Os BSD 4
1147208Scael.Sh NAME
1247208Scael.Nm chmod ,
1347208Scael.Nm fchmod
1447208Scael.Nd change mode of file
1547208Scael.Sh SYNOPSIS
1647208Scael.Fd #include <sys/stat.h>
1747208Scael.Ft int
1847208Scael.Fn chmod "const char *path" "mode_t mode"
1947208Scael.Ft int
2047208Scael.Fn fchmod "int fd" "mode_t mode"
2147208Scael.Sh DESCRIPTION
2247208ScaelThe function
2347208Scael.Fn chmod
2447208Scaelsets the file permission bits
2547208Scaelof the file
2647208Scaelspecified by the pathname
2747208Scael.Fa path
2847208Scaelto
2947208Scael.Fa mode .
3047208Scael.Fn Fchmod
3147208Scaelsets the permission bits of the specified
3247208Scaelfile descriptor
3347208Scael.Fa fd .
3447208Scael.Fn Chmod
3547208Scaelverifies that the process owner (user) either owns
3647208Scaelthe file specified by
3747208Scael.Fa path
3847208Scael(or
3947208Scael.Fa fd ) ,
4047208Scaelor
4147208Scaelis the super-user.
4247208ScaelA mode is created from
4347208Scael.Em or'd
4447208Scaelpermission bit masks
4547208Scaeldefined in
4647208Scael.Aq Pa sys/stat.h :
4747208Scael.Bd -literal -offset indent -compact
4847208Scael#define S_IRWXU 0000700    /* RWX mask for owner */
4947208Scael#define S_IRUSR 0000400    /* R for owner */
5047208Scael#define S_IWUSR 0000200    /* W for owner */
5147208Scael#define S_IXUSR 0000100    /* X for owner */
5247208Scael
5347208Scael#define S_IRWXG 0000070    /* RWX mask for group */
5447208Scael#define S_IRGRP 0000040    /* R for group */
5547208Scael#define S_IWGRP 0000020    /* W for group */
5647208Scael#define S_IXGRP 0000010    /* X for group */
5747208Scael
5847208Scael#define S_IRWXO 0000007    /* RWX mask for other */
5947208Scael#define S_IROTH 0000004    /* R for other */
6047208Scael#define S_IWOTH 0000002    /* W for other */
6147208Scael#define S_IXOTH 0000001    /* X for other */
6247208Scael
6347208Scael#define S_ISUID 0004000    /* set user id on execution */
6447208Scael#define S_ISGID 0002000    /* set group id on execution */
6547208Scael#define S_ISVTX 0001000    /* save swapped text even after use */
6647208Scael.Ed
6747208Scael.Pp
6847208ScaelThe
6947208Scael.Dv ISVTX
7047208Scael(the
7147208Scael.Em sticky bit )
7247208Scaelindicates to the system which executable files are shareable (the
7347208Scaeldefault) and the system maintains the program text of the files
7447208Scaelin the swap area. The sticky bit may only be set by the super user
7547208Scaelon shareable executable files.
7647208Scael.Pp
7747208ScaelIf mode
7847208Scael.Dv ISVTX
7947208Scael(the `sticky bit') is set on a directory,
8026028Sdonnan unprivileged user may not delete or rename
8147208Scaelfiles of other users in that directory. The sticky bit may be
8247208Scaelset by any user on a directory which the user owns or has appropriate
8347208Scaelpermissions.
8426028SdonnFor more details of the properties of the sticky bit, see
8547208Scael.Xr sticky 8 .
8647208Scael.Pp
8720015SmckusickWriting or changing the owner of a file
8828061Skarelsturns off the set-user-id and set-group-id bits
8928061Skarelsunless the user is the super-user.
9020014SmckusickThis makes the system somewhat more secure
9120015Smckusickby protecting set-user-id (set-group-id) files
9220015Smckusickfrom remaining set-user-id (set-group-id) if they are modified,
9320014Smckusickat the expense of a degree of compatibility.
9447208Scael.Sh RETURN VALUES
9520015SmckusickUpon successful completion, a value of 0 is returned.
9647208ScaelOtherwise, a value of -1 is returned and
9747208Scael.Va errno
9820015Smckusickis set to indicate the error.
9947208Scael.Sh ERRORS
10047208Scael.Fn Chmod
10120015Smckusickwill fail and the file mode will be unchanged if:
10247208Scael.Bl -tag -width Er
10347208Scael.It Bq Er ENOTDIR
10420015SmckusickA component of the path prefix is not a directory.
10547208Scael.It Bq Er EINVAL
10621003SmckusickThe pathname contains a character with the high-order bit set.
10747208Scael.It Bq Er ENAMETOOLONG
10821003SmckusickA component of a pathname exceeded 255 characters,
10921003Smckusickor an entire path name exceeded 1023 characters.
11047208Scael.It Bq Er ENOENT
11120015SmckusickThe named file does not exist.
11247208Scael.It Bq Er EACCES
11321003SmckusickSearch permission is denied for a component of the path prefix.
11447208Scael.It Bq Er ELOOP
11521003SmckusickToo many symbolic links were encountered in translating the pathname.
11647208Scael.It Bq Er EPERM
11720015SmckusickThe effective user ID does not match the owner of the file and
11820015Smckusickthe effective user ID is not the super-user.
11947208Scael.It Bq Er EROFS
12020015SmckusickThe named file resides on a read-only file system.
12147208Scael.It Bq Er EFAULT
12247208Scael.Fa Path
12320015Smckusickpoints outside the process's allocated address space.
12447208Scael.It Bq Er EIO
12524439SmckusickAn I/O error occurred while reading from or writing to the file system.
12647208Scael.El
12747208Scael.Pp
12847208Scael.Fn Fchmod
12920015Smckusickwill fail if:
13047208Scael.Bl -tag -width Er
13147208Scael.It Bq Er EBADF
13220015SmckusickThe descriptor is not valid.
13347208Scael.It Bq Er EINVAL
13447208Scael.Fa Fd
13520015Smckusickrefers to a socket, not to a file.
13647208Scael.It Bq Er EROFS
13720015SmckusickThe file resides on a read-only file system.
13847208Scael.It Bq Er EIO
13924439SmckusickAn I/O error occurred while reading from or writing to the file system.
14047208Scael.El
14147208Scael.Sh SEE ALSO
14247208Scael.Xr chmod 1 ,
14347208Scael.Xr open 2 ,
14447208Scael.Xr chown 2 ,
14547208Scael.Xr stat 2 ,
14647208Scael.Xr sticky 8
14747208Scael.Sh STANDARDS
14847208Scael.Fn Chmod
14947208Scaelis expected to conform to IEEE Std 1003.1-1988
15047208Scael.Pq Dq Tn POSIX .
15147208Scael.Sh HISTORY
15247208ScaelThe
15347208Scael.Fn fchmod
15447208Scaelfunction call
15547208Scaelappeared in
15647208Scael.Bx 4.2 .
157