2
* Copyright (C) 2007-2009 Sourcefire, Inc.
4
* Authors: Tomasz Kojm, aCaB
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
#include "clamav-config.h"
37
#include <openssl/ssl.h>
38
#include <openssl/err.h>
39
#include "libclamav/crypto.h"
41
#include "shared/output.h"
42
#include "shared/misc.h"
43
#include "shared/optparser.h"
44
#include "shared/actions.h"
50
extern int printinfected;
51
struct optstruct *clamdopts = NULL;
53
static void print_server_version(const struct optstruct *opt)
55
if(get_clamd_version(opt)) {
56
/* can't get version from server, fallback */
57
printf("ClamAV %s\n", get_version());
61
int main(int argc, char **argv)
63
int ds, dms, ret, infected = 0, err = 0;
64
struct timeval t1, t2;
66
struct optstruct *opts;
67
const struct optstruct *opt;
69
struct sigaction sigact;
72
cl_initialize_crypto();
74
if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMDSCAN, OPT_CLAMSCAN, NULL)) == NULL) {
75
mprintf("!Can't parse command line options\n");
79
if((clamdopts = optparse(optget(opts, "config-file")->strarg, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
80
logg("!Can't parse clamd configuration file %s\n", optget(opts, "config-file")->strarg);
84
if(optget(opts, "verbose")->enabled) {
89
if(optget(opts, "quiet")->enabled)
92
if(optget(opts, "stdout")->enabled)
95
if(optget(opts, "version")->enabled) {
96
print_server_version(opts);
102
if(optget(opts, "help")->enabled) {
108
if(optget(opts, "infected")->enabled)
111
/* initialize logger */
113
if((opt = optget(opts, "log"))->enabled) {
114
logg_file = opt->strarg;
115
if(logg("--------------------------------------\n")) {
116
mprintf("!Problem with internal logger.\n");
125
if(optget(opts, "reload")->enabled) {
126
ret = reload_clamd_database(opts);
141
memset(&sigact, 0, sizeof(struct sigaction));
142
sigact.sa_handler = SIG_IGN;
143
sigemptyset(&sigact.sa_mask);
144
sigaddset(&sigact.sa_mask, SIGPIPE);
145
sigaction(SIGPIPE, &sigact, NULL);
149
/* ctime() does \n, but I need it once more */
151
gettimeofday(&t1, NULL);
153
ret = client(opts, &infected, &err);
156
/* TODO: Implement STATUS in clamd */
157
if(!optget(opts, "no-summary")->enabled) {
158
gettimeofday(&t2, NULL);
159
ds = t2.tv_sec - t1.tv_sec;
160
dms = t2.tv_usec - t1.tv_usec;
161
ds -= (dms < 0) ? (1):(0);
162
dms += (dms < 0) ? (1000000):(0);
163
logg("\n----------- SCAN SUMMARY -----------\n");
164
logg("Infected files: %d\n", infected);
166
logg("Total errors: %d\n", err);
168
logg("Not removed: %d\n", notremoved);
171
logg("Not moved: %d\n", notmoved);
173
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
188
mprintf(" ClamAV Daemon Client %s\n", get_version());
189
printf(" By The ClamAV Team: http://www.clamav.net/team\n");
190
printf(" (C) 2007-2009 Sourcefire, Inc.\n\n");
192
mprintf(" --help -h Show help\n");
193
mprintf(" --version -V Print version number and exit\n");
194
mprintf(" --verbose -v Be verbose\n");
195
mprintf(" --quiet Be quiet, only output error messages\n");
196
mprintf(" --stdout Write to stdout instead of stderr\n");
197
mprintf(" (this help is always written to stdout)\n");
198
mprintf(" --log=FILE -l FILE Save scan report in FILE\n");
199
mprintf(" --file-list=FILE -f FILE Scan files from FILE\n");
200
mprintf(" --remove Remove infected files. Be careful!\n");
201
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n");
202
mprintf(" --copy=DIRECTORY Copy infected files into DIRECTORY\n");
203
mprintf(" --config-file=FILE Read configuration from FILE.\n");
204
mprintf(" --allmatch -z Continue scanning within file after finding a match.\n");
205
mprintf(" --multiscan -m Force MULTISCAN mode\n");
206
mprintf(" --infected -i Only print infected files\n");
207
mprintf(" --no-summary Disable summary at end of scanning\n");
208
mprintf(" --reload Request clamd to reload virus database\n");
209
mprintf(" --fdpass Pass filedescriptor to clamd (useful if clamd is running as a different user)\n");
210
mprintf(" --stream Force streaming files to clamd (for debugging and unit testing)\n");