1 /*-
2 * Copyright (c) 2003-2010 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 /* The sample has some files in a directory with a very long name. */
28 #define TESTPATH "abcdefghijklmnopqrstuvwxyz/" \
29 "abcdefghijklmnopqrstuvwxyz/" \
30 "abcdefghijklmnopqrstuvwxyz/" \
31 "abcdefghijklmnopqrstuvwxyz/" \
32 "abcdefghijklmnopqrstuvwxyz/" \
33 "abcdefghijklmnopqrstuvwxyz/" \
34 "abcdefghijklmnopqrstuvwxyz/"
35
36 static void test_compat_mac_1(void);
37 static void test_compat_mac_2(void);
38
39 /*
40 * Apple shipped an extended version of GNU tar with Mac OS X 10.5
41 * and earlier.
42 */
43 static void
test_compat_mac_1(void)44 test_compat_mac_1(void)
45 {
46 char name[] = "test_compat_mac-1.tar.Z";
47 struct archive_entry *ae;
48 struct archive *a;
49 const void *attr;
50 size_t attrSize;
51
52 assert((a = archive_read_new()) != NULL);
53 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
54 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
55 assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "mac-ext"));
56 extract_reference_file(name);
57 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
58
59 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
60 assertEqualString(TESTPATH, archive_entry_pathname(ae));
61 assertEqualInt(1275688109, archive_entry_mtime(ae));
62 assertEqualInt(95594, archive_entry_uid(ae));
63 assertEqualString("kientzle", archive_entry_uname(ae));
64 assertEqualInt(5000, archive_entry_gid(ae));
65 assertEqualString("", archive_entry_gname(ae));
66 assertEqualInt(040755, archive_entry_mode(ae));
67
68 attr = archive_entry_mac_metadata(ae, &attrSize);
69 assert(attr == NULL);
70 assertEqualInt(0, attrSize);
71
72 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
73 assertEqualString(TESTPATH "dir/", archive_entry_pathname(ae));
74 assertEqualInt(1275687611, archive_entry_mtime(ae));
75 assertEqualInt(95594, archive_entry_uid(ae));
76 assertEqualString("kientzle", archive_entry_uname(ae));
77 assertEqualInt(5000, archive_entry_gid(ae));
78 assertEqualString("", archive_entry_gname(ae));
79 assertEqualInt(040755, archive_entry_mode(ae));
80
81 attr = archive_entry_mac_metadata(ae, &attrSize);
82 assert(attr != NULL);
83 assertEqualInt(225, attrSize);
84
85 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
86 assertEqualString(TESTPATH "file", archive_entry_pathname(ae));
87 assertEqualInt(1275687588, archive_entry_mtime(ae));
88 assertEqualInt(95594, archive_entry_uid(ae));
89 assertEqualString("kientzle", archive_entry_uname(ae));
90 assertEqualInt(5000, archive_entry_gid(ae));
91 assertEqualString("", archive_entry_gname(ae));
92 assertEqualInt(0100644, archive_entry_mode(ae));
93
94 attr = archive_entry_mac_metadata(ae, &attrSize);
95 assert(attr != NULL);
96 assertEqualInt(225, attrSize);
97
98 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
99 assertEqualString("dir/", archive_entry_pathname(ae));
100 assertEqualInt(1275688064, archive_entry_mtime(ae));
101 assertEqualInt(95594, archive_entry_uid(ae));
102 assertEqualString("kientzle", archive_entry_uname(ae));
103 assertEqualInt(5000, archive_entry_gid(ae));
104 assertEqualString("", archive_entry_gname(ae));
105 assertEqualInt(040755, archive_entry_mode(ae));
106
107 attr = archive_entry_mac_metadata(ae, &attrSize);
108 assert(attr != NULL);
109 assertEqualInt(225, attrSize);
110 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
111
112 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
113 assertEqualString("file", archive_entry_pathname(ae));
114 assertEqualInt(1275625860, archive_entry_mtime(ae));
115 assertEqualInt(95594, archive_entry_uid(ae));
116 assertEqualString("kientzle", archive_entry_uname(ae));
117 assertEqualInt(5000, archive_entry_gid(ae));
118 assertEqualString("", archive_entry_gname(ae));
119 assertEqualInt(0100644, archive_entry_mode(ae));
120
121 attr = archive_entry_mac_metadata(ae, &attrSize);
122 assert(attr != NULL);
123 assertEqualInt(225, attrSize);
124 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
125
126 /* Verify the end-of-archive. */
127 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
128
129 /* Verify that the format detection worked. */
130 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
131 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR);
132
133 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
134 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
135 }
136
137 /*
138 * Apple shipped a customized version of bsdtar starting with MacOS 10.6.
139 */
140 static void
test_compat_mac_2(void)141 test_compat_mac_2(void)
142 {
143 char name[] = "test_compat_mac-2.tar.Z";
144 struct archive_entry *ae;
145 struct archive *a;
146 const void *attr;
147 size_t attrSize;
148
149 assert((a = archive_read_new()) != NULL);
150 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
151 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
152 assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "mac-ext"));
153 extract_reference_file(name);
154 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
155
156 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
157 assertEqualString("./", archive_entry_pathname(ae));
158 assertEqualInt(1303628303, archive_entry_mtime(ae));
159 assertEqualInt(501, archive_entry_uid(ae));
160 assertEqualString("tim", archive_entry_uname(ae));
161 assertEqualInt(20, archive_entry_gid(ae));
162 assertEqualString("staff", archive_entry_gname(ae));
163 assertEqualInt(040755, archive_entry_mode(ae));
164
165 attr = archive_entry_mac_metadata(ae, &attrSize);
166 assert(attr == NULL);
167 assertEqualInt(0, attrSize);
168
169 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
170 assertEqualString("./mydir/", archive_entry_pathname(ae));
171 assertEqualInt(1303628303, archive_entry_mtime(ae));
172 assertEqualInt(501, archive_entry_uid(ae));
173 assertEqualString("tim", archive_entry_uname(ae));
174 assertEqualInt(20, archive_entry_gid(ae));
175 assertEqualString("staff", archive_entry_gname(ae));
176 assertEqualInt(040755, archive_entry_mode(ae));
177
178 attr = archive_entry_mac_metadata(ae, &attrSize);
179 assert(attr != NULL);
180 assertEqualInt(267, attrSize);
181 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
182
183 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
184 assertEqualString("./myfile", archive_entry_pathname(ae));
185 assertEqualInt(1303628303, archive_entry_mtime(ae));
186 assertEqualInt(501, archive_entry_uid(ae));
187 assertEqualString("tim", archive_entry_uname(ae));
188 assertEqualInt(20, archive_entry_gid(ae));
189 assertEqualString("staff", archive_entry_gname(ae));
190 assertEqualInt(0100644, archive_entry_mode(ae));
191
192 attr = archive_entry_mac_metadata(ae, &attrSize);
193 assert(attr != NULL);
194 assertEqualInt(267, attrSize);
195 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
196
197 /* Verify the end-of-archive. */
198 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
199
200 /* Verify that the format detection worked. */
201 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
202 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
203
204 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
205 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
206 }
207
DEFINE_TEST(test_compat_mac)208 DEFINE_TEST(test_compat_mac)
209 {
210 test_compat_mac_1();
211 test_compat_mac_2();
212 }
213
214