2
* Copyright (C) 2001 - 2005 Tomasz Kojm <tkojm@clamav.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* Sat Sep 14 22:18:20 CEST 2002: included getfirst*(), getnext*() functions
20
* from Alejandro Dubrovsky <s328940@student.uq.edu.au>
24
#include "clamav-config.h"
40
extern int clamscan(struct optstruct *opt);
42
static char *clamdscan_long[] = { "help", "version", "verbose", "quiet",
43
"stdout", "log", "move", "remove",
44
"config-file", "no-summary",
45
"disable-summary", NULL };
47
static char clamdscan_short[] = { 'h', 'V', 'v', 'l', 0 };
49
int clamdscan_mode = 0;
53
int main(int argc, char **argv)
55
int ret, opt_index, i, len;
56
struct optstruct *opt;
58
const char *getopt_parameters = "hvd:wriVl:m";
60
static struct option long_options[] = {
62
* WARNING: For compatibility reasons options marked as "not used"
63
* must still be accepted !
65
{"help", 0, 0, 'h'}, /* clamscan + clamdscan */
66
{"quiet", 0, 0, 0}, /* clamscan + clamdscan */
67
{"stdout", 0, 0, 0}, /* clamscan + clamdscan */
68
{"verbose", 0, 0, 'v'}, /* clamscan + clamdscan */
70
{"version", 0, 0, 'V'}, /* clamscan + clamdscan */
72
{"leave-temps", 0, 0, 0},
73
{"config-file", 1, 0, 0}, /* clamdscan */
74
{"database", 1, 0, 'd'},
75
{"whole-file", 0, 0, 'w'}, /* not used */
77
{"recursive", 0, 0, 'r'},
79
{"disable-summary", 0, 0, 0}, /* obsolete */
80
{"no-summary", 0, 0, 0},
81
{"infected", 0, 0, 'i'},
83
{"log-verbose", 0, 0, 0}, /* not used */
84
{"threads", 1, 0, 0}, /* not used */
85
{"one-virus", 0, 0, 0}, /* not used */
89
{"exclude-dir", 1, 0, 0},
91
{"include-dir", 1, 0, 0},
92
{"max-files", 1, 0, 0},
93
{"max-space", 1, 0, 0},
94
{"max-ratio", 1, 0, 0},
95
{"max-recursion", 1, 0, 0},
96
{"max-dir-recursion", 1, 0, 0},
100
{"disable-archive", 0, 0, 0},
101
{"no-archive", 0, 0, 0},
102
{"detect-broken", 0, 0, 0},
103
{"block-encrypted", 0, 0, 0},
104
{"block-max", 0, 0, 0},
106
{"no-ole2", 0, 0, 0},
107
{"no-html", 0, 0, 0},
108
{"mbox", 0, 0, 'm'}, /* not used */
109
{"no-mail", 0, 0, 0},
110
{"mail-follow-urls", 0, 0, 0},
111
{"no-phishing", 0, 0, 0},
112
{"no-algorithmic", 0, 0, 0},
115
{"unace", 2, 0, 0}, /* not used */
116
{"unarj", 2, 0, 0}, /* not used */
118
{"zoo", 2, 0, 0}, /* not used */
126
/* developers only */
127
{"dev-ac-only", 0, 0, 0},
128
{"dev-ac-depth", 1, 0, 0},
134
opt=(struct optstruct*) mcalloc(1, sizeof(struct optstruct));
137
if(strstr(argv[0], "clamdscan"))
143
ret=getopt_long(argc, argv, getopt_parameters, long_options, &opt_index);
150
register_long_option(opt, long_options[opt_index].name);
154
if(strchr(getopt_parameters, ret)) {
156
register_char_option(opt, ret, long_options[opt_index].name);
158
register_char_option(opt, ret, NULL);
161
logg("!Unknown option passed.\n");
175
/* count length of non-option arguments */
177
for(i=optind; i<argc; i++)
178
len+=strlen(argv[i]);
180
len=len+argc-optind-1; /* add spaces between arguments */
181
opt->filename=(char*)mcalloc(len + 256, sizeof(char));
183
for(i=optind; i<argc; i++) {
184
strncat(opt->filename, argv[i], strlen(argv[i]));
186
strncat(opt->filename, "\t", 1);
197
void register_char_option(struct optstruct *opt, char ch, const char *longname)
199
struct optnode *newnode;
204
for(i = 0; clamdscan_short[i]; i++)
205
if(clamdscan_short[i] == ch)
210
logg("WARNING: Ignoring option -%c (--%s): please edit clamd.conf instead.\n", ch, longname);
212
logg("WARNING: Ignoring option -%c: please edit clamd.conf instead.\n", ch);
218
newnode = (struct optnode *) mmalloc(sizeof(struct optnode));
219
newnode->optchar = ch;
221
newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char));
222
strcpy(newnode->optarg, optarg);
223
} else newnode->optarg = NULL;
225
newnode->optname = NULL;
226
newnode->next = opt->optlist;
227
opt->optlist = newnode;
230
void register_long_option(struct optstruct *opt, const char *optname)
232
struct optnode *newnode;
237
for(i = 0; clamdscan_long[i]; i++)
238
if(!strcmp(clamdscan_long[i], optname))
242
logg("WARNING: Ignoring option --%s: please edit clamd.conf instead.\n", optname);
247
newnode = (struct optnode *) mmalloc(sizeof(struct optnode));
248
newnode->optchar = 0;
250
newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char));
251
strcpy(newnode->optarg, optarg);
252
} else newnode->optarg = NULL;
254
newnode->optname = (char *) mcalloc(strlen(optname) + 1, sizeof(char));
255
strcpy(newnode->optname, optname);
256
newnode->next = opt->optlist;
257
opt->optlist = newnode;
260
int optc(const struct optstruct *opt, char ch)
262
struct optnode *handler;
264
handler = opt->optlist;
268
if(handler->optchar == ch) return 1;
270
handler = handler->next;
276
int optl(const struct optstruct *opt, const char *optname)
278
struct optnode *handler;
280
handler = opt->optlist;
285
if(!strcmp(handler->optname, optname)) return 1;
287
handler = handler->next;
293
char *getargc(const struct optstruct *opt, char ch)
295
struct optnode *handler;
297
handler = opt->optlist;
301
if(handler->optchar == ch) return handler->optarg;
303
handler = handler->next;
309
char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode)
311
struct optnode *handler;
313
handler = opt->optlist;
317
if(handler->optchar == ch) {
319
return handler->optarg;
322
handler = handler->next;
328
char *getnextargc(struct optnode **optnode, char ch)
330
struct optnode *handler;
332
handler = (*optnode)->next;
336
if(handler->optchar == ch) {
338
return handler->optarg;
341
handler = handler->next;
347
char *getargl(const struct optstruct *opt, const char *optname)
349
struct optnode *handler;
351
handler = opt->optlist;
356
if(!strcmp(handler->optname, optname)) return handler->optarg;
358
handler = handler->next;
364
char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode)
366
struct optnode *handler;
368
handler = opt->optlist;
373
if(!strcmp(handler->optname, optname)) {
375
return handler->optarg;
378
handler = handler->next;
385
char *getnextargl(struct optnode **optnode, const char *optname)
387
struct optnode *handler;
389
handler = (*optnode)->next;
394
if(!strcmp(handler->optname, optname)) {
396
return handler->optarg;
399
handler = handler->next;
406
void free_opt(struct optstruct *opt)
408
struct optnode *handler, *prev;
413
handler = opt->optlist;
415
while(handler != NULL) {
416
handler->optchar = 0;
417
if(handler->optarg) free(handler->optarg);
418
if(handler->optname) free(handler->optname);
420
handler = handler->next;