1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#include "test.h"
26
27/*
28Execute the following command to rebuild the data for this program:
29   tail -n +32 test_read_format_isozisofs_bz2.c | /bin/sh
30
31rm -rf /tmp/iso /tmp/ziso
32mkdir /tmp/iso
33mkdir /tmp/iso/dir
34echo "hello" >/tmp/iso/file
35dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file
36ln /tmp/iso/file /tmp/iso/hardlink
37(cd /tmp/iso; ln -s file symlink)
38(cd /tmp/iso; ln -s /tmp/ symlink2)
39(cd /tmp/iso; ln -s /tmp/../ symlink3)
40(cd /tmp/iso; ln -s .././../tmp/ symlink4)
41TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
42TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
43mkzftree /tmp/iso /tmp/ziso
44TZ=utc touch -afhm -t 197001020000.01 /tmp/ziso /tmp/ziso/file /tmp/ziso/dir
45TZ=utc touch -afhm -t 197001030000.02 /tmp/ziso/symlink
46F=test_read_format_iso_zisofs.iso.Z
47mkhybrid -R -uid 1 -gid 2 -z /tmp/ziso | compress > $F
48uuencode $F $F > $F.uu
49exit 1
50
51 */
52
53DEFINE_TEST(test_read_format_isozisofs_bz2)
54{
55	const char *refname = "test_read_format_iso_zisofs.iso.Z";
56	struct archive_entry *ae;
57	struct archive *a;
58	const void *p;
59	size_t size;
60	int64_t offset;
61	int i;
62
63	extract_reference_file(refname);
64	assert((a = archive_read_new()) != NULL);
65	assertEqualInt(0, archive_read_support_filter_all(a));
66	assertEqualInt(0, archive_read_support_format_all(a));
67	assertEqualInt(ARCHIVE_OK,
68	    archive_read_open_filename(a, refname, 10240));
69
70	/* Retrieve each of the 8 files on the ISO image and
71	 * verify that each one is what we expect. */
72	for (i = 0; i < 8; ++i) {
73		assertEqualInt(0, archive_read_next_header(a, &ae));
74
75		assertEqualInt(archive_entry_is_encrypted(ae), 0);
76		assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
77
78		if (strcmp(".", archive_entry_pathname(ae)) == 0) {
79			/* '.' root directory. */
80			assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
81			assertEqualInt(2048, archive_entry_size(ae));
82			/* Now, we read timestamp recorded by RRIP "TF". */
83			assertEqualInt(86401, archive_entry_mtime(ae));
84			assertEqualInt(0, archive_entry_mtime_nsec(ae));
85			/* Now, we read links recorded by RRIP "PX". */
86			assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
87			assertEqualInt(1, archive_entry_uid(ae));
88			assertEqualIntA(a, ARCHIVE_EOF,
89			    archive_read_data_block(a, &p, &size, &offset));
90			assertEqualInt((int)size, 0);
91		} else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
92			/* A directory. */
93			assertEqualString("dir", archive_entry_pathname(ae));
94			assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
95			assertEqualInt(2048, archive_entry_size(ae));
96			assertEqualInt(86401, archive_entry_mtime(ae));
97			assertEqualInt(86401, archive_entry_atime(ae));
98			assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
99			assertEqualInt(1, archive_entry_uid(ae));
100			assertEqualInt(2, archive_entry_gid(ae));
101		} else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
102			int r;
103			/* A regular file. */
104			assertEqualString("file", archive_entry_pathname(ae));
105			assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
106			assertEqualInt(12345684, archive_entry_size(ae));
107			r = archive_read_data_block(a, &p, &size, &offset);
108			if (r == ARCHIVE_FAILED) {
109			  skipping("Can't read body of ZISOFS entry.");
110			} else {
111			  assertEqualInt(ARCHIVE_OK, r);
112			  assertEqualInt(0, offset);
113			  assertEqualMem(p, "hello\n", 6);
114			}
115			assertEqualInt(86401, archive_entry_mtime(ae));
116			assertEqualInt(86401, archive_entry_atime(ae));
117			assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
118			assertEqualInt(1, archive_entry_uid(ae));
119			assertEqualInt(2, archive_entry_gid(ae));
120		} else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) {
121			/* A hardlink to the regular file. */
122			/* Note: If "hardlink" gets returned before "file",
123			 * then "hardlink" will get returned as a regular file
124			 * and "file" will get returned as the hardlink.
125			 * This test should tolerate that, since it's a
126			 * perfectly permissible thing for libarchive to do. */
127			assertEqualString("hardlink", archive_entry_pathname(ae));
128			assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
129			assertEqualString("file", archive_entry_hardlink(ae));
130			assertEqualInt(0, archive_entry_size_is_set(ae));
131			assertEqualInt(0, archive_entry_size(ae));
132			assertEqualInt(86401, archive_entry_mtime(ae));
133			assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
134			assertEqualInt(1, archive_entry_uid(ae));
135			assertEqualInt(2, archive_entry_gid(ae));
136		} else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) {
137			/* A symlink to the regular file. */
138			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
139			assertEqualString("file", archive_entry_symlink(ae));
140			assertEqualInt(0, archive_entry_size(ae));
141			assertEqualInt(172802, archive_entry_mtime(ae));
142			assertEqualInt(172802, archive_entry_atime(ae));
143			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
144			assertEqualInt(1, archive_entry_uid(ae));
145			assertEqualInt(2, archive_entry_gid(ae));
146		} else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) {
147			/* A symlink to /tmp (an absolute path) */
148			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
149			assertEqualString("/tmp", archive_entry_symlink(ae));
150			assertEqualInt(0, archive_entry_size(ae));
151			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
152			assertEqualInt(1, archive_entry_uid(ae));
153			assertEqualInt(2, archive_entry_gid(ae));
154		} else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) {
155			/* A symlink to /tmp/.. (with a ".." component) */
156			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
157			assertEqualString("/tmp/..", archive_entry_symlink(ae));
158			assertEqualInt(0, archive_entry_size(ae));
159			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
160			assertEqualInt(1, archive_entry_uid(ae));
161			assertEqualInt(2, archive_entry_gid(ae));
162		} else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) {
163			/* A symlink to a path with ".." and "." components */
164			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
165			assertEqualString(".././../tmp",
166			    archive_entry_symlink(ae));
167			assertEqualInt(0, archive_entry_size(ae));
168			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
169			assertEqualInt(1, archive_entry_uid(ae));
170			assertEqualInt(2, archive_entry_gid(ae));
171		} else {
172			failure("Saw a file that shouldn't have been there");
173			assertEqualString(archive_entry_pathname(ae), "");
174		}
175	}
176
177	/* End of archive. */
178	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
179
180	/* Verify archive format. */
181	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
182	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
183
184	/* Close the archive. */
185	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
186	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
187}
188
189
190