"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Rob Landley | 06249fe | 2006-02-20 19:28:53 +0000 | [diff] [blame] | 2 | /* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Glenn L McGrath | 6aa5223 | 2004-02-17 11:55:06 +0000 | [diff] [blame] | 3 | * |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 4 | * FIXME: |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 5 | * In privileged mode if uname and gname map to a uid and gid then use the |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 6 | * mapped value instead of the uid/gid values in tar header |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 7 | * |
| 8 | * References: |
| 9 | * GNU tar and star man pages, |
| 10 | * Opengroup's ustar interchange format, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 11 | * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 14 | #include "libbb.h" |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 15 | #include "unarchive.h" |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 16 | |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 17 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
| 18 | static char *longname; |
| 19 | static char *linkname; |
| 20 | #else |
| 21 | enum { |
| 22 | longname = 0, |
| 23 | linkname = 0, |
| 24 | }; |
Glenn L McGrath | b7a76df | 2002-11-23 10:44:47 +0000 | [diff] [blame] | 25 | #endif |
| 26 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 27 | /* NB: _DESTROYS_ str[len] character! */ |
| 28 | static unsigned long long getOctal(char *str, int len) |
| 29 | { |
| 30 | unsigned long long v; |
| 31 | /* Actually, tar header allows leading spaces also. |
| 32 | * Oh well, we will be liberal and skip this... |
| 33 | * The only downside probably is that we allow "-123" too :) |
| 34 | if (*str < '0' || *str > '7') |
| 35 | bb_error_msg_and_die("corrupted octal value in tar header"); |
| 36 | */ |
| 37 | str[len] = '\0'; |
| 38 | v = strtoull(str, &str, 8); |
| 39 | if (*str) |
| 40 | bb_error_msg_and_die("corrupted octal value in tar header"); |
| 41 | return v; |
| 42 | } |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 43 | #define GET_OCTAL(a) getOctal((a), sizeof(a)) |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 44 | |
| 45 | void BUG_tar_header_size(void); |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 46 | char get_header_tar(archive_handle_t *archive_handle) |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 47 | { |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 48 | static int end; |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 49 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 50 | file_header_t *file_header = archive_handle->file_header; |
| 51 | struct { |
| 52 | /* ustar header, Posix 1003.1 */ |
| 53 | char name[100]; /* 0-99 */ |
| 54 | char mode[8]; /* 100-107 */ |
| 55 | char uid[8]; /* 108-115 */ |
| 56 | char gid[8]; /* 116-123 */ |
| 57 | char size[12]; /* 124-135 */ |
| 58 | char mtime[12]; /* 136-147 */ |
| 59 | char chksum[8]; /* 148-155 */ |
| 60 | char typeflag; /* 156-156 */ |
| 61 | char linkname[100]; /* 157-256 */ |
| 62 | char magic[6]; /* 257-262 */ |
| 63 | char version[2]; /* 263-264 */ |
| 64 | char uname[32]; /* 265-296 */ |
| 65 | char gname[32]; /* 297-328 */ |
| 66 | char devmajor[8]; /* 329-336 */ |
| 67 | char devminor[8]; /* 337-344 */ |
| 68 | char prefix[155]; /* 345-499 */ |
| 69 | char padding[12]; /* 500-512 */ |
| 70 | } tar; |
| 71 | char *cp; |
| 72 | int sum, i; |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 73 | int parse_names; |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 74 | |
| 75 | if (sizeof(tar) != 512) |
| 76 | BUG_tar_header_size(); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 77 | again: |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 78 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 79 | /* Align header */ |
Glenn L McGrath | 237ae42 | 2002-11-03 14:05:15 +0000 | [diff] [blame] | 80 | data_align(archive_handle, 512); |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 81 | |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 82 | again_after_align: |
| 83 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 84 | xread(archive_handle->src_fd, &tar, 512); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 85 | archive_handle->offset += 512; |
| 86 | |
| 87 | /* If there is no filename its an empty header */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 88 | if (tar.name[0] == 0) { |
Paul Fox | 94ff9f1 | 2005-07-20 19:24:13 +0000 | [diff] [blame] | 89 | if (end) { |
| 90 | /* This is the second consecutive empty header! End of archive! |
| 91 | * Read until the end to empty the pipe from gz or bz2 |
| 92 | */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 93 | while (full_read(archive_handle->src_fd, &tar, 512) == 512) |
| 94 | /* repeat */; |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 95 | return EXIT_FAILURE; |
Paul Fox | 94ff9f1 | 2005-07-20 19:24:13 +0000 | [diff] [blame] | 96 | } |
| 97 | end = 1; |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 98 | return EXIT_SUCCESS; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 99 | } |
Paul Fox | 94ff9f1 | 2005-07-20 19:24:13 +0000 | [diff] [blame] | 100 | end = 0; |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 101 | |
Glenn L McGrath | 1d23f3a | 2002-08-13 05:06:43 +0000 | [diff] [blame] | 102 | /* Check header has valid magic, "ustar" is for the proper tar |
| 103 | * 0's are for the old tar format |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 104 | */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 105 | if (strncmp(tar.magic, "ustar", 5) != 0) { |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 106 | #if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 107 | if (memcmp(tar.magic, "\0\0\0\0", 5) != 0) |
Glenn L McGrath | 1d23f3a | 2002-08-13 05:06:43 +0000 | [diff] [blame] | 108 | #endif |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 109 | bb_error_msg_and_die("invalid tar magic"); |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 110 | } |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 111 | /* Do checksum on headers */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 112 | sum = ' ' * sizeof(tar.chksum); |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 113 | for (i = 0; i < 148 ; i++) { |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 114 | sum += ((char*)&tar)[i]; |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 115 | } |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 116 | for (i = 156; i < 512 ; i++) { |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 117 | sum += ((char*)&tar)[i]; |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 118 | } |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 119 | /* This field does not need special treatment (getOctal) */ |
| 120 | if (sum != xstrtoul(tar.chksum, 8)) { |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 121 | bb_error_msg_and_die("invalid tar header checksum"); |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 124 | /* 0 is reserved for high perf file, treat as normal file */ |
| 125 | if (!tar.typeflag) tar.typeflag = '0'; |
| 126 | parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7'); |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 127 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 128 | /* getOctal trashes subsequent field, therefore we call it |
| 129 | * on fields in reverse order */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 130 | if (tar.devmajor[0]) { |
| 131 | unsigned minor = GET_OCTAL(tar.devminor); |
| 132 | unsigned major = GET_OCTAL(tar.devmajor); |
| 133 | file_header->device = makedev(major, minor); |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 134 | } |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 135 | file_header->link_name = NULL; |
| 136 | if (!linkname && parse_names && tar.linkname[0]) { |
| 137 | /* we trash magic[0] here, it's ok */ |
| 138 | tar.linkname[sizeof(tar.linkname)] = '\0'; |
| 139 | file_header->link_name = xstrdup(tar.linkname); |
| 140 | /* FIXME: what if we have non-link object with link_name? */ |
| 141 | /* Will link_name be free()ed? */ |
| 142 | } |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 143 | file_header->mtime = GET_OCTAL(tar.mtime); |
| 144 | file_header->size = GET_OCTAL(tar.size); |
| 145 | file_header->gid = GET_OCTAL(tar.gid); |
| 146 | file_header->uid = GET_OCTAL(tar.uid); |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 147 | /* Set bits 0-11 of the files mode */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 148 | file_header->mode = 07777 & GET_OCTAL(tar.mode); |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 149 | |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 150 | file_header->name = NULL; |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 151 | if (!longname && parse_names) { |
| 152 | /* we trash mode[0] here, it's ok */ |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 153 | tar.name[sizeof(tar.name)] = '\0'; |
Denis Vlasenko | 87cd4a8 | 2006-11-25 23:47:32 +0000 | [diff] [blame] | 154 | if (tar.prefix[0]) { |
| 155 | /* and padding[0] */ |
| 156 | tar.prefix[sizeof(tar.prefix)] = '\0'; |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 157 | file_header->name = concat_path_file(tar.prefix, tar.name); |
Denis Vlasenko | 87cd4a8 | 2006-11-25 23:47:32 +0000 | [diff] [blame] | 158 | } else |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 159 | file_header->name = xstrdup(tar.name); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 160 | /* FIXME: add check for /../ attacks */ |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 163 | /* Set bits 12-15 of the files mode */ |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 164 | /* (typeflag was not trashed because chksum does not use getOctal) */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 165 | switch (tar.typeflag) { |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 166 | /* busybox identifies hard links as being regular files with 0 size and a link name */ |
| 167 | case '1': |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 168 | file_header->mode |= S_IFREG; |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 169 | break; |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 170 | case '7': |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 171 | /* case 0: */ |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 172 | case '0': |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 173 | #if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY |
Glenn L McGrath | 87af49f | 2003-09-09 17:41:03 +0000 | [diff] [blame] | 174 | if (last_char_is(file_header->name, '/')) { |
| 175 | file_header->mode |= S_IFDIR; |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 176 | } else |
| 177 | #endif |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 178 | file_header->mode |= S_IFREG; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 179 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 180 | case '2': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 181 | file_header->mode |= S_IFLNK; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 182 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 183 | case '3': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 184 | file_header->mode |= S_IFCHR; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 185 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 186 | case '4': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 187 | file_header->mode |= S_IFBLK; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 188 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 189 | case '5': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 190 | file_header->mode |= S_IFDIR; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 191 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 192 | case '6': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 193 | file_header->mode |= S_IFIFO; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 194 | break; |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 195 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 196 | case 'L': |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 197 | /* free: paranoia: tar with several consecutive longnames */ |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 198 | free(longname); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 199 | /* For paranoia reasons we allocate extra NUL char */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 200 | longname = xzalloc(file_header->size + 1); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 201 | /* We read ASCIZ string, including NUL */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 202 | xread(archive_handle->src_fd, longname, file_header->size); |
| 203 | archive_handle->offset += file_header->size; |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 204 | /* return get_header_tar(archive_handle); */ |
| 205 | /* gcc 4.1.1 didn't optimize it into jump */ |
| 206 | /* so we will do it ourself, this also saves stack */ |
| 207 | goto again; |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 208 | case 'K': |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 209 | free(linkname); |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 210 | linkname = xzalloc(file_header->size + 1); |
| 211 | xread(archive_handle->src_fd, linkname, file_header->size); |
| 212 | archive_handle->offset += file_header->size; |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 213 | /* return get_header_tar(archive_handle); */ |
| 214 | goto again; |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 215 | case 'D': /* GNU dump dir */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 216 | case 'M': /* Continuation of multi volume archive */ |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 217 | case 'N': /* Old GNU for names > 100 characters */ |
| 218 | case 'S': /* Sparse file */ |
| 219 | case 'V': /* Volume header */ |
Glenn L McGrath | 6aa5223 | 2004-02-17 11:55:06 +0000 | [diff] [blame] | 220 | #endif |
Rob Landley | ff6e21c | 2006-07-06 20:30:19 +0000 | [diff] [blame] | 221 | case 'g': /* pax global header */ |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 222 | case 'x': { /* pax extended header */ |
| 223 | off_t sz; |
| 224 | bb_error_msg("warning: skipping header '%c'", tar.typeflag); |
| 225 | sz = (file_header->size + 511) & ~(off_t)511; |
| 226 | archive_handle->offset += sz; |
| 227 | sz >>= 9; /* sz /= 512 but w/o contortions for signed div */ |
| 228 | while (sz--) |
| 229 | xread(archive_handle->src_fd, &tar, 512); |
| 230 | /* return get_header_tar(archive_handle); */ |
| 231 | goto again_after_align; |
| 232 | } |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 233 | default: |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 234 | bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag); |
Glenn L McGrath | 6aa5223 | 2004-02-17 11:55:06 +0000 | [diff] [blame] | 235 | } |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 236 | |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 237 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
| 238 | if (longname) { |
| 239 | file_header->name = longname; |
| 240 | longname = NULL; |
| 241 | } |
| 242 | if (linkname) { |
| 243 | file_header->link_name = linkname; |
| 244 | linkname = NULL; |
| 245 | } |
| 246 | #endif |
| 247 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 248 | /* Strip trailing '/' in directories */ |
| 249 | /* Must be done after mode is set as '/' is used to check if its a directory */ |
| 250 | cp = last_char_is(file_header->name, '/'); |
Glenn L McGrath | 3d5828f | 2003-08-14 02:55:15 +0000 | [diff] [blame] | 251 | |
Glenn L McGrath | 8e94098 | 2002-11-04 23:47:31 +0000 | [diff] [blame] | 252 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 253 | archive_handle->action_header(archive_handle->file_header); |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 254 | /* Note that we kill the '/' only after action_header() */ |
| 255 | /* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */ |
| 256 | if (cp) *cp = '\0'; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 257 | archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; |
| 258 | archive_handle->action_data(archive_handle); |
Rob Landley | 8bb5078 | 2006-05-26 23:44:51 +0000 | [diff] [blame] | 259 | llist_add_to(&(archive_handle->passed), file_header->name); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 260 | } else { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 261 | data_skip(archive_handle); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 262 | free(file_header->name); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 263 | } |
| 264 | archive_handle->offset += file_header->size; |
| 265 | |
Glenn L McGrath | 54ac057 | 2003-11-15 00:24:43 +0000 | [diff] [blame] | 266 | free(file_header->link_name); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame^] | 267 | /* Do not free(file_header->name)! */ |
Glenn L McGrath | 54ac057 | 2003-11-15 00:24:43 +0000 | [diff] [blame] | 268 | |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 269 | return EXIT_SUCCESS; |
Eric Andersen | 2276d83 | 2002-07-11 11:11:56 +0000 | [diff] [blame] | 270 | } |