git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1437 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2005/03/26 07:23:57... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -240,10 +240,13 @@ void help(void) |
240 | 240 |
mprintf(" --mail-follow-urls Download and scan URLs\n"); |
241 | 241 |
|
242 | 242 |
mprintf("\n"); |
243 |
- mprintf(" --max-space=#n Extract first #n kilobytes only\n"); |
|
244 |
- mprintf(" --max-files=#n Extract first #n files only\n"); |
|
245 |
- mprintf(" --max-recursion=#n Maximal recursion level\n"); |
|
243 |
+ mprintf(" --max-space=#n Only extract first #n kilobytes from\n"); |
|
244 |
+ mprintf(" archived files\n"); |
|
245 |
+ mprintf(" --max-files=#n Only extract first #n files from\n"); |
|
246 |
+ mprintf(" archives\n"); |
|
247 |
+ mprintf(" --max-recursion=#n Maximum archive recursion level\n"); |
|
246 | 248 |
mprintf(" --max-ratio=#n Maximum compression ratio limit\n"); |
249 |
+ mprintf(" --max-dir-recursion=#n Maximum directory recursion level\n"); |
|
247 | 250 |
mprintf(" --unzip[=FULLPATH] Enable support for .zip files\n"); |
248 | 251 |
mprintf(" --unrar[=FULLPATH] Enable support for .rar files\n"); |
249 | 252 |
mprintf(" --arj[=FULLPATH] Enable support for .arj files\n"); |
... | ... |
@@ -452,6 +452,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
452 | 452 |
char *tmpdir, *gendir, *userprg; |
453 | 453 |
struct stat statbuf; |
454 | 454 |
|
455 |
+ |
|
455 | 456 |
stat(filename, &statbuf); |
456 | 457 |
|
457 | 458 |
if(!S_ISREG(statbuf.st_mode)) { |
... | ... |
@@ -569,8 +570,13 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
569 | 569 |
/* fix permissions of extracted files */ |
570 | 570 |
fixperms(gendir); |
571 | 571 |
|
572 |
- if(!ret) /* execute successful */ |
|
573 |
- ret = treewalk(gendir, root, user, opt, limits, options); |
|
572 |
+ if(!ret) { /* execute successful */ |
|
573 |
+ short oldrec = recursion; |
|
574 |
+ |
|
575 |
+ recursion = 1; |
|
576 |
+ ret = treewalk(gendir, root, user, opt, limits, options, 1); |
|
577 |
+ recursion = oldrec; |
|
578 |
+ } |
|
574 | 579 |
|
575 | 580 |
/* remove the directory - as clamav */ |
576 | 581 |
if(!optl(opt, "leave-temps")) |
... | ... |
@@ -608,12 +614,8 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
608 | 608 |
case -3: |
609 | 609 |
return 0; |
610 | 610 |
case 0: |
611 |
- /* no viruses found in archive, we scan just in case the same |
|
612 |
- * archive |
|
611 |
+ /* no viruses found in archive, we scan just in case a raw file |
|
613 | 612 |
*/ |
614 |
- if(!printinfected) |
|
615 |
- mprintf("(raw) "); |
|
616 |
- |
|
617 | 613 |
if((ret = checkfile(filename, root, limits, 0)) == CL_VIRUS) { |
618 | 614 |
if(optl(opt, "remove")) { |
619 | 615 |
if(unlink(filename)) { |
... | ... |
@@ -629,8 +631,8 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
629 | 629 |
} |
630 | 630 |
return ret; |
631 | 631 |
case 1: |
632 |
- logg("%s: Infected Archive FOUND\n", filename); |
|
633 |
- mprintf("%s: Infected Archive FOUND\n", filename); |
|
632 |
+ logg("%s: Infected.Archive FOUND\n", filename); |
|
633 |
+ mprintf("%s: Infected.Archive FOUND\n", filename); |
|
634 | 634 |
|
635 | 635 |
if(bell) |
636 | 636 |
fprintf(stderr, "\007"); |
... | ... |
@@ -714,7 +716,7 @@ int scandenied(const char *filename, struct cl_node *root, const struct passwd * |
714 | 714 |
} |
715 | 715 |
#endif |
716 | 716 |
|
717 |
- if((ret = treewalk(gendir, root, user, opt, limits, options)) == 1) { |
|
717 |
+ if((ret = treewalk(gendir, root, user, opt, limits, options, 1)) == 1) { |
|
718 | 718 |
logg("(Real infected archive: %s)\n", filename); |
719 | 719 |
mprintf("(Real infected archive: %s)\n", filename); |
720 | 720 |
|
... | ... |
@@ -742,7 +744,7 @@ int scandenied(const char *filename, struct cl_node *root, const struct passwd * |
742 | 742 |
|
743 | 743 |
int scandirs(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options) |
744 | 744 |
{ |
745 |
- return treewalk(dirname, root, user, opt, limits, options); |
|
745 |
+ return treewalk(dirname, root, user, opt, limits, options, 1); |
|
746 | 746 |
} |
747 | 747 |
|
748 | 748 |
int checkfile(const char *filename, const struct cl_node *root, const struct cl_limits *limits, int options) |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -40,18 +40,14 @@ |
40 | 40 |
#include "memory.h" |
41 | 41 |
#include "output.h" |
42 | 42 |
|
43 |
-/* |
|
44 |
- * recursive functions, similar to ftw(), these functions are duplicated below |
|
45 |
- * with some small changes. |
|
46 |
- */ |
|
47 |
- |
|
48 |
-int treewalk(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options) |
|
43 |
+int treewalk(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options, unsigned int depth) |
|
49 | 44 |
{ |
50 | 45 |
DIR *dd; |
51 | 46 |
struct dirent *dent; |
52 | 47 |
struct stat statbuf; |
53 | 48 |
char *fname; |
54 | 49 |
int scanret = 0, included; |
50 |
+ unsigned int maxdepth; |
|
55 | 51 |
struct optnode *optnode; |
56 | 52 |
char *argument; |
57 | 53 |
|
... | ... |
@@ -86,6 +82,14 @@ int treewalk(const char *dirname, struct cl_node *root, const struct passwd *use |
86 | 86 |
} |
87 | 87 |
} |
88 | 88 |
|
89 |
+ if(optl(opt, "max-dir-recursion")) |
|
90 |
+ maxdepth = atoi(getargl(opt, "max-dir-recursion")); |
|
91 |
+ else |
|
92 |
+ maxdepth = 15; |
|
93 |
+ |
|
94 |
+ if(depth > maxdepth) |
|
95 |
+ return 0; |
|
96 |
+ |
|
89 | 97 |
claminfo.dirs++; |
90 | 98 |
|
91 | 99 |
if((dd = opendir(dirname)) != NULL) { |
... | ... |
@@ -102,7 +106,7 @@ int treewalk(const char *dirname, struct cl_node *root, const struct passwd *use |
102 | 102 |
/* stat the file */ |
103 | 103 |
if(lstat(fname, &statbuf) != -1) { |
104 | 104 |
if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode) && recursion) { |
105 |
- if(treewalk(fname, root, user, opt, limits, options) == 1) |
|
105 |
+ if(treewalk(fname, root, user, opt, limits, options, ++depth) == 1) |
|
106 | 106 |
scanret++; |
107 | 107 |
} else { |
108 | 108 |
if(S_ISREG(statbuf.st_mode)) |
... | ... |
@@ -29,7 +29,7 @@ struct s_du { |
29 | 29 |
long int space; /* in kilobytes */ |
30 | 30 |
}; |
31 | 31 |
|
32 |
-int treewalk(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options); |
|
32 |
+int treewalk(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options, unsigned int depth); |
|
33 | 33 |
|
34 | 34 |
int rmdirs(const char *dirname); |
35 | 35 |
int clamav_rmdirs(const char *dir); |