summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2021-08-05 08:43:25 +0000
committerMavridis Philippe <[email protected]>2021-08-05 13:42:51 +0000
commit85ac7555490a896b84add847933e5aa22c172c37 (patch)
tree1663314c0d957f01e0323b5cf998b31a8f44a552
parentf81c329356f73ebdd1c18b53b4309d336aea1c42 (diff)
downloadklamav-85ac7555490a896b84add847933e5aa22c172c37.tar.gz
klamav-85ac7555490a896b84add847933e5aa22c172c37.zip
Modernize LibClamAV API usage
This should resolve issue #29. Signed-off-by: Mavridis Philippe <[email protected]> (cherry picked from commit 80c548d4be7fb02d2a6ad93bde2827f4603886fd)
-rwxr-xr-xsrc/klammail/clamdmail.c37
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