This commit is contained in:
Green Sky 2023-10-25 02:44:30 +02:00
parent 9236a26d92
commit 150bbe05f7
No known key found for this signature in database
5 changed files with 20 additions and 5 deletions

View File

@ -10,7 +10,7 @@ target_include_directories(solanaceae_clamav PUBLIC .)
target_compile_features(solanaceae_clamav PUBLIC cxx_std_17) target_compile_features(solanaceae_clamav PUBLIC cxx_std_17)
target_link_libraries(solanaceae_clamav PUBLIC target_link_libraries(solanaceae_clamav PUBLIC
EXT_SOL::libclamav EXT_SOL::libclamav
#solanaceae_util solanaceae_util
) )
add_executable(solanaceae_clamav_test add_executable(solanaceae_clamav_test

View File

@ -1,5 +1,7 @@
#include "./clamav_module.hpp" #include "./clamav_module.hpp"
#include <solanaceae/util/config_model.hpp>
#include <clamav.h> #include <clamav.h>
#include <iostream> #include <iostream>
@ -9,7 +11,7 @@ extern "C" {
void sol_cl_msg_cb(enum cl_msg severity, const char *fullmsg, const char *msg, void *context); void sol_cl_msg_cb(enum cl_msg severity, const char *fullmsg, const char *msg, void *context);
}; };
ClamAVModule::ClamAVModule(void) { ClamAVModule::ClamAVModule(ConfigModelI& conf) : _conf(conf) {
if (cl_init(CL_INIT_DEFAULT) != CL_SUCCESS) { if (cl_init(CL_INIT_DEFAULT) != CL_SUCCESS) {
throw std::domain_error("clamav cl_init() failed"); throw std::domain_error("clamav cl_init() failed");
} }
@ -35,8 +37,12 @@ bool ClamAVModule::startEngine(void) {
return false; return false;
} }
std::string db_dir; std::string db_dir;
// TODO: load from config // TODO: load from config
if (_conf.has_string("ClamAVModule", "database_dir")) {
db_dir = _conf.get_string("ClamAVModule", "database_dir").value();
}
unsigned int signo = 0; unsigned int signo = 0;
@ -65,6 +71,9 @@ bool ClamAVModule::startEngine(void) {
} }
} }
// TODO: dont reset if not changed
_conf.set("ClamAVModule", "database_dir", db_dir);
std::cout << "signatures loaded: " << signo << "\n"; std::cout << "signatures loaded: " << signo << "\n";
if (cl_engine_compile(_clamav_engine) != CL_SUCCESS) { if (cl_engine_compile(_clamav_engine) != CL_SUCCESS) {

View File

@ -5,15 +5,17 @@
extern "C" { extern "C" {
struct cl_engine; struct cl_engine;
} }
struct ConfigModelI;
// blocking // blocking
class ClamAVModule : public ClamAVModuleInterface { class ClamAVModule : public ClamAVModuleInterface {
ConfigModelI& _conf;
cl_engine* _clamav_engine {nullptr}; cl_engine* _clamav_engine {nullptr};
bool startEngine(void); bool startEngine(void);
public: public:
ClamAVModule(void); ClamAVModule(ConfigModelI& conf);
~ClamAVModule(void); ~ClamAVModule(void);
ScanResult scanFilePath(std::string_view path); ScanResult scanFilePath(std::string_view path);

View File

@ -1,10 +1,13 @@
#include "./clamav_module.hpp" #include "./clamav_module.hpp"
#include <solanaceae/util/simple_config_model.hpp>
#include <iostream> #include <iostream>
int main(void) { int main(void) {
SimpleConfigModel scm;
ClamAVModule clamav; ClamAVModule clamav{scm};
auto [is_virus, virus_string] = clamav.scanFilePath("/home/green/Downloads/mal/f8c08d00ff6e8c6adb1a93cd133b19302d0b651afd73ccb54e3b6ac6c60d99c6"); auto [is_virus, virus_string] = clamav.scanFilePath("/home/green/Downloads/mal/f8c08d00ff6e8c6adb1a93cd133b19302d0b651afd73ccb54e3b6ac6c60d99c6");
if (is_virus) { if (is_virus) {
@ -13,6 +16,8 @@ int main(void) {
std::cout << "not virus: " << virus_string << "\n"; std::cout << "not virus: " << virus_string << "\n";
} }
scm.dump();
return 0; return 0;
} }

View File

@ -1 +0,0 @@
#include <clamav.h>