summaryrefslogtreecommitdiff
path: root/glnx-fdio.c
diff options
context:
space:
mode:
authorJonathan Lebon <jonathan@jlebon.com>2021-02-09 16:08:02 -0500
committerJonathan Lebon <jonathan@jlebon.com>2021-02-09 16:24:10 -0500
commit1345882d6a5fc3ea851bfe5510e79861d511c25e (patch)
tree3f091df1acc37cbed8cf335e45fbb5b7d5bb80cf /glnx-fdio.c
parent900caea698690b18db4f2a9cd2c3abb4f84f10b5 (diff)
downloadlibglnx-1345882d6a5fc3ea851bfe5510e79861d511c25e.tar.gz
glnx_file_copy_at: Add GLNX_FILE_COPY_NOCHOWN
In some contexts, we may want to copy a root-owned file but we're not running as root so we can't `fchown` it. (The case I'm interested in is actually a bit more obscure than this: running in a supermin VM as root, and wanting to copy a file we created onto a 9p mount where we don't have perms to `fchown`). Add a `GLNX_FILE_COPY_NOCHOWN` to handle this case.
Diffstat (limited to 'glnx-fdio.c')
-rw-r--r--glnx-fdio.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c
index d4eeb24..3fa73b5 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -1000,8 +1000,11 @@ glnx_file_copy_at (int src_dfd,
if (glnx_regfile_copy_bytes (src_fd, tmp_dest.fd, (off_t) -1) < 0)
return glnx_throw_errno_prefix (error, "regfile copy");
- if (fchown (tmp_dest.fd, src_stbuf->st_uid, src_stbuf->st_gid) != 0)
- return glnx_throw_errno_prefix (error, "fchown");
+ if (!(copyflags & GLNX_FILE_COPY_NOCHOWN))
+ {
+ if (fchown (tmp_dest.fd, src_stbuf->st_uid, src_stbuf->st_gid) != 0)
+ return glnx_throw_errno_prefix (error, "fchown");
+ }
if (!(copyflags & GLNX_FILE_COPY_NOXATTRS))
{