Skip to content
API Documentation
BastionGuard™
BastionGuard::Platform Namespace Reference

Functions

std::string normalize_os_release_value (std::string value)
std::unordered_map< std::string, std::string > read_os_release ()
std::string distribution_id ()
bool is_fedora_rhel_family ()
bool is_ubuntu_family ()
bool is_mageia ()
bool is_openmandriva ()
bool is_opensuse ()
bool cef_daemon_supported ()
bool cef_available ()
bool cef_daemon_available ()

Function Documentation

◆ cef_available()

◆ cef_daemon_available()

bool BastionGuard::Platform::cef_daemon_available ( )
inline

Definition at line 146 of file DistroUtils.hpp.

146 {
147 return BASTIONGUARD_HAS_CEF_DAEMON != 0 &&
149 }
#define BASTIONGUARD_HAS_CEF_DAEMON

References BASTIONGUARD_HAS_CEF_DAEMON, cef_daemon_available(), and cef_daemon_supported().

Referenced by cef_daemon_available().

◆ cef_daemon_supported()

◆ distribution_id()

std::string BastionGuard::Platform::distribution_id ( )
inline

Definition at line 60 of file DistroUtils.hpp.

60 {
61 const auto values = read_os_release();
62 const auto iterator = values.find("ID");
63
64 if (iterator == values.end()) {
65 return {};
66 }
67
68 return iterator->second;
69 }
std::unordered_map< std::string, std::string > read_os_release()

References distribution_id(), and read_os_release().

Referenced by detectDistro(), distribution_id(), is_fedora_rhel_family(), is_mageia(), is_openmandriva(), is_opensuse(), and is_ubuntu_family().

◆ is_fedora_rhel_family()

bool BastionGuard::Platform::is_fedora_rhel_family ( )
inline

Definition at line 71 of file DistroUtils.hpp.

71 {
72 const std::string id = distribution_id();
73
74 return id == "fedora" ||
75 id == "rhel" ||
76 id == "redhat" ||
77 id == "centos" ||
78 id == "almalinux" ||
79 id == "alma" ||
80 id == "rocky" ||
81 id == "rockylinux" ||
82 id == "ol";
83 }
std::string distribution_id()

References distribution_id(), and is_fedora_rhel_family().

Referenced by cef_daemon_supported(), CaInstaller::ensure_trusted(), BastionGuard::wizard::gen_cert_commands(), BastionGuard::wizard::install_system_ca(), CaInstaller::install_system_via_pkexec(), is_fedora_rhel_family(), BastionGuard::wizard::run_wizard_setup(), and BastionGuard::wizard::setup_certificates().

◆ is_mageia()

bool BastionGuard::Platform::is_mageia ( )
inline

Definition at line 92 of file DistroUtils.hpp.

92 {
93 return distribution_id() == "mageia";
94 }

References distribution_id(), and is_mageia().

Referenced by cef_daemon_supported(), and is_mageia().

◆ is_openmandriva()

bool BastionGuard::Platform::is_openmandriva ( )
inline

Definition at line 96 of file DistroUtils.hpp.

96 {
97 const std::string id = distribution_id();
98
99 return id == "openmandriva" ||
100 id == "openmandriva_lx";
101 }

References distribution_id(), and is_openmandriva().

Referenced by cef_daemon_supported(), and is_openmandriva().

◆ is_opensuse()

bool BastionGuard::Platform::is_opensuse ( )
inline

Definition at line 103 of file DistroUtils.hpp.

103 {
104 const std::string id = distribution_id();
105
106 return id == "opensuse-leap" ||
107 id == "opensuse-tumbleweed" ||
108 id == "opensuse";
109 }

References distribution_id(), and is_opensuse().

Referenced by cef_daemon_supported(), and is_opensuse().

◆ is_ubuntu_family()

bool BastionGuard::Platform::is_ubuntu_family ( )
inline

Definition at line 85 of file DistroUtils.hpp.

85 {
86 const std::string id = distribution_id();
87
88 return id == "ubuntu" ||
89 id == "linuxmint";
90 }

References distribution_id(), and is_ubuntu_family().

Referenced by cef_daemon_supported(), and is_ubuntu_family().

◆ normalize_os_release_value()

std::string BastionGuard::Platform::normalize_os_release_value ( std::string value)
inline

Definition at line 20 of file DistroUtils.hpp.

20 {
21 if (value.size() >= 2 && value.front() == '"' && value.back() == '"') {
22 value = value.substr(1, value.size() - 2);
23 }
24
25 std::transform(
26 value.begin(),
27 value.end(),
28 value.begin(),
29 [](unsigned char c) {
30 return static_cast<char>(std::tolower(c));
31 }
32 );
33
34 return value;
35 }

References normalize_os_release_value().

Referenced by normalize_os_release_value(), and read_os_release().

◆ read_os_release()

std::unordered_map< std::string, std::string > BastionGuard::Platform::read_os_release ( )
inline

Definition at line 37 of file DistroUtils.hpp.

37 {
38 std::unordered_map<std::string, std::string> values;
39
40 std::ifstream input("/etc/os-release");
41 std::string line;
42
43 while (std::getline(input, line)) {
44 if (line.empty() || line.front() == '#') {
45 continue;
46 }
47
48 const auto separator = line.find('=');
49 if (separator == std::string::npos) {
50 continue;
51 }
52
53 values[line.substr(0, separator)] =
54 normalize_os_release_value(line.substr(separator + 1));
55 }
56
57 return values;
58 }
std::string normalize_os_release_value(std::string value)

References normalize_os_release_value(), and read_os_release().

Referenced by distribution_id(), and read_os_release().