summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-02-28 11:44:03 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2021-02-28 11:45:46 -0800
commitafe372f33a5dd31bcca34dc4d73e2c092447635f (patch)
treecfc8124e76efbd5ceea4cd3b8b1fb0e9b77bc4a9
parenteb7db65ac17f5340abddb2bc719918eef756e30e (diff)
downloadpaxutils-afe372f33a5dd31bcca34dc4d73e2c092447635f.tar.gz
Avoid linking problem in sys_reset_uid_gid
* lib/system.h (sys_reset_uid_gid) [!MSDOS]: On failure, instead of invoking FATAL_ERROR set errno and return the name of the syscall that failed, so that the caller can decide what to do. This avoids some GNU Tar linking problems on compilers that do not inline this function. All callers changed.
-rw-r--r--lib/rtapelib.c5
-rw-r--r--lib/system.h25
-rw-r--r--paxlib/rtape.c5
3 files changed, 17 insertions, 18 deletions
diff --git a/lib/rtapelib.c b/lib/rtapelib.c
index fae0db8..0c516e5 100644
--- a/lib/rtapelib.c
+++ b/lib/rtapelib.c
@@ -504,7 +504,10 @@ rmt_open__ (const char *file_name, int open_mode, int bias,
error (EXIT_ON_EXEC_ERROR, errno,
_("Cannot redirect files for remote shell"));
- sys_reset_uid_gid ();
+ char const *reseterr = sys_reset_uid_gid ();
+ if (reseterr)
+ error (EXIT_ON_EXEC_ERROR, errno,
+ _("Cannot reset uid and gid: %s"), reseterr);
if (remote_user)
execl (remote_shell, remote_shell_basename, remote_host,
diff --git a/lib/system.h b/lib/system.h
index 1bd5ba9..6acefd7 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -470,29 +470,22 @@ char *getenv ();
# define SET_BINARY_MODE(arc)
# define TTY_NAME "/dev/tty"
# include <paxlib.h>
-static inline void
+static inline char const *
sys_reset_uid_gid (void)
{
- struct passwd *pw;
uid_t uid = getuid ();
gid_t gid = getgid ();
+ struct passwd *pw = getpwuid (uid);
- if ((pw = getpwuid (uid)) == NULL)
- {
- FATAL_ERROR ((0, errno, "%s(%lu)", "getpwuid", (unsigned long)uid));
- }
- if (initgroups (pw->pw_name, getgid ()))
- {
- FATAL_ERROR ((0, errno, "%s", "initgroups"));
- }
+ if (!pw)
+ return "getpwuid";
+ if (initgroups (pw->pw_name, gid))
+ return "initgroups";
if (gid != getegid () && setgid (gid) && errno != EPERM)
- {
- FATAL_ERROR ((0, errno, "%s", "setgid"));
- }
+ return "setgid";
if (uid != geteuid () && setuid (uid) && errno != EPERM)
- {
- FATAL_ERROR ((0, errno, "%s", "setuid"));
- }
+ return "setuid";
+ return NULL;
}
#endif
diff --git a/paxlib/rtape.c b/paxlib/rtape.c
index 41f6ef1..0a31c44 100644
--- a/paxlib/rtape.c
+++ b/paxlib/rtape.c
@@ -503,7 +503,10 @@ rmt_open (const char *file_name, int open_mode, int bias,
close (from_remote[remote_pipe_number][PREAD]);
close (from_remote[remote_pipe_number][PWRITE]);
- sys_reset_uid_gid ();
+ char const *reseterr = sys_reset_uid_gid ();
+ if (reseterr)
+ error (EXIT_ON_EXEC_ERROR, errno,
+ _("Cannot reset uid and gid: %s"), reseterr);
if (!rmt_command)
rmt_command = DEFAULT_RMT_COMMAND;