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$"); 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_filter_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_filter_code(a, 0), ARCHIVE_FILTER_NONE); 74 assertEqualString(archive_filter_name(a, 0), "none"); 75 failure("512 zero bytes should be recognized as a tar archive."); 76 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); 77 78 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 79 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 80 } 81 82 /* Single entry with a hardlink. */ 83 static unsigned char archive1[] = { 84 '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, 85 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 86 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', 87 '0','6','4','4',' ',0,'0','0','1','7','5','0',' ',0,'0','0','1','7','5','0', 88 ' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4','6', 89 '0','5','2','6','6','2',' ','0','1','3','0','5','7',0,' ','1','f','i','l', 90 '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, 91 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 92 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', 93 '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, 94 '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', 95 '0','0','0','0','0',' ',0,'0','0','0','0','0','0',' '}; 96 97 static void verify1(struct archive_entry *ae) 98 { 99 /* A hardlink is not a symlink. */ 100 assert(archive_entry_filetype(ae) != AE_IFLNK); 101 /* Nor is it a directory. */ 102 assert(archive_entry_filetype(ae) != AE_IFDIR); 103 assertEqualInt(archive_entry_mode(ae) & 0777, 0644); 104 assertEqualInt(archive_entry_uid(ae), 1000); 105 assertEqualInt(archive_entry_gid(ae), 1000); 106 assertEqualString(archive_entry_uname(ae), "tim"); 107 assertEqualString(archive_entry_gname(ae), "tim"); 108 assertEqualString(archive_entry_pathname(ae), "hardlink"); 109 assertEqualString(archive_entry_hardlink(ae), "file"); 110 assert(archive_entry_symlink(ae) == NULL); 111 assertEqualInt(archive_entry_mtime(ae), 1184388530); 112 } 113 114 /* Verify that symlinks are read correctly. */ 115 static unsigned char archive2[] = { 116 '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, 117 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 118 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', 119 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', 120 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', 121 '6','0','5','4','1','0','1',' ','0','0','1','3','3','2','3',' ','2','f','i', 122 '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, 123 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 124 0,0,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, 125 '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, 126 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, 127 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; 128 129 static void verify2(struct archive_entry *ae) 130 { 131 assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); 132 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 133 assertEqualInt(archive_entry_uid(ae), 1000); 134 assertEqualInt(archive_entry_gid(ae), 1000); 135 assertEqualString(archive_entry_uname(ae), "tim"); 136 assertEqualString(archive_entry_gname(ae), "tim"); 137 assertEqualString(archive_entry_pathname(ae), "symlink"); 138 assertEqualString(archive_entry_symlink(ae), "file"); 139 assert(archive_entry_hardlink(ae) == NULL); 140 assertEqualInt(archive_entry_mtime(ae), 1184389185); 141 } 142 143 /* Character device node. */ 144 static unsigned char archive3[] = { 145 '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, 146 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 147 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', 148 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', 149 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', 150 '6','0','5','4','1','0','1',' ','0','0','1','2','4','1','2',' ','3',0,0, 151 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 152 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 153 0,0,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, 154 '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, 155 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, 156 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; 157 158 static void verify3(struct archive_entry *ae) 159 { 160 assertEqualInt(archive_entry_filetype(ae), AE_IFCHR); 161 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 162 assertEqualInt(archive_entry_uid(ae), 1000); 163 assertEqualInt(archive_entry_gid(ae), 1000); 164 assertEqualString(archive_entry_uname(ae), "tim"); 165 assertEqualString(archive_entry_gname(ae), "tim"); 166 assertEqualString(archive_entry_pathname(ae), "devchar"); 167 assert(archive_entry_symlink(ae) == NULL); 168 assert(archive_entry_hardlink(ae) == NULL); 169 assertEqualInt(archive_entry_mtime(ae), 1184389185); 170 } 171 172 /* Block device node. */ 173 static unsigned char archive4[] = { 174 '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, 175 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 176 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', 177 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', 178 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', 179 '6','0','5','4','1','0','1',' ','0','0','1','2','5','7','0',' ','4',0,0, 180 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 181 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 182 0,0,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, 183 '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, 184 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, 185 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; 186 187 static void verify4(struct archive_entry *ae) 188 { 189 assertEqualInt(archive_entry_filetype(ae), AE_IFBLK); 190 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 191 assertEqualInt(archive_entry_uid(ae), 1000); 192 assertEqualInt(archive_entry_gid(ae), 1000); 193 assertEqualString(archive_entry_uname(ae), "tim"); 194 assertEqualString(archive_entry_gname(ae), "tim"); 195 assertEqualString(archive_entry_pathname(ae), "devblock"); 196 assert(archive_entry_symlink(ae) == NULL); 197 assert(archive_entry_hardlink(ae) == NULL); 198 assertEqualInt(archive_entry_mtime(ae), 1184389185); 199 } 200 201 /* Directory. */ 202 static unsigned char archive5[] = { 203 '.',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 204 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 205 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', 206 '7','5','5',' ',0,'0','0','1','7','5','0',' ',0,'0','0','1','7','5','0', 207 ' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','1','0','3','3', 208 '4','0','4','1','7','3','6',' ','0','1','0','5','6','1',0,' ','5',0,0,0, 209 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 210 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 211 0,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, 212 '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, 213 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, 214 0,0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0',' '}; 215 216 static void verify5(struct archive_entry *ae) 217 { 218 assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); 219 assertEqualInt(archive_entry_mtime(ae), 1131430878); 220 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 221 assertEqualInt(archive_entry_uid(ae), 1000); 222 assertEqualInt(archive_entry_gid(ae), 1000); 223 assertEqualString(archive_entry_uname(ae), "tim"); 224 assertEqualString(archive_entry_gname(ae), "tim"); 225 } 226 227 /* fifo */ 228 static unsigned char archive6[] = { 229 '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, 230 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 231 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', 232 '0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', 233 '5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', 234 '6','0','5','4','1','0','1',' ','0','0','1','1','7','2','4',' ','6',0,0, 235 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 236 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 237 0,0,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, 238 '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, 239 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, 240 '0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; 241 242 static void verify6(struct archive_entry *ae) 243 { 244 assertEqualInt(archive_entry_filetype(ae), AE_IFIFO); 245 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 246 assertEqualInt(archive_entry_uid(ae), 1000); 247 assertEqualInt(archive_entry_gid(ae), 1000); 248 assertEqualString(archive_entry_uname(ae), "tim"); 249 assertEqualString(archive_entry_gname(ae), "tim"); 250 assertEqualString(archive_entry_pathname(ae), "fifo"); 251 assert(archive_entry_symlink(ae) == NULL); 252 assert(archive_entry_hardlink(ae) == NULL); 253 assertEqualInt(archive_entry_mtime(ae), 1184389185); 254 } 255 256 /* GNU long link name */ 257 static unsigned char archiveK[] = { 258 '.','/','.','/','@','L','o','n','g','L','i','n','k',0,0,0,0,0,0,0,0,0,0,0, 259 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 260 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 261 0,0,'0','0','0','0','0','0','0',0,'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','6','6','6',0,'0','0','0', 263 '0','0','0','0','0','0','0','0',0,'0','1','1','7','1','5',0,' ','K',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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 266 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',' ',' ', 267 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, 268 '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, 269 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 270 0,0,0,0,0,0,0,0,0,0,0,0,0,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 0,0,0,0,0,0,0,0,0,0,0,0,0,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,'t', 274 'h','i','s','_','i','s','_','a','_','v','e','r','y','_','l','o','n','g','_', 275 's','y','m','l','i','n','k','_','b','o','d','y','_','a','b','c','d','e','f', 276 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', 277 'z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q', 278 'r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i', 279 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a', 280 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', 281 'u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l', 282 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d', 283 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', 284 'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', 285 'p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g', 286 'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 287 '_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', 288 's','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j', 289 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b', 290 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u', 291 'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m', 292 'n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e', 293 'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x', 294 'y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p', 295 'q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h', 296 'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',0, 297 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 298 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 299 '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, 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','1', 302 '2','0','7','5','5',0,'0','0','0','1','7','5','0',0,'0','0','0','1','7','5', 303 '0',0,'0','0','0','0','0','0','0','0','0','0','0',0,'1','0','6','4','6','0', 304 '5','6','7','7','0',0,'0','3','5','4','4','7',0,' ','2','t','h','i','s','_', 305 'i','s','_','a','_','v','e','r','y','_','l','o','n','g','_','s','y','m','l', 306 'i','n','k','_','b','o','d','y','_','a','b','c','d','e','f','g','h','i','j', 307 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b', 308 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u', 309 'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l',0, 310 '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, 311 0,0,0,0,0,0,0,0,0,0,0,0,0,'t','i','m'}; 312 313 static void verifyK(struct archive_entry *ae) 314 { 315 assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); 316 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 317 assertEqualInt(archive_entry_uid(ae), 1000); 318 assertEqualInt(archive_entry_gid(ae), 1000); 319 assertEqualString(archive_entry_uname(ae), "tim"); 320 assertEqualString(archive_entry_gname(ae), "tim"); 321 assertEqualString(archive_entry_pathname(ae), "symlink"); 322 assertEqualString(archive_entry_symlink(ae), 323 "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_" 324 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 325 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 326 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 327 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 328 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 329 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 330 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz"); 331 assert(archive_entry_hardlink(ae) == NULL); 332 assertEqualInt(archive_entry_mtime(ae), 1184390648); 333 } 334 335 /* TODO: GNU long name */ 336 337 /* TODO: Solaris ACL */ 338 339 /* Pax extended long link name */ 340 static unsigned char archivexL[] = { 341 '.','/','P','a','x','H','e','a','d','e','r','s','.','8','6','9','7','5','/', 342 '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, 343 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 344 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', 345 '7','5','0',0,'0','0','0','1','7','5','0',0,'0','0','0','0','0','0','0','0', 346 '7','5','3',0,'1','0','6','4','6','0','5','7','6','1','1',0,'0','1','3','7', 347 '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, 348 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 349 0,0,0,0,0,0,0,0,0,0,0,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', 350 '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, 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, 353 0,0,0,0,0,0,0,0,0,0,0,0,0,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,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,'4','5','1',' ','l','i','n','k','p','a','t', 358 'h','=','t','h','i','s','_','i','s','_','a','_','v','e','r','y','_','l','o', 359 'n','g','_','s','y','m','l','i','n','k','_','b','o','d','y','_','a','b','c', 360 'd','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', 361 'w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n', 362 'o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f', 363 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', 364 'z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q', 365 'r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i', 366 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a', 367 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', 368 'u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l', 369 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d', 370 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', 371 'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', 372 'p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g', 373 'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 374 '_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', 375 's','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j', 376 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b', 377 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u', 378 'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m', 379 'n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e', 380 'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x', 381 'y','z',10,'2','0',' ','a','t','i','m','e','=','1','1','8','4','3','9','1', 382 '0','2','5',10,'2','0',' ','c','t','i','m','e','=','1','1','8','4','3','9', 383 '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', 384 '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, 385 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 386 0,0,0,0,0,0,0,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', 387 '5','5',0,'0','0','0','1','7','5','0',0,'0','0','0','1','7','5','0',0,'0', 388 '0','0','0','0','0','0','0','0','0','0',0,'1','0','6','4','6','0','5','6', 389 '7','7','0',0,'0','3','7','1','2','1',0,' ','2','t','h','i','s','_','i','s', 390 '_','a','_','v','e','r','y','_','l','o','n','g','_','s','y','m','l','i','n', 391 'k','_','b','o','d','y','_','a','b','c','d','e','f','g','h','i','j','k','l', 392 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d', 393 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', 394 'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','u','s', 395 '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, 396 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, 397 0,0,0,0,0,0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0'}; 398 399 static void verifyxL(struct archive_entry *ae) 400 { 401 assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); 402 assertEqualInt(archive_entry_mode(ae) & 0777, 0755); 403 assertEqualInt(archive_entry_uid(ae), 1000); 404 assertEqualInt(archive_entry_gid(ae), 1000); 405 assertEqualString(archive_entry_uname(ae), "tim"); 406 assertEqualString(archive_entry_gname(ae), "tim"); 407 assertEqualString(archive_entry_pathname(ae), "symlink"); 408 assertEqualString(archive_entry_symlink(ae), 409 "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_" 410 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 411 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 412 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 413 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 414 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 415 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" 416 "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz"); 417 assert(archive_entry_hardlink(ae) == NULL); 418 assertEqualInt(archive_entry_mtime(ae), 1184390648); 419 } 420 421 422 /* TODO: Any other types of headers? */ 423 424 static void verify(unsigned char *d, size_t s, 425 void (*f)(struct archive_entry *), 426 int compression, int format) 427 { 428 struct archive_entry *ae; 429 struct archive *a; 430 unsigned char *buff = malloc(100000); 431 432 memcpy(buff, d, s); 433 memset(buff + s, 0, 2048); 434 435 assert((a = archive_read_new()) != NULL); 436 assertA(0 == archive_read_support_filter_all(a)); 437 assertA(0 == archive_read_support_format_all(a)); 438 assertA(0 == archive_read_open_memory(a, buff, s + 1024)); 439 assertA(0 == archive_read_next_header(a, &ae)); 440 assertEqualInt(archive_filter_code(a, 0), compression); 441 assertEqualInt(archive_format(a), format); 442 443 /* Verify the only entry. */ 444 f(ae); 445 446 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 447 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 448 free(buff); 449 } 450 451 DEFINE_TEST(test_read_format_tar) 452 { 453 verifyEmpty(); 454 verify(archive1, sizeof(archive1), verify1, 455 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_USTAR); 456 verify(archive2, sizeof(archive2), verify2, 457 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_USTAR); 458 verify(archive3, sizeof(archive3), verify3, 459 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_USTAR); 460 verify(archive4, sizeof(archive4), verify4, 461 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_USTAR); 462 verify(archive5, sizeof(archive5), verify5, 463 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_USTAR); 464 verify(archive6, sizeof(archive6), verify6, 465 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_USTAR); 466 verify(archiveK, sizeof(archiveK), verifyK, 467 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_GNUTAR); 468 verify(archivexL, sizeof(archivexL), verifyxL, 469 ARCHIVE_FILTER_NONE, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE); 470 } 471 472 473