46 ret = cl_init(CL_INIT_DEFAULT);
47 if (ret != CL_SUCCESS) {
48 std::stringstream msg;
49 msg <<
"cl_init() error: " << cl_strerror(ret);
80 "Can't create new virus scan engine.");
85 ret = cl_load(cl_retdbdir(), e, &sigs, CL_DB_STDOPT);
86 if (ret != CL_SUCCESS) {
87 std::stringstream msg;
88 msg <<
"cl_retdbdir() error: " << cl_strerror(ret);
93 std::stringstream msg;
94 msg << sigs <<
" signatures loaded";
97 if ((ret = cl_engine_compile(e)) != CL_SUCCESS) {
98 std::stringstream msg;
99 msg <<
"cl_engine_compile() error: " << cl_strerror(ret);
108 std::stringstream msg;
111 version = (uint) cl_engine_get_num(e, CL_ENGINE_DB_VERSION, &err);
112 if (err != CL_SUCCESS) {
115 db_time = (time_t) cl_engine_get_num(e, CL_ENGINE_DB_TIME, &err);
116 if (err != CL_SUCCESS) {
119 timeinfo = gmtime(&db_time);
120 strftime(buffer,
sizeof (buffer),
"%F %T UTC", timeinfo);
121 msg <<
"ClamAV database version " << version <<
", " << buffer;
133 ret = cl_engine_free(e);
135 std::stringstream msg;
136 msg <<
"cl_engine_free() error: " << cl_strerror(ret);
148 struct cl_engine *ret = NULL;
185 if (cl_statchkdir(&
dbstat) == 1) {
188 cl_statinidir(cl_retdbdir(), &
dbstat);
197 memset(&
dbstat, 0,
sizeof (
struct cl_stat));
198 cl_statinidir(cl_retdbdir(), &
dbstat);
216 char path[PATH_MAX + 1];
217 std::stringstream msg;
219 snprintf(path,
sizeof (path),
"/proc/self/fd/%d", fd);
220 path_len = readlink(path, path,
sizeof (path) - 1);
224 path[path_len] =
'\0';
225 msg <<
"Virus \"" << virname <<
"\" detected in file \"" << path <<
"\".";
248 ret = cl_scandesc(fd, &virname, NULL,
getEngine(), CL_SCAN_STDOPT);
258 std::stringstream msg;
259 msg <<
"cl_scandesc() error: " << cl_strerror(ret);
277 struct timespec interval = {
281 struct timespec interval2 = {
287 vs =
static_cast<VirusScan *
> (virusScan);
293 nanosleep(&interval, NULL);
299 "ClamAV database update detected.");
312 nanosleep(&interval2, NULL);
322 "Using updated ClamAV database.");
338 struct timespec interval = {
345 nanosleep(&interval, NULL);
~VirusScan()
Deletes the virus scanner.
int engineRefCount
Reference count of virus scan enginge.
void dbstat_free()
Frees database status.
pthread_t updateThread
Thrad for updating.
static void version()
Shows version information and exits.
Error, e.g. malfunction of the code, malware detected.
void log_virus_found(const int fd, const char *virname)
Writes log entry.
Status
Status of virus scanning.
struct cl_engine * getEngine()
Gets reference to virus scan engine.
struct cl_engine * createEngine()
Creates a new virus scan engine.
static void * updater(void *)
Thread to update engine.
struct cl_stat dbstat
Struture indicating if database has changed.
pthread_mutex_t mutexEngine
Mutex for accessing the engine.
Environment * env
environment
void destroyEngine(cl_engine *)
void clear()
Removes all entries from the cache.
Information, e.g. access scanning has started.
static void message(const enum Level, const std::string &)
Sends message.
int scan(const int fd)
Scans file for virus.
pthread_mutex_t mutexUpdate
Mutex for accessing the engine.
int isCleanCacheOnUpdate()
Determines if cache shall be cleaned when the virus scanner receives a new pattern file...
void dbstat_clear()
Clears database status.
int dbstat_check()
Checks if database has changed. 0 = unchanged, 1 = changed.
ScanCache * getScanCache()
Gets the scan cache.
struct cl_engine * engine
Reference to virus scan engine.
VirusScan(Environment *)
Initializes virus scan engine.
Debugging information only to be shown in the console.
The environment holds variables that are shared by instances of multiple classes. ...
int createThread()
Creates a new thread for managing the scan engine.