Browse code

freshclam: verify integrity of all *.cvd files during each session

Tomasz Kojm authored on 2011/01/14 23:53:29
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jan 14 15:52:30 CET 2011 (tk)
2
+---------------------------------
3
+ * freshclam: verify integrity of all *.cvd files during each session
4
+
1 5
 Mon Jan 10 23:51:08 EET 2011 (edwin)
2 6
 ------------------------------------
3 7
  * libclamav/c++/ClamBCRTChecks.cpp: fix paranoid mode crash (bb #2434).
... ...
@@ -1565,6 +1565,35 @@ static int test_database_wrap(const char *file, const char *newdb, int bytecode)
1565 1565
 }
1566 1566
 #endif
1567 1567
 
1568
+static int checkdbdir(void)
1569
+{
1570
+	DIR *dir;
1571
+	struct dirent *dent;
1572
+	char fname[512];
1573
+	int ret = 0;
1574
+
1575
+    if(!(dir = opendir(dbdir))) {
1576
+	logg("!checkdbdir: Can't open directory %s\n", dbdir);
1577
+	return -1;
1578
+    }
1579
+
1580
+    while((dent = readdir(dir))) {
1581
+	if(dent->d_ino) {
1582
+	    if(/*cli_strbcasestr(dent->d_name, ".cld") ||*/ cli_strbcasestr(dent->d_name, ".cvd")) {
1583
+		snprintf(fname, sizeof(fname), "%s"PATHSEP"%s", dbdir, dent->d_name);
1584
+		if((ret = cl_cvdverify(fname))) {
1585
+		    mprintf("!Corrupted database file %s: %s\n", fname, cl_strerror(ret));
1586
+		    ret = -1;
1587
+		    break;
1588
+		}
1589
+	    }
1590
+	}
1591
+    }
1592
+
1593
+    closedir(dir);
1594
+    return ret;
1595
+}
1596
+
1568 1597
 extern int sigchld_wait;
1569 1598
 
1570 1599
 static int updatedb(const char *dbname, const char *hostname, char *ip, int *signo, const struct optstruct *opts, const char *dnsreply, char *localip, int outdated, struct mirdat *mdat, int logerr, int extra)
... ...
@@ -2276,6 +2305,13 @@ int downloadmanager(const struct optstruct *opts, const char *hostname, int loge
2276 2276
 
2277 2277
     cli_rmdirs(updtmpdir);
2278 2278
 
2279
+    if(checkdbdir() < 0) {
2280
+	logg("!Broken databases found. Please inspect the problem and remove the files manually before restarting freshclam\n");
2281
+	if(newver)
2282
+	    free(newver);
2283
+	return 54;
2284
+    }
2285
+
2279 2286
     if(updated) {
2280 2287
 	if(optget(opts, "HTTPProxyServer")->enabled || !ipaddr[0]) {
2281 2288
 	    logg("Database updated (%d signatures) from %s\n", signo, hostname);