pkgsrc - initial commit
[pkgsrc.git] / archivers / libarchive / files / libarchive / test / test_read_format_tar.c
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 __FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_tar.c,v 1.3 2008/01/13 23:50:30 kientzle Exp $");
27
28 /*
29  * Each of these archives is a short archive with a single entry.  The
30  * corresponding verify function verifies the entry structure returned
31  * from libarchive is what it should be.  The support functions pad with
32  * lots of zeros, so we can trim trailing zero bytes from each hardcoded
33  * archive to save space.
34  *
35  * The naming here follows the tar file type flags.  E.g. '1' is a hardlink,
36  * '2' is a symlink, '5' is a dir, etc.
37  */
38
39 /* Empty archive. */
40 static unsigned char archiveEmpty[] = {
41         /* 512 zero bytes */
42         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
43         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
44         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
45         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
46
47         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
48         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
49         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
50         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
51
52         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
53         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
54         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
55         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
56
57         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
58         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
59         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
60         0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0
61 };
62
63 static void verifyEmpty(void)
64 {
65         struct archive_entry *ae;
66         struct archive *a;
67
68         assert((a = archive_read_new()) != NULL);
69         assertA(0 == archive_read_support_compression_all(a));
70         assertA(0 == archive_read_support_format_all(a));
71         assertA(0 == archive_read_open_memory(a, archiveEmpty, 512));
72         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
73         assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE);
74         failure("512 zero bytes should be recognized as a tar archive.");
75         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR);
76
77         assert(0 == archive_read_close(a));
78 #if ARCHIVE_API_VERSION > 1
79         assert(0 == archive_read_finish(a));
80 #else
81         archive_read_finish(a);
82 #endif
83 }
84
85 /* Single entry with a hardlink. */
86 static unsigned char archive1[] = {
87 'h','a','r','d','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
88 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
89 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0',
90 '0','6','4','4',' ',0,'0','0','1','7','5','0',' ',0,'0','0','1','7','5','0',
91 ' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4','6',
92 '0','5','2','6','6','2',' ','0','1','3','0','5','7',0,' ','1','f','i','l',
93 'e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
94 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
95 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,'0',
96 '0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
97 't','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0',
98 '0','0','0','0','0',' ',0,'0','0','0','0','0','0',' '};
99
100 static void verify1(struct archive_entry *ae)
101 {
102         /* A hardlink is not a symlink. */
103         assert(!S_ISLNK(archive_entry_mode(ae)));
104         /* Nor is it a directory. */
105         assert(!S_ISDIR(archive_entry_mode(ae)));
106         assertEqualInt(archive_entry_mode(ae) & 0777, 0644);
107         assertEqualInt(archive_entry_uid(ae), 1000);
108         assertEqualInt(archive_entry_gid(ae), 1000);
109         assertEqualString(archive_entry_uname(ae), "tim");
110         assertEqualString(archive_entry_gname(ae), "tim");
111         assertEqualString(archive_entry_pathname(ae), "hardlink");
112         assertEqualString(archive_entry_hardlink(ae), "file");
113         assert(archive_entry_symlink(ae) == NULL);
114         assertEqualInt(archive_entry_mtime(ae), 1184388530);
115 }
116
117 /* Verify that symlinks are read correctly. */
118 static unsigned char archive2[] = {
119 's','y','m','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
120 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
121 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0',
122 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7',
123 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4',
124 '6','0','5','4','1','0','1',' ','0','0','1','3','3','2','3',' ','2','f','i',
125 'l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
126 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
127 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,
128 '0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
129 0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
130 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '};
131
132 static void verify2(struct archive_entry *ae)
133 {
134         assert(S_ISLNK(archive_entry_mode(ae)));
135         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
136         assertEqualInt(archive_entry_uid(ae), 1000);
137         assertEqualInt(archive_entry_gid(ae), 1000);
138         assertEqualString(archive_entry_uname(ae), "tim");
139         assertEqualString(archive_entry_gname(ae), "tim");
140         assertEqualString(archive_entry_pathname(ae), "symlink");
141         assertEqualString(archive_entry_symlink(ae), "file");
142         assert(archive_entry_hardlink(ae) == NULL);
143         assertEqualInt(archive_entry_mtime(ae), 1184389185);
144 }
145
146 /* Character device node. */
147 static unsigned char archive3[] = {
148 'd','e','v','c','h','a','r',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
149 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
150 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0',
151 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7',
152 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4',
153 '6','0','5','4','1','0','1',' ','0','0','1','2','4','1','2',' ','3',0,0,
154 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
155 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
156 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,
157 '0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
158 0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
159 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '};
160
161 static void verify3(struct archive_entry *ae)
162 {
163         assert(S_ISCHR(archive_entry_mode(ae)));
164         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
165         assertEqualInt(archive_entry_uid(ae), 1000);
166         assertEqualInt(archive_entry_gid(ae), 1000);
167         assertEqualString(archive_entry_uname(ae), "tim");
168         assertEqualString(archive_entry_gname(ae), "tim");
169         assertEqualString(archive_entry_pathname(ae), "devchar");
170         assert(archive_entry_symlink(ae) == NULL);
171         assert(archive_entry_hardlink(ae) == NULL);
172         assertEqualInt(archive_entry_mtime(ae), 1184389185);
173 }
174
175 /* Block device node. */
176 static unsigned char archive4[] = {
177 'd','e','v','b','l','o','c','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
178 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
179 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0',
180 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7',
181 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4',
182 '6','0','5','4','1','0','1',' ','0','0','1','2','5','7','0',' ','4',0,0,
183 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
184 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
185 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,
186 '0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
187 0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
188 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '};
189
190 static void verify4(struct archive_entry *ae)
191 {
192         assert(S_ISBLK(archive_entry_mode(ae)));
193         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
194         assertEqualInt(archive_entry_uid(ae), 1000);
195         assertEqualInt(archive_entry_gid(ae), 1000);
196         assertEqualString(archive_entry_uname(ae), "tim");
197         assertEqualString(archive_entry_gname(ae), "tim");
198         assertEqualString(archive_entry_pathname(ae), "devblock");
199         assert(archive_entry_symlink(ae) == NULL);
200         assert(archive_entry_hardlink(ae) == NULL);
201         assertEqualInt(archive_entry_mtime(ae), 1184389185);
202 }
203
204 /* Directory. */
205 static unsigned char archive5[] = {
206 '.',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
207 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
208 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0',
209 '7','5','5',' ',0,'0','0','1','7','5','0',' ',0,'0','0','1','7','5','0',
210 ' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','1','0','3','3',
211 '4','0','4','1','7','3','6',' ','0','1','0','5','6','1',0,' ','5',0,0,0,
212 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
213 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
214 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,
215 '0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
216 0,0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
217 0,0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0',' '};
218
219 static void verify5(struct archive_entry *ae)
220 {
221         assert(S_ISDIR(archive_entry_mode(ae)));
222         assertEqualInt(archive_entry_mtime(ae), 1131430878);
223         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
224         assertEqualInt(archive_entry_uid(ae), 1000);
225         assertEqualInt(archive_entry_gid(ae), 1000);
226         assertEqualString(archive_entry_uname(ae), "tim");
227         assertEqualString(archive_entry_gname(ae), "tim");
228 }
229
230 /* fifo */
231 static unsigned char archive6[] = {
232 'f','i','f','o',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
233 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
234 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0',
235 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7',
236 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4',
237 '6','0','5','4','1','0','1',' ','0','0','1','1','7','2','4',' ','6',0,0,
238 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
239 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
240 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,
241 '0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
242 0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
243 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '};
244
245 static void verify6(struct archive_entry *ae)
246 {
247         assert(S_ISFIFO(archive_entry_mode(ae)));
248         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
249         assertEqualInt(archive_entry_uid(ae), 1000);
250         assertEqualInt(archive_entry_gid(ae), 1000);
251         assertEqualString(archive_entry_uname(ae), "tim");
252         assertEqualString(archive_entry_gname(ae), "tim");
253         assertEqualString(archive_entry_pathname(ae), "fifo");
254         assert(archive_entry_symlink(ae) == NULL);
255         assert(archive_entry_hardlink(ae) == NULL);
256         assertEqualInt(archive_entry_mtime(ae), 1184389185);
257 }
258
259 /* GNU long link name */
260 static unsigned char archiveK[] = {
261 '.','/','.','/','@','L','o','n','g','L','i','n','k',0,0,0,0,0,0,0,0,0,0,0,
262 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
263 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
264 0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0',0,'0','0','0',
265 '0','0','0','0',0,'0','0','0','0','0','0','0','0','6','6','6',0,'0','0','0',
266 '0','0','0','0','0','0','0','0',0,'0','1','1','7','1','5',0,' ','K',0,0,0,
267 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
268 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
269 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',' ',' ',
270 0,'r','o','o','t',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
271 'w','h','e','e','l',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
272 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
273 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
274 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
275 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
276 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'t',
277 'h','i','s','_','i','s','_','a','_','v','e','r','y','_','l','o','n','g','_',
278 's','y','m','l','i','n','k','_','b','o','d','y','_','a','b','c','d','e','f',
279 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y',
280 'z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
281 'r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i',
282 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a',
283 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
284 'u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l',
285 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d',
286 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
287 'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
288 'p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g',
289 'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
290 '_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
291 's','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j',
292 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b',
293 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
294 'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m',
295 'n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e',
296 'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x',
297 'y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
298 'q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h',
299 'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',0,
300 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
301 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
302 's','y','m','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
303 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
304 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','1',
305 '2','0','7','5','5',0,'0','0','0','1','7','5','0',0,'0','0','0','1','7','5',
306 '0',0,'0','0','0','0','0','0','0','0','0','0','0',0,'1','0','6','4','6','0',
307 '5','6','7','7','0',0,'0','3','5','4','4','7',0,' ','2','t','h','i','s','_',
308 'i','s','_','a','_','v','e','r','y','_','l','o','n','g','_','s','y','m','l',
309 'i','n','k','_','b','o','d','y','_','a','b','c','d','e','f','g','h','i','j',
310 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b',
311 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
312 'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l',0,
313 'u','s','t','a','r',' ',' ',0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
314 0,0,0,0,0,0,0,0,0,0,0,0,0,'t','i','m'};
315
316 static void verifyK(struct archive_entry *ae)
317 {
318         assert(S_ISLNK(archive_entry_mode(ae)));
319         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
320         assertEqualInt(archive_entry_uid(ae), 1000);
321         assertEqualInt(archive_entry_gid(ae), 1000);
322         assertEqualString(archive_entry_uname(ae), "tim");
323         assertEqualString(archive_entry_gname(ae), "tim");
324         assertEqualString(archive_entry_pathname(ae), "symlink");
325         assertEqualString(archive_entry_symlink(ae),
326             "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_"
327             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
328             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
329             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
330             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
331             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
332             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
333             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz");
334         assert(archive_entry_hardlink(ae) == NULL);
335         assertEqualInt(archive_entry_mtime(ae), 1184390648);
336 }
337
338 /* TODO: GNU long name */
339
340 /* TODO: Solaris ACL */
341
342 /* Pax extended long link name */
343 static unsigned char archivexL[] = {
344 '.','/','P','a','x','H','e','a','d','e','r','s','.','8','6','9','7','5','/',
345 's','y','m','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
346 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
347 0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0','0','6','4','4',0,'0','0','0','1',
348 '7','5','0',0,'0','0','0','1','7','5','0',0,'0','0','0','0','0','0','0','0',
349 '7','5','3',0,'1','0','6','4','6','0','5','7','6','1','1',0,'0','1','3','7',
350 '1','4',0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
351 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
352 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u',
353 's','t','a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
354 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
355 0,0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0',0,0,0,0,0,
356 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
357 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
358 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
359 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
360 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'4','5','1',' ','l','i','n','k','p','a','t',
361 'h','=','t','h','i','s','_','i','s','_','a','_','v','e','r','y','_','l','o',
362 'n','g','_','s','y','m','l','i','n','k','_','b','o','d','y','_','a','b','c',
363 'd','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
364 'w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n',
365 'o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f',
366 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y',
367 'z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
368 'r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i',
369 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a',
370 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
371 'u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l',
372 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d',
373 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
374 'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
375 'p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g',
376 'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
377 '_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
378 's','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j',
379 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b',
380 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
381 'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m',
382 'n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e',
383 'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x',
384 'y','z',10,'2','0',' ','a','t','i','m','e','=','1','1','8','4','3','9','1',
385 '0','2','5',10,'2','0',' ','c','t','i','m','e','=','1','1','8','4','3','9',
386 '0','6','4','8',10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'s','y','m',
387 'l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
388 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
389 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0','0','7',
390 '5','5',0,'0','0','0','1','7','5','0',0,'0','0','0','1','7','5','0',0,'0',
391 '0','0','0','0','0','0','0','0','0','0',0,'1','0','6','4','6','0','5','6',
392 '7','7','0',0,'0','3','7','1','2','1',0,' ','2','t','h','i','s','_','i','s',
393 '_','a','_','v','e','r','y','_','l','o','n','g','_','s','y','m','l','i','n',
394 'k','_','b','o','d','y','_','a','b','c','d','e','f','g','h','i','j','k','l',
395 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d',
396 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
397 'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','u','s',
398 't','a','r',0,'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
399 0,0,0,0,0,0,0,0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
400 0,0,0,0,0,0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0'};
401
402 static void verifyxL(struct archive_entry *ae)
403 {
404         assert(S_ISLNK(archive_entry_mode(ae)));
405         assertEqualInt(archive_entry_mode(ae) & 0777, 0755);
406         assertEqualInt(archive_entry_uid(ae), 1000);
407         assertEqualInt(archive_entry_gid(ae), 1000);
408         assertEqualString(archive_entry_uname(ae), "tim");
409         assertEqualString(archive_entry_gname(ae), "tim");
410         assertEqualString(archive_entry_pathname(ae), "symlink");
411         assertEqualString(archive_entry_symlink(ae),
412             "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_"
413             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
414             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
415             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
416             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
417             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
418             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_"
419             "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz");
420         assert(archive_entry_hardlink(ae) == NULL);
421         assertEqualInt(archive_entry_mtime(ae), 1184390648);
422 }
423
424
425 /* TODO: Any other types of headers? */
426
427 static void verify(unsigned char *d, size_t s,
428     void (*f)(struct archive_entry *),
429     int compression, int format)
430 {
431         struct archive_entry *ae;
432         struct archive *a;
433         unsigned char *buff = malloc(100000);
434
435         memcpy(buff, d, s);
436         memset(buff + s, 0, 2048);
437
438         assert((a = archive_read_new()) != NULL);
439         assertA(0 == archive_read_support_compression_all(a));
440         assertA(0 == archive_read_support_format_all(a));
441         assertA(0 == archive_read_open_memory(a, buff, s + 1024));
442         assertA(0 == archive_read_next_header(a, &ae));
443         assertEqualInt(archive_compression(a), compression);
444         assertEqualInt(archive_format(a), format);
445
446         /* Verify the only entry. */
447         f(ae);
448
449         assert(0 == archive_read_close(a));
450 #if ARCHIVE_API_VERSION > 1
451         assert(0 == archive_read_finish(a));
452 #else
453         archive_read_finish(a);
454 #endif
455         free(buff);
456 }
457
458 DEFINE_TEST(test_read_format_tar)
459 {
460         verifyEmpty();
461         verify(archive1, sizeof(archive1), verify1,
462             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR);
463         verify(archive2, sizeof(archive2), verify2,
464             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR);
465         verify(archive3, sizeof(archive3), verify3,
466             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR);
467         verify(archive4, sizeof(archive4), verify4,
468             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR);
469         verify(archive5, sizeof(archive5), verify5,
470             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR);
471         verify(archive6, sizeof(archive6), verify6,
472             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR);
473         verify(archiveK, sizeof(archiveK), verifyK,
474             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_GNUTAR);
475         verify(archivexL, sizeof(archivexL), verifyxL,
476             ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE);
477 }
478
479