diff options
author | Jonathan Lebon <jonathan@jlebon.com> | 2021-02-09 16:08:02 -0500 |
---|---|---|
committer | Jonathan Lebon <jonathan@jlebon.com> | 2021-02-09 16:24:10 -0500 |
commit | 1345882d6a5fc3ea851bfe5510e79861d511c25e (patch) | |
tree | 3f091df1acc37cbed8cf335e45fbb5b7d5bb80cf | |
parent | 900caea698690b18db4f2a9cd2c3abb4f84f10b5 (diff) | |
download | libglnx-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.
-rw-r--r-- | glnx-fdio.c | 7 | ||||
-rw-r--r-- | glnx-fdio.h | 3 |
2 files changed, 7 insertions, 3 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)) { diff --git a/glnx-fdio.h b/glnx-fdio.h index 40931bf..3d1f024 100644 --- a/glnx-fdio.h +++ b/glnx-fdio.h @@ -189,7 +189,8 @@ glnx_regfile_copy_bytes (int fdf, int fdt, off_t max_bytes); typedef enum { GLNX_FILE_COPY_OVERWRITE = (1 << 0), GLNX_FILE_COPY_NOXATTRS = (1 << 1), - GLNX_FILE_COPY_DATASYNC = (1 << 2) + GLNX_FILE_COPY_DATASYNC = (1 << 2), + GLNX_FILE_COPY_NOCHOWN = (1 << 3) } GLnxFileCopyFlags; gboolean |