vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / unistd / chown.c
blob69e96a095dc39d3ed9ada211e7c897d5563f5c02
1 /*
2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <errno.h>
8 #include <unistd.h>
10 #include <NodeMonitor.h>
12 #include <errno_private.h>
13 #include <syscalls.h>
14 #include <syscall_utils.h>
17 static int
18 common_chown(int fd, const char* path, bool followLinks, uid_t owner,
19 gid_t group)
21 struct stat stat;
22 status_t status;
24 int mask = 0;
25 if (owner != (uid_t)-1) {
26 stat.st_uid = owner;
27 mask |= B_STAT_UID;
29 if (group != (gid_t)-1) {
30 stat.st_gid = group;
31 mask |= B_STAT_GID;
34 status = _kern_write_stat(fd, path, followLinks, &stat,
35 sizeof(struct stat), mask);
37 RETURN_AND_SET_ERRNO(status);
41 int
42 chown(const char *path, uid_t owner, gid_t group)
44 return common_chown(-1, path, true, owner, group);
48 int
49 lchown(const char *path, uid_t owner, gid_t group)
51 return common_chown(-1, path, false, owner, group);
55 int
56 fchown(int fd, uid_t owner, gid_t group)
58 return common_chown(fd, NULL, false, owner, group);
62 int
63 fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
65 return common_chown(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, owner,
66 group);