aboutsummaryrefslogtreecommitdiff
path: root/archival/rpm2cpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/rpm2cpio.c')
-rw-r--r--archival/rpm2cpio.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 22051dabf..e1e93988f 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -18,10 +18,13 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21#include <sys/types.h>
22#include "busybox.h"
23#include <netinet/in.h> /* For ntohl & htonl function */ 22#include <netinet/in.h> /* For ntohl & htonl function */
23#include <fcntl.h>
24#include <unistd.h>
24#include <string.h> 25#include <string.h>
26#include "busybox.h"
27#include "unarchive.h"
25 28
26#define RPM_MAGIC "\355\253\356\333" 29#define RPM_MAGIC "\355\253\356\333"
27#define RPM_HEADER_MAGIC "\216\255\350" 30#define RPM_HEADER_MAGIC "\216\255\350"
@@ -45,46 +48,54 @@ struct rpm_header {
45 u_int32_t size; /* Size of store (4 bytes) */ 48 u_int32_t size; /* Size of store (4 bytes) */
46}; 49};
47 50
48void skip_header(FILE *rpmfile) 51void skip_header(int rpm_fd)
49{ 52{
50 struct rpm_header header; 53 struct rpm_header header;
51 54
52 fread(&header, sizeof(struct rpm_header), 1, rpmfile); 55 xread_all(rpm_fd, &header, sizeof(struct rpm_header));
53 if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */ 56 if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
54 if (header.version != 1) error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */ 57 error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
58 }
59 if (header.version != 1) {
60 error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
61 }
55 header.entries = ntohl(header.entries); 62 header.entries = ntohl(header.entries);
56 header.size = ntohl(header.size); 63 header.size = ntohl(header.size);
57 fseek (rpmfile, 16 * header.entries, SEEK_CUR); /* Seek past index entries */ 64 lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
58 fseek (rpmfile, header.size, SEEK_CUR); /* Seek past store */ 65 lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
59} 66}
60 67
61/* No getopt required */ 68/* No getopt required */
62extern int rpm2cpio_main(int argc, char **argv) 69extern int rpm2cpio_main(int argc, char **argv)
63{ 70{
64 struct rpm_lead lead; 71 struct rpm_lead lead;
65 int gunzip_pid; 72 int rpm_fd;
66 FILE *rpmfile, *cpiofile;
67 73
68 if (argc == 1) { 74 if (argc == 1) {
69 rpmfile = stdin; 75 rpm_fd = fileno(stdin);
70 } else { 76 } else {
71 rpmfile = xfopen(argv[1], "r"); 77 rpm_fd = xopen(argv[1], O_RDONLY);
72 /* set the buffer size */ 78 }
73 setvbuf(rpmfile, NULL, _IOFBF, 0x8000); 79
80 xread_all(rpm_fd, &lead, sizeof(struct rpm_lead));
81 if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
82 error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
74 } 83 }
75 84
76 fread (&lead, sizeof(struct rpm_lead), 1, rpmfile);
77 if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
78 /* Skip the signature header */ 85 /* Skip the signature header */
79 skip_header(rpmfile); 86 skip_header(rpm_fd);
80 fseek(rpmfile, (8 - (ftell(rpmfile) % 8)) % 8, SEEK_CUR); /* Pad to 8 byte boundary */ 87 data_align(rpm_fd, lseek(rpm_fd, 0, SEEK_CUR), 8);
88
81 /* Skip the main header */ 89 /* Skip the main header */
82 skip_header(rpmfile); 90 skip_header(rpm_fd);
91
92 check_header_gzip(rpm_fd);
93 if (inflate(rpm_fd, fileno(stdout)) != 0) {
94 error_msg("Error inflating");
95 }
96 check_trailer_gzip(rpm_fd);
83 97
84 cpiofile = gz_open(rpmfile, &gunzip_pid); 98 close(rpm_fd);
85 99
86 copyfd(fileno(cpiofile), fileno(stdout));
87 gz_close(gunzip_pid);
88 fclose(rpmfile);
89 return 0; 100 return 0;
90} 101}