Browse code

unify client_scan restore summary spam

git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4666 77e5149b-7576-45b1-b177-96237e5ba77b

aCaB authored on 2009/01/30 20:30:54
Showing 1 changed files
... ...
@@ -451,9 +451,11 @@ int callback(struct stat *sb, char *filename, const char *path, enum cli_ftw_rea
451 451
     return CL_SUCCESS;
452 452
 }
453 453
 
454
-static int client_scan(const char *file, int scantype, int *infected, int *errors, int level) {
454
+static int client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel) {
455 455
     struct cli_ftw_cbdata data;
456 456
     struct client_cb_data cdata;
457
+    char *fullpath;
458
+    int namelen;
457 459
 
458 460
     cdata.infected = 0;
459 461
     cdata.errors = 0;
... ...
@@ -461,9 +463,28 @@ static int client_scan(const char *file, int scantype, int *infected, int *error
461 461
     cdata.spam = 0;
462 462
     data.data = &cdata;
463 463
 
464
-    cli_ftw(file, CLI_FTW_STD, 10, callback, &data);
464
+    if(!(fullpath = malloc(PATH_MAX + 1))) {
465
+	logg("^Can't make room for fullpath.\n");
466
+	(*errors)++;
467
+	return 1;
468
+    }
469
+    if(*file != '/') { /* FIXME: to be unified */
470
+	if(!getcwd(fullpath, PATH_MAX)) {
471
+	    logg("^Can't get absolute pathname of current working directory.\n");
472
+	    free(fullpath);
473
+	    (*errors)++;
474
+	    return 1;
475
+	}
476
+	namelen = strlen(fullpath);
477
+	snprintf(&fullpath[namelen], PATH_MAX - namelen, "/%s", file);
478
+    } else {
479
+	strncpy(fullpath, file, PATH_MAX);
480
+    }
481
+    fullpath[PATH_MAX] = '\0';
465 482
 
466
-    if(!cdata.errors) logg("~%s: OK\n", file);
483
+    cli_ftw(fullpath, CLI_FTW_STD, maxlevel ? maxlevel : INT_MAX, callback, &data);
484
+    if(!cdata.infected && (!cdata.errors || cdata.spam)) logg("~%s: OK\n", fullpath);
485
+    free(fullpath);
467 486
 
468 487
     *infected += cdata.infected;
469 488
     *errors += cdata.errors;
... ...
@@ -528,7 +549,7 @@ int client(const struct optstruct *opts, int *infected)
528 528
 {
529 529
 	const char *clamd_conf = optget(opts, "config-file")->strarg;
530 530
 	struct optstruct *clamdopts;
531
-	int remote, scantype, session = 0, errors = 0, scandash = 0;
531
+	int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec;
532 532
 
533 533
     if((clamdopts = optparse(clamd_conf, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
534 534
 	logg("!Can't parse clamd configuration file %s\n", clamd_conf);
... ...
@@ -549,6 +570,7 @@ int client(const struct optstruct *opts, int *infected)
549 549
     } else if(optget(opts, "multiscan")->enabled) scantype = MULTI;
550 550
     else scantype = CONT;
551 551
 
552
+    maxrec = optget(clamdopts, "MaxDirectoryRecursion")->numarg;
552 553
     optfree(clamdopts);
553 554
 
554 555
     if(!mainsa) {
... ...
@@ -571,40 +593,14 @@ int client(const struct optstruct *opts, int *infected)
571 571
     } else if(opts->filename) {
572 572
 	unsigned int i;
573 573
 	for (i = 0; opts->filename[i]; i++) {
574
-	    char *fullpath;
575 574
 	    if(!strcmp(opts->filename[i], "-")) {
576 575
 		logg("!Scanning from standard input requires \"-\" to be the only file argument\n");
577 576
 		continue;
578 577
 	    }
579
-	    if(!(fullpath = malloc(PATH_MAX + 1))) {
580
-		logg("^Can't make room for fullpath.\n");
581
-		errors++;
582
-		continue;
583
-	    }
584
-	    if(*opts->filename[i] != '/') { /* FIXME: to be unified */
585
-		int namelen;
586
-		if(!getcwd(fullpath, PATH_MAX)) {
587
-		    logg("^Can't get absolute pathname of current working directory.\n");
588
-		    free(fullpath);
589
-		    errors++;
590
-		    break;
591
-		}
592
-		namelen = strlen(fullpath);
593
-		snprintf(&fullpath[namelen], PATH_MAX - namelen, "/%s", opts->filename[i]);
594
-	    } else {
595
-		strncpy(fullpath, opts->filename[i], PATH_MAX);
596
-	    }
597
-	    fullpath[PATH_MAX] = '\0';
598
-	    client_scan(opts->filename[i], scantype, infected, &errors, 0);
599
-	    free(fullpath);
578
+	    if(client_scan(opts->filename[i], scantype, infected, &errors, maxrec)) break;
600 579
 	}
601 580
     } else {
602
-	char cwd[PATH_MAX+1];
603
-	if(!getcwd(cwd, PATH_MAX)) {
604
-	    logg("^Can't get absolute pathname of current working directory.\n");
605
-	    return 2;
606
-	}
607
-	client_scan(cwd, scantype, infected, &errors, 0);
581
+	client_scan("", scantype, infected, &errors, maxrec);
608 582
     }
609 583
     return *infected ? 1 : (errors ? 2 : 0);
610 584
 }