summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-06-11 15:31:38 +0200
committerMichael Vogt <mvo@debian.org>2014-06-11 15:31:38 +0200
commitfc1a78d8e9b958f3d65fe1c03494d785314f9816 (patch)
tree09b61bfae82e32d45db8e264bb3a15f947ca8b76 /apt-pkg/contrib/fileutl.cc
parenteea0f3a6197dba565c5df349ed06c0a70b49b77f (diff)
DropPrivs in the solvers (just to be on the safe side)
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 1ba4674e5..da81edbcc 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -47,6 +47,7 @@
#include <signal.h>
#include <errno.h>
#include <glob.h>
+#include <pwd.h>
#include <set>
#include <algorithm>
@@ -2050,3 +2051,19 @@ bool Rename(std::string From, std::string To)
}
return true;
}
+
+bool DropPrivs()
+{
+ if (getuid() != 0)
+ return true;
+
+ const std::string nobody = _config->Find("APT::User::Nobody", "nobody");
+ struct passwd *pw = getpwnam(nobody.c_str());
+ if (pw == NULL)
+ return _error->Warning("No user %s, can not drop rights", nobody.c_str());
+ if (setgid(pw->pw_gid) != 0)
+ return _error->Errno("setgid", "Failed to setgid");
+ if (setuid(pw->pw_uid) != 0)
+ return _error->Errno("setuid", "Failed to setuid");
+ return true;
+}