185{
187
188 try {
192
193 if (options.checkOnly)
194 return EXIT_SUCCESS;
195
199
202 eventSink.
add(consoleSink);
203
204 std::unique_ptr<JsonEventSink> jsonSink;
206 if (
const auto parent = policy.
eventLog.parent_path(); !parent.empty())
207 std::filesystem::create_directories(parent);
208 jsonSink = std::make_unique<JsonEventSink>(policy.
eventLog);
209 eventSink.
add(*jsonSink);
210 }
211
212 const auto automaticServiceBlockingEnabled = [](
const Policy& activePolicy) {
213 return activePolicy.autoBlockSystemServices &&
216 };
218 eventSink, automaticServiceBlockingEnabled(policy));
223
224 std::cerr << "BastionGuard RootGuard avviato: trusted-app caricati="
229 for (
const auto& warning : report.
warnings)
230 std::cerr << "RootGuard policy warning: " << warning << '\n';
231
233 const int result = engine.pollOnce(250);
234 if (result < 0)
235 throw std::runtime_error("errore ring buffer: " + std::to_string(result));
236
237 engine.runIntegrityCheckIfDue();
238
241 bool auditEntered = false;
242 try {
243
244
245
246
247
248 engine.enterAuditMode();
249 auditEntered = true;
250 responseSink.setAutoBlockSystemServices(false);
253 const auto previousEventLog = policy.
eventLog;
254 const auto reloadedReport = engine.reloadPolicy(reloaded);
255 policy = std::move(reloaded);
256 responseSink.setAutoBlockSystemServices(
257 automaticServiceBlockingEnabled(policy));
260 std::cerr << "RootGuard policy ricaricata: trusted-app="
261 << reloadedReport.trustedApplicationsLoaded
262 << " trusted="
263 << reloadedReport.trustedLoaded << " denied="
264 << reloadedReport.deniedLoaded << " protected="
265 << reloadedReport.protectedLoaded << '\n';
266 if (policy.
eventLog != previousEventLog) {
267 std::cerr << "nota: una modifica di event_log richiede riavvio\n";
268 }
269 } catch (const std::exception& error) {
270 std::cerr << "ricaricamento policy fallito; "
271 << (auditEntered
272 ? "motore lasciato in audit: "
273 : "impossibile garantire il passaggio in audit: ")
274 << error.what() << '\n';
275 }
276 }
277 }
278 std::filesystem::remove("/run/bastionguard-rootguard.status");
279 } catch (const std::exception& error) {
280 std::filesystem::remove("/run/bastionguard-rootguard.status");
281 std::cerr << "RootGuard: " << error.what() << '\n';
282 return EXIT_FAILURE;
283 }
284
285 return EXIT_SUCCESS;
286}
void add(IEventSink &sink)
Options parseOptions(const int argc, char *argv[])
void handleStopSignal(int) noexcept
bastionguard::rootguard::Policy auditRuntimePolicy(bastionguard::rootguard::Policy policy)
volatile std::sig_atomic_t gStopRequested
void printPolicySummary(const bastionguard::rootguard::Policy &policy)
void writeRuntimePolicyView(const bastionguard::rootguard::Policy &policy)
void writeRuntimeStatus(const bastionguard::rootguard::Policy &policy)
void handleReloadSignal(int) noexcept
volatile std::sig_atomic_t gReloadRequested
bastionguard::rootguard::Policy loadPolicy(const Options &options)
std::size_t protectedLoaded
std::size_t trustedApplicationsLoaded
std::vector< std::string > warnings
std::size_t trustedLoaded
std::filesystem::path eventLog