From fc1a78d8e9b958f3d65fe1c03494d785314f9816 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 11 Jun 2014 15:31:38 +0200 Subject: DropPrivs in the solvers (just to be on the safe side) --- apt-pkg/contrib/fileutl.cc | 17 +++++++++++++++++ apt-pkg/contrib/fileutl.h | 3 +++ 2 files changed, 20 insertions(+) (limited to 'apt-pkg/contrib') 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 #include #include +#include #include #include @@ -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; +} diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index cc1a98eae..683c04157 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -191,6 +191,9 @@ pid_t ExecFork(std::set keep_fds); void MergeKeepFdsFromConfiguration(std::set &keep_fds); bool ExecWait(pid_t Pid,const char *Name,bool Reap = false); +// process releated +bool DropPrivs(); + // File string manipulators std::string flNotDir(std::string File); std::string flNotFile(std::string File); -- cgit v1.2.3