fix: use execvp instead of system() for privilege escalation
system() blocked and prevented pkexec from re-launching the program. execvp replaces the process, allowing pkexec to take over properly.
This commit is contained in:
+12
-10
@@ -6,6 +6,7 @@
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
#include "config.h"
|
||||
#include "rsync_manager.h"
|
||||
@@ -24,16 +25,17 @@ static void escalate_privileges(int argc, char* argv[]) {
|
||||
|
||||
g_print("x3-backup requires root privileges. Re-launching with pkexec...\n");
|
||||
|
||||
std::string cmd = "pkexec";
|
||||
for (int i = 0; i < argc; i++) {
|
||||
std::string arg = argv[i];
|
||||
if (arg.find(' ') != std::string::npos)
|
||||
cmd += " \"" + arg + "\"";
|
||||
else
|
||||
cmd += " " + arg;
|
||||
}
|
||||
int ret = system(cmd.c_str());
|
||||
exit(ret);
|
||||
/* Build argv for exec: pkexec + original args + NULL */
|
||||
std::vector<const char*> new_argv;
|
||||
new_argv.push_back("pkexec");
|
||||
for (int i = 0; i < argc; i++)
|
||||
new_argv.push_back(argv[i]);
|
||||
new_argv.push_back(nullptr);
|
||||
|
||||
execvp("pkexec", const_cast<char* const*>(new_argv.data()));
|
||||
/* If execvp returns, it failed */
|
||||
perror("execvp pkexec");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static std::string get_log_path() {
|
||||
|
||||
Reference in New Issue
Block a user