]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
If not root do not try to restore SF_* file flags on FreeBSD and Mac OS
authorMartin Matuska <martin@matuska.org>
Thu, 14 Mar 2019 21:52:39 +0000 (22:52 +0100)
committerMartin Matuska <martin@matuska.org>
Thu, 14 Mar 2019 21:57:35 +0000 (22:57 +0100)
libarchive/archive_write_disk_posix.c

index e5518f295613cb4a023fa0326db0ecc66f4085ff..8424808370ed6d191cbb44735d900cc6602dc937 100644 (file)
@@ -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)