aboutsummaryrefslogtreecommitdiff
path: root/archival/dpkg.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/dpkg.c')
-rw-r--r--archival/dpkg.c134
1 files changed, 15 insertions, 119 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2895f4f38..c911333e0 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -7,19 +7,7 @@
7 * 7 *
8 * Started life as a busybox implementation of udpkg 8 * Started life as a busybox implementation of udpkg
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */ 11 */
24 12
25/* 13/*
@@ -556,7 +544,7 @@ static unsigned int fill_package_struct(char *control_buffer)
556 "Conflicts", "Suggests", "Recommends", "Enhances", 0 544 "Conflicts", "Suggests", "Recommends", "Enhances", 0
557 }; 545 };
558 546
559 common_node_t *new_node = (common_node_t *) xcalloc(1, sizeof(common_node_t)); 547 common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
560 char *field_name; 548 char *field_name;
561 char *field_value; 549 char *field_value;
562 int field_start = 0; 550 int field_start = 0;
@@ -677,8 +665,7 @@ static void set_status(const unsigned int status_node_num, const char *new_value
677 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen"); 665 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
678 } 666 }
679 667
680 new_status = (char *) xmalloc(want_len + flag_len + status_len + 3); 668 new_status = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
681 sprintf(new_status, "%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
682 status_hashtable[status_node_num]->status = search_name_hashtable(new_status); 669 status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
683 free(new_status); 670 free(new_status);
684 return; 671 return;
@@ -741,79 +728,6 @@ static void index_status_file(const char *filename)
741 return; 728 return;
742} 729}
743 730
744#if 0 /* this code is no longer used */
745char *get_depends_field(common_node_t *package, const int depends_type)
746{
747 char *depends = NULL;
748 char *old_sep = (char *)xcalloc(1, 3);
749 char *new_sep = (char *)xcalloc(1, 3);
750 int line_size = 0;
751 int depends_size;
752
753 int i;
754
755 for (i = 0; i < package->num_of_edges; i++) {
756 if ((package->edge[i]->type == EDGE_OR_PRE_DEPENDS) ||
757 (package->edge[i]->type == EDGE_OR_DEPENDS)) {
758 }
759
760 if ((package->edge[i]->type == depends_type) ||
761 (package->edge[i]->type == depends_type + 1)) {
762 /* Check if its the first time through */
763
764 depends_size = 8 + strlen(name_hashtable[package->edge[i]->name])
765 + strlen(name_hashtable[package->edge[i]->version]);
766 line_size += depends_size;
767 depends = (char *) xrealloc(depends, line_size + 1);
768
769 /* Check to see if this dependency is the type we are looking for
770 * +1 to check for 'extra' types, e.g. ored dependecies */
771 strcpy(old_sep, new_sep);
772 if (package->edge[i]->type == depends_type) {
773 strcpy(new_sep, ", ");
774 }
775 else if (package->edge[i]->type == depends_type + 1) {
776 strcpy(new_sep, "| ");
777 }
778
779 if (depends_size == line_size) {
780 strcpy(depends, "");
781 } else {
782 if ((strcmp(old_sep, "| ") == 0) && (strcmp(new_sep, "| ") == 0)) {
783 strcat(depends, " | ");
784 } else {
785 strcat(depends, ", ");
786 }
787 }
788
789 strcat(depends, name_hashtable[package->edge[i]->name]);
790 if (strcmp(name_hashtable[package->edge[i]->version], "NULL") != 0) {
791 if (package->edge[i]->operator == VER_EQUAL) {
792 strcat(depends, " (= ");
793 }
794 else if (package->edge[i]->operator == VER_LESS) {
795 strcat(depends, " (<< ");
796 }
797 else if (package->edge[i]->operator == VER_LESS_EQUAL) {
798 strcat(depends, " (<= ");
799 }
800 else if (package->edge[i]->operator == VER_MORE) {
801 strcat(depends, " (>> ");
802 }
803 else if (package->edge[i]->operator == VER_MORE_EQUAL) {
804 strcat(depends, " (>= ");
805 } else {
806 strcat(depends, " (");
807 }
808 strcat(depends, name_hashtable[package->edge[i]->version]);
809 strcat(depends, ")");
810 }
811 }
812 }
813 return(depends);
814}
815#endif
816
817static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer) 731static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer)
818{ 732{
819 char *name; 733 char *name;
@@ -1027,11 +941,9 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1027 package_hashtable[package_num]->edge[j]->operator); 941 package_hashtable[package_num]->edge[j]->operator);
1028 if (package_hashtable[conflicts_package_num] == NULL) { 942 if (package_hashtable[conflicts_package_num] == NULL) {
1029 /* create a new package */ 943 /* create a new package */
1030 common_node_t *new_node = (common_node_t *) xmalloc(sizeof(common_node_t)); 944 common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
1031 new_node->name = package_hashtable[package_num]->edge[j]->name; 945 new_node->name = package_hashtable[package_num]->edge[j]->name;
1032 new_node->version = package_hashtable[package_num]->edge[j]->version; 946 new_node->version = package_hashtable[package_num]->edge[j]->version;
1033 new_node->num_of_edges = 0;
1034 new_node->edge = NULL;
1035 package_hashtable[conflicts_package_num] = new_node; 947 package_hashtable[conflicts_package_num] = new_node;
1036 } 948 }
1037 conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1)); 949 conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
@@ -1279,15 +1191,10 @@ static int run_package_script(const char *package_name, const char *script_type)
1279 char *script_path; 1191 char *script_path;
1280 int result; 1192 int result;
1281 1193
1282 script_path = xmalloc(strlen(package_name) + strlen(script_type) + 21); 1194 script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
1283 sprintf(script_path, "/var/lib/dpkg/info/%s.%s", package_name, script_type);
1284 1195
1285 /* If the file doesnt exist is isnt a fatal */ 1196 /* If the file doesnt exist is isnt a fatal */
1286 if (lstat(script_path, &path_stat) < 0) { 1197 result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
1287 result = EXIT_SUCCESS;
1288 } else {
1289 result = system(script_path);
1290 }
1291 free(script_path); 1198 free(script_path);
1292 return(result); 1199 return(result);
1293} 1200}
@@ -1301,13 +1208,11 @@ static char **all_control_list(const char *package_name)
1301 char **remove_files; 1208 char **remove_files;
1302 1209
1303 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1210 /* Create a list of all /var/lib/dpkg/info/<package> files */
1304 remove_files = xmalloc(sizeof(all_control_files)); 1211 remove_files = xzalloc(sizeof(all_control_files));
1305 while (all_control_files[i]) { 1212 while (all_control_files[i]) {
1306 remove_files[i] = xmalloc(strlen(package_name) + strlen(all_control_files[i]) + 21); 1213 remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
1307 sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
1308 i++; 1214 i++;
1309 } 1215 }
1310 remove_files[sizeof(all_control_files)/sizeof(char*) - 1] = NULL;
1311 1216
1312 return(remove_files); 1217 return(remove_files);
1313} 1218}
@@ -1400,11 +1305,9 @@ static void remove_package(const unsigned int package_num, int noisy)
1400 free_array(remove_files); 1305 free_array(remove_files);
1401 1306
1402 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */ 1307 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
1403 exclude_files = xmalloc(sizeof(char*) * 3); 1308 exclude_files = xzalloc(sizeof(char*) * 3);
1404 exclude_files[0] = bb_xstrdup(conffile_name); 1309 exclude_files[0] = bb_xstrdup(conffile_name);
1405 exclude_files[1] = xmalloc(package_name_length + 27); 1310 exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
1406 sprintf(exclude_files[1], "/var/lib/dpkg/info/%s.postrm", package_name);
1407 exclude_files[2] = NULL;
1408 1311
1409 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1312 /* Create a list of all /var/lib/dpkg/info/<package> files */
1410 remove_files = all_control_list(package_name); 1313 remove_files = all_control_list(package_name);
@@ -1440,8 +1343,7 @@ static void purge_package(const unsigned int package_num)
1440 sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name); 1343 sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
1441 remove_files = create_list(list_name); 1344 remove_files = create_list(list_name);
1442 1345
1443 exclude_files = xmalloc(sizeof(char*)); 1346 exclude_files = xzalloc(sizeof(char*));
1444 exclude_files[0] = NULL;
1445 1347
1446 /* Some directories cant be removed straight away, so do multiple passes */ 1348 /* Some directories cant be removed straight away, so do multiple passes */
1447 while (remove_file_array(remove_files, exclude_files)); 1349 while (remove_file_array(remove_files, exclude_files));
@@ -1536,9 +1438,7 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
1536 1438
1537 name_ptr += strspn(name_ptr, "./"); 1439 name_ptr += strspn(name_ptr, "./");
1538 if (name_ptr[0] != '\0') { 1440 if (name_ptr[0] != '\0') {
1539 archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 2 + strlen(name_ptr)); 1441 archive_handle->file_header->name = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr);
1540 strcpy(archive_handle->file_header->name, archive_handle->buffer);
1541 strcat(archive_handle->file_header->name, name_ptr);
1542 data_extract_all(archive_handle); 1442 data_extract_all(archive_handle);
1543 } 1443 }
1544 return; 1444 return;
@@ -1567,14 +1467,12 @@ static void unpack_package(deb_file_t *deb_file)
1567 } 1467 }
1568 1468
1569 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ 1469 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
1570 info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2); 1470 info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name);
1571 sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name);
1572 archive_handle = init_archive_deb_ar(deb_file->filename); 1471 archive_handle = init_archive_deb_ar(deb_file->filename);
1573 init_archive_deb_control(archive_handle); 1472 init_archive_deb_control(archive_handle);
1574 1473
1575 while(all_control_files[i]) { 1474 while(all_control_files[i]) {
1576 char *c = (char *) xmalloc(3 + strlen(all_control_files[i])); 1475 char *c = bb_xasprintf("./%s", all_control_files[i]);
1577 sprintf(c, "./%s", all_control_files[i]);
1578 llist_add_to(&accept_list, c); 1476 llist_add_to(&accept_list, c);
1579 i++; 1477 i++;
1580 } 1478 }
@@ -1699,7 +1597,7 @@ int dpkg_main(int argc, char **argv)
1699 while (optind < argc) { 1597 while (optind < argc) {
1700 /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */ 1598 /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
1701 deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2)); 1599 deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
1702 deb_file[deb_count] = (deb_file_t *) xmalloc(sizeof(deb_file_t)); 1600 deb_file[deb_count] = (deb_file_t *) xzalloc(sizeof(deb_file_t));
1703 if (dpkg_opt & dpkg_opt_filename) { 1601 if (dpkg_opt & dpkg_opt_filename) {
1704 archive_handle_t *archive_handle; 1602 archive_handle_t *archive_handle;
1705 llist_t *control_list = NULL; 1603 llist_t *control_list = NULL;
@@ -1742,8 +1640,6 @@ int dpkg_main(int argc, char **argv)
1742 } 1640 }
1743 } 1641 }
1744 else if (dpkg_opt & dpkg_opt_package_name) { 1642 else if (dpkg_opt & dpkg_opt_package_name) {
1745 deb_file[deb_count]->filename = NULL;
1746 deb_file[deb_count]->control_file = NULL;
1747 deb_file[deb_count]->package = search_package_hashtable( 1643 deb_file[deb_count]->package = search_package_hashtable(
1748 search_name_hashtable(argv[optind]), 1644 search_name_hashtable(argv[optind]),
1749 search_name_hashtable("ANY"), VER_ANY); 1645 search_name_hashtable("ANY"), VER_ANY);