Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/archival/rpm2cpio.c

    r1765 r2725  
    55 * Copyright (C) 2001 by Laurence Anderson
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    99#include "libbb.h"
    10 #include "unarchive.h"
     10#include "archive.h"
     11#include "rpm.h"
    1112
    12 #define RPM_MAGIC "\355\253\356\333"
    13 #define RPM_HEADER_MAGIC "\216\255\350"
     13enum { rpm_fd = STDIN_FILENO };
    1414
    15 struct rpm_lead {
    16     unsigned char magic[4];
    17     uint8_t major, minor;
    18     uint16_t type;
    19     uint16_t archnum;
    20     char name[66];
    21     uint16_t osnum;
    22     uint16_t signature_type;
    23     char reserved[16];
    24 };
    25 
    26 struct rpm_header {
    27     char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
    28     uint8_t version; /* 1 byte version number */
    29     uint32_t reserved; /* 4 bytes reserved */
    30     uint32_t entries; /* Number of entries in header (4 bytes) */
    31     uint32_t size; /* Size of store (4 bytes) */
    32 };
    33 
    34 static void skip_header(int rpm_fd)
     15static unsigned skip_header(void)
    3516{
    3617    struct rpm_header header;
     18    unsigned len;
    3719
    38     xread(rpm_fd, &header, sizeof(struct rpm_header));
    39     if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
    40         bb_error_msg_and_die("invalid RPM header magic"); /* Invalid magic */
     20    xread(rpm_fd, &header, sizeof(header));
     21//  if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
     22//      bb_error_msg_and_die("invalid RPM header magic");
     23//  }
     24//  if (header.version != 1) {
     25//      bb_error_msg_and_die("unsupported RPM header version");
     26//  }
     27    if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
     28        bb_error_msg_and_die("invalid RPM header magic or unsupported version");
     29        // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
    4130    }
    42     if (header.version != 1) {
    43         bb_error_msg_and_die("unsupported RPM header version"); /* This program only supports v1 headers */
    44     }
    45     header.entries = ntohl(header.entries);
    46     header.size = ntohl(header.size);
    47     lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
    48     lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
     31
     32    /* Seek past index entries, and past store */
     33    len = 16 * ntohl(header.entries) + ntohl(header.size);
     34    seek_by_jump(rpm_fd, len);
     35
     36    return sizeof(header) + len;
    4937}
    5038
    5139/* No getopt required */
    52 int rpm2cpio_main(int argc, char **argv);
    53 int rpm2cpio_main(int argc, char **argv)
     40int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     41int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
    5442{
    5543    struct rpm_lead lead;
    56     int rpm_fd;
    57     unsigned char magic[2];
     44    unsigned pos;
    5845
    59     if (argc == 1) {
    60         rpm_fd = STDIN_FILENO;
    61     } else {
    62         rpm_fd = xopen(argv[1], O_RDONLY);
     46    if (argv[1]) {
     47        xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
     48    }
     49    xread(rpm_fd, &lead, sizeof(lead));
     50
     51    /* Just check the magic, the rest is irrelevant */
     52    if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
     53        bb_error_msg_and_die("invalid RPM magic");
    6354    }
    6455
    65     xread(rpm_fd, &lead, sizeof(struct rpm_lead));
    66     if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
    67         bb_error_msg_and_die("invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
    68     }
    69 
    70     /* Skip the signature header */
    71     skip_header(rpm_fd);
    72     lseek(rpm_fd, (8 - (lseek(rpm_fd, 0, SEEK_CUR) % 8)) % 8, SEEK_CUR);
     56    /* Skip the signature header, align to 8 bytes */
     57    pos = skip_header();
     58    seek_by_jump(rpm_fd, (-(int)pos) & 7);
    7359
    7460    /* Skip the main header */
    75     skip_header(rpm_fd);
     61    skip_header();
    7662
    77     xread(rpm_fd, &magic, 2);
    78     if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
    79         bb_error_msg_and_die("invalid gzip magic");
     63#if 0
     64    /* This works, but doesn't report uncompress errors (they happen in child) */
     65    setup_unzip_on_fd(rpm_fd /*fail_if_not_detected: 1*/);
     66    if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
     67        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");
    80105    }
     106#endif
    81107
    82     check_header_gzip_or_die(rpm_fd);
    83     if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
    84         bb_error_msg("error inflating");
     108    if (ENABLE_FEATURE_CLEAN_UP) {
     109        close(rpm_fd);
    85110    }
    86 
    87     close(rpm_fd);
    88111
    89112    return 0;
Note: See TracChangeset for help on using the changeset viewer.