From 739297e42dc4618d585c658c60859248ad112d62 Mon Sep 17 00:00:00 2001 From: David Bartley Date: Sat, 7 Mar 2009 13:16:20 -0500 Subject: [PATCH] Fix bug on Solaris that prevents setuid root files from being created. --- ChangeLog.CVS | 6 ++++++ src/extract.c | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog.CVS b/ChangeLog.CVS index 41227f5..f0c53ed 100644 --- a/ChangeLog.CVS +++ b/ChangeLog.CVS @@ -1,3 +1,9 @@ +2009-03-07 David Bartley + + Fix bug on Solaris that prevents setuid root files from being created. + + * src/extract.c: Call restore_unlink_dir if chmod fails with EPERM. + 2009-03-05 Sergey Poznyakoff * src/incremen.c: --no-recursive works with --incremental. diff --git a/src/extract.c b/src/extract.c index 6d70398..fa8ba4b 100644 --- a/src/extract.c +++ b/src/extract.c @@ -1,7 +1,7 @@ /* Extract files from a tar archive. Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, - 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2001, 2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by John Gilmore, on 1985-11-19. @@ -24,6 +24,7 @@ #include #include #include +#include #include "common.h" @@ -186,7 +187,15 @@ 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 dropped a privilege (this happens + when we call cannot_unlink_dir). */ + if (restore_unlink_dir ()) + failed = (chmod (file_name, mode) != 0); + } + if (failed) chmod_error_details (file_name, mode); } -- 1.5.6.5