2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2018-02-06 16:23:07 -05:00
|
|
|
* Copyright (C) 2015, 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
2009-02-13 10:55:45 +00:00
|
|
|
* Copyright (C) 2007-2009 Sourcefire, Inc.
|
|
|
|
*
|
|
|
|
* Authors: Tomasz Kojm, aCaB
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-03-31 20:31:04 +00:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-04-09 19:59:28 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
2003-07-29 15:48:06 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2010-01-31 17:12:34 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <unistd.h>
|
2010-01-31 17:12:34 +01:00
|
|
|
#endif
|
2009-09-24 19:23:21 +02:00
|
|
|
#ifndef _WIN32
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <sys/time.h>
|
2009-09-24 19:23:21 +02:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <time.h>
|
2004-06-22 16:50:58 +00:00
|
|
|
#include <signal.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2014-06-25 13:34:16 -04:00
|
|
|
#include "clamav.h"
|
|
|
|
|
2014-07-01 19:38:01 -04:00
|
|
|
#include "libclamav/clamav.h"
|
2008-12-30 21:16:02 +00:00
|
|
|
#include "shared/output.h"
|
|
|
|
#include "shared/misc.h"
|
|
|
|
#include "shared/optparser.h"
|
2009-02-12 15:14:12 +00:00
|
|
|
#include "shared/actions.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
#include "client.h"
|
2006-05-15 18:30:18 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
void help(void);
|
|
|
|
|
2008-10-07 21:29:57 +00:00
|
|
|
extern int printinfected;
|
2010-05-07 21:14:34 +02:00
|
|
|
struct optstruct *clamdopts = NULL;
|
2004-11-28 23:26:29 +00:00
|
|
|
|
2008-01-10 13:57:05 +00:00
|
|
|
static void print_server_version(const struct optstruct *opt)
|
|
|
|
{
|
|
|
|
if(get_clamd_version(opt)) {
|
|
|
|
/* can't get version from server, fallback */
|
2008-08-04 10:38:24 +00:00
|
|
|
printf("ClamAV %s\n", get_version());
|
2008-01-10 13:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
int main(int argc, char **argv)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
2010-02-03 18:23:30 +01:00
|
|
|
int ds, dms, ret, infected = 0, err = 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
struct timeval t1, t2;
|
|
|
|
time_t starttime;
|
2008-12-30 21:16:02 +00:00
|
|
|
struct optstruct *opts;
|
|
|
|
const struct optstruct *opt;
|
2010-01-31 17:12:34 +01:00
|
|
|
#ifndef _WIN32
|
2009-02-08 16:46:26 +00:00
|
|
|
struct sigaction sigact;
|
2010-01-31 17:12:34 +01:00
|
|
|
#endif
|
2008-12-30 21:16:02 +00:00
|
|
|
|
|
|
|
if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMDSCAN, OPT_CLAMSCAN, NULL)) == NULL) {
|
|
|
|
mprintf("!Can't parse command line options\n");
|
2006-05-15 18:30:18 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2010-05-07 21:14:34 +02:00
|
|
|
if((clamdopts = optparse(optget(opts, "config-file")->strarg, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
|
|
|
|
logg("!Can't parse clamd configuration file %s\n", optget(opts, "config-file")->strarg);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "verbose")->enabled) {
|
2004-03-29 00:00:58 +00:00
|
|
|
mprintf_verbose = 1;
|
|
|
|
logg_verbose = 1;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "quiet")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
mprintf_quiet = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "stdout")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
mprintf_stdout = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "version")->enabled) {
|
|
|
|
print_server_version(opts);
|
|
|
|
optfree(opts);
|
2010-05-07 21:14:34 +02:00
|
|
|
optfree(clamdopts);
|
2004-03-30 21:11:25 +00:00
|
|
|
exit(0);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "help")->enabled) {
|
|
|
|
optfree(opts);
|
2010-05-07 21:14:34 +02:00
|
|
|
optfree(clamdopts);
|
2003-07-29 15:48:06 +00:00
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "infected")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
printinfected = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
/* initialize logger */
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if((opt = optget(opts, "log"))->enabled) {
|
|
|
|
logg_file = opt->strarg;
|
2003-07-29 15:48:06 +00:00
|
|
|
if(logg("--------------------------------------\n")) {
|
|
|
|
mprintf("!Problem with internal logger.\n");
|
2008-12-30 21:16:02 +00:00
|
|
|
optfree(opts);
|
2010-05-07 21:14:34 +02:00
|
|
|
optfree(clamdopts);
|
2004-03-30 21:11:25 +00:00
|
|
|
exit(2);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
} else
|
2004-03-29 00:00:58 +00:00
|
|
|
logg_file = NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if(optget(opts, "reload")->enabled) {
|
2009-02-04 17:18:49 +00:00
|
|
|
ret = reload_clamd_database(opts);
|
2008-12-30 21:16:02 +00:00
|
|
|
optfree(opts);
|
2010-05-07 21:14:34 +02:00
|
|
|
optfree(clamdopts);
|
2008-09-18 08:17:47 +00:00
|
|
|
logg_close();
|
|
|
|
exit(ret);
|
|
|
|
}
|
|
|
|
|
2009-02-12 15:14:12 +00:00
|
|
|
if(actsetup(opts)) {
|
|
|
|
optfree(opts);
|
2010-05-07 21:14:34 +02:00
|
|
|
optfree(clamdopts);
|
2009-02-12 15:14:12 +00:00
|
|
|
logg_close();
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2010-01-31 17:12:34 +01:00
|
|
|
#ifndef _WIN32
|
2009-02-08 16:46:26 +00:00
|
|
|
memset(&sigact, 0, sizeof(struct sigaction));
|
|
|
|
sigact.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset(&sigact.sa_mask);
|
|
|
|
sigaddset(&sigact.sa_mask, SIGPIPE);
|
|
|
|
sigaction(SIGPIPE, &sigact, NULL);
|
2010-01-31 17:12:34 +01:00
|
|
|
#endif
|
2009-01-16 18:29:00 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
time(&starttime);
|
|
|
|
/* ctime() does \n, but I need it once more */
|
|
|
|
|
2009-10-12 23:38:38 +02:00
|
|
|
gettimeofday(&t1, NULL);
|
2004-06-22 16:50:58 +00:00
|
|
|
|
2010-02-03 18:23:30 +01:00
|
|
|
ret = client(opts, &infected, &err);
|
2010-05-07 21:14:34 +02:00
|
|
|
optfree(clamdopts);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
/* TODO: Implement STATUS in clamd */
|
2010-02-03 18:23:30 +01:00
|
|
|
if(!optget(opts, "no-summary")->enabled) {
|
2009-10-12 23:38:38 +02:00
|
|
|
gettimeofday(&t2, NULL);
|
2003-07-29 15:48:06 +00:00
|
|
|
ds = t2.tv_sec - t1.tv_sec;
|
|
|
|
dms = t2.tv_usec - t1.tv_usec;
|
|
|
|
ds -= (dms < 0) ? (1):(0);
|
|
|
|
dms += (dms < 0) ? (1000000):(0);
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("\n----------- SCAN SUMMARY -----------\n");
|
|
|
|
logg("Infected files: %d\n", infected);
|
2010-02-03 18:23:30 +01:00
|
|
|
if(err)
|
2010-02-04 21:33:03 +01:00
|
|
|
logg("Total errors: %d\n", err);
|
2004-11-28 23:26:29 +00:00
|
|
|
if(notremoved) {
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Not removed: %d\n", notremoved);
|
2004-11-28 23:26:29 +00:00
|
|
|
}
|
|
|
|
if(notmoved) {
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Not moved: %d\n", notmoved);
|
2004-11-28 23:26:29 +00:00
|
|
|
}
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 08:17:47 +00:00
|
|
|
logg_close();
|
2008-12-30 21:16:02 +00:00
|
|
|
optfree(opts);
|
2014-05-09 17:09:29 -04:00
|
|
|
cl_cleanup_crypto();
|
2004-03-30 21:11:25 +00:00
|
|
|
exit(ret);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
mprintf_stdout = 1;
|
|
|
|
|
|
|
|
mprintf("\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf(" Clam AntiVirus: Daemon Client %s\n", get_version());
|
2018-03-27 13:06:46 -04:00
|
|
|
mprintf(" By The ClamAV Team: https://www.clamav.net/about.html#credits\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf(" (C) 2007-2018 Cisco Systems, Inc.\n");
|
|
|
|
mprintf("\n");
|
|
|
|
mprintf(" clamdscan [options] [file/directory/-]\n");
|
|
|
|
mprintf("\n");
|
|
|
|
mprintf(" --help -h Show this help\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
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");
|
2009-05-21 13:43:05 +00:00
|
|
|
mprintf(" --file-list=FILE -f FILE Scan files from FILE\n");
|
2004-11-28 23:26:29 +00:00
|
|
|
mprintf(" --remove Remove infected files. Be careful!\n");
|
|
|
|
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n");
|
2006-10-29 14:37:20 +00:00
|
|
|
mprintf(" --copy=DIRECTORY Copy infected files into DIRECTORY\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --config-file=FILE Read configuration from FILE.\n");
|
2012-11-27 14:48:50 -08:00
|
|
|
mprintf(" --allmatch -z Continue scanning within file after finding a match.\n");
|
2007-01-13 00:02:54 +00:00
|
|
|
mprintf(" --multiscan -m Force MULTISCAN mode\n");
|
|
|
|
mprintf(" --infected -i Only print infected files\n");
|
2004-04-10 22:43:41 +00:00
|
|
|
mprintf(" --no-summary Disable summary at end of scanning\n");
|
2008-09-18 08:17:47 +00:00
|
|
|
mprintf(" --reload Request clamd to reload virus database\n");
|
2009-02-17 00:08:17 +00:00
|
|
|
mprintf(" --fdpass Pass filedescriptor to clamd (useful if clamd is running as a different user)\n");
|
|
|
|
mprintf(" --stream Force streaming files to clamd (for debugging and unit testing)\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf("\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|