Browse code

libclamav, clamd, clamscan: use cl_engine_set() to control AC settings

git-svn: trunk@4404

Tomasz Kojm authored on 2008/11/14 04:06:42
Showing 10 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Nov 13 19:06:47 CET 2008 (tk)
2
+---------------------------------
3
+ * libclamav, clamd, clamscan: use cl_engine_set() to control AC settings
4
+
1 5
 Thu Nov 13 16:54:24 CET 2008 (acab)
2 6
 -----------------------------------
3 7
  * clamav-milter: prevent races
... ...
@@ -105,6 +105,7 @@ int main(int argc, char **argv)
105 105
 	unsigned int sigs = 0;
106 106
 	int lsockets[2], nlsockets = 0;
107 107
 	unsigned int dboptions = 0;
108
+	uint32_t val32;
108 109
 #ifdef C_LINUX
109 110
 	struct stat sb;
110 111
 #endif
... ...
@@ -406,11 +407,13 @@ int main(int argc, char **argv)
406 406
 
407 407
     if(cfgopt(copt,"DevACOnly")->enabled) {
408 408
 	logg("#Only using the A-C matcher.\n");
409
-	dboptions |= CL_DB_ACONLY;
409
+        val32 = 1;
410
+	cl_engine_set(engine, CL_ENGINE_AC_ONLY, &val32);
410 411
     }
411 412
 
412 413
     if((cpt = cfgopt(copt, "DevACDepth"))->enabled) {
413
-	cli_ac_setdepth(AC_DEFAULT_MIN_DEPTH, cpt->numarg);
414
+	val32 = cpt->numarg;
415
+        cl_engine_set(engine, CL_ENGINE_AC_MAXDEPTH, &val32);
414 416
 	logg("#Max A-C depth set to %u\n", cpt->numarg);
415 417
     }
416 418
 
... ...
@@ -371,12 +371,6 @@ int scanmanager(const struct optstruct *opt)
371 371
 	options |= CL_SCAN_HEURISTIC_PRECEDENCE;
372 372
     }
373 373
 
374
-    if(opt_check(opt, "dev-ac-only"))
375
-	dboptions |= CL_DB_ACONLY;
376
-
377
-    if(opt_check(opt, "dev-ac-depth"))
378
-	cli_ac_setdepth(AC_DEFAULT_MIN_DEPTH, atoi(opt_arg(opt, "dev-ac-depth")));
379
-
380 374
     if((ret = cl_init(CL_INIT_DEFAULT))) {
381 375
 	logg("!Can't initialize libclamav: %s\n", cl_strerror(ret));
382 376
 	return 50;
... ...
@@ -444,6 +438,16 @@ int scanmanager(const struct optstruct *opt)
444 444
 	}
445 445
     }
446 446
 
