From: Martin Matuska Date: Mon, 4 Mar 2019 13:58:06 +0000 (+0100) Subject: archive_write_disk_posix: processes with CAP_CHOWN may change file owner X-Git-Tag: v3.4.0~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7130b9d4c99bef39a6a6d03f5fc5909a7afd809a;p=thirdparty%2Flibarchive.git archive_write_disk_posix: processes with CAP_CHOWN may change file owner Fixes #1144 --- diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 1fa4bb176..e5518f295 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -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);