From bf0027680b5667b81227252216fa39eaece780db Mon Sep 17 00:00:00 2001 From: David Bartley Date: Sun, 3 May 2009 17:25:04 -0400 Subject: [PATCH] Fix Solaris bug where chmod fails if we don't have PRIV_SYS_LINKDIR * gnulib.modules: Add priv-set. * src/extract.c: Restore PRIV_SYS_LINKDIR on chmod failure. * src/tar.c: Drop PRIV_SYS_LINKDIR on startup. --- gnulib.modules | 1 + src/extract.c | 16 +++++++++++++++- src/tar.c | 4 ++++ 3 files changed, 20 insertions(+), 1 deletions(-) diff --git a/gnulib.modules b/gnulib.modules index fcaf3ac..858967b 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -31,6 +31,7 @@ localcharset mkdtemp modechange obstack +priv-set quote quotearg rpmatch diff --git a/src/extract.c b/src/extract.c index 6d70398..6a648a2 100644 --- a/src/extract.c +++ b/src/extract.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "common.h" @@ -186,7 +187,17 @@ set_mode (char const *file_name, mode = cur_info->st_mode ^ invert_permissions; } - if (chmod (file_name, mode) != 0) + bool 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); } @@ -1198,6 +1209,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, ¤t_stat_info, ¤t_format, 1); if (!current_stat_info.file_name[0] diff --git a/src/tar.c b/src/tar.c index dbffc2a..3baeb41 100644 --- a/src/tar.c +++ b/src/tar.c @@ -50,6 +50,7 @@ #include #include #include +#include /* Local declarations. */ @@ -2454,6 +2455,9 @@ main (int argc, char **argv) obstack_init (&argv_stk); + /* Try to disable the ability to unlink a directory. */ + priv_set_remove_linkdir (); + #ifdef SIGCHLD /* System V fork+wait does not work if SIGCHLD is ignored. */ signal (SIGCHLD, SIG_DFL); -- 1.5.6.5