Klammail: fixed LibClamAV function calls

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/24/head
Mavridis Philippe 4 years ago
parent 522bc92a7e
commit 2d1fd0b275
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -41,6 +41,8 @@
#include "../version.h" #include "../version.h"
#include "../../config.h" #include "../../config.h"
#include "output.h"
#define BUFFSIZE 1024 #define BUFFSIZE 1024
@ -71,7 +73,7 @@ void startclamd(struct optstruct *opt);
struct s_info claminfo; struct s_info claminfo;
short printinfected = 0; short printinfected = 0;
short int mprintf_stdout; /* short int mprintf_stdout; */
int clamdscan(struct optstruct *opt) int clamdscan(struct optstruct *opt)
{ {
@ -97,9 +99,6 @@ 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;
#ifndef SUPPORT_CLAMAV_V095
struct cl_limits limits;
#endif
struct stat sb; struct stat sb;
if(optc(opt, 'V')) { if(optc(opt, 'V')) {
@ -158,12 +157,8 @@ int clamdscan(struct optstruct *opt)
} }
if(fsync(fd) == -1) { if(fsync(fd) == -1) {
close(fd); close(fd);
#ifdef SUPPORT_CLAMAV_V095 return CL_ETMPFILE;
return CL_ETMPFILE;
#else
return CL_EIO;
#endif
} }
close(fd); close(fd);
@ -182,30 +177,22 @@ int clamdscan(struct optstruct *opt)
if((ret == 2)) { if((ret == 2)) {
/* 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);
#ifdef SUPPORT_CLAMAV_V095
if((engine = cl_engine_new()) == NULL) { if((engine = cl_engine_new()) == NULL) {
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);
} }
#endif
if(optc(opt, 'd')) { if(optc(opt, 'd')) {
#ifdef SUPPORT_CLAMAV_V095
if((ret = cl_load(getargc(opt, 'd'), engine, &no, CL_DB_STDOPT))) { if((ret = cl_load(getargc(opt, 'd'), engine, &no, CL_DB_STDOPT))) {
#else
if((ret = cl_load(getargc(opt, 'd'), &engine, &no, CL_DB_STDOPT))) {
#endif
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{
#ifdef SUPPORT_CLAMAV_V095
if((ret = cl_load(cl_retdbdir(), engine, &no, CL_DB_STDOPT))) { if((ret = cl_load(cl_retdbdir(), engine, &no, CL_DB_STDOPT))) {
#else
if((ret = cl_loaddbdir(cl_retdbdir(), &engine, &no, CL_DB_STDOPT))) {
#endif
printf("cl_loaddbdir: %s\n", cl_strerror(ret)); printf("cl_loaddbdir: %s\n", cl_strerror(ret));
close(fd); close(fd);
exit(2); exit(2);
@ -213,42 +200,22 @@ int clamdscan(struct optstruct *opt)
} }
/* build engine */ /* build engine */
#ifdef SUPPORT_CLAMAV_V095
if((ret = cl_engine_compile(engine))) { if((ret = cl_engine_compile(engine))) {
#else
if((ret = cl_build(engine))) {
#endif
printf("Database initialization error: %s\n", cl_strerror(ret));; printf("Database initialization error: %s\n", cl_strerror(ret));;
#ifdef SUPPORT_CLAMAV_V095
cl_engine_free(engine); cl_engine_free(engine);
#else
cl_free(engine);
#endif
close(fd); close(fd);
exit(2); exit(2);
} }
#ifndef SUPPORT_CLAMAV_V095 ret = cl_scandesc(fd, tmpnm, &virname, &size, engine,
/* set up archive limits */ CL_SCAN_GENERAL_ALLMATCHES | CL_SCAN_GENERAL_HEURISTICS |
memset(&limits, 0, sizeof(struct cl_limits)); CL_SCAN_PARSE_ARCHIVE | CL_SCAN_PARSE_MAIL | CL_SCAN_PARSE_OLE2 |
limits.maxfiles = 1000; /* max files */ CL_SCAN_PARSE_HTML | CL_SCAN_PARSE_PDF );
limits.maxfilesize = 10 * 1048576; /* maximum size of archived/compressed
* file (files exceeding this limit
* will be ignored)
*/
/*limits.maxreclevel = 5;*/ /* maximum recursion level for archives */
/*limits.maxmailrec = 64;*/ /* maximum recursion level for mail files */
/*limits.maxratio = 200;*/ /* maximum compression ratio */
limits.archivememlim = 1;
#endif
#ifdef SUPPORT_CLAMAV_V095
ret = cl_scandesc(fd, &virname, &size, engine,
CL_SCAN_STDOPT | CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_HTML);
printf("scandesc returned: %i\n", cl_strerror(ret));; printf("scandesc returned: %i\n", cl_strerror(ret));;
#else if( ret == CL_VIRUS )
ret = cl_scandesc(fd, &virname, &size, engine, &limits, printf("virus found\n");
CL_SCAN_STDOPT | CL_ARCHIVE | CL_MAIL | CL_OLE2 | CL_SCAN_HTML); else
#endif printf("file clean\n");
} }
/* scan descriptor (with archive and mail scanning enabled) */ /* scan descriptor (with archive and mail scanning enabled) */
@ -258,11 +225,7 @@ int clamdscan(struct optstruct *opt)
spoolstdin(tmpnm, fd, ret, &virname, &bndrystore, opt); spoolstdin(tmpnm, fd, ret, &virname, &bndrystore, opt);
if((ret == 2)) if((ret == 2))
#ifdef SUPPORT_CLAMAV_V095
cl_engine_free(engine); cl_engine_free(engine);
#else
cl_free(engine);
#endif
unlink(tmpnm); unlink(tmpnm);
@ -582,11 +545,7 @@ void startclamd(struct optstruct *opt)
if ((strstr(cl_retver(), "0.8")) || (strstr(cl_retver(), "0.7"))) if ((strstr(cl_retver(), "0.8")) || (strstr(cl_retver(), "0.7")))
fprintf(tmp,"FixStaleSocket\n"); fprintf(tmp,"FixStaleSocket\n");
else else
#ifdef SUPPORT_CLAMAV_V095
fprintf(tmp,"FixStaleSocket yes\n"); fprintf(tmp,"FixStaleSocket yes\n");
#else
fprintf(tmp,"FixStaleSocket TRUE\n");
#endif
fflush(tmp); fflush(tmp);

Loading…
Cancel
Save