Skip to content
API Documentation
BastionGuard™
DistroUtils.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 */
9
10#pragma once
11
12#include <algorithm>
13#include <cctype>
14#include <fstream>
15#include <string>
16#include <unordered_map>
17
19
20 inline std::string normalize_os_release_value(std::string value) {
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 }
36
37 inline std::unordered_map<std::string, std::string> read_os_release() {
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 }
59
60 inline std::string distribution_id() {
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 }
70
71 inline bool is_fedora_rhel_family() {
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 }
84
85 inline bool is_ubuntu_family() {
86 const std::string id = distribution_id();
87
88 return id == "ubuntu" ||
89 id == "linuxmint";
90 }
91
92 inline bool is_mageia() {
93 return distribution_id() == "mageia";
94 }
95
96 inline bool is_openmandriva() {
97 const std::string id = distribution_id();
98
99 return id == "openmandriva" ||
100 id == "openmandriva_lx";
101 }
102
103 inline bool is_opensuse() {
104 const std::string id = distribution_id();
105
106 return id == "opensuse-leap" ||
107 id == "opensuse-tumbleweed" ||
108 id == "opensuse";
109 }
110
111 /*
112 * Il daemon CEF e l'installazione della CA di sistema sono disabilitati
113 * su Fedora/RHEL, Ubuntu, Linux Mint, Mageia, OpenMandriva e openSUSE.
114 *
115 * Debian non viene incluso.
116 */
117 inline bool cef_daemon_supported() {
118 return !is_fedora_rhel_family() &&
119 !is_ubuntu_family() &&
120 !is_mageia() &&
121 !is_openmandriva() &&
122 !is_opensuse();
123 }
124
125 #ifndef BASTIONGUARD_HAS_EMBEDDED_CEF
126 #define BASTIONGUARD_HAS_EMBEDDED_CEF 1
127 #endif
128
129 #ifndef BASTIONGUARD_HAS_CEF_DAEMON
130 #define BASTIONGUARD_HAS_CEF_DAEMON 1
131 #endif
132
133 /*
134 * CEF embedded:
135 * Secure Browser, Bank GUI, Bank Opener e Secure Payments.
136 *
137 * Non dipende dalla distribuzione.
138 */
139 inline bool cef_available() {
141 }
142
143 /*
144 * Solo daemon proxy CEF e funzionalità collegate alla CA.
145 */
146 inline bool cef_daemon_available() {
147 return BASTIONGUARD_HAS_CEF_DAEMON != 0 &&
149 }
150
151} // namespace BastionGuard::Platform
#define BASTIONGUARD_HAS_EMBEDDED_CEF
#define BASTIONGUARD_HAS_CEF_DAEMON
std::string normalize_os_release_value(std::string value)
std::unordered_map< std::string, std::string > read_os_release()
std::string distribution_id()