mirror of
https://github.com/sheumann/hush.git
synced 2025-01-18 07:31:34 +00:00
unarchive function changed to support both exclude and include lists, applets that use unarchive changed to match.
This commit is contained in:
parent
051eee6ed3
commit
4bef7b4186
2
ar.c
2
ar.c
@ -84,6 +84,6 @@ extern int ar_main(int argc, char **argv)
|
|||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names);
|
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names, NULL);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,6 @@ extern int ar_main(int argc, char **argv)
|
|||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names);
|
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names, NULL);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ extern int cpio_main(int argc, char **argv)
|
|||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names, NULL);
|
||||||
if (oldmask) {
|
if (oldmask) {
|
||||||
umask(oldmask); /* Restore umask if we changed it */
|
umask(oldmask); /* Restore umask if we changed it */
|
||||||
}
|
}
|
||||||
|
@ -580,15 +580,10 @@ int tar_main(int argc, char **argv)
|
|||||||
untar_extract = 32
|
untar_extract = 32
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
|
||||||
char **exclude_list = NULL;
|
|
||||||
int exclude_list_count = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FILE *src_stream = NULL;
|
FILE *src_stream = NULL;
|
||||||
FILE *uncompressed_stream = NULL;
|
FILE *uncompressed_stream = NULL;
|
||||||
char **include_list = NULL;
|
char **include_list = NULL;
|
||||||
char **the_real_list = NULL;
|
char **exclude_list = NULL;
|
||||||
char *src_filename = NULL;
|
char *src_filename = NULL;
|
||||||
char *dst_prefix = NULL;
|
char *dst_prefix = NULL;
|
||||||
char *file_list_name = NULL;
|
char *file_list_name = NULL;
|
||||||
@ -597,6 +592,7 @@ int tar_main(int argc, char **argv)
|
|||||||
unsigned short untar_funct_required = 0;
|
unsigned short untar_funct_required = 0;
|
||||||
unsigned short extract_function = 0;
|
unsigned short extract_function = 0;
|
||||||
int include_list_count = 0;
|
int include_list_count = 0;
|
||||||
|
int exclude_list_count = 0;
|
||||||
int gunzip_pid;
|
int gunzip_pid;
|
||||||
int gz_fd = 0;
|
int gz_fd = 0;
|
||||||
|
|
||||||
@ -691,25 +687,6 @@ int tar_main(int argc, char **argv)
|
|||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By default the include list is the list we act on */
|
|
||||||
the_real_list = include_list;
|
|
||||||
|
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
|
||||||
if (exclude_list != NULL) {
|
|
||||||
if (include_list == NULL) {
|
|
||||||
/* the_real_list is an exclude list */
|
|
||||||
extract_function |= extract_exclude_list;
|
|
||||||
the_real_list = exclude_list;
|
|
||||||
} else {
|
|
||||||
/* Both an exclude and include file list was present,
|
|
||||||
* its an exclude from include list only.
|
|
||||||
* Remove excluded files from the include list
|
|
||||||
*/
|
|
||||||
the_real_list = list_and_not_list(include_list, exclude_list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (extract_function & (extract_list | extract_all_to_fs)) {
|
if (extract_function & (extract_list | extract_all_to_fs)) {
|
||||||
if (dst_prefix == NULL) {
|
if (dst_prefix == NULL) {
|
||||||
dst_prefix = xstrdup("./");
|
dst_prefix = xstrdup("./");
|
||||||
@ -730,7 +707,7 @@ int tar_main(int argc, char **argv)
|
|||||||
uncompressed_stream = src_stream;
|
uncompressed_stream = src_stream;
|
||||||
|
|
||||||
/* extract or list archive */
|
/* extract or list archive */
|
||||||
unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, the_real_list);
|
unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, include_list, exclude_list);
|
||||||
fclose(uncompressed_stream);
|
fclose(uncompressed_stream);
|
||||||
}
|
}
|
||||||
#ifdef BB_FEATURE_TAR_CREATE
|
#ifdef BB_FEATURE_TAR_CREATE
|
||||||
@ -746,7 +723,7 @@ int tar_main(int argc, char **argv)
|
|||||||
if (extract_function & extract_verbose_list) {
|
if (extract_function & extract_verbose_list) {
|
||||||
verboseFlag = TRUE;
|
verboseFlag = TRUE;
|
||||||
}
|
}
|
||||||
writeTarFile(src_filename, verboseFlag, &argv[argc - 1], the_real_list);
|
writeTarFile(src_filename, verboseFlag, &argv[argc - 1], include_list);
|
||||||
}
|
}
|
||||||
#endif // BB_FEATURE_TAR_CREATE
|
#endif // BB_FEATURE_TAR_CREATE
|
||||||
|
|
||||||
|
2
cpio.c
2
cpio.c
@ -86,7 +86,7 @@ extern int cpio_main(int argc, char **argv)
|
|||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names, NULL);
|
||||||
if (oldmask) {
|
if (oldmask) {
|
||||||
umask(oldmask); /* Restore umask if we changed it */
|
umask(oldmask); /* Restore umask if we changed it */
|
||||||
}
|
}
|
||||||
|
@ -245,8 +245,8 @@ enum extract_functions_e {
|
|||||||
extract_quiet = 2048,
|
extract_quiet = 2048,
|
||||||
extract_exclude_list = 4096
|
extract_exclude_list = 4096
|
||||||
};
|
};
|
||||||
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_header)(FILE *),
|
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
|
||||||
const int extract_function, const char *prefix, char **extract_names);
|
const int extract_function, const char *prefix, char **include_name, char **exclude_name);
|
||||||
char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
|
char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
|
||||||
const char *prefix, const char *filename);
|
const char *prefix, const char *filename);
|
||||||
int read_package_field(const char *package_buffer, char **field_name, char **field_value);
|
int read_package_field(const char *package_buffer, char **field_name, char **field_value);
|
||||||
|
@ -245,8 +245,8 @@ enum extract_functions_e {
|
|||||||
extract_quiet = 2048,
|
extract_quiet = 2048,
|
||||||
extract_exclude_list = 4096
|
extract_exclude_list = 4096
|
||||||
};
|
};
|
||||||
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_header)(FILE *),
|
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
|
||||||
const int extract_function, const char *prefix, char **extract_names);
|
const int extract_function, const char *prefix, char **include_name, char **exclude_name);
|
||||||
char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
|
char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
|
||||||
const char *prefix, const char *filename);
|
const char *prefix, const char *filename);
|
||||||
int read_package_field(const char *package_buffer, char **field_name, char **field_value);
|
int read_package_field(const char *package_buffer, char **field_name, char **field_value);
|
||||||
|
@ -230,35 +230,36 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
|
|||||||
|
|
||||||
#ifdef L_unarchive
|
#ifdef L_unarchive
|
||||||
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
|
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
|
||||||
const int extract_function, const char *prefix, char **extract_names)
|
const int extract_function, const char *prefix, char **include_name, char **exclude_name)
|
||||||
{
|
{
|
||||||
file_header_t *file_entry;
|
file_header_t *file_entry;
|
||||||
int extract_flag;
|
int extract_flag = TRUE;
|
||||||
int i;
|
int i;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
|
|
||||||
archive_offset = 0;
|
archive_offset = 0;
|
||||||
while ((file_entry = get_headers(src_stream)) != NULL) {
|
while ((file_entry = get_headers(src_stream)) != NULL) {
|
||||||
extract_flag = TRUE;
|
|
||||||
if (extract_names != NULL) {
|
if (include_name != NULL) {
|
||||||
int found_flag = FALSE;
|
extract_flag = FALSE;
|
||||||
for(i = 0; extract_names[i] != 0; i++) {
|
for(i = 0; include_name[i] != 0; i++) {
|
||||||
if (fnmatch(extract_names[i], file_entry->name, FNM_LEADING_DIR) == 0) {
|
if (fnmatch(include_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
|
||||||
found_flag = TRUE;
|
extract_flag = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (extract_function & extract_exclude_list) {
|
} else {
|
||||||
if (found_flag == TRUE) {
|
extract_flag = TRUE;
|
||||||
extract_flag = FALSE;
|
}
|
||||||
}
|
|
||||||
} else {
|
/* If the file entry is in the exclude list dont extract it */
|
||||||
/* If its not found in the include list dont extract it */
|
if (exclude_name != NULL) {
|
||||||
if (found_flag == FALSE) {
|
for(i = 0; exclude_name[i] != 0; i++) {
|
||||||
|
if (fnmatch(exclude_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
|
||||||
extract_flag = FALSE;
|
extract_flag = FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extract_flag == TRUE) {
|
if (extract_flag == TRUE) {
|
||||||
@ -607,7 +608,7 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
|
|||||||
/* open a stream of decompressed data */
|
/* open a stream of decompressed data */
|
||||||
uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
|
uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
|
||||||
archive_offset = 0;
|
archive_offset = 0;
|
||||||
output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list);
|
output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list, NULL);
|
||||||
}
|
}
|
||||||
seek_sub_file(deb_stream, ar_header->size);
|
seek_sub_file(deb_stream, ar_header->size);
|
||||||
free(ar_header->name);
|
free(ar_header->name);
|
||||||
|
31
tar.c
31
tar.c
@ -580,15 +580,10 @@ int tar_main(int argc, char **argv)
|
|||||||
untar_extract = 32
|
untar_extract = 32
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
|
||||||
char **exclude_list = NULL;
|
|
||||||
int exclude_list_count = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FILE *src_stream = NULL;
|
FILE *src_stream = NULL;
|
||||||
FILE *uncompressed_stream = NULL;
|
FILE *uncompressed_stream = NULL;
|
||||||
char **include_list = NULL;
|
char **include_list = NULL;
|
||||||
char **the_real_list = NULL;
|
char **exclude_list = NULL;
|
||||||
char *src_filename = NULL;
|
char *src_filename = NULL;
|
||||||
char *dst_prefix = NULL;
|
char *dst_prefix = NULL;
|
||||||
char *file_list_name = NULL;
|
char *file_list_name = NULL;
|
||||||
@ -597,6 +592,7 @@ int tar_main(int argc, char **argv)
|
|||||||
unsigned short untar_funct_required = 0;
|
unsigned short untar_funct_required = 0;
|
||||||
unsigned short extract_function = 0;
|
unsigned short extract_function = 0;
|
||||||
int include_list_count = 0;
|
int include_list_count = 0;
|
||||||
|
int exclude_list_count = 0;
|
||||||
int gunzip_pid;
|
int gunzip_pid;
|
||||||
int gz_fd = 0;
|
int gz_fd = 0;
|
||||||
|
|
||||||
@ -691,25 +687,6 @@ int tar_main(int argc, char **argv)
|
|||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By default the include list is the list we act on */
|
|
||||||
the_real_list = include_list;
|
|
||||||
|
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
|
||||||
if (exclude_list != NULL) {
|
|
||||||
if (include_list == NULL) {
|
|
||||||
/* the_real_list is an exclude list */
|
|
||||||
extract_function |= extract_exclude_list;
|
|
||||||
the_real_list = exclude_list;
|
|
||||||
} else {
|
|
||||||
/* Both an exclude and include file list was present,
|
|
||||||
* its an exclude from include list only.
|
|
||||||
* Remove excluded files from the include list
|
|
||||||
*/
|
|
||||||
the_real_list = list_and_not_list(include_list, exclude_list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (extract_function & (extract_list | extract_all_to_fs)) {
|
if (extract_function & (extract_list | extract_all_to_fs)) {
|
||||||
if (dst_prefix == NULL) {
|
if (dst_prefix == NULL) {
|
||||||
dst_prefix = xstrdup("./");
|
dst_prefix = xstrdup("./");
|
||||||
@ -730,7 +707,7 @@ int tar_main(int argc, char **argv)
|
|||||||
uncompressed_stream = src_stream;
|
uncompressed_stream = src_stream;
|
||||||
|
|
||||||
/* extract or list archive */
|
/* extract or list archive */
|
||||||
unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, the_real_list);
|
unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, include_list, exclude_list);
|
||||||
fclose(uncompressed_stream);
|
fclose(uncompressed_stream);
|
||||||
}
|
}
|
||||||
#ifdef BB_FEATURE_TAR_CREATE
|
#ifdef BB_FEATURE_TAR_CREATE
|
||||||
@ -746,7 +723,7 @@ int tar_main(int argc, char **argv)
|
|||||||
if (extract_function & extract_verbose_list) {
|
if (extract_function & extract_verbose_list) {
|
||||||
verboseFlag = TRUE;
|
verboseFlag = TRUE;
|
||||||
}
|
}
|
||||||
writeTarFile(src_filename, verboseFlag, &argv[argc - 1], the_real_list);
|
writeTarFile(src_filename, verboseFlag, &argv[argc - 1], include_list);
|
||||||
}
|
}
|
||||||
#endif // BB_FEATURE_TAR_CREATE
|
#endif // BB_FEATURE_TAR_CREATE
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user