Skip to content
API Documentation
BastionGuard™
anonymous_namespace{first-run-services-window.cpp} Namespace Reference

Functions

static bool is_system_unit (const std::string &unit_name)
static bool run_cmd (const std::vector< std::string > &argv, bool silence_stderr=true, bool capture_stdout=false, std::string *out_stdout=nullptr)
static bool pkexec_servicectl (const std::vector< std::string > &args, bool silence_stderr=false)
static std::string get_user_intercept_ca_path ()
static std::string get_system_fallback_ca_path ()
static std::string resolve_ca_path ()

Variables

const std::string FLAG_DIR = Glib::get_user_config_dir() + "/BastionGuard"
const std::string FLAG_FILE = FLAG_DIR + "/first-run-services-done"
const std::string CONFIG_DIR = Glib::get_user_config_dir() + "/BastionGuard"
const std::string CONFIG_FILE = CONFIG_DIR + "/config.json"
const std::set< std::string > SYSTEM_UNITS
static constexpr const char * CA_HELPER

Function Documentation

◆ get_system_fallback_ca_path()

std::string anonymous_namespace{first-run-services-window.cpp}::get_system_fallback_ca_path ( )
static

Definition at line 124 of file first-run-services-window.cpp.

125 {
126 return "/etc/BastionGuard/certs/intercept-ca.crt.pem";
127 }

References get_system_fallback_ca_path().

Referenced by get_system_fallback_ca_path(), and resolve_ca_path().

◆ get_user_intercept_ca_path()

std::string anonymous_namespace{first-run-services-window.cpp}::get_user_intercept_ca_path ( )
static

Definition at line 117 of file first-run-services-window.cpp.

118 {
119 return Glib::build_filename(
120 Glib::get_home_dir(),
121 ".local", "share", "BastionGuard", "certs", "intercept-ca.crt.pem");
122 }

References get_user_intercept_ca_path().

Referenced by get_user_intercept_ca_path(), and resolve_ca_path().

◆ is_system_unit()

bool anonymous_namespace{first-run-services-window.cpp}::is_system_unit ( const std::string & unit_name)
static

Definition at line 65 of file first-run-services-window.cpp.

66 {
67 return SYSTEM_UNITS.contains(unit_name);
68 }

References is_system_unit(), and SYSTEM_UNITS.

Referenced by is_system_unit().

◆ pkexec_servicectl()

bool anonymous_namespace{first-run-services-window.cpp}::pkexec_servicectl ( const std::vector< std::string > & args,
bool silence_stderr = false )
static

Definition at line 105 of file first-run-services-window.cpp.

107 {
108 std::vector<std::string> argv;
109 argv.reserve(args.size() + 3);
110 argv.push_back("pkexec");
111 argv.push_back("/usr/libexec/bastionguard/bastionguard-service");
112 argv.push_back("--system");
113 argv.insert(argv.end(), args.begin(), args.end());
114 return run_cmd(argv, silence_stderr);
115 }
static bool run_cmd(const std::vector< std::string > &argv, bool silence_stderr=true, bool capture_stdout=false, std::string *out_stdout=nullptr)

References pkexec_servicectl(), and run_cmd().

Referenced by pkexec_servicectl().

◆ resolve_ca_path()

std::string anonymous_namespace{first-run-services-window.cpp}::resolve_ca_path ( )
static

Definition at line 129 of file first-run-services-window.cpp.

130 {
131 const auto user_ca = get_user_intercept_ca_path();
132 if (std::filesystem::exists(user_ca))
133 return user_ca;
134
135 const auto system_ca = get_system_fallback_ca_path();
136 if (std::filesystem::exists(system_ca))
137 return system_ca;
138
139 return {};
140 }

References get_system_fallback_ca_path(), get_user_intercept_ca_path(), and resolve_ca_path().

Referenced by install_ca_nss_user(), install_ca_system(), and resolve_ca_path().

◆ run_cmd()

bool anonymous_namespace{first-run-services-window.cpp}::run_cmd ( const std::vector< std::string > & argv,
bool silence_stderr = true,
bool capture_stdout = false,
std::string * out_stdout = nullptr )
static

Definition at line 70 of file first-run-services-window.cpp.

74 {
75 try
76 {
77 Gio::Subprocess::Flags flags = Gio::Subprocess::Flags::NONE;
78
79 if (capture_stdout)
80 flags |= Gio::Subprocess::Flags::STDOUT_PIPE;
81
82 if (silence_stderr)
83 flags |= Gio::Subprocess::Flags::STDERR_SILENCE;
84 else
85 flags |= Gio::Subprocess::Flags::STDERR_PIPE;
86
87 auto proc = Gio::Subprocess::create(argv, flags);
88
89 if (capture_stdout && out_stdout)
90 {
91 auto [stdout_str, stderr_str] = proc->communicate_utf8("");
92 *out_stdout = stdout_str.raw();
93 return proc->get_successful();
94 }
95
96 proc->wait();
97 return proc->get_successful();
98 }
99 catch (...)
100 {
101 return false;
102 }
103 }

References run_cmd().

Referenced by install_ca_nss_user(), install_ca_system(), pkexec_servicectl(), and run_cmd().

Variable Documentation

◆ CA_HELPER

const char* anonymous_namespace{first-run-services-window.cpp}::CA_HELPER
staticconstexpr
Initial value:
=
"/usr/share/BastionGuard/data/scripts/install-ca-system.sh"

Definition at line 62 of file first-run-services-window.cpp.

Referenced by install_ca_system().

◆ CONFIG_DIR

const std::string anonymous_namespace{first-run-services-window.cpp}::CONFIG_DIR = Glib::get_user_config_dir() + "/BastionGuard"

Definition at line 48 of file first-run-services-window.cpp.

Referenced by ensure_config_dir().

◆ CONFIG_FILE

const std::string anonymous_namespace{first-run-services-window.cpp}::CONFIG_FILE = CONFIG_DIR + "/config.json"

Definition at line 49 of file first-run-services-window.cpp.

Referenced by save_config().

◆ FLAG_DIR

const std::string anonymous_namespace{first-run-services-window.cpp}::FLAG_DIR = Glib::get_user_config_dir() + "/BastionGuard"

Definition at line 45 of file first-run-services-window.cpp.

Referenced by ensure_flag_dir().

◆ FLAG_FILE

const std::string anonymous_namespace{first-run-services-window.cpp}::FLAG_FILE = FLAG_DIR + "/first-run-services-done"

Definition at line 46 of file first-run-services-window.cpp.

Referenced by touch_flag_file().

◆ SYSTEM_UNITS

const std::set<std::string> anonymous_namespace{first-run-services-window.cpp}::SYSTEM_UNITS
Initial value:
= {
"BastionGuard-phishing-scanner.service",
"BastionGuard-phishing-updater.service",
"BastionGuard-phishing-updater.timer",
"Bastionguard-privhelper.service",
"bastionguard-sanesecurity.service",
"bastionguard-sanesecurity.timer",
"BastionGuard-ransomware-realtime.service",
"BastionGuard-usbd.service",
}

Definition at line 51 of file first-run-services-window.cpp.

Referenced by is_system_unit().