diff options
Diffstat (limited to 'paxlib/rtape.c')
-rw-r--r-- | paxlib/rtape.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/paxlib/rtape.c b/paxlib/rtape.c index 2364594..1089d92 100644 --- a/paxlib/rtape.c +++ b/paxlib/rtape.c @@ -358,6 +358,29 @@ encode_oflag (char *buf, int oflag) strcat (buf, "|O_TRUNC"); } +/* Reset user and group IDs to be those of the real user. + Return NULL on success, a failing syscall name (setting errno) on error. */ +static char const * +sys_reset_uid_gid (void) +{ +#if !MSDOS + uid_t uid = getuid (); + gid_t gid = getgid (); + struct passwd *pw = getpwuid (uid); + + if (!pw) + return "getpwuid"; + if (initgroups (pw->pw_name, gid) != 0) + return "initgroups"; + if (gid != getegid () && setgid (gid) != 0 && errno != EPERM) + return "setgid"; + if (uid != geteuid () && setuid (uid) != 0 && errno != EPERM) + return "setuid"; +#endif + + return NULL; +} + /* Open a remote file on the system specified in FILE_NAME, as the given user. FILE_NAME has the form `[USER@]HOST:FILE'. OPEN_MODE is O_RDONLY, O_WRONLY, etc. If successful, return the |