e3aaff8e |
/* |
c442ca9c |
* Copyright (C) 2013-2019 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
* Copyright (C) 2007-2013 Sourcefire, Inc. |
086eab5c |
*
* Authors: Tomasz Kojm, aCaB |
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> |
80dea059 |
#ifdef HAVE_UNISTD_H |
e3aaff8e |
#include <unistd.h> |
80dea059 |
#endif |
4cd80898 |
#ifndef _WIN32 |
e3aaff8e |
#include <sys/time.h> |
4cd80898 |
#endif |
e3aaff8e |
#include <time.h> |
fe6c6a02 |
#include <signal.h> |
e3aaff8e |
|
bd249d78 |
#include "clamav.h"
|
60d8d2c3 |
#include "libclamav/clamav.h" |
a68d5e2f |
#include "shared/output.h"
#include "shared/misc.h"
#include "shared/optparser.h" |
ee6702ab |
#include "shared/actions.h" |
e3aaff8e |
|
a68d5e2f |
#include "client.h" |
7b8edc5c |
|
e3aaff8e |
void help(void);
|
d61aeda2 |
extern int printinfected; |
247fe3ae |
struct optstruct *clamdopts = NULL; |
63abd169 |
|
2a363377 |
static void print_server_version(const struct optstruct *opt)
{
if(get_clamd_version(opt)) {
/* can't get version from server, fallback */ |
add738d2 |
printf("ClamAV %s\n", get_version()); |
2a363377 |
}
}
|
7b8edc5c |
int main(int argc, char **argv) |
e3aaff8e |
{ |
dd5092ff |
int ds, dms, ret, infected = 0, err = 0; |
e3aaff8e |
struct timeval t1, t2;
time_t starttime; |
a68d5e2f |
struct optstruct *opts;
const struct optstruct *opt; |
80dea059 |
#ifndef _WIN32 |
c72f64c8 |
struct sigaction sigact; |
80dea059 |
#endif |
a68d5e2f |
if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMDSCAN, OPT_CLAMSCAN, NULL)) == NULL) {
mprintf("!Can't parse command line options\n"); |
7b8edc5c |
return 2;
} |
e3aaff8e |
|
247fe3ae |
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;
}
|
a68d5e2f |
if(optget(opts, "verbose")->enabled) { |
afb48b28 |
mprintf_verbose = 1;
logg_verbose = 1;
} |
e3aaff8e |
|
a68d5e2f |
if(optget(opts, "quiet")->enabled) |
58bcf502 |
mprintf_quiet = 1; |
e3aaff8e |
|
a68d5e2f |
if(optget(opts, "stdout")->enabled) |
58bcf502 |
mprintf_stdout = 1; |
e3aaff8e |
|
a68d5e2f |
if(optget(opts, "version")->enabled) {
print_server_version(opts);
optfree(opts); |
247fe3ae |
optfree(clamdopts); |
58bcf502 |
exit(0); |
e3aaff8e |
}
|
a68d5e2f |
if(optget(opts, "help")->enabled) {
optfree(opts); |
247fe3ae |
optfree(clamdopts); |
e3aaff8e |
help();
}
|
a68d5e2f |
if(optget(opts, "infected")->enabled) |
58bcf502 |
printinfected = 1; |
e3aaff8e |
/* initialize logger */
|
a68d5e2f |
if((opt = optget(opts, "log"))->enabled) {
logg_file = opt->strarg; |
e3aaff8e |
if(logg("--------------------------------------\n")) {
mprintf("!Problem with internal logger.\n"); |
a68d5e2f |
optfree(opts); |
247fe3ae |
optfree(clamdopts); |
58bcf502 |
exit(2); |
e3aaff8e |
}
} else |
afb48b28 |
logg_file = NULL; |
e3aaff8e |
|
a68d5e2f |
if(optget(opts, "reload")->enabled) { |
3bf21904 |
ret = reload_clamd_database(opts); |
a68d5e2f |
optfree(opts); |
247fe3ae |
optfree(clamdopts); |
c1c9d9f9 |
logg_close();
exit(ret);
}
|
ee6702ab |
if(actsetup(opts)) {
optfree(opts); |
247fe3ae |
optfree(clamdopts); |
ee6702ab |
logg_close();
exit(2);
}
|
80dea059 |
#ifndef _WIN32 |
c72f64c8 |
memset(&sigact, 0, sizeof(struct sigaction));
sigact.sa_handler = SIG_IGN;
sigemptyset(&sigact.sa_mask);
sigaddset(&sigact.sa_mask, SIGPIPE);
sigaction(SIGPIPE, &sigact, NULL); |
80dea059 |
#endif |
abd6d2c7 |
|
e3aaff8e |
time(&starttime);
/* ctime() does \n, but I need it once more */
|
b8f3f028 |
gettimeofday(&t1, NULL); |
fe6c6a02 |
|
dd5092ff |
ret = client(opts, &infected, &err); |
247fe3ae |
optfree(clamdopts); |
e3aaff8e |
|
7b8edc5c |
/* TODO: Implement STATUS in clamd */ |
dd5092ff |
if(!optget(opts, "no-summary")->enabled) { |
b8f3f028 |
gettimeofday(&t2, NULL); |
e3aaff8e |
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); |
dd5092ff |
if(err) |
8770404a |
logg("Total errors: %d\n", err); |
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 |
}
|
c1c9d9f9 |
logg_close(); |
a68d5e2f |
optfree(opts); |
f9afc309 |
cl_cleanup_crypto(); |
58bcf502 |
exit(ret); |
e3aaff8e |
}
void help(void)
{
mprintf_stdout = 1;
mprintf("\n"); |
e098cdc5 |
mprintf(" Clam AntiVirus: Daemon Client %s\n", get_version()); |
964a1e73 |
mprintf(" By The ClamAV Team: https://www.clamav.net/about.html#credits\n"); |
c442ca9c |
mprintf(" (C) 2019 Cisco Systems, Inc.\n"); |
e098cdc5 |
mprintf("\n");
mprintf(" clamdscan [options] [file/directory/-]\n");
mprintf("\n");
mprintf(" --help -h Show this help\n"); |
5def21ff |
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"); |
c2b6681b |
mprintf(" --file-list=FILE -f FILE Scan files from 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"); |
1feaa72a |
mprintf(" --allmatch -z Continue scanning within file after finding a match.\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"); |
c1c9d9f9 |
mprintf(" --reload Request clamd to reload virus database\n"); |
408be01f |
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"); |
5def21ff |
mprintf("\n"); |
e3aaff8e |
exit(0);
} |