summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 1d20c9c35..837edef4b 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -2141,6 +2141,8 @@ std::string GetTempDir(std::string const &User)
if (pw == NULL)
return GetTempDir();
+ gid_t const old_euid = geteuid();
+ gid_t const old_egid = getegid();
if (setegid(pw->pw_gid) != 0)
_error->Errno("setegid", "setegid %u failed", pw->pw_gid);
if (seteuid(pw->pw_uid) != 0)
@@ -2148,10 +2150,10 @@ std::string GetTempDir(std::string const &User)
std::string const tmp = GetTempDir();
- if (seteuid(0) != 0)
- _error->Errno("seteuid", "seteuid %u failed", 0);
- if (setegid(0) != 0)
- _error->Errno("setegid", "setegid %u failed", 0);
+ if (seteuid(old_euid) != 0)
+ _error->Errno("seteuid", "seteuid %u failed", old_euid);
+ if (setegid(old_egid) != 0)
+ _error->Errno("setegid", "setegid %u failed", old_egid);
return tmp;
}