]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
On some platforms, the GID bit is inherited by subdirectories.
authorTim Kientzle <kientzle@gmail.com>
Sat, 14 Jun 2008 15:11:37 +0000 (11:11 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 14 Jun 2008 15:11:37 +0000 (11:11 -0400)
This caused a lot of false failures in the libarchive test
harness.  Be a little more careful:  the GID bit on created
directories should only be checked if ARCHIVE_EXTRACT_PERM
was used when the dir was created.
Submitted by: Carey Evans

SVN-Revision: 115

libarchive/test/test_read_extract.c
libarchive/test/test_write_disk.c
libarchive/test/test_write_disk_perms.c
libarchive/test/test_write_disk_secure.c

index bd42fd0c9677783c0f7308eb105aff344b3779be..36976b0bccf890fa479f9d4477d6adcec8928c3d 100644 (file)
@@ -135,12 +135,18 @@ DEFINE_TEST(test_read_extract)
 #endif
 
        /* Test the entries on disk. */
+       /* This first entry was extracted with ARCHIVE_EXTRACT_PERM,
+        * so the permissions should have been restored exactly,
+        * including resetting the gid bit on those platforms
+        * where gid is inherited by subdirs. */
        assert(0 == stat("dir_0775", &st));
        failure("This was 0775 in archive, and should be 0775 on disk");
-       assert(st.st_mode == (S_IFDIR | 0775));
+       assertEqualInt(st.st_mode, S_IFDIR | 0775);
+       /* Everything else was extracted without ARCHIVE_EXTRACT_PERM,
+        * so there may be some sloppiness about gid bits on directories. */
        assert(0 == stat("file", &st));
        failure("st.st_mode=%o should be %o", st.st_mode, S_IFREG | 0755);
-       assert(st.st_mode == (S_IFREG | 0755));
+       assertEqualInt(st.st_mode, S_IFREG | 0755);
        failure("The file extracted to disk is the wrong size.");
        assert(st.st_size == FILE_BUFF_SIZE);
        fd = open("file", O_RDONLY);
@@ -153,23 +159,26 @@ DEFINE_TEST(test_read_extract)
        assert(memcmp(buff, file_buff, FILE_BUFF_SIZE) == 0);
        assert(0 == stat("dir", &st));
        failure("This was 0777 in archive, but umask should make it 0755");
-       assert(st.st_mode == (S_IFDIR | 0755));
+       /* If EXTRACT_PERM wasn't used, be careful to ignore sgid bit
+        * when checking dir modes, as some systems inherit sgid bit
+        * from the parent dir. */
+       assertEqualInt(0755, st.st_mode & 0777);
        assert(0 == stat("dir/file", &st));
        assert(st.st_mode == (S_IFREG | 0700));
        assert(0 == stat("dir2", &st));
-       assert(st.st_mode == (S_IFDIR | 0755));
+       assertEqualInt(0755, st.st_mode & 0777);
        assert(0 == stat("dir2/file", &st));
        assert(st.st_mode == (S_IFREG | 0000));
        assert(0 == stat("dir3", &st));
-       assert(st.st_mode == (S_IFDIR | 0710));
+       assertEqualInt(0710, st.st_mode & 0777);
        assert(0 == stat("dir4", &st));
-       assert(st.st_mode == (S_IFDIR | 0755));
+       assertEqualInt(0755, st.st_mode & 0777);
        assert(0 == stat("dir4/a", &st));
-       assert(st.st_mode == (S_IFDIR | 0755));
+       assertEqualInt(0755, st.st_mode & 0777);
        assert(0 == stat("dir4/b", &st));
-       assert(st.st_mode == (S_IFDIR | 0755));
+       assertEqualInt(0755, st.st_mode & 0777);
        assert(0 == stat("dir4/c", &st));
-       assert(st.st_mode == (S_IFDIR | 0711));
+       assertEqualInt(0711, st.st_mode & 0777);
        assert(0 == lstat("symlink", &st));
        assert(S_ISLNK(st.st_mode));
 #if HAVE_LCHMOD
index 480cf29b56616564535d8075aa93d33fd9e26b27..0576c8ca528ba208a545f4fc94a839edc4084f74 100644 (file)
@@ -48,7 +48,11 @@ static void create(struct archive_entry *ae, const char *msg)
        assert(0 == stat(archive_entry_pathname(ae), &st));
        failure("st.st_mode=%o archive_entry_mode(ae)=%o",
            st.st_mode, archive_entry_mode(ae));
-       assert(st.st_mode == (archive_entry_mode(ae) & ~UMASK));
+       /* When verifying a dir, ignore the S_ISGID bit, as some systems set
+        * that automatically. */
+       if (archive_entry_filetype(ae) == AE_IFDIR)
+               st.st_mode &= ~S_ISGID;
+       assertEqualInt(st.st_mode, archive_entry_mode(ae) & ~UMASK);
 }
 
 static void create_reg_file(struct archive_entry *ae, const char *msg)
index 4c03c75b4919506c5130d8b8f40223a7947631a8..e0ca9f4bab64bb323ceb267b57ca3ced830399cc 100644 (file)
@@ -186,7 +186,7 @@ DEFINE_TEST(test_write_disk_perms)
        /* Check original perms. */
        assert(0 == stat("dir_overwrite_0744", &st));
        failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode);
-       assert((st.st_mode & 07777) == 0744);
+       assert((st.st_mode & 0777) == 0744);
        /* Overwrite shouldn't edit perms. */
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir_overwrite_0744");
@@ -197,7 +197,7 @@ DEFINE_TEST(test_write_disk_perms)
        /* Make sure they're unchanged. */
        assert(0 == stat("dir_overwrite_0744", &st));
        failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode);
-       assert((st.st_mode & 07777) == 0744);
+       assert((st.st_mode & 0777) == 0744);
 
        /* Write a regular file with SUID bit, but don't use _EXTRACT_PERM. */
        assert((ae = archive_entry_new()) != NULL);
@@ -385,7 +385,7 @@ DEFINE_TEST(test_write_disk_perms)
 
        assert(0 == stat("dir_overwrite_0744", &st));
        failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode);
-       assert((st.st_mode & 07777) == 0744);
+       assert((st.st_mode & 0777) == 0744);
 
        assert(0 == stat("file_no_suid", &st));
        failure("file_0755: st.st_mode=%o", st.st_mode);
index 80876b46c4c258b621cee1c174dc4898a9fa1bb8..2de3efbfa1b8bdc57187bdd5a1563d823a76d306 100644 (file)
@@ -115,7 +115,7 @@ DEFINE_TEST(test_write_disk_secure)
        /* Test the entries on disk. */
        assert(0 == lstat("dir", &st));
        failure("dir: st.st_mode=%o", st.st_mode);
-       assert((st.st_mode & 07777) == 0755);
+       assert((st.st_mode & 0777) == 0755);
 
        assert(0 == lstat("link_to_dir", &st));
        failure("link_to_dir: st.st_mode=%o", st.st_mode);
@@ -137,7 +137,7 @@ DEFINE_TEST(test_write_disk_secure)
        failure("link_to_dir2 should have been re-created as a true dir");
        assert(S_ISDIR(st.st_mode));
        failure("link_to_dir2: Implicit dir creation should obey umask, but st.st_mode=%o", st.st_mode);
-       assert((st.st_mode & 07777) == 0755);
+       assert((st.st_mode & 0777) == 0755);
 
        assert(0 == lstat("link_to_dir2/filec", &st));
        assert(S_ISREG(st.st_mode));