447
+    if(opt_check(opt, "dev-ac-only")) {
448
+	val32 = 1;
449
+	cl_engine_set(engine, CL_ENGINE_AC_ONLY, &val32);
450
+    }
451
+
452
+    if(opt_check(opt, "dev-ac-depth")) {
453
+	val32 = atoi(opt_arg(opt, "dev-ac-depth"));
454
+	cl_engine_set(engine, CL_ENGINE_AC_MAXDEPTH, &val32);
455
+    }
456
+
447 457
     if(opt_check(opt, "database")) {
448 458
 	if((ret = cl_load(opt_arg(opt, "database"), engine, &info.sigs, dboptions))) {
449 459
 	    logg("!%s\n", cl_strerror(ret));
... ...
@@ -67,7 +67,6 @@ extern "C"
67 67
 
68 68
 /* db options */
69 69
 #define CL_DB_PHISHING	    0x2
70
-#define CL_DB_ACONLY	    0x4 /* WARNING: only for developers */
71 70
 #define CL_DB_PHISHING_URLS 0x8
72 71
 #define CL_DB_PUA	    0x10
73 72
 #define CL_DB_CVDNOTMP	    0x20
... ...
@@ -120,7 +119,10 @@ enum cl_engine_field {
120 120
     CL_ENGINE_MIN_SSN_COUNT,	    /* uint32_t */
121 121
     CL_ENGINE_PUA_CATEGORIES,	    /* (char *) */
122 122
     CL_ENGINE_DB_VERSION,	    /* uint32_t */
123
-    CL_ENGINE_DB_TIME		    /* uint32_t */
123
+    CL_ENGINE_DB_TIME,		    /* uint32_t */
124
+    CL_ENGINE_AC_ONLY,		    /* uint32_t */
125
+    CL_ENGINE_AC_MINDEPTH,	    /* uint32_t */
126
+    CL_ENGINE_AC_MAXDEPTH	    /* uint32_t */
124 127
 };
125 128
 
126 129
 extern int cl_engine_set(struct cl_engine *engine, enum cl_engine_field field, const void *val);
... ...
@@ -28,7 +28,6 @@ CLAMAV_PUBLIC {
28 28
 };
29 29
 CLAMAV_PRIVATE {
30 30
   global:
31
-    cli_ac_setdepth;
32 31
     cli_strtok;
33 32
     cli_untgz;
34 33
     cli_regcomp;
... ...
@@ -43,9 +43,6 @@
43 43
 
44 44
 #include "mpool.h"
45 45
 
46
-uint8_t cli_ac_mindepth = AC_DEFAULT_MIN_DEPTH;
47
-uint8_t cli_ac_maxdepth = AC_DEFAULT_MAX_DEPTH;
48
-
49 46
 int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
50 47
 {
51 48
 	struct cli_ac_node *pt, *next;
... ...
@@ -1465,9 +1462,3 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1465 1465
 
1466 1466
     return CL_SUCCESS;
1467 1467
 }
1468
-
1469
-void cli_ac_setdepth(uint8_t mindepth, uint8_t maxdepth)
1470
-{
1471
-    cli_ac_mindepth = mindepth;
1472
-    cli_ac_maxdepth = maxdepth;
1473
-}
... ...
@@ -30,7 +30,6 @@
30 30
 #define AC_DEFAULT_MAX_DEPTH 3
31 31
 #define AC_DEFAULT_TRACKLEN 8
32 32
 #define AC_CH_MAXDIST 32
33
-extern uint8_t cli_ac_mindepth, cli_ac_maxdepth;
34 33
 
35 34
 #define AC_SCAN_VIR 1
36 35
 #define AC_SCAN_FT  2
... ...
@@ -90,6 +89,5 @@ int cli_ac_buildtrie(struct cli_matcher *root);
90 90
 int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth);
91 91
 void cli_ac_free(struct cli_matcher *root);
92 92
 int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, const uint32_t *lsigid, unsigned int options);
93
-void cli_ac_setdepth(uint8_t mindepth, uint8_t maxdepth);
94 93
 
95 94
 #endif
... ...
@@ -81,6 +81,7 @@ static pthread_mutex_t cli_ctime_mutex = PTHREAD_MUTEX_INITIALIZER;
81 81
 #include "cltypes.h"
82 82
 #include "regex/regex.h"
83 83
 #include "ltdl.h"
84
+#include "matcher-ac.h"
84 85
 
85 86
 #ifndef	O_BINARY
86 87
 #define	O_BINARY	0
... ...
@@ -257,6 +258,9 @@ struct cl_engine *cl_engine_new(void)
257 257
     new->min_ssn_count = 3;
258 258
 
259 259
     new->refcount = 1;
260
+    new->ac_only = 0;
261
+    new->ac_mindepth = AC_DEFAULT_MIN_DEPTH;
262
+    new->ac_maxdepth = AC_DEFAULT_MAX_DEPTH;
260 263
 
261 264
 #ifdef USE_MPOOL
262 265
     if(!(new->mempool = mp_create())) {
... ...
@@ -323,7 +327,16 @@ int cl_engine_set(struct cl_engine *engine, enum cl_engine_field field, const vo
323 323
 	case CL_ENGINE_DB_VERSION:
324 324
 	case CL_ENGINE_DB_TIME:
325 325
 	    cli_warnmsg("cl_engine_set: The field is read only\n");
326
-	    return CL_SUCCESS;
326
+	    break;
327
+	case CL_ENGINE_AC_ONLY:
328
+	    engine->ac_only = *((const uint32_t *) val);
329
+	    break;
330
+	case CL_ENGINE_AC_MINDEPTH:
331
+	    engine->ac_mindepth = *((const uint32_t *) val);
332
+	    break;
333
+	case CL_ENGINE_AC_MAXDEPTH:
334
+	    engine->ac_maxdepth = *((const uint32_t *) val);
335
+	    break;
327 336
 	default:
328 337
 	    cli_errmsg("cl_engine_set: Incorrect field number\n");
329 338
 	    return CL_ENULLARG; /* FIXME */
... ...
@@ -366,6 +379,15 @@ int cl_engine_get(const struct cl_engine *engine, enum cl_engine_field field, vo
366 366
 	case CL_ENGINE_DB_TIME:
367 367
 	    *((uint32_t *) val) = engine->dbversion[1];
368 368
 	    break;
369
+	case CL_ENGINE_AC_ONLY:
370
+	    *((uint32_t *) val) = engine->ac_only;
371
+	    break;
372
+	case CL_ENGINE_AC_MINDEPTH:
373
+	    *((uint32_t *) val) = engine->ac_mindepth;
374
+	    break;
375
+	case CL_ENGINE_AC_MAXDEPTH:
376
+	    *((uint32_t *) val) = engine->ac_maxdepth;
377
+	    break;
369 378
 	default:
370 379
 	    cli_errmsg("cl_engine_get: Incorrect field number\n");
371 380
 	    return CL_ENULLARG; /* FIXME */
... ...
@@ -97,6 +97,9 @@ struct cl_engine {
97 97
     uint32_t sdb;
98 98
     uint32_t dboptions;
99 99
     uint32_t dbversion[2];
100
+    uint32_t ac_only;
101
+    uint32_t ac_mindepth;
102
+    uint32_t ac_maxdepth;
100 103
 
101 104
     /* Limits */
102 105
     uint64_t maxscansize;  /* during the scanning of archives this size
... ...
@@ -314,11 +314,11 @@ static int cli_initroots(struct cl_engine *engine, unsigned int options)
314 314
 		return CL_EMEM;
315 315
 	    }
316 316
 
317
-	    if(cli_mtargets[i].ac_only || (options & CL_DB_ACONLY))
317
+	    if(cli_mtargets[i].ac_only || engine->ac_only)
318 318
 		root->ac_only = 1;
319 319
 
320 320
 	    cli_dbgmsg("Initialising AC pattern matcher of root[%d]\n", i);
321
-	    if((ret = cli_ac_init(root, cli_ac_mindepth, cli_ac_maxdepth))) {
321
+	    if((ret = cli_ac_init(root, engine->ac_mindepth, engine->ac_maxdepth))) {
322 322
 		/* no need to free previously allocated memory here */
323 323
 		cli_errmsg("cli_initroots: Can't initialise AC pattern matcher\n");
324 324
 		return ret;