Modernize LibClamAV API usage

This should resolve issue #29.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/30/head
Mavridis Philippe 3 years ago
parent 824f93c1eb
commit 80c548d4be
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -99,6 +99,7 @@ int clamdscan(struct optstruct *opt)
long double mb; long double mb;
const char *virname; const char *virname;
struct cl_engine *engine = NULL; struct cl_engine *engine = NULL;
struct cl_scan_options options;
struct stat sb; struct stat sb;
if(optc(opt, 'V')) { 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. */ /* Clamd isn't running, start it so it is available next time. */
startclamd(opt); startclamd(opt);
if((engine = cl_engine_new()) == NULL) { if ((ret = cl_init(CL_INIT_DEFAULT)) != CL_SUCCESS) {
printf("Database initialization error: %s\n", cl_strerror(ret));; 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); cl_engine_free(engine);
close(fd); close(fd);
exit(2); exit(2);
} }
if(optc(opt, 'd')) { 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)); printf("cl_load: %s\n", cl_strerror(ret));
close(fd); close(fd);
return 50; return 50;
} }
}else{ }else{
if((ret = cl_load(cl_retdbdir(), engine, &no, CL_DB_STDOPT))) { if((ret = cl_load(cl_retdbdir(), engine, &no, CL_DB_STDOPT)) != CL_SUCCESS) {
printf("cl_loaddbdir: %s\n", cl_strerror(ret)); printf("cl_loaddbdir: %s\n", cl_strerror(ret));
close(fd); close(fd);
exit(2); exit(2);
} }
} }
/* build engine */ /* build engine */
if((ret = cl_engine_compile(engine))) { if((ret = cl_engine_compile(engine)) != CL_SUCCESS ) {
printf("Database initialization error: %s\n", cl_strerror(ret));; printf("Database initialization error: %s\n", cl_strerror(ret));
cl_engine_free(engine); cl_engine_free(engine);
close(fd); close(fd);
exit(2); exit(2);
} }
ret = cl_scandesc(fd, tmpnm, &virname, &size, engine, /* scan file descriptor */
CL_SCAN_GENERAL_ALLMATCHES | CL_SCAN_GENERAL_HEURISTICS | memset(&options, 0, sizeof(struct cl_scan_options));
CL_SCAN_PARSE_ARCHIVE | CL_SCAN_PARSE_MAIL | CL_SCAN_PARSE_OLE2 | options.parse = ~0; // all parsers
CL_SCAN_PARSE_HTML | CL_SCAN_PARSE_PDF ); options.general |= CL_SCAN_GENERAL_HEURISTICS;
printf("scandesc returned: %i\n", cl_strerror(ret));; 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 ) if( ret == CL_VIRUS )
printf("virus found\n"); printf("virus found\n");
else else

Loading…
Cancel
Save