From: Martin Matuska Date: Thu, 14 Mar 2019 21:52:39 +0000 (+0100) Subject: If not root do not try to restore SF_* file flags on FreeBSD and Mac OS X-Git-Tag: v3.4.0~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f759ffd2ca5e509f61f8e3be269944e274a5025;p=thirdparty%2Flibarchive.git If not root do not try to restore SF_* file flags on FreeBSD and Mac OS --- diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index e5518f295..842480837 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -3618,8 +3618,9 @@ set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, mode_t mode, unsigned long set, unsigned long clear) { int r; - + int sf_mask = 0; (void)mode; /* UNUSED */ + if (set == 0 && clear == 0) return (ARCHIVE_OK); @@ -3634,6 +3635,23 @@ set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, a->st.st_flags &= ~clear; a->st.st_flags |= set; + + /* Only super-user may change SF_* flags */ +#ifdef SF_APPEND + sf_mask |= SF_APPEND; +#endif +#ifdef SF_ARCHIVED + sf_mask |= SF_ARCHIVED; +#endif +#ifdef SF_IMMUTABLE + sf_mask |= SF_IMMUTABLE; +#endif +#ifdef SF_NOUNLINK + sf_mask |= SF_NOUNLINK; +#endif + if (a->user_uid != 0) + a->st.st_flags &= ~sf_mask; + #ifdef HAVE_FCHFLAGS /* If platform has fchflags() and we were given an fd, use it. */ if (fd >= 0 && fchflags(fd, a->st.st_flags) == 0)