extern int dpkg_deb_main(int argc, char **argv)
{
- char *target_dir;
+ char *argument = NULL;
int opt = 0;
int optflag = 0;
- while ((opt = getopt(argc, argv, "cetXxl")) != -1) {
+ while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
switch (opt) {
case 'c':
optflag |= extract_contents;
case 'e':
optflag |= extract_control;
break;
+ case 'f':
+ optflag |= extract_field;
+ break;
case 't':
optflag |= extract_fsys_tarfile;
break;
case 'x':
optflag |= extract_extract;
break;
- case 'l':
- optflag |= extract_list;
- break;
-/* case 'I':
+ case 'I':
optflag |= extract_info;
break;
-*/
default:
show_usage();
}
case (extract_control):
case (extract_extract):
case (extract_verbose_extract):
+ /* argument is a dir name */
if ( (optind + 1) == argc ) {
- target_dir = (char *) xmalloc(7);
- strcpy(target_dir, "DEBIAN");
+ argument = xstrdup("DEBIAN");
} else {
- target_dir = (char *) xmalloc(strlen(argv[optind + 1]) + 1);
- strcpy(target_dir, argv[optind + 1]);
+ argument = xstrdup(argv[optind + 1]);
}
break;
+ case (extract_field):
+ /* argument is a control field name */
+ if ((optind + 1) != argc) {
+ argument = xstrdup(argv[optind + 1]);
+ }
+ break;
+ case (extract_info):
+ /* argument is a control field name */
+ if ((optind + 1) != argc) {
+ argument = xstrdup(argv[optind + 1]);
+ break;
+ } else {
+ error_msg("-I currently requires a filename to be specifies");
+ return(EXIT_FAILURE);
+ }
+ /* argument is a filename */
default:
- target_dir = NULL;
}
- deb_extract(argv[optind], optflag, target_dir);
-/* else if (optflag & dpkg_deb_info) {
- extract_flag = TRUE;
- extract_to_stdout = TRUE;
- strcpy(ar_filename, "control.tar.gz");
- extract_list = argv+optind+1;
- printf("list one is [%s]\n",extract_list[0]);
- }
-*/
+ deb_extract(argv[optind], optflag, argument);
+
return(EXIT_SUCCESS);
}
extern int dpkg_deb_main(int argc, char **argv)
{
- char *target_dir;
+ char *argument = NULL;
int opt = 0;
int optflag = 0;
- while ((opt = getopt(argc, argv, "cetXxl")) != -1) {
+ while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
switch (opt) {
case 'c':
optflag |= extract_contents;
case 'e':
optflag |= extract_control;
break;
+ case 'f':
+ optflag |= extract_field;
+ break;
case 't':
optflag |= extract_fsys_tarfile;
break;
case 'x':
optflag |= extract_extract;
break;
- case 'l':
- optflag |= extract_list;
- break;
-/* case 'I':
+ case 'I':
optflag |= extract_info;
break;
-*/
default:
show_usage();
}
case (extract_control):
case (extract_extract):
case (extract_verbose_extract):
+ /* argument is a dir name */
if ( (optind + 1) == argc ) {
- target_dir = (char *) xmalloc(7);
- strcpy(target_dir, "DEBIAN");
+ argument = xstrdup("DEBIAN");
} else {
- target_dir = (char *) xmalloc(strlen(argv[optind + 1]) + 1);
- strcpy(target_dir, argv[optind + 1]);
+ argument = xstrdup(argv[optind + 1]);
}
break;
+ case (extract_field):
+ /* argument is a control field name */
+ if ((optind + 1) != argc) {
+ argument = xstrdup(argv[optind + 1]);
+ }
+ break;
+ case (extract_info):
+ /* argument is a control field name */
+ if ((optind + 1) != argc) {
+ argument = xstrdup(argv[optind + 1]);
+ break;
+ } else {
+ error_msg("-I currently requires a filename to be specifies");
+ return(EXIT_FAILURE);
+ }
+ /* argument is a filename */
default:
- target_dir = NULL;
}
- deb_extract(argv[optind], optflag, target_dir);
-/* else if (optflag & dpkg_deb_info) {
- extract_flag = TRUE;
- extract_to_stdout = TRUE;
- strcpy(ar_filename, "control.tar.gz");
- extract_list = argv+optind+1;
- printf("list one is [%s]\n",extract_list[0]);
- }
-*/
+ deb_extract(argv[optind], optflag, argument);
+
return(EXIT_SUCCESS);
}
extract_extract = 8,
extract_verbose_extract = 16,
extract_list = 32,
- extract_fsys_tarfile = 64
+ extract_fsys_tarfile = 64,
+ extract_field = 128
} extract_function_t;
extern int deb_extract(const char *package_filename, int function, char *target_dir);
-extern int untar(FILE *src_tar_file, int untar_function, char *base_path);
+extern int untar(FILE *src_tar_file, const int untar_function, const char *argument);
extern int unzip(FILE *l_in_file, FILE *l_out_file);
extern void gz_close(int gunzip_pid);
#include <signal.h>
#include "libbb.h"
-extern int deb_extract(const char *package_filename, int function, char *target_dir)
+/*
+ * The contents of argument depend on the value of function.
+ * It is either a dir name or a control file or field name(see dpkg_deb.c)
+ */
+extern int deb_extract(const char *package_filename, int function, char *argument)
{
FILE *deb_file, *uncompressed_file;
switch (function) {
case (extract_info):
case (extract_control):
+ case (extract_field):
ared_file = xstrdup("control.tar.gz");
break;
default:
if (function & extract_fsys_tarfile) {
copy_file_chunk(uncompressed_file, stdout, -1);
} else {
- untar(uncompressed_file, function, target_dir);
+ untar(uncompressed_file, function, argument);
}
/* we are deliberately terminating the child so we can safely ignore this */
gz_close(gunzip_pid);
extract_extract = 8,
extract_verbose_extract = 16,
extract_list = 32,
- extract_fsys_tarfile = 64
+ extract_fsys_tarfile = 64,
+ extract_field = 128
} extract_function_t;
extern int deb_extract(const char *package_filename, int function, char *target_dir);
-extern int untar(FILE *src_tar_file, int untar_function, char *base_path);
+extern int untar(FILE *src_tar_file, const int untar_function, const char *argument);
extern int unzip(FILE *l_in_file, FILE *l_out_file);
extern void gz_close(int gunzip_pid);
#include <unistd.h>
#include "libbb.h"
-extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
+extern int untar(FILE *src_tar_file, const int untar_function, const char *argument)
{
typedef struct raw_tar_header {
char name[100]; /* 0-99 */
if (size % 512 != 0) {
next_header_offset += (512 - size % 512);
}
- /*
- * seek to start of control file, return length
- *
- if (dpkg_untar_function & dpkg_untar_seek_control) {
- if ((raw_tar_header.typeflag == '0') || (raw_tar_header.typeflag == '\0')) {
- char *tar_filename;
-
- tar_filename = strrchr(raw_tar_header.name, '/');
- if (tar_filename == NULL) {
- tar_filename = strdup(raw_tar_header.name);
- } else {
- tar_filename++;
- }
-
- if (strcmp(tar_filename, "control") == 0) {
- return(size);
- }
- }
- }
-*/
if (untar_function & (extract_contents | extract_verbose_extract)) {
printf("%s\n", raw_tar_header.name);
}
/* extract files */
- if (base_path != NULL) {
- dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2);
- sprintf(dir, "%s/%s", base_path, raw_tar_header.name);
+ if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) {
+ dir = xmalloc(strlen(raw_tar_header.name) + strlen(argument) + 2);
+ sprintf(dir, "%s/%s", argument, raw_tar_header.name);
create_path(dir, 0777);
}
+
switch (raw_tar_header.typeflag ) {
case '0':
case '\0':
uncompressed_count += size;
fclose(dst_file);
}
- while (uncompressed_count < next_header_offset) {
- if (fgetc(src_tar_file) == EOF) {
- perror_msg("untar");
- break;
+ else if (untar_function & extract_info) {
+ if (strstr(raw_tar_header.name, argument) != NULL) {
+ copy_file_chunk(src_tar_file, stdout, (unsigned long long) size);
+ uncompressed_count += size;
+ }
+ }
+ else if (untar_function & extract_field) {
+ if (strstr(raw_tar_header.name, "./control") != NULL) {
+ char *line;
+ while ((line = get_line_from_file(src_tar_file)) != NULL) {
+ uncompressed_count += strlen(line);
+ if (argument == NULL) {
+ printf("%s",line);
+ }
+ else if (strncmp(line, argument, strlen(argument)) == 0) {
+ char *file_ptr;
+ file_ptr = strstr(line, ": ");
+ printf("%s", file_ptr + 2);
+ }
+ }
}
- uncompressed_count++;
}
- uncompressed_count += size;
break;
}
case '5':
free(dir);
return(EXIT_FAILURE);
}
+
+ /*
+ * Seek to start of next block, cant use fseek as unzip() does support it
+ */
+ while (uncompressed_count < next_header_offset) {
+ if (fgetc(src_tar_file) == EOF) {
+ break;
+ }
+ uncompressed_count++;
+ }
+
// free(dir);
}
return(EXIT_SUCCESS);