2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2006-04-07 19:22:21 +00:00
|
|
|
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-04-09 19:59:28 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
2003-07-29 15:48:06 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
#include "clamscan_opt.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
#include "others.h"
|
|
|
|
#include "shared.h"
|
|
|
|
#include "manager.h"
|
|
|
|
#include "defaults.h"
|
|
|
|
#include "treewalk.h"
|
2004-08-23 20:38:10 +00:00
|
|
|
#include "misc.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-03-29 00:00:58 +00:00
|
|
|
#include "output.h"
|
2006-05-15 18:30:18 +00:00
|
|
|
#include "options.h"
|
2004-03-29 00:00:58 +00:00
|
|
|
|
2003-11-09 19:26:44 +00:00
|
|
|
#ifdef C_LINUX
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
void help(void);
|
|
|
|
|
2004-03-30 21:11:25 +00:00
|
|
|
struct s_info claminfo;
|
|
|
|
short recursion = 0, printinfected = 0, bell = 0;
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
int main(int argc, char **argv)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
int ds, dms, ret;
|
|
|
|
double mb;
|
|
|
|
struct timeval t1, t2;
|
|
|
|
struct timezone tz;
|
2006-05-15 18:30:18 +00:00
|
|
|
struct optstruct *opt;
|
|
|
|
const char *pt;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL);
|
|
|
|
if(!opt) {
|
|
|
|
mprintf("!Can't parse the command line\n");
|
|
|
|
return 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_check(opt, "verbose")) {
|
2004-03-29 00:00:58 +00:00
|
|
|
mprintf_verbose = 1;
|
|
|
|
logg_verbose = 1;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "quiet"))
|
2004-03-30 21:11:25 +00:00
|
|
|
mprintf_quiet = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "stdout"))
|
2004-03-30 21:11:25 +00:00
|
|
|
mprintf_stdout = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
|
|
|
|
if(opt_check(opt, "debug")) {
|
2003-11-09 19:26:44 +00:00
|
|
|
#if defined(C_LINUX)
|
|
|
|
/* njh@bandsman.co.uk: create a dump if needed */
|
|
|
|
struct rlimit rlim;
|
|
|
|
|
|
|
|
rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
|
|
|
|
if(setrlimit(RLIMIT_CORE, &rlim) < 0)
|
|
|
|
perror("setrlimit");
|
|
|
|
#endif
|
|
|
|
cl_debug(); /* enable debug messages */
|
|
|
|
}
|
2003-08-02 22:37:52 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "version")) {
|
|
|
|
opt_free(opt);
|
2004-08-23 20:38:10 +00:00
|
|
|
print_version();
|
2004-03-13 20:08:10 +00:00
|
|
|
return 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "help")) {
|
|
|
|
opt_free(opt);
|
2003-07-29 15:48:06 +00:00
|
|
|
help();
|
2006-05-15 18:30:18 +00:00
|
|
|
return 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "recursive"))
|
2004-03-30 21:11:25 +00:00
|
|
|
recursion = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "infected"))
|
2004-03-30 21:11:25 +00:00
|
|
|
printinfected = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "bell"))
|
2004-03-30 21:11:25 +00:00
|
|
|
bell = 1;
|
2004-01-09 01:10:52 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "tempdir"))
|
|
|
|
cl_settempdir(opt_arg(opt, "tempdir"), 0);
|
2004-05-13 00:27:02 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "leave-temps"))
|
2004-05-13 00:27:02 +00:00
|
|
|
cl_settempdir(NULL, 1);
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
/* initialize logger */
|
2006-10-25 10:44:17 +00:00
|
|
|
if(opt_check(opt, "log")) {
|
|
|
|
logg_file = opt_arg(opt, "log");
|
2005-06-12 09:27:00 +00:00
|
|
|
if(logg("#\n-------------------------------------------------------------------------------\n\n")) {
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("!Problem with internal logger.\n");
|
2006-05-15 18:30:18 +00:00
|
|
|
opt_free(opt);
|
2005-05-11 00:54:14 +00:00
|
|
|
return 62;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
} else
|
2004-03-29 00:00:58 +00:00
|
|
|
logg_file = NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
|
|
|
|
/* validate some numerical options */
|
|
|
|
|
|
|
|
if(opt_check(opt, "max-space")) {
|
|
|
|
pt = opt_arg(opt, "max-space");
|
|
|
|
if(!strchr(pt, 'M') && !strchr(pt, 'm')) {
|
|
|
|
if(!isnumb(pt)) {
|
|
|
|
logg("!--max-space requires a natural number\n");
|
|
|
|
opt_free(opt);
|
2005-05-11 00:54:14 +00:00
|
|
|
return 40;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "max-files")) {
|
|
|
|
if(!isnumb(opt_arg(opt, "max-files"))) {
|
|
|
|
logg("!--max-files requires a natural number\n");
|
|
|
|
opt_free(opt);
|
2005-05-11 00:54:14 +00:00
|
|
|
return 40;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "max-recursion")) {
|
|
|
|
if(!isnumb(opt_arg(opt, "max-recursion"))) {
|
|
|
|
logg("!--max-recursion requires a natural number\n");
|
|
|
|
opt_free(opt);
|
2005-05-11 00:54:14 +00:00
|
|
|
return 40;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "max-dir-recursion")) {
|
|
|
|
if(!isnumb(opt_arg(opt, "max-dir-recursion"))) {
|
|
|
|
logg("!--max-dir-recursion requires a natural number\n");
|
|
|
|
opt_free(opt);
|
2005-07-19 18:17:11 +00:00
|
|
|
return 40;
|
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
}
|
2005-07-19 18:17:11 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(opt_check(opt, "max-ratio")) {
|
|
|
|
if(!isnumb(opt_arg(opt, "max-ratio"))) {
|
|
|
|
logg("!--max-ratio requires a natural number\n");
|
|
|
|
opt_free(opt);
|
2005-07-19 18:17:11 +00:00
|
|
|
return 40;
|
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
memset(&claminfo, 0, sizeof(struct s_info));
|
|
|
|
|
|
|
|
gettimeofday(&t1, &tz);
|
|
|
|
ret = scanmanager(opt);
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) {
|
2003-07-29 15:48:06 +00:00
|
|
|
gettimeofday(&t2, &tz);
|
|
|
|
ds = t2.tv_sec - t1.tv_sec;
|
|
|
|
dms = t2.tv_usec - t1.tv_usec;
|
|
|
|
ds -= (dms < 0) ? (1):(0);
|
|
|
|
dms += (dms < 0) ? (1000000):(0);
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("\n----------- SCAN SUMMARY -----------\n");
|
|
|
|
logg("Known viruses: %d\n", claminfo.signs);
|
2006-10-15 00:25:32 +00:00
|
|
|
if(opt_check(opt, "ncore"))
|
|
|
|
logg("Engine version: %s [ncore]\n", cl_retver());
|
2006-04-07 19:22:21 +00:00
|
|
|
else
|
|
|
|
logg("Engine version: %s\n", cl_retver());
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Scanned directories: %d\n", claminfo.dirs);
|
|
|
|
logg("Scanned files: %d\n", claminfo.files);
|
|
|
|
logg("Infected files: %d\n", claminfo.ifiles);
|
2003-07-29 15:48:06 +00:00
|
|
|
if(claminfo.notremoved) {
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Not removed: %d\n", claminfo.notremoved);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
if(claminfo.notmoved) {
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Not moved: %d\n", claminfo.notmoved);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
mb = claminfo.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Data scanned: %2.2lf MB\n", mb);
|
|
|
|
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
opt_free(opt);
|
2004-03-13 20:08:10 +00:00
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
mprintf_stdout = 1;
|
|
|
|
|
|
|
|
mprintf("\n");
|
2005-03-18 11:57:56 +00:00
|
|
|
mprintf(" Clam AntiVirus Scanner "VERSION"\n");
|
|
|
|
mprintf(" (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --help -h Print this help screen\n");
|
|
|
|
mprintf(" --version -V Print version number\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --verbose -v Be verbose\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --debug Enable libclamav's debug messages\n");
|
|
|
|
mprintf(" --quiet Only output error messages\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --stdout Write to stdout instead of stderr\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --no-summary Disable summary at end of scanning\n");
|
|
|
|
mprintf(" --infected -i Only print infected files\n");
|
|
|
|
mprintf(" --bell Sound bell on virus detection\n");
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("\n");
|
2004-07-05 23:50:55 +00:00
|
|
|
mprintf(" --tempdir=DIRECTORY Create temporary files in DIRECTORY\n");
|
|
|
|
mprintf(" --leave-temps Do not remove temporary files\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --database=FILE/DIR -d FILE/DIR Load virus database from FILE or load\n");
|
2004-05-10 00:48:15 +00:00
|
|
|
mprintf(" all .cvd and .db[2] files from DIR\n");
|
2004-02-20 15:49:29 +00:00
|
|
|
mprintf(" --log=FILE -l FILE Save scan report to FILE\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --recursive -r Scan subdirectories recursively\n");
|
|
|
|
mprintf(" --remove Remove infected files. Be careful!\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
#ifdef HAVE_REGEX_H
|
|
|
|
mprintf(" --exclude=REGEX Don't scan file names matching REGEX\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --exclude-dir=REGEX Don't scan directories matching REGEX\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
mprintf(" --include=REGEX Only scan file names matching REGEX\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --include-dir=REGEX Only scan directories matching REGEX\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
#else
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --exclude=PATT Don't scan file names containing PATT\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --exclude-dir=PATT Don't scan directories containing PATT\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --include=PATT Only scan file names containing PATT\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --include-dir=PATT Only scan directories containing PATT\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
#endif
|
2006-10-15 00:25:32 +00:00
|
|
|
#ifdef HAVE_NCORE
|
|
|
|
mprintf("\n --ncore Use hardware acceleration\n");
|
2006-04-07 19:22:21 +00:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --no-mail Disable mail file support\n");
|
2005-11-13 23:38:41 +00:00
|
|
|
mprintf(" --no-phishing Disable phishing detection\n");
|
2006-09-14 17:40:20 +00:00
|
|
|
#ifdef CL_EXPERIMENTAL
|
|
|
|
mprintf(" --no-phishing-scan-urls Disable url-based phishing detection\n");
|
2006-10-15 00:00:32 +00:00
|
|
|
mprintf(" --phishing-strict-url-check Enable phishing detection for all domains (might lead to false positives!)\n");
|
2006-09-14 17:40:20 +00:00
|
|
|
#endif
|
2006-05-12 18:07:19 +00:00
|
|
|
mprintf(" --no-algorithmic Disable algorithmic detection\n");
|
2004-07-05 23:50:55 +00:00
|
|
|
mprintf(" --no-pe Disable PE analysis\n");
|
2006-10-28 22:01:51 +00:00
|
|
|
mprintf(" --no-elf Disable ELF support\n");
|
2004-01-23 11:17:16 +00:00
|
|
|
mprintf(" --no-ole2 Disable OLE2 support\n");
|
2004-07-02 23:00:58 +00:00
|
|
|
mprintf(" --no-html Disable HTML support\n");
|
2004-01-09 01:10:52 +00:00
|
|
|
mprintf(" --no-archive Disable libclamav archive support\n");
|
2004-08-04 20:11:18 +00:00
|
|
|
mprintf(" --detect-broken Try to detect broken executable files\n");
|
|
|
|
mprintf(" --block-encrypted Block encrypted archives\n");
|
2004-09-13 01:43:57 +00:00
|
|
|
mprintf(" --block-max Block archives that exceed limits\n");
|
2005-07-24 22:27:13 +00:00
|
|
|
#ifdef WITH_CURL
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --mail-follow-urls Download and scan URLs\n");
|
2005-07-24 22:27:13 +00:00
|
|
|
#endif
|
2004-08-18 15:22:48 +00:00
|
|
|
|
|
|
|
mprintf("\n");
|
2005-03-25 22:23:57 +00:00
|
|
|
mprintf(" --max-space=#n Only extract first #n kilobytes from\n");
|
|
|
|
mprintf(" archived files\n");
|
|
|
|
mprintf(" --max-files=#n Only extract first #n files from\n");
|
|
|
|
mprintf(" archives\n");
|
|
|
|
mprintf(" --max-recursion=#n Maximum archive recursion level\n");
|
2004-08-04 20:11:18 +00:00
|
|
|
mprintf(" --max-ratio=#n Maximum compression ratio limit\n");
|
2005-03-25 22:23:57 +00:00
|
|
|
mprintf(" --max-dir-recursion=#n Maximum directory recursion level\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --unzip[=FULLPATH] Enable support for .zip files\n");
|
|
|
|
mprintf(" --unrar[=FULLPATH] Enable support for .rar files\n");
|
|
|
|
mprintf(" --arj[=FULLPATH] Enable support for .arj files\n");
|
|
|
|
mprintf(" --unzoo[=FULLPATH] Enable support for .zoo files\n");
|
|
|
|
mprintf(" --lha[=FULLPATH] Enable support for .lha files\n");
|
|
|
|
mprintf(" --jar[=FULLPATH] Enable support for .jar files\n");
|
|
|
|
mprintf(" --tar[=FULLPATH] Enable support for .tar files\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --deb[=FULLPATH to ar] Enable support for .deb files\n");
|
2005-11-13 23:38:41 +00:00
|
|
|
mprintf(" --tgz[=FULLPATH] Enable support for .tar.gz, .tgz files\n\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|