#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);
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
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)
/* 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");
/* 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);
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);
/* 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);
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));