static void run_tar(const char *target, const char *pack_options, const char *unpack_options, const char *flist) { int r; assertMakeDir(target, 0775); /* Use the tar program to create an archive. */ r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); failure("Error invoking %s cf -", testprog, pack_options); assertEqualInt(r, 0); assertChdir(target); /* Verify that nothing went to stderr. */ assertEmptyFile("pack.err"); /* * Use tar to unpack the archive into another directory. */ r = systemf("%s xf archive %s >unpack.out 2>unpack.err", testprog, unpack_options); failure("Error invoking %s xf archive %s", testprog, unpack_options); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ assertEmptyFile("unpack.err"); assertChdir(".."); }
/* * We should get a warning if the contents file doesn't exist. */ static void test_read_format_mtree5(void) { static char archive[] = "#mtree\n" "a type=file contents=nonexistent_file\n"; struct archive_entry *ae; struct archive *a; assertMakeDir("mtree5", 0777); assertChdir("mtree5"); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assert(strlen(archive_error_string(a)) > 0); assertEqualString(archive_entry_pathname(ae), "a"); assertEqualInt(archive_entry_filetype(ae), AE_IFREG); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(1, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); assertChdir(".."); }
static const char * make_files(void) { FILE *f; /* File with 10 bytes content. */ f = fopen("file", "wb"); assert(f != NULL); assertEqualInt(10, fwrite("123456789", 1, 10, f)); fclose(f); /* hardlink to above file. */ assertMakeHardlink("linkfile", "file"); assertIsHardlink("file", "linkfile"); /* Symlink to above file. */ if (canSymlink()) assertMakeSymlink("symlink", "file", 0); /* Directory. */ assertMakeDir("dir", 0775); return canSymlink() ? "file linkfile symlink dir" : "file linkfile dir"; }
static void passthrough(const char *target) { int r; if (!assertMakeDir(target, 0775)) return; /* * Use cpio passthrough mode to copy files to another directory. */ r = systemf("%s -p %s <filelist >%s/stdout 2>%s/stderr", testprog, target, target, target); failure("Error invoking %s -p", testprog); assertEqualInt(r, 0); assertChdir(target); /* Verify stderr. */ failure("Error invoking %s -p in dir %s", testprog, target); assertTextFileContents("1 block\n", "stderr"); verify_files("passthrough"); assertChdir(".."); }
/* * Unpack the archive in a new dir. */ static void unpack(const char *dirname, const char *option) { int r; assertMakeDir(dirname, 0755); assertChdir(dirname); extract_reference_file("test_option_f.cpio"); r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option); assertEqualInt(0, r); assertChdir(".."); }
static void unpack_test(const char *from, const char *options, const char *se) { int r; /* Create a work dir named after the file we're unpacking. */ assertMakeDir(from, 0775); assertChdir(from); /* * Use cpio to unpack the sample archive */ extract_reference_file(from); r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", testprog, options, from); failure("Error invoking %s -i %s < %s", testprog, options, from); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ if (canSymlink()) { failure("Error invoking %s -i %s < %s", testprog, options, from); assertTextFileContents(se, "unpack.err"); } /* * Verify unpacked files. */ /* Regular file with 2 links. */ assertIsReg("file", 0644); failure("%s", from); assertFileSize("file", 10); assertFileSize("linkfile", 10); failure("%s", from); assertFileNLinks("file", 2); /* Another name for the same file. */ failure("%s", from); assertIsHardlink("linkfile", "file"); assertFileSize("file", 10); assertFileSize("linkfile", 10); /* Symlink */ if (canSymlink()) assertIsSymlink("symlink", "file"); /* dir */ assertIsDir("dir", 0775); assertChdir(".."); }
static void create_tree(void) { char buff[260]; char buff2[260]; int i; int LOOP_MAX; compute_filenames(); /* Log that we'll be omitting some checks. */ if (!canSymlink()) { skipping("Symlink checks"); } assertMakeDir("original", 0775); assertEqualInt(0, chdir("original")); LOOP_MAX = compute_loop_max(); assertMakeDir("f", 0775); assertMakeDir("l", 0775); assertMakeDir("m", 0775); assertMakeDir("s", 0775); assertMakeDir("d", 0775); for (i = 1; i < LOOP_MAX; i++) { failure("Internal sanity check failed: i = %d", i); assert(filenames[i] != NULL); sprintf(buff, "f/%s", filenames[i]); assertMakeFile(buff, 0777, buff); /* Create a link named "l/abcdef..." to the above. */ sprintf(buff2, "l/%s", filenames[i]); assertMakeHardlink(buff2, buff); /* Create a link named "m/abcdef..." to the above. */ sprintf(buff2, "m/%s", filenames[i]); assertMakeHardlink(buff2, buff); if (canSymlink()) { /* Create a symlink named "s/abcdef..." to the above. */ sprintf(buff, "s/%s", filenames[i]); sprintf(buff2, "../f/%s", filenames[i]); failure("buff=\"%s\" buff2=\"%s\"", buff, buff2); assertMakeSymlink(buff, buff2); } /* Create a dir named "d/abcdef...". */ buff[0] = 'd'; failure("buff=\"%s\"", buff); assertMakeDir(buff, 0775); } assertEqualInt(0, chdir("..")); }
static void basic_tar(const char *target, const char *pack_options, const char *unpack_options, const char *flist) { int r; assertMakeDir(target, 0775); /* Use the tar program to create an archive. */ r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); failure("Error invoking %s cf -", testprog, pack_options); assertEqualInt(r, 0); assertChdir(target); /* Verify that nothing went to stderr. */ assertEmptyFile("pack.err"); /* * Use tar to unpack the archive into another directory. */ r = systemf("%s xf archive %s >unpack.out 2>unpack.err", testprog, unpack_options); failure("Error invoking %s xf archive %s", testprog, unpack_options); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ assertEmptyFile("unpack.err"); /* * Verify unpacked files. */ /* Regular file with 2 links. */ assertIsReg("file", -1); assertFileSize("file", 10); failure("%s", target); assertFileNLinks("file", 2); /* Another name for the same file. */ assertIsReg("linkfile", -1); assertFileSize("linkfile", 10); assertFileNLinks("linkfile", 2); assertIsHardlink("file", "linkfile"); /* Symlink */ if (canSymlink()) assertIsSymlink("symlink", "file"); /* dir */ assertIsDir("dir", 0775); assertChdir(".."); }
static void copy_ustar(void) { const char *target = "ustar"; int r; /* NOTE: for proper operation on cygwin-1.5 and windows, the * length of the name of the directory below, "ustar", must be * less than or equal to the lengthe of the name of the original * directory, "original" This restriction derives from the * extremely limited pathname lengths on those platforms. */ assertMakeDir(target, 0775); assertEqualInt(0, chdir(target)); /* * Use the tar program to create an archive. */ r = systemf("%s cf archive --format=ustar -C ../original f d l m s >pack.out 2>pack.err", testprog); failure("Error invoking \"%s cf archive --format=ustar\"", testprog); assertEqualInt(r, 0); /* Verify that nothing went to stdout. */ assertEmptyFile("pack.out"); /* Stderr is non-empty, since there are a bunch of files * with filenames too long to archive. */ /* * Use tar to unpack the archive into another directory. */ r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); failure("Error invoking %s xf archive", testprog); assertEqualInt(r, 0); /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("unpack.err"); assertEmptyFile("unpack.out"); verify_tree(LIMIT_USTAR); assertEqualInt(0, chdir("../..")); }
static void copy_basic(void) { int r; /* NOTE: for proper operation on cygwin-1.5 and windows, the * length of the name of the directory below, "plain", must be * less than or equal to the lengthe of the name of the original * directory, "original" This restriction derives from the * extremely limited pathname lengths on those platforms. */ assertMakeDir("plain", 0775); assertEqualInt(0, chdir("plain")); /* * Use the tar program to create an archive. */ r = systemf("%s cf archive -C ../original f d l m s >pack.out 2>pack.err", testprog); failure("Error invoking \"%s cf\"", testprog); assertEqualInt(r, 0); /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("pack.err"); assertEmptyFile("pack.out"); /* * Use tar to unpack the archive into another directory. */ r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); failure("Error invoking %s xf archive", testprog); assertEqualInt(r, 0); /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("unpack.err"); assertEmptyFile("unpack.out"); verify_tree(LIMIT_NONE); assertEqualInt(0, chdir("..")); }
static void basic_cpio(const char *target, const char *pack_options, const char *unpack_options, const char *se, const char *se2) { int r; if (!assertMakeDir(target, 0775)) return; /* Use the cpio program to create an archive. */ r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err", testprog, pack_options, target, target); failure("Error invoking %s -o %s", testprog, pack_options); assertEqualInt(r, 0); assertChdir(target); /* Verify stderr. */ failure("Expected: %s, options=%s", se, pack_options); assertTextFileContents(se, "pack.err"); /* * Use cpio to unpack the archive into another directory. */ r = systemf("%s -i %s< archive >unpack.out 2>unpack.err", testprog, unpack_options); failure("Error invoking %s -i %s", testprog, unpack_options); assertEqualInt(r, 0); /* Verify stderr. */ failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target); assertTextFileContents(se2, "unpack.err"); verify_files(pack_options); assertChdir(".."); }
/* * Reported to libarchive.googlecode.com as Issue 121. */ static void test_read_format_mtree3(void) { static char archive[] = "#mtree\n" "a type=file contents=file\n" "b type=link link=a\n" "c type=file contents=file\n"; struct archive_entry *ae; struct archive *a; assertMakeDir("mtree3", 0777); assertChdir("mtree3"); assertMakeFile("file", 0644, "file contents"); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "a"); assertEqualInt(archive_entry_filetype(ae), AE_IFREG); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "b"); assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "c"); assertEqualInt(archive_entry_filetype(ae), AE_IFREG); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(3, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); assertChdir(".."); }
compare_acls(acl_t acl, struct archive_test_acl_t *myacls, int n) #endif { int *marker; int matched; int i; #if HAVE_SUN_ACL int e; aclent_t *acl_entry; #else int entry_id = ACL_FIRST_ENTRY; acl_entry_t acl_entry; #endif /* Count ACL entries in myacls array and allocate an indirect array. */ marker = malloc(sizeof(marker[0]) * n); if (marker == NULL) return; for (i = 0; i < n; i++) marker[i] = i; /* * Iterate over acls in system acl object, try to match each * one with an item in the myacls array. */ #if HAVE_SUN_ACL for(e = 0; e < acl->acl_cnt; e++) { acl_entry = &((aclent_t *)acl->acl_aclp)[e]; #else while (1 == acl_get_entry(acl, entry_id, &acl_entry)) { /* After the first time... */ entry_id = ACL_NEXT_ENTRY; #endif /* Search for a matching entry (tag and qualifier) */ for (i = 0, matched = 0; i < n && !matched; i++) { if (acl_match(acl_entry, &myacls[marker[i]])) { /* We found a match; remove it. */ marker[i] = marker[n - 1]; n--; matched = 1; } } /* TODO: Print out more details in this case. */ failure("ACL entry on file that shouldn't be there"); assert(matched == 1); } /* Dump entries in the myacls array that weren't in the system acl. */ for (i = 0; i < n; ++i) { failure(" ACL entry missing from file: " "type=%#010x,permset=%#010x,tag=%d,qual=%d,name=``%s''\n", myacls[marker[i]].type, myacls[marker[i]].permset, myacls[marker[i]].tag, myacls[marker[i]].qual, myacls[marker[i]].name); assert(0); /* Record this as a failure. */ } free(marker); } #endif /* * Verify ACL restore-to-disk. This test is Platform-specific. */ DEFINE_TEST(test_acl_platform_posix1e_restore) { #if !HAVE_SUN_ACL && !HAVE_POSIX_ACL skipping("POSIX.1e ACLs are not supported on this platform"); #else /* HAVE_SUN_ACL || HAVE_POSIX_ACL */ struct stat st; struct archive *a; struct archive_entry *ae; int n, fd; char *func; #if HAVE_SUN_ACL acl_t *acl, *acl2; #else acl_t acl; #endif /* * First, do a quick manual set/read of ACL data to * verify that the local filesystem does support ACLs. * If it doesn't, we'll simply skip the remaining tests. */ #if HAVE_SUN_ACL n = acl_fromtext("user::rwx,user:1:rw-,group::rwx,group:15:r-x,other:rwx,mask:rwx", &acl); failure("acl_fromtext(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); #else acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx"); failure("acl_from_text(): errno = %d (%s)", errno, strerror(errno)); assert((void *)acl != NULL); #endif /* Create a test file and try ACL on it. */ fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777); failure("Could not create test file?!"); if (!assert(fd >= 0)) { acl_free(acl); return; } #if HAVE_SUN_ACL n = facl_get(fd, 0, &acl2); if (n != 0) { close(fd); acl_free(acl); } if (errno == ENOSYS) { skipping("POSIX.1e ACLs are not supported on this filesystem"); return; } failure("facl_get(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); if (acl2->acl_type != ACLENT_T) { acl_free(acl2); skipping("POSIX.1e ACLs are not supported on this filesystem"); return; } acl_free(acl2); func = "facl_set()"; n = facl_set(fd, acl); #else func = "acl_set_fd()"; n = acl_set_fd(fd, acl); #endif acl_free(acl); if (n != 0) { #if HAVE_SUN_ACL if (errno == ENOSYS) #else if (errno == EOPNOTSUPP || errno == EINVAL) #endif { close(fd); skipping("POSIX.1e ACLs are not supported on this filesystem"); return; } } failure("%s: errno = %d (%s)", func, errno, strerror(errno)); assertEqualInt(0, n); #if HAVE_SUN_ACL #endif close(fd); /* Create a write-to-disk object. */ assert(NULL != (a = archive_write_disk_new())); archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL); /* Populate an archive entry with some metadata, including ACL info */ ae = archive_entry_new(); assert(ae != NULL); archive_entry_set_pathname(ae, "test0"); archive_entry_set_mtime(ae, 123456, 7890); archive_entry_set_size(ae, 0); assertEntrySetAcls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); archive_entry_free(ae); /* Close the archive. */ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); assertEqualInt(ARCHIVE_OK, archive_write_free(a)); /* Verify the data on disk. */ assertEqualInt(0, stat("test0", &st)); assertEqualInt(st.st_mtime, 123456); #if HAVE_SUN_ACL n = acl_get("test0", 0, &acl); failure("acl_get(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); #else acl = acl_get_file("test0", ACL_TYPE_ACCESS); failure("acl_get_file(): errno = %d (%s)", errno, strerror(errno)); assert(acl != (acl_t)NULL); #endif compare_acls(acl, acls2, sizeof(acls2)/sizeof(acls2[0])); acl_free(acl); #endif /* HAVE_SUN_ACL || HAVE_POSIX_ACL */ } /* * Verify ACL read-from-disk. This test is Platform-specific. */ DEFINE_TEST(test_acl_platform_posix1e_read) { #if !HAVE_SUN_ACL && !HAVE_POSIX_ACL skipping("POSIX.1e ACLs are not supported on this platform"); #else struct archive *a; struct archive_entry *ae; int n, fd, flags, dflags; char *func, *acl_text; const char *acl1_text, *acl2_text, *acl3_text; #if HAVE_SUN_ACL acl_t *acl, *acl1, *acl2, *acl3; #else acl_t acl1, acl2, acl3; #endif /* * Manually construct a directory and two files with * different ACLs. This also serves to verify that ACLs * are supported on the local filesystem. */ /* Create a test file f1 with acl1 */ #if HAVE_SUN_ACL acl1_text = "user::rwx," "group::rwx," "other:rwx," "user:1:rw-," "group:15:r-x," "mask:rwx"; n = acl_fromtext(acl1_text, &acl1); failure("acl_fromtext(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); #else acl1_text = "user::rwx\n" "group::rwx\n" "other::rwx\n" "user:1:rw-\n" "group:15:r-x\n" "mask::rwx"; acl1 = acl_from_text(acl1_text); failure("acl_from_text(): errno = %d (%s)", errno, strerror(errno)); assert((void *)acl1 != NULL); #endif fd = open("f1", O_WRONLY | O_CREAT | O_EXCL, 0777); failure("Could not create test file?!"); if (!assert(fd >= 0)) { acl_free(acl1); return; } #if HAVE_SUN_ACL /* Check if Solaris filesystem supports POSIX.1e ACLs */ n = facl_get(fd, 0, &acl); if (n != 0) close(fd); if (n != 0 && errno == ENOSYS) { acl_free(acl1); skipping("POSIX.1e ACLs are not supported on this filesystem"); return; } failure("facl_get(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); if (acl->acl_type != ACLENT_T) { acl_free(acl); acl_free(acl1); close(fd); skipping("POSIX.1e ACLs are not supported on this filesystem"); return; } func = "facl_set()"; n = facl_set(fd, acl1); #else func = "acl_set_fd()"; n = acl_set_fd(fd, acl1); #endif acl_free(acl1); if (n != 0) { #if HAVE_SUN_ACL if (errno == ENOSYS) #else if (errno == EOPNOTSUPP || errno == EINVAL) #endif { close(fd); skipping("POSIX.1e ACLs are not supported on this filesystem"); return; } } failure("%s: errno = %d (%s)", func, errno, strerror(errno)); assertEqualInt(0, n); close(fd); assertMakeDir("d", 0700); /* * Create file d/f1 with acl2 * * This differs from acl1 in the u:1: and g:15: permissions. * * This file deliberately has the same name but a different ACL. * Github Issue #777 explains how libarchive's directory traversal * did not always correctly enter directories before attempting * to read ACLs, resulting in reading the ACL from a like-named * file in the wrong directory. */ #if HAVE_SUN_ACL acl2_text = "user::rwx," "group::rwx," "other:---," "user:1:r--," "group:15:r--," "mask:rwx"; n = acl_fromtext(acl2_text, &acl2); failure("acl_fromtext(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); #else acl2_text = "user::rwx\n" "group::rwx\n" "other::---\n" "user:1:r--\n" "group:15:r--\n" "mask::rwx"; acl2 = acl_from_text(acl2_text); failure("acl_from_text(): errno = %d (%s)", errno, strerror(errno)); assert((void *)acl2 != NULL); #endif fd = open("d/f1", O_WRONLY | O_CREAT | O_EXCL, 0777); failure("Could not create test file?!"); if (!assert(fd >= 0)) { acl_free(acl2); return; } #if HAVE_SUN_ACL func = "facl_set()"; n = facl_set(fd, acl2); #else func = "acl_set_fd()"; n = acl_set_fd(fd, acl2); #endif acl_free(acl2); if (n != 0) close(fd); failure("%s: errno = %d (%s)", func, errno, strerror(errno)); assertEqualInt(0, n); close(fd); /* Create nested directory d2 with default ACLs */ assertMakeDir("d/d2", 0755); #if HAVE_SUN_ACL acl3_text = "user::rwx," "group::r-x," "other:r-x," "user:2:r--," "group:16:-w-," "mask:rwx," "default:user::rwx," "default:user:1:r--," "default:group::r-x," "default:group:15:r--," "default:mask:rwx," "default:other:r-x"; n = acl_fromtext(acl3_text, &acl3); failure("acl_fromtext(): errno = %d (%s)", errno, strerror(errno)); assertEqualInt(0, n); #else acl3_text = "user::rwx\n" "user:1:r--\n" "group::r-x\n" "group:15:r--\n" "mask::rwx\n" "other::r-x"; acl3 = acl_from_text(acl3_text); failure("acl_from_text(): errno = %d (%s)", errno, strerror(errno)); assert((void *)acl3 != NULL); #endif #if HAVE_SUN_ACL func = "acl_set()"; n = acl_set("d/d2", acl3); #else func = "acl_set_file()"; n = acl_set_file("d/d2", ACL_TYPE_DEFAULT, acl3); #endif acl_free(acl3); failure("%s: errno = %d (%s)", func, errno, strerror(errno)); assertEqualInt(0, n); /* Create a read-from-disk object. */ assert(NULL != (a = archive_read_disk_new())); assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, ".")); assert(NULL != (ae = archive_entry_new())); #if HAVE_SUN_ACL flags = ARCHIVE_ENTRY_ACL_TYPE_POSIX1E | ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA | ARCHIVE_ENTRY_ACL_STYLE_SOLARIS; dflags = flags; #else flags = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; dflags = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; #endif /* Walk the dir until we see both of the files */ while (ARCHIVE_OK == archive_read_next_header2(a, ae)) { archive_read_disk_descend(a); if (strcmp(archive_entry_pathname(ae), "./f1") == 0) { acl_text = archive_entry_acl_to_text(ae, NULL, flags); assertEqualString(acl_text, acl1_text); free(acl_text); } else if (strcmp(archive_entry_pathname(ae), "./d/f1") == 0) { acl_text = archive_entry_acl_to_text(ae, NULL, flags); assertEqualString(acl_text, acl2_text); free(acl_text); } else if (strcmp(archive_entry_pathname(ae), "./d/d2") == 0) { acl_text = archive_entry_acl_to_text(ae, NULL, dflags); assertEqualString(acl_text, acl3_text); free(acl_text); } } archive_entry_free(ae); assertEqualInt(ARCHIVE_OK, archive_free(a)); #endif }
static void test_read_format_mtree1(void) { const char reffile[] = "test_read_format_mtree.mtree"; char buff[16]; struct archive_entry *ae; struct archive *a; FILE *f; extract_reference_file(reffile); /* * An access error occurred on some platform when mtree * format handling open a directory. It is for through * the routine which open a directory that we create * "dir" and "dir2" directories. */ assertMakeDir("dir", 0775); assertMakeDir("dir2", 0775); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11)); /* * Read "file", whose data is available on disk. */ f = fopen("file", "wb"); assert(f != NULL); assertEqualInt(3, fwrite("hi\n", 1, 3, f)); fclose(f); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); assertEqualString(archive_entry_pathname(ae), "file"); assertEqualInt(archive_entry_uid(ae), 18); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); assertEqualInt(archive_entry_size(ae), 3); assertEqualInt(3, archive_read_data(a, buff, 3)); assertEqualMem(buff, "hi\n", 3); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir"); assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir/file with space"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "file with space"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3a"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2"); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/indir2"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3b"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "notindir"); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); }
static void test_read_format_mtree1(void) { const char reffile[] = "test_read_format_mtree.mtree"; char buff[16]; struct archive_entry *ae; struct archive *a; FILE *f; /* Compute max 64-bit signed twos-complement value * without relying on overflow. This assumes that long long * is at least 64 bits. */ const static long long max_int64 = ((((long long)1) << 62) - 1) + (((long long)1) << 62); time_t min_time, t; extract_reference_file(reffile); /* * An access error occurred on some platform when mtree * format handling open a directory. It is for through * the routine which open a directory that we create * "dir" and "dir2" directories. */ assertMakeDir("dir", 0775); assertMakeDir("dir2", 0775); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11)); /* * Read "file", whose data is available on disk. */ f = fopen("file", "wb"); assert(f != NULL); assertEqualInt(3, fwrite("hi\n", 1, 3, f)); fclose(f); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); assertEqualString(archive_entry_pathname(ae), "file"); assertEqualInt(archive_entry_uid(ae), 18); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); assertEqualInt(archive_entry_size(ae), 3); assertEqualInt(3, archive_read_data(a, buff, 3)); assertEqualMem(buff, "hi\n", 3); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir"); assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir/file with space"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "file with space"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3a"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2"); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/indir2"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3b"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "notindir"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/emptyfile"); assertEqualInt(archive_entry_size(ae), 0); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/smallfile"); assertEqualInt(archive_entry_size(ae), 1); /* TODO: Mtree reader should probably return ARCHIVE_WARN for this. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/toosmallfile"); assertEqualInt(archive_entry_size(ae), -1); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/bigfile"); assertEqualInt(archive_entry_size(ae), max_int64); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/toobigfile"); /* Size in mtree is max_int64 + 1; should return max_int64. */ assertEqualInt(archive_entry_size(ae), max_int64); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/veryoldfile"); /* The value in the file is MIN_INT64_T, but time_t may be narrower. */ /* Verify min_time is the smallest possible time_t. */ min_time = archive_entry_mtime(ae); assert(min_time <= 0); /* Simply asserting min_time - 1 > 0 breaks with some compiler optimizations. */ t = min_time - 1; assert(t > 0); /* toooldfile is 1 sec older, which should overflow and get returned * with the same value. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/toooldfile"); assertEqualInt(archive_entry_mtime(ae), min_time); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(19, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_read_format_mtree4(void) { const char reffile[] = "test_read_format_mtree_nomagic.mtree"; char buff[16]; struct archive_entry *ae; struct archive *a; FILE *f; assertMakeDir("mtree4", 0777); assertChdir("mtree4"); extract_reference_file(reffile); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11)); /* * Read "file", whose data is available on disk. */ f = fopen("file", "wb"); assert(f != NULL); assertEqualInt(3, fwrite("hi\n", 1, 3, f)); fclose(f); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); assertEqualString(archive_entry_pathname(ae), "file"); assertEqualInt(archive_entry_uid(ae), 18); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); assertEqualInt(archive_entry_size(ae), 3); assertEqualInt(3, archive_read_data(a, buff, 3)); assertEqualMem(buff, "hi\n", 3); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir"); assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir/file with space"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "file with space"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3a"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2"); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/indir2"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3b"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b"); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "notindir"); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(12, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); assertChdir(".."); }