2015-10-09 13:20:18 +02:00
|
|
|
|
Index: cpio-2.12/src/copyin.c
|
2014-07-29 13:44:14 +02:00
|
|
|
|
===================================================================
|
2015-10-09 13:20:18 +02:00
|
|
|
|
--- cpio-2.12.orig/src/copyin.c
|
|
|
|
|
+++ cpio-2.12/src/copyin.c
|
|
|
|
|
@@ -695,6 +695,51 @@ copyin_link (struct cpio_file_stat *file
|
2014-07-29 13:44:14 +02:00
|
|
|
|
free (link_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+static int
|
|
|
|
|
+path_contains_symlink(char *path)
|
|
|
|
|
+{
|
|
|
|
|
+ struct stat st;
|
|
|
|
|
+ char *slash;
|
|
|
|
|
+ char *nextslash;
|
|
|
|
|
+
|
|
|
|
|
+ /* we got NULL pointer or empty string */
|
|
|
|
|
+ if (!path || !*path) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ slash = path;
|
|
|
|
|
+
|
|
|
|
|
+ while ((nextslash = strchr(slash + 1, '/')) != NULL) {
|
|
|
|
|
+ slash = nextslash;
|
|
|
|
|
+ *slash = '\0';
|
|
|
|
|
+
|
|
|
|
|
+ if (lstat(path, &st) != 0) {
|
|
|
|
|
+ if (errno == ELOOP) {
|
|
|
|
|
+ /* ELOOP - too many symlinks */
|
|
|
|
|
+ *slash = '/';
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else if (errno == ENOMEM) {
|
|
|
|
|
+ /* No memory for lstat - terminate */
|
|
|
|
|
+ xalloc_die();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ /* cannot lstat path - give up */
|
|
|
|
|
+ *slash = '/';
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (S_ISLNK(st.st_mode)) {
|
|
|
|
|
+ *slash = '/';
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ *slash = '/';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
static void
|
|
|
|
|
copyin_file (struct cpio_file_stat *file_hdr, int in_file_des)
|
|
|
|
|
{
|
2015-10-09 13:20:18 +02:00
|
|
|
|
@@ -1474,6 +1519,23 @@ process_copy_in ()
|
2014-07-29 13:44:14 +02:00
|
|
|
|
{
|
|
|
|
|
/* Copy the input file into the directory structure. */
|
|
|
|
|
|
|
|
|
|
+ /* Can we write files over symlinks? */
|
|
|
|
|
+ if (!extract_over_symlinks)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (path_contains_symlink(file_hdr.c_name))
|
|
|
|
|
+ {
|
|
|
|
|
+ /* skip the file */
|
|
|
|
|
+ /*
|
|
|
|
|
+ fprintf(stderr, "Can't write over symlinks. Skipping %s\n", file_hdr.c_name);
|
|
|
|
|
+ tape_toss_input (in_file_des, file_hdr.c_filesize);
|
|
|
|
|
+ tape_skip_padding (in_file_des, file_hdr.c_filesize);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ */
|
|
|
|
|
+ /* terminate */
|
|
|
|
|
+ error (1, 0, _("Can't write over symlinks: %s\n"), file_hdr.c_name);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
/* Do we need to rename the file? */
|
|
|
|
|
if (rename_flag || rename_batch_file)
|
|
|
|
|
{
|
2015-10-09 13:20:18 +02:00
|
|
|
|
Index: cpio-2.12/src/global.c
|
2014-07-29 13:44:14 +02:00
|
|
|
|
===================================================================
|
2015-10-09 13:20:18 +02:00
|
|
|
|
--- cpio-2.12.orig/src/global.c
|
|
|
|
|
+++ cpio-2.12/src/global.c
|
2014-07-29 13:44:14 +02:00
|
|
|
|
@@ -187,6 +187,9 @@ bool to_stdout_option = false;
|
|
|
|
|
/* The name this program was run with. */
|
|
|
|
|
char *program_name;
|
|
|
|
|
|
|
|
|
|
+/* Extract files over symbolic links */
|
|
|
|
|
+bool extract_over_symlinks;
|
|
|
|
|
+
|
|
|
|
|
/* A pointer to either lstat or stat, depending on whether
|
|
|
|
|
dereferencing of symlinks is done for input files. */
|
|
|
|
|
int (*xstat) ();
|
2015-10-09 13:20:18 +02:00
|
|
|
|
Index: cpio-2.12/src/main.c
|
2014-07-29 13:44:14 +02:00
|
|
|
|
===================================================================
|
2015-10-09 13:20:18 +02:00
|
|
|
|
--- cpio-2.12.orig/src/main.c
|
|
|
|
|
+++ cpio-2.12/src/main.c
|
|
|
|
|
@@ -59,6 +59,7 @@ enum cpio_options {
|
2014-07-29 13:44:14 +02:00
|
|
|
|
DEBUG_OPTION,
|
|
|
|
|
BLOCK_SIZE_OPTION,
|
2015-10-09 13:20:18 +02:00
|
|
|
|
TO_STDOUT_OPTION,
|
|
|
|
|
+ EXTRACT_OVER_SYMLINKS,
|
|
|
|
|
RENUMBER_INODES_OPTION,
|
|
|
|
|
IGNORE_DEVNO_OPTION,
|
|
|
|
|
DEVICE_INDEPENDENT_OPTION
|
|
|
|
|
@@ -243,6 +244,8 @@ static struct argp_option options[] = {
|
2014-07-29 13:44:14 +02:00
|
|
|
|
N_("Create leading directories where needed"), GRID+1 },
|
|
|
|
|
{"no-preserve-owner", NO_PRESERVE_OWNER_OPTION, 0, 0,
|
|
|
|
|
N_("Do not change the ownership of the files"), GRID+1 },
|
|
|
|
|
+ {"extract-over-symlinks", EXTRACT_OVER_SYMLINKS, 0, 0,
|
|
|
|
|
+ N_("Force writing over symbolic links"), GRID+1 },
|
|
|
|
|
{"unconditional", 'u', NULL, 0,
|
|
|
|
|
N_("Replace all files unconditionally"), GRID+1 },
|
|
|
|
|
{"sparse", SPARSE_OPTION, NULL, 0,
|
2015-10-09 13:20:18 +02:00
|
|
|
|
@@ -433,6 +436,10 @@ crc newc odc bin ustar tar (all-caps als
|
2014-07-29 13:44:14 +02:00
|
|
|
|
no_chown_flag = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
+ case EXTRACT_OVER_SYMLINKS: /* --extract-over-symlinks */
|
|
|
|
|
+ extract_over_symlinks = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
case 'o': /* Copy-out mode. */
|
|
|
|
|
if (copy_function != 0)
|
2015-10-09 13:20:18 +02:00
|
|
|
|
USAGE_ERROR ((0, 0, _("Mode already defined")));
|
|
|
|
|
Index: cpio-2.12/src/extern.h
|
2014-07-29 13:44:14 +02:00
|
|
|
|
===================================================================
|
2015-10-09 13:20:18 +02:00
|
|
|
|
--- cpio-2.12.orig/src/extern.h
|
|
|
|
|
+++ cpio-2.12/src/extern.h
|
|
|
|
|
@@ -96,6 +96,7 @@ extern char input_is_special;
|
2014-07-29 13:44:14 +02:00
|
|
|
|
extern char output_is_special;
|
|
|
|
|
extern char input_is_seekable;
|
|
|
|
|
extern char output_is_seekable;
|
|
|
|
|
+extern bool extract_over_symlinks;
|
|
|
|
|
extern int (*xstat) ();
|
|
|
|
|
extern void (*copy_function) ();
|
2015-10-09 13:20:18 +02:00
|
|
|
|
extern char *change_directory_option;
|
|
|
|
|
Index: cpio-2.12/doc/cpio.1
|
2014-07-29 13:44:14 +02:00
|
|
|
|
===================================================================
|
2015-10-09 13:20:18 +02:00
|
|
|
|
--- cpio-2.12.orig/doc/cpio.1
|
|
|
|
|
+++ cpio-2.12/doc/cpio.1
|
|
|
|
|
@@ -50,6 +50,7 @@ cpio \- copy files to and from archives
|
|
|
|
|
[\fB\-\-force\-local\fR] [\fB\-\-no\-absolute\-filenames\fR] [\fB\-\-sparse\fR]
|
|
|
|
|
[\fB\-\-only\-verify\-crc\fR] [\fB\-\-to\-stdout\fR] [\fB\-\-quiet\fR]
|
|
|
|
|
[\fB\-\-rsh\-command=\fICOMMAND\fR]
|
|
|
|
|
+[\fB\-\-extract\-over\-symlinks\fR]
|
|
|
|
|
[\fIpattern\fR...] [\fB<\fR \fIarchive\fR]
|
2014-07-29 13:44:14 +02:00
|
|
|
|
|
|
|
|
|
.B cpio
|