summaryrefslogtreecommitdiff
path: root/cmdline/apt-helper.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2018-01-25 17:14:49 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2018-02-19 15:56:09 +0100
commit887e331abb6ac0a850e5d53de55f43c9ebdee5a2 (patch)
tree4c0a90ad39c784584d7319f40a8ed7818326a4be /cmdline/apt-helper.cc
parentbda3bce0197fe64819626f9ab116f72f80ce63c5 (diff)
add apt-helper drop-privs command…
Diffstat (limited to 'cmdline/apt-helper.cc')
-rw-r--r--cmdline/apt-helper.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index d1a3b4e6e..beac0efba 100644
--- a/cmdline/apt-helper.cc
+++ b/cmdline/apt-helper.cc
@@ -219,6 +219,22 @@ static bool DoWaitOnline(CommandLine &)
return _error->PendingError() == false;
}
/*}}}*/
+static bool DropPrivsAndRun(CommandLine &CmdL) /*{{{*/
+{
+ if (CmdL.FileSize() < 2)
+ return _error->Error("No command given to run without privileges");
+ if (DropPrivileges() == false)
+ return _error->Error("Dropping Privileges failed, not executing '%s'", CmdL.FileList[1]);
+
+ std::vector<char const *> Args;
+ Args.reserve(CmdL.FileSize() + 1);
+ for (auto a = CmdL.FileList + 1; *a != nullptr; ++a)
+ Args.push_back(*a);
+ Args.push_back(nullptr);
+ auto const pid = ExecuteProcess(Args.data());
+ return ExecWait(pid, CmdL.FileList[1]);
+}
+ /*}}}*/
static bool ShowHelp(CommandLine &) /*{{{*/
{
std::cout <<
@@ -239,6 +255,7 @@ static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
{"cat-file", &DoCatFile, _("concatenate files, with automatic decompression")},
{"auto-detect-proxy", &DoAutoDetectProxy, _("detect proxy using apt.conf")},
{"wait-online", &DoWaitOnline, _("wait for system to be online")},
+ {"drop-privs", &DropPrivsAndRun, _("drop privileges before running given command")},
{nullptr, nullptr, nullptr}};
}
/*}}}*/