e3aaff8e |
/* |
f51e962f |
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
e3aaff8e |
*
* 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 |
48b7b4a7 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. |
e3aaff8e |
*/
|
6d6e8271 |
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
|
e3aaff8e |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
|
7b8edc5c |
#include "clamscan_opt.h" |
e3aaff8e |
#include "others.h"
#include "shared.h"
#include "manager.h"
#include "defaults.h"
#include "treewalk.h" |
7b304dee |
#include "misc.h" |
e3aaff8e |
|
afb48b28 |
#include "output.h" |
7b8edc5c |
#include "options.h" |
afb48b28 |
|
fc56deed |
#ifdef C_LINUX
#include <sys/resource.h>
#endif
|
e3aaff8e |
void help(void);
|
58bcf502 |
struct s_info claminfo;
short recursion = 0, printinfected = 0, bell = 0;
|
7b8edc5c |
int main(int argc, char **argv) |
e3aaff8e |
{
int ds, dms, ret;
double mb;
struct timeval t1, t2;
struct timezone tz; |
7b8edc5c |
struct optstruct *opt;
const char *pt; |
e3aaff8e |
|
7b8edc5c |
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")) { |
afb48b28 |
mprintf_verbose = 1;
logg_verbose = 1;
} |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "quiet")) |
58bcf502 |
mprintf_quiet = 1; |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "stdout")) |
58bcf502 |
mprintf_stdout = 1; |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "debug")) { |
fc56deed |
#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 */
} |
d4d14218 |
|
7b8edc5c |
if(opt_check(opt, "version")) {
opt_free(opt); |
7b304dee |
print_version(); |
c32360c1 |
return 0; |
e3aaff8e |
}
|
7b8edc5c |
if(opt_check(opt, "help")) {
opt_free(opt); |
e3aaff8e |
help(); |
7b8edc5c |
return 0; |
e3aaff8e |
}
|
7b8edc5c |
if(opt_check(opt, "recursive")) |
58bcf502 |
recursion = 1; |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "infected")) |
58bcf502 |
printinfected = 1; |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "bell")) |
58bcf502 |
bell = 1; |
af22ece1 |
|
7b8edc5c |
if(opt_check(opt, "tempdir"))
cl_settempdir(opt_arg(opt, "tempdir"), 0); |
590135f9 |
|
7b8edc5c |
if(opt_check(opt, "leave-temps")) |
590135f9 |
cl_settempdir(NULL, 1);
|
e3aaff8e |
/* initialize logger */ |
7b8edc5c |
if(opt_check(opt, "logger")) {
logg_file = opt_arg(opt, "logger"); |
914ce12d |
if(logg("#\n-------------------------------------------------------------------------------\n\n")) { |
e3aaff8e |
mprintf("!Problem with internal logger.\n"); |
7b8edc5c |
opt_free(opt); |
932616b1 |
return 62; |
e3aaff8e |
}
} else |
afb48b28 |
logg_file = NULL; |
e3aaff8e |
|
7b8edc5c |
/* 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); |
932616b1 |
return 40; |
e3aaff8e |
} |
7b8edc5c |
}
} |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "max-files")) {
if(!isnumb(opt_arg(opt, "max-files"))) {
logg("!--max-files requires a natural number\n");
opt_free(opt); |
932616b1 |
return 40; |
e3aaff8e |
} |
7b8edc5c |
} |
e3aaff8e |
|
7b8edc5c |
if(opt_check(opt, "max-recursion")) {
if(!isnumb(opt_arg(opt, "max-recursion"))) {
logg("!--max-recursion requires a natural number\n");
opt_free(opt); |
932616b1 |
return 40; |
e3aaff8e |
} |
7b8edc5c |
} |
e3aaff8e |
|
7b8edc5c |
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); |
75367c6a |
return 40;
} |
7b8edc5c |
} |
75367c6a |
|
7b8edc5c |
if(opt_check(opt, "max-ratio")) {
if(!isnumb(opt_arg(opt, "max-ratio"))) {
logg("!--max-ratio requires a natural number\n");
opt_free(opt); |
75367c6a |
return 40;
} |
7b8edc5c |
} |
e3aaff8e |
memset(&claminfo, 0, sizeof(struct s_info));
gettimeofday(&t1, &tz);
ret = scanmanager(opt);
|
7b8edc5c |
if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) { |
e3aaff8e |
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); |
0ae41a2d |
logg("\n----------- SCAN SUMMARY -----------\n");
logg("Known viruses: %d\n", claminfo.signs); |
7b8edc5c |
if(opt_check(opt, "hwaccel")) |
f51e962f |
logg("Engine version: %s [hwaccel]\n", cl_retver());
else
logg("Engine version: %s\n", cl_retver()); |
0ae41a2d |
logg("Scanned directories: %d\n", claminfo.dirs);
logg("Scanned files: %d\n", claminfo.files);
logg("Infected files: %d\n", claminfo.ifiles); |
e3aaff8e |
if(claminfo.notremoved) { |
0ae41a2d |
logg("Not removed: %d\n", claminfo.notremoved); |
e3aaff8e |
}
if(claminfo.notmoved) { |
0ae41a2d |
logg("Not moved: %d\n", claminfo.notmoved); |
e3aaff8e |
}
mb = claminfo.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0; |
0ae41a2d |
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); |
e3aaff8e |
}
|
7b8edc5c |
opt_free(opt); |
c32360c1 |
return ret; |
e3aaff8e |
}
void help(void)
{
mprintf_stdout = 1;
mprintf("\n"); |
4d89cb07 |
mprintf(" Clam AntiVirus Scanner "VERSION"\n");
mprintf(" (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n"); |
5def21ff |
|
a36e6e5c |
mprintf(" --help -h Print this help screen\n");
mprintf(" --version -V Print version number\n"); |
5def21ff |
mprintf(" --verbose -v Be verbose\n"); |
a36e6e5c |
mprintf(" --debug Enable libclamav's debug messages\n");
mprintf(" --quiet Only output error messages\n"); |
5def21ff |
mprintf(" --stdout Write to stdout instead of stderr\n"); |
a36e6e5c |
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");
|
e3aaff8e |
mprintf("\n"); |
a9082ea2 |
mprintf(" --tempdir=DIRECTORY Create temporary files in DIRECTORY\n");
mprintf(" --leave-temps Do not remove temporary files\n"); |
5def21ff |
mprintf(" --database=FILE/DIR -d FILE/DIR Load virus database from FILE or load\n"); |
908db4df |
mprintf(" all .cvd and .db[2] files from DIR\n"); |
a9ebff44 |
mprintf(" --log=FILE -l FILE Save scan report to FILE\n"); |
a36e6e5c |
mprintf(" --recursive -r Scan subdirectories recursively\n");
mprintf(" --remove Remove infected files. Be careful!\n"); |
5def21ff |
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n"); |
266f3967 |
#ifdef HAVE_REGEX_H
mprintf(" --exclude=REGEX Don't scan file names matching REGEX\n"); |
66ceca09 |
mprintf(" --exclude-dir=REGEX Don't scan directories matching REGEX\n"); |
266f3967 |
mprintf(" --include=REGEX Only scan file names matching REGEX\n"); |
66ceca09 |
mprintf(" --include-dir=REGEX Only scan directories matching REGEX\n"); |
266f3967 |
#else |
5def21ff |
mprintf(" --exclude=PATT Don't scan file names containing PATT\n"); |
66ceca09 |
mprintf(" --exclude-dir=PATT Don't scan directories containing PATT\n"); |
5def21ff |
mprintf(" --include=PATT Only scan file names containing PATT\n"); |
66ceca09 |
mprintf(" --include-dir=PATT Only scan directories containing PATT\n"); |
266f3967 |
#endif |
f51e962f |
#ifdef HAVE_HWACCEL
mprintf("\n --hwaccel Use hardware acceleration\n");
#endif |
e3aaff8e |
mprintf("\n"); |
a36e6e5c |
mprintf(" --no-mail Disable mail file support\n"); |
d6449522 |
mprintf(" --no-phishing Disable phishing detection\n"); |
a68507c5 |
#ifdef CL_EXPERIMENTAL
mprintf(" --no-phishing-scan-urls Disable url-based phishing detection\n"); |
525f4b84 |
mprintf(" --phishing-strict-url-check Enable phishing detection for all domains (might lead to false positives!)\n"); |
a68507c5 |
#endif |
47138a98 |
mprintf(" --no-algorithmic Disable algorithmic detection\n"); |
a9082ea2 |
mprintf(" --no-pe Disable PE analysis\n"); |
47bbbc56 |
mprintf(" --no-ole2 Disable OLE2 support\n"); |
888f5794 |
mprintf(" --no-html Disable HTML support\n"); |
af22ece1 |
mprintf(" --no-archive Disable libclamav archive support\n"); |
20c3d44d |
mprintf(" --detect-broken Try to detect broken executable files\n");
mprintf(" --block-encrypted Block encrypted archives\n"); |
d272908a |
mprintf(" --block-max Block archives that exceed limits\n"); |
3f0112d0 |
#ifdef WITH_CURL |
a36e6e5c |
mprintf(" --mail-follow-urls Download and scan URLs\n"); |
3f0112d0 |
#endif |
a36e6e5c |
mprintf("\n"); |
14dee074 |
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"); |
20c3d44d |
mprintf(" --max-ratio=#n Maximum compression ratio limit\n"); |
14dee074 |
mprintf(" --max-dir-recursion=#n Maximum directory recursion level\n"); |
5def21ff |
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"); |
a36e6e5c |
mprintf(" --deb[=FULLPATH to ar] Enable support for .deb files\n"); |
d6449522 |
mprintf(" --tgz[=FULLPATH] Enable support for .tar.gz, .tgz files\n\n"); |
e3aaff8e |
} |