aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c117
1 files changed, 113 insertions, 4 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 3129781d2..2909eca1b 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -22,7 +22,6 @@
22 * 22 *
23 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 23 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
24 */ 24 */
25
26/* TODO: security with -C DESTDIR option can be enhanced. 25/* TODO: security with -C DESTDIR option can be enhanced.
27 * Consider tar file created via: 26 * Consider tar file created via:
28 * $ tar cvf bug.tar anything.txt 27 * $ tar cvf bug.tar anything.txt
@@ -42,6 +41,109 @@
42 * This doesn't feel right, and IIRC GNU tar doesn't do that. 41 * This doesn't feel right, and IIRC GNU tar doesn't do that.
43 */ 42 */
44 43
44//config:config TAR
45//config: bool "tar"
46//config: default y
47//config: help
48//config: tar is an archiving program. It's commonly used with gzip to
49//config: create compressed archives. It's probably the most widely used
50//config: UNIX archive program.
51//config:
52//config:config FEATURE_TAR_CREATE
53//config: bool "Enable archive creation"
54//config: default y
55//config: depends on TAR
56//config: help
57//config: If you enable this option you'll be able to create
58//config: tar archives using the `-c' option.
59//config:
60//config:config FEATURE_TAR_AUTODETECT
61//config: bool "Autodetect compressed tarballs"
62//config: default y
63//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
64//config: help
65//config: With this option tar can automatically detect compressed
66//config: tarballs. Currently it works only on files (not pipes etc).
67//config:
68//config:config FEATURE_TAR_FROM
69//config: bool "Enable -X (exclude from) and -T (include from) options)"
70//config: default y
71//config: depends on TAR
72//config: help
73//config: If you enable this option you'll be able to specify
74//config: a list of files to include or exclude from an archive.
75//config:
76//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
77//config: bool "Support for old tar header format"
78//config: default y
79//config: depends on TAR || DPKG
80//config: help
81//config: This option is required to unpack archives created in
82//config: the old GNU format; help to kill this old format by
83//config: repacking your ancient archives with the new format.
84//config:
85//config:config FEATURE_TAR_OLDSUN_COMPATIBILITY
86//config: bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
87//config: default y
88//config: depends on TAR || DPKG
89//config: help
90//config: This option is required to unpack archives created by some old
91//config: version of Sun's tar (it was calculating checksum using signed
92//config: arithmetic). It is said to be fixed in newer Sun tar, but "old"
93//config: tarballs still exist.
94//config:
95//config:config FEATURE_TAR_GNU_EXTENSIONS
96//config: bool "Support for GNU tar extensions (long filenames)"
97//config: default y
98//config: depends on TAR || DPKG
99//config: help
100//config: With this option busybox supports GNU long filenames and
101//config: linknames.
102//config:
103//config:config FEATURE_TAR_LONG_OPTIONS
104//config: bool "Enable long options"
105//config: default y
106//config: depends on TAR && LONG_OPTS
107//config: help
108//config: Enable use of long options, increases size by about 400 Bytes
109//config:
110//config:config FEATURE_TAR_TO_COMMAND
111//config: bool "Support for writing to an external program"
112//config: default y
113//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
114//config: help
115//config: If you enable this option you'll be able to instruct tar to send
116//config: the contents of each extracted file to the standard input of an
117//config: external program.
118//config:
119//config:config FEATURE_TAR_UNAME_GNAME
120//config: bool "Enable use of user and group names"
121//config: default y
122//config: depends on TAR
123//config: help
124//config: Enables use of user and group names in tar. This affects contents
125//config: listings (-t) and preserving permissions when unpacking (-p).
126//config: +200 bytes.
127//config:
128//config:config FEATURE_TAR_NOPRESERVE_TIME
129//config: bool "Enable -m (do not preserve time) option"
130//config: default y
131//config: depends on TAR
132//config: help
133//config: With this option busybox supports GNU tar -m
134//config: (do not preserve time) option.
135//config:
136//config:config FEATURE_TAR_SELINUX
137//config: bool "Support for extracting SELinux labels"
138//config: default n
139//config: depends on TAR && SELINUX
140//config: help
141//config: With this option busybox supports restoring SELinux labels
142//config: when extracting files from tar archives.
143
144//applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP))
145//kbuild:lib-$(CONFIG_TAR) += tar.o
146
45#include <fnmatch.h> 147#include <fnmatch.h>
46#include "libbb.h" 148#include "libbb.h"
47#include "bb_archive.h" 149#include "bb_archive.h"
@@ -1096,8 +1198,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1096 /*tar_handle->offset = 0; - already is */ 1198 /*tar_handle->offset = 0; - already is */
1097 } 1199 }
1098 1200
1201 /* Zero processed headers (== empty file) is not a valid tarball.
1202 * We (ab)use bb_got_signal as exitcode here,
1203 * because check_errors_in_children() uses _it_ as error indicator.
1204 */
1205 bb_got_signal = EXIT_FAILURE;
1206
1099 while (get_header_tar(tar_handle) == EXIT_SUCCESS) 1207 while (get_header_tar(tar_handle) == EXIT_SUCCESS)
1100 continue; 1208 bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
1101 1209
1102 /* Check that every file that should have been extracted was */ 1210 /* Check that every file that should have been extracted was */
1103 while (tar_handle->accept) { 1211 while (tar_handle->accept) {
@@ -1113,8 +1221,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1113 close(tar_handle->src_fd); 1221 close(tar_handle->src_fd);
1114 1222
1115 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { 1223 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
1224 /* Set bb_got_signal to 1 if a child died with !0 exitcode */
1116 check_errors_in_children(0); 1225 check_errors_in_children(0);
1117 return bb_got_signal;
1118 } 1226 }
1119 return EXIT_SUCCESS; 1227
1228 return bb_got_signal;
1120} 1229}