diff options
author | Mavridis Philippe <[email protected]> | 2021-08-05 08:43:25 +0000 |
---|---|---|
committer | Mavridis Philippe <[email protected]> | 2021-08-05 08:47:31 +0000 |
commit | 80c548d4be7fb02d2a6ad93bde2827f4603886fd (patch) | |
tree | 2a368c0f3cf2662ac44417e9d7df3755db3e2089 /src/klammail | |
parent | 824f93c1eb483ee8cd682207976bdcc7d94e4702 (diff) | |
download | klamav-80c548d4be7fb02d2a6ad93bde2827f4603886fd.tar.gz klamav-80c548d4be7fb02d2a6ad93bde2827f4603886fd.zip |
Modernize LibClamAV API usage
This should resolve issue #29.
Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'src/klammail')
-rwxr-xr-x | src/klammail/clamdmail.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/klammail/clamdmail.c b/src/klammail/clamdmail.c index 101e9b7..287de48 100755 --- a/src/klammail/clamdmail.c +++ b/src/klammail/clamdmail.c @@ -99,6 +99,7 @@ int clamdscan(struct optstruct *opt) long double mb; const char *virname; struct cl_engine *engine = NULL; + struct cl_scan_options options; struct stat sb; if(optc(opt, 'V')) { @@ -178,40 +179,48 @@ int clamdscan(struct optstruct *opt) /* Clamd isn't running, start it so it is available next time. */ startclamd(opt); - if((engine = cl_engine_new()) == NULL) { - printf("Database initialization error: %s\n", cl_strerror(ret));; + if ((ret = cl_init(CL_INIT_DEFAULT)) != CL_SUCCESS) { + printf("Can't initialize libclamav: %s\n", cl_strerror(ret)); + close(fd); + exit(2); + } + + if(!(engine = cl_engine_new())) { + printf("Cannot create scanner engine: %s\n", cl_strerror(ret));; cl_engine_free(engine); close(fd); exit(2); } if(optc(opt, 'd')) { - if((ret = cl_load(getargc(opt, 'd'), engine, &no, CL_DB_STDOPT))) { + if((ret = cl_load(getargc(opt, 'd'), engine, &no, CL_DB_STDOPT)) != CL_SUCCESS) { printf("cl_load: %s\n", cl_strerror(ret)); close(fd); return 50; } }else{ - if((ret = cl_load(cl_retdbdir(), engine, &no, CL_DB_STDOPT))) { - printf("cl_loaddbdir: %s\n", cl_strerror(ret)); - close(fd); - exit(2); + if((ret = cl_load(cl_retdbdir(), engine, &no, CL_DB_STDOPT)) != CL_SUCCESS) { + printf("cl_loaddbdir: %s\n", cl_strerror(ret)); + close(fd); + exit(2); } } /* build engine */ - if((ret = cl_engine_compile(engine))) { - printf("Database initialization error: %s\n", cl_strerror(ret));; + if((ret = cl_engine_compile(engine)) != CL_SUCCESS ) { + printf("Database initialization error: %s\n", cl_strerror(ret)); cl_engine_free(engine); close(fd); exit(2); } - ret = cl_scandesc(fd, tmpnm, &virname, &size, engine, - CL_SCAN_GENERAL_ALLMATCHES | CL_SCAN_GENERAL_HEURISTICS | - CL_SCAN_PARSE_ARCHIVE | CL_SCAN_PARSE_MAIL | CL_SCAN_PARSE_OLE2 | - CL_SCAN_PARSE_HTML | CL_SCAN_PARSE_PDF ); - printf("scandesc returned: %i\n", cl_strerror(ret));; + /* scan file descriptor */ + memset(&options, 0, sizeof(struct cl_scan_options)); + options.parse = ~0; // all parsers + options.general |= CL_SCAN_GENERAL_HEURISTICS; + options.mail |= CL_SCAN_MAIL_PARTIAL_MESSAGE; + ret = cl_scandesc(fd, tmpnm, &virname, &size, engine, &options ); + printf("scandesc returned: %i\n", cl_strerror(ret)); if( ret == CL_VIRUS ) printf("virus found\n"); else |