git-svn: trunk@2043
Tomasz Kojm authored on 2006/06/22 18:16:07... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Thu Jun 22 11:14:25 CEST 2006 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * sigtool/sigtool.c: create db.info file and include it in CVD |
|
4 |
+ |
|
1 | 5 |
Wed Jun 21 21:06:06 CEST 2006 (tk) |
2 | 6 |
---------------------------------- |
3 | 7 |
* sigtool/sigtool.c: use getpass() replacement in getdsig(), thanks to |
... | ... |
@@ -263,11 +263,61 @@ static char *getdsig(const char *host, const char *user, const char *data) |
263 | 263 |
return strdup(pt); |
264 | 264 |
} |
265 | 265 |
|
266 |
+static int writeinfo(const char *db, unsigned int ver) |
|
267 |
+{ |
|
268 |
+ FILE *fh; |
|
269 |
+ int i; |
|
270 |
+ struct stat sb; |
|
271 |
+ char file[32], *md5; |
|
272 |
+ char *extlist[] = { "db", "fp", "hdb", "ndb", "rmd", "zmd", "sdb", NULL }; |
|
273 |
+ |
|
274 |
+ |
|
275 |
+ snprintf(file, sizeof(file), "%s.info", db); |
|
276 |
+ if(stat(file, &sb) != -1) { |
|
277 |
+ if(unlink(file) == -1) { |
|
278 |
+ logg("!writeinfo: Can't unlink %s\n", file); |
|
279 |
+ return -1; |
|
280 |
+ } |
|
281 |
+ } |
|
282 |
+ |
|
283 |
+ if(!(fh = fopen(file, "w"))) { |
|
284 |
+ logg("!writeinfo: Can't create file %s\n", file); |
|
285 |
+ return -1; |
|
286 |
+ } |
|
287 |
+ |
|
288 |
+ if(fprintf(fh, "%s:%u\n", db, ver) < 0) { |
|
289 |
+ logg("!writeinfo: Can't write to info file\n"); |
|
290 |
+ fclose(fh); |
|
291 |
+ return -1; |
|
292 |
+ } |
|
293 |
+ |
|
294 |
+ for(i = 0; extlist[i]; i++) { |
|
295 |
+ snprintf(file, sizeof(file), "%s.%s", db, extlist[i]); |
|
296 |
+ if(stat(file, &sb) != -1) { |
|
297 |
+ if(!(md5 = cli_md5file(file))) { |
|
298 |
+ logg("!writeinfo: Can't generate MD5 checksum for %s\n", file); |
|
299 |
+ fclose(fh); |
|
300 |
+ return -1; |
|
301 |
+ } |
|
302 |
+ if(fprintf(fh, "%s.%s:%s\n", db, extlist[i], md5) < 0) { |
|
303 |
+ logg("!writeinfo: Can't write to info file\n"); |
|
304 |
+ fclose(fh); |
|
305 |
+ free(md5); |
|
306 |
+ return -1; |
|
307 |
+ } |
|
308 |
+ free(md5); |
|
309 |
+ } |
|
310 |
+ } |
|
311 |
+ |
|
312 |
+ fclose(fh); |
|
313 |
+ return 0; |
|
314 |
+} |
|
315 |
+ |
|
266 | 316 |
static int build(struct optstruct *opt) |
267 | 317 |
{ |
268 |
- int ret, itmp; |
|
318 |
+ int ret; |
|
269 | 319 |
size_t bytes; |
270 |
- unsigned int sigs = 0, lines = 0; |
|
320 |
+ unsigned int sigs = 0, lines = 0, version; |
|
271 | 321 |
struct stat foo; |
272 | 322 |
char buffer[FILEBUFF], *tarfile, *gzfile, header[513], |
273 | 323 |
smbuff[30], *pt, *dbdir; |
... | ... |
@@ -276,7 +326,7 @@ static int build(struct optstruct *opt) |
276 | 276 |
gzFile *gz; |
277 | 277 |
time_t timet; |
278 | 278 |
struct tm *brokent; |
279 |
- struct cl_cvd *oldcvd = NULL; |
|
279 |
+ struct cl_cvd *oldcvd; |
|
280 | 280 |
|
281 | 281 |
|
282 | 282 |
if(!opt_check(opt, "server")) { |
... | ... |
@@ -292,6 +342,7 @@ static int build(struct optstruct *opt) |
292 | 292 |
if(stat("main.db", &foo) == -1 && stat("daily.db", &foo) == -1 && |
293 | 293 |
stat("main.hdb", &foo) == -1 && stat("daily.hdb", &foo) == -1 && |
294 | 294 |
stat("main.ndb", &foo) == -1 && stat("daily.ndb", &foo) == -1 && |
295 |
+ stat("main.sdb", &foo) == -1 && stat("daily.sdb", &foo) == -1 && |
|
295 | 296 |
stat("main.zmd", &foo) == -1 && stat("daily.zmd", &foo) == -1 && |
296 | 297 |
stat("main.rmd", &foo) == -1 && stat("daily.rmd", &foo) == -1) |
297 | 298 |
{ |
... | ... |
@@ -315,6 +366,7 @@ static int build(struct optstruct *opt) |
315 | 315 |
lines = countlines("main.db") + countlines("daily.db") + |
316 | 316 |
countlines("main.hdb") + countlines("daily.hdb") + |
317 | 317 |
countlines("main.ndb") + countlines("daily.ndb") + |
318 |
+ countlines("main.sdb") + countlines("daily.sdb") + |
|
318 | 319 |
countlines("main.zmd") + countlines("daily.zmd") + |
319 | 320 |
countlines("main.rmd") + countlines("daily.rmd") + |
320 | 321 |
countlines("main.fp") + countlines("daily.fp"); |
... | ... |
@@ -327,6 +379,35 @@ static int build(struct optstruct *opt) |
327 | 327 |
} |
328 | 328 |
} |
329 | 329 |
|
330 |
+ /* try to read cvd header of current database */ |
|
331 |
+ dbdir = freshdbdir(); |
|
332 |
+ snprintf(buffer, sizeof(buffer), "%s/%s", dbdir, opt_arg(opt, "build")); |
|
333 |
+ free(dbdir); |
|
334 |
+ if(!(oldcvd = cl_cvdhead(buffer))) { |
|
335 |
+ logg("^build: CAN'T READ CVD HEADER OF CURRENT DATABASE %s\n", buffer); |
|
336 |
+ sleep(3); |
|
337 |
+ } |
|
338 |
+ |
|
339 |
+ if(oldcvd) { |
|
340 |
+ version = oldcvd->version + 1; |
|
341 |
+ cl_cvdfree(oldcvd); |
|
342 |
+ } else { |
|
343 |
+ fflush(stdin); |
|
344 |
+ logg("Version number: "); |
|
345 |
+ scanf("%u", &version); |
|
346 |
+ } |
|
347 |
+ |
|
348 |
+ pt = opt_arg(opt, "build"); |
|
349 |
+ if(strstr(pt, "main")) |
|
350 |
+ pt = "main"; |
|
351 |
+ else |
|
352 |
+ pt = "daily"; |
|
353 |
+ |
|
354 |
+ if(writeinfo(pt, version) == -1) { |
|
355 |
+ logg("!build: Can't generate info file\n"); |
|
356 |
+ return -1; |
|
357 |
+ } |
|
358 |
+ |
|
330 | 359 |
if(!(tarfile = cli_gentemp("."))) { |
331 | 360 |
logg("!build: Can't generate temporary name for tarfile\n"); |
332 | 361 |
return -1; |
... | ... |
@@ -341,9 +422,10 @@ static int build(struct optstruct *opt) |
341 | 341 |
{ |
342 | 342 |
char *args[] = { "tar", "-cvf", NULL, "COPYING", "main.db", |
343 | 343 |
"daily.db", "main.hdb", "daily.hdb", |
344 |
- "main.ndb", "daily.ndb", "main.zmd", |
|
345 |
- "daily.zmd", "main.rmd", "daily.rmd", |
|
346 |
- "main.fp", "daily.fp", NULL }; |
|
344 |
+ "main.ndb", "daily.ndb", "main.sdb", |
|
345 |
+ "daily.sdb", "main.zmd", "daily.zmd", |
|
346 |
+ "main.rmd", "daily.rmd", "main.fp", |
|
347 |
+ "daily.fp", "daily.info", "main.info", NULL }; |
|
347 | 348 |
args[2] = tarfile; |
348 | 349 |
execv("/bin/tar", args); |
349 | 350 |
logg("!build: Can't execute tar\n"); |
... | ... |
@@ -398,15 +480,6 @@ static int build(struct optstruct *opt) |
398 | 398 |
unlink(tarfile); |
399 | 399 |
free(tarfile); |
400 | 400 |
|
401 |
- /* try to read cvd header of current database */ |
|
402 |
- dbdir = freshdbdir(); |
|
403 |
- snprintf(buffer, sizeof(buffer), "%s/%s", dbdir, opt_arg(opt, "build")); |
|
404 |
- free(dbdir); |
|
405 |
- if((oldcvd = cl_cvdhead(buffer)) == NULL) { |
|
406 |
- logg("^build: CAN'T READ CVD HEADER OF CURRENT DATABASE %s\n", buffer); |
|
407 |
- sleep(3); |
|
408 |
- } |
|
409 |
- |
|
410 | 401 |
/* build header */ |
411 | 402 |
strcpy(header, "ClamAV-VDB:"); |
412 | 403 |
|
... | ... |
@@ -418,14 +491,7 @@ static int build(struct optstruct *opt) |
418 | 418 |
strcat(header, smbuff); |
419 | 419 |
|
420 | 420 |
/* increment version number by one */ |
421 |
- if(oldcvd) { |
|
422 |
- sprintf(smbuff, ":%d:", oldcvd->version + 1); |
|
423 |
- } else { |
|
424 |
- fflush(stdin); |
|
425 |
- logg("Version number: "); |
|
426 |
- scanf("%d", &itmp); |
|
427 |
- sprintf(smbuff, "%d:", itmp); |
|
428 |
- } |
|
421 |
+ sprintf(smbuff, ":%d:", version); |
|
429 | 422 |
strcat(header, smbuff); |
430 | 423 |
|
431 | 424 |
/* number of signatures */ |
... | ... |
@@ -625,6 +691,7 @@ static int listdir(const char *dirname) |
625 | 625 |
(cli_strbcasestr(dent->d_name, ".db") || |
626 | 626 |
cli_strbcasestr(dent->d_name, ".hdb") || |
627 | 627 |
cli_strbcasestr(dent->d_name, ".ndb") || |
628 |
+ cli_strbcasestr(dent->d_name, ".sdb") || |
|
628 | 629 |
cli_strbcasestr(dent->d_name, ".zmd") || |
629 | 630 |
cli_strbcasestr(dent->d_name, ".rmd") || |
630 | 631 |
cli_strbcasestr(dent->d_name, ".cvd"))) { |
... | ... |
@@ -762,7 +829,7 @@ static int listdb(const char *filename) |
762 | 762 |
free(start); |
763 | 763 |
} |
764 | 764 |
|
765 |
- } else if(cli_strbcasestr(filename, ".ndb") || cli_strbcasestr(filename, ".zmd") || cli_strbcasestr(filename, ".rmd")) { |
|
765 |
+ } else if(cli_strbcasestr(filename, ".ndb") || cli_strbcasestr(filename, ".sdb") || cli_strbcasestr(filename, ".zmd") || cli_strbcasestr(filename, ".rmd")) { |
|
766 | 766 |
|
767 | 767 |
while(fgets(buffer, FILEBUFF, fd)) { |
768 | 768 |
line++; |