mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 10:23:17 +00:00
Add option to disable the cache. Add a new bitfield in the engine struct that will govern options relating to engine internals.
This commit is contained in:
parent
1af0323cae
commit
34e9acb098
8 changed files with 59 additions and 1 deletions
|
@ -338,6 +338,9 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
|
||||
if (optget(opts, "disable-cache")->enabled)
|
||||
cl_engine_set_num(engine, CL_ENGINE_DISABLE_CACHE, 1);
|
||||
|
||||
/* load the database(s) */
|
||||
dbdir = optget(opts, "DatabaseDirectory")->strarg;
|
||||
logg("#Reading databases from %s\n", dbdir);
|
||||
|
|
|
@ -567,6 +567,9 @@ int scanmanager(const struct optstruct *opts)
|
|||
return 2;
|
||||
}
|
||||
|
||||
if (optget(opts, "disable-cache")->enabled)
|
||||
cl_engine_set_num(engine, CL_ENGINE_DISABLE_CACHE, 1);
|
||||
|
||||
if(optget(opts, "detect-pua")->enabled) {
|
||||
dboptions |= CL_DB_PUA;
|
||||
if((opt = optget(opts, "exclude-pua"))->enabled) {
|
||||
|
|
|
@ -246,6 +246,13 @@ Example
|
|||
# when the LeaveTemporaryFiles option is enabled.
|
||||
#ForceToDisk yes
|
||||
|
||||
# This option allows you to disable the caching feature of the engine. By
|
||||
# default, the engine will store an MD5 in a cache of any files that are
|
||||
# not flagged as virus or that hit limits checks. Disabling the cache will
|
||||
# have a negative performance impact on large scans.
|
||||
# Default: no
|
||||
#DisableCache yes
|
||||
|
||||
##
|
||||
## Executable files
|
||||
##
|
||||
|
|
|
@ -743,6 +743,11 @@ int cli_cache_init(struct cl_engine *engine) {
|
|||
struct CACHE *cache;
|
||||
unsigned int i, j;
|
||||
|
||||
if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) {
|
||||
cli_dbgmsg("cli_cache_init: Caching disabled.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!engine) {
|
||||
cli_errmsg("cli_cache_init: mpool malloc fail\n");
|
||||
return 1;
|
||||
|
@ -777,6 +782,10 @@ void cli_cache_destroy(struct cl_engine *engine) {
|
|||
struct CACHE *cache;
|
||||
unsigned int i;
|
||||
|
||||
if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!engine || !(cache = engine->cache))
|
||||
return;
|
||||
|
||||
|
@ -813,6 +822,11 @@ void cache_add(unsigned char *md5, size_t size, cli_ctx *ctx) {
|
|||
uint32_t level;
|
||||
struct CACHE *c;
|
||||
|
||||
if (ctx->engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) {
|
||||
cli_dbgmsg("cache_add: Caching disabled. Not adding sample to cache.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ctx || !ctx->engine || !ctx->engine->cache)
|
||||
return;
|
||||
|
||||
|
@ -851,6 +865,11 @@ void cache_remove(unsigned char *md5, size_t size, const struct cl_engine *engin
|
|||
unsigned int key = getkey(md5);
|
||||
struct CACHE *c;
|
||||
|
||||
if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) {
|
||||
cli_dbgmsg("cache_remove: Caching disabled.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!engine || !engine->cache)
|
||||
return;
|
||||
|
||||
|
@ -886,6 +905,11 @@ int cache_check(unsigned char *hash, cli_ctx *ctx) {
|
|||
cli_md5_ctx md5;
|
||||
int ret;
|
||||
|
||||
if (ctx->engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) {
|
||||
cli_dbgmsg("cache_check: Caching disabled. Returning CL_VIRUS.\n");
|
||||
return CL_VIRUS;
|
||||
}
|
||||
|
||||
if(!ctx || !ctx->engine || !ctx->engine->cache)
|
||||
return CL_VIRUS;
|
||||
|
||||
|
|
|
@ -194,7 +194,8 @@ enum cl_engine_field {
|
|||
CL_ENGINE_MAX_HTMLNOTAGS, /* uint64_t */
|
||||
CL_ENGINE_MAX_SCRIPTNORMALIZE, /* uint64_t */
|
||||
CL_ENGINE_MAX_ZIPTYPERCG, /* uint64_t */
|
||||
CL_ENGINE_FORCETODISK /* uint32_t */
|
||||
CL_ENGINE_FORCETODISK, /* uint32_t */
|
||||
CL_ENGINE_DISABLE_CACHE /* uint32_t */
|
||||
};
|
||||
|
||||
enum bytecode_security {
|
||||
|
@ -232,6 +233,13 @@ extern int cl_engine_addref(struct cl_engine *engine);
|
|||
|
||||
extern int cl_engine_free(struct cl_engine *engine);
|
||||
|
||||
extern void cli_cache_disable(void);
|
||||
|
||||
extern int cli_cache_enable(struct cl_engine *engine);
|
||||
|
||||
/* For the new engine_options bit field in the engine */
|
||||
#define ENGINE_OPTIONS_NONE 0
|
||||
#define ENGINE_OPTIONS_DISABLE_CACHE 1
|
||||
|
||||
/* CALLBACKS */
|
||||
|
||||
|
|
|
@ -490,6 +490,15 @@ int cl_engine_set_num(struct cl_engine *engine, enum cl_engine_field field, long
|
|||
if (num == CL_BYTECODE_MODE_TEST)
|
||||
cli_infomsg(NULL, "bytecode engine in test mode\n");
|
||||
break;
|
||||
case CL_ENGINE_DISABLE_CACHE:
|
||||
if (num) {
|
||||
engine->engine_options |= ENGINE_OPTIONS_DISABLE_CACHE;
|
||||
} else {
|
||||
engine->engine_options &= ~(ENGINE_OPTIONS_DISABLE_CACHE);
|
||||
if (!(engine->cache))
|
||||
cli_cache_init(engine);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cli_errmsg("cl_engine_set_num: Incorrect field number\n");
|
||||
return CL_EARG;
|
||||
|
|
|
@ -193,6 +193,7 @@ struct cl_engine {
|
|||
uint32_t ac_maxdepth;
|
||||
char *tmpdir;
|
||||
uint32_t keeptmp;
|
||||
uint64_t engine_options;
|
||||
|
||||
/* Limits */
|
||||
uint64_t maxscansize; /* during the scanning of archives this size
|
||||
|
@ -307,6 +308,7 @@ struct cl_settings {
|
|||
uint32_t bytecode_timeout;
|
||||
enum bytecode_mode bytecode_mode;
|
||||
char *pua_cats;
|
||||
uint64_t engine_options;
|
||||
|
||||
/* callbacks */
|
||||
clcb_pre_cache cb_pre_cache;
|
||||
|
|
|
@ -253,6 +253,8 @@ const struct clam_option __clam_options[] = {
|
|||
|
||||
{ "SelfCheck", NULL, 0, TYPE_NUMBER, MATCH_NUMBER, 600, NULL, 0, OPT_CLAMD, "This option specifies the time intervals (in seconds) in which clamd\nshould perform a database check.", "600" },
|
||||
|
||||
{ "DisableCache", "disable-cache", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_CLAMSCAN, "This option allows you to disable clamd's caching feature.", "no" },
|
||||
|
||||
{ "VirusEvent", NULL, 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD, "Execute a command when a virus is found. In the command string %v will be\nreplaced with the virus name. Additionally, two environment variables will\nbe defined: $CLAM_VIRUSEVENT_FILENAME and $CLAM_VIRUSEVENT_VIRUSNAME.", "/usr/bin/mailx -s \"ClamAV VIRUS ALERT: %v\" alert < /dev/null" },
|
||||
|
||||
{ "ExitOnOOM", NULL, 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD, "Stop the daemon when libclamav reports an out of memory condition.", "yes" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue