b151ef55 |
/* |
d119f7a0 |
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
b151ef55 |
*
* 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 |
30738099 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. |
b151ef55 |
*/
|
8b242bb9 |
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
|
b151ef55 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
|
2bc31f05 |
#include "clamscan_opt.h" |
b151ef55 |
#include "others.h"
#include "shared.h"
#include "manager.h"
#include "defaults.h"
#include "treewalk.h" |
e441c102 |
#include "misc.h" |
b151ef55 |
|
36f2038b |
#include "output.h" |
2bc31f05 |
#include "options.h" |
36f2038b |
|
97de3c9d |
#ifdef C_LINUX
#include <sys/resource.h>
#endif
|
b151ef55 |
void help(void);
|
7fbb6473 |
struct s_info claminfo;
short recursion = 0, printinfected = 0, bell = 0;
|
2bc31f05 |
int main(int argc, char **argv) |
b151ef55 |
{
int ds, dms, ret;
double mb;
struct timeval t1, t2;
struct timezone tz; |
2bc31f05 |
struct optstruct *opt;
const char *pt; |
b151ef55 |
|
2bc31f05 |
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")) { |
36f2038b |
mprintf_verbose = 1;
logg_verbose = 1;
} |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "quiet")) |
7fbb6473 |
mprintf_quiet = 1; |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "stdout")) |
7fbb6473 |
mprintf_stdout = 1; |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "debug")) { |
97de3c9d |
#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 */
} |
0bcad2b1 |
|
2bc31f05 |
if(opt_check(opt, "version")) {
opt_free(opt); |
e441c102 |
print_version(); |
d927f46c |
return 0; |
b151ef55 |
}
|
2bc31f05 |
if(opt_check(opt, "help")) {
opt_free(opt); |
b151ef55 |
help(); |
2bc31f05 |
return 0; |
b151ef55 |
}
|
2bc31f05 |
if(opt_check(opt, "recursive")) |
7fbb6473 |
recursion = 1; |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "infected")) |
7fbb6473 |
printinfected = 1; |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "bell")) |
7fbb6473 |
bell = 1; |
026ebd88 |
|
2bc31f05 |
if(opt_check(opt, "tempdir"))
cl_settempdir(opt_arg(opt, "tempdir"), 0); |
3506c157 |
|
2bc31f05 |
if(opt_check(opt, "leave-temps")) |
3506c157 |
cl_settempdir(NULL, 1);
|
b151ef55 |
/* initialize logger */ |
2bc31f05 |
if(opt_check(opt, "logger")) {
logg_file = opt_arg(opt, "logger"); |
18bf7562 |
if(logg("#\n-------------------------------------------------------------------------------\n\n")) { |
b151ef55 |
mprintf("!Problem with internal logger.\n"); |
2bc31f05 |
opt_free(opt); |
ed826ef4 |
return 62; |
b151ef55 |
}
} else |
36f2038b |
logg_file = NULL; |
b151ef55 |
|
2bc31f05 |
/* 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); |
ed826ef4 |
return 40; |
b151ef55 |
} |
2bc31f05 |
}
} |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "max-files")) {
if(!isnumb(opt_arg(opt, "max-files"))) {
logg("!--max-files requires a natural number\n");
opt_free(opt); |
ed826ef4 |
return 40; |
b151ef55 |
} |
2bc31f05 |
} |
b151ef55 |
|
2bc31f05 |
if(opt_check(opt, "max-recursion")) {
if(!isnumb(opt_arg(opt, "max-recursion"))) {
logg("!--max-recursion requires a natural number\n");
opt_free(opt); |
ed826ef4 |
return 40; |
b151ef55 |
} |
2bc31f05 |
} |
b151ef55 |
|
2bc31f05 |
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); |
112cc469 |
return 40;
} |
2bc31f05 |
} |
112cc469 |
|
2bc31f05 |
if(opt_check(opt, "max-ratio")) {
if(!isnumb(opt_arg(opt, "max-ratio"))) {
logg("!--max-ratio requires a natural number\n");
opt_free(opt); |
112cc469 |
return 40;
} |
2bc31f05 |
} |
b151ef55 |
memset(&claminfo, 0, sizeof(struct s_info));
gettimeofday(&t1, &tz);
ret = scanmanager(opt);
|
2bc31f05 |
if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) { |
b151ef55 |
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); |
f1c4563e |
logg("\n----------- SCAN SUMMARY -----------\n");
logg("Known viruses: %d\n", claminfo.signs); |
7def75f3 |
if(opt_check(opt, "ncore"))
logg("Engine version: %s [ncore]\n", cl_retver()); |
d119f7a0 |
else
logg("Engine version: %s\n", cl_retver()); |
f1c4563e |
logg("Scanned directories: %d\n", claminfo.dirs);
logg("Scanned files: %d\n", claminfo.files);
logg("Infected files: %d\n", claminfo.ifiles); |
b151ef55 |
if(claminfo.notremoved) { |
f1c4563e |
logg("Not removed: %d\n", claminfo.notremoved); |
b151ef55 |
}
if(claminfo.notmoved) { |
f1c4563e |
logg("Not moved: %d\n", claminfo.notmoved); |
b151ef55 |
}
mb = claminfo.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0; |
f1c4563e |
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); |
b151ef55 |
}
|
2bc31f05 |
opt_free(opt); |
d927f46c |
return ret; |
b151ef55 |
}
void help(void)
{
mprintf_stdout = 1;
mprintf("\n"); |
8ef2ff6f |
mprintf(" Clam AntiVirus Scanner "VERSION"\n");
mprintf(" (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n"); |
a0faaedf |
|
94da957a |
mprintf(" --help -h Print this help screen\n");
mprintf(" --version -V Print version number\n"); |
a0faaedf |
mprintf(" --verbose -v Be verbose\n"); |
94da957a |
mprintf(" --debug Enable libclamav's debug messages\n");
mprintf(" --quiet Only output error messages\n"); |
a0faaedf |
mprintf(" --stdout Write to stdout instead of stderr\n"); |
94da957a |
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");
|
b151ef55 |
mprintf("\n"); |
c2484690 |
mprintf(" --tempdir=DIRECTORY Create temporary files in DIRECTORY\n");
mprintf(" --leave-temps Do not remove temporary files\n"); |
a0faaedf |
mprintf(" --database=FILE/DIR -d FILE/DIR Load virus database from FILE or load\n"); |
cfe76364 |
mprintf(" all .cvd and .db[2] files from DIR\n"); |
521b19b4 |
mprintf(" --log=FILE -l FILE Save scan report to FILE\n"); |
94da957a |
mprintf(" --recursive -r Scan subdirectories recursively\n");
mprintf(" --remove Remove infected files. Be careful!\n"); |
a0faaedf |
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n"); |
7084e554 |
#ifdef HAVE_REGEX_H
mprintf(" --exclude=REGEX Don't scan file names matching REGEX\n"); |
e9a4812d |
mprintf(" --exclude-dir=REGEX Don't scan directories matching REGEX\n"); |
7084e554 |
mprintf(" --include=REGEX Only scan file names matching REGEX\n"); |
e9a4812d |
mprintf(" --include-dir=REGEX Only scan directories matching REGEX\n"); |
7084e554 |
#else |
a0faaedf |
mprintf(" --exclude=PATT Don't scan file names containing PATT\n"); |
e9a4812d |
mprintf(" --exclude-dir=PATT Don't scan directories containing PATT\n"); |
a0faaedf |
mprintf(" --include=PATT Only scan file names containing PATT\n"); |
e9a4812d |
mprintf(" --include-dir=PATT Only scan directories containing PATT\n"); |
7084e554 |
#endif |
7def75f3 |
#ifdef HAVE_NCORE
mprintf("\n --ncore Use hardware acceleration\n"); |
d119f7a0 |
#endif |
b151ef55 |
mprintf("\n"); |
94da957a |
mprintf(" --no-mail Disable mail file support\n"); |
8eec8ae5 |
mprintf(" --no-phishing Disable phishing detection\n"); |
6366e652 |
#ifdef CL_EXPERIMENTAL
mprintf(" --no-phishing-scan-urls Disable url-based phishing detection\n"); |
1ddad067 |
mprintf(" --phishing-strict-url-check Enable phishing detection for all domains (might lead to false positives!)\n"); |
6366e652 |
#endif |
f32c9757 |
mprintf(" --no-algorithmic Disable algorithmic detection\n"); |
c2484690 |
mprintf(" --no-pe Disable PE analysis\n"); |
c561d2a3 |
mprintf(" --no-ole2 Disable OLE2 support\n"); |
2fe19b26 |
mprintf(" --no-html Disable HTML support\n"); |
026ebd88 |
mprintf(" --no-archive Disable libclamav archive support\n"); |
f8355d13 |
mprintf(" --detect-broken Try to detect broken executable files\n");
mprintf(" --block-encrypted Block encrypted archives\n"); |
728f8802 |
mprintf(" --block-max Block archives that exceed limits\n"); |
b4017e32 |
#ifdef WITH_CURL |
94da957a |
mprintf(" --mail-follow-urls Download and scan URLs\n"); |
b4017e32 |
#endif |
94da957a |
mprintf("\n"); |
3fa35dc1 |
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"); |
f8355d13 |
mprintf(" --max-ratio=#n Maximum compression ratio limit\n"); |
3fa35dc1 |
mprintf(" --max-dir-recursion=#n Maximum directory recursion level\n"); |
a0faaedf |
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"); |
94da957a |
mprintf(" --deb[=FULLPATH to ar] Enable support for .deb files\n"); |
8eec8ae5 |
mprintf(" --tgz[=FULLPATH] Enable support for .tar.gz, .tgz files\n\n"); |
b151ef55 |
} |