]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_write_disk_posix: processes with CAP_CHOWN may change file owner
authorMartin Matuska <martin@matuska.org>
Mon, 4 Mar 2019 13:58:06 +0000 (14:58 +0100)
committerMartin Matuska <martin@matuska.org>
Mon, 4 Mar 2019 15:57:46 +0000 (16:57 +0100)
Fixes #1144

libarchive/archive_write_disk_posix.c

index 1fa4bb176e9cdcd4ecd59fa775eb319d22b225c3..e5518f295613cb4a023fa0326db0ecc66f4085ff 100644 (file)
@@ -3131,12 +3131,14 @@ create_dir(struct archive_write_disk *a, char *path)
 static int
 set_ownership(struct archive_write_disk *a)
 {
-#ifndef __CYGWIN__
-/* unfortunately, on win32 there is no 'root' user with uid 0,
-   so we just have to try the chown and see if it works */
-
-       /* If we know we can't change it, don't bother trying. */
-       if (a->user_uid != 0  &&  a->user_uid != a->uid) {
+#if !defined(__CYGWIN__) && !defined(__linux__)
+/*
+ * On Linux, a process may have the CAP_CHOWN capability.
+ * On Windows there is no 'root' user with uid 0.
+ * Elsewhere we can skip calling chown if we are not root and the desired
+ * user id does not match the current user.
+ */
+       if (a->user_uid != 0 && a->user_uid != a->uid) {
                archive_set_error(&a->archive, errno,
                    "Can't set UID=%jd", (intmax_t)a->uid);
                return (ARCHIVE_WARN);