summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/rtapelib.c5
-rw-r--r--lib/system.h25
2 files changed, 13 insertions, 17 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