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
) MAIN_EXTERNALLY_VISIBLE
;
53 int rpm2cpio_main(int argc
, char **argv
)
57 unsigned char magic
[2];
60 rpm_fd
= STDIN_FILENO
;
62 rpm_fd
= xopen(argv
[1], O_RDONLY
);
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 */
70 /* Skip the signature header */
72 lseek(rpm_fd
, (8 - (lseek(rpm_fd
, 0, SEEK_CUR
) % 8)) % 8, SEEK_CUR
);
74 /* Skip the main header */
77 xread(rpm_fd
, &magic
, 2);
78 if ((magic
[0] != 0x1f) || (magic
[1] != 0x8b)) {
79 bb_error_msg_and_die("invalid gzip magic");
82 if (unpack_gz_stream(rpm_fd
, STDOUT_FILENO
) < 0) {
83 bb_error_msg("error inflating");