diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 09:30:38 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 09:32:19 +0200 |
commit | 3fa9262dcd4186a9a5cabb5a7586597187a62565 (patch) | |
tree | 51e4566429c3f5b2c4c18cadfc0182cd18eb460d /archival/rpm.c | |
parent | 3bc2317c610af0a34c665e0e84169caa2653ff41 (diff) | |
download | busybox-w32-3fa9262dcd4186a9a5cabb5a7586597187a62565.tar.gz busybox-w32-3fa9262dcd4186a9a5cabb5a7586597187a62565.tar.bz2 busybox-w32-3fa9262dcd4186a9a5cabb5a7586597187a62565.zip |
rpm,rpm2cpio: put both sources into one file, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/rpm.c')
-rw-r--r-- | archival/rpm.c | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/archival/rpm.c b/archival/rpm.c index 89b36dd46..bb6cc4520 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -6,7 +6,6 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | |||
10 | //config:config RPM | 9 | //config:config RPM |
11 | //config: bool "rpm (33 kb)" | 10 | //config: bool "rpm (33 kb)" |
12 | //config: default y | 11 | //config: default y |
@@ -14,6 +13,7 @@ | |||
14 | //config: Mini RPM applet - queries and extracts RPM packages. | 13 | //config: Mini RPM applet - queries and extracts RPM packages. |
15 | 14 | ||
16 | //applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) | 15 | //applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) |
16 | |||
17 | //kbuild:lib-$(CONFIG_RPM) += rpm.o | 17 | //kbuild:lib-$(CONFIG_RPM) += rpm.o |
18 | 18 | ||
19 | #include "libbb.h" | 19 | #include "libbb.h" |
@@ -479,3 +479,98 @@ int rpm_main(int argc, char **argv) | |||
479 | 479 | ||
480 | return 0; | 480 | return 0; |
481 | } | 481 | } |
482 | |||
483 | /* | ||
484 | * Mini rpm2cpio implementation for busybox | ||
485 | * | ||
486 | * Copyright (C) 2001 by Laurence Anderson | ||
487 | * | ||
488 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
489 | */ | ||
490 | //config:config RPM2CPIO | ||
491 | //config: bool "rpm2cpio (20 kb)" | ||
492 | //config: default y | ||
493 | //config: help | ||
494 | //config: Converts a RPM file into a CPIO archive. | ||
495 | |||
496 | //applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
497 | |||
498 | //kbuild:lib-$(CONFIG_RPM2CPIO) += rpm.o | ||
499 | |||
500 | //usage:#define rpm2cpio_trivial_usage | ||
501 | //usage: "PACKAGE.rpm" | ||
502 | //usage:#define rpm2cpio_full_usage "\n\n" | ||
503 | //usage: "Output a cpio archive of the rpm file" | ||
504 | |||
505 | enum { rpm_fd = STDIN_FILENO }; | ||
506 | |||
507 | static unsigned skip_header(void) | ||
508 | { | ||
509 | struct rpm_header header; | ||
510 | unsigned len; | ||
511 | |||
512 | xread(rpm_fd, &header, sizeof(header)); | ||
513 | // if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) { | ||
514 | // bb_error_msg_and_die("invalid RPM header magic"); | ||
515 | // } | ||
516 | // if (header.version != 1) { | ||
517 | // bb_error_msg_and_die("unsupported RPM header version"); | ||
518 | // } | ||
519 | if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) { | ||
520 | bb_error_msg_and_die("invalid RPM header magic or unsupported version"); | ||
521 | // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER)); | ||
522 | } | ||
523 | |||
524 | /* Seek past index entries, and past store */ | ||
525 | len = 16 * ntohl(header.entries) + ntohl(header.size); | ||
526 | seek_by_jump(rpm_fd, len); | ||
527 | |||
528 | return sizeof(header) + len; | ||
529 | } | ||
530 | |||
531 | /* No getopt required */ | ||
532 | int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
533 | int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) | ||
534 | { | ||
535 | struct rpm_lead lead; | ||
536 | unsigned pos; | ||
537 | |||
538 | if (argv[1]) { | ||
539 | xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd); | ||
540 | } | ||
541 | xread(rpm_fd, &lead, sizeof(lead)); | ||
542 | |||
543 | /* Just check the magic, the rest is irrelevant */ | ||
544 | if (lead.magic != htonl(RPM_LEAD_MAGIC)) { | ||
545 | bb_error_msg_and_die("invalid RPM magic"); | ||
546 | } | ||
547 | |||
548 | /* Skip the signature header, align to 8 bytes */ | ||
549 | pos = skip_header(); | ||
550 | seek_by_jump(rpm_fd, (-(int)pos) & 7); | ||
551 | |||
552 | /* Skip the main header */ | ||
553 | skip_header(); | ||
554 | |||
555 | //if (SEAMLESS_COMPRESSION) - we do this at the end instead. | ||
556 | // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ | ||
557 | // signal(SIGCHLD, check_errors_in_children); | ||
558 | |||
559 | //TODO: look for rpm tag RPMTAG_PAYLOADCOMPRESSOR (dec 1125, hex 0x465), | ||
560 | // if the value is "lzma", set up decompressor without detection | ||
561 | // (lzma can't be detected). | ||
562 | |||
563 | setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1); | ||
564 | if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) | ||
565 | bb_error_msg_and_die("error unpacking"); | ||
566 | |||
567 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
568 | close(rpm_fd); | ||
569 | } | ||
570 | |||
571 | if (SEAMLESS_COMPRESSION) { | ||
572 | check_errors_in_children(0); | ||
573 | return bb_got_signal; | ||
574 | } | ||
575 | return EXIT_SUCCESS; | ||
576 | } | ||