mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-21 21:46:15 +02:00
executePrivileged: support multiple privesc commands, support sudo
This commit is contained in:
parent
d7e702b121
commit
8a11cfdda8
1 changed files with 14 additions and 5 deletions
|
@ -34,13 +34,22 @@ using namespace nix;
|
|||
void executePrivileged(std::string program, Strings args) {
|
||||
args.push_front(program);
|
||||
auto exe = program;
|
||||
if(getuid() != 0) {
|
||||
args.push_front("doas");
|
||||
exe = "doas";
|
||||
auto privCmds = Strings {
|
||||
"doas",
|
||||
"sudo"
|
||||
};
|
||||
bool isRoot = getuid() == 0;
|
||||
for (auto privCmd : privCmds) {
|
||||
if(!isRoot) {
|
||||
args.push_front(privCmd);
|
||||
exe = privCmd;
|
||||
}
|
||||
execvp(exe.c_str(), stringsToCharPtrs(args).data());
|
||||
if(!isRoot)
|
||||
args.pop_front();
|
||||
}
|
||||
execvp(exe.c_str(), stringsToCharPtrs(args).data());
|
||||
|
||||
throw SysError("unable to execute '%s'", exe);
|
||||
throw SysError("unable to execute privilege elevation helper (tried %s)", concatStringsSep(", ", privCmds));
|
||||
}
|
||||
|
||||
struct SystemCommand : InstallableCommand
|
||||
|
|
Loading…
Reference in a new issue