diff options
Diffstat (limited to 'archival')
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 40 | ||||
-rw-r--r-- | archival/tar.c | 107 |
2 files changed, 75 insertions, 72 deletions
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index fcddcb834..01c10433e 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -118,34 +118,10 @@ static char *get_selinux_sctx_from_pax_hdr(archive_handle_t *archive_handle, uns | |||
118 | } | 118 | } |
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | void BUG_tar_header_size(void); | ||
122 | char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | 121 | char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) |
123 | { | 122 | { |
124 | file_header_t *file_header = archive_handle->file_header; | 123 | file_header_t *file_header = archive_handle->file_header; |
125 | struct { | 124 | struct tar_header_t tar; |
126 | /* ustar header, Posix 1003.1 */ | ||
127 | char name[100]; /* 0-99 */ | ||
128 | char mode[8]; /* 100-107 */ | ||
129 | char uid[8]; /* 108-115 */ | ||
130 | char gid[8]; /* 116-123 */ | ||
131 | char size[12]; /* 124-135 */ | ||
132 | char mtime[12]; /* 136-147 */ | ||
133 | char chksum[8]; /* 148-155 */ | ||
134 | char typeflag; /* 156-156 */ | ||
135 | char linkname[100]; /* 157-256 */ | ||
136 | /* POSIX: "ustar" NUL "00" */ | ||
137 | /* GNU tar: "ustar " NUL */ | ||
138 | /* Normally it's defined as magic[6] followed by | ||
139 | * version[2], but we put them together to simplify code | ||
140 | */ | ||
141 | char magic[8]; /* 257-264 */ | ||
142 | char uname[32]; /* 265-296 */ | ||
143 | char gname[32]; /* 297-328 */ | ||
144 | char devmajor[8]; /* 329-336 */ | ||
145 | char devminor[8]; /* 337-344 */ | ||
146 | char prefix[155]; /* 345-499 */ | ||
147 | char padding[12]; /* 500-512 */ | ||
148 | } tar; | ||
149 | char *cp; | 125 | char *cp; |
150 | int i, sum_u, sum; | 126 | int i, sum_u, sum; |
151 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY | 127 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY |
@@ -162,9 +138,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
162 | # define p_linkname 0 | 138 | # define p_linkname 0 |
163 | #endif | 139 | #endif |
164 | 140 | ||
165 | if (sizeof(tar) != 512) | ||
166 | BUG_tar_header_size(); | ||
167 | |||
168 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX | 141 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX |
169 | again: | 142 | again: |
170 | #endif | 143 | #endif |
@@ -230,18 +203,21 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
230 | * we can switch to get_header_tar_gz/bz2/lzma(). | 203 | * we can switch to get_header_tar_gz/bz2/lzma(). |
231 | * Needs seekable fd. I wish recv(MSG_PEEK) works | 204 | * Needs seekable fd. I wish recv(MSG_PEEK) works |
232 | * on any fd... */ | 205 | * on any fd... */ |
233 | #if ENABLE_FEATURE_SEAMLESS_GZ | 206 | # if ENABLE_FEATURE_SEAMLESS_GZ |
234 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ | 207 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ |
235 | get_header_ptr = get_header_tar_gz; | 208 | get_header_ptr = get_header_tar_gz; |
236 | } else | 209 | } else |
237 | #endif | 210 | # endif |
238 | #if ENABLE_FEATURE_SEAMLESS_BZ2 | 211 | # if ENABLE_FEATURE_SEAMLESS_BZ2 |
239 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' | 212 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' |
240 | && tar.name[2] == 'h' && isdigit(tar.name[3]) | 213 | && tar.name[2] == 'h' && isdigit(tar.name[3]) |
241 | ) { /* bzip2 */ | 214 | ) { /* bzip2 */ |
242 | get_header_ptr = get_header_tar_bz2; | 215 | get_header_ptr = get_header_tar_bz2; |
243 | } else | 216 | } else |
244 | #endif | 217 | # endif |
218 | # if ENABLE_FEATURE_SEAMLESS_XZ | ||
219 | //TODO | ||
220 | # endif | ||
245 | goto err; | 221 | goto err; |
246 | /* Two different causes for lseek() != 0: | 222 | /* Two different causes for lseek() != 0: |
247 | * unseekable fd (would like to support that too, but...), | 223 | * unseekable fd (would like to support that too, but...), |
diff --git a/archival/tar.c b/archival/tar.c index 344c9dea4..f49fb129e 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -48,37 +48,6 @@ | |||
48 | 48 | ||
49 | #if ENABLE_FEATURE_TAR_CREATE | 49 | #if ENABLE_FEATURE_TAR_CREATE |
50 | 50 | ||
51 | /* Tar file constants */ | ||
52 | |||
53 | #define TAR_BLOCK_SIZE 512 | ||
54 | |||
55 | /* POSIX tar Header Block, from POSIX 1003.1-1990 */ | ||
56 | #define NAME_SIZE 100 | ||
57 | #define NAME_SIZE_STR "100" | ||
58 | typedef struct TarHeader { /* byte offset */ | ||
59 | char name[NAME_SIZE]; /* 0-99 */ | ||
60 | char mode[8]; /* 100-107 */ | ||
61 | char uid[8]; /* 108-115 */ | ||
62 | char gid[8]; /* 116-123 */ | ||
63 | char size[12]; /* 124-135 */ | ||
64 | char mtime[12]; /* 136-147 */ | ||
65 | char chksum[8]; /* 148-155 */ | ||
66 | char typeflag; /* 156-156 */ | ||
67 | char linkname[NAME_SIZE]; /* 157-256 */ | ||
68 | /* POSIX: "ustar" NUL "00" */ | ||
69 | /* GNU tar: "ustar " NUL */ | ||
70 | /* Normally it's defined as magic[6] followed by | ||
71 | * version[2], but we put them together to save code. | ||
72 | */ | ||
73 | char magic[8]; /* 257-264 */ | ||
74 | char uname[32]; /* 265-296 */ | ||
75 | char gname[32]; /* 297-328 */ | ||
76 | char devmajor[8]; /* 329-336 */ | ||
77 | char devminor[8]; /* 337-344 */ | ||
78 | char prefix[155]; /* 345-499 */ | ||
79 | char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */ | ||
80 | } TarHeader; | ||
81 | |||
82 | /* | 51 | /* |
83 | ** writeTarFile(), writeFileToTarball(), and writeTarHeader() are | 52 | ** writeTarFile(), writeFileToTarball(), and writeTarHeader() are |
84 | ** the only functions that deal with the HardLinkInfo structure. | 53 | ** the only functions that deal with the HardLinkInfo structure. |
@@ -193,7 +162,7 @@ static void putOctal(char *cp, int len, off_t value) | |||
193 | } | 162 | } |
194 | #define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) | 163 | #define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) |
195 | 164 | ||
196 | static void chksum_and_xwrite(int fd, struct TarHeader* hp) | 165 | static void chksum_and_xwrite(int fd, struct tar_header_t* hp) |
197 | { | 166 | { |
198 | /* POSIX says that checksum is done on unsigned bytes | 167 | /* POSIX says that checksum is done on unsigned bytes |
199 | * (Sun and HP-UX gets it wrong... more details in | 168 | * (Sun and HP-UX gets it wrong... more details in |
@@ -235,7 +204,7 @@ static void writeLongname(int fd, int type, const char *name, int dir) | |||
235 | "00000000000", | 204 | "00000000000", |
236 | "00000000000", | 205 | "00000000000", |
237 | }; | 206 | }; |
238 | struct TarHeader header; | 207 | struct tar_header_t header; |
239 | int size; | 208 | int size; |
240 | 209 | ||
241 | dir = !!dir; /* normalize: 0/1 */ | 210 | dir = !!dir; /* normalize: 0/1 */ |
@@ -262,17 +231,13 @@ static void writeLongname(int fd, int type, const char *name, int dir) | |||
262 | #endif | 231 | #endif |
263 | 232 | ||
264 | /* Write out a tar header for the specified file/directory/whatever */ | 233 | /* Write out a tar header for the specified file/directory/whatever */ |
265 | void BUG_tar_header_size(void); | ||
266 | static int writeTarHeader(struct TarBallInfo *tbInfo, | 234 | static int writeTarHeader(struct TarBallInfo *tbInfo, |
267 | const char *header_name, const char *fileName, struct stat *statbuf) | 235 | const char *header_name, const char *fileName, struct stat *statbuf) |
268 | { | 236 | { |
269 | struct TarHeader header; | 237 | struct tar_header_t header; |
270 | |||
271 | if (sizeof(header) != 512) | ||
272 | BUG_tar_header_size(); | ||
273 | |||
274 | memset(&header, 0, sizeof(struct TarHeader)); | ||
275 | 238 | ||
239 | memset(&header, 0, sizeof(header)); | ||
240 | |||
276 | strncpy(header.name, header_name, sizeof(header.name)); | 241 | strncpy(header.name, header_name, sizeof(header.name)); |
277 | 242 | ||
278 | /* POSIX says to mask mode with 07777. */ | 243 | /* POSIX says to mask mode with 07777. */ |
@@ -738,6 +703,68 @@ static void handle_SIGCHLD(int status) | |||
738 | } | 703 | } |
739 | #endif | 704 | #endif |
740 | 705 | ||
706 | //usage:#define tar_trivial_usage | ||
707 | //usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt" IF_FEATURE_SEAMLESS_GZ("z") | ||
708 | //usage: IF_FEATURE_SEAMLESS_BZ2("j") IF_FEATURE_SEAMLESS_LZMA("a") | ||
709 | //usage: IF_FEATURE_SEAMLESS_Z("Z") IF_FEATURE_TAR_NOPRESERVE_TIME("m") "vO] " | ||
710 | //usage: IF_FEATURE_TAR_FROM("[-X FILE] ") | ||
711 | //usage: "[-f TARFILE] [-C DIR] [FILE]..." | ||
712 | //usage:#define tar_full_usage "\n\n" | ||
713 | //usage: IF_FEATURE_TAR_CREATE("Create, extract, ") | ||
714 | //usage: IF_NOT_FEATURE_TAR_CREATE("Extract ") | ||
715 | //usage: "or list files from a tar file\n" | ||
716 | //usage: "\nOperation:" | ||
717 | //usage: IF_FEATURE_TAR_CREATE( | ||
718 | //usage: "\n c Create" | ||
719 | //usage: ) | ||
720 | //usage: "\n x Extract" | ||
721 | //usage: "\n t List" | ||
722 | //usage: "\nOptions:" | ||
723 | //usage: "\n f Name of TARFILE ('-' for stdin/out)" | ||
724 | //usage: "\n C Change to DIR before operation" | ||
725 | //usage: "\n v Verbose" | ||
726 | //usage: IF_FEATURE_SEAMLESS_GZ( | ||
727 | //usage: "\n z (De)compress using gzip" | ||
728 | //usage: ) | ||
729 | //usage: IF_FEATURE_SEAMLESS_BZ2( | ||
730 | //usage: "\n j (De)compress using bzip2" | ||
731 | //usage: ) | ||
732 | //usage: IF_FEATURE_SEAMLESS_LZMA( | ||
733 | //usage: "\n a (De)compress using lzma" | ||
734 | //usage: ) | ||
735 | //usage: IF_FEATURE_SEAMLESS_Z( | ||
736 | //usage: "\n Z (De)compress using compress" | ||
737 | //usage: ) | ||
738 | //usage: "\n O Extract to stdout" | ||
739 | //usage: IF_FEATURE_TAR_CREATE( | ||
740 | //usage: "\n h Follow symlinks" | ||
741 | //usage: ) | ||
742 | //usage: IF_FEATURE_TAR_NOPRESERVE_TIME( | ||
743 | //usage: "\n m Don't restore mtime" | ||
744 | //usage: ) | ||
745 | //usage: IF_FEATURE_TAR_FROM( | ||
746 | //usage: IF_FEATURE_TAR_LONG_OPTIONS( | ||
747 | //usage: "\n exclude File to exclude" | ||
748 | //usage: ) | ||
749 | //usage: "\n X File with names to exclude" | ||
750 | //usage: "\n T File with names to include" | ||
751 | //usage: ) | ||
752 | //usage: | ||
753 | //usage:#define tar_example_usage | ||
754 | //usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" | ||
755 | //usage: "$ tar -cf /tmp/tarball.tar /usr/local\n" | ||
756 | |||
757 | // Supported but aren't in --help: | ||
758 | // o no-same-owner | ||
759 | // p same-permissions | ||
760 | // k keep-old | ||
761 | // numeric-owner | ||
762 | // no-same-permissions | ||
763 | // overwrite | ||
764 | //IF_FEATURE_TAR_TO_COMMAND( | ||
765 | // to-command | ||
766 | //) | ||
767 | |||
741 | enum { | 768 | enum { |
742 | OPTBIT_KEEP_OLD = 8, | 769 | OPTBIT_KEEP_OLD = 8, |
743 | IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,) | 770 | IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,) |