diff options
Diffstat (limited to 'archival')
-rw-r--r-- | archival/ar.c | 88 | ||||
-rw-r--r-- | archival/dpkg.c | 25 | ||||
-rw-r--r-- | archival/dpkg_deb.c | 105 |
3 files changed, 98 insertions, 120 deletions
diff --git a/archival/ar.c b/archival/ar.c index 08cd5c501..7359f4910 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -30,36 +30,27 @@ | |||
30 | 30 | ||
31 | extern int ar_main(int argc, char **argv) | 31 | extern int ar_main(int argc, char **argv) |
32 | { | 32 | { |
33 | const int preserve_date = 1; /* preserve original dates */ | 33 | FILE *src_stream = NULL; |
34 | const int verbose = 2; /* be verbose */ | 34 | int extract_function = 0, opt = 0; |
35 | const int display = 4; /* display contents */ | 35 | file_headers_t *head; |
36 | const int extract_to_file = 8; /* extract contents of archive */ | 36 | file_headers_t *ar_extract_list = NULL; |
37 | const int extract_to_stdout = 16; /* extract to stdout */ | ||
38 | |||
39 | FILE *src_file = NULL, *dst_file = NULL; | ||
40 | int funct = 0, opt=0; | ||
41 | |||
42 | ar_headers_t *head, *ar_extract_list=NULL; | ||
43 | |||
44 | ar_extract_list = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); | ||
45 | head = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); | ||
46 | 37 | ||
47 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { | 38 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { |
48 | switch (opt) { | 39 | switch (opt) { |
49 | case 'o': | 40 | case 'o': |
50 | funct |= preserve_date; | 41 | extract_function |= extract_preserve_date; |
51 | break; | 42 | break; |
52 | case 'v': | 43 | case 'v': |
53 | funct |= verbose; | 44 | extract_function |= extract_verbose_list; |
54 | break; | 45 | break; |
55 | case 't': | 46 | case 't': |
56 | funct |= display; | 47 | extract_function |= extract_list; |
57 | break; | 48 | break; |
58 | case 'p': | 49 | case 'p': |
59 | funct |= extract_to_stdout; | 50 | extract_function |= extract_to_stdout; |
60 | break; | 51 | break; |
61 | case 'x': | 52 | case 'x': |
62 | funct |= extract_to_file; | 53 | extract_function |= extract_all_to_fs; |
63 | break; | 54 | break; |
64 | default: | 55 | default: |
65 | show_usage(); | 56 | show_usage(); |
@@ -71,57 +62,28 @@ extern int ar_main(int argc, char **argv) | |||
71 | show_usage(); | 62 | show_usage(); |
72 | } | 63 | } |
73 | 64 | ||
74 | if ( (src_file = wfopen(argv[optind], "r")) < 0) { | 65 | src_stream = xfopen(argv[optind++], "r"); |
75 | error_msg_and_die("Cannot read %s", argv[optind]); | 66 | head = get_ar_headers(src_stream); |
76 | } | ||
77 | 67 | ||
78 | optind++; | ||
79 | head = get_ar_headers(src_file); | ||
80 | /* find files to extract or display */ | 68 | /* find files to extract or display */ |
81 | /* search through argv and build extract list */ | 69 | /* search through argv and build extract list */ |
82 | for (;optind < argc; optind++) { | 70 | ar_extract_list = (file_headers_t *) xcalloc(1, sizeof(file_headers_t)); |
83 | ar_headers_t *ar_entry; | 71 | if (optind < argc) { |
84 | ar_entry = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); | 72 | while (optind < argc) { |
85 | ar_entry = head; | 73 | ar_extract_list = add_from_archive_list(head, ar_extract_list, argv[optind]); |
86 | while (ar_entry->next != NULL) { | 74 | optind++; |
87 | if (strcmp(argv[optind], ar_entry->name) == 0) { | ||
88 | ar_headers_t *tmp; | ||
89 | tmp = (ar_headers_t *) xmalloc(sizeof(ar_headers_t)); | ||
90 | *tmp = *ar_extract_list; | ||
91 | *ar_extract_list = *ar_entry; | ||
92 | ar_extract_list->next = tmp; | ||
93 | break; | ||
94 | } | ||
95 | ar_entry=ar_entry->next; | ||
96 | } | 75 | } |
97 | } | 76 | } else { |
98 | |||
99 | /* if individual files not found extract all files */ | ||
100 | if (ar_extract_list->next==NULL) { | ||
101 | ar_extract_list = head; | 77 | ar_extract_list = head; |
102 | } | 78 | } |
103 | 79 | ||
104 | /* find files to extract or display */ | 80 | /* If there isnt even one possible entry then abort */ |
105 | while (ar_extract_list->next != NULL) { | 81 | if (ar_extract_list->name == NULL) { |
106 | if (funct & extract_to_file) { | 82 | error_msg_and_die("No files to extract"); |
107 | dst_file = wfopen(ar_extract_list->name, "w"); | 83 | } |
108 | } | 84 | |
109 | else if (funct & extract_to_stdout) { | 85 | fseek(src_stream, 0, SEEK_SET); |
110 | dst_file = stdout; | 86 | extract_archive(src_stream, stdout, ar_extract_list, extract_function, "./"); |
111 | } | 87 | |
112 | if ((funct & extract_to_file) || (funct & extract_to_stdout)) { | ||
113 | fseek(src_file, ar_extract_list->offset, SEEK_SET); | ||
114 | copy_file_chunk(src_file, dst_file, ar_extract_list->size); | ||
115 | } | ||
116 | if (funct & verbose) { | ||
117 | printf("%s %d/%d %8d %s ", mode_string(ar_extract_list->mode), | ||
118 | ar_extract_list->uid, ar_extract_list->gid, | ||
119 | (int) ar_extract_list->size, time_string(ar_extract_list->mtime)); | ||
120 | } | ||
121 | if ((funct & display) || (funct & verbose)){ | ||
122 | puts(ar_extract_list->name); | ||
123 | } | ||
124 | ar_extract_list = ar_extract_list->next; | ||
125 | } | ||
126 | return EXIT_SUCCESS; | 88 | return EXIT_SUCCESS; |
127 | } | 89 | } |
diff --git a/archival/dpkg.c b/archival/dpkg.c index 0010df537..4224672ec 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -13,7 +13,6 @@ | |||
13 | 13 | ||
14 | #include "busybox.h" | 14 | #include "busybox.h" |
15 | 15 | ||
16 | |||
17 | #define DEPENDSMAX 64 /* maximum number of depends we can handle */ | 16 | #define DEPENDSMAX 64 /* maximum number of depends we can handle */ |
18 | 17 | ||
19 | /* Should we do full dependency checking? */ | 18 | /* Should we do full dependency checking? */ |
@@ -487,7 +486,7 @@ static void *status_read(void) | |||
487 | return(NULL); | 486 | return(NULL); |
488 | } | 487 | } |
489 | 488 | ||
490 | while ( (package_control_buffer = read_text_file_to_buffer(f)) != NULL) { | 489 | while ( (package_control_buffer = fgets_str(f, "\n\n")) != NULL) { |
491 | m = (package_t *)xcalloc(1, sizeof(package_t)); | 490 | m = (package_t *)xcalloc(1, sizeof(package_t)); |
492 | fill_package_struct(m, package_control_buffer); | 491 | fill_package_struct(m, package_control_buffer); |
493 | if (m->package) { | 492 | if (m->package) { |
@@ -650,24 +649,26 @@ static int dpkg_doconfigure(package_t *pkg) | |||
650 | 649 | ||
651 | static int dpkg_dounpack(package_t *pkg) | 650 | static int dpkg_dounpack(package_t *pkg) |
652 | { | 651 | { |
653 | int r = 0; | 652 | FILE *out_stream; |
653 | char *info_prefix; | ||
654 | int status = TRUE; | 654 | int status = TRUE; |
655 | char *lst_path; | 655 | int r = 0; |
656 | 656 | ||
657 | DPRINTF("Unpacking %s\n", pkg->package); | 657 | DPRINTF("Unpacking %s\n", pkg->package); |
658 | 658 | ||
659 | /* extract the data file */ | 659 | /* extract the data file */ |
660 | deb_extract(pkg->filename, extract_extract, "/", NULL); | 660 | deb_extract(pkg->filename, stdout, (extract_data_tar_gz | extract_all_to_fs), "/", NULL); |
661 | 661 | ||
662 | /* extract the control files */ | 662 | /* extract the control files */ |
663 | deb_extract(pkg->filename, extract_control, infodir, pkg->package); | 663 | info_prefix = (char *) malloc(strlen(pkg->package) + strlen(infodir) + 2 + 5 + 1); |
664 | sprintf(info_prefix, "%s/%s.", infodir, pkg->package); | ||
665 | deb_extract(pkg->package, stdout, (extract_control_tar_gz | extract_all_to_fs), info_prefix, NULL); | ||
664 | 666 | ||
665 | /* Create the list file */ | 667 | /* Create the list file */ |
666 | lst_path = xmalloc(strlen(infodir) + strlen(pkg->package) + 6); | 668 | strcat(info_prefix, "list"); |
667 | strcpy(lst_path, infodir); | 669 | out_stream = wfopen(info_prefix, "w"); |
668 | strcat(lst_path, pkg->package); | 670 | deb_extract(pkg->package, out_stream, (extract_data_tar_gz | extract_list), NULL, NULL); |
669 | strcat(lst_path, ".list"); | 671 | fclose(out_stream); |
670 | deb_extract(pkg->filename, extract_contents_to_file, lst_path, NULL); | ||
671 | 672 | ||
672 | pkg->state_want = state_want_install; | 673 | pkg->state_want = state_want_install; |
673 | pkg->state_flag = state_flag_ok; | 674 | pkg->state_flag = state_flag_ok; |
@@ -692,7 +693,7 @@ static int dpkg_read_control(package_t *pkg) | |||
692 | if ((pkg_file = wfopen(pkg->filename, "r")) == NULL) { | 693 | if ((pkg_file = wfopen(pkg->filename, "r")) == NULL) { |
693 | return EXIT_FAILURE; | 694 | return EXIT_FAILURE; |
694 | } | 695 | } |
695 | control_buffer = deb_extract(pkg->filename, extract_field, NULL, NULL); | 696 | control_buffer = deb_extract(pkg->filename, stdout, (extract_control_tar_gz | extract_one_to_buffer), NULL, "./control"); |
696 | fill_package_struct(pkg, control_buffer); | 697 | fill_package_struct(pkg, control_buffer); |
697 | return EXIT_SUCCESS; | 698 | return EXIT_SUCCESS; |
698 | } | 699 | } |
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 17b5476d0..400f2385a 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
@@ -21,33 +21,54 @@ | |||
21 | 21 | ||
22 | extern int dpkg_deb_main(int argc, char **argv) | 22 | extern int dpkg_deb_main(int argc, char **argv) |
23 | { | 23 | { |
24 | char *argument = NULL; | 24 | char *prefix = NULL; |
25 | char *filename = NULL; | ||
25 | char *output_buffer = NULL; | 26 | char *output_buffer = NULL; |
26 | int opt = 0; | 27 | int opt = 0; |
27 | int optflag = 0; | 28 | int arg_type = 0; |
29 | int deb_extract_funct = 0; | ||
28 | 30 | ||
31 | const int arg_type_prefix = 1; | ||
32 | const int arg_type_field = 2; | ||
33 | const int arg_type_filename = 4; | ||
34 | // const int arg_type_un_ar_gz = 8; | ||
35 | |||
29 | while ((opt = getopt(argc, argv, "ceftXxI")) != -1) { | 36 | while ((opt = getopt(argc, argv, "ceftXxI")) != -1) { |
30 | switch (opt) { | 37 | switch (opt) { |
31 | case 'c': | 38 | case 'c': |
32 | optflag |= extract_contents; | 39 | deb_extract_funct |= extract_data_tar_gz; |
40 | deb_extract_funct |= extract_verbose_list; | ||
33 | break; | 41 | break; |
34 | case 'e': | 42 | case 'e': |
35 | optflag |= extract_control; | 43 | arg_type = arg_type_prefix; |
44 | deb_extract_funct |= extract_control_tar_gz; | ||
45 | deb_extract_funct |= extract_all_to_fs; | ||
36 | break; | 46 | break; |
37 | case 'f': | 47 | case 'f': |
38 | optflag |= extract_field; | 48 | arg_type = arg_type_field; |
49 | deb_extract_funct |= extract_control_tar_gz; | ||
50 | deb_extract_funct |= extract_one_to_buffer; | ||
51 | filename = xstrdup("./control"); | ||
39 | break; | 52 | break; |
40 | case 't': | 53 | case 't': /* --fsys-tarfile, i just made up this short name */ |
41 | optflag |= extract_fsys_tarfile; | 54 | /* Integrate the functionality needed with some code from ar.c */ |
55 | error_msg_and_die("Option disabled"); | ||
56 | // arg_type = arg_type_un_ar_gz; | ||
42 | break; | 57 | break; |
43 | case 'X': | 58 | case 'X': |
44 | optflag |= extract_verbose_extract; | 59 | arg_type = arg_type_prefix; |
45 | break; | 60 | deb_extract_funct |= extract_data_tar_gz; |
61 | deb_extract_funct |= extract_all_to_fs; | ||
62 | deb_extract_funct |= extract_list; | ||
46 | case 'x': | 63 | case 'x': |
47 | optflag |= extract_extract; | 64 | arg_type = arg_type_prefix; |
65 | deb_extract_funct |= extract_data_tar_gz; | ||
66 | deb_extract_funct |= extract_all_to_fs; | ||
48 | break; | 67 | break; |
49 | case 'I': | 68 | case 'I': |
50 | optflag |= extract_info; | 69 | arg_type = arg_type_filename; |
70 | deb_extract_funct |= extract_control_tar_gz; | ||
71 | deb_extract_funct |= extract_one_to_buffer; | ||
51 | break; | 72 | break; |
52 | default: | 73 | default: |
53 | show_usage(); | 74 | show_usage(); |
@@ -58,48 +79,42 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
58 | show_usage(); | 79 | show_usage(); |
59 | } | 80 | } |
60 | 81 | ||
61 | switch (optflag) { | 82 | /* Workout where to extract the files */ |
62 | case (extract_control): | 83 | if (arg_type == arg_type_prefix) { |
63 | case (extract_extract): | 84 | /* argument is a dir name */ |
64 | case (extract_verbose_extract): | 85 | if ((optind + 1) == argc ) { |
65 | /* argument is a dir name */ | 86 | prefix = xstrdup("./DEBIAN/"); |
66 | if ( (optind + 1) == argc ) { | 87 | } else { |
67 | argument = xstrdup("DEBIAN"); | 88 | prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2); |
68 | } else { | 89 | strcpy(prefix, argv[optind + 1]); |
69 | argument = xstrdup(argv[optind + 1]); | 90 | /* Make sure the directory has a trailing '/' */ |
70 | } | 91 | if (last_char_is(prefix, '/') == NULL) { |
71 | break; | 92 | strcat(prefix, "/"); |
72 | case (extract_field): | ||
73 | /* argument is a control field name */ | ||
74 | if ((optind + 1) != argc) { | ||
75 | argument = xstrdup(argv[optind + 1]); | ||
76 | } | ||
77 | break; | ||
78 | case (extract_info): | ||
79 | /* argument is a control field name */ | ||
80 | if ((optind + 1) != argc) { | ||
81 | argument = xstrdup(argv[optind + 1]); | ||
82 | break; | ||
83 | } else { | ||
84 | error_msg("-I currently requires a filename to be specifies"); | ||
85 | return(EXIT_FAILURE); | ||
86 | } | 93 | } |
87 | /* argument is a filename */ | 94 | } |
88 | default: | ||
89 | } | 95 | } |
90 | 96 | ||
91 | output_buffer = deb_extract(argv[optind], optflag, argument, NULL); | 97 | if (arg_type == arg_type_filename) { |
98 | if ((optind + 1) != argc) { | ||
99 | filename = xstrdup(argv[optind + 1]); | ||
100 | } else { | ||
101 | error_msg_and_die("-I currently requires a filename to be specified"); | ||
102 | } | ||
103 | } | ||
92 | 104 | ||
93 | if (optflag & extract_field) { | 105 | output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename); |
106 | |||
107 | if ((arg_type == arg_type_filename) && (output_buffer != NULL)) { | ||
108 | puts(output_buffer); | ||
109 | } | ||
110 | else if (arg_type == arg_type_field) { | ||
94 | char *field = NULL; | 111 | char *field = NULL; |
95 | int field_length = 0; | ||
96 | int field_start = 0; | 112 | int field_start = 0; |
97 | 113 | ||
98 | while ((field = read_package_field(&output_buffer[field_start])) != NULL) { | 114 | while ((field = read_package_field(&output_buffer[field_start])) != NULL) { |
99 | field_length = strlen(field); | 115 | field_start += (strlen(field) + 1); |
100 | field_start += (field_length + 1); | 116 | if (strstr(field, argv[optind + 1]) == field) { |
101 | if (strstr(field, argument) == field) { | 117 | puts(field + strlen(argv[optind + 1]) + 2); |
102 | puts(field + strlen(argument) + 2); | ||
103 | } | 118 | } |
104 | free(field); | 119 | free(field); |
105 | } | 120 | } |