diff options
Diffstat (limited to 'ports/unix/guts/fchown.c')
-rw-r--r-- | ports/unix/guts/fchown.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ports/unix/guts/fchown.c b/ports/unix/guts/fchown.c new file mode 100644 index 0000000..c36a869 --- /dev/null +++ b/ports/unix/guts/fchown.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_fchown(int fd, uid_t owner, gid_t group) { + * int rc = -1; + */ + pseudo_msg_t *msg; + struct stat buf; + int save_errno; + + if (real_fstat(fd, &buf) == -1) { + save_errno = errno; + pseudo_debug(2, "fchown failing because fstat failed: %s\n", + strerror(errno)); + errno = save_errno; + return -1; + } + if (owner == (uid_t) -1 || group == (gid_t) -1) { + msg = pseudo_client_op_plain(OP_STAT, 0, fd, -1, NULL, &buf); + /* copy in any existing values... */ + if (msg) { + if (msg->result == RESULT_SUCCEED) { + pseudo_stat_msg_plain(&buf, msg); + } else { + pseudo_debug(2, "fchown fd %d, ino %llu, unknown file.\n", + fd, (unsigned long long) buf.st_ino); + } + } else { + pseudo_diag("stat within chown of fd %d [%llu] failed.\n", + fd, (unsigned long long) buf.st_ino); + } + } + /* now override with arguments */ + if (owner != (uid_t) -1) { + buf.st_uid = owner; + } + if (group != (gid_t) -1) { + buf.st_gid = group; + } + pseudo_debug(2, "fchown, fd %d: %d:%d -> %d:%d\n", + fd, owner, group, buf.st_uid, buf.st_gid); + msg = pseudo_client_op_plain(OP_FCHOWN, 0, fd, -1, 0, &buf); + if (msg && msg->result != RESULT_SUCCEED) { + errno = EPERM; + rc = -1; + } else { + /* just pretend we worked */ + rc = 0; + } + +/* return rc; + * } + */ |