]> Dogcows Code - chaz/tar/blobdiff - src/extract.c
tar: fix 1.23 Solaris regression related to PRIV_SYS_LINKDIR
[chaz/tar] / src / extract.c
index 0ad5545426d611ae6cd88058cb171395fb4ead81..653e2a0d2f879f4bf95442275928ba69a4d129cb 100644 (file)
@@ -144,7 +144,7 @@ set_mode (char const *file_name,
          char typeflag)
 {
   mode_t mode;
-  bool failed;
+  int chmod_errno;
 
   if (0 < same_permissions_option
       && permstatus != INTERDIR_PERMSTATUS)
@@ -187,18 +187,24 @@ set_mode (char const *file_name,
       mode = cur_info->st_mode ^ invert_permissions;
     }
 
-  failed = chmod (file_name, mode) != 0;
-  if (failed && errno == EPERM)
+  chmod_errno = chmod (file_name, mode) == 0 ? 0 : errno;
+  if (chmod_errno == EPERM && (mode & S_ISUID) != 0)
     {
-      /* On Solaris, chmod may fail if we don't have PRIV_ALL.  */
+      /* On Solaris, chmod may fail if we don't have PRIV_ALL, because
+        setuid-root files would otherwise be a backdoor.  See
+        http://opensolaris.org/jive/thread.jspa?threadID=95826
+        (2009-09-03).  */
       if (priv_set_restore_linkdir () == 0)
        {
-         failed = chmod (file_name, mode) != 0;
+         chmod_errno = chmod (file_name, mode) == 0 ? 0 : errno;
          priv_set_remove_linkdir ();
        }
     }
-  if (failed)
-    chmod_error_details (file_name, mode);
+  if (chmod_errno)
+    {
+      errno = chmod_errno;
+      chmod_error_details (file_name, mode);
+    }
 }
 
 /* Check time after successfully setting FILE_NAME's time stamp to T.  */
@@ -1271,9 +1277,6 @@ extract_archive (void)
 
   fatal_exit_hook = extract_finish;
 
-  /* Try to disable the ability to unlink a directory.  */
-  priv_set_remove_linkdir ();
-
   set_next_block_after (current_header);
 
   if (!current_stat_info.file_name[0]
This page took 0.021821 seconds and 4 git commands to generate.