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 <ctime>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "rsync_manager.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");
|
g_print("x3-backup requires root privileges. Re-launching with pkexec...\n");
|
||||||
|
|
||||||
std::string cmd = "pkexec";
|
/* Build argv for exec: pkexec + original args + NULL */
|
||||||
for (int i = 0; i < argc; i++) {
|
std::vector<const char*> new_argv;
|
||||||
std::string arg = argv[i];
|
new_argv.push_back("pkexec");
|
||||||
if (arg.find(' ') != std::string::npos)
|
for (int i = 0; i < argc; i++)
|
||||||
cmd += " \"" + arg + "\"";
|
new_argv.push_back(argv[i]);
|
||||||
else
|
new_argv.push_back(nullptr);
|
||||||
cmd += " " + arg;
|
|
||||||
}
|
execvp("pkexec", const_cast<char* const*>(new_argv.data()));
|
||||||
int ret = system(cmd.c_str());
|
/* If execvp returns, it failed */
|
||||||
exit(ret);
|
perror("execvp pkexec");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string get_log_path() {
|
static std::string get_log_path() {
|
||||||
|
|||||||
Reference in New Issue
Block a user