Skip to content
API Documentation
BastionGuard™
PrivacyPage.cpp File Reference

Go to the source code of this file.

Functions

static bool run_privhelper_pkexec (const std::string &action)
static std::string read_text_file (const std::string &path)
static std::string read_cmdline (const std::string &path)
static std::string read_exe_path (const std::string &pid_str)
static bool is_noise_process (const std::string &comm, const std::string &exe, const std::string &cmdline)
static int read_ppid (const std::string &pid_str)
static bool parent_is_noise (const std::string &pid_str)

Variables

std::queue< std::string > alert_queue_
Gtk::Window * current_alert_ = nullptr

Function Documentation

◆ is_noise_process()

bool is_noise_process ( const std::string & comm,
const std::string & exe,
const std::string & cmdline )
static

Definition at line 100 of file PrivacyPage.cpp.

103{
104 // Match per nome (comm)
105 static const std::set<std::string> kCommDeny = {
106 "bash","zsh","fish","sh","dash",
107 "konsole","gnome-terminal-","xfce4-terminal","kitty","alacritty","wezterm",
108 "tmux","screen",
109 "pkexec",
110 "polkitd","polkit-agent-helper-1","polkit-kde-authentication-agent-1",
111 "gnome-shell","plasmashell","kwin_wayland","kwin_x11",
112 "xdg-desktop-portal","xdg-desktop-portal-gtk","xdg-desktop-portal-kde",
113 "pipewire","wireplumber","pulseaudio"
114 };
115
116 if (!comm.empty() && kCommDeny.count(comm)) return true;
117
118 // Match per path exe (più stabile di comm)
119 auto has = [&](const char* needle) {
120 return (!exe.empty() && exe.find(needle) != std::string::npos) ||
121 (!cmdline.empty() && cmdline.find(needle) != std::string::npos);
122 };
123
124 // Polkit / privilege prompts
125 if (has("polkit") || has("pkexec")) return true;
126
127 // Terminali / shell
128 if (has("konsole") || has("gnome-terminal") || has("xfce4-terminal") ||
129 has("kitty") || has("alacritty") || has("wezterm") ||
130 has("/bin/bash") || has("/usr/bin/bash") || has("/bin/zsh") || has("/usr/bin/zsh") ||
131 has("/bin/fish") || has("/usr/bin/fish"))
132 return true;
133
134 // Portali / media stack (spesso fanno probing o broker)
135 if (has("xdg-desktop-portal") || has("pipewire") || has("wireplumber") || has("pulseaudio"))
136 return true;
137
138 // Desktop env “core”
139 if (has("plasmashell") || has("gnome-shell") || has("kwin"))
140 return true;
141
142 return false;
143}

References is_noise_process().

Referenced by PrivacyPage::detect_active_devices(), is_noise_process(), and parent_is_noise().

◆ parent_is_noise()

bool parent_is_noise ( const std::string & pid_str)
static

Definition at line 164 of file PrivacyPage.cpp.

164 {
165 std::string cur = pid_str;
166 for (int i = 0; i < 3; ++i) { // risali max 3 livelli
167 int ppid = read_ppid(cur);
168 if (ppid <= 1) break;
169 std::string p = std::to_string(ppid);
170 std::string comm = read_text_file("/proc/" + p + "/comm");
171 std::string exe = read_exe_path(p);
172 std::string cmd = read_cmdline("/proc/" + p + "/cmdline");
173 if (is_noise_process(comm, exe, cmd)) return true;
174 cur = p;
175 }
176 return false;
177}
static std::string read_exe_path(const std::string &pid_str)
static std::string read_cmdline(const std::string &path)
static int read_ppid(const std::string &pid_str)
static bool is_noise_process(const std::string &comm, const std::string &exe, const std::string &cmdline)
static std::string read_text_file(const std::string &path)

References is_noise_process(), parent_is_noise(), read_cmdline(), read_exe_path(), read_ppid(), and read_text_file().

Referenced by PrivacyPage::detect_active_devices(), and parent_is_noise().

◆ read_cmdline()

std::string read_cmdline ( const std::string & path)
static

Definition at line 85 of file PrivacyPage.cpp.

85 {
86 std::ifstream f(path, std::ios::binary);
87 if (!f.is_open()) return {};
88 std::string buf((std::istreambuf_iterator<char>(f)), {});
89 for (char& c : buf) if (c == '\0') c = ' ';
90 return buf;
91}

References read_cmdline().

Referenced by PrivacyPage::detect_active_devices(), parent_is_noise(), and read_cmdline().

◆ read_exe_path()

std::string read_exe_path ( const std::string & pid_str)
static

Definition at line 93 of file PrivacyPage.cpp.

93 {
94 std::error_code ec;
95 auto p = fs::read_symlink("/proc/" + pid_str + "/exe", ec);
96 if (ec) return {};
97 return p.string();
98}

References read_exe_path().

Referenced by PrivacyPage::detect_active_devices(), parent_is_noise(), and read_exe_path().

◆ read_ppid()

int read_ppid ( const std::string & pid_str)
static

Definition at line 145 of file PrivacyPage.cpp.

145 {
146 std::ifstream f("/proc/" + pid_str + "/status");
147 if (!f.is_open()) return -1;
148
149 std::string line;
150 while (std::getline(f, line)) {
151 if (line.rfind("PPid:", 0) == 0) {
152 try {
153 // dopo "PPid:" ci sono tab/spazi -> stoi li gestisce
154 return std::stoi(line.substr(5));
155 } catch (...) {
156 return -1;
157 }
158 }
159 }
160 return -1;
161}

References read_ppid().

Referenced by parent_is_noise(), and read_ppid().

◆ read_text_file()

std::string read_text_file ( const std::string & path)
static

Definition at line 77 of file PrivacyPage.cpp.

77 {
78 std::ifstream f(path);
79 if (!f.is_open()) return {};
80 std::string s;
81 std::getline(f, s);
82 return s;
83}

References read_text_file().

Referenced by PrivacyPage::detect_active_devices(), parent_is_noise(), and read_text_file().

◆ run_privhelper_pkexec()

bool run_privhelper_pkexec ( const std::string & action)
static

Definition at line 47 of file PrivacyPage.cpp.

47 {
48 if (action != "block" && action != "unblock")
49 return false;
50
51 const pid_t pid = ::fork();
52 if (pid < 0)
53 return false;
54
55 if (pid == 0) {
56 ::execl(
57 "/usr/bin/pkexec",
58 "pkexec",
59 "/usr/bin/bastionguard-privhelper",
60 action.c_str(),
61 static_cast<char*>(nullptr)
62 );
63 _exit(127);
64 }
65
66 int status = 0;
67 while (::waitpid(pid, &status, 0) < 0) {
68 if (errno == EINTR)
69 continue;
70 return false;
71 }
72
73 return WIFEXITED(status) && WEXITSTATUS(status) == 0;
74}

References run_privhelper_pkexec().

Referenced by PrivacyPage::manual_unlock_devices(), PrivacyPage::run_privacy_script_async(), run_privhelper_pkexec(), PrivacyPage::show_next_alert(), and PrivacyPage::unblock_devices_local().

Variable Documentation

◆ alert_queue_

std::queue<std::string> alert_queue_

◆ current_alert_

Gtk::Window* current_alert_ = nullptr