source: MondoRescue/branches/3.3/mindi-busybox/archival/rpm2cpio.c@ 3904

Last change on this file since 3904 was 3621, checked in by Bruno Cornec, 10 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

File size: 2.5 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * Mini rpm2cpio implementation for busybox
4 *
5 * Copyright (C) 2001 by Laurence Anderson
6 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]8 */
[3232]9
[3621]10//config:config RPM2CPIO
11//config: bool "rpm2cpio"
12//config: default y
13//config: help
14//config: Converts a RPM file into a CPIO archive.
15
16//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
17//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
18
[3232]19//usage:#define rpm2cpio_trivial_usage
20//usage: "package.rpm"
21//usage:#define rpm2cpio_full_usage "\n\n"
22//usage: "Output a cpio archive of the rpm file"
23
[1765]24#include "libbb.h"
[3232]25#include "bb_archive.h"
[2725]26#include "rpm.h"
[821]27
[2725]28enum { rpm_fd = STDIN_FILENO };
[821]29
[2725]30static unsigned skip_header(void)
[821]31{
32 struct rpm_header header;
[2725]33 unsigned len;
[821]34
[2725]35 xread(rpm_fd, &header, sizeof(header));
36// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
37// bb_error_msg_and_die("invalid RPM header magic");
38// }
39// if (header.version != 1) {
40// bb_error_msg_and_die("unsupported RPM header version");
41// }
42 if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
43 bb_error_msg_and_die("invalid RPM header magic or unsupported version");
44 // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
[821]45 }
[2725]46
47 /* Seek past index entries, and past store */
48 len = 16 * ntohl(header.entries) + ntohl(header.size);
49 seek_by_jump(rpm_fd, len);
50
51 return sizeof(header) + len;
[821]52}
53
54/* No getopt required */
[2725]55int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
56int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
[821]57{
58 struct rpm_lead lead;
[2725]59 unsigned pos;
[821]60
[2725]61 if (argv[1]) {
62 xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
[821]63 }
[2725]64 xread(rpm_fd, &lead, sizeof(lead));
[821]65
[2725]66 /* Just check the magic, the rest is irrelevant */
67 if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
68 bb_error_msg_and_die("invalid RPM magic");
[821]69 }
70
[2725]71 /* Skip the signature header, align to 8 bytes */
72 pos = skip_header();
73 seek_by_jump(rpm_fd, (-(int)pos) & 7);
[821]74
75 /* Skip the main header */
[2725]76 skip_header();
[821]77
[3232]78 //if (SEAMLESS_COMPRESSION)
79 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */
80 // signal(SIGCHLD, check_errors_in_children);
81
[2725]82 /* This works, but doesn't report uncompress errors (they happen in child) */
[3621]83 setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
[2725]84 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
85 bb_error_msg_and_die("error unpacking");
86
87 if (ENABLE_FEATURE_CLEAN_UP) {
88 close(rpm_fd);
[821]89 }
90
[3232]91 if (SEAMLESS_COMPRESSION) {
92 check_errors_in_children(0);
93 return bb_got_signal;
94 }
95 return EXIT_SUCCESS;
[821]96}
Note: See TracBrowser for help on using the repository browser.