]> Dogcows Code - chaz/tar/commitdiff
Fix Solaris bug where chmod fails if we don't have PRIV_SYS_LINKDIR
authorDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Thu, 18 Jun 2009 10:57:10 +0000 (13:57 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Thu, 18 Jun 2009 10:57:10 +0000 (13:57 +0300)
* gnulib.modules: Add priv-set.
* src/extract.c (set_mode, extract_archive): Restore
PRIV_SYS_LINKDIR on chmod failure.
* src/tar.c (main): Drop PRIV_SYS_LINKDIR on startup.

gnulib.modules
src/extract.c
src/tar.c

index fcaf3ac46ebad1bddd6bdcaa1a1c02900e7eb5eb..858967b584c54c874809a8a131c26a0c577cec96 100644 (file)
@@ -31,6 +31,7 @@ localcharset
 mkdtemp
 modechange
 obstack
+priv-set
 quote
 quotearg
 rpmatch
index 300f52bc3c5a8cc96305003d10fd93ca63e770ca..40d55282ff4275d4c44586bcad5ec8fce2864b49 100644 (file)
@@ -24,6 +24,7 @@
 #include <utimens.h>
 #include <errno.h>
 #include <xgetcwd.h>
+#include <priv-set.h>
 
 #include "common.h"
 
@@ -144,7 +145,8 @@ set_mode (char const *file_name,
          char typeflag)
 {
   mode_t mode;
-
+  bool failed;
+  
   if (0 < same_permissions_option
       && permstatus != INTERDIR_PERMSTATUS)
     {
@@ -186,7 +188,17 @@ set_mode (char const *file_name,
       mode = cur_info->st_mode ^ invert_permissions;
     }
 
-  if (chmod (file_name, mode) != 0)
+  failed = chmod (file_name, mode) != 0;
+  if (failed && errno == EPERM)
+    {
+      /* On Solaris, chmod may fail if we don't have PRIV_ALL.  */
+      if (priv_set_restore_linkdir () == 0)
+       {
+         failed = chmod (file_name, mode) != 0;
+         priv_set_remove_linkdir ();
+       }
+    }
+  if (failed)
     chmod_error_details (file_name, mode);
 }
 
@@ -1218,6 +1230,9 @@ extract_archive (void)
   char typeflag;
   tar_extractor_t fun;
 
+  /* Try to disable the ability to unlink a directory.  */
+  priv_set_remove_linkdir ();
+
   set_next_block_after (current_header);
   decode_header (current_header, &current_stat_info, &current_format, 1);
   if (!current_stat_info.file_name[0]
index e10b80431c1c60ba5f7fa2ee04b9e0f07310970a..31537eb23fad6121f810ff80aa3b4ed25b4ccb5c 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -50,6 +50,7 @@
 #include <version-etc.h>
 #include <xstrtol.h>
 #include <stdopen.h>
+#include <priv-set.h>
 
 /* Local declarations.  */
 
@@ -2459,6 +2460,9 @@ main (int argc, char **argv)
   /* System V fork+wait does not work if SIGCHLD is ignored.  */
   signal (SIGCHLD, SIG_DFL);
 
+  /* Try to disable the ability to unlink a directory.  */
+  priv_set_remove_linkdir ();
+  
   /* Decode options.  */
 
   decode_options (argc, argv);
This page took 0.025106 seconds and 4 git commands to generate.