1 /* vi: set sw=4 ts=4: */
3 * Mini rpm2cpio implementation for busybox
5 * Copyright (C) 2001 by Laurence Anderson
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 #include "unarchive.h"
12 #define RPM_MAGIC "\355\253\356\333"
13 #define RPM_HEADER_MAGIC "\216\255\350"
16 unsigned char magic[4];
22 uint16_t signature_type;
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) */
34 static void skip_header(int rpm_fd)
36 struct rpm_header header;
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 */
42 if (header.version != 1) {
43 bb_error_msg_and_die("unsupported RPM header version"); /* This program only supports v1 headers */
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 */
51 /* No getopt required */
52 int rpm2cpio_main(int argc, char **argv)
56 unsigned char magic[2];
59 rpm_fd = STDIN_FILENO;
61 rpm_fd = xopen(argv[1], O_RDONLY);
64 xread(rpm_fd, &lead, sizeof(struct rpm_lead));
65 if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
66 bb_error_msg_and_die("invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
69 /* Skip the signature header */
71 lseek(rpm_fd, (8 - (lseek(rpm_fd, 0, SEEK_CUR) % 8)) % 8, SEEK_CUR);
73 /* Skip the main header */
76 xread(rpm_fd, &magic, 2);
77 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
78 bb_error_msg_and_die("invalid gzip magic");
81 check_header_gzip(rpm_fd);
82 if (inflate_gunzip(rpm_fd, STDOUT_FILENO) < 0) {
83 bb_error_msg("error inflating");