[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-167-g4319a8f

tkojm tkojm at 77e5149b-7576-45b1-b177-96237e5ba77b
Fri Jun 12 19:12:13 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 6b0f936324dea7037c0bd24ac2a0707418bcbb46
Author: tkojm <tkojm at 77e5149b-7576-45b1-b177-96237e5ba77b>
Date:   Thu May 21 13:43:05 2009 +0000

    clamscan, clamdscan: add support for --file-list/-f
    
    
    git-svn-id: http://svn.clamav.net/svn/clamav-devel/trunk@5069 77e5149b-7576-45b1-b177-96237e5ba77b

diff --git a/ChangeLog b/ChangeLog
index dfdfb01..6cfc9c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu May 21 15:41:36 CEST 2009 (tk)
+----------------------------------
+ * clamscan, clamdscan: add support for --file-list/-f
+
 Fri May 15 15:10:59 EEST 2009 (edwin)
 -------------------------------------
  * libclamav/others.h, libclamav/regex/regex.h: fix compiler warning
diff --git a/clamdscan/clamdscan.c b/clamdscan/clamdscan.c
index a2aea85..6e71ae3 100644
--- a/clamdscan/clamdscan.c
+++ b/clamdscan/clamdscan.c
@@ -169,6 +169,7 @@ void help(void)
     mprintf("    --stdout                           Write to stdout instead of stderr\n");
     mprintf("                                       (this help is always written to stdout)\n");
     mprintf("    --log=FILE          -l FILE        Save scan report in FILE\n");
+    mprintf("    --file-list=FILE    -f FILE        Scan files from FILE\n");
     mprintf("    --remove                           Remove infected files. Be careful!\n");
     mprintf("    --move=DIRECTORY                   Move infected files into DIRECTORY\n");
     mprintf("    --copy=DIRECTORY                   Copy infected files into DIRECTORY\n");
diff --git a/clamdscan/client.c b/clamdscan/client.c
index 91f54bf..cf616e1 100644
--- a/clamdscan/client.c
+++ b/clamdscan/client.c
@@ -215,13 +215,14 @@ int client(const struct optstruct *opts, int *infected)
 	const char *clamd_conf = optget(opts, "config-file")->strarg;
 	struct optstruct *clamdopts;
 	int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec, flags = 0;
+	const char *fname;
 
     if((clamdopts = optparse(clamd_conf, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
 	logg("!Can't parse clamd configuration file %s\n", clamd_conf);
 	return 2;
     }
 
-    scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !opts->filename[1]);
+    scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !optget(opts, "file-list")->enabled && !opts->filename[1]);
     remote = isremote(opts) | optget(opts, "stream")->enabled;
 #ifdef HAVE_FD_PASSING
     if(!remote && optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) {
@@ -261,14 +262,16 @@ int client(const struct optstruct *opts, int *infected)
 	else
 	    errors = 1;
 	if(sockd >= 0) close(sockd);
-    } else if(opts->filename) {
-	unsigned int i;
-	for (i = 0; !errors && opts->filename[i]; i++) {
-	    if(!strcmp(opts->filename[i], "-")) {
+    } else if(opts->filename || optget(opts, "file-list")->enabled) {
+	if(opts->filename && optget(opts, "file-list")->enabled)
+	    logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");
+
+	while(!errors && (fname = filelist(opts, NULL))) {
+	    if(!strcmp(fname, "-")) {
 		logg("!Scanning from standard input requires \"-\" to be the only file argument\n");
 		continue;
 	    }
-	    errors = client_scan(opts->filename[i], scantype, infected, maxrec, session, flags);
+	    errors = client_scan(fname, scantype, infected, maxrec, session, flags);
 	}
     } else {
 	errors = client_scan("", scantype, infected, maxrec, session, flags);
diff --git a/clamscan/clamscan.c b/clamscan/clamscan.c
index f6ea2eb..d1b3e8f 100644
--- a/clamscan/clamscan.c
+++ b/clamscan/clamscan.c
@@ -238,6 +238,7 @@ void help(void)
     mprintf("                                         all supported db files from DIR\n");
     mprintf("    --log=FILE            -l FILE        Save scan report to FILE\n");
     mprintf("    --recursive[=yes/no(*)]  -r          Scan subdirectories recursively\n");
+    mprintf("    --file-list=FILE      -f FILE        Scan files from FILE\n");
     mprintf("    --remove[=yes/no(*)]                 Remove infected files. Be careful!\n");
     mprintf("    --move=DIRECTORY                     Move infected files into DIRECTORY\n");
     mprintf("    --copy=DIRECTORY                     Copy infected files into DIRECTORY\n");
diff --git a/clamscan/manager.c b/clamscan/manager.c
index c38860c..1e6ebf2 100644
--- a/clamscan/manager.c
+++ b/clamscan/manager.c
@@ -238,7 +238,6 @@ static int scandirs(const char *dirname, struct cl_engine *engine, const struct
 		    }
 		    free(fname);
 		}
-
 	    }
 	}
     } else {
@@ -328,11 +327,12 @@ static int scanstdin(const struct cl_engine *engine, const struct optstruct *opt
 int scanmanager(const struct optstruct *opts)
 {
 	mode_t fmode;
-	int ret = 0, fmodeint, i, x;
+	int ret = 0, fmodeint, i;
 	unsigned int options = 0, dboptions = 0;
 	struct cl_engine *engine;
 	struct stat sb;
 	char *file, cwd[1024], *pua_cats = NULL;
+	const char *filename;
 	const struct optstruct *opt;
 #ifndef C_WINDOWS
 	struct rlimit rlim;
@@ -588,7 +588,7 @@ int scanmanager(const struct optstruct *opts)
 #endif
 
     /* check filetype */
-    if(opts->filename == NULL) {
+    if(!opts->filename && !optget(opts, "file-list")->enabled) {
 	/* we need full path for some reasons (eg. archive handling) */
 	if(!getcwd(cwd, sizeof(cwd))) {
 	    logg("!Can't get absolute pathname of current working directory\n");
@@ -596,11 +596,14 @@ int scanmanager(const struct optstruct *opts)
 	} else
 	    ret = scandirs(cwd, engine, opts, options, 1);
 
-    } else if(!strcmp(opts->filename[0], "-")) { /* read data from stdin */
+    } else if(opts->filename && !optget(opts, "file-list")->enabled && !strcmp(opts->filename[0], "-")) { /* read data from stdin */
 	ret = scanstdin(engine, opts, options);
 
     } else {
-	for (x = 0; opts->filename[x] && (file = strdup(opts->filename[x])); x++) {
+	if(opts->filename && optget(opts, "file-list")->enabled)
+	    logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");
+
+	while((filename = filelist(opts, &ret)) && (file = strdup(filename))) {
 	    if((fmodeint = fileinfo(file, 2)) == -1) {
 		logg("^Can't access file %s\n", file);
 		perror(file);
diff --git a/docs/man/clamdscan.1.in b/docs/man/clamdscan.1.in
index 2c55cf4..651ee0c 100644
--- a/docs/man/clamdscan.1.in
+++ b/docs/man/clamdscan.1.in
@@ -33,6 +33,9 @@ Read clamd settings from FILE.
 \fB\-l FILE, \-\-log=FILE\fR
 Save the scan report to FILE.
 .TP 
+\fB\-f FILE, \-\-file\-list=FILE\fR
+Scan files listed line by line in FILE.
+.TP 
 \fB\-m, \-\-multiscan\fR
 In multiscan mode several files are scanned in parallel, one for each available scan thread in clamd.
 This is achieved either via MULTISCAN or IDSESSION requests, depending on the configuration and other options.
diff --git a/docs/man/clamscan.1.in b/docs/man/clamscan.1.in
index 33482bf..807aa1c 100644
--- a/docs/man/clamscan.1.in
+++ b/docs/man/clamscan.1.in
@@ -42,6 +42,9 @@ Create temporary files in DIRECTORY. Directory must be writable for the '@CLAMAV
 \fB\-\-leave\-temps\fR
 Do not remove temporary files.
 .TP 
+\fB\-f FILE, \-\-file\-list=FILE\fR
+Scan files listed line by line in FILE.
+.TP 
 \fB\-r, \-\-recursive\fR
 Scan directories recursively. All the subdirectories in the given directory will be scanned.
 .TP 
diff --git a/shared/misc.c b/shared/misc.c
index 24869fd..49d1de1 100644
--- a/shared/misc.c
+++ b/shared/misc.c
@@ -159,6 +159,45 @@ void print_version(const char *dbdir)
 }
 #endif
 
+const char *filelist(const struct optstruct *opts, int *err)
+{
+	static char buff[1025];
+	static unsigned int cnt = 0;
+	const struct optstruct *opt;
+	static FILE *fs = NULL;
+	size_t len;
+
+    if(!cnt && (opt = optget(opts, "file-list"))->enabled) {
+	if(!fs) {
+	    fs = fopen(opt->strarg, "r");
+	    if(!fs) {
+		fprintf(stderr, "ERROR: --file-list: Can't open file %s\n", opt->strarg);
+		if(err)
+		    *err = 54;
+		return NULL;
+	    }
+	}
+
+	if(fgets(buff, 1024, fs)) {
+	    buff[1024] = 0;
+	    len = strlen(buff);
+	    if(!len) {
+		fclose(fs);
+		return NULL;
+	    }
+	    len--;
+	    while(len && ((buff[len] == '\n') || (buff[len] == '\r')))
+		buff[len--] = '\0';
+	    return buff;
+	} else {
+	    fclose(fs);
+	    return NULL;
+	}
+    }
+
+    return opts->filename ? opts->filename[cnt++] : NULL;
+}
+
 int filecopy(const char *src, const char *dest)
 {
 #ifdef C_DARWIN
diff --git a/shared/misc.h b/shared/misc.h
index 80e0029..2cf6df2 100644
--- a/shared/misc.h
+++ b/shared/misc.h
@@ -46,6 +46,7 @@ typedef unsigned        int     in_addr_t;
 
 char *freshdbdir(void);
 void print_version(const char *dbdir);
+const char *filelist(const struct optstruct *opts, int *err);
 int filecopy(const char *src, const char *dest);
 int daemonize(void);
 const char *get_version(void);
diff --git a/shared/optparser.c b/shared/optparser.c
index 7422c74..99bbe7b 100644
--- a/shared/optparser.c
+++ b/shared/optparser.c
@@ -85,6 +85,7 @@ const struct clam_option clam_options[] = {
     { NULL, "recursive", 'r', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
     { NULL, "bell", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
     { NULL, "no-summary", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
+    { NULL, "file-list", 'f', TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
     { NULL, "infected", 'i', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
     { NULL, "move", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
     { NULL, "copy", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list