diff options
author | Michael Vogt <mvo@debian.org> | 2014-06-18 10:47:19 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2014-06-18 10:47:57 +0200 |
commit | 17091f2f33de16c2dae501e7868f7aec4fc3452f (patch) | |
tree | f3eed549bbcb50a46d7c10aa7c3a048cf7fee166 /apt-pkg/contrib/fileutl.cc | |
parent | b6fea8bbe25e3c0312de72c99b0d49c699d02b7b (diff) | |
parent | fc1a78d8e9b958f3d65fe1c03494d785314f9816 (diff) |
Merge remote-tracking branch 'mvo/feature/drop-rights' into debian/experimental
Conflicts:
apt-pkg/contrib/fileutl.cc
apt-pkg/contrib/fileutl.h
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 29450ada0..6b8f04dea 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> @@ -2166,3 +2167,20 @@ bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode) 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; +} |