48 {
49
50 const std::string tmpDir = "/var/lib/clamav/sanesecurity.tmp";
51
52
53
54
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
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
72
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
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
102 std::cerr <<
_(
"⚠ Impossibile ricaricare il servizio ClamAV: servizio non trovato") <<
"\n";
103}
104
105 return copies_ok;
106}
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={})