git-svn: trunk@4332
Tomasz Kojm authored on 2008/11/05 03:45:48... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Tue Nov 4 20:15:55 CET 2008 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav, clamd: always return correct db version in VERSION (bb#1168) |
|
4 |
+ |
|
1 | 5 |
Tue Nov 4 13:11:24 EET 2008 (edwin) |
2 | 6 |
------------------------------------ |
3 | 7 |
* contrib/clamdtop/TODO, contrib/clamdtop/clamdtop.c: fix bar |
... | ... |
@@ -158,32 +158,16 @@ int command(int desc, const struct cl_engine *engine, const struct cl_limits *li |
158 | 158 |
return COMMAND_SHUTDOWN; |
159 | 159 |
|
160 | 160 |
} else if(!strncmp(buff, CMD7, strlen(CMD7))) { /* VERSION */ |
161 |
- const char *dbdir = cfgopt(copt, "DatabaseDirectory")->strarg; |
|
162 |
- char *path; |
|
163 |
- struct cl_cvd *daily; |
|
164 |
- |
|
165 | 161 |
thrmgr_setactivetask(NULL, CMD7); |
166 |
- if(!(path = malloc(strlen(dbdir) + 30))) { |
|
167 |
- mdprintf(desc, "Memory allocation error - SHUTDOWN forced\n"); |
|
168 |
- return COMMAND_SHUTDOWN; |
|
169 |
- } |
|
170 |
- |
|
171 |
- sprintf(path, "%s/daily.cvd", dbdir); |
|
172 |
- if(access(path, R_OK)) |
|
173 |
- sprintf(path, "%s/daily.cld", dbdir); |
|
174 |
- |
|
175 |
- if(!access(path, R_OK) && (daily = cl_cvdhead(path))) { |
|
162 |
+ if(engine->dbversion[0]) { |
|
176 | 163 |
char timestr[32]; |
177 |
- time_t t = (time_t) daily->stime; |
|
164 |
+ time_t t = (time_t) engine->dbversion[1]; |
|
178 | 165 |
|
179 |
- mdprintf(desc, "ClamAV %s/%d/%s", get_version(), daily->version, cli_ctime(&t, timestr, sizeof(timestr))); |
|
180 |
- cl_cvdfree(daily); |
|
166 |
+ mdprintf(desc, "ClamAV %s/%d/%s", get_version(), engine->dbversion[0], cli_ctime(&t, timestr, sizeof(timestr))); |
|
181 | 167 |
} else { |
182 | 168 |
mdprintf(desc, "ClamAV %s\n", get_version()); |
183 | 169 |
} |
184 | 170 |
|
185 |
- free(path); |
|
186 |
- |
|
187 | 171 |
} else if(!strncmp(buff, CMD8, strlen(CMD8))) { /* STREAM */ |
188 | 172 |
thrmgr_setactivetask(NULL, CMD8); |
189 | 173 |
if(scanstream(desc, NULL, engine, limits, options, copt) == CL_EMEM) |
... | ... |
@@ -500,7 +500,7 @@ int cl_cvdverify(const char *file) |
500 | 500 |
return ret; |
501 | 501 |
} |
502 | 502 |
|
503 |
-int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short warn, unsigned int options, unsigned int cld) |
|
503 |
+int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, unsigned int daily, unsigned int options, unsigned int cld) |
|
504 | 504 |
{ |
505 | 505 |
char *dir; |
506 | 506 |
struct cl_cvd cvd; |
... | ... |
@@ -515,7 +515,7 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short |
515 | 515 |
if((ret = cli_cvdverify(fs, &cvd, cld))) |
516 | 516 |
return ret; |
517 | 517 |
|
518 |
- if(cvd.stime && warn) { |
|
518 |
+ if(cvd.stime && daily) { |
|
519 | 519 |
time(&s_time); |
520 | 520 |
if((int) s_time - cvd.stime > 604800) { |
521 | 521 |
cli_warnmsg("**************************************************\n"); |
... | ... |
@@ -543,6 +543,11 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short |
543 | 543 |
return CL_EIO; |
544 | 544 |
} |
545 | 545 |
|
546 |
+ if(daily) { |
|
547 |
+ (*engine)->dbversion[0] = cvd.version; |
|
548 |
+ (*engine)->dbversion[1] = cvd.stime; |
|
549 |
+ } |
|
550 |
+ |
|
546 | 551 |
if(options & CL_DB_CVDNOTMP) { |
547 | 552 |
|
548 | 553 |
return cli_tgzload(cfd, engine, signo, options | CL_DB_OFFICIAL); |
... | ... |
@@ -31,7 +31,7 @@ struct cli_dbio { |
31 | 31 |
unsigned int size; |
32 | 32 |
}; |
33 | 33 |
|
34 |
-int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short warn, unsigned int options, unsigned int cld); |
|
34 |
+int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, unsigned int daily, unsigned int options, unsigned int cld); |
|
35 | 35 |
int cli_untgz(int fd, const char *destdir); |
36 | 36 |
|
37 | 37 |
#endif |
... | ... |
@@ -388,11 +388,11 @@ int cli_initengine(struct cl_engine **engine, unsigned int options) |
388 | 388 |
cli_errmsg("Can't initialize dynamic configuration\n"); |
389 | 389 |
return CL_EMEM; |
390 | 390 |
} |
391 |
- } |
|
392 | 391 |
|
393 |
- if((options & CL_DB_PHISHING_URLS) && (((struct cli_dconf*) (*engine)->dconf)->phishing & PHISHING_CONF_ENGINE)) |
|
394 |
- if((ret = phishing_init(*engine))) |
|
395 |
- return ret; |
|
392 |
+ if((options & CL_DB_PHISHING_URLS) && (((struct cli_dconf*) (*engine)->dconf)->phishing & PHISHING_CONF_ENGINE)) |
|
393 |
+ if((ret = phishing_init(*engine))) |
|
394 |
+ return ret; |
|
395 |
+ } |
|
396 | 396 |
|
397 | 397 |
return CL_SUCCESS; |
398 | 398 |
} |
... | ... |
@@ -528,11 +528,6 @@ static int cli_loaddb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
528 | 528 |
struct cli_matcher *root; |
529 | 529 |
|
530 | 530 |
|
531 |
- if((ret = cli_initengine(engine, options))) { |
|
532 |
- cl_free(*engine); |
|
533 |
- return ret; |
|
534 |
- } |
|
535 |
- |
|
536 | 531 |
if((ret = cli_initroots(*engine, options))) { |
537 | 532 |
cl_free(*engine); |
538 | 533 |
return ret; |
... | ... |
@@ -589,11 +584,6 @@ static int cli_loadwdb(FILE *fs, struct cl_engine **engine, unsigned int options |
589 | 589 |
int ret = 0; |
590 | 590 |
|
591 | 591 |
|
592 |
- if((ret = cli_initengine(engine, options))) { |
|
593 |
- cl_free(*engine); |
|
594 |
- return ret; |
|
595 |
- } |
|
596 |
- |
|
597 | 592 |
if(!(((struct cli_dconf *) (*engine)->dconf)->phishing & PHISHING_CONF_ENGINE)) |
598 | 593 |
return CL_SUCCESS; |
599 | 594 |
|
... | ... |
@@ -619,11 +609,6 @@ static int cli_loadpdb(FILE *fs, struct cl_engine **engine, unsigned int options |
619 | 619 |
int ret = 0; |
620 | 620 |
|
621 | 621 |
|
622 |
- if((ret = cli_initengine(engine, options))) { |
|
623 |
- cl_free(*engine); |
|
624 |
- return ret; |
|
625 |
- } |
|
626 |
- |
|
627 | 622 |
if(!(((struct cli_dconf *) (*engine)->dconf)->phishing & PHISHING_CONF_ENGINE)) |
628 | 623 |
return CL_SUCCESS; |
629 | 624 |
|
... | ... |
@@ -656,11 +641,6 @@ static int cli_loadndb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
656 | 656 |
unsigned int phish = options & CL_DB_PHISHING; |
657 | 657 |
|
658 | 658 |
|
659 |
- if((ret = cli_initengine(engine, options))) { |
|
660 |
- cl_free(*engine); |
|
661 |
- return ret; |
|
662 |
- } |
|
663 |
- |
|
664 | 659 |
if((ret = cli_initroots(*engine, options))) { |
665 | 660 |
cl_free(*engine); |
666 | 661 |
return ret; |
... | ... |
@@ -946,11 +926,6 @@ static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
946 | 946 |
struct cli_lsig_tdb tdb; |
947 | 947 |
|
948 | 948 |
|
949 |
- if((ret = cli_initengine(engine, options))) { |
|
950 |
- cl_free(*engine); |
|
951 |
- return ret; |
|
952 |
- } |
|
953 |
- |
|
954 | 949 |
if((ret = cli_initroots(*engine, options))) { |
955 | 950 |
cl_free(*engine); |
956 | 951 |
return ret; |
... | ... |
@@ -1127,11 +1102,6 @@ static int cli_loadftm(FILE *fs, struct cl_engine **engine, unsigned int options |
1127 | 1127 |
int ret; |
1128 | 1128 |
|
1129 | 1129 |
|
1130 |
- if((ret = cli_initengine(engine, options))) { |
|
1131 |
- cl_free(*engine); |
|
1132 |
- return ret; |
|
1133 |
- } |
|
1134 |
- |
|
1135 | 1130 |
if((ret = cli_initroots(*engine, options))) { |
1136 | 1131 |
cl_free(*engine); |
1137 | 1132 |
return ret; |
... | ... |
@@ -1258,13 +1228,8 @@ static int cli_loadign(FILE *fs, struct cl_engine **engine, unsigned int options |
1258 | 1258 |
unsigned int line = 0; |
1259 | 1259 |
struct cli_ignsig *new; |
1260 | 1260 |
struct cli_ignored *ignored; |
1261 |
- int ret; |
|
1262 |
- |
|
1261 |
+ int ret = CL_SUCCESS; |
|
1263 | 1262 |
|
1264 |
- if((ret = cli_initengine(engine, options))) { |
|
1265 |
- cl_free(*engine); |
|
1266 |
- return ret; |
|
1267 |
- } |
|
1268 | 1263 |
|
1269 | 1264 |
if(!(ignored = (*engine)->ignored)) { |
1270 | 1265 |
ignored = (*engine)->ignored = (struct cli_ignored *) cli_calloc(sizeof(struct cli_ignored), 1); |
... | ... |
@@ -1421,10 +1386,6 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
1421 | 1421 |
struct cli_bm_patt *new; |
1422 | 1422 |
struct cli_matcher *db = NULL; |
1423 | 1423 |
|
1424 |
- if((ret = cli_initengine(engine, options))) { |
|
1425 |
- cl_free(*engine); |
|
1426 |
- return ret; |
|
1427 |
- } |
|
1428 | 1424 |
|
1429 | 1425 |
if(mode == MD5_MDB) { |
1430 | 1426 |
size_field = 0; |
... | ... |
@@ -1562,15 +1523,10 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
1562 | 1562 |
{ |
1563 | 1563 |
char buffer[FILEBUFF], *pt; |
1564 | 1564 |
unsigned int line = 0, sigs = 0; |
1565 |
- int ret, crc; |
|
1565 |
+ int ret = CL_SUCCESS, crc; |
|
1566 | 1566 |
struct cli_meta_node *new; |
1567 | 1567 |
|
1568 | 1568 |
|
1569 |
- if((ret = cli_initengine(engine, options))) { |
|
1570 |
- cl_free(*engine); |
|
1571 |
- return ret; |
|
1572 |
- } |
|
1573 |
- |
|
1574 | 1569 |
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) { |
1575 | 1570 |
line++; |
1576 | 1571 |
if(buffer[0] == '#') |
... | ... |
@@ -1791,20 +1747,10 @@ int cli_load(const char *filename, struct cl_engine **engine, unsigned int *sign |
1791 | 1791 |
ret = cli_loaddb(fs, engine, signo, options, dbio, dbname); |
1792 | 1792 |
|
1793 | 1793 |
} else if(cli_strbcasestr(dbname, ".cvd")) { |
1794 |
- int warn = 0; |
|
1795 |
- |
|
1796 |
- if(!strcmp(dbname, "daily.cvd")) |
|
1797 |
- warn = 1; |
|
1798 |
- |
|
1799 |
- ret = cli_cvdload(fs, engine, signo, warn, options, 0); |
|
1794 |
+ ret = cli_cvdload(fs, engine, signo, !strcmp(dbname, "daily.cvd"), options, 0); |
|
1800 | 1795 |
|
1801 | 1796 |
} else if(cli_strbcasestr(dbname, ".cld")) { |
1802 |
- int warn = 0; |
|
1803 |
- |
|
1804 |
- if(!strcmp(dbname, "daily.cld")) |
|
1805 |
- warn = 1; |
|
1806 |
- |
|
1807 |
- ret = cli_cvdload(fs, engine, signo, warn, options | CL_DB_CVDNOTMP, 1); |
|
1797 |
+ ret = cli_cvdload(fs, engine, signo, !strcmp(dbname, "daily.cld"), options | CL_DB_CVDNOTMP, 1); |
|
1808 | 1798 |
|
1809 | 1799 |
} else if(cli_strbcasestr(dbname, ".hdb")) { |
1810 | 1800 |
ret = cli_loadmd5(fs, engine, signo, MD5_HDB, options, dbio, dbname); |
... | ... |
@@ -1894,6 +1840,12 @@ int cli_load(const char *filename, struct cl_engine **engine, unsigned int *sign |
1894 | 1894 |
} |
1895 | 1895 |
|
1896 | 1896 |
int cl_loaddb(const char *filename, struct cl_engine **engine, unsigned int *signo) { |
1897 |
+ int ret; |
|
1898 |
+ |
|
1899 |
+ if((ret = cli_initengine(engine, CL_DB_STDOPT))) { |
|
1900 |
+ cl_free(*engine); |
|
1901 |
+ return ret; |
|
1902 |
+ } |
|
1897 | 1903 |
return cli_load(filename, engine, signo, CL_DB_STDOPT, NULL); |
1898 | 1904 |
} |
1899 | 1905 |
|
... | ... |
@@ -1992,6 +1944,12 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine **engine, unsigne |
1992 | 1992 |
} |
1993 | 1993 |
|
1994 | 1994 |
int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo) { |
1995 |
+ int ret; |
|
1996 |
+ |
|
1997 |
+ if((ret = cli_initengine(engine, CL_DB_STDOPT))) { |
|
1998 |
+ cl_free(*engine); |
|
1999 |
+ return ret; |
|
2000 |
+ } |
|
1995 | 2001 |
return cli_loaddbdir(dirname, engine, signo, CL_DB_STDOPT); |
1996 | 2002 |
} |
1997 | 2003 |
|
... | ... |
@@ -2002,7 +1960,7 @@ int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, un |
2002 | 2002 |
|
2003 | 2003 |
|
2004 | 2004 |
if(stat(path, &sb) == -1) { |
2005 |
- cli_errmsg("cl_loaddbdir(): Can't get status of %s\n", path); |
|
2005 |
+ cli_errmsg("cl_load(): Can't get status of %s\n", path); |
|
2006 | 2006 |
return CL_EIO; |
2007 | 2007 |
} |
2008 | 2008 |
|