Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (6 years ago)
Author:
bruno
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/archival
Files:
49 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/archival/Config.src

    r2725 r3232  
    3333
    3434config FEATURE_SEAMLESS_Z
    35     bool "Make tar and gunzip understand .Z data"
    36     default n
    37     help
    38       Make tar and gunzip understand .Z data.
     35    bool "tar, rpm, modprobe etc understand .Z data"
     36    default n
     37    help
     38      Make tar, rpm, modprobe etc understand .Z data.
    3939
    4040config AR
     
    188188      Enable use of long options, increases size by about 106 Bytes
    189189
     190config GZIP_FAST
     191    int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
     192    default 0
     193    range 0 2
     194    depends on GZIP
     195    help
     196      Enable big memory options for gzip.
     197      0: small buffers, small hash-tables
     198      1: larger buffers, larger hash-tables
     199      2: larger buffers, largest hash-tables
     200      Larger models may give slightly better compression
     201
    190202config LZOP
    191203    bool "lzop"
     
    331343      compressors.
    332344
    333       The BusyBox unlzma applet is limited to de-compression only.
     345      The BusyBox unlzma applet is limited to decompression only.
    334346      On an x86 system, this applet adds about 4K.
    335 
    336       Unless you have a specific application which requires unlzma, you
    337       should probably say N here.
    338347
    339348config FEATURE_LZMA_FAST
    340349    bool "Optimize unlzma for speed"
    341     default y
     350    default n
    342351    depends on UNLZMA
    343352    help
  • branches/3.2/mindi-busybox/archival/ar.c

    r2725 r3232  
    1818 */
    1919
     20//usage:#define ar_trivial_usage
     21//usage:       "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
     22//usage:#define ar_full_usage "\n\n"
     23//usage:       "Extract or list FILES from an ar archive\n"
     24//usage:     "\n    -o  Preserve original dates"
     25//usage:     "\n    -p  Extract to stdout"
     26//usage:     "\n    -t  List"
     27//usage:     "\n    -x  Extract"
     28//usage:     "\n    -v  Verbose"
     29
    2030#include "libbb.h"
    21 #include "archive.h"
     31#include "bb_archive.h"
    2232#include "ar.h"
    2333
     
    7282
    7383/*
    74  * when replacing files in an existing archive, copy from the the
     84 * when replacing files in an existing archive, copy from the
    7585 * original archive those files that are to be left intact
    7686 */
  • branches/3.2/mindi-busybox/archival/bbunzip.c

    r2725 r3232  
    66 */
    77#include "libbb.h"
    8 #include "archive.h"
     8#include "bb_archive.h"
    99
    1010enum {
     
    3434
    3535int FAST_FUNC bbunpack(char **argv,
    36     IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(unpack_info_t *info),
     36    IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
    3737    char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
    3838    const char *expected_ext
     
    4343    char *filename, *new_name;
    4444    smallint exitcode = 0;
    45     unpack_info_t info;
     45    transformer_aux_data_t aux;
    4646
    4747    do {
     
    9999        }
    100100
    101         /* memset(&info, 0, sizeof(info)); */
    102         info.mtime = 0; /* so far it has one member only */
    103         status = unpacker(&info);
     101        init_transformer_aux_data(&aux);
     102        aux.check_signature = 1;
     103        status = unpacker(&aux);
    104104        if (status < 0)
    105105            exitcode = 1;
    106         xclose(STDOUT_FILENO); /* with error check! */
     106
     107        if (!(option_mask32 & OPT_STDOUT))
     108            xclose(STDOUT_FILENO); /* with error check! */
    107109
    108110        if (filename) {
     
    110112            if (status >= 0) {
    111113                /* TODO: restore other things? */
    112                 if (info.mtime) {
     114                if (aux.mtime != 0) {
    113115                    struct timeval times[2];
    114116
    115                     times[1].tv_sec = times[0].tv_sec = info.mtime;
     117                    times[1].tv_sec = times[0].tv_sec = aux.mtime;
    116118                    times[1].tv_usec = times[0].tv_usec = 0;
    117119                    /* Note: we closed it first.
     
    143145        }
    144146    } while (*argv && *++argv);
     147
     148    if (option_mask32 & OPT_STDOUT)
     149        xclose(STDOUT_FILENO); /* with error check! */
    145150
    146151    return exitcode;
     
    168173 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    169174 */
     175
     176//usage:#define uncompress_trivial_usage
     177//usage:       "[-cf] [FILE]..."
     178//usage:#define uncompress_full_usage "\n\n"
     179//usage:       "Decompress .Z file[s]\n"
     180//usage:     "\n    -c  Write to stdout"
     181//usage:     "\n    -f  Overwrite"
     182
    170183#if ENABLE_UNCOMPRESS
    171184static
    172 IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(unpack_info_t *info UNUSED_PARAM)
    173 {
    174     IF_DESKTOP(long long) int status = -1;
    175 
    176     if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
    177         bb_error_msg("invalid magic");
    178     } else {
    179         status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
    180     }
    181     return status;
     185IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
     186{
     187    return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    182188}
    183189int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    219225 * See the file algorithm.doc for the compression algorithms and file formats.
    220226 */
     227
     228//usage:#define gunzip_trivial_usage
     229//usage:       "[-cft] [FILE]..."
     230//usage:#define gunzip_full_usage "\n\n"
     231//usage:       "Decompress FILEs (or stdin)\n"
     232//usage:     "\n    -c  Write to stdout"
     233//usage:     "\n    -f  Force"
     234//usage:     "\n    -t  Test file integrity"
     235//usage:
     236//usage:#define gunzip_example_usage
     237//usage:       "$ ls -la /tmp/BusyBox*\n"
     238//usage:       "-rw-rw-r--    1 andersen andersen   557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n"
     239//usage:       "$ gunzip /tmp/BusyBox-0.43.tar.gz\n"
     240//usage:       "$ ls -la /tmp/BusyBox*\n"
     241//usage:       "-rw-rw-r--    1 andersen andersen  1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar\n"
     242//usage:
     243//usage:#define zcat_trivial_usage
     244//usage:       "FILE"
     245//usage:#define zcat_full_usage "\n\n"
     246//usage:       "Decompress to stdout"
     247
    221248#if ENABLE_GUNZIP
    222249static
     
    246273}
    247274static
    248 IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(unpack_info_t *info)
    249 {
    250     IF_DESKTOP(long long) int status = -1;
    251 
    252     /* do the decompression, and cleanup */
    253     if (xread_char(STDIN_FILENO) == 0x1f) {
    254         unsigned char magic2;
    255 
    256         magic2 = xread_char(STDIN_FILENO);
    257         if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) {
    258             status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
    259         } else if (magic2 == 0x8b) {
    260             status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info);
    261         } else {
    262             goto bad_magic;
    263         }
    264         if (status < 0) {
    265             bb_error_msg("error inflating");
    266         }
    267     } else {
    268  bad_magic:
    269         bb_error_msg("invalid magic");
    270         /* status is still == -1 */
    271     }
    272     return status;
     275IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
     276{
     277    return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    273278}
    274279/*
     
    309314//usage:#define bunzip2_full_usage "\n\n"
    310315//usage:       "Decompress FILEs (or stdin)\n"
    311 //usage:     "\nOptions:"
    312316//usage:     "\n    -c  Write to stdout"
    313317//usage:     "\n    -f  Force"
     
    316320//usage:#define bzcat_full_usage "\n\n"
    317321//usage:       "Decompress to stdout"
    318 //applet:IF_BUNZIP2(APPLET(bunzip2, _BB_DIR_USR_BIN, _BB_SUID_DROP))
    319 //applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, _BB_DIR_USR_BIN, _BB_SUID_DROP, bzcat))
     322//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
     323//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
    320324#if ENABLE_BUNZIP2
    321325static
    322 IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(unpack_info_t *info UNUSED_PARAM)
    323 {
    324     return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO);
     326IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
     327{
     328    return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    325329}
    326330int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    345349 * Licensed under GPLv2, see file LICENSE in this source tree.
    346350 */
     351
     352//usage:#define unlzma_trivial_usage
     353//usage:       "[-cf] [FILE]..."
     354//usage:#define unlzma_full_usage "\n\n"
     355//usage:       "Decompress FILE (or stdin)\n"
     356//usage:     "\n    -c  Write to stdout"
     357//usage:     "\n    -f  Force"
     358//usage:
     359//usage:#define lzma_trivial_usage
     360//usage:       "-d [-cf] [FILE]..."
     361//usage:#define lzma_full_usage "\n\n"
     362//usage:       "Decompress FILE (or stdin)\n"
     363//usage:     "\n    -d  Decompress"
     364//usage:     "\n    -c  Write to stdout"
     365//usage:     "\n    -f  Force"
     366//usage:
     367//usage:#define lzcat_trivial_usage
     368//usage:       "FILE"
     369//usage:#define lzcat_full_usage "\n\n"
     370//usage:       "Decompress to stdout"
     371//usage:
     372//usage:#define unxz_trivial_usage
     373//usage:       "[-cf] [FILE]..."
     374//usage:#define unxz_full_usage "\n\n"
     375//usage:       "Decompress FILE (or stdin)\n"
     376//usage:     "\n    -c  Write to stdout"
     377//usage:     "\n    -f  Force"
     378//usage:
     379//usage:#define xz_trivial_usage
     380//usage:       "-d [-cf] [FILE]..."
     381//usage:#define xz_full_usage "\n\n"
     382//usage:       "Decompress FILE (or stdin)\n"
     383//usage:     "\n    -d  Decompress"
     384//usage:     "\n    -c  Write to stdout"
     385//usage:     "\n    -f  Force"
     386//usage:
     387//usage:#define xzcat_trivial_usage
     388//usage:       "FILE"
     389//usage:#define xzcat_full_usage "\n\n"
     390//usage:       "Decompress to stdout"
     391
    347392#if ENABLE_UNLZMA
    348393static
    349 IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(unpack_info_t *info UNUSED_PARAM)
    350 {
    351     return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
     394IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
     395{
     396    return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    352397}
    353398int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    372417#if ENABLE_UNXZ
    373418static
    374 IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(unpack_info_t *info UNUSED_PARAM)
    375 {
    376     struct {
    377         uint32_t v1;
    378         uint16_t v2;
    379     } magic;
    380     xread(STDIN_FILENO, &magic, 6);
    381     if (magic.v1 != XZ_MAGIC1a || magic.v2 != XZ_MAGIC2a) {
    382         bb_error_msg("invalid magic");
    383         return -1;
    384     }
    385     return unpack_xz_stream(STDIN_FILENO, STDOUT_FILENO);
     419IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
     420{
     421    return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    386422}
    387423int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  • branches/3.2/mindi-busybox/archival/bzip2.c

    r2725 r3232  
    88 */
    99
     10//usage:#define bzip2_trivial_usage
     11//usage:       "[OPTIONS] [FILE]..."
     12//usage:#define bzip2_full_usage "\n\n"
     13//usage:       "Compress FILEs (or stdin) with bzip2 algorithm\n"
     14//usage:     "\n    -1..9   Compression level"
     15//usage:     "\n    -d  Decompress"
     16//usage:     "\n    -c  Write to stdout"
     17//usage:     "\n    -f  Force"
     18
    1019#include "libbb.h"
    11 #include "archive.h"
     20#include "bb_archive.h"
    1221
    13 #define CONFIG_BZIP2_FEATURE_SPEED 1
     22#define CONFIG_BZIP2_FAST 1
    1423
    1524/* Speed test:
     
    1928 * At SPEED 5 difference is 32.7%.
    2029 *
    21  * Test run of all CONFIG_BZIP2_FEATURE_SPEED values on a 11Mb text file:
     30 * Test run of all CONFIG_BZIP2_FAST values on a 11Mb text file:
    2231 *     Size   Time (3 runs)
    2332 * 0:  10828  4.145 4.146 4.148
     
    103112
    104113static
    105 IF_DESKTOP(long long) int FAST_FUNC compressStream(unpack_info_t *info UNUSED_PARAM)
     114IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
    106115{
    107116    IF_DESKTOP(long long) int total;
  • branches/3.2/mindi-busybox/archival/cpio.c

    r2725 r3232  
    1313 */
    1414#include "libbb.h"
    15 #include "archive.h"
     15#include "bb_archive.h"
     16
     17//usage:#define cpio_trivial_usage
     18//usage:       "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
     19//usage:       " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
     20//usage:       " [EXTR_FILE]..."
     21//usage:#define cpio_full_usage "\n\n"
     22//usage:       "Extract or list files from a cpio archive"
     23//usage:    IF_FEATURE_CPIO_O(", or"
     24//usage:     "\ncreate an archive" IF_FEATURE_CPIO_P(" (-o) or copy files (-p)")
     25//usage:        " using file list on stdin"
     26//usage:    )
     27//usage:     "\n"
     28//usage:     "\nMain operation mode:"
     29//usage:     "\n    -t  List"
     30//usage:     "\n    -i  Extract EXTR_FILEs (or all)"
     31//usage:    IF_FEATURE_CPIO_O(
     32//usage:     "\n    -o  Create (requires -H newc)"
     33//usage:    )
     34//usage:    IF_FEATURE_CPIO_P(
     35//usage:     "\n    -p DIR  Copy files to DIR"
     36//usage:    )
     37//usage:     "\n    -d  Make leading directories"
     38//usage:     "\n    -m  Preserve mtime"
     39//usage:     "\n    -v  Verbose"
     40//usage:     "\n    -u  Overwrite"
     41//usage:     "\n    -F FILE Input (-t,-i,-p) or output (-o) file"
     42//usage:    IF_FEATURE_CPIO_O(
     43//usage:     "\n    -H newc Archive format"
     44//usage:    )
    1645
    1746/* GNU cpio 2.9 --help (abridged):
     
    2150  -i, --extract              Extract files from an archive
    2251  -o, --create               Create the archive
    23   -p, --pass-through         Copy-pass mode [was ist das?!]
     52  -p, --pass-through         Copy-pass mode
    2453
    2554 Options valid in any mode:
     
    79108  -u, --unconditional        Replace all files unconditionally
    80109 */
     110
    81111enum {
    82     CPIO_OPT_EXTRACT            = (1 << 0),
    83     CPIO_OPT_TEST               = (1 << 1),
    84     CPIO_OPT_NUL_TERMINATED     = (1 << 2),
    85     CPIO_OPT_UNCONDITIONAL      = (1 << 3),
    86     CPIO_OPT_VERBOSE            = (1 << 4),
    87     CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
    88     CPIO_OPT_PRESERVE_MTIME     = (1 << 6),
    89     CPIO_OPT_DEREF              = (1 << 7),
    90     CPIO_OPT_FILE               = (1 << 8),
     112    OPT_EXTRACT            = (1 << 0),
     113    OPT_TEST               = (1 << 1),
     114    OPT_NUL_TERMINATED     = (1 << 2),
     115    OPT_UNCONDITIONAL      = (1 << 3),
     116    OPT_VERBOSE            = (1 << 4),
     117    OPT_CREATE_LEADING_DIR = (1 << 5),
     118    OPT_PRESERVE_MTIME     = (1 << 6),
     119    OPT_DEREF              = (1 << 7),
     120    OPT_FILE               = (1 << 8),
    91121    OPTBIT_FILE = 8,
    92122    IF_FEATURE_CPIO_O(OPTBIT_CREATE     ,)
     
    95125    IF_LONG_OPTS(     OPTBIT_QUIET      ,)
    96126    IF_LONG_OPTS(     OPTBIT_2STDOUT    ,)
    97     CPIO_OPT_CREATE             = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE     )) + 0,
    98     CPIO_OPT_FORMAT             = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT     )) + 0,
    99     CPIO_OPT_PASSTHROUGH        = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
    100     CPIO_OPT_QUIET              = IF_LONG_OPTS(     (1 << OPTBIT_QUIET      )) + 0,
    101     CPIO_OPT_2STDOUT            = IF_LONG_OPTS(     (1 << OPTBIT_2STDOUT    )) + 0,
     127    OPT_CREATE             = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE     )) + 0,
     128    OPT_FORMAT             = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT     )) + 0,
     129    OPT_PASSTHROUGH        = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
     130    OPT_QUIET              = IF_LONG_OPTS(     (1 << OPTBIT_QUIET      )) + 0,
     131    OPT_2STDOUT            = IF_LONG_OPTS(     (1 << OPTBIT_2STDOUT    )) + 0,
    102132};
    103133
     
    139169        struct stat st;
    140170
    141         line = (option_mask32 & CPIO_OPT_NUL_TERMINATED)
     171        line = (option_mask32 & OPT_NUL_TERMINATED)
    142172                ? bb_get_chunk_from_file(stdin, NULL)
    143173                : xmalloc_fgetline(stdin);
     
    154184                continue;
    155185            }
    156             if ((option_mask32 & CPIO_OPT_DEREF)
     186            if ((option_mask32 & OPT_DEREF)
    157187                    ? stat(name, &st)
    158188                    : lstat(name, &st)
     
    224254
    225255        bytes += printf("070701"
    226                         "%08X%08X%08X%08X%08X%08X%08X"
    227                         "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
     256                "%08X%08X%08X%08X%08X%08X%08X"
     257                "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
    228258                /* strlen+1: */ "%08X"
    229259                /* chksum: */   "00000000" /* (only for "070702" files) */
    230260                /* name,NUL: */ "%s%c",
    231                         (unsigned)(uint32_t) st.st_ino,
    232                         (unsigned)(uint32_t) st.st_mode,
    233                         (unsigned)(uint32_t) st.st_uid,
    234                         (unsigned)(uint32_t) st.st_gid,
    235                         (unsigned)(uint32_t) st.st_nlink,
    236                         (unsigned)(uint32_t) st.st_mtime,
    237                         (unsigned)(uint32_t) st.st_size,
    238                         (unsigned)(uint32_t) major(st.st_dev),
    239                         (unsigned)(uint32_t) minor(st.st_dev),
    240                         (unsigned)(uint32_t) major(st.st_rdev),
    241                         (unsigned)(uint32_t) minor(st.st_rdev),
    242                         (unsigned)(strlen(name) + 1),
    243                         name, '\0');
     261                (unsigned)(uint32_t) st.st_ino,
     262                (unsigned)(uint32_t) st.st_mode,
     263                (unsigned)(uint32_t) st.st_uid,
     264                (unsigned)(uint32_t) st.st_gid,
     265                (unsigned)(uint32_t) st.st_nlink,
     266                (unsigned)(uint32_t) st.st_mtime,
     267                (unsigned)(uint32_t) st.st_size,
     268                (unsigned)(uint32_t) major(st.st_dev),
     269                (unsigned)(uint32_t) minor(st.st_dev),
     270                (unsigned)(uint32_t) major(st.st_rdev),
     271                (unsigned)(uint32_t) minor(st.st_rdev),
     272                (unsigned)(strlen(name) + 1),
     273                name, '\0');
    244274        bytes = cpio_pad4(bytes);
    245275
     
    311341    opt = getopt32(argv, OPTION_STR, &cpio_filename);
    312342    argv += optind;
    313     if (opt & CPIO_OPT_FILE) { /* -F */
     343    if (opt & OPT_FILE) { /* -F */
    314344        xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
    315345    }
     
    317347    opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
    318348    argv += optind;
    319     if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */
     349    if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
    320350        xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
    321351    }
    322     if (opt & CPIO_OPT_PASSTHROUGH) {
     352    if (opt & OPT_PASSTHROUGH) {
    323353        pid_t pid;
    324354        struct fd_pair pp;
     
    326356        if (argv[0] == NULL)
    327357            bb_show_usage();
    328         if (opt & CPIO_OPT_CREATE_LEADING_DIR)
     358        if (opt & OPT_CREATE_LEADING_DIR)
    329359            mkdir(argv[0], 0777);
    330360        /* Crude existence check:
     
    355385        }
    356386        /* parent */
     387        USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */
    357388        xchdir(*argv++);
    358389        close(pp.wr);
    359390        xmove_fd(pp.rd, STDIN_FILENO);
    360         //opt &= ~CPIO_OPT_PASSTHROUGH;
    361         opt |= CPIO_OPT_EXTRACT;
     391        //opt &= ~OPT_PASSTHROUGH;
     392        opt |= OPT_EXTRACT;
    362393        goto skip;
    363394    }
    364395    /* -o */
    365     if (opt & CPIO_OPT_CREATE) {
     396    if (opt & OPT_CREATE) {
    366397        if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
    367398            bb_show_usage();
    368         if (opt & CPIO_OPT_FILE) {
     399        if (opt & OPT_FILE) {
    369400            xmove_fd(xopen(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
    370401        }
     
    376407
    377408    /* One of either extract or test options must be given */
    378     if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
     409    if ((opt & (OPT_TEST | OPT_EXTRACT)) == 0) {
    379410        bb_show_usage();
    380411    }
    381412
    382     if (opt & CPIO_OPT_TEST) {
     413    if (opt & OPT_TEST) {
    383414        /* if both extract and test options are given, ignore extract option */
    384         opt &= ~CPIO_OPT_EXTRACT;
     415        opt &= ~OPT_EXTRACT;
    385416        archive_handle->action_header = header_list;
    386417    }
    387     if (opt & CPIO_OPT_EXTRACT) {
     418    if (opt & OPT_EXTRACT) {
    388419        archive_handle->action_data = data_extract_all;
    389         if (opt & CPIO_OPT_2STDOUT)
     420        if (opt & OPT_2STDOUT)
    390421            archive_handle->action_data = data_extract_to_stdout;
    391422    }
    392     if (opt & CPIO_OPT_UNCONDITIONAL) {
     423    if (opt & OPT_UNCONDITIONAL) {
    393424        archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
    394425        archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
    395426    }
    396     if (opt & CPIO_OPT_VERBOSE) {
     427    if (opt & OPT_VERBOSE) {
    397428        if (archive_handle->action_header == header_list) {
    398429            archive_handle->action_header = header_verbose_list;
     
    401432        }
    402433    }
    403     if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
     434    if (opt & OPT_CREATE_LEADING_DIR) {
    404435        archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
    405436    }
    406     if (opt & CPIO_OPT_PRESERVE_MTIME) {
     437    if (opt & OPT_PRESERVE_MTIME) {
    407438        archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
    408439    }
     
    420451
    421452    if (archive_handle->cpio__blocks != (off_t)-1
    422      && !(opt & CPIO_OPT_QUIET)
     453     && !(opt & OPT_QUIET)
    423454    ) {
    424455        fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
  • branches/3.2/mindi-busybox/archival/dpkg.c

    r2725 r3232  
    2929 */
    3030
     31//usage:#define dpkg_trivial_usage
     32//usage:       "[-ilCPru] [-F OPT] PACKAGE"
     33//usage:#define dpkg_full_usage "\n\n"
     34//usage:       "Install, remove and manage Debian packages\n"
     35//usage:    IF_LONG_OPTS(
     36//usage:     "\n    -i,--install    Install the package"
     37//usage:     "\n    -l,--list   List of installed packages"
     38//usage:     "\n    --configure Configure an unpackaged package"
     39//usage:     "\n    -P,--purge  Purge all files of a package"
     40//usage:     "\n    -r,--remove Remove all but the configuration files for a package"
     41//usage:     "\n    --unpack    Unpack a package, but don't configure it"
     42//usage:     "\n    --force-depends Ignore dependency problems"
     43//usage:     "\n    --force-confnew Overwrite existing config files when installing"
     44//usage:     "\n    --force-confold Keep old config files when installing"
     45//usage:    )
     46//usage:    IF_NOT_LONG_OPTS(
     47//usage:     "\n    -i      Install the package"
     48//usage:     "\n    -l      List of installed packages"
     49//usage:     "\n    -C      Configure an unpackaged package"
     50//usage:     "\n    -P      Purge all files of a package"
     51//usage:     "\n    -r      Remove all but the configuration files for a package"
     52//usage:     "\n    -u      Unpack a package, but don't configure it"
     53//usage:     "\n    -F depends  Ignore dependency problems"
     54//usage:     "\n    -F confnew  Overwrite existing config files when installing"
     55//usage:     "\n    -F confold  Keep old config files when installing"
     56//usage:    )
     57
    3158#include "libbb.h"
    3259#include <fnmatch.h>
    33 #include "archive.h"
     60#include "bb_archive.h"
    3461
    3562/* note: if you vary hash_prime sizes be aware,
     
    675702static void set_status(const unsigned status_node_num, const char *new_value, const int position)
    676703{
    677     const unsigned new_value_len = strlen(new_value);
    678704    const unsigned new_value_num = search_name_hashtable(new_value);
    679705    unsigned want = get_status(status_node_num, 1);
    680706    unsigned flag = get_status(status_node_num, 2);
    681707    unsigned status = get_status(status_node_num, 3);
    682     int want_len = strlen(name_hashtable[want]);
    683     int flag_len = strlen(name_hashtable[flag]);
    684     int status_len = strlen(name_hashtable[status]);
    685708    char *new_status;
    686709
     
    688711        case 1:
    689712            want = new_value_num;
    690             want_len = new_value_len;
    691713            break;
    692714        case 2:
    693715            flag = new_value_num;
    694             flag_len = new_value_len;
    695716            break;
    696717        case 3:
    697718            status = new_value_num;
    698             status_len = new_value_len;
    699719            break;
    700720        default:
     
    10071027                const unsigned package_num =
    10081028                    search_package_hashtable(package_edge->name,
    1009                                  package_edge->version,
    1010                                  package_edge->operator);
     1029                                package_edge->version,
     1030                                package_edge->operator);
    10111031                int result = 0;
    10121032                if (package_hashtable[package_num] != NULL) {
     
    10951115                if (root_of_alternatives && package_edge->type != root_of_alternatives->type - 1)
    10961116                    bb_error_msg_and_die("fatal error, package dependencies corrupt: %d != %d - 1",
    1097                                  package_edge->type, root_of_alternatives->type);
     1117                            package_edge->type, root_of_alternatives->type);
    10981118
    10991119                if (package_hashtable[package_num] != NULL)
     
    16461666    init_archive_deb_data(archive_handle);
    16471667    archive_handle->dpkg__sub_archive->accept = conffile_list;
     1668    /* Why ARCHIVE_REMEMBER_NAMES?
     1669     * We want names collected in ->passed list even if conffile_list
     1670     * is NULL (otherwise get_header_tar may optimize name saving out):
     1671     */
     1672    archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_REMEMBER_NAMES | ARCHIVE_UNLINK_OLD;
    16481673    archive_handle->dpkg__sub_archive->filter = filter_rename_config;
    16491674    archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
    16501675    archive_handle->dpkg__sub_archive->dpkg__buffer = (char*)"/"; /* huh? */
    1651     archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
    16521676    unpack_ar_archive(archive_handle);
    16531677
     
    16551679    list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
    16561680    out_stream = xfopen_for_write(list_filename);
     1681    archive_handle->dpkg__sub_archive->passed = llist_rev(archive_handle->dpkg__sub_archive->passed);
    16571682    while (archive_handle->dpkg__sub_archive->passed) {
     1683        char *filename = llist_pop(&archive_handle->dpkg__sub_archive->passed);
    16581684        /* the leading . has been stripped by data_extract_all_prefix already */
    1659         fputs(archive_handle->dpkg__sub_archive->passed->data, out_stream);
    1660         fputc('\n', out_stream);
    1661         archive_handle->dpkg__sub_archive->passed = archive_handle->dpkg__sub_archive->passed->link;
     1685        fprintf(out_stream, "%s\n", filename);
     1686        free(filename);
    16621687    }
    16631688    fclose(out_stream);
  • branches/3.2/mindi-busybox/archival/dpkg_deb.c

    r2725 r3232  
    55 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    66 */
     7
     8//usage:#define dpkg_deb_trivial_usage
     9//usage:       "[-cefxX] FILE [argument"
     10//usage:#define dpkg_deb_full_usage "\n\n"
     11//usage:       "Perform actions on Debian packages (.debs)\n"
     12//usage:     "\n    -c  List contents of filesystem tree"
     13//usage:     "\n    -e  Extract control files to [argument] directory"
     14//usage:     "\n    -f  Display control field name starting with [argument]"
     15//usage:     "\n    -x  Extract packages filesystem tree to directory"
     16//usage:     "\n    -X  Verbose extract"
     17//usage:
     18//usage:#define dpkg_deb_example_usage
     19//usage:       "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
     20
    721#include "libbb.h"
    8 #include "archive.h"
     22#include "bb_archive.h"
    923
    1024#define DPKG_DEB_OPT_CONTENTS         1
  • branches/3.2/mindi-busybox/archival/gzip.c

    r2725 r3232  
    4040*/
    4141
     42//usage:#define gzip_trivial_usage
     43//usage:       "[-cfd] [FILE]..."
     44//usage:#define gzip_full_usage "\n\n"
     45//usage:       "Compress FILEs (or stdin)\n"
     46//usage:     "\n    -d  Decompress"
     47//usage:     "\n    -c  Write to stdout"
     48//usage:     "\n    -f  Force"
     49//usage:
     50//usage:#define gzip_example_usage
     51//usage:       "$ ls -la /tmp/busybox*\n"
     52//usage:       "-rw-rw-r--    1 andersen andersen  1761280 Apr 14 17:47 /tmp/busybox.tar\n"
     53//usage:       "$ gzip /tmp/busybox.tar\n"
     54//usage:       "$ ls -la /tmp/busybox*\n"
     55//usage:       "-rw-rw-r--    1 andersen andersen   554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
     56
    4257#include "libbb.h"
    43 #include "archive.h"
     58#include "bb_archive.h"
    4459
    4560
     
    6782/* ===========================================================================
    6883 */
    69 #define SMALL_MEM
     84#if   CONFIG_GZIP_FAST == 0
     85# define SMALL_MEM
     86#elif CONFIG_GZIP_FAST == 1
     87# define MEDIUM_MEM
     88#elif CONFIG_GZIP_FAST == 2
     89# define BIG_MEM
     90#else
     91# error "Invalid CONFIG_GZIP_FAST value"
     92#endif
    7093
    7194#ifndef INBUFSIZ
     
    11571180     */
    11581181    Assert(code + G2.bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
    1159            "inconsistent bit counts");
     1182            "inconsistent bit counts");
    11601183    Tracev((stderr, "\ngen_codes: max_code %d ", max_code));
    11611184
     
    15051528        out_length >>= 3;
    15061529        Trace((stderr,
    1507                "\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
    1508                G2.last_lit, G2.last_dist, in_length, out_length,
    1509                100L - out_length * 100L / in_length));
     1530                "\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
     1531                G2.last_lit, G2.last_dist, in_length, out_length,
     1532                100L - out_length * 100L / in_length));
    15101533        if (G2.last_dist < G2.last_lit / 2 && out_length < in_length / 2)
    15111534            return 1;
     
    15991622
    16001623    Trace((stderr,
    1601            "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
    1602            opt_lenb, G2.opt_len, static_lenb, G2.static_len, stored_len,
    1603            G2.last_lit, G2.last_dist));
     1624            "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
     1625            opt_lenb, G2.opt_len, static_lenb, G2.static_len, stored_len,
     1626            G2.last_lit, G2.last_dist));
    16041627
    16051628    if (static_lenb <= opt_lenb)
     
    16391662        send_bits((DYN_TREES << 1) + eof, 3);
    16401663        send_all_trees(G2.l_desc.max_code + 1, G2.d_desc.max_code + 1,
    1641                        max_blindex + 1);
     1664                    max_blindex + 1);
    16421665        compress_block((ct_data *) G2.dyn_ltree, (ct_data *) G2.dyn_dtree);
    16431666        G2.compressed_len += 3 + G2.opt_len;
     
    16591682/* ===========================================================================
    16601683 * Update a hash value with the given input byte
    1661  * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
     1684 * IN  assertion: all calls to UPDATE_HASH are made with consecutive
    16621685 *    input characters, so that a running hash key can be computed from the
    16631686 *    previous key instead of complete recalculation each time.
     
    16901713 * of the hash chain (the most recent string with same hash key). Return
    16911714 * the previous length of the hash chain.
    1692  * IN  assertion: all calls to to INSERT_STRING are made with consecutive
     1715 * IN  assertion: all calls to INSERT_STRING are made with consecutive
    16931716 *    input characters and the first MIN_MATCH bytes of s are valid
    16941717 *    (except for the last MIN_MATCH-1 bytes of the input file). */
     
    19932016/* ======================================================================== */
    19942017static
    1995 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(unpack_info_t *info UNUSED_PARAM)
     2018IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
    19962019{
    19972020    struct stat s;
  • branches/3.2/mindi-busybox/archival/libarchive/Kbuild.src

    r2725 r3232  
    2929
    3030DPKG_FILES:= \
     31    unpack_ar_archive.o \
     32    filter_accept_list_reassign.o \
    3133    get_header_ar.o \
    32     unpack_ar_archive.o \
    3334    get_header_tar.o \
    34     filter_accept_list_reassign.o
     35    get_header_tar_gz.o \
     36    get_header_tar_bz2.o \
     37    get_header_tar_lzma.o \
    3538
    3639INSERT
     
    4346lib-$(CONFIG_DPKG)                      += $(DPKG_FILES)
    4447lib-$(CONFIG_DPKG_DEB)                  += $(DPKG_FILES)
    45 lib-$(CONFIG_GUNZIP)                    += decompress_unzip.o
    46 lib-$(CONFIG_RPM2CPIO)                  += decompress_unzip.o get_header_cpio.o
    47 lib-$(CONFIG_RPM)                       += open_transformer.o decompress_unzip.o get_header_cpio.o
     48lib-$(CONFIG_GUNZIP)                    += open_transformer.o decompress_gunzip.o
     49lib-$(CONFIG_RPM2CPIO)                  += decompress_gunzip.o get_header_cpio.o
     50lib-$(CONFIG_RPM)                       += open_transformer.o decompress_gunzip.o get_header_cpio.o
    4851lib-$(CONFIG_TAR)                       += get_header_tar.o
    4952lib-$(CONFIG_UNCOMPRESS)                += decompress_uncompress.o
    50 lib-$(CONFIG_UNZIP)                     += decompress_unzip.o
     53lib-$(CONFIG_UNZIP)                     += decompress_gunzip.o
    5154lib-$(CONFIG_LZOP)                      += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
    5255lib-$(CONFIG_LZOP_COMPR_HIGH)           += lzo1x_9x.o
     56lib-$(CONFIG_MODINFO)                   += open_transformer.o
     57lib-$(CONFIG_INSMOD)                    += open_transformer.o
    5358lib-$(CONFIG_FEATURE_SEAMLESS_Z)        += open_transformer.o decompress_uncompress.o
    54 lib-$(CONFIG_FEATURE_SEAMLESS_GZ)       += open_transformer.o decompress_unzip.o get_header_tar_gz.o
    55 lib-$(CONFIG_FEATURE_SEAMLESS_BZ2)      += open_transformer.o decompress_bunzip2.o get_header_tar_bz2.o
    56 lib-$(CONFIG_FEATURE_SEAMLESS_LZMA)     += open_transformer.o decompress_unlzma.o get_header_tar_lzma.o
     59lib-$(CONFIG_FEATURE_SEAMLESS_GZ)       += open_transformer.o decompress_gunzip.o
     60lib-$(CONFIG_FEATURE_SEAMLESS_BZ2)      += open_transformer.o decompress_bunzip2.o
     61lib-$(CONFIG_FEATURE_SEAMLESS_LZMA)     += open_transformer.o decompress_unlzma.o
    5762lib-$(CONFIG_FEATURE_SEAMLESS_XZ)       += open_transformer.o decompress_unxz.o
    58 lib-$(CONFIG_FEATURE_COMPRESS_USAGE)    += decompress_bunzip2.o
     63lib-$(CONFIG_FEATURE_COMPRESS_USAGE)    += open_transformer.o decompress_bunzip2.o
    5964lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o
    6065lib-$(CONFIG_FEATURE_TAR_TO_COMMAND)    += data_extract_to_command.o
  • branches/3.2/mindi-busybox/archival/libarchive/bz/blocksort.c

    r2725 r3232  
    386386 */
    387387
    388 #if CONFIG_BZIP2_FEATURE_SPEED >= 1
     388#if CONFIG_BZIP2_FAST >= 1
    389389
    390390#define TIMES_8(code) \
     
    497497
    498498/* 1.5% overall speedup, +290 bytes */
    499 #if CONFIG_BZIP2_FEATURE_SPEED >= 3
     499#if CONFIG_BZIP2_FAST >= 3
    500500            /*-- copy 2 --*/
    501501            if (i > hi) break;
     
    751751    i = nblock - 1;
    752752/* 3%, +300 bytes */
    753 #if CONFIG_BZIP2_FEATURE_SPEED >= 2
     753#if CONFIG_BZIP2_FAST >= 2
    754754    for (; i >= 3; i -= 4) {
    755755        quadrant[i] = 0;
     
    788788    s = block[0] << 8;
    789789    i = nblock - 1;
    790 #if CONFIG_BZIP2_FEATURE_SPEED >= 2
     790#if CONFIG_BZIP2_FAST >= 2
    791791    for (; i >= 3; i -= 4) {
    792792        s = (s >> 8) | (block[i] << 8);
  • branches/3.2/mindi-busybox/archival/libarchive/bz/bzlib_private.h

    r2725 r3232  
    184184    int32_t  sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
    185185    int32_t  sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
    186 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     186#if CONFIG_BZIP2_FAST >= 5
    187187    /* second dimension: only 3 needed; 4 makes index calculations faster */
    188188    uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
  • branches/3.2/mindi-busybox/archival/libarchive/bz/compress.c

    r2725 r3232  
    6262static
    6363/* Helps only on level 5, on other levels hurts. ? */
    64 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     64#if CONFIG_BZIP2_FAST >= 5
    6565ALWAYS_INLINE
    6666#endif
     
    252252    int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
    253253    int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
    254     int32_t nGroups, nBytes;
     254    int32_t nGroups;
    255255
    256256    /*
     
    332332                s->rfreq[t][v] = 0;
    333333
    334 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     334#if CONFIG_BZIP2_FAST >= 5
    335335        /*
    336336         * Set up an auxiliary length table which is used to fast-track
     
    362362            for (t = 0; t < nGroups; t++)
    363363                cost[t] = 0;
    364 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     364#if CONFIG_BZIP2_FAST >= 5
    365365            if (nGroups == 6 && 50 == ge-gs+1) {
    366366                /*--- fast track the common case ---*/
     
    421421             */
    422422/* 1% faster compress. +800 bytes */
    423 #if CONFIG_BZIP2_FEATURE_SPEED >= 4
     423#if CONFIG_BZIP2_FAST >= 4
    424424            if (nGroups == 6 && 50 == ge-gs+1) {
    425425                /*--- fast track the common case ---*/
     
    513513        }
    514514
    515         nBytes = s->numZ;
    516515        bsW(s, 16, inUse16);
    517516
     
    529528
    530529    /*--- Now the selectors. ---*/
    531     nBytes = s->numZ;
    532530    bsW(s, 3, nGroups);
    533531    bsW(s, 15, nSelectors);
     
    539537
    540538    /*--- Now the coding tables. ---*/
    541     nBytes = s->numZ;
    542 
    543539    for (t = 0; t < nGroups; t++) {
    544540        int32_t curr = s->len[t][0];
     
    552548
    553549    /*--- And finally, the block data proper ---*/
    554     nBytes = s->numZ;
    555550    selCtr = 0;
    556551    gs = 0;
  • branches/3.2/mindi-busybox/archival/libarchive/bz/huffman.c

    r2725 r3232  
    4949
    5050/* 90 bytes, 0.3% of overall compress speed */
    51 #if CONFIG_BZIP2_FEATURE_SPEED >= 1
     51#if CONFIG_BZIP2_FAST >= 1
    5252
    5353/* macro works better than inline (gcc 4.2.1) */
  • branches/3.2/mindi-busybox/archival/libarchive/data_align.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
  • branches/3.2/mindi-busybox/archival/libarchive/data_extract_all.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
     
    1414
    1515#if ENABLE_FEATURE_TAR_SELINUX
    16     char *sctx = archive_handle->tar__next_file_sctx;
     16    char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
    1717    if (!sctx)
    18         sctx = archive_handle->tar__global_sctx;
     18        sctx = archive_handle->tar__sctx[PAX_GLOBAL];
    1919    if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */
    2020        setfscreatecon(sctx);
    21         free(archive_handle->tar__next_file_sctx);
    22         archive_handle->tar__next_file_sctx = NULL;
     21        free(archive_handle->tar__sctx[PAX_NEXT_FILE]);
     22        archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL;
    2323    }
    2424#endif
  • branches/3.2/mindi-busybox/archival/libarchive/data_extract_to_command.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99enum {
     
    6565
    6666#if 0 /* do we need this? ENABLE_FEATURE_TAR_SELINUX */
    67     char *sctx = archive_handle->tar__next_file_sctx;
     67    char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
    6868    if (!sctx)
    69         sctx = archive_handle->tar__global_sctx;
     69        sctx = archive_handle->tar__sctx[PAX_GLOBAL];
    7070    if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */
    7171        setfscreatecon(sctx);
    72         free(archive_handle->tar__next_file_sctx);
    73         archive_handle->tar__next_file_sctx = NULL;
     72        free(archive_handle->tar__sctx[PAX_NEXT_FILE]);
     73        archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL;
    7474    }
    7575#endif
     
    100100            xdup2(p[0], STDIN_FILENO);
    101101            signal(SIGPIPE, SIG_DFL);
    102             execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", archive_handle->tar__to_command, NULL);
    103             bb_perror_msg_and_die("can't execute '%s'", DEFAULT_SHELL);
     102            execl(archive_handle->tar__to_command_shell,
     103                archive_handle->tar__to_command_shell,
     104                "-c",
     105                archive_handle->tar__to_command,
     106                NULL);
     107            bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell);
    104108        }
    105109        close(p[0]);
  • branches/3.2/mindi-busybox/archival/libarchive/data_extract_to_stdout.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_extract_to_stdout(archive_handle_t *archive_handle)
  • branches/3.2/mindi-busybox/archival/libarchive/data_skip.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_skip(archive_handle_t *archive_handle)
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_bunzip2.c

    r2725 r3232  
    4141
    4242#include "libbb.h"
    43 #include "archive.h"
     43#include "bb_archive.h"
    4444
    4545/* Constants for Huffman coding */
     
    722722/* Decompress src_fd to dst_fd.  Stops at end of bzip data, not end of file. */
    723723IF_DESKTOP(long long) int FAST_FUNC
    724 unpack_bz2_stream(int src_fd, int dst_fd)
     724unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
    725725{
    726726    IF_DESKTOP(long long total_written = 0;)
     
    729729    int i;
    730730    unsigned len;
     731
     732    if (check_signature16(aux, src_fd, BZIP2_MAGIC))
     733        return -1;
    731734
    732735    outbuf = xmalloc(IOBUF_SIZE);
     
    753756        }
    754757
    755         if (i != RETVAL_LAST_BLOCK) {
     758        if (i != RETVAL_LAST_BLOCK
     759        /* Observed case when i == RETVAL_OK:
     760         * "bzcat z.bz2", where "z.bz2" is a bzipped zero-length file
     761         * (to be exact, z.bz2 is exactly these 14 bytes:
     762         * 42 5a 68 39 17 72 45 38  50 90 00 00 00 00).
     763         */
     764         && i != RETVAL_OK
     765        ) {
    756766            bb_error_msg("bunzip error %d", i);
    757767            break;
     
    788798}
    789799
    790 IF_DESKTOP(long long) int FAST_FUNC
    791 unpack_bz2_stream_prime(int src_fd, int dst_fd)
    792 {
    793     uint16_t magic2;
    794     xread(src_fd, &magic2, 2);
    795     if (magic2 != BZIP2_MAGIC) {
    796         bb_error_msg_and_die("invalid magic");
    797     }
    798     return unpack_bz2_stream(src_fd, dst_fd);
    799 }
    800 
    801800#ifdef TESTING
    802801
     
    813812    char c;
    814813
    815     int i = unpack_bz2_stream_prime(0, 1);
     814    int i = unpack_bz2_stream(0, 1);
    816815    if (i < 0)
    817816        fprintf(stderr, "%s\n", bunzip_errors[-i]);
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_uncompress.c

    r2725 r3232  
    2626
    2727#include "libbb.h"
    28 #include "archive.h"
     28#include "bb_archive.h"
    2929
    3030
     
    7474
    7575IF_DESKTOP(long long) int FAST_FUNC
    76 unpack_Z_stream(int fd_in, int fd_out)
     76unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
    7777{
    7878    IF_DESKTOP(long long total_written = 0;)
    7979    IF_DESKTOP(long long) int retval = -1;
    8080    unsigned char *stackp;
    81     long code;
    8281    int finchar;
    8382    long oldcode;
     
    104103    int block_mode; /* = BLOCK_MODE; */
    105104
     105    if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
     106        return -1;
     107
    106108    inbuf = xzalloc(IBUFSIZ + 64);
    107109    outbuf = xzalloc(OBUFSIZ + 2048);
    108     htab = xzalloc(HSIZE);  /* wsn't zeroed out before, maybe can xmalloc? */
     110    htab = xzalloc(HSIZE);  /* wasn't zeroed out before, maybe can xmalloc? */
    109111    codetab = xzalloc(HSIZE * sizeof(codetab[0]));
    110112
     
    113115    /* xread isn't good here, we have to return - caller may want
    114116     * to do some cleanup (e.g. delete incomplete unpacked file etc) */
    115     if (full_read(fd_in, inbuf, 1) != 1) {
     117    if (full_read(src_fd, inbuf, 1) != 1) {
    116118        bb_error_msg("short read");
    117119        goto err;
     
    141143    /*clear_tab_prefixof(); - done by xzalloc */
    142144
    143     for (code = 255; code >= 0; --code) {
    144         tab_suffixof(code) = (unsigned char) code;
     145    {
     146        int i;
     147        for (i = 255; i >= 0; --i)
     148            tab_suffixof(i) = (unsigned char) i;
    145149    }
    146150
     
    163167
    164168        if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
    165             rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
    166 //error check??
     169            rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
     170            if (rsize < 0)
     171                bb_error_msg_and_die(bb_msg_read_error);
    167172            insize += rsize;
    168173        }
     
    172177
    173178        while (inbits > posbits) {
     179            long code;
     180
    174181            if (free_ent > maxcode) {
    175182                posbits =
     
    188195            {
    189196                unsigned char *p = &inbuf[posbits >> 3];
    190 
    191                 code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
    192                         ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
     197                code = ((p[0]
     198                    | ((long) (p[1]) << 8)
     199                    | ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
    193200            }
    194201            posbits += n_bits;
    195202
    196 
    197203            if (oldcode == -1) {
     204                if (code >= 256)
     205                    bb_error_msg_and_die("corrupted data"); /* %ld", code); */
    198206                oldcode = code;
    199207                finchar = (int) oldcode;
     
    221229            if (code >= free_ent) {
    222230                if (code > free_ent) {
     231/*
    223232                    unsigned char *p;
    224233
    225234                    posbits -= n_bits;
    226235                    p = &inbuf[posbits >> 3];
    227 
    228236                    bb_error_msg
    229237                        ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)",
    230                          insize, posbits, p[-1], p[0], p[1], p[2], p[3],
    231                          (posbits & 07));
     238                        insize, posbits, p[-1], p[0], p[1], p[2], p[3],
     239                        (posbits & 07));
     240*/
    232241                    bb_error_msg("corrupted data");
    233242                    goto err;
     
    239248
    240249            /* Generate output characters in reverse order */
    241             while ((long) code >= (long) 256) {
     250            while (code >= 256) {
     251                if (stackp <= &htabof(0))
     252                    bb_error_msg_and_die("corrupted data");
    242253                *--stackp = tab_suffixof(code);
    243254                code = tab_prefixof(code);
     
    264275
    265276                        if (outpos >= OBUFSIZ) {
    266                             full_write(fd_out, outbuf, outpos);
    267 //error check??
     277                            xwrite(dst_fd, outbuf, outpos);
    268278                            IF_DESKTOP(total_written += outpos;)
    269279                            outpos = 0;
     
    279289
    280290            /* Generate the new entry. */
    281             code = free_ent;
    282             if (code < maxmaxcode) {
    283                 tab_prefixof(code) = (unsigned short) oldcode;
    284                 tab_suffixof(code) = (unsigned char) finchar;
    285                 free_ent = code + 1;
     291            if (free_ent < maxmaxcode) {
     292                tab_prefixof(free_ent) = (unsigned short) oldcode;
     293                tab_suffixof(free_ent) = (unsigned char) finchar;
     294                free_ent++;
    286295            }
    287296
     
    293302
    294303    if (outpos > 0) {
    295         full_write(fd_out, outbuf, outpos);
    296 //error check??
     304        xwrite(dst_fd, outbuf, outpos);
    297305        IF_DESKTOP(total_written += outpos;)
    298306    }
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_unlzma.c

    r2725 r3232  
    1010 */
    1111#include "libbb.h"
    12 #include "archive.h"
     12#include "bb_archive.h"
    1313
    1414#if ENABLE_FEATURE_LZMA_FAST
     
    214214
    215215IF_DESKTOP(long long) int FAST_FUNC
    216 unpack_lzma_stream(int src_fd, int dst_fd)
     216unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
    217217{
    218218    IF_DESKTOP(long long total_written = 0;)
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_unxz.c

    r2725 r3232  
    1111 */
    1212#include "libbb.h"
    13 #include "archive.h"
     13#include "bb_archive.h"
    1414
    1515#define XZ_FUNC FAST_FUNC
     
    3131#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
    3232#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
    33 #define put_unaligned_le32(val, buf) move_to_unaligned16(buf, SWAP_LE32(val))
    34 #define put_unaligned_be32(val, buf) move_to_unaligned16(buf, SWAP_BE32(val))
     33#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
     34#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
    3535
    3636#include "unxz/xz_dec_bcj.c"
     
    3939
    4040IF_DESKTOP(long long) int FAST_FUNC
    41 unpack_xz_stream(int src_fd, int dst_fd)
     41unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
    4242{
     43    enum xz_ret xz_result;
    4344    struct xz_buf iobuf;
    4445    struct xz_dec *state;
     
    5051
    5152    memset(&iobuf, 0, sizeof(iobuf));
    52     /* Preload XZ file signature */
    53     membuf = (void*) strcpy(xmalloc(2 * BUFSIZ), HEADER_MAGIC);
     53    membuf = xmalloc(2 * BUFSIZ);
    5454    iobuf.in = membuf;
    55     iobuf.in_size = HEADER_MAGIC_SIZE;
    5655    iobuf.out = membuf + BUFSIZ;
    5756    iobuf.out_size = BUFSIZ;
     57
     58    if (!aux || aux->check_signature == 0) {
     59        /* Preload XZ file signature */
     60        strcpy((char*)membuf, HEADER_MAGIC);
     61        iobuf.in_size = HEADER_MAGIC_SIZE;
     62    } /* else: let xz code read & check it */
    5863
    5964    /* Limit memory usage to about 64 MiB. */
    6065    state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
    6166
     67    xz_result = X_OK;
    6268    while (1) {
    63         enum xz_ret r;
    64 
    6569        if (iobuf.in_pos == iobuf.in_size) {
    6670            int rd = safe_read(src_fd, membuf, BUFSIZ);
     
    7074                break;
    7175            }
     76            if (rd == 0 && xz_result == XZ_STREAM_END)
     77                break;
    7278            iobuf.in_size = rd;
    7379            iobuf.in_pos = 0;
    7480        }
     81        if (xz_result == XZ_STREAM_END) {
     82            /*
     83             * Try to start decoding next concatenated stream.
     84             * Stream padding must always be a multiple of four
     85             * bytes to preserve four-byte alignment. To keep the
     86             * code slightly smaller, we aren't as strict here as
     87             * the .xz spec requires. We just skip all zero-bytes
     88             * without checking the alignment and thus can accept
     89             * files that aren't valid, e.g. the XZ utils test
     90             * files bad-0pad-empty.xz and bad-0catpad-empty.xz.
     91             */
     92            do {
     93                if (membuf[iobuf.in_pos] != 0) {
     94                    xz_dec_reset(state);
     95                    goto do_run;
     96                }
     97                iobuf.in_pos++;
     98            } while (iobuf.in_pos < iobuf.in_size);
     99        }
     100 do_run:
    75101//      bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
    76102//              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
    77         r = xz_dec_run(state, &iobuf);
     103        xz_result = xz_dec_run(state, &iobuf);
    78104//      bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
    79 //              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, r);
     105//              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
    80106        if (iobuf.out_pos) {
    81107            xwrite(dst_fd, iobuf.out, iobuf.out_pos);
     
    83109            iobuf.out_pos = 0;
    84110        }
    85         if (r == XZ_STREAM_END) {
    86             break;
     111        if (xz_result == XZ_STREAM_END) {
     112            /*
     113             * Can just "break;" here, if not for concatenated
     114             * .xz streams.
     115             * Checking for padding may require buffer
     116             * replenishment. Can't do it here.
     117             */
     118            continue;
    87119        }
    88         if (r != XZ_OK && r != XZ_UNSUPPORTED_CHECK) {
     120        if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
    89121            bb_error_msg("corrupted data");
    90122            total = -1;
     
    92124        }
    93125    }
     126
    94127    xz_dec_end(state);
    95128    free(membuf);
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_all.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/* Accept any non-null name, its not really a filter at all */
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_list.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/*
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_list_reassign.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_reject_list.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/*
     
    2525        return EXIT_FAILURE;
    2626    }
    27     accept_entry = find_list_entry2(archive_handle->accept, key);
    2827
    2928    /* Fail if an accept list was specified and the key wasnt in there */
    30     if ((accept_entry == NULL) && archive_handle->accept) {
    31         return EXIT_FAILURE;
     29    if (archive_handle->accept) {
     30        accept_entry = find_list_entry2(archive_handle->accept, key);
     31        if (!accept_entry) {
     32            return EXIT_FAILURE;
     33        }
    3234    }
    3335
  • branches/3.2/mindi-busybox/archival/libarchive/find_list_entry.c

    r2725 r3232  
    88#include <fnmatch.h>
    99#include "libbb.h"
    10 #include "archive.h"
     10#include "bb_archive.h"
    1111
    1212/* Find a string in a shell pattern list */
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_ar.c

    r2725 r3232  
    66
    77#include "libbb.h"
    8 #include "archive.h"
     8#include "bb_archive.h"
    99#include "ar.h"
    1010
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_cpio.c

    r2725 r3232  
    66
    77#include "libbb.h"
    8 #include "archive.h"
     8#include "bb_archive.h"
    99
    1010typedef struct hardlinks_t {
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar.c

    r2725 r3232  
    1313
    1414#include "libbb.h"
    15 #include "archive.h"
     15#include "bb_archive.h"
    1616
    1717typedef uint32_t aliased_uint32_t FIX_ALIASING;
    1818typedef off_t    aliased_off_t    FIX_ALIASING;
    1919
     20
     21const char* FAST_FUNC strip_unsafe_prefix(const char *str)
     22{
     23    const char *cp = str;
     24    while (1) {
     25        char *cp2;
     26        if (*cp == '/') {
     27            cp++;
     28            continue;
     29        }
     30        if (strncmp(cp, "/../"+1, 3) == 0) {
     31            cp += 3;
     32            continue;
     33        }
     34        cp2 = strstr(cp, "/../");
     35        if (!cp2)
     36            break;
     37        cp = cp2 + 4;
     38    }
     39    if (cp != str) {
     40        static smallint warned = 0;
     41        if (!warned) {
     42            warned = 1;
     43            bb_error_msg("removing leading '%.*s' from member names",
     44                (int)(cp - str), str);
     45        }
     46    }
     47    return cp;
     48}
    2049
    2150/* NB: _DESTROYS_ str[len] character! */
     
    5180         * NB: tarballs with NEGATIVE unix times encoded that way were seen!
    5281         */
    53         v = first;
    54         /* Sign-extend using 6th bit: */
    55         v <<= sizeof(unsigned long long)*8 - 7;
    56         v = (long long)v >> (sizeof(unsigned long long)*8 - 7);
     82        /* Sign-extend 7bit 'first' to 64bit 'v' (that is, using 6th bit as sign): */
     83        first <<= 1;
     84        first >>= 1; /* now 7th bit = 6th bit */
     85        v = first;   /* sign-extend 8 bits to 64 */
    5786        while (--len != 0)
    58             v = (v << 8) + (unsigned char) *str++;
     87            v = (v << 8) + (uint8_t) *++str;
    5988    }
    6089    return v;
     
    6291#define GET_OCTAL(a) getOctal((a), sizeof(a))
    6392
    64 #if ENABLE_FEATURE_TAR_SELINUX
    65 /* Scan a PAX header for SELinux contexts, via "RHT.security.selinux" keyword.
    66  * This is what Red Hat's patched version of tar uses.
    67  */
    68 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
    69 static char *get_selinux_sctx_from_pax_hdr(archive_handle_t *archive_handle, unsigned sz)
     93/* "global" is 0 or 1 */
     94static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
    7095{
    7196    char *buf, *p;
    72     char *result;
    73 
    74     p = buf = xmalloc(sz + 1);
     97    unsigned blk_sz;
     98
     99    blk_sz = (sz + 511) & (~511);
     100    p = buf = xmalloc(blk_sz + 1);
     101    xread(archive_handle->src_fd, buf, blk_sz);
     102    archive_handle->offset += blk_sz;
     103
    75104    /* prevent bb_strtou from running off the buffer */
    76105    buf[sz] = '\0';
    77     xread(archive_handle->src_fd, buf, sz);
    78     archive_handle->offset += sz;
    79 
    80     result = NULL;
     106
    81107    while (sz != 0) {
    82108        char *end, *value;
     
    105131         */
    106132        p[-1] = '\0';
    107         /* Is it selinux security context? */
    108133        value = end + 1;
     134
     135#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
     136        if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
     137            value += sizeof("path=") - 1;
     138            free(archive_handle->tar__longname);
     139            archive_handle->tar__longname = xstrdup(value);
     140            continue;
     141        }
     142#endif
     143
     144#if ENABLE_FEATURE_TAR_SELINUX
     145        /* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
     146         * This is what Red Hat's patched version of tar uses.
     147         */
     148# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
    109149        if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
    110150            value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
    111             result = xstrdup(value);
    112             break;
    113         }
     151            free(archive_handle->tar__sctx[global]);
     152            archive_handle->tar__sctx[global] = xstrdup(value);
     153            continue;
     154        }
     155#endif
    114156    }
    115157
    116158    free(buf);
    117     return result;
    118159}
    119 #endif
    120160
    121161char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
     
    196236    ) {
    197237#if ENABLE_FEATURE_TAR_AUTODETECT
    198         char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
    199         uint16_t magic2;
    200 
    201238 autodetect:
    202         magic2 = *(uint16_t*)tar.name;
    203         /* tar gz/bz autodetect: check for gz/bz2 magic.
    204          * If we see the magic, and it is the very first block,
    205          * we can switch to get_header_tar_gz/bz2/lzma().
    206          * Needs seekable fd. I wish recv(MSG_PEEK) works
    207          * on any fd... */
    208 # if ENABLE_FEATURE_SEAMLESS_GZ
    209         if (magic2 == GZIP_MAGIC) {
    210             get_header_ptr = get_header_tar_gz;
    211         } else
    212 # endif
    213 # if ENABLE_FEATURE_SEAMLESS_BZ2
    214         if (magic2 == BZIP2_MAGIC
    215          && tar.name[2] == 'h' && isdigit(tar.name[3])
    216         ) { /* bzip2 */
    217             get_header_ptr = get_header_tar_bz2;
    218         } else
    219 # endif
    220 # if ENABLE_FEATURE_SEAMLESS_XZ
    221         //TODO: if (magic2 == XZ_MAGIC1)...
    222         //else
    223 # endif
    224             goto err;
    225239        /* Two different causes for lseek() != 0:
    226240         * unseekable fd (would like to support that too, but...),
     
    228242        if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
    229243            goto err;
    230         while (get_header_ptr(archive_handle) == EXIT_SUCCESS)
    231             continue;
    232         return EXIT_FAILURE;
     244        if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
    233245 err:
    234 #endif /* FEATURE_TAR_AUTODETECT */
     246            bb_error_msg_and_die("invalid tar magic");
     247        archive_handle->offset = 0;
     248        goto again_after_align;
     249#endif
    235250        bb_error_msg_and_die("invalid tar magic");
    236251    }
     
    320335    /* (typeflag was not trashed because chksum does not use getOctal) */
    321336    switch (tar.typeflag) {
    322     /* busybox identifies hard links as being regular files with 0 size and a link name */
    323     case '1':
     337    case '1': /* hardlink */
     338        /* we mark hardlinks as regular files with zero size and a link name */
    324339        file_header->mode |= S_IFREG;
    325         break;
     340        /* on size of link fields from star(4)
     341         * ... For tar archives written by pre POSIX.1-1988
     342         * implementations, the size field usually contains the size of
     343         * the file and needs to be ignored as no data may follow this
     344         * header type.  For POSIX.1- 1988 compliant archives, the size
     345         * field needs to be 0.  For POSIX.1-2001 compliant archives,
     346         * the size field may be non zero, indicating that file data is
     347         * included in the archive.
     348         * i.e; always assume this is zero for safety.
     349         */
     350        goto size0;
    326351    case '7':
    327352    /* case 0: */
     
    380405    case 'V':   /* Volume header */
    381406#endif
    382 #if !ENABLE_FEATURE_TAR_SELINUX
    383407    case 'g':   /* pax global header */
    384     case 'x':   /* pax extended header */
    385 #else
     408    case 'x': { /* pax extended header */
     409        if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
     410            goto skip_ext_hdr;
     411        process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
     412        goto again_after_align;
     413    }
    386414 skip_ext_hdr:
    387 #endif
    388415    {
    389416        off_t sz;
     
    397424        goto again_after_align;
    398425    }
    399 #if ENABLE_FEATURE_TAR_SELINUX
    400     case 'g':   /* pax global header */
    401     case 'x': { /* pax extended header */
    402         char **pp;
    403         if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
    404             goto skip_ext_hdr;
    405         pp = (tar.typeflag == 'g') ? &archive_handle->tar__global_sctx : &archive_handle->tar__next_file_sctx;
    406         free(*pp);
    407         *pp = get_selinux_sctx_from_pax_hdr(archive_handle, file_header->size);
    408         goto again;
    409     }
    410 #endif
    411426    default:
    412427        bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
     
    423438    }
    424439#endif
    425     if (strncmp(file_header->name, "/../"+1, 3) == 0
    426      || strstr(file_header->name, "/../")
    427     ) {
    428         bb_error_msg_and_die("name with '..' encountered: '%s'",
    429                 file_header->name);
    430     }
     440
     441    /* Everything up to and including last ".." component is stripped */
     442    overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
    431443
    432444    /* Strip trailing '/' in directories */
     
    441453            *cp = '\0';
    442454        archive_handle->action_data(archive_handle);
    443         if (archive_handle->accept || archive_handle->reject)
     455        if (archive_handle->accept || archive_handle->reject
     456         || (archive_handle->ah_flags & ARCHIVE_REMEMBER_NAMES)
     457        ) {
    444458            llist_add_to(&archive_handle->passed, file_header->name);
    445         else /* Caller isn't interested in list of unpacked files */
     459        } else /* Caller isn't interested in list of unpacked files */
    446460            free(file_header->name);
    447461    } else {
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar_bz2.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
     
    1212    archive_handle->seek = seek_by_read;
    1313
    14     open_transformer(archive_handle->src_fd, unpack_bz2_stream_prime, "bunzip2");
     14    open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
    1515    archive_handle->offset = 0;
    1616    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar_gz.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
    1010{
    11 #if BB_MMU
    12     unsigned char magic[2];
    13 #endif
    14 
    1511    /* Can't lseek over pipes */
    1612    archive_handle->seek = seek_by_read;
    1713
    18     /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
    19      * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
    20      * need the header. */
    21 #if BB_MMU
    22     xread(archive_handle->src_fd, &magic, 2);
    23     /* Can skip this check, but error message will be less clear */
    24     if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
    25         bb_error_msg_and_die("invalid gzip magic");
    26     }
    27 #endif
    28 
    29     open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
     14    open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
    3015    archive_handle->offset = 0;
    3116    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar_lzma.c

    r2725 r3232  
    88
    99#include "libbb.h"
    10 #include "archive.h"
     10#include "bb_archive.h"
    1111
    1212char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
     
    1515    archive_handle->seek = seek_by_read;
    1616
    17     open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
     17    open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
    1818    archive_handle->offset = 0;
    1919    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.2/mindi-busybox/archival/libarchive/header_list.c

    r2725 r3232  
    44 */
    55#include "libbb.h"
    6 #include "archive.h"
     6#include "bb_archive.h"
    77
    88void FAST_FUNC header_list(const file_header_t *file_header)
  • branches/3.2/mindi-busybox/archival/libarchive/header_skip.c

    r2725 r3232  
    44 */
    55#include "libbb.h"
    6 #include "archive.h"
     6#include "bb_archive.h"
    77
    88void FAST_FUNC header_skip(const file_header_t *file_header UNUSED_PARAM)
  • branches/3.2/mindi-busybox/archival/libarchive/header_verbose_list.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC header_verbose_list(const file_header_t *file_header)
  • branches/3.2/mindi-busybox/archival/libarchive/init_handle.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99archive_handle_t* FAST_FUNC init_handle(void)
  • branches/3.2/mindi-busybox/archival/libarchive/lzo1x_9x.c

    r2725 r3232  
    645645
    646646static int min_gain(unsigned ahead, unsigned lit1,
    647             unsigned lit2, int l1, int l2, int l3)
     647            unsigned lit2, int l1, int l2, int l3)
    648648{
    649649    int lazy_match_min_gain = 0;
     
    674674
    675675static void better_match(const lzo_swd_p swd,
    676                unsigned *m_len, unsigned *m_off)
     676            unsigned *m_len, unsigned *m_off)
    677677{
    678678    if (*m_len <= M2_MIN_LEN)
     
    915915    compression_level -= 7;
    916916    return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
    917                        c[compression_level].good_length,
    918                        c[compression_level].max_lazy,
    919                        c[compression_level].max_chain,
    920                        c[compression_level].use_best_off);
    921 }
     917                    c[compression_level].good_length,
     918                    c[compression_level].max_lazy,
     919                    c[compression_level].max_chain,
     920                    c[compression_level].use_best_off);
     921}
  • branches/3.2/mindi-busybox/archival/libarchive/lzo1x_c.c

    r2725 r3232  
    1616   The LZO library is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    2020
  • branches/3.2/mindi-busybox/archival/libarchive/lzo1x_d.c

    r2725 r3232  
    1616   The LZO library is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    2020
  • branches/3.2/mindi-busybox/archival/libarchive/open_transformer.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
     8
     9void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
     10{
     11    memset(aux, 0, sizeof(*aux));
     12}
     13
     14int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
     15{
     16    if (aux && aux->check_signature) {
     17        uint16_t magic2;
     18        if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
     19            bb_error_msg("invalid magic");
     20#if 0 /* possible future extension */
     21            if (aux->check_signature > 1)
     22                xfunc_die();
     23#endif
     24            return -1;
     25        }
     26    }
     27    return 0;
     28}
     29
     30void check_errors_in_children(int signo)
     31{
     32    int status;
     33
     34    if (!signo) {
     35        /* block waiting for any child */
     36        if (wait(&status) < 0)
     37            return; /* probably there are no children */
     38        goto check_status;
     39    }
     40
     41    /* Wait for any child without blocking */
     42    for (;;) {
     43        if (wait_any_nohang(&status) < 0)
     44            /* wait failed?! I'm confused... */
     45            return;
     46 check_status:
     47        if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
     48            /* this child exited with 0 */
     49            continue;
     50        /* Cannot happen?
     51        if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */
     52        bb_got_signal = 1;
     53    }
     54}
    855
    956/* transformer(), more than meets the eye */
    10 /*
    11  * On MMU machine, the transform_prog is removed by macro magic
    12  * in include/archive.h. On NOMMU, transformer is removed.
    13  */
     57#if BB_MMU
    1458void FAST_FUNC open_transformer(int fd,
    15     IF_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
    16     const char *transform_prog)
     59    int check_signature,
     60    IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     61)
     62#else
     63void FAST_FUNC open_transformer(int fd, const char *transform_prog)
     64#endif
    1765{
    1866    struct fd_pair fd_pipe;
     
    2674        // FIXME: error check?
    2775#if BB_MMU
    28         transformer(fd, fd_pipe.wr);
    29         if (ENABLE_FEATURE_CLEAN_UP) {
    30             close(fd_pipe.wr); /* send EOF */
    31             close(fd);
    32         }
    33         /* must be _exit! bug was actually seen here */
    34         _exit(EXIT_SUCCESS);
     76        {
     77            transformer_aux_data_t aux;
     78            init_transformer_aux_data(&aux);
     79            aux.check_signature = check_signature;
     80            transformer(&aux, fd, fd_pipe.wr);
     81            if (ENABLE_FEATURE_CLEAN_UP) {
     82                close(fd_pipe.wr); /* send EOF */
     83                close(fd);
     84            }
     85            /* must be _exit! bug was actually seen here */
     86            _exit(EXIT_SUCCESS);
     87        }
    3588#else
    3689        {
     
    53106    xmove_fd(fd_pipe.rd, fd);
    54107}
     108
     109
     110#if SEAMLESS_COMPRESSION
     111
     112/* Used by e.g. rpm which gives us a fd without filename,
     113 * thus we can't guess the format from filename's extension.
     114 */
     115int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
     116{
     117    union {
     118        uint8_t b[4];
     119        uint16_t b16[2];
     120        uint32_t b32[1];
     121    } magic;
     122    int offset = -2;
     123    USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
     124    USE_FOR_NOMMU(const char *xformer_prog;)
     125
     126    /* .gz and .bz2 both have 2-byte signature, and their
     127     * unpack_XXX_stream wants this header skipped. */
     128    xread(fd, magic.b16, sizeof(magic.b16[0]));
     129    if (ENABLE_FEATURE_SEAMLESS_GZ
     130     && magic.b16[0] == GZIP_MAGIC
     131    ) {
     132        USE_FOR_MMU(xformer = unpack_gz_stream;)
     133        USE_FOR_NOMMU(xformer_prog = "gunzip";)
     134        goto found_magic;
     135    }
     136    if (ENABLE_FEATURE_SEAMLESS_BZ2
     137     && magic.b16[0] == BZIP2_MAGIC
     138    ) {
     139        USE_FOR_MMU(xformer = unpack_bz2_stream;)
     140        USE_FOR_NOMMU(xformer_prog = "bunzip2";)
     141        goto found_magic;
     142    }
     143    if (ENABLE_FEATURE_SEAMLESS_XZ
     144     && magic.b16[0] == XZ_MAGIC1
     145    ) {
     146        offset = -6;
     147        xread(fd, magic.b32, sizeof(magic.b32[0]));
     148        if (magic.b32[0] == XZ_MAGIC2) {
     149            USE_FOR_MMU(xformer = unpack_xz_stream;)
     150            USE_FOR_NOMMU(xformer_prog = "unxz";)
     151            goto found_magic;
     152        }
     153    }
     154
     155    /* No known magic seen */
     156    if (fail_if_not_detected)
     157        bb_error_msg_and_die("no gzip"
     158            IF_FEATURE_SEAMLESS_BZ2("/bzip2")
     159            IF_FEATURE_SEAMLESS_XZ("/xz")
     160            " magic");
     161    xlseek(fd, offset, SEEK_CUR);
     162    return 1;
     163
     164 found_magic:
     165# if BB_MMU
     166    open_transformer_with_no_sig(fd, xformer);
     167# else
     168    /* NOMMU version of open_transformer execs
     169     * an external unzipper that wants
     170     * file position at the start of the file */
     171    xlseek(fd, offset, SEEK_CUR);
     172    open_transformer_with_sig(fd, xformer, xformer_prog);
     173# endif
     174    return 0;
     175}
     176
     177int FAST_FUNC open_zipped(const char *fname)
     178{
     179    char *sfx;
     180    int fd;
     181
     182    fd = open(fname, O_RDONLY);
     183    if (fd < 0)
     184        return fd;
     185
     186    sfx = strrchr(fname, '.');
     187    if (sfx) {
     188        sfx++;
     189        if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
     190            /* .lzma has no header/signature, just trust it */
     191            open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
     192        else
     193        if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
     194         || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
     195         || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
     196        ) {
     197            setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
     198        }
     199    }
     200
     201    return fd;
     202}
     203
     204#endif /* SEAMLESS_COMPRESSION */
     205
     206void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
     207{
     208    int fd;
     209    char *image;
     210
     211    fd = open_zipped(fname);
     212    if (fd < 0)
     213        return NULL;
     214
     215    image = xmalloc_read(fd, maxsz_p);
     216    if (!image)
     217        bb_perror_msg("read error from '%s'", fname);
     218    close(fd);
     219
     220    return image;
     221}
  • branches/3.2/mindi-busybox/archival/libarchive/seek_by_jump.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC seek_by_jump(int fd, off_t amount)
  • branches/3.2/mindi-busybox/archival/libarchive/seek_by_read.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99/*  If we are reading through a pipe, or from stdin then we can't lseek,
  • branches/3.2/mindi-busybox/archival/libarchive/unpack_ar_archive.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88#include "ar.h"
    99
  • branches/3.2/mindi-busybox/archival/lzop.c

    r2725 r3232  
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    1919
     
    2626*/
    2727
     28//usage:#define lzop_trivial_usage
     29//usage:       "[-cfvd123456789CF] [FILE]..."
     30//usage:#define lzop_full_usage "\n\n"
     31//usage:       "    -1..9   Compression level"
     32//usage:     "\n    -d  Decompress"
     33//usage:     "\n    -c  Write to stdout"
     34//usage:     "\n    -f  Force"
     35//usage:     "\n    -v  Verbose"
     36//usage:     "\n    -F  Don't store or verify checksum"
     37//usage:     "\n    -C  Also write checksum of compressed block"
     38//usage:
     39//usage:#define lzopcat_trivial_usage
     40//usage:       "[-vCF] [FILE]..."
     41//usage:#define lzopcat_full_usage "\n\n"
     42//usage:       "    -v  Verbose"
     43//usage:     "\n    -F  Don't store or verify checksum"
     44//usage:
     45//usage:#define unlzop_trivial_usage
     46//usage:       "[-cfvCF] [FILE]..."
     47//usage:#define unlzop_full_usage "\n\n"
     48//usage:       "    -c  Write to stdout"
     49//usage:     "\n    -f  Force"
     50//usage:     "\n    -v  Verbose"
     51//usage:     "\n    -F  Don't store or verify checksum"
     52
    2853#include "libbb.h"
    29 #include "archive.h"
     54#include "bb_archive.h"
    3055#include "liblzo_interface.h"
    3156
     
    92117    unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
    93118
    94 //    LZO_UNUSED(wrkmem);
     119//  LZO_UNUSED(wrkmem);
    95120
    96121    *out_len = 0;
     
    177202                    *litp &= ~3;
    178203                    /* copy over the 2 literals that replace the match */
    179                     copy2(ip-3+1,m_pos,pd(op,m_pos));
     204                    copy2(ip-3+1, m_pos, pd(op, m_pos));
    180205                    /* move literals 1 byte ahead */
    181206                    litp += 2;
     
    187212
    188213                    o_m1_b++;
    189                     *op++ = *m_pos++; *op++ = *m_pos++;
     214                    *op++ = *m_pos++;
     215                    *op++ = *m_pos++;
    190216                    goto copy_literal_run;
    191217                }
     
    216242                        t = *ip++;
    217243                        /* copy over the 3 literals that replace the match */
    218                         copy3(ip-1-2,m_pos,pd(op,m_pos));
     244                        copy3(ip-1-2, m_pos, pd(op, m_pos));
    219245                        /* set new length of previous literal run */
    220246                        lit += 3 + t + 3;
     
    265291                        *litp = (unsigned char)((*litp & ~3) | lit);
    266292                        /* copy over the 3 literals that replace the match */
    267                         copy3(ip-3,m_pos,pd(op,m_pos));
     293                        copy3(ip-3, m_pos, pd(op, m_pos));
    268294                        o_m3_a++;
    269295                    }
     
    276302                        *litp &= ~3;
    277303                        /* copy over the 3 literals that replace the match */
    278                         copy3(ip-4+1,m_pos,pd(op,m_pos));
     304                        copy3(ip-4+1, m_pos, pd(op, m_pos));
    279305                        /* move literals 1 byte ahead */
    280306                        litp += 2;
     
    321347
    322348 eof_found:
    323 //    LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2);
    324 //    LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b);
     349//  LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2);
     350//  LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b);
    325351    *out_len = pd(op, out);
    326352    return (ip == ip_end ? LZO_E_OK :
    327            (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
     353        (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
    328354}
    329355
     
    402428//#define G (*ptr_to_globals)
    403429//#define INIT_G() do {
    404 //        SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
     430//  SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
    405431//} while (0)
    406432
     
    10521078}
    10531079
    1054 static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(unpack_info_t *info UNUSED_PARAM)
     1080static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
    10551081{
    10561082    if (option_mask32 & OPT_DECOMPRESS)
  • branches/3.2/mindi-busybox/archival/rpm.c

    r2725 r3232  
    88 */
    99
     10//usage:#define rpm_trivial_usage
     11//usage:       "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
     12//usage:#define rpm_full_usage "\n\n"
     13//usage:       "Manipulate RPM packages\n"
     14//usage:     "\nCommands:"
     15//usage:     "\n    -i  Install package"
     16//usage:     "\n    -qp Query package"
     17//usage:     "\n    -i  Show information"
     18//usage:     "\n    -l  List contents"
     19//usage:     "\n    -d  List documents"
     20//usage:     "\n    -c  List config files"
     21
    1022#include "libbb.h"
    11 #include "archive.h"
     23#include "bb_archive.h"
    1224#include "rpm.h"
    1325
     
    225237    /*archive_handle->offset = 0; - init_handle() did it */
    226238
    227     setup_unzip_on_fd(archive_handle->src_fd /*, fail_if_not_detected: 1*/);
     239    setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
    228240    while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
    229241        continue;
  • branches/3.2/mindi-busybox/archival/rpm2cpio.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define rpm2cpio_trivial_usage
     11//usage:       "package.rpm"
     12//usage:#define rpm2cpio_full_usage "\n\n"
     13//usage:       "Output a cpio archive of the rpm file"
     14
    915#include "libbb.h"
    10 #include "archive.h"
     16#include "bb_archive.h"
    1117#include "rpm.h"
    1218
     
    6167    skip_header();
    6268
    63 #if 0
     69    //if (SEAMLESS_COMPRESSION)
     70    //  /* We need to know whether child (gzip/bzip/etc) exits abnormally */
     71    //  signal(SIGCHLD, check_errors_in_children);
     72
    6473    /* This works, but doesn't report uncompress errors (they happen in child) */
    65     setup_unzip_on_fd(rpm_fd /*fail_if_not_detected: 1*/);
     74    setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
    6675    if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
    6776        bb_error_msg_and_die("error unpacking");
    68 #else
    69     /* BLOAT */
    70     {
    71         union {
    72             uint8_t b[4];
    73             uint16_t b16[2];
    74             uint32_t b32[1];
    75         } magic;
    76         IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
    77 
    78         xread(rpm_fd, magic.b16, sizeof(magic.b16[0]));
    79         if (magic.b16[0] == GZIP_MAGIC) {
    80             unpack = unpack_gz_stream;
    81         } else
    82         if (ENABLE_FEATURE_SEAMLESS_BZ2
    83          && magic.b16[0] == BZIP2_MAGIC
    84         ) {
    85             unpack = unpack_bz2_stream;
    86         } else
    87         if (ENABLE_FEATURE_SEAMLESS_XZ
    88          && magic.b16[0] == XZ_MAGIC1
    89         ) {
    90             xread(rpm_fd, magic.b32, sizeof(magic.b32[0]));
    91             if (magic.b32[0] != XZ_MAGIC2)
    92                 goto no_magic;
    93             /* unpack_xz_stream wants fd at position 6, no need to seek */
    94             //xlseek(rpm_fd, -6, SEEK_CUR);
    95             unpack = unpack_xz_stream;
    96         } else {
    97  no_magic:
    98             bb_error_msg_and_die("no gzip"
    99                     IF_FEATURE_SEAMLESS_BZ2("/bzip2")
    100                     IF_FEATURE_SEAMLESS_XZ("/xz")
    101                     " magic");
    102         }
    103         if (unpack(rpm_fd, STDOUT_FILENO) < 0)
    104             bb_error_msg_and_die("error unpacking");
    105     }
    106 #endif
    10777
    10878    if (ENABLE_FEATURE_CLEAN_UP) {
     
    11080    }
    11181
    112     return 0;
     82    if (SEAMLESS_COMPRESSION) {
     83        check_errors_in_children(0);
     84        return bb_got_signal;
     85    }
     86    return EXIT_SUCCESS;
    11387}
  • branches/3.2/mindi-busybox/archival/tar.c

    r2725 r3232  
    2424 */
    2525
     26/* TODO: security with -C DESTDIR option can be enhanced.
     27 * Consider tar file created via:
     28 * $ tar cvf bug.tar anything.txt
     29 * $ ln -s /tmp symlink
     30 * $ tar --append -f bug.tar symlink
     31 * $ rm symlink
     32 * $ mkdir symlink
     33 * $ tar --append -f bug.tar symlink/evil.py
     34 *
     35 * This will result in an archive which contains:
     36 * $ tar --list -f bug.tar
     37 * anything.txt
     38 * symlink
     39 * symlink/evil.py
     40 *
     41 * Untarring it puts evil.py in '/tmp' even if the -C DESTDIR is given.
     42 * This doesn't feel right, and IIRC GNU tar doesn't do that.
     43 */
     44
    2645#include <fnmatch.h>
    2746#include "libbb.h"
    28 #include "archive.h"
     47#include "bb_archive.h"
    2948/* FIXME: Stop using this non-standard feature */
    3049#ifndef FNM_LEADING_DIR
     
    4261#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
    4362/* Do not pass gzip flag to writeTarFile() */
    44 #define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \
    45     writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude)
     63#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
     64    writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
    4665#endif
    4766
     
    246265    PUT_OCTAL(header.gid, statbuf->st_gid);
    247266    memset(header.size, '0', sizeof(header.size)-1); /* Regular file size is handled later */
    248     PUT_OCTAL(header.mtime, statbuf->st_mtime);
     267    /* users report that files with negative st_mtime cause trouble, so: */
     268    PUT_OCTAL(header.mtime, statbuf->st_mtime >= 0 ? statbuf->st_mtime : 0);
    249269
    250270    /* Enter the user and group names */
     
    298318        header.typeflag = FIFOTYPE;
    299319    } else if (S_ISREG(statbuf->st_mode)) {
    300         if (sizeof(statbuf->st_size) > 4
    301          && statbuf->st_size > (off_t)0777777777777LL
     320        /* header.size field is 12 bytes long */
     321        /* Does octal-encoded size fit? */
     322        uoff_t filesize = statbuf->st_size;
     323        if (sizeof(filesize) <= 4
     324         || filesize <= (uoff_t)0777777777777LL
    302325        ) {
     326            PUT_OCTAL(header.size, filesize);
     327        }
     328        /* Does base256-encoded size fit?
     329         * It always does unless off_t is wider than 64 bits.
     330         */
     331        else if (ENABLE_FEATURE_TAR_GNU_EXTENSIONS
     332#if ULLONG_MAX > 0xffffffffffffffffLL /* 2^64-1 */
     333         && (filesize <= 0x3fffffffffffffffffffffffLL)
     334#endif
     335        ) {
     336            /* GNU tar uses "base-256 encoding" for very large numbers.
     337             * Encoding is binary, with highest bit always set as a marker
     338             * and sign in next-highest bit:
     339             * 80 00 .. 00 - zero
     340             * bf ff .. ff - largest positive number
     341             * ff ff .. ff - minus 1
     342             * c0 00 .. 00 - smallest negative number
     343             */
     344            char *p8 = header.size + sizeof(header.size);
     345            do {
     346                *--p8 = (uint8_t)filesize;
     347                filesize >>= 8;
     348            } while (p8 != header.size);
     349            *p8 |= 0x80;
     350        } else {
    303351            bb_error_msg_and_die("can't store file '%s' "
    304352                "of size %"OFF_FMT"u, aborting",
     
    306354        }
    307355        header.typeflag = REGTYPE;
    308         PUT_OCTAL(header.size, statbuf->st_size);
    309356    } else {
    310357        bb_error_msg("%s: unknown file type", fileName);
     
    379426    DBG("writeFileToTarball('%s')", fileName);
    380427
    381     /* Strip leading '/' (must be before memorizing hardlink's name) */
    382     header_name = fileName;
    383     while (header_name[0] == '/') {
    384         static smallint warned;
    385 
    386         if (!warned) {
    387             bb_error_msg("removing leading '/' from member names");
    388             warned = 1;
    389         }
    390         header_name++;
    391     }
     428    /* Strip leading '/' and such (must be before memorizing hardlink's name) */
     429    header_name = strip_unsafe_prefix(fileName);
    392430
    393431    if (header_name[0] == '\0')
     
    561599/* gcc 4.2.1 inlines it, making code bigger */
    562600static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
    563     int dereferenceFlag, const llist_t *include,
     601    int recurseFlags, const llist_t *include,
    564602    const llist_t *exclude, int gzip)
    565603{
     
    584622    /* Read the directory/files and iterate over them one at a time */
    585623    while (include) {
    586         if (!recursive_action(include->data, ACTION_RECURSE |
    587                 (dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
     624        if (!recursive_action(include->data, recurseFlags,
    588625                writeFileToTarball, writeFileToTarball, &tbInfo, 0)
    589626        ) {
     
    625662#else
    626663int writeTarFile(int tar_fd, int verboseFlag,
    627     int dereferenceFlag, const llist_t *include,
     664    int recurseFlags, const llist_t *include,
    628665    const llist_t *exclude, int gzip);
    629666#endif /* FEATURE_TAR_CREATE */
     
    637674
    638675    while (list) {
    639         src_stream = xfopen_for_read(llist_pop(&list));
     676        src_stream = xfopen_stdin(llist_pop(&list));
    640677        while ((line = xmalloc_fgetline(src_stream)) != NULL) {
    641678            /* kill trailing '/' unless the string is just "/" */
     
    653690#endif
    654691
    655 #if ENABLE_FEATURE_SEAMLESS_Z
    656 static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
    657 {
    658     /* Can't lseek over pipes */
    659     archive_handle->seek = seek_by_read;
    660 
    661     /* do the decompression, and cleanup */
    662     if (xread_char(archive_handle->src_fd) != 0x1f
    663      || xread_char(archive_handle->src_fd) != 0x9d
    664     ) {
    665         bb_error_msg_and_die("invalid magic");
    666     }
    667 
    668     open_transformer(archive_handle->src_fd, unpack_Z_stream, "uncompress");
    669     archive_handle->offset = 0;
    670     while (get_header_tar(archive_handle) == EXIT_SUCCESS)
    671         continue;
    672 
    673     /* Can only do one file at a time */
    674     return EXIT_FAILURE;
    675 }
    676 #else
    677 # define get_header_tar_Z NULL
    678 #endif
    679 
    680 #ifdef CHECK_FOR_CHILD_EXITCODE
    681 /* Looks like it isn't needed - tar detects malformed (truncated)
    682  * archive if e.g. bunzip2 fails */
    683 static int child_error;
    684 
    685 static void handle_SIGCHLD(int status)
    686 {
    687     /* Actually, 'status' is a signo. We reuse it for other needs */
    688 
    689     /* Wait for any child without blocking */
    690     if (wait_any_nohang(&status) < 0)
    691         /* wait failed?! I'm confused... */
    692         return;
    693 
    694     if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
    695         /* child exited with 0 */
    696         return;
    697     /* Cannot happen?
    698     if (!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
    699     child_error = 1;
    700 }
    701 #endif
    702 
    703692//usage:#define tar_trivial_usage
    704 //usage:       "-[" IF_FEATURE_TAR_CREATE("c") "xt" IF_FEATURE_SEAMLESS_GZ("z")
    705 //usage:    IF_FEATURE_SEAMLESS_BZ2("j") IF_FEATURE_SEAMLESS_LZMA("a")
    706 //usage:    IF_FEATURE_SEAMLESS_Z("Z") IF_FEATURE_TAR_NOPRESERVE_TIME("m") "vO] "
    707 //usage:    IF_FEATURE_TAR_FROM("[-X FILE] ")
    708 //usage:       "[-f TARFILE] [-C DIR] [FILE]..."
     693//usage:    "-[" IF_FEATURE_TAR_CREATE("c") "xt"
     694//usage:    IF_FEATURE_SEAMLESS_Z("Z")
     695//usage:    IF_FEATURE_SEAMLESS_GZ("z")
     696//usage:    IF_FEATURE_SEAMLESS_XZ("J")
     697//usage:    IF_FEATURE_SEAMLESS_BZ2("j")
     698//usage:    IF_FEATURE_SEAMLESS_LZMA("a")
     699//usage:    IF_FEATURE_TAR_CREATE("h")
     700//usage:    IF_FEATURE_TAR_NOPRESERVE_TIME("m")
     701//usage:    "vO] "
     702//usage:    IF_FEATURE_TAR_FROM("[-X FILE] [-T FILE] ")
     703//usage:    "[-f TARFILE] [-C DIR] [FILE]..."
    709704//usage:#define tar_full_usage "\n\n"
    710705//usage:    IF_FEATURE_TAR_CREATE("Create, extract, ")
     
    717712//usage:     "\n    x   Extract"
    718713//usage:     "\n    t   List"
    719 //usage:     "\nOptions:"
    720714//usage:     "\n    f   Name of TARFILE ('-' for stdin/out)"
    721715//usage:     "\n    C   Change to DIR before operation"
    722716//usage:     "\n    v   Verbose"
     717//usage:    IF_FEATURE_SEAMLESS_Z(
     718//usage:     "\n    Z   (De)compress using compress"
     719//usage:    )
    723720//usage:    IF_FEATURE_SEAMLESS_GZ(
    724721//usage:     "\n    z   (De)compress using gzip"
     722//usage:    )
     723//usage:    IF_FEATURE_SEAMLESS_XZ(
     724//usage:     "\n    J   (De)compress using xz"
    725725//usage:    )
    726726//usage:    IF_FEATURE_SEAMLESS_BZ2(
     
    729729//usage:    IF_FEATURE_SEAMLESS_LZMA(
    730730//usage:     "\n    a   (De)compress using lzma"
    731 //usage:    )
    732 //usage:    IF_FEATURE_SEAMLESS_Z(
    733 //usage:     "\n    Z   (De)compress using compress"
    734731//usage:    )
    735732//usage:     "\n    O   Extract to stdout"
     
    756753//  p   same-permissions
    757754//  k   keep-old
     755//  no-recursion
    758756//  numeric-owner
    759757//  no-same-permissions
     
    772770    IF_FEATURE_TAR_FROM(     OPTBIT_EXCLUDE_FROM,)
    773771    IF_FEATURE_SEAMLESS_GZ(  OPTBIT_GZIP        ,)
    774     IF_FEATURE_SEAMLESS_Z(   OPTBIT_COMPRESS    ,) // 16th bit
     772    IF_FEATURE_SEAMLESS_XZ(  OPTBIT_XZ          ,) // 16th bit
     773    IF_FEATURE_SEAMLESS_Z(   OPTBIT_COMPRESS    ,)
    775774    IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
    776775#if ENABLE_FEATURE_TAR_LONG_OPTIONS
     776    OPTBIT_NORECURSION,
    777777    IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND   ,)
    778778    OPTBIT_NUMERIC_OWNER,
     
    796796    OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM(     (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
    797797    OPT_GZIP         = IF_FEATURE_SEAMLESS_GZ(  (1 << OPTBIT_GZIP        )) + 0, // z
     798    OPT_XZ           = IF_FEATURE_SEAMLESS_XZ(  (1 << OPTBIT_XZ          )) + 0, // J
    798799    OPT_COMPRESS     = IF_FEATURE_SEAMLESS_Z(   (1 << OPTBIT_COMPRESS    )) + 0, // Z
    799800    OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
     801    OPT_NORECURSION     = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION    )) + 0, // no-recursion
    800802    OPT_2COMMAND        = IF_FEATURE_TAR_TO_COMMAND(  (1 << OPTBIT_2COMMAND       )) + 0, // to-command
    801803    OPT_NUMERIC_OWNER   = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER  )) + 0, // numeric-owner
    802804    OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
    803805    OPT_OVERWRITE       = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE      )) + 0, // overwrite
     806
     807    OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS),
    804808};
    805809#if ENABLE_FEATURE_TAR_LONG_OPTIONS
     
    834838    "gzip\0"                No_argument       "z"
    835839# endif
     840# if ENABLE_FEATURE_SEAMLESS_XZ
     841    "xz\0"                  No_argument       "J"
     842# endif
    836843# if ENABLE_FEATURE_SEAMLESS_Z
    837844    "compress\0"            No_argument       "Z"
     
    840847    "touch\0"               No_argument       "m"
    841848# endif
     849    "no-recursion\0"    No_argument       "\xfa"
    842850# if ENABLE_FEATURE_TAR_TO_COMMAND
    843851    "to-command\0"      Required_argument "\xfb"
     
    860868int tar_main(int argc UNUSED_PARAM, char **argv)
    861869{
    862     char FAST_FUNC (*get_header_ptr)(archive_handle_t *) = get_header_tar;
    863870    archive_handle_t *tar_handle;
    864871    char *base_dir = NULL;
     
    883890    opt_complementary = "--:" // first arg is options
    884891        "tt:vv:" // count -t,-v
    885         "?:" // bail out with usage instead of error return
    886         "X::T::" // cumulative lists
     892        IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
    887893#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
    888894        "\xff::" // cumulative lists for --exclude
     
    928934        IF_FEATURE_TAR_FROM(     "T:X:")
    929935        IF_FEATURE_SEAMLESS_GZ(  "z"   )
     936        IF_FEATURE_SEAMLESS_XZ(  "J"   )
    930937        IF_FEATURE_SEAMLESS_Z(   "Z"   )
    931938        IF_FEATURE_TAR_NOPRESERVE_TIME("m")
     
    957964        signal(SIGPIPE, SIG_IGN);
    958965        tar_handle->action_data = data_extract_to_command;
     966        IF_FEATURE_TAR_TO_COMMAND(tar_handle->tar__to_command_shell = xstrdup(get_shell_name());)
    959967    }
    960968
     
    975983        tar_handle->ah_flags |= ARCHIVE_O_TRUNC;
    976984    }
    977 
    978     if (opt & OPT_GZIP)
    979         get_header_ptr = get_header_tar_gz;
    980 
    981     if (opt & OPT_BZIP2)
    982         get_header_ptr = get_header_tar_bz2;
    983 
    984     if (opt & OPT_LZMA)
    985         get_header_ptr = get_header_tar_lzma;
    986 
    987     if (opt & OPT_COMPRESS)
    988         get_header_ptr = get_header_tar_Z;
    989985
    990986    if (opt & OPT_NOPRESERVE_TIME)
     
    10401036            if (ENABLE_FEATURE_TAR_AUTODETECT
    10411037             && flags == O_RDONLY
    1042              && get_header_ptr == get_header_tar
     1038             && !(opt & OPT_ANY_COMPRESS)
    10431039            ) {
    10441040                tar_handle->src_fd = open_zipped(tar_filename);
     
    10541050        xchdir(base_dir);
    10551051
    1056 #ifdef CHECK_FOR_CHILD_EXITCODE
    1057     /* We need to know whether child (gzip/bzip/etc) exits abnormally */
    1058     signal(SIGCHLD, handle_SIGCHLD);
    1059 #endif
     1052    //if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
     1053    //  /* We need to know whether child (gzip/bzip/etc) exits abnormally */
     1054    //  signal(SIGCHLD, check_errors_in_children);
    10601055
    10611056    /* Create an archive */
     
    10691064#endif
    10701065        /* NB: writeTarFile() closes tar_handle->src_fd */
    1071         return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
     1066        return writeTarFile(tar_handle->src_fd, verboseFlag,
     1067                (opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
     1068                | (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE),
    10721069                tar_handle->accept,
    10731070                tar_handle->reject, zipMode);
    10741071    }
    10751072
    1076     while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
     1073    if (opt & OPT_ANY_COMPRESS) {
     1074        USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
     1075        USE_FOR_NOMMU(const char *xformer_prog;)
     1076
     1077        if (opt & OPT_COMPRESS)
     1078            USE_FOR_MMU(xformer = unpack_Z_stream;)
     1079            USE_FOR_NOMMU(xformer_prog = "uncompress";)
     1080        if (opt & OPT_GZIP)
     1081            USE_FOR_MMU(xformer = unpack_gz_stream;)
     1082            USE_FOR_NOMMU(xformer_prog = "gunzip";)
     1083        if (opt & OPT_BZIP2)
     1084            USE_FOR_MMU(xformer = unpack_bz2_stream;)
     1085            USE_FOR_NOMMU(xformer_prog = "bunzip2";)
     1086        if (opt & OPT_LZMA)
     1087            USE_FOR_MMU(xformer = unpack_lzma_stream;)
     1088            USE_FOR_NOMMU(xformer_prog = "unlzma";)
     1089        if (opt & OPT_XZ)
     1090            USE_FOR_MMU(xformer = unpack_xz_stream;)
     1091            USE_FOR_NOMMU(xformer_prog = "unxz";)
     1092
     1093        open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
     1094        /* Can't lseek over pipes */
     1095        tar_handle->seek = seek_by_read;
     1096        /*tar_handle->offset = 0; - already is */
     1097    }
     1098
     1099    while (get_header_tar(tar_handle) == EXIT_SUCCESS)
    10771100        continue;
    10781101
     
    10901113        close(tar_handle->src_fd);
    10911114
     1115    if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
     1116        check_errors_in_children(0);
     1117        return bb_got_signal;
     1118    }
    10921119    return EXIT_SUCCESS;
    10931120}
  • branches/3.2/mindi-busybox/archival/unzip.c

    r2725 r3232  
    2020 */
    2121
     22//usage:#define unzip_trivial_usage
     23//usage:       "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
     24//usage:#define unzip_full_usage "\n\n"
     25//usage:       "Extract FILEs from ZIP archive\n"
     26//usage:     "\n    -l  List contents (with -q for short form)"
     27//usage:     "\n    -n  Never overwrite files (default: ask)"
     28//usage:     "\n    -o  Overwrite"
     29//usage:     "\n    -p  Print to stdout"
     30//usage:     "\n    -q  Quiet"
     31//usage:     "\n    -x FILE Exclude FILEs"
     32//usage:     "\n    -d DIR  Extract into DIR"
     33
    2234#include "libbb.h"
    23 #include "archive.h"
     35#include "bb_archive.h"
    2436
    2537enum {
     
    224236    char *name = xstrdup(fn);
    225237    if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
    226         bb_error_msg_and_die("exiting"); /* bb_make_directory is noisy */
     238        xfunc_die(); /* bb_make_directory is noisy */
    227239    }
    228240    free(name);
     
    238250    } else {
    239251        /* Method 8 - inflate */
    240         inflate_unzip_result res;
    241         if (inflate_unzip(&res, zip_header->formatted.cmpsize, zip_fd, dst_fd) < 0)
     252        transformer_aux_data_t aux;
     253        init_transformer_aux_data(&aux);
     254        aux.bytes_in = zip_header->formatted.cmpsize;
     255        if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
    242256            bb_error_msg_and_die("inflate error");
    243257        /* Validate decompression - crc */
    244         if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
     258        if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
    245259            bb_error_msg_and_die("crc error");
    246260        }
    247261        /* Validate decompression - size */
    248         if (zip_header->formatted.ucmpsize != res.bytes_out) {
     262        if (zip_header->formatted.ucmpsize != aux.bytes_out) {
    249263            /* Don't die. Who knows, maybe len calculation
    250264             * was botched somewhere. After all, crc matched! */
     
    264278    smallint listing = 0;
    265279    smallint overwrite = O_PROMPT;
     280    smallint x_opt_seen;
    266281#if ENABLE_DESKTOP
    267282    uint32_t cdf_offset;
     
    277292    char *base_dir = NULL;
    278293    int i, opt;
    279     int opt_range = 0;
    280294    char key_buf[80];
    281295    struct stat stat_buf;
     
    322336 */
    323337
     338    x_opt_seen = 0;
    324339    /* '-' makes getopt return 1 for non-options */
    325340    while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
    326         switch (opt_range) {
    327         case 0: /* Options */
    328             switch (opt) {
    329             case 'l': /* List */
    330                 listing = 1;
    331                 break;
    332 
    333             case 'n': /* Never overwrite existing files */
    334                 overwrite = O_NEVER;
    335                 break;
    336 
    337             case 'o': /* Always overwrite existing files */
    338                 overwrite = O_ALWAYS;
    339                 break;
    340 
    341             case 'p': /* Extract files to stdout and fall through to set verbosity */
    342                 dst_fd = STDOUT_FILENO;
    343 
    344             case 'q': /* Be quiet */
    345                 quiet++;
    346                 break;
    347 
    348             case 'v': /* Verbose list */
    349                 IF_DESKTOP(verbose++;)
    350                 listing = 1;
    351                 break;
    352 
    353             case 1: /* The zip file */
     341        switch (opt) {
     342        case 'd':  /* Extract to base directory */
     343            base_dir = optarg;
     344            break;
     345
     346        case 'l': /* List */
     347            listing = 1;
     348            break;
     349
     350        case 'n': /* Never overwrite existing files */
     351            overwrite = O_NEVER;
     352            break;
     353
     354        case 'o': /* Always overwrite existing files */
     355            overwrite = O_ALWAYS;
     356            break;
     357
     358        case 'p': /* Extract files to stdout and fall through to set verbosity */
     359            dst_fd = STDOUT_FILENO;
     360
     361        case 'q': /* Be quiet */
     362            quiet++;
     363            break;
     364
     365        case 'v': /* Verbose list */
     366            IF_DESKTOP(verbose++;)
     367            listing = 1;
     368            break;
     369
     370        case 'x':
     371            x_opt_seen = 1;
     372            break;
     373
     374        case 1:
     375            if (!src_fn) {
     376                /* The zip file */
    354377                /* +5: space for ".zip" and NUL */
    355378                src_fn = xmalloc(strlen(optarg) + 5);
    356379                strcpy(src_fn, optarg);
    357                 opt_range++;
    358                 break;
    359 
    360             default:
    361                 bb_show_usage();
     380            } else if (!x_opt_seen) {
     381                /* Include files */
     382                llist_add_to(&zaccept, optarg);
     383            } else {
     384                /* Exclude files */
     385                llist_add_to(&zreject, optarg);
    362386            }
    363387            break;
    364 
    365         case 1: /* Include files */
    366             if (opt == 1) {
    367                 llist_add_to(&zaccept, optarg);
    368                 break;
    369             }
    370             if (opt == 'd') {
    371                 base_dir = optarg;
    372                 opt_range += 2;
    373                 break;
    374             }
    375             if (opt == 'x') {
    376                 opt_range++;
    377                 break;
    378             }
    379             bb_show_usage();
    380 
    381         case 2 : /* Exclude files */
    382             if (opt == 1) {
    383                 llist_add_to(&zreject, optarg);
    384                 break;
    385             }
    386             if (opt == 'd') { /* Extract to base directory */
    387                 base_dir = optarg;
    388                 opt_range++;
    389                 break;
    390             }
    391             /* fall through */
    392388
    393389        default:
     
    396392    }
    397393
    398     if (src_fn == NULL) {
     394#ifndef __GLIBC__
     395    /*
     396     * This code is needed for non-GNU getopt
     397     * which doesn't understand "-" in option string.
     398     * The -x option won't work properly in this case:
     399     * "unzip a.zip q -x w e" will be interpreted as
     400     * "unzip a.zip q w e -x" = "unzip a.zip q w e"
     401     */
     402    argv += optind;
     403    if (argv[0]) {
     404        /* +5: space for ".zip" and NUL */
     405        src_fn = xmalloc(strlen(argv[0]) + 5);
     406        strcpy(src_fn, argv[0]);
     407        while (*++argv)
     408            llist_add_to(&zaccept, *argv);
     409    }
     410#endif
     411
     412    if (!src_fn) {
    399413        bb_show_usage();
    400414    }
     
    407421            overwrite = O_NEVER;
    408422    } else {
    409         static const char extn[][5] = {"", ".zip", ".ZIP"};
    410         int orig_src_fn_len = strlen(src_fn);
    411         int src_fd = -1;
    412 
    413         for (i = 0; (i < 3) && (src_fd == -1); i++) {
    414             strcpy(src_fn + orig_src_fn_len, extn[i]);
     423        static const char extn[][5] = { ".zip", ".ZIP" };
     424        char *ext = src_fn + strlen(src_fn);
     425        int src_fd;
     426
     427        i = 0;
     428        for (;;) {
    415429            src_fd = open(src_fn, O_RDONLY);
    416         }
    417         if (src_fd == -1) {
    418             src_fn[orig_src_fn_len] = '\0';
    419             bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
     430            if (src_fd >= 0)
     431                break;
     432            if (++i > 2) {
     433                *ext = '\0';
     434                bb_error_msg_and_die("can't open %s[.zip]", src_fn);
     435            }
     436            strcpy(ext, extn[i - 1]);
    420437        }
    421438        xmove_fd(src_fd, zip_fd);
     
    583600                    }
    584601                    unzip_create_leading_dirs(dst_fn);
    585                     if (bb_make_directory(dst_fn, dir_mode, 0)) {
    586                         bb_error_msg_and_die("exiting");
     602                    if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
     603                        xfunc_die();
    587604                    }
    588605                } else {
     
    608625                        } else {
    609626                            printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
     627                            fflush_all();
    610628                            if (!fgets(key_buf, sizeof(key_buf), stdin)) {
    611629                                bb_perror_msg_and_die("can't read input");
Note: See TracChangeset for help on using the changeset viewer.