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 | |
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>
-rw-r--r-- | archival/rpm.c | 97 | ||||
-rw-r--r-- | archival/rpm2cpio.c | 99 |
2 files changed, 96 insertions, 100 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 | } | ||
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c deleted file mode 100644 index a6db19c13..000000000 --- a/archival/rpm2cpio.c +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini rpm2cpio implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2001 by Laurence Anderson | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | |||
10 | //config:config RPM2CPIO | ||
11 | //config: bool "rpm2cpio (20 kb)" | ||
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 | |||
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 | |||
24 | #include "libbb.h" | ||
25 | #include "bb_archive.h" | ||
26 | #include "rpm.h" | ||
27 | |||
28 | enum { rpm_fd = STDIN_FILENO }; | ||
29 | |||
30 | static unsigned skip_header(void) | ||
31 | { | ||
32 | struct rpm_header header; | ||
33 | unsigned len; | ||
34 | |||
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)); | ||
45 | } | ||
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; | ||
52 | } | ||
53 | |||
54 | /* No getopt required */ | ||
55 | int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
56 | int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) | ||
57 | { | ||
58 | struct rpm_lead lead; | ||
59 | unsigned pos; | ||
60 | |||
61 | if (argv[1]) { | ||
62 | xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd); | ||
63 | } | ||
64 | xread(rpm_fd, &lead, sizeof(lead)); | ||
65 | |||
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"); | ||
69 | } | ||
70 | |||
71 | /* Skip the signature header, align to 8 bytes */ | ||
72 | pos = skip_header(); | ||
73 | seek_by_jump(rpm_fd, (-(int)pos) & 7); | ||
74 | |||
75 | /* Skip the main header */ | ||
76 | skip_header(); | ||
77 | |||
78 | //if (SEAMLESS_COMPRESSION) - we do this at the end instead. | ||
79 | // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ | ||
80 | // signal(SIGCHLD, check_errors_in_children); | ||
81 | |||
82 | //TODO: look for rpm tag RPMTAG_PAYLOADCOMPRESSOR (dec 1125, hex 0x465), | ||
83 | // if the value is "lzma", set up decompressor without detection | ||
84 | // (lzma can't be detected). | ||
85 | |||
86 | setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1); | ||
87 | if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) | ||
88 | bb_error_msg_and_die("error unpacking"); | ||
89 | |||
90 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
91 | close(rpm_fd); | ||
92 | } | ||
93 | |||
94 | if (SEAMLESS_COMPRESSION) { | ||
95 | check_errors_in_children(0); | ||
96 | return bb_got_signal; | ||
97 | } | ||
98 | return EXIT_SUCCESS; | ||
99 | } | ||