e3aaff8e |
/* |
6d6e8271 |
* Copyright (C) 2002 - 2004 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
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
|
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>
#include "options.h"
#include "others.h"
#include "shared.h"
#include "manager.h"
#include "defaults.h"
#include "treewalk.h"
|
afb48b28 |
#include "output.h"
|
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;
|
c32360c1 |
int clamscan(struct optstruct *opt) |
e3aaff8e |
{
int ds, dms, ret;
double mb;
struct timeval t1, t2;
struct timezone tz;
time_t starttime;
/* initialize some important variables */
|
afb48b28 |
if(optc(opt, 'v')) {
mprintf_verbose = 1;
logg_verbose = 1;
} |
e3aaff8e |
|
58bcf502 |
if(optl(opt, "quiet"))
mprintf_quiet = 1; |
e3aaff8e |
|
58bcf502 |
if(optl(opt, "stdout"))
mprintf_stdout = 1; |
e3aaff8e |
|
fc56deed |
if(optl(opt, "debug")) {
#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 |
|
e3aaff8e |
if(optc(opt, 'V')) {
mprintf("clamscan / ClamAV version "VERSION"\n"); |
c32360c1 |
return 0; |
e3aaff8e |
}
if(optc(opt, 'h')) {
free_opt(opt);
help();
}
/* check other options */
|
58bcf502 |
if(optc(opt, 'r'))
recursion = 1; |
e3aaff8e |
|
58bcf502 |
if(optc(opt, 'i'))
printinfected = 1; |
e3aaff8e |
|
58bcf502 |
if(optl(opt, "bell"))
bell = 1; |
af22ece1 |
|
590135f9 |
if(optl(opt, "tempdir"))
cl_settempdir(getargl(opt, "tempdir"), 0);
if(optl(opt, "leave-temps"))
cl_settempdir(NULL, 1);
|
e3aaff8e |
/* initialize logger */
if(optc(opt, 'l')) { |
afb48b28 |
logg_file = getargc(opt, 'l'); |
e3aaff8e |
if(logg("--------------------------------------\n")) {
mprintf("!Problem with internal logger.\n"); |
c32360c1 |
return 1; |
e3aaff8e |
}
} else |
afb48b28 |
logg_file = NULL; |
e3aaff8e |
/* we need some pre-checks */
if(optl(opt, "max-space"))
if(!strchr(getargl(opt, "max-space"), 'M') && !strchr(getargl(opt, "max-space"), 'm'))
if(!isnumb(getargl(opt, "max-space"))) {
mprintf("!--max-space requires natural number.\n");
exit(40);
}
if(optl(opt, "max-files"))
if(!isnumb(getargl(opt, "max-files"))) {
mprintf("!--max-files requires natural number.\n");
exit(40);
}
if(optl(opt, "max-recursion"))
if(!isnumb(getargl(opt, "max-recursion"))) {
mprintf("!--max-recursion requires natural number.\n");
exit(40);
}
time(&starttime);
/* ctime() does \n, but I need it once more */
logg("Scan started: %s\n", ctime(&starttime));
memset(&claminfo, 0, sizeof(struct s_info));
gettimeofday(&t1, &tz);
ret = scanmanager(opt);
|
af22ece1 |
if(!optl(opt, "disable-summary") && !optl(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);
mprintf("\n----------- SCAN SUMMARY -----------\n");
logg("\n-- summary --\n");
mprintf("Known viruses: %d\n", claminfo.signs);
logg("Known viruses: %d\n", claminfo.signs);
mprintf("Scanned directories: %d\n", claminfo.dirs);
logg("Scanned directories: %d\n", claminfo.dirs);
mprintf("Scanned files: %d\n", claminfo.files);
logg("Scanned files: %d\n", claminfo.files);
mprintf("Infected files: %d\n", claminfo.ifiles);
logg("Infected files: %d\n", claminfo.ifiles);
if(claminfo.notremoved) {
mprintf("Not removed: %d\n", claminfo.notremoved);
logg("Not removed: %d\n", claminfo.notremoved);
}
if(claminfo.notmoved) {
mprintf("Not moved: %d\n", claminfo.notmoved);
logg("Not moved: %d\n", claminfo.notmoved);
}
mb = claminfo.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
mprintf("Data scanned: %2.2lf MB\n", mb);
logg("Data scanned: %2.2lf MB\n", mb);
|
f7148839 |
mprintf("I/O buffer size: %d bytes\n", SCANBUFF);
logg("I/O buffer size: %d bytes\n", SCANBUFF); |
e3aaff8e |
mprintf("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
}
|
c32360c1 |
return ret; |
e3aaff8e |
}
void help(void)
{
mprintf_stdout = 1;
mprintf("\n"); |
5def21ff |
mprintf(" Clam AntiVirus Scanner "VERSION"\n"); |
a3ee0766 |
mprintf(" (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>\n\n"); |
5def21ff |
mprintf(" --help -h Show help\n");
mprintf(" --version -V Print version number and exit\n");
mprintf(" --verbose -v Be verbose\n");
mprintf(" --debug Enable debug messages\n");
mprintf(" --quiet Be quiet - only output error messages\n");
mprintf(" --stdout Write to stdout instead of stderr\n");
mprintf(" (this help is always written to stdout)\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"); |
5def21ff |
mprintf(" --recursive -r Scan directories recursively\n");
mprintf(" --infected -i Print infected files only\n");
mprintf(" --remove Remove infected files. Be careful.\n");
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");
mprintf(" --include=REGEX Only scan file names matching REGEX\n");
#else |
5def21ff |
mprintf(" --exclude=PATT Don't scan file names containing PATT\n");
mprintf(" --include=PATT Only scan file names containing PATT\n"); |
266f3967 |
#endif |
af22ece1 |
mprintf(" --bell Sound bell on virus detection\n");
mprintf(" --no-summary Disable summary at end of scanning\n"); |
5def21ff |
mprintf(" --mbox -m Treat stdin as a mailbox\n"); |
e3aaff8e |
mprintf("\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"); |
5484e03c |
mprintf(" --block-encrypted Block encrypted archives.\n"); |
5def21ff |
mprintf(" --max-space=#n Extract first #n kilobytes only\n");
mprintf(" --max-files=#n Extract first #n files only\n");
mprintf(" --max-recursion=#n Maximal recursion level\n");
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");
mprintf(" --deb[=FULLPATH to ar] Enable support for .deb files,\n");
mprintf(" implies --tgz , but doesn't conflict\n");
mprintf(" with --tgz=FULLPATH.\n");
mprintf(" --tgz[=FULLPATH] enable support for .tar.gz, .tgz files\n\n"); |
e3aaff8e |
exit(0);
} |