Rev | Author | # | Line |
---|---|---|---|
1 | perry | 1 | !!NAME |
2 | PerryLorier | 2 | fchown - change ownership of a file |
1 | perry | 3 | !!SYNOPSIS |
4 | |||
2 | PerryLorier | 5 | __#include <sys/types.h>__ /* For uid_t and gid_t */ |
6 | __#include <unistd.h>__ /* for fchown prototype */ | ||
1 | perry | 7 | |
2 | PerryLorier | 8 | __int fchown(int__ ''fd''__, uid_t__ ''owner''__, gid_t__ ''group''__);__ |
1 | perry | 9 | |
10 | !!DESCRIPTION | ||
2 | PerryLorier | 11 | The owner of the file specified by ''fd'' is changed. Only the super-user may change the owner of a file. The owner of a file may change the group of the file to any group of which that owner is a member. The |
1 | perry | 12 | super-user may change the group arbitrarily. |
13 | |||
2 | PerryLorier | 14 | If the ''owner'' or ''group'' is specified as -1, then that ID is not changed. |
1 | perry | 15 | |
2 | PerryLorier | 16 | When the owner or group of an executable file are changed by a non-super-user, the S_ISUID and S_ISGID mode bits are cleared. POSIX does not specify whether this also should happen when root does the ''chown''; the Linux behaviour depends on the kernel version. In case of a non-group-executable file (with clear S_IXGRP bit) the S_ISGID bit indicates mandatory locking, and is not cleared by a ''chown''. |
1 | perry | 17 | |
18 | !!RETURN VALUE | ||
2 | PerryLorier | 19 | On success, zero is returned. On error, -1 is returned, and ''errno'' is set appropriately. |
1 | perry | 20 | |
21 | !!ERRORS | ||
22 | Depending on the file system, other errors can be returned. | ||
23 | |||
2 | PerryLorier | 24 | ;[EPERM]: The effective UID does not match the owner of the file, and is not zero; or the ''owner'' or ''group'' were specified incorrectly. |
25 | ;[EROFS]: The named file resides on a read-only file system. | ||
26 | ;[ENOMEM]: Insufficient kernel memory was available. | ||
27 | ;[EBADF]: The descriptor is not valid. | ||
28 | ;[ENOENT]: See above. | ||
29 | ;[EIO]: A low-level I/O error occurred while modifying the inode. | ||
1 | perry | 30 | |
31 | !!NOTES | ||
2 | PerryLorier | 32 | The prototype for __fchown__ is only available if ___BSD_SOURCE__ is defined (either explicitly, or implicitly, by not defining _POSIX_SOURCE or compiling with the -ansi flag). |
1 | perry | 33 | |
2 | PerryLorier | 34 | !!CONFORMING TO |
35 | The __fchown__ call conforms to 4.4BSD and SVr4. SVr4 documents additional [EINVAL], [EIO], [EINTR], and [ENOLINK] error conditions. | ||
1 | perry | 36 | |
2 | PerryLorier | 37 | !!RESTRICTIONS |
38 | The fchown(2) semantics are deliberately violated on NFS file systems which have UID mapping enabled. Additionally, the semantics of all system calls which access the file contents are violated, because fchown(2) may | ||
39 | cause immediate access revocation on already open files. Client side caching may lead to a delay between the time where ownership have been changed to allow access for a user and the time where the file can actually be accessed by the user on other clients. | ||
1 | perry | 40 | |
2 | PerryLorier | 41 | !!EXAMPLE |
42 | /* | ||
43 | * This program creates a file, and uses fchown to change it's ownership. | ||
44 | * | ||
45 | * This program will fail with an error unless run as root. | ||
46 | */ | ||
1 | perry | 47 | |
2 | PerryLorier | 48 | #include <sys/stat.h> /* for S_* constants */ |
49 | #include <sys/types.h> /* for mode_t for creat(2) */ | ||
50 | #include <unistd.h> /* for fchown(2) prototype */ | ||
51 | #include <string.h> /* for strerror(3) prototype */ | ||
52 | #include <fcntl.h> /* for creat(2) prototype */ | ||
53 | #include <stdio.h> /* for fprintf(3),stderr protype */ | ||
54 | #include <errno.h> /* for errno prototype */ | ||
1 | perry | 55 | |
2 | PerryLorier | 56 | #define FILENAME "/tmp/fchown.example" |
57 | #define UID 100 | ||
58 | #define GID 100 | ||
1 | perry | 59 | |
2 | PerryLorier | 60 | int main(int argc,char **argv) |
61 | { | ||
62 | int fd; | ||
1 | perry | 63 | |
2 | PerryLorier | 64 | fd = creat(FILENAME,S_IRUSR|S_IWUSR); |
65 | if (fd<0) { | ||
66 | fprintf( | ||
67 | stderr, | ||
68 | "creat(\"%s\",S_IRUSR|S_IWUSR): %s (%i)\n", | ||
69 | FILENAME, | ||
70 | strerror(errno), | ||
71 | errno); | ||
72 | return 1; | ||
73 | } | ||
74 | if (fchown(fd,UID,GID)==-1) { | ||
75 | fprintf( | ||
76 | stderr, | ||
77 | "fchown(fd,%i,%i): %s (%i)\n", | ||
78 | UID, | ||
79 | GID, | ||
80 | strerror(errno), | ||
81 | errno); | ||
82 | return 1; | ||
83 | } | ||
84 | close(fd); | ||
85 | printf( | ||
86 | "%s successfully changed to uid=%i, gid=%i\n", | ||
87 | FILENAME, | ||
88 | UID, | ||
89 | GID); | ||
90 | return 0; | ||
91 | } | ||
1 | perry | 92 | |
93 | |||
94 | !!SEE ALSO | ||
2 | PerryLorier | 95 | chown(2), lchown(2), chmod(2), flock(2) |
lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 9 times)