e3aaff8e |
/* |
7b8edc5c |
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
e3aaff8e |
*
* This program is free software; you can redistribute it and/or modify |
bb34cb31 |
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. |
e3aaff8e |
*
* 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 <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h> |
fe6c6a02 |
#include <signal.h> |
e3aaff8e |
#include "options.h"
#include "others.h"
#include "defaults.h" |
2d70a403 |
#include "client.h" |
afb48b28 |
#include "output.h" |
7b304dee |
#include "misc.h" |
e3aaff8e |
|
2dbbadf2 |
#include "clamscan/clamscan_opt.h" |
7b8edc5c |
|
e3aaff8e |
void help(void);
|
07a73978 |
short printinfected = 0;
|
63abd169 |
extern int notremoved, notmoved;
|
7b8edc5c |
int main(int argc, char **argv) |
e3aaff8e |
{ |
fe6c6a02 |
int ds, dms, ret, infected; |
e3aaff8e |
struct timeval t1, t2;
struct timezone tz;
time_t starttime; |
7b8edc5c |
struct optstruct *opt; |
fc83da82 |
const char *clamdscan_accepted[] = { "help", "version", "verbose", "quiet", |
c6d2bbbc |
"stdout", "log", "move", "copy", "remove", |
7b8edc5c |
"config-file", "no-summary", |
3bb3357a |
"disable-summary", "multiscan", NULL }; |
e3aaff8e |
|
7b8edc5c |
opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, clamdscan_accepted);
if(!opt) {
mprintf("!Can't parse the command line\n");
return 2;
} |
e3aaff8e |
|
7b8edc5c |
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, "version")) { |
7b304dee |
print_version(); |
7b8edc5c |
opt_free(opt); |
58bcf502 |
exit(0); |
e3aaff8e |
}
|
7b8edc5c |
if(opt_check(opt, "help")) {
opt_free(opt); |
e3aaff8e |
help();
}
|
7b8edc5c |
if(opt_check(opt, "infected")) |
58bcf502 |
printinfected = 1; |
e3aaff8e |
/* initialize logger */
|
7b8edc5c |
if(opt_check(opt, "log")) {
logg_file = opt_arg(opt, "log"); |
e3aaff8e |
if(logg("--------------------------------------\n")) {
mprintf("!Problem with internal logger.\n"); |
7b8edc5c |
opt_free(opt); |
58bcf502 |
exit(2); |
e3aaff8e |
}
} else |
afb48b28 |
logg_file = NULL; |
e3aaff8e |
time(&starttime);
/* ctime() does \n, but I need it once more */
gettimeofday(&t1, &tz); |
fe6c6a02 |
ret = client(opt, &infected); |
e3aaff8e |
|
7b8edc5c |
/* TODO: Implement STATUS in clamd */
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("Infected files: %d\n", infected); |
63abd169 |
if(notremoved) { |
0ae41a2d |
logg("Not removed: %d\n", notremoved); |
63abd169 |
}
if(notmoved) { |
0ae41a2d |
logg("Not moved: %d\n", notmoved); |
63abd169 |
} |
0ae41a2d |
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60); |
e3aaff8e |
}
|
7b8edc5c |
opt_free(opt); |
58bcf502 |
exit(ret); |
e3aaff8e |
}
void help(void)
{
mprintf_stdout = 1;
mprintf("\n"); |
4d89cb07 |
mprintf(" ClamAV Daemon Client "VERSION"\n"); |
61409916 |
mprintf(" (C) 2002 - 2007 ClamAV Team - http://www.clamav.net/team\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(" --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"); |
63abd169 |
mprintf(" --remove Remove infected files. Be careful!\n");
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n"); |
c6d2bbbc |
mprintf(" --copy=DIRECTORY Copy infected files into DIRECTORY\n"); |
5def21ff |
mprintf(" --config-file=FILE Read configuration from FILE.\n"); |
3bb3357a |
mprintf(" --multiscan -m Force MULTISCAN mode\n");
mprintf(" --infected -i Only print infected files\n"); |
dc1e77db |
mprintf(" --no-summary Disable summary at end of scanning\n"); |
5def21ff |
mprintf("\n"); |
e3aaff8e |
exit(0);
} |