git-svn: trunk@4933
Tomasz Kojm authored on 2009/03/13 00:21:36... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Thu Mar 12 16:22:36 CET 2009 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav, clamd, clamscan: replace cl_engine_(set|get) with |
|
4 |
+ cl_engine_set_(num|str) and cl_engine_get_(num|str) |
|
5 |
+ |
|
1 | 6 |
Thu Mar 12 16:57:45 EET 2009 (edwin) |
2 | 7 |
------------------------------------ |
3 | 8 |
* libclamav/others_common.c: typo |
... | ... |
@@ -106,7 +106,6 @@ int main(int argc, char **argv) |
106 | 106 |
unsigned int sigs = 0; |
107 | 107 |
int lsockets[2], nlsockets = 0; |
108 | 108 |
unsigned int dboptions = 0; |
109 |
- uint32_t val32; |
|
110 | 109 |
#ifdef C_LINUX |
111 | 110 |
struct stat sb; |
112 | 111 |
#endif |
... | ... |
@@ -365,8 +364,8 @@ int main(int argc, char **argv) |
365 | 365 |
} |
366 | 366 |
|
367 | 367 |
if(pua_cats) { |
368 |
- if((ret = cl_engine_set(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) { |
|
369 |
- logg("!cli_engine_set(CL_ENGINE_PUA_CATEGORIES) failed: %s\n", cl_strerror(ret)); |
|
368 |
+ if((ret = cl_engine_set_str(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) { |
|
369 |
+ logg("!cli_engine_set_str(CL_ENGINE_PUA_CATEGORIES) failed: %s\n", cl_strerror(ret)); |
|
370 | 370 |
free(pua_cats); |
371 | 371 |
ret = 1; |
372 | 372 |
break; |
... | ... |
@@ -379,17 +378,15 @@ int main(int argc, char **argv) |
379 | 379 |
|
380 | 380 |
/* set the temporary dir */ |
381 | 381 |
if((opt = optget(opts, "TemporaryDirectory"))->enabled) { |
382 |
- if((ret = cl_engine_set(engine, CL_ENGINE_TMPDIR, opt->strarg))) { |
|
383 |
- logg("!cli_engine_set(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret)); |
|
382 |
+ if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) { |
|
383 |
+ logg("!cli_engine_set_str(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret)); |
|
384 | 384 |
ret = 1; |
385 | 385 |
break; |
386 | 386 |
} |
387 | 387 |
} |
388 | 388 |
|
389 |
- if(optget(opts, "LeaveTemporaryFiles")->enabled) { |
|
390 |
- val32 = 1; |
|
391 |
- cl_engine_set(engine, CL_ENGINE_KEEPTMP, &val32); |
|
392 |
- } |
|
389 |
+ if(optget(opts, "LeaveTemporaryFiles")->enabled) |
|
390 |
+ cl_engine_set_num(engine, CL_ENGINE_KEEPTMP, 1); |
|
393 | 391 |
|
394 | 392 |
if(optget(opts, "PhishingSignatures")->enabled) |
395 | 393 |
dboptions |= CL_DB_PHISHING; |
... | ... |
@@ -403,13 +400,11 @@ int main(int argc, char **argv) |
403 | 403 |
|
404 | 404 |
if(optget(opts,"DevACOnly")->enabled) { |
405 | 405 |
logg("#Only using the A-C matcher.\n"); |
406 |
- val32 = 1; |
|
407 |
- cl_engine_set(engine, CL_ENGINE_AC_ONLY, &val32); |
|
406 |
+ cl_engine_set_num(engine, CL_ENGINE_AC_ONLY, 1); |
|
408 | 407 |
} |
409 | 408 |
|
410 | 409 |
if((opt = optget(opts, "DevACDepth"))->enabled) { |
411 |
- val32 = opt->numarg; |
|
412 |
- cl_engine_set(engine, CL_ENGINE_AC_MAXDEPTH, &val32); |
|
410 |
+ cl_engine_set_num(engine, CL_ENGINE_AC_MAXDEPTH, opt->numarg); |
|
413 | 411 |
logg("#Max A-C depth set to %u\n", opt->numarg); |
414 | 412 |
} |
415 | 413 |
|
... | ... |
@@ -692,8 +692,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
692 | 692 |
char buff[BUFFSIZE + 1]; |
693 | 693 |
pid_t mainpid; |
694 | 694 |
int idletimeout; |
695 |
- uint32_t val32; |
|
696 |
- uint64_t val64; |
|
695 |
+ unsigned long long val; |
|
697 | 696 |
size_t i, j, rr_last = 0; |
698 | 697 |
pthread_t accept_th; |
699 | 698 |
struct acceptdata acceptdata = ACCEPTDATA_INIT; |
... | ... |
@@ -714,40 +713,36 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
714 | 714 |
|
715 | 715 |
/* set up limits */ |
716 | 716 |
if((opt = optget(opts, "MaxScanSize"))->enabled) { |
717 |
- val64 = opt->numarg; |
|
718 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_SCANSIZE, &val64))) { |
|
719 |
- logg("!cli_engine_set(CL_ENGINE_MAX_SCANSIZE) failed: %s\n", cl_strerror(ret)); |
|
717 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_SCANSIZE, opt->numarg))) { |
|
718 |
+ logg("!cl_engine_set_num(CL_ENGINE_MAX_SCANSIZE) failed: %s\n", cl_strerror(ret)); |
|
720 | 719 |
cl_engine_free(engine); |
721 | 720 |
return 1; |
722 | 721 |
} |
723 | 722 |
} |
724 |
- cl_engine_get(engine, CL_ENGINE_MAX_SCANSIZE, &val64); |
|
725 |
- if(val64) |
|
726 |
- logg("Limits: Global size limit set to %llu bytes.\n", (unsigned long long) val64); |
|
723 |
+ val = cl_engine_get_num(engine, CL_ENGINE_MAX_SCANSIZE, NULL); |
|
724 |
+ if(val) |
|
725 |
+ logg("Limits: Global size limit set to %llu bytes.\n", val); |
|
727 | 726 |
else |
728 | 727 |
logg("^Limits: Global size limit protection disabled.\n"); |
729 | 728 |
|
730 | 729 |
if((opt = optget(opts, "MaxFileSize"))->enabled) { |
731 |
- val64 = opt->numarg; |
|
732 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_FILESIZE, &val64))) { |
|
733 |
- logg("!cli_engine_set(CL_ENGINE_MAX_FILESIZE) failed: %s\n", cl_strerror(ret)); |
|
730 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_FILESIZE, opt->numarg))) { |
|
731 |
+ logg("!cl_engine_set_num(CL_ENGINE_MAX_FILESIZE) failed: %s\n", cl_strerror(ret)); |
|
734 | 732 |
cl_engine_free(engine); |
735 | 733 |
return 1; |
736 | 734 |
} |
737 | 735 |
} |
738 |
- cl_engine_get(engine, CL_ENGINE_MAX_FILESIZE, &val64); |
|
739 |
- if(val64) |
|
740 |
- logg("Limits: File size limit set to %llu bytes.\n", (unsigned long long) val64); |
|
736 |
+ val = cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL); |
|
737 |
+ if(val) |
|
738 |
+ logg("Limits: File size limit set to %llu bytes.\n", val); |
|
741 | 739 |
else |
742 | 740 |
logg("^Limits: File size limit protection disabled.\n"); |
743 | 741 |
|
744 | 742 |
#ifndef C_WINDOWS |
745 | 743 |
if(getrlimit(RLIMIT_FSIZE, &rlim) == 0) { |
746 |
- cl_engine_get(engine, CL_ENGINE_MAX_FILESIZE, &val64); |
|
747 |
- if(rlim.rlim_max < val64) |
|
744 |
+ if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL)) |
|
748 | 745 |
logg("^System limit for file size is lower than engine->maxfilesize\n"); |
749 |
- cl_engine_get(engine, CL_ENGINE_MAX_SCANSIZE, &val64); |
|
750 |
- if(rlim.rlim_max < val64) |
|
746 |
+ if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_SCANSIZE, NULL)) |
|
751 | 747 |
logg("^System limit for file size is lower than engine->maxscansize\n"); |
752 | 748 |
} else { |
753 | 749 |
logg("^Cannot obtain resource limits for file size\n"); |
... | ... |
@@ -755,30 +750,28 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
755 | 755 |
#endif |
756 | 756 |
|
757 | 757 |
if((opt = optget(opts, "MaxRecursion"))->enabled) { |
758 |
- val32 = opt->numarg; |
|
759 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_RECURSION, &val32))) { |
|
760 |
- logg("!cli_engine_set(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret)); |
|
758 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_RECURSION, opt->numarg))) { |
|
759 |
+ logg("!cl_engine_set_num(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret)); |
|
761 | 760 |
cl_engine_free(engine); |
762 | 761 |
return 1; |
763 | 762 |
} |
764 | 763 |
} |
765 |
- cl_engine_get(engine, CL_ENGINE_MAX_RECURSION, &val32); |
|
766 |
- if(val32) |
|
767 |
- logg("Limits: Recursion level limit set to %u.\n", (unsigned int) val32); |
|
764 |
+ val = cl_engine_get_num(engine, CL_ENGINE_MAX_RECURSION, NULL); |
|
765 |
+ if(val) |
|
766 |
+ logg("Limits: Recursion level limit set to %u.\n", (unsigned int) val); |
|
768 | 767 |
else |
769 | 768 |
logg("^Limits: Recursion level limit protection disabled.\n"); |
770 | 769 |
|
771 | 770 |
if((opt = optget(opts, "MaxFiles"))->enabled) { |
772 |
- val32 = opt->numarg; |
|
773 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_FILES, &val32))) { |
|
774 |
- logg("!cli_engine_set(CL_ENGINE_MAX_FILES) failed: %s\n", cl_strerror(ret)); |
|
771 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_FILES, opt->numarg))) { |
|
772 |
+ logg("!cl_engine_set_num(CL_ENGINE_MAX_FILES) failed: %s\n", cl_strerror(ret)); |
|
775 | 773 |
cl_engine_free(engine); |
776 | 774 |
return 1; |
777 | 775 |
} |
778 | 776 |
} |
779 |
- cl_engine_get(engine, CL_ENGINE_MAX_FILES, &val32); |
|
780 |
- if(val32) |
|
781 |
- logg("Limits: Files limit set to %u.\n", (unsigned int) val32); |
|
777 |
+ val = cl_engine_get_num(engine, CL_ENGINE_MAX_FILES, NULL); |
|
778 |
+ if(val) |
|
779 |
+ logg("Limits: Files limit set to %u.\n", (unsigned int) val); |
|
782 | 780 |
else |
783 | 781 |
logg("^Limits: Files limit protection disabled.\n"); |
784 | 782 |
|
... | ... |
@@ -885,26 +878,24 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
885 | 885 |
options |= CL_SCAN_STRUCTURED; |
886 | 886 |
|
887 | 887 |
if((opt = optget(opts, "StructuredMinCreditCardCount"))->enabled) { |
888 |
- val32 = opt->numarg; |
|
889 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MIN_CC_COUNT, &val32))) { |
|
890 |
- logg("!cli_engine_set(CL_ENGINE_MIN_CC_COUNT) failed: %s\n", cl_strerror(ret)); |
|
888 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MIN_CC_COUNT, opt->numarg))) { |
|
889 |
+ logg("!cl_engine_set_num(CL_ENGINE_MIN_CC_COUNT) failed: %s\n", cl_strerror(ret)); |
|
891 | 890 |
cl_engine_free(engine); |
892 | 891 |
return 1; |
893 | 892 |
} |
894 | 893 |
} |
895 |
- cl_engine_get(engine, CL_ENGINE_MIN_CC_COUNT, &val32); |
|
896 |
- logg("Structured: Minimum Credit Card Number Count set to %u\n", (unsigned int) val32); |
|
894 |
+ val = cl_engine_get_num(engine, CL_ENGINE_MIN_CC_COUNT, NULL); |
|
895 |
+ logg("Structured: Minimum Credit Card Number Count set to %u\n", (unsigned int) val); |
|
897 | 896 |
|
898 | 897 |
if((opt = optget(opts, "StructuredMinSSNCount"))->enabled) { |
899 |
- val32 = opt->numarg; |
|
900 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MIN_SSN_COUNT, &val32))) { |
|
901 |
- logg("!cli_engine_set(CL_ENGINE_MIN_SSN_COUNT) failed: %s\n", cl_strerror(ret)); |
|
898 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MIN_SSN_COUNT, opt->numarg))) { |
|
899 |
+ logg("!cl_engine_set_num(CL_ENGINE_MIN_SSN_COUNT) failed: %s\n", cl_strerror(ret)); |
|
902 | 900 |
cl_engine_free(engine); |
903 | 901 |
return 1; |
904 | 902 |
} |
905 | 903 |
} |
906 |
- cl_engine_get(engine, CL_ENGINE_MIN_SSN_COUNT, &val32); |
|
907 |
- logg("Structured: Minimum Social Security Number Count set to %u\n", (unsigned int) val32); |
|
904 |
+ val = cl_engine_get_num(engine, CL_ENGINE_MIN_SSN_COUNT, NULL); |
|
905 |
+ logg("Structured: Minimum Social Security Number Count set to %u\n", (unsigned int) val); |
|
908 | 906 |
|
909 | 907 |
if(optget(opts, "StructuredSSNFormatNormal")->enabled) |
910 | 908 |
options |= CL_SCAN_STRUCTURED_SSN_NORMAL; |
... | ... |
@@ -407,12 +407,12 @@ static int print_ver(int desc, char term, const struct cl_engine *engine) |
407 | 407 |
{ |
408 | 408 |
uint32_t ver; |
409 | 409 |
|
410 |
- cl_engine_get(engine, CL_ENGINE_DB_VERSION, &ver); |
|
410 |
+ ver = cl_engine_get_num(engine, CL_ENGINE_DB_VERSION, NULL); |
|
411 | 411 |
if(ver) { |
412 | 412 |
char timestr[32]; |
413 | 413 |
const char *tstr; |
414 | 414 |
time_t t; |
415 |
- cl_engine_get(engine, CL_ENGINE_DB_TIME, &t); |
|
415 |
+ t = cl_engine_get_num(engine, CL_ENGINE_DB_TIME, NULL); |
|
416 | 416 |
tstr = cli_ctime(&t, timestr, sizeof(timestr)); |
417 | 417 |
/* cut trailing \n */ |
418 | 418 |
timestr[strlen(tstr)-1] = '\0'; |
... | ... |
@@ -337,8 +337,6 @@ int scanmanager(const struct optstruct *opts) |
337 | 337 |
#ifndef C_WINDOWS |
338 | 338 |
struct rlimit rlim; |
339 | 339 |
#endif |
340 |
- uint64_t val64; |
|
341 |
- uint32_t val32; |
|
342 | 340 |
|
343 | 341 |
if(optget(opts, "phishing-sigs")->enabled) |
344 | 342 |
dboptions |= CL_DB_PHISHING; |
... | ... |
@@ -400,8 +398,8 @@ int scanmanager(const struct optstruct *opts) |
400 | 400 |
} |
401 | 401 |
|
402 | 402 |
if(pua_cats) { |
403 |
- if((ret = cl_engine_set(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) { |
|
404 |
- logg("!cli_engine_set(CL_ENGINE_PUA_CATEGORIES) failed: %s\n", cl_strerror(ret)); |
|
403 |
+ if((ret = cl_engine_set_str(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) { |
|
404 |
+ logg("!cli_engine_set_str(CL_ENGINE_PUA_CATEGORIES) failed: %s\n", cl_strerror(ret)); |
|
405 | 405 |
free(pua_cats); |
406 | 406 |
cl_engine_free(engine); |
407 | 407 |
return 50; |
... | ... |
@@ -410,24 +408,18 @@ int scanmanager(const struct optstruct *opts) |
410 | 410 |
} |
411 | 411 |
} |
412 | 412 |
|
413 |
- if(optget(opts, "dev-ac-only")->enabled) { |
|
414 |
- val32 = 1; |
|
415 |
- cl_engine_set(engine, CL_ENGINE_AC_ONLY, &val32); |
|
416 |
- } |
|
413 |
+ if(optget(opts, "dev-ac-only")->enabled) |
|
414 |
+ cl_engine_set_num(engine, CL_ENGINE_AC_ONLY, 1); |
|
417 | 415 |
|
418 |
- if(optget(opts, "dev-ac-depth")->enabled) { |
|
419 |
- val32 = optget(opts, "dev-ac-depth")->numarg; |
|
420 |
- cl_engine_set(engine, CL_ENGINE_AC_MAXDEPTH, &val32); |
|
421 |
- } |
|
416 |
+ if(optget(opts, "dev-ac-depth")->enabled) |
|
417 |
+ cl_engine_set_num(engine, CL_ENGINE_AC_MAXDEPTH, optget(opts, "dev-ac-depth")->numarg); |
|
422 | 418 |
|
423 |
- if(optget(opts, "leave-temps")->enabled) { |
|
424 |
- val32 = 1; |
|
425 |
- cl_engine_set(engine, CL_ENGINE_KEEPTMP, &val32); |
|
426 |
- } |
|
419 |
+ if(optget(opts, "leave-temps")->enabled) |
|
420 |
+ cl_engine_set_num(engine, CL_ENGINE_KEEPTMP, 1); |
|
427 | 421 |
|
428 | 422 |
if((opt = optget(opts, "tempdir"))->enabled) { |
429 |
- if((ret = cl_engine_set(engine, CL_ENGINE_TMPDIR, opt->strarg))) { |
|
430 |
- logg("!cli_engine_set(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret)); |
|
423 |
+ if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) { |
|
424 |
+ logg("!cli_engine_set_str(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret)); |
|
431 | 425 |
cl_engine_free(engine); |
432 | 426 |
return 50; |
433 | 427 |
} |
... | ... |
@@ -461,18 +453,16 @@ int scanmanager(const struct optstruct *opts) |
461 | 461 |
/* set limits */ |
462 | 462 |
|
463 | 463 |
if((opt = optget(opts, "max-scansize"))->enabled) { |
464 |
- val64 = opt->numarg; |
|
465 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_SCANSIZE, &val64))) { |
|
466 |
- logg("!cli_engine_set(CL_ENGINE_MAX_SCANSIZE) failed: %s\n", cl_strerror(ret)); |
|
464 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_SCANSIZE, opt->numarg))) { |
|
465 |
+ logg("!cli_engine_set_num(CL_ENGINE_MAX_SCANSIZE) failed: %s\n", cl_strerror(ret)); |
|
467 | 466 |
cl_engine_free(engine); |
468 | 467 |
return 50; |
469 | 468 |
} |
470 | 469 |
} |
471 | 470 |
|
472 | 471 |
if((opt = optget(opts, "max-filesize"))->enabled) { |
473 |
- val64 = opt->numarg; |
|
474 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_FILESIZE, &val64))) { |
|
475 |
- logg("!cli_engine_set(CL_ENGINE_MAX_FILESIZE) failed: %s\n", cl_strerror(ret)); |
|
472 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_FILESIZE, opt->numarg))) { |
|
473 |
+ logg("!cli_engine_set_num(CL_ENGINE_MAX_FILESIZE) failed: %s\n", cl_strerror(ret)); |
|
476 | 474 |
cl_engine_free(engine); |
477 | 475 |
return 50; |
478 | 476 |
} |
... | ... |
@@ -480,11 +470,9 @@ int scanmanager(const struct optstruct *opts) |
480 | 480 |
|
481 | 481 |
#ifndef C_WINDOWS |
482 | 482 |
if(getrlimit(RLIMIT_FSIZE, &rlim) == 0) { |
483 |
- cl_engine_get(engine, CL_ENGINE_MAX_FILESIZE, &val64); |
|
484 |
- if(rlim.rlim_max < val64) |
|
483 |
+ if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL)) |
|
485 | 484 |
logg("^System limit for file size is lower than engine->maxfilesize\n"); |
486 |
- cl_engine_get(engine, CL_ENGINE_MAX_SCANSIZE, &val64); |
|
487 |
- if(rlim.rlim_max < val64) |
|
485 |
+ if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_SCANSIZE, NULL)) |
|
488 | 486 |
logg("^System limit for file size is lower than engine->maxscansize\n"); |
489 | 487 |
} else { |
490 | 488 |
logg("^Cannot obtain resource limits for file size\n"); |
... | ... |
@@ -492,18 +480,16 @@ int scanmanager(const struct optstruct *opts) |
492 | 492 |
#endif |
493 | 493 |
|
494 | 494 |
if((opt = optget(opts, "max-files"))->enabled) { |
495 |
- val32 = opt->numarg; |
|
496 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_FILES, &val32))) { |
|
497 |
- logg("!cli_engine_set(CL_ENGINE_MAX_FILES) failed: %s\n", cl_strerror(ret)); |
|
495 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_FILES, opt->numarg))) { |
|
496 |
+ logg("!cli_engine_set_num(CL_ENGINE_MAX_FILES) failed: %s\n", cl_strerror(ret)); |
|
498 | 497 |
cl_engine_free(engine); |
499 | 498 |
return 50; |
500 | 499 |
} |
501 | 500 |
} |
502 | 501 |
|
503 | 502 |
if((opt = optget(opts, "max-recursion"))->enabled) { |
504 |
- val32 = opt->numarg; |
|
505 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MAX_RECURSION, &val32))) { |
|
506 |
- logg("!cli_engine_set(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret)); |
|
503 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_RECURSION, opt->numarg))) { |
|
504 |
+ logg("!cli_engine_set_num(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret)); |
|
507 | 505 |
cl_engine_free(engine); |
508 | 506 |
return 50; |
509 | 507 |
} |
... | ... |
@@ -576,18 +562,16 @@ int scanmanager(const struct optstruct *opts) |
576 | 576 |
} |
577 | 577 |
|
578 | 578 |
if((opt = optget(opts, "structured-ssn-count"))->enabled) { |
579 |
- val32 = opt->numarg; |
|
580 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MIN_SSN_COUNT, &val32))) { |
|
581 |
- logg("!cli_engine_set(CL_ENGINE_MIN_SSN_COUNT) failed: %s\n", cl_strerror(ret)); |
|
579 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MIN_SSN_COUNT, opt->numarg))) { |
|
580 |
+ logg("!cli_engine_set_num(CL_ENGINE_MIN_SSN_COUNT) failed: %s\n", cl_strerror(ret)); |
|
582 | 581 |
cl_engine_free(engine); |
583 | 582 |
return 50; |
584 | 583 |
} |
585 | 584 |
} |
586 | 585 |
|
587 | 586 |
if((opt = optget(opts, "structured-cc-count"))->enabled) { |
588 |
- val32 = opt->numarg; |
|
589 |
- if((ret = cl_engine_set(engine, CL_ENGINE_MIN_CC_COUNT, &val32))) { |
|
590 |
- logg("!cli_engine_set(CL_ENGINE_MIN_CC_COUNT) failed: %s\n", cl_strerror(ret)); |
|
587 |
+ if((ret = cl_engine_set_num(engine, CL_ENGINE_MIN_CC_COUNT, opt->numarg))) { |
|
588 |
+ logg("!cli_engine_set_num(CL_ENGINE_MIN_CC_COUNT) failed: %s\n", cl_strerror(ret)); |
|
591 | 589 |
cl_engine_free(engine); |
592 | 590 |
return 50; |
593 | 591 |
} |
... | ... |
@@ -38,6 +38,7 @@ typedef enum { |
38 | 38 |
CL_SUCCESS = 0, |
39 | 39 |
CL_VIRUS, |
40 | 40 |
CL_ENULLARG, |
41 |
+ CL_EARG, |
|
41 | 42 |
CL_EMALFDB, |
42 | 43 |
CL_ECVD, |
43 | 44 |
CL_EVERIFY, |
... | ... |
@@ -110,7 +111,7 @@ struct cl_engine; |
110 | 110 |
struct cl_settings; |
111 | 111 |
|
112 | 112 |
#define CL_INIT_DEFAULT 0x0 |
113 |
-extern int cl_init(unsigned int options); |
|
113 |
+extern int cl_init(unsigned int initoptions); |
|
114 | 114 |
|
115 | 115 |
extern struct cl_engine *cl_engine_new(void); |
116 | 116 |
|
... | ... |
@@ -131,9 +132,13 @@ enum cl_engine_field { |
131 | 131 |
CL_ENGINE_KEEPTMP /* uint32_t */ |
132 | 132 |
}; |
133 | 133 |
|
134 |
-extern int cl_engine_set(struct cl_engine *engine, enum cl_engine_field field, const void *val); |
|
134 |
+extern int cl_engine_set_num(struct cl_engine *engine, enum cl_engine_field field, long long num); |
|
135 | 135 |
|
136 |
-extern int cl_engine_get(const struct cl_engine *engine, enum cl_engine_field field, void *val); |
|
136 |
+long long cl_engine_get_num(const struct cl_engine *engine, enum cl_engine_field field, int *err); |
|
137 |
+ |
|
138 |
+int cl_engine_set_str(struct cl_engine *engine, enum cl_engine_field field, const char *str); |
|
139 |
+ |
|
140 |
+const char *cl_engine_get_str(const struct cl_engine *engine, enum cl_engine_field field, int *err); |
|
137 | 141 |
|
138 | 142 |
extern struct cl_settings *cl_engine_settings_copy(const struct cl_engine *engine); |
139 | 143 |
|
... | ... |
@@ -168,12 +173,12 @@ struct cl_cvd { /* field no. */ |
168 | 168 |
}; |
169 | 169 |
|
170 | 170 |
/* file scanning */ |
171 |
-extern int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options); |
|
171 |
+extern int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions); |
|
172 | 172 |
|
173 |
-extern int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options); |
|
173 |
+extern int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions); |
|
174 | 174 |
|
175 | 175 |
/* database handling */ |
176 |
-extern int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int options); |
|
176 |
+extern int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int dboptions); |
|
177 | 177 |
extern const char *cl_retdbdir(void); |
178 | 178 |
|
179 | 179 |
/* engine handling */ |
... | ... |
@@ -7,8 +7,10 @@ CLAMAV_PUBLIC { |
7 | 7 |
cl_debug; |
8 | 8 |
cl_init; |
9 | 9 |
cl_engine_new; |
10 |
- cl_engine_set; |
|
11 |
- cl_engine_get; |
|
10 |
+ cl_engine_set_num; |
|
11 |
+ cl_engine_get_num; |
|
12 |
+ cl_engine_set_str; |
|
13 |
+ cl_engine_get_str; |
|
12 | 14 |
cl_engine_settings_copy; |
13 | 15 |
cl_engine_settings_apply; |
14 | 16 |
cl_engine_settings_free; |
... | ... |
@@ -146,6 +146,8 @@ const char *cl_strerror(int clerror) |
146 | 146 |
return "Virus(es) detected"; |
147 | 147 |
case CL_ENULLARG: |
148 | 148 |
return "Null argument passed to function"; |
149 |
+ case CL_EARG: |
|
150 |
+ return "Invalid argument passed to function"; |
|
149 | 151 |
case CL_EMALFDB: |
150 | 152 |
return "Malformed database"; |
151 | 153 |
case CL_ECVD: |
... | ... |
@@ -196,7 +198,7 @@ const char *cl_strerror(int clerror) |
196 | 196 |
} |
197 | 197 |
} |
198 | 198 |
|
199 |
-int cl_init(unsigned int options) |
|
199 |
+int cl_init(unsigned int initoptions) |
|
200 | 200 |
{ |
201 | 201 |
/* put dlopen() stuff here, etc. */ |
202 | 202 |
cli_rarload(); |
... | ... |
@@ -260,123 +262,151 @@ struct cl_engine *cl_engine_new(void) |
260 | 260 |
return new; |
261 | 261 |
} |
262 | 262 |
|
263 |
-int cl_engine_set(struct cl_engine *engine, enum cl_engine_field field, const void *val) |
|
263 |
+int cl_engine_set_num(struct cl_engine *engine, enum cl_engine_field field, long long num) |
|
264 | 264 |
{ |
265 |
- if(!engine || !val) |
|
265 |
+ if(!engine) |
|
266 | 266 |
return CL_ENULLARG; |
267 | 267 |
|
268 |
+ /* TODO: consider adding checks and warn/errs when num overflows the |
|
269 |
+ * destination type |
|
270 |
+ */ |
|
268 | 271 |
switch(field) { |
269 | 272 |
case CL_ENGINE_MAX_SCANSIZE: |
270 |
- engine->maxscansize = *((const uint64_t *) val); |
|
273 |
+ engine->maxscansize = num; |
|
271 | 274 |
break; |
272 | 275 |
case CL_ENGINE_MAX_FILESIZE: |
273 |
- engine->maxfilesize = *((const uint64_t *) val); |
|
276 |
+ engine->maxfilesize = num; |
|
274 | 277 |
break; |
275 | 278 |
case CL_ENGINE_MAX_RECURSION: |
276 |
- engine->maxreclevel = *((const uint32_t *) val); |
|
279 |
+ engine->maxreclevel = num; |
|
277 | 280 |
break; |
278 | 281 |
case CL_ENGINE_MAX_FILES: |
279 |
- engine->maxfiles = *((const uint32_t *) val); |
|
282 |
+ engine->maxfiles = num; |
|
280 | 283 |
break; |
281 | 284 |
case CL_ENGINE_MIN_CC_COUNT: |
282 |
- engine->min_cc_count = *((const uint32_t *) val); |
|
285 |
+ engine->min_cc_count = num; |
|
283 | 286 |
break; |
284 | 287 |
case CL_ENGINE_MIN_SSN_COUNT: |
285 |
- engine->min_ssn_count = *((const uint32_t *) val); |
|
286 |
- break; |
|
287 |
- case CL_ENGINE_PUA_CATEGORIES: |
|
288 |
- engine->pua_cats = cli_mpool_strdup(engine->mempool, (const char *) val); |
|
289 |
- if(!engine->pua_cats) |
|
290 |
- return CL_EMEM; |
|
288 |
+ engine->min_ssn_count = num; |
|
291 | 289 |
break; |
292 | 290 |
case CL_ENGINE_DB_VERSION: |
293 | 291 |
case CL_ENGINE_DB_TIME: |
294 |
- cli_warnmsg("cl_engine_set: The field is read only\n"); |
|
295 |
- break; |
|
292 |
+ cli_warnmsg("cl_engine_set_num: The field is read only\n"); |
|
293 |
+ return CL_EARG; |
|
296 | 294 |
case CL_ENGINE_AC_ONLY: |
297 |
- engine->ac_only = *((const uint32_t *) val); |
|
295 |
+ engine->ac_only = num; |
|
298 | 296 |
break; |
299 | 297 |
case CL_ENGINE_AC_MINDEPTH: |
300 |
- engine->ac_mindepth = *((const uint32_t *) val); |
|
298 |
+ engine->ac_mindepth = num; |
|
301 | 299 |
break; |
302 | 300 |
case CL_ENGINE_AC_MAXDEPTH: |
303 |
- engine->ac_maxdepth = *((const uint32_t *) val); |
|
304 |
- break; |
|
305 |
- case CL_ENGINE_TMPDIR: |
|
306 |
- engine->tmpdir = cli_mpool_strdup(engine->mempool, (const char *) val); |
|
307 |
- if(!engine->tmpdir) |
|
308 |
- return CL_EMEM; |
|
301 |
+ engine->ac_maxdepth = num; |
|
309 | 302 |
break; |
310 | 303 |
case CL_ENGINE_KEEPTMP: |
311 |
- engine->keeptmp = *((const uint32_t *) val); |
|
304 |
+ engine->keeptmp = num; |
|
312 | 305 |
break; |
313 | 306 |
default: |
314 |
- cli_errmsg("cl_engine_set: Incorrect field number\n"); |
|
315 |
- return CL_ENULLARG; /* FIXME */ |
|
307 |
+ cli_errmsg("cl_engine_set_num: Incorrect field number\n"); |
|
308 |
+ return CL_EARG; |
|
316 | 309 |
} |
317 | 310 |
|
318 | 311 |
return CL_SUCCESS; |
319 | 312 |
} |
320 | 313 |
|
321 |
-int cl_engine_get(const struct cl_engine *engine, enum cl_engine_field field, void *val) |
|
314 |
+long long cl_engine_get_num(const struct cl_engine *engine, enum cl_engine_field field, int *err) |
|
322 | 315 |
{ |
323 |
- if(!engine || !val) |
|
324 |
- return CL_ENULLARG; |
|
316 |
+ if(!engine) { |
|
317 |
+ cli_errmsg("cl_engine_get_num: engine == NULL\n"); |
|
318 |
+ if(err) |
|
319 |
+ *err = CL_ENULLARG; |
|
320 |
+ return -1; |
|
321 |
+ } |
|
322 |
+ |
|
323 |
+ if(err) |
|
324 |
+ *err = CL_SUCCESS; |
|
325 | 325 |
|
326 | 326 |
switch(field) { |
327 | 327 |
case CL_ENGINE_MAX_SCANSIZE: |
328 |
- *((uint64_t *) val) = engine->maxscansize; |
|
329 |
- break; |
|
328 |
+ return engine->maxscansize; |
|
330 | 329 |
case CL_ENGINE_MAX_FILESIZE: |
331 |
- *((uint64_t *) val) = engine->maxfilesize; |
|
332 |
- break; |
|
330 |
+ return engine->maxfilesize; |
|
333 | 331 |
case CL_ENGINE_MAX_RECURSION: |
334 |
- *((uint32_t *) val) = engine->maxreclevel; |
|
335 |
- break; |
|
332 |
+ return engine->maxreclevel; |
|
336 | 333 |
case CL_ENGINE_MAX_FILES: |
337 |
- *((uint32_t *) val) = engine->maxfiles; |
|
338 |
- break; |
|
334 |
+ return engine->maxfiles; |
|
339 | 335 |
case CL_ENGINE_MIN_CC_COUNT: |
340 |
- *((uint32_t *) val) = engine->min_cc_count; |
|
341 |
- break; |
|
336 |
+ return engine->min_cc_count; |
|
342 | 337 |
case CL_ENGINE_MIN_SSN_COUNT: |
343 |
- *((uint32_t *) val) = engine->min_ssn_count; |
|
344 |
- break; |
|
345 |
- case CL_ENGINE_PUA_CATEGORIES: |
|
346 |
- if(engine->pua_cats) |
|
347 |
- strncpy((char *) val, engine->pua_cats, 128); |
|
348 |
- break; |
|
338 |
+ return engine->min_ssn_count; |
|
349 | 339 |
case CL_ENGINE_DB_VERSION: |
350 |
- *((uint32_t *) val) = engine->dbversion[0]; |
|
351 |
- break; |
|
340 |
+ return engine->dbversion[0]; |
|
352 | 341 |
case CL_ENGINE_DB_TIME: |
353 |
- /* time_t may be 64-bit! */ |
|
354 |
- *((time_t *) val) = engine->dbversion[1]; |
|
355 |
- break; |
|
342 |
+ return engine->dbversion[1]; |
|
356 | 343 |
case CL_ENGINE_AC_ONLY: |
357 |
- *((uint32_t *) val) = engine->ac_only; |
|
358 |
- break; |
|
344 |
+ return engine->ac_only; |
|
359 | 345 |
case CL_ENGINE_AC_MINDEPTH: |
360 |
- *((uint32_t *) val) = engine->ac_mindepth; |
|
361 |
- break; |
|
346 |
+ return engine->ac_mindepth; |
|
362 | 347 |
case CL_ENGINE_AC_MAXDEPTH: |
363 |
- *((uint32_t *) val) = engine->ac_maxdepth; |
|
348 |
+ return engine->ac_maxdepth; |
|
349 |
+ case CL_ENGINE_KEEPTMP: |
|
350 |
+ return engine->keeptmp; |
|
351 |
+ default: |
|
352 |
+ cli_errmsg("cl_engine_get: Incorrect field number\n"); |
|
353 |
+ if(err) |
|
354 |
+ *err = CL_EARG; |
|
355 |
+ return -1; |
|
356 |
+ } |
|
357 |
+} |
|
358 |
+ |
|
359 |
+int cl_engine_set_str(struct cl_engine *engine, enum cl_engine_field field, const char *str) |
|
360 |
+{ |
|
361 |
+ if(!engine) |
|
362 |
+ return CL_ENULLARG; |
|
363 |
+ |
|
364 |
+ switch(field) { |
|
365 |
+ case CL_ENGINE_PUA_CATEGORIES: |
|
366 |
+ engine->pua_cats = cli_mpool_strdup(engine->mempool, str); |
|
367 |
+ if(!engine->pua_cats) |
|
368 |
+ return CL_EMEM; |
|
364 | 369 |
break; |
365 | 370 |
case CL_ENGINE_TMPDIR: |
366 |
- if(engine->tmpdir) |
|
367 |
- strncpy((char *) val, engine->tmpdir, 128); |
|
368 |
- break; |
|
369 |
- case CL_ENGINE_KEEPTMP: |
|
370 |
- *((uint32_t *) val) = engine->keeptmp; |
|
371 |
+ engine->tmpdir = cli_mpool_strdup(engine->mempool, str); |
|
372 |
+ if(!engine->tmpdir) |
|
373 |
+ return CL_EMEM; |
|
371 | 374 |
break; |
372 | 375 |
default: |
373 |
- cli_errmsg("cl_engine_get: Incorrect field number\n"); |
|
374 |
- return CL_ENULLARG; /* FIXME */ |
|
376 |
+ cli_errmsg("cl_engine_set_num: Incorrect field number\n"); |
|
377 |
+ return CL_EARG; |
|
375 | 378 |
} |
376 | 379 |
|
377 | 380 |
return CL_SUCCESS; |
378 | 381 |
} |
379 | 382 |
|
383 |
+const char *cl_engine_get_str(const struct cl_engine *engine, enum cl_engine_field field, int *err) |
|
384 |
+{ |
|
385 |
+ if(!engine) { |
|
386 |
+ cli_errmsg("cl_engine_get_str: engine == NULL\n"); |
|
387 |
+ if(err) |
|
388 |
+ *err = CL_ENULLARG; |
|
389 |
+ return NULL; |
|
390 |
+ } |
|
391 |
+ |
|
392 |
+ if(err) |
|
393 |
+ *err = CL_SUCCESS; |
|
394 |
+ |
|
395 |
+ switch(field) { |
|
396 |
+ case CL_ENGINE_PUA_CATEGORIES: |
|
397 |
+ return engine->pua_cats; |
|
398 |
+ case CL_ENGINE_TMPDIR: |
|
399 |
+ return engine->tmpdir; |
|
400 |
+ default: |
|
401 |
+ cli_errmsg("cl_engine_get: Incorrect field number\n"); |
|
402 |
+ if(err) |
|
403 |
+ *err = CL_EARG; |
|
404 |
+ return NULL; |
|
405 |
+ } |
|
406 |
+} |
|
407 |
+ |
|
380 | 408 |
struct cl_settings *cl_engine_settings_copy(const struct cl_engine *engine) |
381 | 409 |
{ |
382 | 410 |
struct cl_settings *settings; |
... | ... |
@@ -1639,7 +1639,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned |
1639 | 1639 |
return ret; |
1640 | 1640 |
} |
1641 | 1641 |
|
1642 |
-int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int options) |
|
1642 |
+int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int dboptions) |
|
1643 | 1643 |
{ |
1644 | 1644 |
struct stat sb; |
1645 | 1645 |
int ret; |
... | ... |
@@ -1654,19 +1654,19 @@ int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, uns |
1654 | 1654 |
return CL_ESTAT; |
1655 | 1655 |
} |
1656 | 1656 |
|
1657 |
- if((options & CL_DB_PHISHING_URLS) && !engine->phishcheck && (engine->dconf->phishing & PHISHING_CONF_ENGINE)) |
|
1657 |
+ if((dboptions & CL_DB_PHISHING_URLS) && !engine->phishcheck && (engine->dconf->phishing & PHISHING_CONF_ENGINE)) |
|
1658 | 1658 |
if((ret = phishing_init(engine))) |
1659 | 1659 |
return ret; |
1660 | 1660 |
|
1661 |
- engine->dboptions = options; |
|
1661 |
+ engine->dboptions = dboptions; |
|
1662 | 1662 |
|
1663 | 1663 |
switch(sb.st_mode & S_IFMT) { |
1664 | 1664 |
case S_IFREG: |
1665 |
- ret = cli_load(path, engine, signo, options, NULL); |
|
1665 |
+ ret = cli_load(path, engine, signo, dboptions, NULL); |
|
1666 | 1666 |
break; |
1667 | 1667 |
|
1668 | 1668 |
case S_IFDIR: |
1669 |
- ret = cli_loaddbdir(path, engine, signo, options); |
|
1669 |
+ ret = cli_loaddbdir(path, engine, signo, dboptions); |
|
1670 | 1670 |
break; |
1671 | 1671 |
|
1672 | 1672 |
default: |
... | ... |
@@ -2114,7 +2114,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx) |
2114 | 2114 |
} |
2115 | 2115 |
} |
2116 | 2116 |
|
2117 |
-int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options) |
|
2117 |
+int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions) |
|
2118 | 2118 |
{ |
2119 | 2119 |
cli_ctx ctx; |
2120 | 2120 |
int rc; |
... | ... |
@@ -2123,7 +2123,7 @@ int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, cons |
2123 | 2123 |
ctx.engine = engine; |
2124 | 2124 |
ctx.virname = virname; |
2125 | 2125 |
ctx.scanned = scanned; |
2126 |
- ctx.options = options; |
|
2126 |
+ ctx.options = scanoptions; |
|
2127 | 2127 |
ctx.found_possibly_unwanted = 0; |
2128 | 2128 |
ctx.dconf = (struct cli_dconf *) engine->dconf; |
2129 | 2129 |
|
... | ... |
@@ -2168,7 +2168,7 @@ static int cli_scanfile(const char *filename, cli_ctx *ctx) |
2168 | 2168 |
return ret; |
2169 | 2169 |
} |
2170 | 2170 |
|
2171 |
-int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options) |
|
2171 |
+int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions) |
|
2172 | 2172 |
{ |
2173 | 2173 |
int fd, ret; |
2174 | 2174 |
|
... | ... |
@@ -2176,7 +2176,7 @@ int cl_scanfile(const char *filename, const char **virname, unsigned long int *s |
2176 | 2176 |
if((fd = open(filename, O_RDONLY|O_BINARY)) == -1) |
2177 | 2177 |
return CL_EOPEN; |
2178 | 2178 |
|
2179 |
- ret = cl_scandesc(fd, virname, scanned, engine, options); |
|
2179 |
+ ret = cl_scandesc(fd, virname, scanned, engine, scanoptions); |
|
2180 | 2180 |
close(fd); |
2181 | 2181 |
|
2182 | 2182 |
return ret; |