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 /*
28 PLEASE use old cdrtools; mkisofs version is 2.01.
29 This version mkisofs made wrong "SL" System Use Entry of RRIP.
30
31 Execute the following command to rebuild the data for this program:
32 tail -n +34 test_read_format_isorr_bz2.c | /bin/sh
33
34 rm -rf /tmp/iso
35 mkdir /tmp/iso
36 mkdir /tmp/iso/dir
37 echo "hello" >/tmp/iso/file
38 dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file
39 ln /tmp/iso/file /tmp/iso/hardlink
40 (cd /tmp/iso; ln -s file symlink)
41 (cd /tmp/iso; ln -s /tmp/ symlink2)
42 (cd /tmp/iso; ln -s /tmp/../ symlink3)
43 (cd /tmp/iso; ln -s .././../tmp/ symlink4)
44 (cd /tmp/iso; ln -s .///file symlink5)
45 (cd /tmp/iso; ln -s /tmp//../ symlink6)
46 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
47 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink /tmp/iso/symlink5
48 F=test_read_format_iso_rockridge.iso.Z
49 mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F
50 uuencode $F $F > $F.uu
51 exit 1
52 */
53
DEFINE_TEST(test_read_format_isorr_bz2)54 DEFINE_TEST(test_read_format_isorr_bz2)
55 {
56 const char *refname = "test_read_format_iso_rockridge.iso.Z";
57 struct archive_entry *ae;
58 struct archive *a;
59 const void *p;
60 size_t size;
61 int64_t offset;
62 int i;
63
64 extract_reference_file(refname);
65 assert((a = archive_read_new()) != NULL);
66 assertEqualInt(0, archive_read_support_filter_all(a));
67 assertEqualInt(0, archive_read_support_format_all(a));
68 assertEqualInt(ARCHIVE_OK,
69 archive_read_open_filename(a, refname, 10240));
70
71 /* Retrieve each of the 8 files on the ISO image and
72 * verify that each one is what we expect. */
73 for (i = 0; i < 10; ++i) {
74 assertEqualInt(0, archive_read_next_header(a, &ae));
75
76 assertEqualInt(archive_entry_is_encrypted(ae), 0);
77 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
78
79 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
80 /* '.' root directory. */
81 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
82 assertEqualInt(2048, archive_entry_size(ae));
83 /* Now, we read timestamp recorded by RRIP "TF". */
84 assertEqualInt(86401, archive_entry_mtime(ae));
85 assertEqualInt(0, archive_entry_mtime_nsec(ae));
86 /* Now, we read links recorded by RRIP "PX". */
87 assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
88 assertEqualInt(1, archive_entry_uid(ae));
89 assertEqualIntA(a, ARCHIVE_EOF,
90 archive_read_data_block(a, &p, &size, &offset));
91 assertEqualInt((int)size, 0);
92 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
93 /* A directory. */
94 assertEqualString("dir", archive_entry_pathname(ae));
95 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
96 assertEqualInt(2048, archive_entry_size(ae));
97 assertEqualInt(86401, archive_entry_mtime(ae));
98 assertEqualInt(86401, archive_entry_atime(ae));
99 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
100 assertEqualInt(1, archive_entry_uid(ae));
101 assertEqualInt(2, archive_entry_gid(ae));
102 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
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 assertEqualInt(0,
108 archive_read_data_block(a, &p, &size, &offset));
109 assertEqualInt(0, offset);
110 assertEqualMem(p, "hello\n", 6);
111 assertEqualInt(86401, archive_entry_mtime(ae));
112 assertEqualInt(86401, archive_entry_atime(ae));
113 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
114 assertEqualInt(1, archive_entry_uid(ae));
115 assertEqualInt(2, archive_entry_gid(ae));
116 } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) {
117 /* A hardlink to the regular file. */
118 /* Note: If "hardlink" gets returned before "file",
119 * then "hardlink" will get returned as a regular file
120 * and "file" will get returned as the hardlink.
121 * This test should tolerate that, since it's a
122 * perfectly permissible thing for libarchive to do. */
123 assertEqualString("hardlink", archive_entry_pathname(ae));
124 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
125 assertEqualString("file", archive_entry_hardlink(ae));
126 assertEqualInt(0, archive_entry_size_is_set(ae));
127 assertEqualInt(0, archive_entry_size(ae));
128 assertEqualInt(86401, archive_entry_mtime(ae));
129 assertEqualInt(86401, archive_entry_atime(ae));
130 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
131 assertEqualInt(1, archive_entry_uid(ae));
132 assertEqualInt(2, archive_entry_gid(ae));
133 } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) {
134 /* A symlink to the regular file. */
135 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
136 assertEqualString("file", archive_entry_symlink(ae));
137 assertEqualInt(0, archive_entry_size(ae));
138 assertEqualInt(172802, archive_entry_mtime(ae));
139 assertEqualInt(172802, archive_entry_atime(ae));
140 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
141 assertEqualInt(1, archive_entry_uid(ae));
142 assertEqualInt(2, archive_entry_gid(ae));
143 } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) {
144 /* A symlink to /tmp (an absolute path) */
145 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
146 assertEqualString("/tmp", archive_entry_symlink(ae));
147 assertEqualInt(0, archive_entry_size(ae));
148 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
149 assertEqualInt(1, archive_entry_uid(ae));
150 assertEqualInt(2, archive_entry_gid(ae));
151 } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) {
152 /* A symlink to /tmp/.. (with a ".." component) */
153 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
154 assertEqualString("/tmp/..", archive_entry_symlink(ae));
155 assertEqualInt(0, archive_entry_size(ae));
156 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
157 assertEqualInt(1, archive_entry_uid(ae));
158 assertEqualInt(2, archive_entry_gid(ae));
159 } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) {
160 /* A symlink to a path with ".." and "." components */
161 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
162 assertEqualString(".././../tmp",
163 archive_entry_symlink(ae));
164 assertEqualInt(0, archive_entry_size(ae));
165 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
166 assertEqualInt(1, archive_entry_uid(ae));
167 assertEqualInt(2, archive_entry_gid(ae));
168 } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) {
169 /* A symlink to the regular file with "/" components. */
170 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
171 assertEqualString(".///file", archive_entry_symlink(ae));
172 assertEqualInt(0, archive_entry_size(ae));
173 assertEqualInt(172802, archive_entry_mtime(ae));
174 assertEqualInt(172802, archive_entry_atime(ae));
175 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
176 assertEqualInt(1, archive_entry_uid(ae));
177 assertEqualInt(2, archive_entry_gid(ae));
178 } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) {
179 /* A symlink to /tmp//..
180 * (with "/" and ".." components) */
181 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
182 assertEqualString("/tmp//..", archive_entry_symlink(ae));
183 assertEqualInt(0, archive_entry_size(ae));
184 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
185 assertEqualInt(1, archive_entry_uid(ae));
186 assertEqualInt(2, archive_entry_gid(ae));
187 } else {
188 failure("Saw a file that shouldn't have been there");
189 assertEqualString(archive_entry_pathname(ae), "");
190 }
191 }
192
193 /* End of archive. */
194 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
195
196 /* Verify archive format. */
197 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
198 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
199
200 /* Close the archive. */
201 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
202 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
203 }
204
205
206