b151ef55 |
/* |
8b242bb9 |
* Copyright (C) 2002 - 2004 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
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
|
8b242bb9 |
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
|
b151ef55 |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h> |
df52b7aa |
#include <signal.h> |
b151ef55 |
#include "options.h"
#include "others.h"
#include "shared.h"
#include "defaults.h" |
e8217f5a |
#include "client.h" |
36f2038b |
#include "output.h" |
e441c102 |
#include "misc.h" |
b151ef55 |
void help(void);
|
9b0efa74 |
short printinfected = 0;
|
b77a9c76 |
extern int notremoved, notmoved;
|
a0faaedf |
void clamscan(struct optstruct *opt) |
b151ef55 |
{ |
df52b7aa |
int ds, dms, ret, infected; |
b151ef55 |
struct timeval t1, t2;
struct timezone tz;
time_t starttime;
/* initialize some important variables */
|
36f2038b |
if(optc(opt, 'v')) {
mprintf_verbose = 1;
logg_verbose = 1;
} |
b151ef55 |
|
7fbb6473 |
if(optl(opt, "quiet"))
mprintf_quiet = 1; |
b151ef55 |
|
7fbb6473 |
if(optl(opt, "stdout"))
mprintf_stdout = 1; |
b151ef55 |
if(optc(opt, 'V')) { |
e441c102 |
print_version(); |
7fbb6473 |
exit(0); |
b151ef55 |
}
if(optc(opt, 'h')) {
free_opt(opt);
help();
}
|
7fbb6473 |
if(optc(opt, 'i'))
printinfected = 1; |
b151ef55 |
/* initialize logger */
if(optc(opt, 'l')) { |
36f2038b |
logg_file = getargc(opt, 'l'); |
b151ef55 |
if(logg("--------------------------------------\n")) {
mprintf("!Problem with internal logger.\n"); |
7fbb6473 |
exit(2); |
b151ef55 |
}
} else |
36f2038b |
logg_file = NULL; |
b151ef55 |
time(&starttime);
/* ctime() does \n, but I need it once more */
logg("Scan started: %s\n", ctime(&starttime));
gettimeofday(&t1, &tz); |
df52b7aa |
ret = client(opt, &infected); |
b151ef55 |
|
8a05efc5 |
/* Implement STATUS in clamd */ |
51c97adc |
if(!optl(opt, "disable-summary") && !optl(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);
mprintf("\n----------- SCAN SUMMARY -----------\n");
logg("\n-- summary --\n"); |
df52b7aa |
mprintf("Infected files: %d\n", infected);
logg("Infected files: %d\n", infected); |
b77a9c76 |
if(notremoved) {
mprintf("Not removed: %d\n", notremoved);
logg("Not removed: %d\n", notremoved);
}
if(notmoved) {
mprintf("Not moved: %d\n", notmoved);
logg("Not moved: %d\n", notmoved);
} |
b151ef55 |
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);
}
|
7fbb6473 |
exit(ret); |
b151ef55 |
}
void help(void)
{
mprintf_stdout = 1;
mprintf("\n"); |
8ef2ff6f |
mprintf(" ClamAV Daemon Client "VERSION"\n");
mprintf(" (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n"); |
a0faaedf |
mprintf(" --help -h Show help\n");
mprintf(" --version -V Print version number and exit\n");
mprintf(" --verbose -v Be verbose\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");
mprintf(" --log=FILE -l FILE Save scan report in FILE\n"); |
b77a9c76 |
mprintf(" --remove Remove infected files. Be careful!\n");
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n"); |
a0faaedf |
mprintf(" --config-file=FILE Read configuration from FILE.\n"); |
a6d49269 |
mprintf(" --infected -i Only print infected files\n"); |
cba38bf1 |
mprintf(" --no-summary Disable summary at end of scanning\n"); |
a0faaedf |
mprintf("\n"); |
b151ef55 |
exit(0);
} |