git-svn: trunk@3899
Tomasz Kojm authored on 2008/07/02 20:13:56... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Wed Jul 2 12:43:46 CEST 2008 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * sigtool/sigtool.c: verify MD5's in --run-cdiff |
|
4 |
+ |
|
1 | 5 |
Mon Jun 30 21:14:03 EEST 2008 (edwin) |
2 | 6 |
------------------------------------ |
3 | 7 |
* freshclam/manager.c: add missing closesocket on error path (bb #1073). |
... | ... |
@@ -1222,6 +1222,56 @@ static int vbadump(struct optstruct *opt) |
1222 | 1222 |
return 0; |
1223 | 1223 |
} |
1224 | 1224 |
|
1225 |
+static int comparemd5(const char *dbname) |
|
1226 |
+{ |
|
1227 |
+ char info[16], buff[256], *md5, *pt; |
|
1228 |
+ FILE *fh; |
|
1229 |
+ int ret = 0; |
|
1230 |
+ |
|
1231 |
+ |
|
1232 |
+ if(strstr(dbname, "main")) |
|
1233 |
+ strcpy(info, "main.info"); |
|
1234 |
+ else |
|
1235 |
+ strcpy(info, "daily.info"); |
|
1236 |
+ |
|
1237 |
+ if(!(fh = fopen(info, "r"))) { |
|
1238 |
+ mprintf("!verifydiff: Can't open %s\n", info); |
|
1239 |
+ return -1; |
|
1240 |
+ } |
|
1241 |
+ |
|
1242 |
+ if(!fgets(buff, sizeof(buff), fh) || strncmp(buff, "ClamAV-VDB", 10)) { |
|
1243 |
+ mprintf("!verifydiff: Incorrect info file %s\n", info); |
|
1244 |
+ fclose(fh); |
|
1245 |
+ return -1; |
|
1246 |
+ } |
|
1247 |
+ |
|
1248 |
+ while(fgets(buff, sizeof(buff), fh)) { |
|
1249 |
+ cli_chomp(buff); |
|
1250 |
+ if(!(pt = strchr(buff, ':'))) { |
|
1251 |
+ mprintf("!verifydiff: Incorrect format of %s\n", info); |
|
1252 |
+ ret = -1; |
|
1253 |
+ break; |
|
1254 |
+ } |
|
1255 |
+ *pt++ = 0; |
|
1256 |
+ if(!(md5 = cli_md5file(buff))) { |
|
1257 |
+ mprintf("!verifydiff: Can't generate MD5 for %s\n", buff); |
|
1258 |
+ ret = -1; |
|
1259 |
+ break; |
|
1260 |
+ } |
|
1261 |
+ if(strcmp(pt, md5)) { |
|
1262 |
+ mprintf("!verifydiff: %s has incorrect checksum\n", buff); |
|
1263 |
+ ret = -1; |
|
1264 |
+ free(md5); |
|
1265 |
+ break; |
|
1266 |
+ } |
|
1267 |
+ free(md5); |
|
1268 |
+ } |
|
1269 |
+ |
|
1270 |
+ fclose(fh); |
|
1271 |
+ return ret; |
|
1272 |
+} |
|
1273 |
+ |
|
1274 |
+ |
|
1225 | 1275 |
static int rundiff(struct optstruct *opt) |
1226 | 1276 |
{ |
1227 | 1277 |
int fd, ret; |
... | ... |
@@ -1247,6 +1297,9 @@ static int rundiff(struct optstruct *opt) |
1247 | 1247 |
ret = cdiff_apply(fd, mode); |
1248 | 1248 |
close(fd); |
1249 | 1249 |
|
1250 |
+ if(!ret) |
|
1251 |
+ ret = comparemd5(diff); |
|
1252 |
+ |
|
1250 | 1253 |
return ret; |
1251 | 1254 |
} |
1252 | 1255 |
|
... | ... |
@@ -1356,8 +1409,7 @@ static int compare(const char *oldpath, const char *newpath, FILE *diff) |
1356 | 1356 |
|
1357 | 1357 |
static int verifydiff(const char *diff, const char *cvd, const char *incdir) |
1358 | 1358 |
{ |
1359 |
- char *tempdir, cwd[512], buff[1024], info[32], *md5, *pt; |
|
1360 |
- FILE *fh; |
|
1359 |
+ char *tempdir, cwd[512]; |
|
1361 | 1360 |
int ret = 0, fd; |
1362 | 1361 |
unsigned short mode; |
1363 | 1362 |
|
... | ... |
@@ -1432,50 +1484,8 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir) |
1432 | 1432 |
} |
1433 | 1433 |
close(fd); |
1434 | 1434 |
|
1435 |
- if(strstr(diff, "main")) |
|
1436 |
- strcpy(info, "main.info"); |
|
1437 |
- else |
|
1438 |
- strcpy(info, "daily.info"); |
|
1435 |
+ ret = comparemd5(diff); |
|
1439 | 1436 |
|
1440 |
- if(!(fh = fopen(info, "r"))) { |
|
1441 |
- mprintf("!verifydiff: Can't open %s\n", info); |
|
1442 |
- if(chdir(cwd) == -1) |
|
1443 |
- mprintf("^verifydiff: Can't chdir to %s\n", cwd); |
|
1444 |
- cli_rmdirs(tempdir); |
|
1445 |
- free(tempdir); |
|
1446 |
- return -1; |
|
1447 |
- } |
|
1448 |
- |
|
1449 |
- if(!fgets(buff, sizeof(buff), fh) || strncmp(buff, "ClamAV-VDB", 10)) { |
|
1450 |
- mprintf("!verifydiff: Incorrect info file %s\n", info); |
|
1451 |
- if(chdir(cwd) == -1) |
|
1452 |
- mprintf("^verifydiff: Can't chdir to %s\n", cwd); |
|
1453 |
- cli_rmdirs(tempdir); |
|
1454 |
- free(tempdir); |
|
1455 |
- return -1; |
|
1456 |
- } |
|
1457 |
- |
|
1458 |
- while(fgets(buff, sizeof(buff), fh)) { |
|
1459 |
- cli_chomp(buff); |
|
1460 |
- if(!(pt = strchr(buff, ':'))) { |
|
1461 |
- mprintf("!verifydiff: Incorrect format of %s\n", info); |
|
1462 |
- ret = -1; |
|
1463 |
- break; |
|
1464 |
- } |
|
1465 |
- *pt++ = 0; |
|
1466 |
- if(!(md5 = cli_md5file(buff))) { |
|
1467 |
- mprintf("!verifydiff: Can't generate MD5 for %s\n", buff); |
|
1468 |
- ret = -1; |
|
1469 |
- break; |
|
1470 |
- } |
|
1471 |
- if(strcmp(pt, md5)) { |
|
1472 |
- mprintf("!verifydiff: %s has incorrect checksum\n", buff); |
|
1473 |
- ret = -1; |
|
1474 |
- break; |
|
1475 |
- } |
|
1476 |
- } |
|
1477 |
- |
|
1478 |
- fclose(fh); |
|
1479 | 1437 |
if(chdir(cwd) == -1) |
1480 | 1438 |
mprintf("^verifydiff: Can't chdir to %s\n", cwd); |
1481 | 1439 |
cli_rmdirs(tempdir); |