Skip to content
API Documentation
BastionGuard™
SaneSecurityUpdater Class Reference

#include <SaneSecurityUpdater.hpp>

Static Public Member Functions

static bool runHeadless ()

Detailed Description

Definition at line 24 of file SaneSecurityUpdater.hpp.

Member Function Documentation

◆ runHeadless()

bool SaneSecurityUpdater::runHeadless ( )
static

Definition at line 48 of file SaneSecurityUpdater.cpp.

48 {
49
50 const std::string tmpDir = "/var/lib/clamav/sanesecurity.tmp";
51
52
53 // Fixed working directory and argument-vector execution: no root shell.
54 // Keep deletion confined to this directory, never to /var/lib/clamav.
55 namespace fs = std::filesystem;
56 std::error_code ec;
57 fs::remove_all(tmpDir, ec);
58 if (ec || !fs::create_directories(tmpDir, ec) || ec) {
59 std::cerr << _("Errore: impossibile creare la cartella temporanea") << std::endl;
60 return false;
61 }
62
63 const auto sync = bg_process::run({"rsync", "-av", "--delete", "--",
64 "rsync://rsync.sanesecurity.net/sanesecurity", tmpDir + "/"}, true);
65 if (!sync.ok()) {
66 std::cerr << _("Errore durante rsync") << std::endl;
67 fs::remove_all(tmpDir, ec);
68 return false;
69 }
70
71 // Never evaluate downloaded filenames as shell metacharacters.
72 // Copy only extensions that ClamAV/SaneSecurity expects.
73 const std::vector<std::string> extensions = {
74 ".ndb", ".hdb", ".ldb", ".yar", ".yara", ".ign2", ".txt"
75 };
76 bool copies_ok = true;
77 for (const auto& entry : fs::directory_iterator(tmpDir, ec)) {
78 if (ec) { copies_ok = false; break; }
79 // Never follow symlinks provided by an external rsync mirror.
80 if (entry.is_symlink(ec) || ec) {
81 copies_ok = false;
82 ec.clear();
83 continue;
84 }
85 if (!entry.is_regular_file(ec) || ec) {
86 ec.clear();
87 continue;
88 }
89 const auto extension = entry.path().extension().string();
90 if (std::find(extensions.begin(), extensions.end(), extension) == extensions.end()) continue;
91 const fs::path destination = fs::path("/var/lib/clamav") / entry.path().filename();
92 fs::copy_file(entry.path(), destination, fs::copy_options::overwrite_existing, ec);
93 if (ec) {
94 copies_ok = false;
95 ec.clear();
96 }
97 }
98 fs::remove_all(tmpDir, ec);
99 if (!copies_ok) std::cerr << _("Errore copiando i file SaneSecurity") << std::endl;
100
101 if (!reload_clamav_service()) {
102 std::cerr << _("⚠ Impossibile ricaricare il servizio ClamAV: servizio non trovato") << "\n";
103}
104
105 return copies_ok;
106}
#define _(s)
static bool reload_clamav_service()
Result run(const std::vector< std::string > &args, bool merge_stderr=false, std::size_t limit=8U *1024U *1024U, const std::map< std::string, std::string > &environment={}, const std::function< bool(const std::string &)> &on_line={})

References _, reload_clamav_service(), and bg_process::run().

Referenced by main().


The documentation for this class was generated from the following files: