Hello. The attached patch adds a --disable-default-root-preserve configure 
option, so root does not preserve file mode or ownership when extracting. The 
current behavior is not effected by this patch, unless the configure option 
is used.

The purpose of this patch is not to remove the current behavior, but just to 
make it optional.

robert
Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
Date: 2008-03-08
Initial Package Version: 1.19
Upstream Status: Submitted
Origin: http://www.xs4all.nl/~hanb/software/crux/han/tar/tar.patch
Description: GNU Tar preserves file ownership and permissions by default when
tar is extracting files as root. This patch adds the
'--disable-default-root-preserve' ./configure option to disable this default
behavior, and use umask instead. The '--same-owner' and '--preserve' options
will still work correctly if they're specified.

diff -Naur tar-1.19.orig/config.hin tar-1.19/config.hin
--- tar-1.19.orig/config.hin	2007-10-10 11:01:17.000000000 +0000
+++ tar-1.19/config.hin	2008-03-08 20:49:16.000000000 +0000
@@ -61,6 +61,9 @@
 #endif
 
 
+/* Define to disable root's default --same-owner --preserve options */
+#undef DISABLE_DEFAULT_ROOT_PRESERVE
+
 /* Define to 1 if // is a file system root distinct from /. */
 #undef DOUBLE_SLASH_IS_DISTINCT_ROOT
 
diff -Naur tar-1.19.orig/configure tar-1.19/configure
--- tar-1.19.orig/configure	2007-10-10 11:00:16.000000000 +0000
+++ tar-1.19/configure	2008-03-08 20:50:42.000000000 +0000
@@ -1545,6 +1545,9 @@
   --disable-rpath         do not hardcode runtime library paths
   --disable-nls           do not use Native Language Support
   --enable-backup-scripts Create and install backup and restore scripts
+  --disable-default-root-preserve
+                          Do not use --same-owner --preserve by default with
+                          root
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -35971,6 +35974,22 @@
 	BACKUP_SED_COND='/^\#IF_DATE_FORMAT_OK/,/^\#ELSE_DATE_FORMAT_OK/d;/^\#ENDIF_DATE_FORMAT_OK/d'
 fi
 
+# Check whether --enable-default-root-preserve was given.
+if test "${enable_default_root_preserve+set}" = set; then
+  enableval=$enable_default_root_preserve; case $enableval in
+               no) ENABLE_DEFAULT_ROOT_PRESERVE='no'
+                   ;;
+               esac
+fi
+
+if test "$ENABLE_DEFAULT_ROOT_PRESERVE" = "no"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define DISABLE_DEFAULT_ROOT_PRESERVE
+_ACEOF
+
+fi
+
 ac_config_files="$ac_config_files Makefile doc/Makefile lib/Makefile po/Makefile.in scripts/Makefile rmt/Makefile src/Makefile"
 
 cat >confcache <<\_ACEOF
diff -Naur tar-1.19.orig/configure.ac tar-1.19/configure.ac
--- tar-1.19.orig/configure.ac	2007-10-10 10:59:28.000000000 +0000
+++ tar-1.19/configure.ac	2008-03-08 20:50:32.000000000 +0000
@@ -239,6 +239,18 @@
 	BACKUP_SED_COND='/^\#IF_DATE_FORMAT_OK/,/^\#ELSE_DATE_FORMAT_OK/d;/^\#ENDIF_DATE_FORMAT_OK/d'
 fi
 
+AC_ARG_ENABLE(default-root-preserve,
+              AC_HELP_STRING([--disable-default-root-preserve],
+                             [Do not use --same-owner --preserve by default with root]),
+              [case $enableval in
+               no) ENABLE_DEFAULT_ROOT_PRESERVE='no'
+                   ;;
+               esac])
+if test "$ENABLE_DEFAULT_ROOT_PRESERVE" = "no"; then
+AC_DEFINE([DISABLE_DEFAULT_ROOT_PRESERVE],,
+  [Define to disable root's default --same-owner --preserve options])
+fi
+
 AC_OUTPUT([Makefile\
            doc/Makefile\
            lib/Makefile\
diff -Naur tar-1.19.orig/src/extract.c tar-1.19/src/extract.c
--- tar-1.19.orig/src/extract.c	2007-08-26 08:56:55.000000000 +0000
+++ tar-1.19/src/extract.c	2008-03-08 20:49:16.000000000 +0000
@@ -113,8 +113,10 @@
 extr_init (void)
 {
   we_are_root = geteuid () == 0;
-  same_permissions_option += we_are_root;
-  same_owner_option += we_are_root;
+#ifndef DISABLE_DEFAULT_ROOT_PRESERVE
+ same_permissions_option += we_are_root;
+ same_owner_option += we_are_root;
+#endif
 
   /* Option -p clears the kernel umask, so it does not affect proper
      restoration of file permissions.  New intermediate directories will

Attachment: pgp7Tc1BPDSem.pgp
Description: PGP signature

Reply via email to