git-svn: trunk@1977
Tomasz Kojm authored on 2006/05/16 03:30:18... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Mon May 15 20:23:30 CEST 2006 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * shared/options.[ch]: new command line parser module |
|
4 |
+ * clamd, clamdscan, clamscan, freshclam, sigtool: remove duplicate code and |
|
5 |
+ use new command line parser |
|
6 |
+ |
|
1 | 7 |
Sat May 13 18:14:57 CEST 2006 (tk) |
2 | 8 |
---------------------------------- |
3 | 9 |
* libclamav/vba_extract.c: decode_ole_object: return readable file descriptor |
... | ... |
@@ -206,11 +206,13 @@ int main(int argc, char **argv) |
206 | 206 |
case 'c': |
207 | 207 |
free(confdir); |
208 | 208 |
confdir = strdup(optarg); |
209 |
+ printf("LONG: %s, %c, idx: %d\n", long_options[opt_index].name, ret, opt_index); |
|
209 | 210 |
break; |
210 | 211 |
|
211 | 212 |
case 'h': |
212 | 213 |
help(); |
213 | 214 |
free(confdir); |
215 |
+ printf("LONG: %s, %c, idx: %d\n", long_options[opt_index].name, ret, opt_index); |
|
214 | 216 |
exit(0); |
215 | 217 |
|
216 | 218 |
default: |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
# |
2 |
-# Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+# Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
# |
4 | 4 |
# This program is free software; you can redistribute it and/or modify |
5 | 5 |
# it under the terms of the GNU General Public License as published by |
... | ... |
@@ -33,8 +33,8 @@ clamd_SOURCES = \ |
33 | 33 |
$(top_srcdir)/shared/misc.h \ |
34 | 34 |
$(top_srcdir)/shared/network.c \ |
35 | 35 |
$(top_srcdir)/shared/network.h \ |
36 |
- options.c \ |
|
37 |
- options.h \ |
|
36 |
+ $(top_srcdir)/shared/options.c \ |
|
37 |
+ $(top_srcdir)/shared/options.h \ |
|
38 | 38 |
clamd.c \ |
39 | 39 |
tcpserver.c \ |
40 | 40 |
tcpserver.h \ |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
@SET_MAKE@ |
16 | 16 |
|
17 | 17 |
# |
18 |
-# Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
18 |
+# Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
19 | 19 |
# |
20 | 20 |
# This program is free software; you can redistribute it and/or modify |
21 | 21 |
# it under the terms of the GNU General Public License as published by |
... | ... |
@@ -75,12 +75,13 @@ am__clamd_SOURCES_DIST = $(top_srcdir)/shared/output.c \ |
75 | 75 |
$(top_srcdir)/shared/getopt.h $(top_srcdir)/shared/memory.c \ |
76 | 76 |
$(top_srcdir)/shared/memory.h $(top_srcdir)/shared/misc.c \ |
77 | 77 |
$(top_srcdir)/shared/misc.h $(top_srcdir)/shared/network.c \ |
78 |
- $(top_srcdir)/shared/network.h options.c options.h clamd.c \ |
|
79 |
- tcpserver.c tcpserver.h localserver.c localserver.h session.c \ |
|
80 |
- session.h thrmgr.c thrmgr.h server-th.c server.h scanner.c \ |
|
81 |
- scanner.h others.c others.h clamuko.c clamuko.h \ |
|
82 |
- dazukoio_compat12.c dazukoio_compat12.h dazukoio.c dazukoio.h \ |
|
83 |
- dazuko_xp.h dazukoio_xp.h shared.h |
|
78 |
+ $(top_srcdir)/shared/network.h $(top_srcdir)/shared/options.c \ |
|
79 |
+ $(top_srcdir)/shared/options.h clamd.c tcpserver.c tcpserver.h \ |
|
80 |
+ localserver.c localserver.h session.c session.h thrmgr.c \ |
|
81 |
+ thrmgr.h server-th.c server.h scanner.c scanner.h others.c \ |
|
82 |
+ others.h clamuko.c clamuko.h dazukoio_compat12.c \ |
|
83 |
+ dazukoio_compat12.h dazukoio.c dazukoio.h dazuko_xp.h \ |
|
84 |
+ dazukoio_xp.h shared.h |
|
84 | 85 |
@BUILD_CLAMD_TRUE@am_clamd_OBJECTS = output.$(OBJEXT) \ |
85 | 86 |
@BUILD_CLAMD_TRUE@ cfgparser.$(OBJEXT) getopt.$(OBJEXT) \ |
86 | 87 |
@BUILD_CLAMD_TRUE@ memory.$(OBJEXT) misc.$(OBJEXT) \ |
... | ... |
@@ -231,8 +232,8 @@ target_vendor = @target_vendor@ |
231 | 231 |
@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/misc.h \ |
232 | 232 |
@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/network.c \ |
233 | 233 |
@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/network.h \ |
234 |
-@BUILD_CLAMD_TRUE@ options.c \ |
|
235 |
-@BUILD_CLAMD_TRUE@ options.h \ |
|
234 |
+@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/options.c \ |
|
235 |
+@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/options.h \ |
|
236 | 236 |
@BUILD_CLAMD_TRUE@ clamd.c \ |
237 | 237 |
@BUILD_CLAMD_TRUE@ tcpserver.c \ |
238 | 238 |
@BUILD_CLAMD_TRUE@ tcpserver.h \ |
... | ... |
@@ -454,6 +455,20 @@ network.obj: $(top_srcdir)/shared/network.c |
454 | 454 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
455 | 455 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o network.obj `if test -f '$(top_srcdir)/shared/network.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/network.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/network.c'; fi` |
456 | 456 |
|
457 |
+options.o: $(top_srcdir)/shared/options.c |
|
458 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c; \ |
|
459 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
460 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@ |
|
461 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
462 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c |
|
463 |
+ |
|
464 |
+options.obj: $(top_srcdir)/shared/options.c |
|
465 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`; \ |
|
466 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
467 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@ |
|
468 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
469 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi` |
|
470 |
+ |
|
457 | 471 |
mostlyclean-libtool: |
458 | 472 |
-rm -f *.lo |
459 | 473 |
|
... | ... |
@@ -63,7 +63,7 @@ short debug_mode = 0, logok = 0; |
63 | 63 |
|
64 | 64 |
short foreground = 0; |
65 | 65 |
|
66 |
-void clamd(struct optstruct *opt) |
|
66 |
+int main(int argc, char **argv) |
|
67 | 67 |
{ |
68 | 68 |
struct cfgstruct *copt, *cpt; |
69 | 69 |
struct passwd *user; |
... | ... |
@@ -76,19 +76,34 @@ void clamd(struct optstruct *opt) |
76 | 76 |
#ifdef C_LINUX |
77 | 77 |
struct stat sb; |
78 | 78 |
#endif |
79 |
+ struct optstruct *opt; |
|
80 |
+ const char *short_options = "hc:V"; |
|
81 |
+ |
|
82 |
+ static struct option long_options[] = { |
|
83 |
+ {"help", 0, 0, 'h'}, |
|
84 |
+ {"config-file", 1, 0, 'c'}, |
|
85 |
+ {"version", 0, 0, 'V'}, |
|
86 |
+ {"debug", 0, 0, 0}, |
|
87 |
+ {0, 0, 0, 0} |
|
88 |
+ }; |
|
89 |
+ |
|
90 |
+ |
|
91 |
+ opt = opt_parse(argc, argv, short_options, long_options, NULL); |
|
92 |
+ if(!opt) { |
|
93 |
+ mprintf("!Can't parse the command line\n"); |
|
94 |
+ return 1; |
|
95 |
+ } |
|
79 | 96 |
|
80 |
- /* initialize some important variables */ |
|
81 |
- |
|
82 |
- if(optc(opt, 'V')) { |
|
97 |
+ if(opt_check(opt, "version")) { |
|
83 | 98 |
print_version(); |
84 | 99 |
exit(0); |
85 | 100 |
} |
86 | 101 |
|
87 |
- if(optc(opt, 'h')) { |
|
102 |
+ if(opt_check(opt, "help")) { |
|
88 | 103 |
help(); |
89 | 104 |
} |
90 | 105 |
|
91 |
- if(optl(opt, "debug")) { |
|
106 |
+ if(opt_check(opt, "debug")) { |
|
92 | 107 |
#if defined(C_LINUX) |
93 | 108 |
/* njh@bandsman.co.uk: create a dump if needed */ |
94 | 109 |
struct rlimit rlim; |
... | ... |
@@ -102,8 +117,8 @@ void clamd(struct optstruct *opt) |
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
/* parse the config file */ |
105 |
- if(optc(opt, 'c')) |
|
106 |
- cfgfile = getargc(opt, 'c'); |
|
105 |
+ if(opt_check(opt, "config-file")) |
|
106 |
+ cfgfile = opt_arg(opt, "config-file"); |
|
107 | 107 |
else |
108 | 108 |
cfgfile = CONFDIR"/clamd.conf"; |
109 | 109 |
|
110 | 110 |
deleted file mode 100644 |
... | ... |
@@ -1,326 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2001-2002 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- * |
|
19 |
- * Sat Sep 14 22:18:20 CEST 2002: included getfirst*(), getnext*() functions |
|
20 |
- * from Alejandro Dubrovsky <s328940@student.uq.edu.au> |
|
21 |
- */ |
|
22 |
- |
|
23 |
-#if HAVE_CONFIG_H |
|
24 |
-#include "clamav-config.h" |
|
25 |
-#endif |
|
26 |
- |
|
27 |
-#include <stdio.h> |
|
28 |
-#include <stdlib.h> |
|
29 |
-#include <string.h> |
|
30 |
-#define _GNU_SOURCE |
|
31 |
-#include "getopt.h" |
|
32 |
- |
|
33 |
-#if defined(C_LINUX) && defined(CL_DEBUG) |
|
34 |
-#include <sys/resource.h> |
|
35 |
-#endif |
|
36 |
- |
|
37 |
-#include "options.h" |
|
38 |
-#include "others.h" |
|
39 |
-#include "../libclamav/others.h" |
|
40 |
-#include "memory.h" |
|
41 |
- |
|
42 |
-void clamd(struct optstruct *opt); |
|
43 |
- |
|
44 |
-int main(int argc, char **argv) |
|
45 |
-{ |
|
46 |
- int ret, opt_index, i, len; |
|
47 |
- struct optstruct *opt; |
|
48 |
- |
|
49 |
- const char *getopt_parameters = "hc:V"; |
|
50 |
- |
|
51 |
- static struct option long_options[] = { |
|
52 |
- {"help", 0, 0, 'h'}, |
|
53 |
- {"config-file", 1, 0, 'c'}, |
|
54 |
- {"version", 0, 0, 'V'}, |
|
55 |
- {"debug", 0, 0, 0}, |
|
56 |
- {0, 0, 0, 0} |
|
57 |
- }; |
|
58 |
- |
|
59 |
-#if defined(C_LINUX) && defined(CL_DEBUG) |
|
60 |
- /* njh@bandsman.co.uk: create a dump if needed */ |
|
61 |
- struct rlimit rlim; |
|
62 |
- |
|
63 |
- rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; |
|
64 |
- if(setrlimit(RLIMIT_CORE, &rlim) < 0) |
|
65 |
- perror("setrlimit"); |
|
66 |
-#endif |
|
67 |
- opt=(struct optstruct*)mcalloc(1, sizeof(struct optstruct)); |
|
68 |
- opt->optlist = NULL; |
|
69 |
- opt->filename = NULL; |
|
70 |
- |
|
71 |
- while(1) { |
|
72 |
- |
|
73 |
- opt_index=0; |
|
74 |
- ret=getopt_long(argc, argv, getopt_parameters, long_options, &opt_index); |
|
75 |
- |
|
76 |
- if (ret == -1) |
|
77 |
- break; |
|
78 |
- |
|
79 |
- switch (ret) { |
|
80 |
- case 0: |
|
81 |
- register_long_option(opt, long_options[opt_index].name); |
|
82 |
- break; |
|
83 |
- |
|
84 |
- default: |
|
85 |
- if(strchr(getopt_parameters, ret)) |
|
86 |
- register_char_option(opt, ret); |
|
87 |
- else { |
|
88 |
- fprintf(stderr, "ERROR: Unknown option passed.\n"); |
|
89 |
- free_opt(opt); |
|
90 |
- exit(40); |
|
91 |
- } |
|
92 |
- } |
|
93 |
- } |
|
94 |
- |
|
95 |
- if (optind < argc) { |
|
96 |
- |
|
97 |
- len=0; |
|
98 |
- |
|
99 |
- /* count length of non-option arguments */ |
|
100 |
- |
|
101 |
- for(i=optind; i<argc; i++) |
|
102 |
- len+=strlen(argv[i]); |
|
103 |
- |
|
104 |
- len=len+argc-optind-1; /* add spaces between arguments */ |
|
105 |
- opt->filename=(char*)mcalloc(len + 256, sizeof(char)); |
|
106 |
- |
|
107 |
- for(i=optind; i<argc; i++) { |
|
108 |
- strncat(opt->filename, argv[i], strlen(argv[i])); |
|
109 |
- if(i != argc-1) |
|
110 |
- strncat(opt->filename, " ", 1); |
|
111 |
- } |
|
112 |
- |
|
113 |
- } |
|
114 |
- |
|
115 |
- clamd(opt); |
|
116 |
- |
|
117 |
- free_opt(opt); |
|
118 |
- |
|
119 |
- mprintf("*exit main()"); |
|
120 |
- return(0); |
|
121 |
-} |
|
122 |
- |
|
123 |
-void register_char_option(struct optstruct *opt, char ch) |
|
124 |
-{ |
|
125 |
- struct optnode *newnode; |
|
126 |
- |
|
127 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
128 |
- newnode->optchar = ch; |
|
129 |
- if(optarg != NULL) { |
|
130 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
131 |
- strcpy(newnode->optarg, optarg); |
|
132 |
- } else newnode->optarg = NULL; |
|
133 |
- |
|
134 |
- newnode->optname = NULL; |
|
135 |
- newnode->next = opt->optlist; |
|
136 |
- opt->optlist = newnode; |
|
137 |
-} |
|
138 |
- |
|
139 |
-void register_long_option(struct optstruct *opt, const char *optname) |
|
140 |
-{ |
|
141 |
- struct optnode *newnode; |
|
142 |
- |
|
143 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
144 |
- newnode->optchar = 0; |
|
145 |
- if(optarg != NULL) { |
|
146 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
147 |
- strcpy(newnode->optarg, optarg); |
|
148 |
- } else newnode->optarg = NULL; |
|
149 |
- |
|
150 |
- newnode->optname = (char *) mcalloc(strlen(optname) + 1, sizeof(char)); |
|
151 |
- strcpy(newnode->optname, optname); |
|
152 |
- newnode->next = opt->optlist; |
|
153 |
- opt->optlist = newnode; |
|
154 |
-} |
|
155 |
- |
|
156 |
-int optc(const struct optstruct *opt, char ch) |
|
157 |
-{ |
|
158 |
- struct optnode *handler; |
|
159 |
- |
|
160 |
- handler = opt->optlist; |
|
161 |
- |
|
162 |
- while(1) { |
|
163 |
- if(handler) { |
|
164 |
- if(handler->optchar == ch) return 1; |
|
165 |
- } else break; |
|
166 |
- handler = handler->next; |
|
167 |
- } |
|
168 |
- |
|
169 |
- return(0); |
|
170 |
-} |
|
171 |
- |
|
172 |
-int optl(const struct optstruct *opt, const char *optname) |
|
173 |
-{ |
|
174 |
- struct optnode *handler; |
|
175 |
- |
|
176 |
- handler = opt->optlist; |
|
177 |
- |
|
178 |
- while(1) { |
|
179 |
- if(handler) { |
|
180 |
- if(handler->optname) |
|
181 |
- if(!strcmp(handler->optname, optname)) return 1; |
|
182 |
- } else break; |
|
183 |
- handler = handler->next; |
|
184 |
- } |
|
185 |
- |
|
186 |
- return(0); |
|
187 |
-} |
|
188 |
- |
|
189 |
-char *getargc(const struct optstruct *opt, char ch) |
|
190 |
-{ |
|
191 |
- struct optnode *handler; |
|
192 |
- |
|
193 |
- handler = opt->optlist; |
|
194 |
- |
|
195 |
- while(1) { |
|
196 |
- if(handler) { |
|
197 |
- if(handler->optchar == ch) return handler->optarg; |
|
198 |
- } else break; |
|
199 |
- handler = handler->next; |
|
200 |
- } |
|
201 |
- |
|
202 |
- return(NULL); |
|
203 |
-} |
|
204 |
- |
|
205 |
-char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode) |
|
206 |
-{ |
|
207 |
- struct optnode *handler; |
|
208 |
- |
|
209 |
- handler = opt->optlist; |
|
210 |
- |
|
211 |
- while(1) { |
|
212 |
- if(handler) { |
|
213 |
- if(handler->optchar == ch) { |
|
214 |
- *optnode = handler; |
|
215 |
- return handler->optarg; |
|
216 |
- } |
|
217 |
- } else break; |
|
218 |
- handler = handler->next; |
|
219 |
- } |
|
220 |
- *optnode = NULL; |
|
221 |
- return(NULL); |
|
222 |
-} |
|
223 |
- |
|
224 |
-char *getnextargc(struct optnode **optnode, char ch) |
|
225 |
-{ |
|
226 |
- struct optnode *handler; |
|
227 |
- |
|
228 |
- handler = (*optnode)->next; |
|
229 |
- |
|
230 |
- while(1) { |
|
231 |
- if(handler) { |
|
232 |
- if(handler->optchar == ch) { |
|
233 |
- *optnode = handler; |
|
234 |
- return handler->optarg; |
|
235 |
- } |
|
236 |
- } else break; |
|
237 |
- handler = handler->next; |
|
238 |
- } |
|
239 |
- *optnode = NULL; |
|
240 |
- return(NULL); |
|
241 |
-} |
|
242 |
- |
|
243 |
- |
|
244 |
-char *getargl(const struct optstruct *opt, const char *optname) |
|
245 |
-{ |
|
246 |
- struct optnode *handler; |
|
247 |
- |
|
248 |
- handler = opt->optlist; |
|
249 |
- |
|
250 |
- while(1) { |
|
251 |
- if(handler) { |
|
252 |
- if(handler->optname) |
|
253 |
- if(!strcmp(handler->optname, optname)) return handler->optarg; |
|
254 |
- } else break; |
|
255 |
- handler = handler->next; |
|
256 |
- } |
|
257 |
- |
|
258 |
- return(NULL); |
|
259 |
-} |
|
260 |
- |
|
261 |
-char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode) |
|
262 |
-{ |
|
263 |
- struct optnode *handler; |
|
264 |
- |
|
265 |
- handler = opt->optlist; |
|
266 |
- |
|
267 |
- while(1) { |
|
268 |
- if(handler) { |
|
269 |
- if(handler->optname) |
|
270 |
- if(!strcmp(handler->optname, optname)) { |
|
271 |
- *optnode = handler; |
|
272 |
- return handler->optarg; |
|
273 |
- } |
|
274 |
- } else break; |
|
275 |
- handler = handler->next; |
|
276 |
- } |
|
277 |
- |
|
278 |
- *optnode = NULL; |
|
279 |
- return(NULL); |
|
280 |
-} |
|
281 |
- |
|
282 |
-char *getnextargl(struct optnode **optnode, const char *optname) |
|
283 |
-{ |
|
284 |
- struct optnode *handler; |
|
285 |
- |
|
286 |
- handler = (*optnode)->next; |
|
287 |
- |
|
288 |
- while(1) { |
|
289 |
- if(handler) { |
|
290 |
- if(handler->optname) |
|
291 |
- if(!strcmp(handler->optname, optname)) { |
|
292 |
- *optnode = handler; |
|
293 |
- return handler->optarg; |
|
294 |
- } |
|
295 |
- } else break; |
|
296 |
- handler = handler->next; |
|
297 |
- } |
|
298 |
- |
|
299 |
- *optnode = NULL; |
|
300 |
- return(NULL); |
|
301 |
-} |
|
302 |
- |
|
303 |
- |
|
304 |
- |
|
305 |
-void free_opt(struct optstruct *opt) |
|
306 |
-{ |
|
307 |
- struct optnode *handler, *prev; |
|
308 |
- |
|
309 |
- if(!opt) |
|
310 |
- return; |
|
311 |
- |
|
312 |
- handler = opt->optlist; |
|
313 |
- |
|
314 |
- while(handler != NULL) { |
|
315 |
- handler->optchar = 0; |
|
316 |
- if(handler->optarg) free(handler->optarg); |
|
317 |
- if(handler->optname) free(handler->optname); |
|
318 |
- prev = handler; |
|
319 |
- handler = handler->next; |
|
320 |
- free(prev); |
|
321 |
- } |
|
322 |
- |
|
323 |
- if(opt->filename) |
|
324 |
- free(opt->filename); |
|
325 |
- free(opt); |
|
326 |
-} |
327 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,47 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#ifndef __OPTIONS_H |
|
21 |
-#define __OPTIONS_H |
|
22 |
- |
|
23 |
-struct optnode { |
|
24 |
- char optchar; |
|
25 |
- char *optarg; |
|
26 |
- char *optname; |
|
27 |
- struct optnode *next; |
|
28 |
-}; |
|
29 |
- |
|
30 |
-struct optstruct { |
|
31 |
- struct optnode *optlist; |
|
32 |
- char *filename; |
|
33 |
-}; |
|
34 |
- |
|
35 |
-int optc(const struct optstruct *opt, char ch); |
|
36 |
-int optl(const struct optstruct *opt, const char *optname); |
|
37 |
-void register_char_option(struct optstruct *opt, char ch); |
|
38 |
-void register_long_option(struct optstruct *opt, const char *optname); |
|
39 |
-char *getargc(const struct optstruct *opt, char ch); |
|
40 |
-char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode); |
|
41 |
-char *getnextargc(struct optnode **optnode, char ch); |
|
42 |
-char *getargl(const struct optstruct *opt, const char *optname); |
|
43 |
-char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode); |
|
44 |
-char *getnextargl(struct optnode **optnode, const char *optname); |
|
45 |
-void free_opt(struct optstruct *opt); |
|
46 |
- |
|
47 |
-#endif |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
# |
2 |
-# Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+# Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
# |
4 | 4 |
# This program is free software; you can redistribute it and/or modify |
5 | 5 |
# it under the terms of the GNU General Public License as published by |
... | ... |
@@ -29,13 +29,15 @@ clamdscan_SOURCES = \ |
29 | 29 |
$(top_srcdir)/shared/memory.h \ |
30 | 30 |
$(top_srcdir)/shared/misc.c \ |
31 | 31 |
$(top_srcdir)/shared/misc.h \ |
32 |
+ $(top_srcdir)/shared/getopt.c \ |
|
33 |
+ $(top_srcdir)/shared/getopt.h \ |
|
34 |
+ $(top_srcdir)/shared/options.c \ |
|
35 |
+ $(top_srcdir)/shared/options.h \ |
|
32 | 36 |
clamdscan.c \ |
33 | 37 |
client.c \ |
34 | 38 |
client.h \ |
35 | 39 |
defaults.h |
36 | 40 |
|
37 |
-clamdscan_LDADD = $(top_builddir)/clamscan/options.o $(top_builddir)/clamscan/getopt.o |
|
38 |
- |
|
39 | 41 |
endif |
40 | 42 |
|
41 | 43 |
DEFS = @DEFS@ -DCL_NOTHREADS |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
@SET_MAKE@ |
16 | 16 |
|
17 | 17 |
# |
18 |
-# Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net> |
|
18 |
+# Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
19 | 19 |
# |
20 | 20 |
# This program is free software; you can redistribute it and/or modify |
21 | 21 |
# it under the terms of the GNU General Public License as published by |
... | ... |
@@ -73,16 +73,17 @@ am__clamdscan_SOURCES_DIST = $(top_srcdir)/shared/output.c \ |
73 | 73 |
$(top_srcdir)/shared/output.h $(top_srcdir)/shared/cfgparser.c \ |
74 | 74 |
$(top_srcdir)/shared/cfgparser.h $(top_srcdir)/shared/memory.c \ |
75 | 75 |
$(top_srcdir)/shared/memory.h $(top_srcdir)/shared/misc.c \ |
76 |
- $(top_srcdir)/shared/misc.h clamdscan.c client.c client.h \ |
|
76 |
+ $(top_srcdir)/shared/misc.h $(top_srcdir)/shared/getopt.c \ |
|
77 |
+ $(top_srcdir)/shared/getopt.h $(top_srcdir)/shared/options.c \ |
|
78 |
+ $(top_srcdir)/shared/options.h clamdscan.c client.c client.h \ |
|
77 | 79 |
defaults.h |
78 | 80 |
@BUILD_CLAMD_TRUE@am_clamdscan_OBJECTS = output.$(OBJEXT) \ |
79 | 81 |
@BUILD_CLAMD_TRUE@ cfgparser.$(OBJEXT) memory.$(OBJEXT) \ |
80 |
-@BUILD_CLAMD_TRUE@ misc.$(OBJEXT) clamdscan.$(OBJEXT) \ |
|
82 |
+@BUILD_CLAMD_TRUE@ misc.$(OBJEXT) getopt.$(OBJEXT) \ |
|
83 |
+@BUILD_CLAMD_TRUE@ options.$(OBJEXT) clamdscan.$(OBJEXT) \ |
|
81 | 84 |
@BUILD_CLAMD_TRUE@ client.$(OBJEXT) |
82 | 85 |
clamdscan_OBJECTS = $(am_clamdscan_OBJECTS) |
83 |
-@BUILD_CLAMD_TRUE@clamdscan_DEPENDENCIES = \ |
|
84 |
-@BUILD_CLAMD_TRUE@ $(top_builddir)/clamscan/options.o \ |
|
85 |
-@BUILD_CLAMD_TRUE@ $(top_builddir)/clamscan/getopt.o |
|
86 |
+clamdscan_LDADD = $(LDADD) |
|
86 | 87 |
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) |
87 | 88 |
depcomp = $(SHELL) $(top_srcdir)/depcomp |
88 | 89 |
am__depfiles_maybe = depfiles |
... | ... |
@@ -216,12 +217,15 @@ target_vendor = @target_vendor@ |
216 | 216 |
@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/memory.h \ |
217 | 217 |
@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/misc.c \ |
218 | 218 |
@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/misc.h \ |
219 |
+@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/getopt.c \ |
|
220 |
+@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/getopt.h \ |
|
221 |
+@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/options.c \ |
|
222 |
+@BUILD_CLAMD_TRUE@ $(top_srcdir)/shared/options.h \ |
|
219 | 223 |
@BUILD_CLAMD_TRUE@ clamdscan.c \ |
220 | 224 |
@BUILD_CLAMD_TRUE@ client.c \ |
221 | 225 |
@BUILD_CLAMD_TRUE@ client.h \ |
222 | 226 |
@BUILD_CLAMD_TRUE@ defaults.h |
223 | 227 |
|
224 |
-@BUILD_CLAMD_TRUE@clamdscan_LDADD = $(top_builddir)/clamscan/options.o $(top_builddir)/clamscan/getopt.o |
|
225 | 228 |
INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav |
226 | 229 |
all: all-am |
227 | 230 |
|
... | ... |
@@ -297,8 +301,10 @@ distclean-compile: |
297 | 297 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@ |
298 | 298 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamdscan.Po@am__quote@ |
299 | 299 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client.Po@am__quote@ |
300 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ |
|
300 | 301 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@ |
301 | 302 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@ |
303 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@ |
|
302 | 304 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@ |
303 | 305 |
|
304 | 306 |
.c.o: |
... | ... |
@@ -378,6 +384,34 @@ misc.obj: $(top_srcdir)/shared/misc.c |
378 | 378 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
379 | 379 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi` |
380 | 380 |
|
381 |
+getopt.o: $(top_srcdir)/shared/getopt.c |
|
382 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT getopt.o -MD -MP -MF "$(DEPDIR)/getopt.Tpo" -c -o getopt.o `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c; \ |
|
383 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/getopt.Tpo" "$(DEPDIR)/getopt.Po"; else rm -f "$(DEPDIR)/getopt.Tpo"; exit 1; fi |
|
384 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@ |
|
385 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
386 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.o `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c |
|
387 |
+ |
|
388 |
+getopt.obj: $(top_srcdir)/shared/getopt.c |
|
389 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT getopt.obj -MD -MP -MF "$(DEPDIR)/getopt.Tpo" -c -o getopt.obj `if test -f '$(top_srcdir)/shared/getopt.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/getopt.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/getopt.c'; fi`; \ |
|
390 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/getopt.Tpo" "$(DEPDIR)/getopt.Po"; else rm -f "$(DEPDIR)/getopt.Tpo"; exit 1; fi |
|
391 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@ |
|
392 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
393 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.obj `if test -f '$(top_srcdir)/shared/getopt.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/getopt.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/getopt.c'; fi` |
|
394 |
+ |
|
395 |
+options.o: $(top_srcdir)/shared/options.c |
|
396 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c; \ |
|
397 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
398 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@ |
|
399 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
400 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c |
|
401 |
+ |
|
402 |
+options.obj: $(top_srcdir)/shared/options.c |
|
403 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`; \ |
|
404 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
405 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@ |
|
406 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
407 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi` |
|
408 |
+ |
|
381 | 409 |
mostlyclean-libtool: |
382 | 410 |
-rm -f *.lo |
383 | 411 |
|
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -37,53 +37,65 @@ |
37 | 37 |
#include "output.h" |
38 | 38 |
#include "misc.h" |
39 | 39 |
|
40 |
+#include "clamscan_opt.h" |
|
41 |
+ |
|
40 | 42 |
void help(void); |
41 | 43 |
|
42 | 44 |
short printinfected = 0; |
43 | 45 |
|
44 | 46 |
extern int notremoved, notmoved; |
45 | 47 |
|
46 |
- |
|
47 |
-void clamscan(struct optstruct *opt) |
|
48 |
+int main(int argc, char **argv) |
|
48 | 49 |
{ |
49 | 50 |
int ds, dms, ret, infected; |
50 | 51 |
struct timeval t1, t2; |
51 | 52 |
struct timezone tz; |
52 | 53 |
time_t starttime; |
54 |
+ struct optstruct *opt; |
|
55 |
+ char *clamdscan_accepted[] = { "help", "version", "verbose", "quiet", |
|
56 |
+ "stdout", "log", "move", "remove", |
|
57 |
+ "config-file", "no-summary", |
|
58 |
+ "disable-summary", NULL }; |
|
53 | 59 |
|
54 | 60 |
|
55 |
- /* initialize some important variables */ |
|
61 |
+ opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, clamdscan_accepted); |
|
62 |
+ if(!opt) { |
|
63 |
+ mprintf("!Can't parse the command line\n"); |
|
64 |
+ return 2; |
|
65 |
+ } |
|
56 | 66 |
|
57 |
- if(optc(opt, 'v')) { |
|
67 |
+ if(opt_check(opt, "verbose")) { |
|
58 | 68 |
mprintf_verbose = 1; |
59 | 69 |
logg_verbose = 1; |
60 | 70 |
} |
61 | 71 |
|
62 |
- if(optl(opt, "quiet")) |
|
72 |
+ if(opt_check(opt, "quiet")) |
|
63 | 73 |
mprintf_quiet = 1; |
64 | 74 |
|
65 |
- if(optl(opt, "stdout")) |
|
75 |
+ if(opt_check(opt, "stdout")) |
|
66 | 76 |
mprintf_stdout = 1; |
67 | 77 |
|
68 |
- if(optc(opt, 'V')) { |
|
78 |
+ if(opt_check(opt, "version")) { |
|
69 | 79 |
print_version(); |
80 |
+ opt_free(opt); |
|
70 | 81 |
exit(0); |
71 | 82 |
} |
72 | 83 |
|
73 |
- if(optc(opt, 'h')) { |
|
74 |
- free_opt(opt); |
|
84 |
+ if(opt_check(opt, "help")) { |
|
85 |
+ opt_free(opt); |
|
75 | 86 |
help(); |
76 | 87 |
} |
77 | 88 |
|
78 |
- if(optc(opt, 'i')) |
|
89 |
+ if(opt_check(opt, "infected")) |
|
79 | 90 |
printinfected = 1; |
80 | 91 |
|
81 | 92 |
/* initialize logger */ |
82 | 93 |
|
83 |
- if(optc(opt, 'l')) { |
|
84 |
- logg_file = getargc(opt, 'l'); |
|
94 |
+ if(opt_check(opt, "log")) { |
|
95 |
+ logg_file = opt_arg(opt, "log"); |
|
85 | 96 |
if(logg("--------------------------------------\n")) { |
86 | 97 |
mprintf("!Problem with internal logger.\n"); |
98 |
+ opt_free(opt); |
|
87 | 99 |
exit(2); |
88 | 100 |
} |
89 | 101 |
} else |
... | ... |
@@ -97,8 +109,8 @@ void clamscan(struct optstruct *opt) |
97 | 97 |
|
98 | 98 |
ret = client(opt, &infected); |
99 | 99 |
|
100 |
-/* Implement STATUS in clamd */ |
|
101 |
- if(!optl(opt, "disable-summary") && !optl(opt, "no-summary")) { |
|
100 |
+ /* TODO: Implement STATUS in clamd */ |
|
101 |
+ if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) { |
|
102 | 102 |
gettimeofday(&t2, &tz); |
103 | 103 |
ds = t2.tv_sec - t1.tv_sec; |
104 | 104 |
dms = t2.tv_usec - t1.tv_usec; |
... | ... |
@@ -115,6 +127,7 @@ void clamscan(struct optstruct *opt) |
115 | 115 |
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60); |
116 | 116 |
} |
117 | 117 |
|
118 |
+ opt_free(opt); |
|
118 | 119 |
exit(ret); |
119 | 120 |
} |
120 | 121 |
|
... | ... |
@@ -137,6 +150,7 @@ void help(void) |
137 | 137 |
mprintf(" --remove Remove infected files. Be careful!\n"); |
138 | 138 |
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n"); |
139 | 139 |
mprintf(" --config-file=FILE Read configuration from FILE.\n"); |
140 |
+ mprintf(" --infected -i Only print infected files\n"); |
|
140 | 141 |
mprintf(" --no-summary Disable summary at end of scanning\n"); |
141 | 142 |
mprintf("\n"); |
142 | 143 |
|
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -80,7 +80,7 @@ static int dsresult(int sockd, const struct optstruct *opt) |
80 | 80 |
if(strstr(buff, "FOUND\n")) { |
81 | 81 |
infected++; |
82 | 82 |
logg("%s", buff); |
83 |
- if(optl(opt, "move")) { |
|
83 |
+ if(opt_check(opt, "move")) { |
|
84 | 84 |
/* filename: Virus FOUND */ |
85 | 85 |
if((pt = strrchr(buff, ':'))) { |
86 | 86 |
*pt = 0; |
... | ... |
@@ -89,7 +89,7 @@ static int dsresult(int sockd, const struct optstruct *opt) |
89 | 89 |
mprintf("@Broken data format. File not moved.\n"); |
90 | 90 |
} |
91 | 91 |
|
92 |
- } else if(optl(opt, "remove")) { |
|
92 |
+ } else if(opt_check(opt, "remove")) { |
|
93 | 93 |
if(!(pt = strrchr(buff, ':'))) { |
94 | 94 |
mprintf("@Broken data format. File not removed.\n"); |
95 | 95 |
} else { |
... | ... |
@@ -316,7 +316,7 @@ static int dconnect(const struct optstruct *opt) |
316 | 316 |
struct sockaddr_in server2; |
317 | 317 |
struct hostent *he; |
318 | 318 |
struct cfgstruct *copt, *cpt; |
319 |
- const char *clamav_conf = getargl(opt, "config-file"); |
|
319 |
+ const char *clamav_conf = opt_arg(opt, "config-file"); |
|
320 | 320 |
int sockd; |
321 | 321 |
|
322 | 322 |
|
... | ... |
@@ -496,9 +496,9 @@ void move_infected(const char *filename, const struct optstruct *opt) |
496 | 496 |
struct utimbuf ubuf; |
497 | 497 |
|
498 | 498 |
|
499 |
- if(!(movedir = getargl(opt, "move"))) { |
|
499 |
+ if(!(movedir = opt_arg(opt, "move"))) { |
|
500 | 500 |
/* Should never reach here */ |
501 |
- logg("^getargc() returned NULL\n"); |
|
501 |
+ logg("^opt_arg() returned NULL\n"); |
|
502 | 502 |
notmoved++; |
503 | 503 |
return; |
504 | 504 |
} |
... | ... |
@@ -30,9 +30,10 @@ clamscan_SOURCES = \ |
30 | 30 |
$(top_srcdir)/shared/cfgparser.h \ |
31 | 31 |
$(top_srcdir)/shared/misc.c \ |
32 | 32 |
$(top_srcdir)/shared/misc.h \ |
33 |
+ $(top_srcdir)/shared/options.c \ |
|
34 |
+ $(top_srcdir)/shared/options.h \ |
|
33 | 35 |
clamscan.c \ |
34 |
- options.c \ |
|
35 |
- options.h \ |
|
36 |
+ clamscan_opt.h \ |
|
36 | 37 |
others.c \ |
37 | 38 |
others.h \ |
38 | 39 |
shared.h \ |
... | ... |
@@ -72,7 +72,7 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) |
72 | 72 |
PROGRAMS = $(bin_PROGRAMS) |
73 | 73 |
am_clamscan_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) \ |
74 | 74 |
memory.$(OBJEXT) cfgparser.$(OBJEXT) misc.$(OBJEXT) \ |
75 |
- clamscan.$(OBJEXT) options.$(OBJEXT) others.$(OBJEXT) \ |
|
75 |
+ options.$(OBJEXT) clamscan.$(OBJEXT) others.$(OBJEXT) \ |
|
76 | 76 |
manager.$(OBJEXT) treewalk.$(OBJEXT) |
77 | 77 |
clamscan_OBJECTS = $(am_clamscan_OBJECTS) |
78 | 78 |
clamscan_LDADD = $(LDADD) |
... | ... |
@@ -211,9 +211,10 @@ clamscan_SOURCES = \ |
211 | 211 |
$(top_srcdir)/shared/cfgparser.h \ |
212 | 212 |
$(top_srcdir)/shared/misc.c \ |
213 | 213 |
$(top_srcdir)/shared/misc.h \ |
214 |
+ $(top_srcdir)/shared/options.c \ |
|
215 |
+ $(top_srcdir)/shared/options.h \ |
|
214 | 216 |
clamscan.c \ |
215 |
- options.c \ |
|
216 |
- options.h \ |
|
217 |
+ clamscan_opt.h \ |
|
217 | 218 |
others.c \ |
218 | 219 |
others.h \ |
219 | 220 |
shared.h \ |
... | ... |
@@ -397,6 +398,20 @@ misc.obj: $(top_srcdir)/shared/misc.c |
397 | 397 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
398 | 398 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi` |
399 | 399 |
|
400 |
+options.o: $(top_srcdir)/shared/options.c |
|
401 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c; \ |
|
402 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
403 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@ |
|
404 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
405 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c |
|
406 |
+ |
|
407 |
+options.obj: $(top_srcdir)/shared/options.c |
|
408 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`; \ |
|
409 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
410 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@ |
|
411 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
412 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi` |
|
413 |
+ |
|
400 | 414 |
mostlyclean-libtool: |
401 | 415 |
-rm -f *.lo |
402 | 416 |
|
... | ... |
@@ -28,7 +28,7 @@ |
28 | 28 |
#include <sys/time.h> |
29 | 29 |
#include <time.h> |
30 | 30 |
|
31 |
-#include "options.h" |
|
31 |
+#include "clamscan_opt.h" |
|
32 | 32 |
#include "others.h" |
33 | 33 |
#include "shared.h" |
34 | 34 |
#include "manager.h" |
... | ... |
@@ -37,6 +37,7 @@ |
37 | 37 |
#include "misc.h" |
38 | 38 |
|
39 | 39 |
#include "output.h" |
40 |
+#include "options.h" |
|
40 | 41 |
|
41 | 42 |
#ifdef C_LINUX |
42 | 43 |
#include <sys/resource.h> |
... | ... |
@@ -47,27 +48,35 @@ void help(void); |
47 | 47 |
struct s_info claminfo; |
48 | 48 |
short recursion = 0, printinfected = 0, bell = 0; |
49 | 49 |
|
50 |
-int clamscan(struct optstruct *opt) |
|
50 |
+int main(int argc, char **argv) |
|
51 | 51 |
{ |
52 | 52 |
int ds, dms, ret; |
53 | 53 |
double mb; |
54 | 54 |
struct timeval t1, t2; |
55 | 55 |
struct timezone tz; |
56 |
+ struct optstruct *opt; |
|
57 |
+ const char *pt; |
|
56 | 58 |
|
57 |
- /* initialize some important variables */ |
|
58 | 59 |
|
59 |
- if(optc(opt, 'v')) { |
|
60 |
+ opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL); |
|
61 |
+ if(!opt) { |
|
62 |
+ mprintf("!Can't parse the command line\n"); |
|
63 |
+ return 40; |
|
64 |
+ } |
|
65 |
+ |
|
66 |
+ if(opt_check(opt, "verbose")) { |
|
60 | 67 |
mprintf_verbose = 1; |
61 | 68 |
logg_verbose = 1; |
62 | 69 |
} |
63 | 70 |
|
64 |
- if(optl(opt, "quiet")) |
|
71 |
+ if(opt_check(opt, "quiet")) |
|
65 | 72 |
mprintf_quiet = 1; |
66 | 73 |
|
67 |
- if(optl(opt, "stdout")) |
|
74 |
+ if(opt_check(opt, "stdout")) |
|
68 | 75 |
mprintf_stdout = 1; |
69 | 76 |
|
70 |
- if(optl(opt, "debug")) { |
|
77 |
+ |
|
78 |
+ if(opt_check(opt, "debug")) { |
|
71 | 79 |
#if defined(C_LINUX) |
72 | 80 |
/* njh@bandsman.co.uk: create a dump if needed */ |
73 | 81 |
struct rlimit rlim; |
... | ... |
@@ -79,82 +88,96 @@ int clamscan(struct optstruct *opt) |
79 | 79 |
cl_debug(); /* enable debug messages */ |
80 | 80 |
} |
81 | 81 |
|
82 |
- if(optc(opt, 'V')) { |
|
82 |
+ if(opt_check(opt, "version")) { |
|
83 |
+ opt_free(opt); |
|
83 | 84 |
print_version(); |
84 | 85 |
return 0; |
85 | 86 |
} |
86 | 87 |
|
87 |
- if(optc(opt, 'h')) { |
|
88 |
- free_opt(opt); |
|
88 |
+ if(opt_check(opt, "help")) { |
|
89 |
+ opt_free(opt); |
|
89 | 90 |
help(); |
91 |
+ return 0; |
|
90 | 92 |
} |
91 | 93 |
|
92 |
- /* check other options */ |
|
93 |
- |
|
94 |
- if(optc(opt, 'r')) |
|
94 |
+ if(opt_check(opt, "recursive")) |
|
95 | 95 |
recursion = 1; |
96 | 96 |
|
97 |
- if(optc(opt, 'i')) |
|
97 |
+ if(opt_check(opt, "infected")) |
|
98 | 98 |
printinfected = 1; |
99 | 99 |
|
100 |
- if(optl(opt, "bell")) |
|
100 |
+ if(opt_check(opt, "bell")) |
|
101 | 101 |
bell = 1; |
102 | 102 |
|
103 |
- if(optl(opt, "tempdir")) |
|
104 |
- cl_settempdir(getargl(opt, "tempdir"), 0); |
|
103 |
+ if(opt_check(opt, "tempdir")) |
|
104 |
+ cl_settempdir(opt_arg(opt, "tempdir"), 0); |
|
105 | 105 |
|
106 |
- if(optl(opt, "leave-temps")) |
|
106 |
+ if(opt_check(opt, "leave-temps")) |
|
107 | 107 |
cl_settempdir(NULL, 1); |
108 | 108 |
|
109 | 109 |
/* initialize logger */ |
110 |
- |
|
111 |
- if(optc(opt, 'l')) { |
|
112 |
- logg_file = getargc(opt, 'l'); |
|
110 |
+ if(opt_check(opt, "logger")) { |
|
111 |
+ logg_file = opt_arg(opt, "logger"); |
|
113 | 112 |
if(logg("#\n-------------------------------------------------------------------------------\n\n")) { |
114 | 113 |
mprintf("!Problem with internal logger.\n"); |
114 |
+ opt_free(opt); |
|
115 | 115 |
return 62; |
116 | 116 |
} |
117 | 117 |
} else |
118 | 118 |
logg_file = NULL; |
119 | 119 |
|
120 |
- /* we need some pre-checks */ |
|
121 |
- if(optl(opt, "max-space")) |
|
122 |
- if(!strchr(getargl(opt, "max-space"), 'M') && !strchr(getargl(opt, "max-space"), 'm')) |
|
123 |
- if(!isnumb(getargl(opt, "max-space"))) { |
|
124 |
- logg("!--max-space requires natural number.\n"); |
|
120 |
+ |
|
121 |
+ /* validate some numerical options */ |
|
122 |
+ |
|
123 |
+ if(opt_check(opt, "max-space")) { |
|
124 |
+ pt = opt_arg(opt, "max-space"); |
|
125 |
+ if(!strchr(pt, 'M') && !strchr(pt, 'm')) { |
|
126 |
+ if(!isnumb(pt)) { |
|
127 |
+ logg("!--max-space requires a natural number\n"); |
|
128 |
+ opt_free(opt); |
|
125 | 129 |
return 40; |
126 | 130 |
} |
131 |
+ } |
|
132 |
+ } |
|
127 | 133 |
|
128 |
- if(optl(opt, "max-files")) |
|
129 |
- if(!isnumb(getargl(opt, "max-files"))) { |
|
130 |
- logg("!--max-files requires natural number.\n"); |
|
134 |
+ if(opt_check(opt, "max-files")) { |
|
135 |
+ if(!isnumb(opt_arg(opt, "max-files"))) { |
|
136 |
+ logg("!--max-files requires a natural number\n"); |
|
137 |
+ opt_free(opt); |
|
131 | 138 |
return 40; |
132 | 139 |
} |
140 |
+ } |
|
133 | 141 |
|
134 |
- if(optl(opt, "max-recursion")) |
|
135 |
- if(!isnumb(getargl(opt, "max-recursion"))) { |
|
136 |
- logg("!--max-recursion requires natural number.\n"); |
|
142 |
+ if(opt_check(opt, "max-recursion")) { |
|
143 |
+ if(!isnumb(opt_arg(opt, "max-recursion"))) { |
|
144 |
+ logg("!--max-recursion requires a natural number\n"); |
|
145 |
+ opt_free(opt); |
|
137 | 146 |
return 40; |
138 | 147 |
} |
148 |
+ } |
|
139 | 149 |
|
140 |
- if(optl(opt, "max-dir-recursion")) |
|
141 |
- if(!isnumb(getargl(opt, "max-dir-recursion"))) { |
|
142 |
- logg("!--max-dir-recursion requires natural number.\n"); |
|
150 |
+ if(opt_check(opt, "max-dir-recursion")) { |
|
151 |
+ if(!isnumb(opt_arg(opt, "max-dir-recursion"))) { |
|
152 |
+ logg("!--max-dir-recursion requires a natural number\n"); |
|
153 |
+ opt_free(opt); |
|
143 | 154 |
return 40; |
144 | 155 |
} |
156 |
+ } |
|
145 | 157 |
|
146 |
- if(optl(opt, "max-ratio")) |
|
147 |
- if(!isnumb(getargl(opt, "max-ratio"))) { |
|
148 |
- logg("!--max-ratio requires natural number.\n"); |
|
158 |
+ if(opt_check(opt, "max-ratio")) { |
|
159 |
+ if(!isnumb(opt_arg(opt, "max-ratio"))) { |
|
160 |
+ logg("!--max-ratio requires a natural number\n"); |
|
161 |
+ opt_free(opt); |
|
149 | 162 |
return 40; |
150 | 163 |
} |
164 |
+ } |
|
151 | 165 |
|
152 | 166 |
memset(&claminfo, 0, sizeof(struct s_info)); |
153 | 167 |
|
154 | 168 |
gettimeofday(&t1, &tz); |
155 | 169 |
ret = scanmanager(opt); |
156 | 170 |
|
157 |
- if(!optl(opt, "disable-summary") && !optl(opt, "no-summary")) { |
|
171 |
+ if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) { |
|
158 | 172 |
gettimeofday(&t2, &tz); |
159 | 173 |
ds = t2.tv_sec - t1.tv_sec; |
160 | 174 |
dms = t2.tv_usec - t1.tv_usec; |
... | ... |
@@ -162,7 +185,7 @@ int clamscan(struct optstruct *opt) |
162 | 162 |
dms += (dms < 0) ? (1000000):(0); |
163 | 163 |
logg("\n----------- SCAN SUMMARY -----------\n"); |
164 | 164 |
logg("Known viruses: %d\n", claminfo.signs); |
165 |
- if(optl(opt, "hwaccel")) |
|
165 |
+ if(opt_check(opt, "hwaccel")) |
|
166 | 166 |
logg("Engine version: %s [hwaccel]\n", cl_retver()); |
167 | 167 |
else |
168 | 168 |
logg("Engine version: %s\n", cl_retver()); |
... | ... |
@@ -177,14 +200,10 @@ int clamscan(struct optstruct *opt) |
177 | 177 |
} |
178 | 178 |
mb = claminfo.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0; |
179 | 179 |
logg("Data scanned: %2.2lf MB\n", mb); |
180 |
-/* |
|
181 |
- mprintf("I/O buffer size: %d bytes\n", SCANBUFF); |
|
182 |
- logg("I/O buffer size: %d bytes\n", SCANBUFF); |
|
183 |
-*/ |
|
184 |
- |
|
185 | 180 |
logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60); |
186 | 181 |
} |
187 | 182 |
|
183 |
+ opt_free(opt); |
|
188 | 184 |
return ret; |
189 | 185 |
} |
190 | 186 |
|
... | ... |
@@ -262,6 +281,4 @@ void help(void) |
262 | 262 |
mprintf(" --tar[=FULLPATH] Enable support for .tar files\n"); |
263 | 263 |
mprintf(" --deb[=FULLPATH to ar] Enable support for .deb files\n"); |
264 | 264 |
mprintf(" --tgz[=FULLPATH] Enable support for .tar.gz, .tgz files\n\n"); |
265 |
- |
|
266 |
- exit(0); |
|
267 | 265 |
} |
268 | 266 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,100 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * |
|
3 |
+ * This program is free software; you can redistribute it and/or modify |
|
4 |
+ * it under the terms of the GNU General Public License as published by |
|
5 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
6 |
+ * (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * This program is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+ * GNU General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU General Public License |
|
14 |
+ * along with this program; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
16 |
+ * MA 02110-1301, USA. |
|
17 |
+ * |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+#ifndef __CLAMSCAN_OPT_H |
|
21 |
+#define __CLAMSCAN_OPT_H |
|
22 |
+ |
|
23 |
+#if HAVE_CONFIG_H |
|
24 |
+#include "clamav-config.h" |
|
25 |
+#endif |
|
26 |
+ |
|
27 |
+#include "getopt.h" |
|
28 |
+ |
|
29 |
+const char *clamscan_shortopt = "hvd:wriVl:m"; |
|
30 |
+static struct option clamscan_longopt[] = { |
|
31 |
+ {"help", 0, 0, 'h'}, /* clamscan + clamdscan */ |
|
32 |
+ {"quiet", 0, 0, 0}, /* clamscan + clamdscan */ |
|
33 |
+ {"stdout", 0, 0, 0}, /* clamscan + clamdscan */ |
|
34 |
+ {"verbose", 0, 0, 'v'}, /* clamscan + clamdscan */ |
|
35 |
+ {"debug", 0, 0, 0}, |
|
36 |
+ {"version", 0, 0, 'V'}, /* clamscan + clamdscan */ |
|
37 |
+ {"tempdir", 1, 0, 0}, |
|
38 |
+ {"leave-temps", 0, 0, 0}, |
|
39 |
+ {"config-file", 1, 0, 0}, /* clamdscan */ |
|
40 |
+ {"database", 1, 0, 'd'}, |
|
41 |
+ {"whole-file", 0, 0, 'w'}, /* not used */ |
|
42 |
+ {"force", 0, 0, 0}, |
|
43 |
+ {"recursive", 0, 0, 'r'}, |
|
44 |
+ {"bell", 0, 0, 0}, |
|
45 |
+ {"disable-summary", 0, 0, 0}, /* obsolete */ |
|
46 |
+ {"no-summary", 0, 0, 0}, |
|
47 |
+ {"infected", 0, 0, 'i'}, |
|
48 |
+ {"log", 1, 0, 'l'}, |
|
49 |
+ {"log-verbose", 0, 0, 0}, /* not used */ |
|
50 |
+ {"threads", 1, 0, 0}, /* not used */ |
|
51 |
+ {"one-virus", 0, 0, 0}, /* not used */ |
|
52 |
+ {"move", 1, 0, 0}, |
|
53 |
+ {"remove", 0, 0, 0}, |
|
54 |
+ {"exclude", 1, 0, 0}, |
|
55 |
+ {"exclude-dir", 1, 0, 0}, |
|
56 |
+ {"include", 1, 0, 0}, |
|
57 |
+ {"include-dir", 1, 0, 0}, |
|
58 |
+ {"max-files", 1, 0, 0}, |
|
59 |
+ {"max-space", 1, 0, 0}, |
|
60 |
+ {"max-ratio", 1, 0, 0}, |
|
61 |
+ {"max-recursion", 1, 0, 0}, |
|
62 |
+ {"max-dir-recursion", 1, 0, 0}, |
|
63 |
+#ifdef HAVE_HWACCEL |
|
64 |
+ {"hwaccel", 0, 0, 0}, |
|
65 |
+#endif |
|
66 |
+ {"disable-archive", 0, 0, 0}, |
|
67 |
+ {"no-archive", 0, 0, 0}, |
|
68 |
+ {"detect-broken", 0, 0, 0}, |
|
69 |
+ {"block-encrypted", 0, 0, 0}, |
|
70 |
+ {"block-max", 0, 0, 0}, |
|
71 |
+ {"no-pe", 0, 0, 0}, |
|
72 |
+ {"no-ole2", 0, 0, 0}, |
|
73 |
+ {"no-html", 0, 0, 0}, |
|
74 |
+ {"mbox", 0, 0, 'm'}, /* not used */ |
|
75 |
+ {"no-mail", 0, 0, 0}, |
|
76 |
+ {"mail-follow-urls", 0, 0, 0}, |
|
77 |
+ {"no-phishing", 0, 0, 0}, |
|
78 |
+ {"no-algorithmic", 0, 0, 0}, |
|
79 |
+ {"unzip", 2, 0, 0}, |
|
80 |
+ {"unrar", 2, 0, 0}, |
|
81 |
+ {"unace", 2, 0, 0}, /* not used */ |
|
82 |
+ {"unarj", 2, 0, 0}, /* not used */ |
|
83 |
+ {"arj", 2, 0, 0}, |
|
84 |
+ {"zoo", 2, 0, 0}, /* not used */ |
|
85 |
+ {"unzoo", 2, 0, 0}, |
|
86 |
+ {"lha", 2, 0, 0}, |
|
87 |
+ {"jar", 2, 0, 0}, |
|
88 |
+ {"tar", 2, 0, 0}, |
|
89 |
+ {"tgz", 2, 0, 0}, |
|
90 |
+ {"deb", 2, 0, 0}, |
|
91 |
+ |
|
92 |
+ /* developers only */ |
|
93 |
+ {"dev-ac-only", 0, 0, 0}, |
|
94 |
+ {"dev-ac-depth", 1, 0, 0}, |
|
95 |
+ |
|
96 |
+ {0, 0, 0, 0} |
|
97 |
+}; |
|
98 |
+ |
|
99 |
+#endif |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -81,27 +81,27 @@ int scanmanager(const struct optstruct *opt) |
81 | 81 |
} |
82 | 82 |
#endif |
83 | 83 |
|
84 |
- if(optl(opt, "unzip") || optl(opt, "unrar") || optl(opt, "arj") || |
|
85 |
- optl(opt, "unzoo") || optl(opt, "jar") || optl(opt, "lha") || |
|
86 |
- optl(opt, "tar") || optl(opt, "tgz") || optl(opt, "deb")) |
|
84 |
+ if(opt_check(opt, "unzip") || opt_check(opt, "unrar") || opt_check(opt, "arj") || |
|
85 |
+ opt_check(opt, "unzoo") || opt_check(opt, "jar") || opt_check(opt, "lha") || |
|
86 |
+ opt_check(opt, "tar") || opt_check(opt, "tgz") || opt_check(opt, "deb")) |
|
87 | 87 |
compression = 1; |
88 | 88 |
|
89 | 89 |
|
90 |
- if(optl(opt, "hwaccel")) |
|
90 |
+ if(opt_check(opt, "hwaccel")) |
|
91 | 91 |
dboptions |= CL_DB_HWACCEL; |
92 | 92 |
|
93 |
- if(optl(opt, "no-phishing")) |
|
93 |
+ if(opt_check(opt, "no-phishing")) |
|
94 | 94 |
dboptions |= CL_DB_NOPHISHING; |
95 | 95 |
|
96 |
- if(optl(opt, "dev-ac-only")) { |
|
96 |
+ if(opt_check(opt, "dev-ac-only")) { |
|
97 | 97 |
dboptions |= CL_DB_ACONLY; |
98 | 98 |
|
99 |
- if(optl(opt, "dev-ac-depth")) |
|
100 |
- cli_ac_setdepth(atoi(getargl(opt, "dev-ac-depth"))); |
|
99 |
+ if(opt_check(opt, "dev-ac-depth")) |
|
100 |
+ cli_ac_setdepth(atoi(opt_arg(opt, "dev-ac-depth"))); |
|
101 | 101 |
} |
102 | 102 |
|
103 |
- if(optc(opt, 'd')) { |
|
104 |
- if((ret = cl_load(getargc(opt, 'd'), &trie, &claminfo.signs, dboptions))) { |
|
103 |
+ if(opt_check(opt, "database")) { |
|
104 |
+ if((ret = cl_load(opt_arg(opt, "database"), &trie, &claminfo.signs, dboptions))) { |
|
105 | 105 |
logg("^%s\n", cl_strerror(ret)); |
106 | 106 |
return 50; |
107 | 107 |
} |
... | ... |
@@ -131,9 +131,9 @@ int scanmanager(const struct optstruct *opt) |
131 | 131 |
|
132 | 132 |
limits = (struct cl_limits *) calloc(1, sizeof(struct cl_limits)); |
133 | 133 |
|
134 |
- if(optl(opt, "max-space")) { |
|
134 |
+ if(opt_check(opt, "max-space")) { |
|
135 | 135 |
char *cpy, *ptr; |
136 |
- ptr = getargl(opt, "max-space"); |
|
136 |
+ ptr = opt_arg(opt, "max-space"); |
|
137 | 137 |
if(tolower(ptr[strlen(ptr) - 1]) == 'm') { |
138 | 138 |
cpy = mcalloc(strlen(ptr), sizeof(char)); |
139 | 139 |
strncpy(cpy, ptr, strlen(ptr) - 1); |
... | ... |
@@ -144,58 +144,58 @@ int scanmanager(const struct optstruct *opt) |
144 | 144 |
} else |
145 | 145 |
limits->maxfilesize = 10485760; |
146 | 146 |
|
147 |
- if(optl(opt, "max-files")) |
|
148 |
- limits->maxfiles = atoi(getargl(opt, "max-files")); |
|
147 |
+ if(opt_check(opt, "max-files")) |
|
148 |
+ limits->maxfiles = atoi(opt_arg(opt, "max-files")); |
|
149 | 149 |
else |
150 | 150 |
limits->maxfiles = 500; |
151 | 151 |
|
152 |
- if(optl(opt, "max-recursion")) |
|
153 |
- limits->maxreclevel = atoi(getargl(opt, "max-recursion")); |
|
152 |
+ if(opt_check(opt, "max-recursion")) |
|
153 |
+ limits->maxreclevel = atoi(opt_arg(opt, "max-recursion")); |
|
154 | 154 |
else |
155 | 155 |
limits->maxreclevel = 8; |
156 | 156 |
|
157 |
- if(optl(opt, "max-ratio")) |
|
158 |
- limits->maxratio = atoi(getargl(opt, "max-ratio")); |
|
157 |
+ if(opt_check(opt, "max-ratio")) |
|
158 |
+ limits->maxratio = atoi(opt_arg(opt, "max-ratio")); |
|
159 | 159 |
else |
160 | 160 |
limits->maxratio = 250; |
161 | 161 |
|
162 | 162 |
/* set options */ |
163 | 163 |
|
164 |
- if(optl(opt, "disable-archive") || optl(opt, "no-archive")) |
|
164 |
+ if(opt_check(opt, "disable-archive") || opt_check(opt, "no-archive")) |
|
165 | 165 |
options &= ~CL_SCAN_ARCHIVE; |
166 | 166 |
else |
167 | 167 |
options |= CL_SCAN_ARCHIVE; |
168 | 168 |
|
169 |
- if(optl(opt, "detect-broken")) |
|
169 |
+ if(opt_check(opt, "detect-broken")) |
|
170 | 170 |
options |= CL_SCAN_BLOCKBROKEN; |
171 | 171 |
|
172 |
- if(optl(opt, "block-encrypted")) |
|
172 |
+ if(opt_check(opt, "block-encrypted")) |
|
173 | 173 |
options |= CL_SCAN_BLOCKENCRYPTED; |
174 | 174 |
|
175 |
- if(optl(opt, "block-max")) |
|
175 |
+ if(opt_check(opt, "block-max")) |
|
176 | 176 |
options |= CL_SCAN_BLOCKMAX; |
177 | 177 |
|
178 |
- if(optl(opt, "no-pe")) |
|
178 |
+ if(opt_check(opt, "no-pe")) |
|
179 | 179 |
options &= ~CL_SCAN_PE; |
180 | 180 |
else |
181 | 181 |
options |= CL_SCAN_PE; |
182 | 182 |
|
183 |
- if(optl(opt, "no-ole2")) |
|
183 |
+ if(opt_check(opt, "no-ole2")) |
|
184 | 184 |
options &= ~CL_SCAN_OLE2; |
185 | 185 |
else |
186 | 186 |
options |= CL_SCAN_OLE2; |
187 | 187 |
|
188 |
- if(optl(opt, "no-html")) |
|
188 |
+ if(opt_check(opt, "no-html")) |
|
189 | 189 |
options &= ~CL_SCAN_HTML; |
190 | 190 |
else |
191 | 191 |
options |= CL_SCAN_HTML; |
192 | 192 |
|
193 |
- if(optl(opt, "no-mail")) { |
|
193 |
+ if(opt_check(opt, "no-mail")) { |
|
194 | 194 |
options &= ~CL_SCAN_MAIL; |
195 | 195 |
} else { |
196 | 196 |
options |= CL_SCAN_MAIL; |
197 | 197 |
|
198 |
- if(optl(opt, "mail-follow-urls")) |
|
198 |
+ if(opt_check(opt, "mail-follow-urls")) |
|
199 | 199 |
#ifdef WITH_CURL |
200 | 200 |
options |= CL_SCAN_MAILURL; |
201 | 201 |
#else |
... | ... |
@@ -203,7 +203,7 @@ int scanmanager(const struct optstruct *opt) |
203 | 203 |
#endif |
204 | 204 |
} |
205 | 205 |
|
206 |
- if(optl(opt, "no-algorithmic")) |
|
206 |
+ if(opt_check(opt, "no-algorithmic")) |
|
207 | 207 |
options &= ~CL_SCAN_ALGO; |
208 | 208 |
else |
209 | 209 |
options |= CL_SCAN_ALGO; |
... | ... |
@@ -318,27 +318,27 @@ int scanfile(const char *filename, struct cl_node *root, const struct passwd *us |
318 | 318 |
} |
319 | 319 |
#endif |
320 | 320 |
|
321 |
- if(optl(opt, "exclude")) { |
|
322 |
- argument = getfirstargl(opt, "exclude", &optnode); |
|
321 |
+ if(opt_check(opt, "exclude")) { |
|
322 |
+ argument = opt_firstarg(opt, "exclude", &optnode); |
|
323 | 323 |
while(argument) { |
324 | 324 |
if(match_regex(filename, argument) == 1) { |
325 | 325 |
if(!printinfected) |
326 | 326 |
logg("%s: Excluded\n", filename); |
327 | 327 |
return 0; |
328 | 328 |
} |
329 |
- argument = getnextargl(&optnode, "exclude"); |
|
329 |
+ argument = opt_nextarg(&optnode, "exclude"); |
|
330 | 330 |
} |
331 | 331 |
} |
332 | 332 |
|
333 |
- if(optl(opt, "include")) { |
|
333 |
+ if(opt_check(opt, "include")) { |
|
334 | 334 |
included = 0; |
335 |
- argument = getfirstargl(opt, "include", &optnode); |
|
335 |
+ argument = opt_firstarg(opt, "include", &optnode); |
|
336 | 336 |
while(argument && !included) { |
337 | 337 |
if(match_regex(filename, argument) == 1) { |
338 | 338 |
included = 1; |
339 | 339 |
break; |
340 | 340 |
} |
341 |
- argument = getnextargl(&optnode, "include"); |
|
341 |
+ argument = opt_nextarg(&optnode, "include"); |
|
342 | 342 |
} |
343 | 343 |
|
344 | 344 |
if(!included) { |
... | ... |
@@ -373,14 +373,14 @@ int scanfile(const char *filename, struct cl_node *root, const struct passwd *us |
373 | 373 |
if((cli_strbcasestr(filename, ".zip") || cli_strbcasestr(filename, ".rar")) && (options & CL_SCAN_ARCHIVE)) { |
374 | 374 |
/* try to use internal archivers */ |
375 | 375 |
if((ret = checkfile(filename, root, limits, options, 1)) == CL_VIRUS) { |
376 |
- if(optl(opt, "remove")) { |
|
376 |
+ if(opt_check(opt, "remove")) { |
|
377 | 377 |
if(unlink(filename)) { |
378 | 378 |
logg("%s: Can't remove\n", filename); |
379 | 379 |
claminfo.notremoved++; |
380 | 380 |
} else { |
381 | 381 |
logg("%s: Removed\n", filename); |
382 | 382 |
} |
383 |
- } else if (optl(opt, "move")) |
|
383 |
+ } else if (opt_check(opt, "move")) |
|
384 | 384 |
move_infected(filename, opt); |
385 | 385 |
|
386 | 386 |
return 1; |
... | ... |
@@ -396,16 +396,16 @@ int scanfile(const char *filename, struct cl_node *root, const struct passwd *us |
396 | 396 |
printclean = 0; |
397 | 397 |
} |
398 | 398 |
|
399 |
- if((cli_strbcasestr(filename, ".zip") && optl(opt, "unzip")) |
|
400 |
- || (cli_strbcasestr(filename, ".rar") && optl(opt, "unrar")) |
|
401 |
- || (cli_strbcasestr(filename, ".arj") && optl(opt, "arj")) |
|
402 |
- || (cli_strbcasestr(filename, ".zoo") && optl(opt, "unzoo")) |
|
403 |
- || (cli_strbcasestr(filename, ".jar") && optl(opt, "jar")) |
|
404 |
- || (cli_strbcasestr(filename, ".lzh") && optl(opt, "lha")) |
|
405 |
- || (cli_strbcasestr(filename, ".tar") && optl(opt, "tar")) |
|
406 |
- || (cli_strbcasestr(filename, ".deb") && optl(opt, "deb")) |
|
399 |
+ if((cli_strbcasestr(filename, ".zip") && opt_check(opt, "unzip")) |
|
400 |
+ || (cli_strbcasestr(filename, ".rar") && opt_check(opt, "unrar")) |
|
401 |
+ || (cli_strbcasestr(filename, ".arj") && opt_check(opt, "arj")) |
|
402 |
+ || (cli_strbcasestr(filename, ".zoo") && opt_check(opt, "unzoo")) |
|
403 |
+ || (cli_strbcasestr(filename, ".jar") && opt_check(opt, "jar")) |
|
404 |
+ || (cli_strbcasestr(filename, ".lzh") && opt_check(opt, "lha")) |
|
405 |
+ || (cli_strbcasestr(filename, ".tar") && opt_check(opt, "tar")) |
|
406 |
+ || (cli_strbcasestr(filename, ".deb") && opt_check(opt, "deb")) |
|
407 | 407 |
|| ((cli_strbcasestr(filename, ".tar.gz") || cli_strbcasestr(filename, ".tgz")) |
408 |
- && (optl(opt, "tgz") || optl(opt, "deb"))) ) { |
|
408 |
+ && (opt_check(opt, "tgz") || opt_check(opt, "deb"))) ) { |
|
409 | 409 |
|
410 | 410 |
/* check permissions */ |
411 | 411 |
switch(checkaccess(filename, UNPUSER, R_OK)) { |
... | ... |
@@ -437,14 +437,14 @@ int scanfile(const char *filename, struct cl_node *root, const struct passwd *us |
437 | 437 |
} |
438 | 438 |
|
439 | 439 |
if((ret = checkfile(filename, root, limits, options, printclean)) == CL_VIRUS) { |
440 |
- if(optl(opt, "remove")) { |
|
440 |
+ if(opt_check(opt, "remove")) { |
|
441 | 441 |
if(unlink(filename)) { |
442 | 442 |
logg("%s: Can't remove\n", filename); |
443 | 443 |
claminfo.notremoved++; |
444 | 444 |
} else { |
445 | 445 |
logg("%s: Removed\n", filename); |
446 | 446 |
} |
447 |
- } else if (optl(opt, "move")) |
|
447 |
+ } else if (opt_check(opt, "move")) |
|
448 | 448 |
move_infected(filename, opt); |
449 | 449 |
} |
450 | 450 |
return ret; |
... | ... |
@@ -502,7 +502,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
502 | 502 |
*/ |
503 | 503 |
args[4] = (char *) filename; |
504 | 504 |
|
505 |
- if((userprg = getargl(opt, "unzip"))) |
|
505 |
+ if((userprg = opt_arg(opt, "unzip"))) |
|
506 | 506 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
507 | 507 |
else |
508 | 508 |
ret = clamav_unpack("unzip", args, gendir, user, opt); |
... | ... |
@@ -510,7 +510,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
510 | 510 |
} else if(cli_strbcasestr(filename, ".rar")) { |
511 | 511 |
char *args[] = { "unrar", "x", "-p-", "-y", NULL, NULL }; |
512 | 512 |
args[4] = (char *) filename; |
513 |
- if((userprg = getargl(opt, "unrar"))) |
|
513 |
+ if((userprg = opt_arg(opt, "unrar"))) |
|
514 | 514 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
515 | 515 |
else |
516 | 516 |
ret = clamav_unpack("unrar", args, gendir, user, opt); |
... | ... |
@@ -518,7 +518,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
518 | 518 |
} else if(cli_strbcasestr(filename, ".arj")) { |
519 | 519 |
char *args[] = { "arj", "x","-y", NULL, NULL }; |
520 | 520 |
args[3] = (char *) filename; |
521 |
- if((userprg = getargl(opt, "arj"))) |
|
521 |
+ if((userprg = opt_arg(opt, "arj"))) |
|
522 | 522 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
523 | 523 |
else |
524 | 524 |
ret = clamav_unpack("arj", args, gendir, user, opt); |
... | ... |
@@ -526,7 +526,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
526 | 526 |
} else if(cli_strbcasestr(filename, ".zoo")) { |
527 | 527 |
char *args[] = { "unzoo", "-x","-j","./", NULL, NULL }; |
528 | 528 |
args[4] = (char *) filename; |
529 |
- if((userprg = getargl(opt, "unzoo"))) |
|
529 |
+ if((userprg = opt_arg(opt, "unzoo"))) |
|
530 | 530 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
531 | 531 |
else |
532 | 532 |
ret = clamav_unpack("unzoo", args, gendir, user, opt); |
... | ... |
@@ -534,7 +534,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
534 | 534 |
} else if(cli_strbcasestr(filename, ".jar")) { |
535 | 535 |
char *args[] = { "unzip", "-P", "clam", "-o", NULL, NULL }; |
536 | 536 |
args[4] = (char *) filename; |
537 |
- if((userprg = getargl(opt, "jar"))) |
|
537 |
+ if((userprg = opt_arg(opt, "jar"))) |
|
538 | 538 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
539 | 539 |
else |
540 | 540 |
ret = clamav_unpack("unzip", args, gendir, user, opt); |
... | ... |
@@ -542,7 +542,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
542 | 542 |
} else if(cli_strbcasestr(filename, ".lzh")) { |
543 | 543 |
char *args[] = { "lha", "xf", NULL, NULL }; |
544 | 544 |
args[2] = (char *) filename; |
545 |
- if((userprg = getargl(opt, "lha"))) |
|
545 |
+ if((userprg = opt_arg(opt, "lha"))) |
|
546 | 546 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
547 | 547 |
else |
548 | 548 |
ret = clamav_unpack("lha", args, gendir, user, opt); |
... | ... |
@@ -550,7 +550,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
550 | 550 |
} else if(cli_strbcasestr(filename, ".tar")) { |
551 | 551 |
char *args[] = { "tar", "-xpvf", NULL, NULL }; |
552 | 552 |
args[2] = (char *) filename; |
553 |
- if((userprg = getargl(opt, "tar"))) |
|
553 |
+ if((userprg = opt_arg(opt, "tar"))) |
|
554 | 554 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
555 | 555 |
else |
556 | 556 |
ret = clamav_unpack("tar", args, gendir, user, opt); |
... | ... |
@@ -558,7 +558,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
558 | 558 |
} else if(cli_strbcasestr(filename, ".deb")) { |
559 | 559 |
char *args[] = { "ar", "x", NULL, NULL }; |
560 | 560 |
args[2] = (char *) filename; |
561 |
- if((userprg = getargl(opt, "deb"))) |
|
561 |
+ if((userprg = opt_arg(opt, "deb"))) |
|
562 | 562 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
563 | 563 |
else |
564 | 564 |
ret = clamav_unpack("ar", args, gendir, user, opt); |
... | ... |
@@ -566,7 +566,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
566 | 566 |
} else if((cli_strbcasestr(filename, ".tar.gz") || cli_strbcasestr(filename, ".tgz"))) { |
567 | 567 |
char *args[] = { "tar", "-zxpvf", NULL, NULL }; |
568 | 568 |
args[2] = (char *) filename; |
569 |
- if((userprg = getargl(opt, "tgz"))) |
|
569 |
+ if((userprg = opt_arg(opt, "tgz"))) |
|
570 | 570 |
ret = clamav_unpack(userprg, args, gendir, user, opt); |
571 | 571 |
else |
572 | 572 |
ret = clamav_unpack("tar", args, gendir, user, opt); |
... | ... |
@@ -584,7 +584,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
/* remove the directory - as clamav */ |
587 |
- if(!optl(opt, "leave-temps")) |
|
587 |
+ if(!opt_check(opt, "leave-temps")) |
|
588 | 588 |
clamav_rmdirs(gendir); |
589 | 589 |
|
590 | 590 |
/* free gendir - it's not necessary now */ |
... | ... |
@@ -600,14 +600,14 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
600 | 600 |
* raw archive. |
601 | 601 |
*/ |
602 | 602 |
if((ret = checkfile(filename, root, limits, 0, 0)) == CL_VIRUS) { |
603 |
- if(optl(opt, "remove")) { |
|
603 |
+ if(opt_check(opt, "remove")) { |
|
604 | 604 |
if(unlink(filename)) { |
605 | 605 |
logg("%s: Can't remove\n", filename); |
606 | 606 |
claminfo.notremoved++; |
607 | 607 |
} else { |
608 | 608 |
logg("%s: Removed\n", filename); |
609 | 609 |
} |
610 |
- } else if (optl(opt, "move")) |
|
610 |
+ } else if (opt_check(opt, "move")) |
|
611 | 611 |
move_infected(filename, opt); |
612 | 612 |
} |
613 | 613 |
return ret; |
... | ... |
@@ -617,14 +617,14 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
617 | 617 |
/* no viruses found in archive, we scan just in case a raw file |
618 | 618 |
*/ |
619 | 619 |
if((ret = checkfile(filename, root, limits, 0, 1)) == CL_VIRUS) { |
620 |
- if(optl(opt, "remove")) { |
|
620 |
+ if(opt_check(opt, "remove")) { |
|
621 | 621 |
if(unlink(filename)) { |
622 | 622 |
logg("%s: Can't remove\n", filename); |
623 | 623 |
claminfo.notremoved++; |
624 | 624 |
} else { |
625 | 625 |
logg("%s: Removed\n", filename); |
626 | 626 |
} |
627 |
- } else if (optl(opt, "move")) |
|
627 |
+ } else if (opt_check(opt, "move")) |
|
628 | 628 |
move_infected(filename, opt); |
629 | 629 |
} |
630 | 630 |
return ret; |
... | ... |
@@ -634,14 +634,14 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass |
634 | 634 |
if(bell) |
635 | 635 |
fprintf(stderr, "\007"); |
636 | 636 |
|
637 |
- if(optl(opt, "remove")) { |
|
637 |
+ if(opt_check(opt, "remove")) { |
|
638 | 638 |
if(unlink(filename)) { |
639 | 639 |
logg("%s: Can't remove\n", filename); |
640 | 640 |
claminfo.notremoved++; |
641 | 641 |
} else { |
642 | 642 |
logg("%s: Removed\n", filename); |
643 | 643 |
} |
644 |
- } else if (optl(opt, "move")) |
|
644 |
+ } else if (opt_check(opt, "move")) |
|
645 | 645 |
move_infected(filename, opt); |
646 | 646 |
|
647 | 647 |
return 1; |
... | ... |
@@ -714,14 +714,14 @@ int scandenied(const char *filename, struct cl_node *root, const struct passwd * |
714 | 714 |
if((ret = treewalk(gendir, root, user, opt, limits, options, 1)) == 1) { |
715 | 715 |
logg("(Real infected archive: %s)\n", filename); |
716 | 716 |
|
717 |
- if(optl(opt, "remove")) { |
|
717 |
+ if(opt_check(opt, "remove")) { |
|
718 | 718 |
if(unlink(filename)) { |
719 | 719 |
logg("%s: Can't remove\n", filename); |
720 | 720 |
claminfo.notremoved++; |
721 | 721 |
} else { |
722 | 722 |
logg("%s: Removed\n", filename); |
723 | 723 |
} |
724 |
- } else if (optl(opt, "move")) |
|
724 |
+ } else if (opt_check(opt, "move")) |
|
725 | 725 |
move_infected(filename, opt); |
726 | 726 |
} |
727 | 727 |
|
... | ... |
@@ -841,14 +841,14 @@ int clamav_unpack(const char *prog, char **args, const char *tmpdir, const struc |
841 | 841 |
struct s_du n; |
842 | 842 |
|
843 | 843 |
|
844 |
- if(optl(opt, "max-files")) |
|
845 |
- maxfiles = atoi(getargl(opt, "max-files")); |
|
844 |
+ if(opt_check(opt, "max-files")) |
|
845 |
+ maxfiles = atoi(opt_arg(opt, "max-files")); |
|
846 | 846 |
else |
847 | 847 |
maxfiles = 0; |
848 | 848 |
|
849 |
- if(optl(opt, "max-space")) { |
|
849 |
+ if(opt_check(opt, "max-space")) { |
|
850 | 850 |
char *cpy, *ptr; |
851 |
- ptr = getargl(opt, "max-space"); |
|
851 |
+ ptr = opt_arg(opt, "max-space"); |
|
852 | 852 |
if(tolower(ptr[strlen(ptr) - 1]) == 'm') { /* megabytes */ |
853 | 853 |
cpy = mcalloc(strlen(ptr), sizeof(char)); |
854 | 854 |
strncpy(cpy, ptr, strlen(ptr) - 1); |
... | ... |
@@ -949,15 +949,15 @@ void move_infected(const char *filename, const struct optstruct *opt) |
949 | 949 |
struct utimbuf ubuf; |
950 | 950 |
|
951 | 951 |
|
952 |
- if(!(movedir = getargl(opt, "move"))) { |
|
952 |
+ if(!(movedir = opt_arg(opt, "move"))) { |
|
953 | 953 |
/* Should never reach here */ |
954 |
- logg("^getargc() returned NULL\n", filename); |
|
954 |
+ logg("!opt_arg() returned NULL\n", filename); |
|
955 | 955 |
claminfo.notmoved++; |
956 | 956 |
return; |
957 | 957 |
} |
958 | 958 |
|
959 | 959 |
if(access(movedir, W_OK|X_OK) == -1) { |
960 |
- logg("^error moving file '%s': cannot write to '%s': %s\n", filename, movedir, strerror(errno)); |
|
960 |
+ logg("!Can't move file '%s': cannot write to '%s': %s\n", filename, movedir, strerror(errno)); |
|
961 | 961 |
claminfo.notmoved++; |
962 | 962 |
return; |
963 | 963 |
} |
... | ... |
@@ -968,12 +968,12 @@ void move_infected(const char *filename, const struct optstruct *opt) |
968 | 968 |
movefilename_size = sizeof(char) * (strlen(movedir) + strlen(tmp) + sizeof(numext) + 2); |
969 | 969 |
|
970 | 970 |
if(!(movefilename = mmalloc(movefilename_size))) { |
971 |
- logg("^Memory allocation error\n"); |
|
971 |
+ logg("!mmalloc() failed\n"); |
|
972 | 972 |
exit(71); |
973 | 973 |
} |
974 | 974 |
|
975 | 975 |
if(!(strrcpy(movefilename, movedir))) { |
976 |
- logg("^strrcpy() returned NULL\n"); |
|
976 |
+ logg("!strrcpy() returned NULL\n"); |
|
977 | 977 |
claminfo.notmoved++; |
978 | 978 |
free(movefilename); |
979 | 979 |
return; |
... | ... |
@@ -982,7 +982,7 @@ void move_infected(const char *filename, const struct optstruct *opt) |
982 | 982 |
strcat(movefilename, "/"); |
983 | 983 |
|
984 | 984 |
if(!(strcat(movefilename, tmp))) { |
985 |
- logg("^strcat() returned NULL\n"); |
|
985 |
+ logg("!strcat() returned NULL\n"); |
|
986 | 986 |
claminfo.notmoved++; |
987 | 987 |
free(movefilename); |
988 | 988 |
return; |
... | ... |
@@ -1017,7 +1017,7 @@ void move_infected(const char *filename, const struct optstruct *opt) |
1017 | 1017 |
|
1018 | 1018 |
if(rename(filename, movefilename) == -1) { |
1019 | 1019 |
if(filecopy(filename, movefilename) == -1) { |
1020 |
- logg("^cannot move '%s' to '%s': %s\n", filename, movefilename, strerror(errno)); |
|
1020 |
+ logg("!Can't move '%s' to '%s': %s\n", filename, movefilename, strerror(errno)); |
|
1021 | 1021 |
claminfo.notmoved++; |
1022 | 1022 |
free(movefilename); |
1023 | 1023 |
return; |
... | ... |
@@ -1033,7 +1033,7 @@ void move_infected(const char *filename, const struct optstruct *opt) |
1033 | 1033 |
utime(movefilename, &ubuf); |
1034 | 1034 |
|
1035 | 1035 |
if(unlink(filename)) { |
1036 |
- logg("^cannot unlink '%s': %s\n", filename, strerror(errno)); |
|
1036 |
+ logg("!Can't unlink '%s': %s\n", filename, strerror(errno)); |
|
1037 | 1037 |
claminfo.notremoved++; |
1038 | 1038 |
free(movefilename); |
1039 | 1039 |
return; |
... | ... |
@@ -38,11 +38,6 @@ int checkfile(const char *filename, const struct cl_node *root, const struct cl_ |
38 | 38 |
|
39 | 39 |
int checkstdin(const struct cl_node *root, const struct cl_limits *limits, int options); |
40 | 40 |
|
41 |
-#ifdef CLAMSCAN_THREADS |
|
42 |
- int thr_exitno, thr_pid; |
|
43 |
- void thr_exit(int sig); |
|
44 |
-#endif |
|
45 |
- |
|
46 | 41 |
int clamav_unpack(const char *prog, char **args, const char *tmpdir, const struct passwd *user, const struct optstruct *opt); |
47 | 42 |
|
48 | 43 |
void move_infected(const char *filename, const struct optstruct *opt); |
49 | 44 |
deleted file mode 100644 |
... | ... |
@@ -1,427 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2001 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- * |
|
19 |
- * Sat Sep 14 22:18:20 CEST 2002: included getfirst*(), getnext*() functions |
|
20 |
- * from Alejandro Dubrovsky <s328940@student.uq.edu.au> |
|
21 |
- */ |
|
22 |
- |
|
23 |
-#if HAVE_CONFIG_H |
|
24 |
-#include "clamav-config.h" |
|
25 |
-#endif |
|
26 |
- |
|
27 |
-#include <stdio.h> |
|
28 |
-#include <stdlib.h> |
|
29 |
-#include <string.h> |
|
30 |
-#include <clamav.h> |
|
31 |
-#define _GNU_SOURCE |
|
32 |
-#include "getopt.h" |
|
33 |
- |
|
34 |
- |
|
35 |
-#include "options.h" |
|
36 |
-#include "shared.h" |
|
37 |
-#include "memory.h" |
|
38 |
-#include "output.h" |
|
39 |
- |
|
40 |
-extern int clamscan(struct optstruct *opt); |
|
41 |
- |
|
42 |
-static char *clamdscan_long[] = { "help", "version", "verbose", "quiet", |
|
43 |
- "stdout", "log", "move", "remove", |
|
44 |
- "config-file", "no-summary", |
|
45 |
- "disable-summary", NULL }; |
|
46 |
- |
|
47 |
-static char clamdscan_short[] = { 'h', 'V', 'v', 'l', 0 }; |
|
48 |
- |
|
49 |
-int clamdscan_mode = 0; |
|
50 |
- |
|
51 |
-short foreground = 1; |
|
52 |
- |
|
53 |
-int main(int argc, char **argv) |
|
54 |
-{ |
|
55 |
- int ret, opt_index, i, len; |
|
56 |
- struct optstruct *opt; |
|
57 |
- |
|
58 |
- const char *getopt_parameters = "hvd:wriVl:m"; |
|
59 |
- |
|
60 |
- static struct option long_options[] = { |
|
61 |
- /* |
|
62 |
- * WARNING: For compatibility reasons options marked as "not used" |
|
63 |
- * must still be accepted ! |
|
64 |
- */ |
|
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 */ |
|
69 |
- {"debug", 0, 0, 0}, |
|
70 |
- {"version", 0, 0, 'V'}, /* clamscan + clamdscan */ |
|
71 |
- {"tempdir", 1, 0, 0}, |
|
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 */ |
|
76 |
- {"force", 0, 0, 0}, |
|
77 |
- {"recursive", 0, 0, 'r'}, |
|
78 |
- {"bell", 0, 0, 0}, |
|
79 |
- {"disable-summary", 0, 0, 0}, /* obsolete */ |
|
80 |
- {"no-summary", 0, 0, 0}, |
|
81 |
- {"infected", 0, 0, 'i'}, |
|
82 |
- {"log", 1, 0, 'l'}, |
|
83 |
- {"log-verbose", 0, 0, 0}, /* not used */ |
|
84 |
- {"threads", 1, 0, 0}, /* not used */ |
|
85 |
- {"one-virus", 0, 0, 0}, /* not used */ |
|
86 |
- {"move", 1, 0, 0}, |
|
87 |
- {"remove", 0, 0, 0}, |
|
88 |
- {"exclude", 1, 0, 0}, |
|
89 |
- {"exclude-dir", 1, 0, 0}, |
|
90 |
- {"include", 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}, |
|
97 |
-#ifdef HAVE_HWACCEL |
|
98 |
- {"hwaccel", 0, 0, 0}, |
|
99 |
-#endif |
|
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}, |
|
105 |
- {"no-pe", 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}, |
|
113 |
- {"unzip", 2, 0, 0}, |
|
114 |
- {"unrar", 2, 0, 0}, |
|
115 |
- {"unace", 2, 0, 0}, /* not used */ |
|
116 |
- {"unarj", 2, 0, 0}, /* not used */ |
|
117 |
- {"arj", 2, 0, 0}, |
|
118 |
- {"zoo", 2, 0, 0}, /* not used */ |
|
119 |
- {"unzoo", 2, 0, 0}, |
|
120 |
- {"lha", 2, 0, 0}, |
|
121 |
- {"jar", 2, 0, 0}, |
|
122 |
- {"tar", 2, 0, 0}, |
|
123 |
- {"tgz", 2, 0, 0}, |
|
124 |
- {"deb", 2, 0, 0}, |
|
125 |
- |
|
126 |
- /* developers only */ |
|
127 |
- {"dev-ac-only", 0, 0, 0}, |
|
128 |
- {"dev-ac-depth", 1, 0, 0}, |
|
129 |
- |
|
130 |
- {0, 0, 0, 0} |
|
131 |
- }; |
|
132 |
- |
|
133 |
- |
|
134 |
- opt=(struct optstruct*) mcalloc(1, sizeof(struct optstruct)); |
|
135 |
- opt->optlist = NULL; |
|
136 |
- |
|
137 |
- if(strstr(argv[0], "clamdscan")) |
|
138 |
- clamdscan_mode = 1; |
|
139 |
- |
|
140 |
- while(1) { |
|
141 |
- |
|
142 |
- opt_index=0; |
|
143 |
- ret=getopt_long(argc, argv, getopt_parameters, long_options, &opt_index); |
|
144 |
- |
|
145 |
- if (ret == -1) |
|
146 |
- break; |
|
147 |
- |
|
148 |
- switch (ret) { |
|
149 |
- case 0: |
|
150 |
- register_long_option(opt, long_options[opt_index].name); |
|
151 |
- break; |
|
152 |
- |
|
153 |
- default: |
|
154 |
- if(strchr(getopt_parameters, ret)) { |
|
155 |
- if(opt_index) |
|
156 |
- register_char_option(opt, ret, long_options[opt_index].name); |
|
157 |
- else |
|
158 |
- register_char_option(opt, ret, NULL); |
|
159 |
- |
|
160 |
- } else { |
|
161 |
- logg("!Unknown option passed.\n"); |
|
162 |
- free_opt(opt); |
|
163 |
- if(clamdscan_mode) |
|
164 |
- exit(2); |
|
165 |
- else |
|
166 |
- exit(40); |
|
167 |
- } |
|
168 |
- } |
|
169 |
- } |
|
170 |
- |
|
171 |
- if (optind < argc) { |
|
172 |
- |
|
173 |
- len=0; |
|
174 |
- |
|
175 |
- /* count length of non-option arguments */ |
|
176 |
- |
|
177 |
- for(i=optind; i<argc; i++) |
|
178 |
- len+=strlen(argv[i]); |
|
179 |
- |
|
180 |
- len=len+argc-optind-1; /* add spaces between arguments */ |
|
181 |
- opt->filename=(char*)mcalloc(len + 256, sizeof(char)); |
|
182 |
- |
|
183 |
- for(i=optind; i<argc; i++) { |
|
184 |
- strncat(opt->filename, argv[i], strlen(argv[i])); |
|
185 |
- if(i != argc-1) |
|
186 |
- strncat(opt->filename, "\t", 1); |
|
187 |
- } |
|
188 |
- |
|
189 |
- } |
|
190 |
- ret = clamscan(opt); |
|
191 |
- |
|
192 |
- free_opt(opt); |
|
193 |
- |
|
194 |
- return ret; |
|
195 |
-} |
|
196 |
- |
|
197 |
-void register_char_option(struct optstruct *opt, char ch, const char *longname) |
|
198 |
-{ |
|
199 |
- struct optnode *newnode; |
|
200 |
- int i, found = 0; |
|
201 |
- |
|
202 |
- |
|
203 |
- if(clamdscan_mode) { |
|
204 |
- for(i = 0; clamdscan_short[i]; i++) |
|
205 |
- if(clamdscan_short[i] == ch) |
|
206 |
- found = 1; |
|
207 |
- |
|
208 |
- if(!found) { |
|
209 |
- if(longname) |
|
210 |
- logg("WARNING: Ignoring option -%c (--%s): please edit clamd.conf instead.\n", ch, longname); |
|
211 |
- else |
|
212 |
- logg("WARNING: Ignoring option -%c: please edit clamd.conf instead.\n", ch); |
|
213 |
- |
|
214 |
- return; |
|
215 |
- } |
|
216 |
- } |
|
217 |
- |
|
218 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
219 |
- newnode->optchar = ch; |
|
220 |
- if(optarg != NULL) { |
|
221 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
222 |
- strcpy(newnode->optarg, optarg); |
|
223 |
- } else newnode->optarg = NULL; |
|
224 |
- |
|
225 |
- newnode->optname = NULL; |
|
226 |
- newnode->next = opt->optlist; |
|
227 |
- opt->optlist = newnode; |
|
228 |
-} |
|
229 |
- |
|
230 |
-void register_long_option(struct optstruct *opt, const char *optname) |
|
231 |
-{ |
|
232 |
- struct optnode *newnode; |
|
233 |
- int i, found = 0; |
|
234 |
- |
|
235 |
- |
|
236 |
- if(clamdscan_mode) { |
|
237 |
- for(i = 0; clamdscan_long[i]; i++) |
|
238 |
- if(!strcmp(clamdscan_long[i], optname)) |
|
239 |
- found = 1; |
|
240 |
- |
|
241 |
- if(!found) { |
|
242 |
- logg("WARNING: Ignoring option --%s: please edit clamd.conf instead.\n", optname); |
|
243 |
- return; |
|
244 |
- } |
|
245 |
- } |
|
246 |
- |
|
247 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
248 |
- newnode->optchar = 0; |
|
249 |
- if(optarg != NULL) { |
|
250 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
251 |
- strcpy(newnode->optarg, optarg); |
|
252 |
- } else newnode->optarg = NULL; |
|
253 |
- |
|
254 |
- newnode->optname = (char *) mcalloc(strlen(optname) + 1, sizeof(char)); |
|
255 |
- strcpy(newnode->optname, optname); |
|
256 |
- newnode->next = opt->optlist; |
|
257 |
- opt->optlist = newnode; |
|
258 |
-} |
|
259 |
- |
|
260 |
-int optc(const struct optstruct *opt, char ch) |
|
261 |
-{ |
|
262 |
- struct optnode *handler; |
|
263 |
- |
|
264 |
- handler = opt->optlist; |
|
265 |
- |
|
266 |
- while(1) { |
|
267 |
- if(handler) { |
|
268 |
- if(handler->optchar == ch) return 1; |
|
269 |
- } else break; |
|
270 |
- handler = handler->next; |
|
271 |
- } |
|
272 |
- |
|
273 |
- return(0); |
|
274 |
-} |
|
275 |
- |
|
276 |
-int optl(const struct optstruct *opt, const char *optname) |
|
277 |
-{ |
|
278 |
- struct optnode *handler; |
|
279 |
- |
|
280 |
- handler = opt->optlist; |
|
281 |
- |
|
282 |
- while(1) { |
|
283 |
- if(handler) { |
|
284 |
- if(handler->optname) |
|
285 |
- if(!strcmp(handler->optname, optname)) return 1; |
|
286 |
- } else break; |
|
287 |
- handler = handler->next; |
|
288 |
- } |
|
289 |
- |
|
290 |
- return(0); |
|
291 |
-} |
|
292 |
- |
|
293 |
-char *getargc(const struct optstruct *opt, char ch) |
|
294 |
-{ |
|
295 |
- struct optnode *handler; |
|
296 |
- |
|
297 |
- handler = opt->optlist; |
|
298 |
- |
|
299 |
- while(1) { |
|
300 |
- if(handler) { |
|
301 |
- if(handler->optchar == ch) return handler->optarg; |
|
302 |
- } else break; |
|
303 |
- handler = handler->next; |
|
304 |
- } |
|
305 |
- |
|
306 |
- return(NULL); |
|
307 |
-} |
|
308 |
- |
|
309 |
-char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode) |
|
310 |
-{ |
|
311 |
- struct optnode *handler; |
|
312 |
- |
|
313 |
- handler = opt->optlist; |
|
314 |
- |
|
315 |
- while(1) { |
|
316 |
- if(handler) { |
|
317 |
- if(handler->optchar == ch) { |
|
318 |
- *optnode = handler; |
|
319 |
- return handler->optarg; |
|
320 |
- } |
|
321 |
- } else break; |
|
322 |
- handler = handler->next; |
|
323 |
- } |
|
324 |
- *optnode = NULL; |
|
325 |
- return(NULL); |
|
326 |
-} |
|
327 |
- |
|
328 |
-char *getnextargc(struct optnode **optnode, char ch) |
|
329 |
-{ |
|
330 |
- struct optnode *handler; |
|
331 |
- |
|
332 |
- handler = (*optnode)->next; |
|
333 |
- |
|
334 |
- while(1) { |
|
335 |
- if(handler) { |
|
336 |
- if(handler->optchar == ch) { |
|
337 |
- *optnode = handler; |
|
338 |
- return handler->optarg; |
|
339 |
- } |
|
340 |
- } else break; |
|
341 |
- handler = handler->next; |
|
342 |
- } |
|
343 |
- *optnode = NULL; |
|
344 |
- return(NULL); |
|
345 |
-} |
|
346 |
- |
|
347 |
-char *getargl(const struct optstruct *opt, const char *optname) |
|
348 |
-{ |
|
349 |
- struct optnode *handler; |
|
350 |
- |
|
351 |
- handler = opt->optlist; |
|
352 |
- |
|
353 |
- while(1) { |
|
354 |
- if(handler) { |
|
355 |
- if(handler->optname) |
|
356 |
- if(!strcmp(handler->optname, optname)) return handler->optarg; |
|
357 |
- } else break; |
|
358 |
- handler = handler->next; |
|
359 |
- } |
|
360 |
- |
|
361 |
- return(NULL); |
|
362 |
-} |
|
363 |
- |
|
364 |
-char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode) |
|
365 |
-{ |
|
366 |
- struct optnode *handler; |
|
367 |
- |
|
368 |
- handler = opt->optlist; |
|
369 |
- |
|
370 |
- while(1) { |
|
371 |
- if(handler) { |
|
372 |
- if(handler->optname) |
|
373 |
- if(!strcmp(handler->optname, optname)) { |
|
374 |
- *optnode = handler; |
|
375 |
- return handler->optarg; |
|
376 |
- } |
|
377 |
- } else break; |
|
378 |
- handler = handler->next; |
|
379 |
- } |
|
380 |
- |
|
381 |
- *optnode = NULL; |
|
382 |
- return(NULL); |
|
383 |
-} |
|
384 |
- |
|
385 |
-char *getnextargl(struct optnode **optnode, const char *optname) |
|
386 |
-{ |
|
387 |
- struct optnode *handler; |
|
388 |
- |
|
389 |
- handler = (*optnode)->next; |
|
390 |
- |
|
391 |
- while(1) { |
|
392 |
- if(handler) { |
|
393 |
- if(handler->optname) |
|
394 |
- if(!strcmp(handler->optname, optname)) { |
|
395 |
- *optnode = handler; |
|
396 |
- return handler->optarg; |
|
397 |
- } |
|
398 |
- } else break; |
|
399 |
- handler = handler->next; |
|
400 |
- } |
|
401 |
- |
|
402 |
- *optnode = NULL; |
|
403 |
- return(NULL); |
|
404 |
-} |
|
405 |
- |
|
406 |
-void free_opt(struct optstruct *opt) |
|
407 |
-{ |
|
408 |
- struct optnode *handler, *prev; |
|
409 |
- |
|
410 |
- if(!opt) |
|
411 |
- return; |
|
412 |
- |
|
413 |
- handler = opt->optlist; |
|
414 |
- |
|
415 |
- while(handler != NULL) { |
|
416 |
- handler->optchar = 0; |
|
417 |
- if(handler->optarg) free(handler->optarg); |
|
418 |
- if(handler->optname) free(handler->optname); |
|
419 |
- prev = handler; |
|
420 |
- handler = handler->next; |
|
421 |
- free(prev); |
|
422 |
- } |
|
423 |
- |
|
424 |
- if (opt->filename) |
|
425 |
- free(opt->filename); |
|
426 |
- free(opt); |
|
427 |
-} |
428 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,47 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002, 2003 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#ifndef __OPTIONS_H |
|
21 |
-#define __OPTIONS_H |
|
22 |
- |
|
23 |
-struct optnode { |
|
24 |
- char optchar; |
|
25 |
- char *optarg; |
|
26 |
- char *optname; |
|
27 |
- struct optnode *next; |
|
28 |
-}; |
|
29 |
- |
|
30 |
-struct optstruct { |
|
31 |
- struct optnode *optlist; |
|
32 |
- char *filename; |
|
33 |
-}; |
|
34 |
- |
|
35 |
-int optc(const struct optstruct *opt, char ch); |
|
36 |
-int optl(const struct optstruct *opt, const char *optname); |
|
37 |
-void register_char_option(struct optstruct *opt, char ch, const char *longname); |
|
38 |
-void register_long_option(struct optstruct *opt, const char *optname); |
|
39 |
-char *getargc(const struct optstruct *opt, char ch); |
|
40 |
-char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode); |
|
41 |
-char *getnextargc(struct optnode **optnode, char ch); |
|
42 |
-char *getargl(const struct optstruct *opt, const char *optname); |
|
43 |
-char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode); |
|
44 |
-char *getnextargl(struct optnode **optnode, const char *optname); |
|
45 |
-void free_opt(struct optstruct *opt); |
|
46 |
- |
|
47 |
-#endif |
... | ... |
@@ -53,27 +53,27 @@ int treewalk(const char *dirname, struct cl_node *root, const struct passwd *use |
53 | 53 |
char *argument; |
54 | 54 |
|
55 | 55 |
|
56 |
- if(optl(opt, "exclude-dir")) { |
|
57 |
- argument = getfirstargl(opt, "exclude-dir", &optnode); |
|
56 |
+ if(opt_check(opt, "exclude-dir")) { |
|
57 |
+ argument = opt_firstarg(opt, "exclude-dir", &optnode); |
|
58 | 58 |
while(argument) { |
59 | 59 |
if(match_regex(dirname, argument) == 1) { |
60 | 60 |
if(!printinfected) |
61 | 61 |
logg("%s: Excluded\n", dirname); |
62 | 62 |
return 0; |
63 | 63 |
} |
64 |
- argument = getnextargl(&optnode, "exclude-dir"); |
|
64 |
+ argument = opt_nextarg(&optnode, "exclude-dir"); |
|
65 | 65 |
} |
66 | 66 |
} |
67 | 67 |
|
68 |
- if(optl(opt, "include-dir")) { |
|
68 |
+ if(opt_check(opt, "include-dir")) { |
|
69 | 69 |
included = 0; |
70 |
- argument = getfirstargl(opt, "include-dir", &optnode); |
|
70 |
+ argument = opt_firstarg(opt, "include-dir", &optnode); |
|
71 | 71 |
while(argument && !included) { |
72 | 72 |
if(match_regex(dirname, argument) == 1) { |
73 | 73 |
included = 1; |
74 | 74 |
break; |
75 | 75 |
} |
76 |
- argument = getnextargl(&optnode, "include"); |
|
76 |
+ argument = opt_nextarg(&optnode, "include"); |
|
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
if(!included) { |
... | ... |
@@ -83,8 +83,8 @@ int treewalk(const char *dirname, struct cl_node *root, const struct passwd *use |
83 | 83 |
} |
84 | 84 |
} |
85 | 85 |
|
86 |
- if(optl(opt, "max-dir-recursion")) |
|
87 |
- maxdepth = atoi(getargl(opt, "max-dir-recursion")); |
|
86 |
+ if(opt_check(opt, "max-dir-recursion")) |
|
87 |
+ maxdepth = atoi(opt_arg(opt, "max-dir-recursion")); |
|
88 | 88 |
else |
89 | 89 |
maxdepth = 15; |
90 | 90 |
|
... | ... |
@@ -30,10 +30,10 @@ freshclam_SOURCES = \ |
30 | 30 |
$(top_srcdir)/shared/memory.h \ |
31 | 31 |
$(top_srcdir)/shared/misc.c \ |
32 | 32 |
$(top_srcdir)/shared/misc.h \ |
33 |
+ $(top_srcdir)/shared/options.c \ |
|
34 |
+ $(top_srcdir)/shared/options.h \ |
|
33 | 35 |
freshclam.c \ |
34 | 36 |
freshclam.h \ |
35 |
- options.c \ |
|
36 |
- options.h \ |
|
37 | 37 |
manager.c \ |
38 | 38 |
manager.h \ |
39 | 39 |
defaults.h \ |
... | ... |
@@ -72,7 +72,7 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) |
72 | 72 |
PROGRAMS = $(bin_PROGRAMS) |
73 | 73 |
am_freshclam_OBJECTS = output.$(OBJEXT) cfgparser.$(OBJEXT) \ |
74 | 74 |
getopt.$(OBJEXT) memory.$(OBJEXT) misc.$(OBJEXT) \ |
75 |
- freshclam.$(OBJEXT) options.$(OBJEXT) manager.$(OBJEXT) \ |
|
75 |
+ options.$(OBJEXT) freshclam.$(OBJEXT) manager.$(OBJEXT) \ |
|
76 | 76 |
notify.$(OBJEXT) dns.$(OBJEXT) execute.$(OBJEXT) |
77 | 77 |
freshclam_OBJECTS = $(am_freshclam_OBJECTS) |
78 | 78 |
freshclam_LDADD = $(LDADD) |
... | ... |
@@ -211,10 +211,10 @@ freshclam_SOURCES = \ |
211 | 211 |
$(top_srcdir)/shared/memory.h \ |
212 | 212 |
$(top_srcdir)/shared/misc.c \ |
213 | 213 |
$(top_srcdir)/shared/misc.h \ |
214 |
+ $(top_srcdir)/shared/options.c \ |
|
215 |
+ $(top_srcdir)/shared/options.h \ |
|
214 | 216 |
freshclam.c \ |
215 | 217 |
freshclam.h \ |
216 |
- options.c \ |
|
217 |
- options.h \ |
|
218 | 218 |
manager.c \ |
219 | 219 |
manager.h \ |
220 | 220 |
defaults.h \ |
... | ... |
@@ -400,6 +400,20 @@ misc.obj: $(top_srcdir)/shared/misc.c |
400 | 400 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
401 | 401 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi` |
402 | 402 |
|
403 |
+options.o: $(top_srcdir)/shared/options.c |
|
404 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c; \ |
|
405 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
406 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@ |
|
407 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
408 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c |
|
409 |
+ |
|
410 |
+options.obj: $(top_srcdir)/shared/options.c |
|
411 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`; \ |
|
412 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
413 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@ |
|
414 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
415 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi` |
|
416 |
+ |
|
403 | 417 |
mostlyclean-libtool: |
404 | 418 |
-rm -f *.lo |
405 | 419 |
|
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -93,8 +93,7 @@ static void writepid(char *pidfile) { |
93 | 93 |
umask(old_umask); |
94 | 94 |
} |
95 | 95 |
|
96 |
- |
|
97 |
-int freshclam(struct optstruct *opt) |
|
96 |
+int main(int argc, char **argv) |
|
98 | 97 |
{ |
99 | 98 |
int ret = 52; |
100 | 99 |
char *newdir, *cfgfile; |
... | ... |
@@ -107,14 +106,48 @@ int freshclam(struct optstruct *opt) |
107 | 107 |
struct passwd *user; |
108 | 108 |
#endif |
109 | 109 |
struct stat statbuf; |
110 |
+ struct optstruct *opt; |
|
111 |
+ const char *short_options = "hvdp:Vl:c:u:a:"; |
|
112 |
+ static struct option long_options[] = { |
|
113 |
+ {"help", 0, 0, 'h'}, |
|
114 |
+ {"quiet", 0, 0, 0}, |
|
115 |
+ {"verbose", 0, 0, 'v'}, |
|
116 |
+ {"debug", 0, 0, 0}, |
|
117 |
+ {"version", 0, 0, 'V'}, |
|
118 |
+ {"datadir", 1, 0, 0}, |
|
119 |
+ {"log", 1, 0, 'l'}, |
|
120 |
+ {"log-verbose", 0, 0, 0}, /* not used */ |
|
121 |
+ {"stdout", 0, 0, 0}, |
|
122 |
+ {"daemon", 0, 0, 'd'}, |
|
123 |
+ {"pid", 1, 0, 'p'}, |
|
124 |
+ {"user", 1, 0, 'u'}, /* not used */ |
|
125 |
+ {"config-file", 1, 0, 0}, |
|
126 |
+ {"no-dns", 0, 0, 0}, |
|
127 |
+ {"checks", 1, 0, 'c'}, |
|
128 |
+ {"http-proxy", 1, 0, 0}, |
|
129 |
+ {"local-address", 1, 0, 'a'}, |
|
130 |
+ {"proxy-user", 1, 0, 0}, |
|
131 |
+ {"daemon-notify", 2, 0, 0}, |
|
132 |
+ {"on-update-execute", 1, 0, 0}, |
|
133 |
+ {"on-error-execute", 1, 0, 0}, |
|
134 |
+ {"on-outdated-execute", 1, 0, 0}, |
|
135 |
+ {0, 0, 0, 0} |
|
136 |
+ }; |
|
137 |
+ |
|
138 |
+ |
|
139 |
+ opt = opt_parse(argc, argv, short_options, long_options, NULL); |
|
140 |
+ if(!opt) { |
|
141 |
+ mprintf("!Can't parse the command line\n"); |
|
142 |
+ return 40; |
|
143 |
+ } |
|
110 | 144 |
|
111 |
- if(optc(opt, 'h')) { |
|
112 |
- free_opt(opt); |
|
145 |
+ if(opt_check(opt, "help")) { |
|
146 |
+ opt_free(opt); |
|
113 | 147 |
help(); |
114 | 148 |
} |
115 | 149 |
|
116 | 150 |
/* parse the config file */ |
117 |
- if((cfgfile = getargl(opt, "config-file"))) { |
|
151 |
+ if((cfgfile = opt_arg(opt, "config-file"))) { |
|
118 | 152 |
copt = getcfg(cfgfile, 1); |
119 | 153 |
} else { |
120 | 154 |
/* TODO: force strict permissions on freshclam.conf */ |
... | ... |
@@ -124,20 +157,23 @@ int freshclam(struct optstruct *opt) |
124 | 124 |
|
125 | 125 |
if(!copt) { |
126 | 126 |
logg("!Can't parse the config file %s\n", cfgfile); |
127 |
+ opt_free(opt); |
|
127 | 128 |
return 56; |
128 | 129 |
} |
129 | 130 |
|
130 |
- if(optl(opt, "http-proxy") || optl(opt, "proxy-user")) |
|
131 |
+ if(opt_check(opt, "http-proxy") || opt_check(opt, "proxy-user")) |
|
131 | 132 |
logg("WARNING: Proxy settings are now only configurable in the config file.\n"); |
132 | 133 |
|
133 | 134 |
if(cfgopt(copt, "HTTPProxyPassword")->enabled) { |
134 | 135 |
if(stat(cfgfile, &statbuf) == -1) { |
135 | 136 |
logg("^Can't stat %s (critical error)\n", cfgfile); |
137 |
+ opt_free(opt); |
|
136 | 138 |
return 56; |
137 | 139 |
} |
138 | 140 |
#ifndef C_CYGWIN |
139 | 141 |
if(statbuf.st_mode & (S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) { |
140 | 142 |
logg("^Insecure permissions (for HTTPProxyPassword): %s must have no more than 0700 permissions.\n", cfgfile); |
143 |
+ opt_free(opt); |
|
141 | 144 |
return 56; |
142 | 145 |
} |
143 | 146 |
#endif |
... | ... |
@@ -145,8 +181,8 @@ int freshclam(struct optstruct *opt) |
145 | 145 |
|
146 | 146 |
#if !defined(C_CYGWIN) && !defined(C_OS2) |
147 | 147 |
/* freshclam shouldn't work with root privileges */ |
148 |
- if(optc(opt, 'u')) { |
|
149 |
- unpuser = getargc(opt, 'u'); |
|
148 |
+ if(opt_check(opt, "user")) { |
|
149 |
+ unpuser = opt_arg(opt, "user"); |
|
150 | 150 |
} else if((cpt = cfgopt(copt, "DatabaseOwner"))->enabled) { |
151 | 151 |
unpuser = cpt->strarg; |
152 | 152 |
} else { |
... | ... |
@@ -189,19 +225,19 @@ int freshclam(struct optstruct *opt) |
189 | 189 |
|
190 | 190 |
/* initialize some important variables */ |
191 | 191 |
|
192 |
- if(optl(opt, "debug") || cfgopt(copt, "Debug")->enabled) |
|
192 |
+ if(opt_check(opt, "debug") || cfgopt(copt, "Debug")->enabled) |
|
193 | 193 |
cl_debug(); |
194 | 194 |
|
195 |
- if(optc(opt, 'v')) |
|
195 |
+ if(opt_check(opt, "verbose")) |
|
196 | 196 |
mprintf_verbose = 1; |
197 | 197 |
|
198 |
- if(optl(opt, "quiet")) |
|
198 |
+ if(opt_check(opt, "quiet")) |
|
199 | 199 |
mprintf_quiet = 1; |
200 | 200 |
|
201 |
- if(optl(opt, "stdout")) |
|
201 |
+ if(opt_check(opt, "stdout")) |
|
202 | 202 |
mprintf_stdout = 1; |
203 | 203 |
|
204 |
- if(optc(opt, 'V')) { |
|
204 |
+ if(opt_check(opt, "version")) { |
|
205 | 205 |
print_version(); |
206 | 206 |
exit(0); |
207 | 207 |
} |
... | ... |
@@ -211,8 +247,8 @@ int freshclam(struct optstruct *opt) |
211 | 211 |
if(cfgopt(copt, "LogVerbose")->enabled) |
212 | 212 |
logg_verbose = 1; |
213 | 213 |
|
214 |
- if(optc(opt, 'l')) { |
|
215 |
- logg_file = getargc(opt, 'l'); |
|
214 |
+ if(opt_check(opt, "log")) { |
|
215 |
+ logg_file = opt_arg(opt, "log"); |
|
216 | 216 |
if(logg("#--------------------------------------\n")) { |
217 | 217 |
mprintf("!Problem with internal logger.\n"); |
218 | 218 |
exit(62); |
... | ... |
@@ -243,8 +279,8 @@ int freshclam(struct optstruct *opt) |
243 | 243 |
#endif |
244 | 244 |
|
245 | 245 |
/* change the current working directory */ |
246 |
- if(optl(opt, "datadir")) |
|
247 |
- newdir = getargl(opt, "datadir"); |
|
246 |
+ if(opt_check(opt, "datadir")) |
|
247 |
+ newdir = opt_arg(opt, "datadir"); |
|
248 | 248 |
else |
249 | 249 |
newdir = cfgopt(copt, "DatabaseDirectory")->strarg; |
250 | 250 |
|
... | ... |
@@ -255,15 +291,15 @@ int freshclam(struct optstruct *opt) |
255 | 255 |
logg("*Current working dir is %s\n", newdir); |
256 | 256 |
|
257 | 257 |
|
258 |
- if(optc(opt, 'd')) { |
|
258 |
+ if(opt_check(opt, "daemon")) { |
|
259 | 259 |
int bigsleep, checks; |
260 | 260 |
time_t now, wakeup; |
261 | 261 |
|
262 | 262 |
memset(&sigact, 0, sizeof(struct sigaction)); |
263 | 263 |
sigact.sa_handler = daemon_sighandler; |
264 | 264 |
|
265 |
- if(optc(opt, 'c')) |
|
266 |
- checks = atoi(getargc(opt, 'c')); |
|
265 |
+ if(opt_check(opt, "checks")) |
|
266 |
+ checks = atoi(opt_arg(opt, "checks")); |
|
267 | 267 |
else |
268 | 268 |
checks = cfgopt(copt, "Checks")->numarg; |
269 | 269 |
|
... | ... |
@@ -272,7 +308,7 @@ int freshclam(struct optstruct *opt) |
272 | 272 |
exit(41); |
273 | 273 |
} |
274 | 274 |
|
275 |
- if(!cfgopt(copt, "DNSDatabaseInfo")->enabled || optl(opt, "no-dns")) { |
|
275 |
+ if(!cfgopt(copt, "DNSDatabaseInfo")->enabled || opt_check(opt, "no-dns")) { |
|
276 | 276 |
if(checks > 50) { |
277 | 277 |
logg("^Number of checks must be between 1 and 50.\n"); |
278 | 278 |
exit(41); |
... | ... |
@@ -286,8 +322,8 @@ int freshclam(struct optstruct *opt) |
286 | 286 |
daemonize(); |
287 | 287 |
} |
288 | 288 |
|
289 |
- if (optc(opt, 'p')) { |
|
290 |
- pidfile = getargc(opt, 'p'); |
|
289 |
+ if(opt_check(opt, "pid")) { |
|
290 |
+ pidfile = opt_arg(opt, "pid"); |
|
291 | 291 |
} else if ((cpt = cfgopt(copt, "PidFile"))->enabled) { |
292 | 292 |
pidfile = cpt->strarg; |
293 | 293 |
} |
... | ... |
@@ -310,8 +346,8 @@ int freshclam(struct optstruct *opt) |
310 | 310 |
if(ret > 1) { |
311 | 311 |
const char *arg = NULL; |
312 | 312 |
|
313 |
- if(optl(opt, "on-error-execute")) |
|
314 |
- arg = getargl(opt, "on-error-execute"); |
|
313 |
+ if(opt_check(opt, "on-error-execute")) |
|
314 |
+ arg = opt_arg(opt, "on-error-execute"); |
|
315 | 315 |
else if((cpt = cfgopt(copt, "OnErrorExecute"))->enabled) |
316 | 316 |
arg = cpt->strarg; |
317 | 317 |
|
... | ... |
@@ -346,9 +382,9 @@ int freshclam(struct optstruct *opt) |
346 | 346 |
} else |
347 | 347 |
ret = download(copt, opt); |
348 | 348 |
|
349 |
- if(optl(opt, "on-error-execute")) { |
|
349 |
+ if(opt_check(opt, "on-error-execute")) { |
|
350 | 350 |
if(ret > 1) |
351 |
- system(getargl(opt, "on-error-execute")); |
|
351 |
+ system(opt_arg(opt, "on-error-execute")); |
|
352 | 352 |
|
353 | 353 |
} else if((cpt = cfgopt(copt, "OnErrorExecute"))->enabled) { |
354 | 354 |
if(ret > 1) |
... | ... |
@@ -358,6 +394,7 @@ int freshclam(struct optstruct *opt) |
358 | 358 |
unlink(pidfile); |
359 | 359 |
} |
360 | 360 |
|
361 |
+ opt_free(opt); |
|
361 | 362 |
return(ret); |
362 | 363 |
} |
363 | 364 |
|
... | ... |
@@ -77,7 +77,7 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
77 | 77 |
#ifdef HAVE_RESOLV_H |
78 | 78 |
dnsdbinfo = cfgopt(copt, "DNSDatabaseInfo")->strarg; |
79 | 79 |
|
80 |
- if(optl(opt, "no-dns")) { |
|
80 |
+ if(opt_check(opt, "no-dns")) { |
|
81 | 81 |
dnsreply = NULL; |
82 | 82 |
} else { |
83 | 83 |
if((dnsreply = txtquery(dnsdbinfo, &ttl))) { |
... | ... |
@@ -139,8 +139,8 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
139 | 139 |
} |
140 | 140 |
#endif /* HAVE_RESOLV_H */ |
141 | 141 |
|
142 |
- if(optl(opt, "local-address")) { |
|
143 |
- localip = getargl(opt, "local-address"); |
|
142 |
+ if(opt_check(opt, "local-address")) { |
|
143 |
+ localip = opt_arg(opt, "local-address"); |
|
144 | 144 |
} else if((cpt = cfgopt(copt, "LocalIPAddress"))->enabled) { |
145 | 145 |
localip = cpt->strarg; |
146 | 146 |
} |
... | ... |
@@ -183,8 +183,8 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
183 | 183 |
} |
184 | 184 |
|
185 | 185 |
#ifdef BUILD_CLAMD |
186 |
- if(optl(opt, "daemon-notify")) { |
|
187 |
- const char *clamav_conf = getargl(opt, "daemon-notify"); |
|
186 |
+ if(opt_check(opt, "daemon-notify")) { |
|
187 |
+ const char *clamav_conf = opt_arg(opt, "daemon-notify"); |
|
188 | 188 |
if(!clamav_conf) |
189 | 189 |
clamav_conf = CONFDIR"/clamd.conf"; |
190 | 190 |
|
... | ... |
@@ -194,13 +194,13 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
194 | 194 |
} |
195 | 195 |
#endif |
196 | 196 |
|
197 |
- if(optl(opt, "on-update-execute")) |
|
198 |
- arg = getargl(opt, "on-update-execute"); |
|
197 |
+ if(opt_check(opt, "on-update-execute")) |
|
198 |
+ arg = opt_arg(opt, "on-update-execute"); |
|
199 | 199 |
else if((cpt = cfgopt(copt, "OnUpdateExecute"))->enabled) |
200 | 200 |
arg = cpt->strarg; |
201 | 201 |
|
202 | 202 |
if(arg) { |
203 |
- if(optc(opt, 'd')) |
|
203 |
+ if(opt_check(opt, "daemon")) |
|
204 | 204 |
execute("OnUpdateExecute", arg); |
205 | 205 |
else |
206 | 206 |
system(arg); |
... | ... |
@@ -208,8 +208,8 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
208 | 208 |
} |
209 | 209 |
|
210 | 210 |
if(outdated) { |
211 |
- if(optl(opt, "on-outdated-execute")) |
|
212 |
- arg = getargl(opt, "on-outdated-execute"); |
|
211 |
+ if(opt_check(opt, "on-outdated-execute")) |
|
212 |
+ arg = opt_arg(opt, "on-outdated-execute"); |
|
213 | 213 |
else if((cpt = cfgopt(copt, "OnOutdatedExecute"))->enabled) |
214 | 214 |
arg = cpt->strarg; |
215 | 215 |
|
... | ... |
@@ -227,7 +227,7 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
227 | 227 |
free(buffer); |
228 | 228 |
} |
229 | 229 |
|
230 |
- if(optc(opt, 'd')) |
|
230 |
+ if(opt_check(opt, "daemon")) |
|
231 | 231 |
execute("OnOutdatedExecute", cmd); |
232 | 232 |
else |
233 | 233 |
system(cmd); |
234 | 234 |
deleted file mode 100644 |
... | ... |
@@ -1,285 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2001-2002 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#include <stdio.h> |
|
21 |
-#include <stdlib.h> |
|
22 |
-#include <string.h> |
|
23 |
-#include <clamav.h> |
|
24 |
-#define _GNU_SOURCE |
|
25 |
-#include "getopt.h" |
|
26 |
- |
|
27 |
-#include "options.h" |
|
28 |
-#include "output.h" |
|
29 |
-#include "memory.h" |
|
30 |
- |
|
31 |
-int freshclam(struct optstruct *opt); |
|
32 |
- |
|
33 |
-static void register_char_opt(struct optstruct *opt, char ch, struct option* longopts); |
|
34 |
-static void register_long_opt(struct optstruct *opt, const char *optname, struct option* longopts); |
|
35 |
- |
|
36 |
-int main(int argc, char **argv) |
|
37 |
-{ |
|
38 |
- int ret, opt_index, i, len; |
|
39 |
- struct optstruct *opt; |
|
40 |
- |
|
41 |
- const char *getopt_parameters = "hvdp:Vl:c:u:a:"; |
|
42 |
- |
|
43 |
- static struct option long_options[] = { |
|
44 |
- /* |
|
45 |
- * WARNING: For compatibility reasons options marked as "not used" |
|
46 |
- * must still be accepted ! |
|
47 |
- */ |
|
48 |
- {"help", 0, 0, 'h'}, |
|
49 |
- {"quiet", 0, 0, 0}, |
|
50 |
- {"verbose", 0, 0, 'v'}, |
|
51 |
- {"debug", 0, 0, 0}, |
|
52 |
- {"version", 0, 0, 'V'}, |
|
53 |
- {"datadir", 1, 0, 0}, |
|
54 |
- {"log", 1, 0, 'l'}, |
|
55 |
- {"log-verbose", 0, 0, 0}, /* not used */ |
|
56 |
- {"stdout", 0, 0, 0}, |
|
57 |
- {"daemon", 0, 0, 'd'}, |
|
58 |
- {"pid", 1, 0, 'p'}, |
|
59 |
- {"user", 1, 0, 'u'}, /* not used */ |
|
60 |
- {"config-file", 1, 0, 0}, |
|
61 |
- {"no-dns", 0, 0, 0}, |
|
62 |
- {"checks", 1, 0, 'c'}, |
|
63 |
- {"http-proxy", 1, 0, 0}, |
|
64 |
- {"local-address", 1, 0, 'a'}, |
|
65 |
- {"proxy-user", 1, 0, 0}, |
|
66 |
- {"daemon-notify", 2, 0, 0}, |
|
67 |
- {"on-update-execute", 1, 0, 0}, |
|
68 |
- {"on-error-execute", 1, 0, 0}, |
|
69 |
- {"on-outdated-execute", 1, 0, 0}, |
|
70 |
- {0, 0, 0, 0} |
|
71 |
- }; |
|
72 |
- |
|
73 |
- |
|
74 |
- opt=(struct optstruct*)mcalloc(1, sizeof(struct optstruct)); |
|
75 |
- opt->optlist = NULL; |
|
76 |
- |
|
77 |
- while(1) { |
|
78 |
- |
|
79 |
- opt_index=0; |
|
80 |
- ret=getopt_long(argc, argv, getopt_parameters, long_options, &opt_index); |
|
81 |
- |
|
82 |
- if (ret == -1) |
|
83 |
- break; |
|
84 |
- |
|
85 |
- switch (ret) { |
|
86 |
- case 0: |
|
87 |
- register_long_opt(opt, long_options[opt_index].name, long_options); |
|
88 |
- break; |
|
89 |
- |
|
90 |
- default: |
|
91 |
- if(strchr(getopt_parameters, ret)) |
|
92 |
- register_char_opt(opt, ret, long_options); |
|
93 |
- else { |
|
94 |
- mprintf("!Unknown option passed.\n"); |
|
95 |
- free_opt(opt); |
|
96 |
- exit(40); |
|
97 |
- } |
|
98 |
- } |
|
99 |
- } |
|
100 |
- |
|
101 |
- if (optind < argc) { |
|
102 |
- |
|
103 |
- len=0; |
|
104 |
- |
|
105 |
- /* count length of non-option arguments */ |
|
106 |
- |
|
107 |
- for(i=optind; i<argc; i++) |
|
108 |
- len+=strlen(argv[i]); |
|
109 |
- |
|
110 |
- len=len+argc-optind-1; /* add spaces between arguments */ |
|
111 |
- opt->filename=(char*)mcalloc(len + 256, sizeof(char)); |
|
112 |
- |
|
113 |
- for(i=optind; i<argc; i++) { |
|
114 |
- strncat(opt->filename, argv[i], strlen(argv[i])); |
|
115 |
- if(i != argc-1) |
|
116 |
- strncat(opt->filename, " ", 1); |
|
117 |
- } |
|
118 |
- |
|
119 |
- } |
|
120 |
- |
|
121 |
- ret = freshclam(opt); |
|
122 |
- |
|
123 |
- free_opt(opt); |
|
124 |
- |
|
125 |
- return ret; |
|
126 |
-} |
|
127 |
- |
|
128 |
-static struct option* find_char_opt(char optchar, struct option* longopts) |
|
129 |
-{ |
|
130 |
- int i; |
|
131 |
- |
|
132 |
- for (i=0; longopts[i].name; i++) { |
|
133 |
- if ((char) longopts[i].val == optchar) { |
|
134 |
- return (&longopts[i]); |
|
135 |
- } |
|
136 |
- } |
|
137 |
- return NULL; |
|
138 |
-} |
|
139 |
- |
|
140 |
-static void register_char_opt(struct optstruct *opt, char ch, struct option* longopts) |
|
141 |
-{ |
|
142 |
- struct optnode *newnode; |
|
143 |
- struct option *longopt = find_char_opt(ch, longopts); |
|
144 |
- |
|
145 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
146 |
- |
|
147 |
- newnode->optchar = ch; |
|
148 |
- if(optarg != NULL) { |
|
149 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
150 |
- strcpy(newnode->optarg, optarg); |
|
151 |
- } else newnode->optarg = NULL; |
|
152 |
- |
|
153 |
- if (longopt) { |
|
154 |
- newnode->optname = strdup(longopt->name); |
|
155 |
- } else { |
|
156 |
- newnode->optname = NULL; |
|
157 |
- } |
|
158 |
- newnode->next = opt->optlist; |
|
159 |
- opt->optlist = newnode; |
|
160 |
-} |
|
161 |
- |
|
162 |
-static struct option* find_long_opt(const char *optname, struct option* longopts) |
|
163 |
-{ |
|
164 |
- int i; |
|
165 |
- |
|
166 |
- for (i=0; longopts[i].name; i++) { |
|
167 |
- if (strcmp(longopts[i].name, optname) == 0) { |
|
168 |
- return (&longopts[i]); |
|
169 |
- } |
|
170 |
- } |
|
171 |
- return NULL; |
|
172 |
-} |
|
173 |
- |
|
174 |
-static void register_long_opt(struct optstruct *opt, const char *optname, struct option* longopts) |
|
175 |
-{ |
|
176 |
- struct optnode *newnode; |
|
177 |
- struct option *longopt = find_long_opt(optname, longopts); |
|
178 |
- |
|
179 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
180 |
- if (longopt) { |
|
181 |
- newnode->optchar = longopt->val; |
|
182 |
- } else { |
|
183 |
- newnode->optchar = 0; |
|
184 |
- } |
|
185 |
- if(optarg != NULL) { |
|
186 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
187 |
- strcpy(newnode->optarg, optarg); |
|
188 |
- } else newnode->optarg = NULL; |
|
189 |
- |
|
190 |
- newnode->optname = (char *) mcalloc(strlen(optname) + 1, sizeof(char)); |
|
191 |
- strcpy(newnode->optname, optname); |
|
192 |
- newnode->next = opt->optlist; |
|
193 |
- opt->optlist = newnode; |
|
194 |
-} |
|
195 |
- |
|
196 |
-int optc(const struct optstruct *opt, char ch) |
|
197 |
-{ |
|
198 |
- struct optnode *handler; |
|
199 |
- |
|
200 |
- handler = opt->optlist; |
|
201 |
- |
|
202 |
- while(1) { |
|
203 |
- if(handler) { |
|
204 |
- if(handler->optchar == ch) return 1; |
|
205 |
- } else break; |
|
206 |
- handler = handler->next; |
|
207 |
- } |
|
208 |
- |
|
209 |
- return(0); |
|
210 |
-} |
|
211 |
- |
|
212 |
-int optl(const struct optstruct *opt, const char *optname) |
|
213 |
-{ |
|
214 |
- struct optnode *handler; |
|
215 |
- |
|
216 |
- handler = opt->optlist; |
|
217 |
- |
|
218 |
- while(1) { |
|
219 |
- if(handler) { |
|
220 |
- if(handler->optname) |
|
221 |
- if(!strcmp(handler->optname, optname)) return 1; |
|
222 |
- } else break; |
|
223 |
- handler = handler->next; |
|
224 |
- } |
|
225 |
- |
|
226 |
- return(0); |
|
227 |
-} |
|
228 |
- |
|
229 |
-char *getargc(const struct optstruct *opt, char ch) |
|
230 |
-{ |
|
231 |
- struct optnode *handler; |
|
232 |
- |
|
233 |
- handler = opt->optlist; |
|
234 |
- |
|
235 |
- while(1) { |
|
236 |
- if(handler) { |
|
237 |
- if(handler->optchar == ch) return handler->optarg; |
|
238 |
- } else break; |
|
239 |
- handler = handler->next; |
|
240 |
- } |
|
241 |
- |
|
242 |
- return(NULL); |
|
243 |
-} |
|
244 |
- |
|
245 |
-char *getargl(const struct optstruct *opt, const char *optname) |
|
246 |
-{ |
|
247 |
- struct optnode *handler; |
|
248 |
- |
|
249 |
- handler = opt->optlist; |
|
250 |
- |
|
251 |
- while(1) { |
|
252 |
- if(handler) { |
|
253 |
- if(handler->optname) |
|
254 |
- if(!strcmp(handler->optname, optname)) return handler->optarg; |
|
255 |
- } else break; |
|
256 |
- handler = handler->next; |
|
257 |
- } |
|
258 |
- |
|
259 |
- return(NULL); |
|
260 |
-} |
|
261 |
- |
|
262 |
-void free_opt(struct optstruct *opt) |
|
263 |
-{ |
|
264 |
- struct optnode *handler, *prev; |
|
265 |
- |
|
266 |
- if(!opt) |
|
267 |
- return; |
|
268 |
- |
|
269 |
- logg("*Freeing option list..."); |
|
270 |
- handler = opt->optlist; |
|
271 |
- |
|
272 |
- while(handler != NULL) { |
|
273 |
- handler->optchar = 0; |
|
274 |
- if(handler->optarg) free(handler->optarg); |
|
275 |
- if(handler->optname) free(handler->optname); |
|
276 |
- prev = handler; |
|
277 |
- handler = handler->next; |
|
278 |
- free(prev); |
|
279 |
- } |
|
280 |
- |
|
281 |
- if (opt->filename) |
|
282 |
- free(opt->filename); |
|
283 |
- free(opt); |
|
284 |
- logg("*done\n"); |
|
285 |
-} |
286 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,47 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#ifndef __OPTIONS_H |
|
21 |
-#define __OPTIONS_H |
|
22 |
- |
|
23 |
-struct optnode { |
|
24 |
- char optchar; |
|
25 |
- char *optarg; |
|
26 |
- char *optname; |
|
27 |
- struct optnode *next; |
|
28 |
-}; |
|
29 |
- |
|
30 |
-struct optstruct { |
|
31 |
- struct optnode *optlist; |
|
32 |
- char *filename; |
|
33 |
-}; |
|
34 |
- |
|
35 |
-int optc(const struct optstruct *opt, char ch); |
|
36 |
-int optl(const struct optstruct *opt, const char *optname); |
|
37 |
-void register_char_option(struct optstruct *opt, char ch); |
|
38 |
-void register_long_option(struct optstruct *opt, const char *optname); |
|
39 |
-char *getargc(const struct optstruct *opt, char ch); |
|
40 |
-char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode); |
|
41 |
-char *getnextargc(struct optnode **optnode, char ch); |
|
42 |
-char *getargl(const struct optstruct *opt, const char *optname); |
|
43 |
-char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode); |
|
44 |
-char *getnextargl(struct optnode **optnode, const char *optname); |
|
45 |
-void free_opt(struct optstruct *opt); |
|
46 |
- |
|
47 |
-#endif |
48 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,285 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2001 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * |
|
3 |
+ * This program is free software; you can redistribute it and/or modify |
|
4 |
+ * it under the terms of the GNU General Public License as published by |
|
5 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
6 |
+ * (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * This program is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+ * GNU General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU General Public License |
|
14 |
+ * along with this program; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
16 |
+ * MA 02110-1301, USA. |
|
17 |
+ * |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+#if HAVE_CONFIG_H |
|
21 |
+#include "clamav-config.h" |
|
22 |
+#endif |
|
23 |
+ |
|
24 |
+#include <stdio.h> |
|
25 |
+#include <stdlib.h> |
|
26 |
+#include <string.h> |
|
27 |
+#define _GNU_SOURCE |
|
28 |
+#include "getopt.h" |
|
29 |
+ |
|
30 |
+#include "options.h" |
|
31 |
+#include "memory.h" |
|
32 |
+#include "output.h" |
|
33 |
+ |
|
34 |
+ |
|
35 |
+static int register_option(struct optstruct *opt, const char *optlong, char optshort, const struct option *options_long, const char **accepted_long) |
|
36 |
+{ |
|
37 |
+ struct optnode *newnode; |
|
38 |
+ int i, found = 0; |
|
39 |
+ const char *longname = NULL; |
|
40 |
+ |
|
41 |
+ |
|
42 |
+ if(optshort) { |
|
43 |
+ for(i = 0; options_long[i].name; i++) { |
|
44 |
+ if(options_long[i].val == optshort) { |
|
45 |
+ longname = options_long[i].name; |
|
46 |
+ break; |
|
47 |
+ } |
|
48 |
+ } |
|
49 |
+ } else |
|
50 |
+ longname = optlong; |
|
51 |
+ |
|
52 |
+ if(!longname) { |
|
53 |
+ mprintf("!register_option: No long option for -%c\n", optshort); |
|
54 |
+ return -1; |
|
55 |
+ } |
|
56 |
+ |
|
57 |
+ if(accepted_long) { |
|
58 |
+ for(i = 0; accepted_long[i]; i++) |
|
59 |
+ if(!strcmp(accepted_long[i], longname)) |
|
60 |
+ found = 1; |
|
61 |
+ |
|
62 |
+ if(!found) { |
|
63 |
+ mprintf("WARNING: Ignoring option --%s\n", optlong); |
|
64 |
+ return 0; |
|
65 |
+ } |
|
66 |
+ } |
|
67 |
+ |
|
68 |
+ newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
69 |
+ if(!newnode) { |
|
70 |
+ mprintf("!register_long_option: mmalloc failed\n"); |
|
71 |
+ return -1; |
|
72 |
+ } |
|
73 |
+ |
|
74 |
+ newnode->optshort = optshort; |
|
75 |
+ |
|
76 |
+ if(optarg) { |
|
77 |
+ newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
78 |
+ if(!newnode->optarg) { |
|
79 |
+ mprintf("!register_long_option: mcalloc failed\n"); |
|
80 |
+ free(newnode); |
|
81 |
+ return -1; |
|
82 |
+ } |
|
83 |
+ strcpy(newnode->optarg, optarg); |
|
84 |
+ } else |
|
85 |
+ newnode->optarg = NULL; |
|
86 |
+ |
|
87 |
+ newnode->optlong = (char *) mcalloc(strlen(longname) + 1, sizeof(char)); |
|
88 |
+ if(!newnode->optlong) { |
|
89 |
+ mprintf("ERROR: register_long_option: mcalloc failed\n"); |
|
90 |
+ free(newnode->optarg); |
|
91 |
+ free(newnode); |
|
92 |
+ return -1; |
|
93 |
+ } |
|
94 |
+ strcpy(newnode->optlong, longname); |
|
95 |
+ |
|
96 |
+ newnode->next = opt->optlist; |
|
97 |
+ opt->optlist = newnode; |
|
98 |
+ return 0; |
|
99 |
+} |
|
100 |
+ |
|
101 |
+void opt_free(struct optstruct *opt) |
|
102 |
+{ |
|
103 |
+ struct optnode *handler, *prev; |
|
104 |
+ |
|
105 |
+ if(!opt) |
|
106 |
+ return; |
|
107 |
+ |
|
108 |
+ handler = opt->optlist; |
|
109 |
+ while(handler) { |
|
110 |
+ if(handler->optarg) |
|
111 |
+ free(handler->optarg); |
|
112 |
+ if(handler->optlong) |
|
113 |
+ free(handler->optlong); |
|
114 |
+ prev = handler; |
|
115 |
+ handler = handler->next; |
|
116 |
+ free(prev); |
|
117 |
+ } |
|
118 |
+ |
|
119 |
+ if(opt->filename) |
|
120 |
+ free(opt->filename); |
|
121 |
+ |
|
122 |
+ free(opt); |
|
123 |
+} |
|
124 |
+ |
|
125 |
+struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char **accepted_long) |
|
126 |
+{ |
|
127 |
+ int ret, opt_index, i, len; |
|
128 |
+ struct optstruct *opt; |
|
129 |
+ const char *longname; |
|
130 |
+ |
|
131 |
+ |
|
132 |
+ opt = (struct optstruct *) mcalloc(1, sizeof(struct optstruct)); |
|
133 |
+ if(!opt) { |
|
134 |
+ mprintf("!opt_parse: mcalloc failed\n"); |
|
135 |
+ return NULL; |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ while(1) { |
|
139 |
+ opt_index = 0; |
|
140 |
+ ret = getopt_long(argc, argv, getopt_short, options_long, &opt_index); |
|
141 |
+ |
|
142 |
+ if(ret == -1) |
|
143 |
+ break; |
|
144 |
+ |
|
145 |
+ switch(ret) { |
|
146 |
+ case 0: |
|
147 |
+ if(register_option(opt, options_long[opt_index].name, 0, options_long, accepted_long) == -1) { |
|
148 |
+ opt_free(opt); |
|
149 |
+ return NULL; |
|
150 |
+ } |
|
151 |
+ break; |
|
152 |
+ |
|
153 |
+ default: |
|
154 |
+ if(strchr(getopt_short, ret)) { |
|
155 |
+ if(opt_index) |
|
156 |
+ longname = options_long[opt_index].name; |
|
157 |
+ else |
|
158 |
+ longname = NULL; |
|
159 |
+ |
|
160 |
+ if(register_option(opt, options_long[opt_index].name, ret, options_long, accepted_long) == -1) { |
|
161 |
+ opt_free(opt); |
|
162 |
+ return NULL; |
|
163 |
+ } |
|
164 |
+ |
|
165 |
+ } else { |
|
166 |
+ mprintf("!Unknown option passed.\n"); |
|
167 |
+ opt_free(opt); |
|
168 |
+ return NULL; |
|
169 |
+ } |
|
170 |
+ } |
|
171 |
+ } |
|
172 |
+ |
|
173 |
+ if(optind < argc) { |
|
174 |
+ len = 0; |
|
175 |
+ |
|
176 |
+ /* count length of non-option arguments */ |
|
177 |
+ for(i = optind; i < argc; i++) |
|
178 |
+ len += strlen(argv[i]); |
|
179 |
+ |
|
180 |
+ len += argc - optind - 1; |
|
181 |
+ opt->filename = (char *) mcalloc(len + 64, sizeof(char)); |
|
182 |
+ if(!opt->filename) { |
|
183 |
+ mprintf("!opt_parse: mcalloc failed\n"); |
|
184 |
+ opt_free(opt); |
|
185 |
+ return NULL; |
|
186 |
+ } |
|
187 |
+ |
|
188 |
+ for(i = optind; i < argc; i++) { |
|
189 |
+ strncat(opt->filename, argv[i], strlen(argv[i])); |
|
190 |
+ if(i != argc - 1) |
|
191 |
+ strncat(opt->filename, "\t", 1); |
|
192 |
+ } |
|
193 |
+ } |
|
194 |
+ |
|
195 |
+ return opt; |
|
196 |
+} |
|
197 |
+ |
|
198 |
+int opt_check(const struct optstruct *opt, char *optlong) |
|
199 |
+{ |
|
200 |
+ struct optnode *handler; |
|
201 |
+ |
|
202 |
+ if(!opt) { |
|
203 |
+ mprintf("!opt_check: opt == NULL\n"); |
|
204 |
+ return 0; |
|
205 |
+ } |
|
206 |
+ |
|
207 |
+ handler = opt->optlist; |
|
208 |
+ |
|
209 |
+ while(handler) { |
|
210 |
+ if(handler->optlong && !strcmp(handler->optlong, optlong)) |
|
211 |
+ return 1; |
|
212 |
+ |
|
213 |
+ handler = handler->next; |
|
214 |
+ } |
|
215 |
+ |
|
216 |
+ return 0; |
|
217 |
+} |
|
218 |
+ |
|
219 |
+char *opt_arg(const struct optstruct *opt, char *optlong) |
|
220 |
+{ |
|
221 |
+ struct optnode *handler; |
|
222 |
+ |
|
223 |
+ if(!opt) { |
|
224 |
+ mprintf("!opt_arg: opt == NULL\n"); |
|
225 |
+ return 0; |
|
226 |
+ } |
|
227 |
+ |
|
228 |
+ handler = opt->optlist; |
|
229 |
+ |
|
230 |
+ while(handler) { |
|
231 |
+ if(handler->optlong && !strcmp(handler->optlong, optlong)) |
|
232 |
+ return handler->optarg; |
|
233 |
+ |
|
234 |
+ handler = handler->next; |
|
235 |
+ } |
|
236 |
+ |
|
237 |
+ return NULL; |
|
238 |
+} |
|
239 |
+ |
|
240 |
+char *opt_firstarg(const struct optstruct *opt, const char *optlong, const struct optnode **optnode) |
|
241 |
+{ |
|
242 |
+ struct optnode *handler; |
|
243 |
+ |
|
244 |
+ if(!opt) { |
|
245 |
+ mprintf("!opt_firstarg: opt == NULL\n"); |
|
246 |
+ return 0; |
|
247 |
+ } |
|
248 |
+ |
|
249 |
+ handler = opt->optlist; |
|
250 |
+ |
|
251 |
+ while(handler) { |
|
252 |
+ if(handler->optlong && !strcmp(handler->optlong, optlong)) { |
|
253 |
+ *optnode = handler; |
|
254 |
+ return handler->optarg; |
|
255 |
+ } |
|
256 |
+ handler = handler->next; |
|
257 |
+ } |
|
258 |
+ |
|
259 |
+ *optnode = NULL; |
|
260 |
+ return NULL; |
|
261 |
+} |
|
262 |
+ |
|
263 |
+char *opt_nextarg(const struct optnode **optnode, const char *optlong) |
|
264 |
+{ |
|
265 |
+ struct optnode *handler; |
|
266 |
+ |
|
267 |
+ if(!optnode || !*optnode) { |
|
268 |
+ mprintf("!opt_nextarg: *optnode == NULL\n"); |
|
269 |
+ return 0; |
|
270 |
+ } |
|
271 |
+ |
|
272 |
+ handler = (*optnode)->next; |
|
273 |
+ |
|
274 |
+ while(handler) { |
|
275 |
+ if(handler->optlong && !strcmp(handler->optlong, optlong)) { |
|
276 |
+ *optnode = handler; |
|
277 |
+ return handler->optarg; |
|
278 |
+ } |
|
279 |
+ handler = handler->next; |
|
280 |
+ } |
|
281 |
+ |
|
282 |
+ *optnode = NULL; |
|
283 |
+ return NULL; |
|
284 |
+} |
0 | 285 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,50 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * |
|
3 |
+ * This program is free software; you can redistribute it and/or modify |
|
4 |
+ * it under the terms of the GNU General Public License as published by |
|
5 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
6 |
+ * (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * This program is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+ * GNU General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU General Public License |
|
14 |
+ * along with this program; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
16 |
+ * MA 02110-1301, USA. |
|
17 |
+ */ |
|
18 |
+ |
|
19 |
+#ifndef __OPTIONS_H |
|
20 |
+#define __OPTIONS_H |
|
21 |
+ |
|
22 |
+#define _GNU_SOURCE |
|
23 |
+#include "getopt.h" |
|
24 |
+ |
|
25 |
+struct optnode { |
|
26 |
+ char optshort; |
|
27 |
+ char *optlong; |
|
28 |
+ char *optarg; |
|
29 |
+ struct optnode *next; |
|
30 |
+}; |
|
31 |
+ |
|
32 |
+struct optstruct { |
|
33 |
+ struct optnode *optlist; |
|
34 |
+ char *filename; |
|
35 |
+}; |
|
36 |
+ |
|
37 |
+void opt_free(struct optstruct *opt); |
|
38 |
+ |
|
39 |
+struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char **accepted_long); |
|
40 |
+ |
|
41 |
+int opt_check(const struct optstruct *opt, char *optlong); |
|
42 |
+ |
|
43 |
+char *opt_arg(const struct optstruct *opt, char *optlong); |
|
44 |
+ |
|
45 |
+char *opt_firstarg(const struct optstruct *opt, const char *optlong, const struct optnode **optnode); |
|
46 |
+ |
|
47 |
+char *opt_nextarg(const struct optnode **optnode, const char *optlong); |
|
48 |
+ |
|
49 |
+#endif |
... | ... |
@@ -70,15 +70,13 @@ pthread_mutex_t logg_mutex = PTHREAD_MUTEX_INITIALIZER; |
70 | 70 |
|
71 | 71 |
FILE *logg_fd = NULL; |
72 | 72 |
|
73 |
-short int logg_verbose = 0, logg_lock = 1, logg_time = 0; |
|
73 |
+short int logg_verbose = 0, logg_lock = 1, logg_time = 0, logg_foreground = 1; |
|
74 | 74 |
int logg_size = 0; |
75 | 75 |
const char *logg_file = NULL; |
76 | 76 |
#if defined(USE_SYSLOG) && !defined(C_AIX) |
77 | 77 |
short logg_syslog; |
78 | 78 |
#endif |
79 | 79 |
|
80 |
-short foreground; |
|
81 |
- |
|
82 | 80 |
short int mprintf_disabled = 0, mprintf_verbose = 0, mprintf_quiet = 0, |
83 | 81 |
mprintf_stdout = 0; |
84 | 82 |
|
... | ... |
@@ -228,7 +226,7 @@ int logg(const char *str, ...) |
228 | 228 |
} |
229 | 229 |
#endif |
230 | 230 |
|
231 |
- if(foreground) { |
|
231 |
+ if(logg_foreground) { |
|
232 | 232 |
_(str); |
233 | 233 |
vsnprintf(vbuff, 1024, str, argsout); |
234 | 234 |
vbuff[1024] = 0; |
... | ... |
@@ -29,8 +29,8 @@ sigtool_SOURCES = \ |
29 | 29 |
$(top_srcdir)/shared/cfgparser.h \ |
30 | 30 |
$(top_srcdir)/shared/misc.c \ |
31 | 31 |
$(top_srcdir)/shared/misc.h \ |
32 |
- options.c \ |
|
33 |
- options.h \ |
|
32 |
+ $(top_srcdir)/shared/options.c \ |
|
33 |
+ $(top_srcdir)/shared/options.h \ |
|
34 | 34 |
vba.c \ |
35 | 35 |
vba.h \ |
36 | 36 |
sigtool.c |
... | ... |
@@ -209,8 +209,8 @@ sigtool_SOURCES = \ |
209 | 209 |
$(top_srcdir)/shared/cfgparser.h \ |
210 | 210 |
$(top_srcdir)/shared/misc.c \ |
211 | 211 |
$(top_srcdir)/shared/misc.h \ |
212 |
- options.c \ |
|
213 |
- options.h \ |
|
212 |
+ $(top_srcdir)/shared/options.c \ |
|
213 |
+ $(top_srcdir)/shared/options.h \ |
|
214 | 214 |
vba.c \ |
215 | 215 |
vba.h \ |
216 | 216 |
sigtool.c |
... | ... |
@@ -388,6 +388,20 @@ misc.obj: $(top_srcdir)/shared/misc.c |
388 | 388 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
389 | 389 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi` |
390 | 390 |
|
391 |
+options.o: $(top_srcdir)/shared/options.c |
|
392 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c; \ |
|
393 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
394 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@ |
|
395 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
396 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c |
|
397 |
+ |
|
398 |
+options.obj: $(top_srcdir)/shared/options.c |
|
399 |
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF "$(DEPDIR)/options.Tpo" -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`; \ |
|
400 |
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/options.Tpo" "$(DEPDIR)/options.Po"; else rm -f "$(DEPDIR)/options.Tpo"; exit 1; fi |
|
401 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@ |
|
402 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
403 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi` |
|
404 |
+ |
|
391 | 405 |
mostlyclean-libtool: |
392 | 406 |
-rm -f *.lo |
393 | 407 |
|
394 | 408 |
deleted file mode 100644 |
... | ... |
@@ -1,250 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2001-2002 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- * |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#if HAVE_CONFIG_H |
|
22 |
-#include "clamav-config.h" |
|
23 |
-#endif |
|
24 |
- |
|
25 |
-#include <stdio.h> |
|
26 |
-#include <stdlib.h> |
|
27 |
-#include <string.h> |
|
28 |
-#include <clamav.h> |
|
29 |
-#define _GNU_SOURCE |
|
30 |
-#include "getopt.h" |
|
31 |
- |
|
32 |
-#include "options.h" |
|
33 |
-#include "memory.h" |
|
34 |
-#include "output.h" |
|
35 |
- |
|
36 |
-void sigtool(struct optstruct *opt); |
|
37 |
- |
|
38 |
-short foreground = 1; |
|
39 |
- |
|
40 |
-int main(int argc, char **argv) |
|
41 |
-{ |
|
42 |
- int ret, opt_index, i, len; |
|
43 |
- struct optstruct *opt; |
|
44 |
- |
|
45 |
- const char *getopt_parameters = "hvVb:i:u:l::"; |
|
46 |
- |
|
47 |
- static struct option long_options[] = { |
|
48 |
- {"help", 0, 0, 'h'}, |
|
49 |
- {"quiet", 0, 0, 0}, |
|
50 |
- {"debug", 0, 0, 0}, |
|
51 |
- {"verbose", 0, 0, 'v'}, |
|
52 |
- {"stdout", 0, 0, 0}, |
|
53 |
- {"version", 0, 0, 'V'}, |
|
54 |
- {"tempdir", 1, 0, 0}, |
|
55 |
- {"hex-dump", 0, 0, 0}, |
|
56 |
- {"md5", 0, 0, 0}, |
|
57 |
- {"html-normalise", 1, 0, 0}, |
|
58 |
- {"build", 1, 0, 'b'}, |
|
59 |
- {"server", 1, 0, 0}, |
|
60 |
- {"unpack", 1, 0, 'u'}, |
|
61 |
- {"unpack-current", 1, 0, 0}, |
|
62 |
- {"info", 1, 0, 'i'}, |
|
63 |
- {"list-sigs", 2, 0, 'l'}, |
|
64 |
- {"vba", 1, 0 ,0}, |
|
65 |
- {"vba-hex", 1, 0, 0}, |
|
66 |
- {0, 0, 0, 0} |
|
67 |
- }; |
|
68 |
- |
|
69 |
- |
|
70 |
- opt=(struct optstruct*) mcalloc(1, sizeof(struct optstruct)); |
|
71 |
- opt->optlist = NULL; |
|
72 |
- |
|
73 |
- |
|
74 |
- while(1) { |
|
75 |
- |
|
76 |
- opt_index=0; |
|
77 |
- ret=getopt_long(argc, argv, getopt_parameters, long_options, &opt_index); |
|
78 |
- |
|
79 |
- if (ret == -1) |
|
80 |
- break; |
|
81 |
- |
|
82 |
- switch (ret) { |
|
83 |
- case 0: |
|
84 |
- register_long_option(opt, long_options[opt_index].name); |
|
85 |
- break; |
|
86 |
- |
|
87 |
- default: |
|
88 |
- if(strchr(getopt_parameters, ret)) { |
|
89 |
- if(opt_index) |
|
90 |
- register_char_option(opt, ret, long_options[opt_index].name); |
|
91 |
- else |
|
92 |
- register_char_option(opt, ret, NULL); |
|
93 |
- |
|
94 |
- } else { |
|
95 |
- logg("!Unknown option passed.\n"); |
|
96 |
- free_opt(opt); |
|
97 |
- exit(40); |
|
98 |
- } |
|
99 |
- } |
|
100 |
- } |
|
101 |
- |
|
102 |
- if (optind < argc) { |
|
103 |
- |
|
104 |
- len=0; |
|
105 |
- |
|
106 |
- /* count length of non-option arguments */ |
|
107 |
- |
|
108 |
- for(i=optind; i<argc; i++) |
|
109 |
- len+=strlen(argv[i]); |
|
110 |
- |
|
111 |
- len=len+argc-optind-1; /* add spaces between arguments */ |
|
112 |
- opt->filename=(char*)mcalloc(len + 256, sizeof(char)); |
|
113 |
- |
|
114 |
- for(i=optind; i<argc; i++) { |
|
115 |
- strncat(opt->filename, argv[i], strlen(argv[i])); |
|
116 |
- if(i != argc-1) |
|
117 |
- strncat(opt->filename, "\t", 1); |
|
118 |
- } |
|
119 |
- |
|
120 |
- } |
|
121 |
- |
|
122 |
- sigtool(opt); |
|
123 |
- free_opt(opt); |
|
124 |
- |
|
125 |
- return 0; |
|
126 |
-} |
|
127 |
- |
|
128 |
-void register_char_option(struct optstruct *opt, char ch, const char *longname) |
|
129 |
-{ |
|
130 |
- struct optnode *newnode; |
|
131 |
- |
|
132 |
- |
|
133 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
134 |
- newnode->optchar = ch; |
|
135 |
- if(optarg != NULL) { |
|
136 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
137 |
- strcpy(newnode->optarg, optarg); |
|
138 |
- } else newnode->optarg = NULL; |
|
139 |
- |
|
140 |
- newnode->optname = NULL; |
|
141 |
- newnode->next = opt->optlist; |
|
142 |
- opt->optlist = newnode; |
|
143 |
-} |
|
144 |
- |
|
145 |
-void register_long_option(struct optstruct *opt, const char *optname) |
|
146 |
-{ |
|
147 |
- struct optnode *newnode; |
|
148 |
- |
|
149 |
- |
|
150 |
- newnode = (struct optnode *) mmalloc(sizeof(struct optnode)); |
|
151 |
- newnode->optchar = 0; |
|
152 |
- if(optarg != NULL) { |
|
153 |
- newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char)); |
|
154 |
- strcpy(newnode->optarg, optarg); |
|
155 |
- } else newnode->optarg = NULL; |
|
156 |
- |
|
157 |
- newnode->optname = (char *) mcalloc(strlen(optname) + 1, sizeof(char)); |
|
158 |
- strcpy(newnode->optname, optname); |
|
159 |
- newnode->next = opt->optlist; |
|
160 |
- opt->optlist = newnode; |
|
161 |
-} |
|
162 |
- |
|
163 |
-int optc(const struct optstruct *opt, char ch) |
|
164 |
-{ |
|
165 |
- struct optnode *handler; |
|
166 |
- |
|
167 |
- handler = opt->optlist; |
|
168 |
- |
|
169 |
- while(1) { |
|
170 |
- if(handler) { |
|
171 |
- if(handler->optchar == ch) return 1; |
|
172 |
- } else break; |
|
173 |
- handler = handler->next; |
|
174 |
- } |
|
175 |
- |
|
176 |
- return(0); |
|
177 |
-} |
|
178 |
- |
|
179 |
-int optl(const struct optstruct *opt, const char *optname) |
|
180 |
-{ |
|
181 |
- struct optnode *handler; |
|
182 |
- |
|
183 |
- handler = opt->optlist; |
|
184 |
- |
|
185 |
- while(1) { |
|
186 |
- if(handler) { |
|
187 |
- if(handler->optname) |
|
188 |
- if(!strcmp(handler->optname, optname)) return 1; |
|
189 |
- } else break; |
|
190 |
- handler = handler->next; |
|
191 |
- } |
|
192 |
- |
|
193 |
- return(0); |
|
194 |
-} |
|
195 |
- |
|
196 |
-char *getargc(const struct optstruct *opt, char ch) |
|
197 |
-{ |
|
198 |
- struct optnode *handler; |
|
199 |
- |
|
200 |
- handler = opt->optlist; |
|
201 |
- |
|
202 |
- while(1) { |
|
203 |
- if(handler) { |
|
204 |
- if(handler->optchar == ch) return handler->optarg; |
|
205 |
- } else break; |
|
206 |
- handler = handler->next; |
|
207 |
- } |
|
208 |
- |
|
209 |
- return(NULL); |
|
210 |
-} |
|
211 |
- |
|
212 |
-char *getargl(const struct optstruct *opt, const char *optname) |
|
213 |
-{ |
|
214 |
- struct optnode *handler; |
|
215 |
- |
|
216 |
- handler = opt->optlist; |
|
217 |
- |
|
218 |
- while(1) { |
|
219 |
- if(handler) { |
|
220 |
- if(handler->optname) |
|
221 |
- if(!strcmp(handler->optname, optname)) return handler->optarg; |
|
222 |
- } else break; |
|
223 |
- handler = handler->next; |
|
224 |
- } |
|
225 |
- |
|
226 |
- return(NULL); |
|
227 |
-} |
|
228 |
- |
|
229 |
-void free_opt(struct optstruct *opt) |
|
230 |
-{ |
|
231 |
- struct optnode *handler, *prev; |
|
232 |
- |
|
233 |
- if(!opt) |
|
234 |
- return; |
|
235 |
- |
|
236 |
- handler = opt->optlist; |
|
237 |
- |
|
238 |
- while(handler != NULL) { |
|
239 |
- handler->optchar = 0; |
|
240 |
- if(handler->optarg) free(handler->optarg); |
|
241 |
- if(handler->optname) free(handler->optname); |
|
242 |
- prev = handler; |
|
243 |
- handler = handler->next; |
|
244 |
- free(prev); |
|
245 |
- } |
|
246 |
- |
|
247 |
- if (opt->filename) |
|
248 |
- free(opt->filename); |
|
249 |
- free(opt); |
|
250 |
-} |
251 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,43 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002, 2003 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
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. |
|
8 |
- * |
|
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. |
|
13 |
- * |
|
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, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#ifndef __OPTIONS_H |
|
21 |
-#define __OPTIONS_H |
|
22 |
- |
|
23 |
-struct optnode { |
|
24 |
- char optchar; |
|
25 |
- char *optarg; |
|
26 |
- char *optname; |
|
27 |
- struct optnode *next; |
|
28 |
-}; |
|
29 |
- |
|
30 |
-struct optstruct { |
|
31 |
- struct optnode *optlist; |
|
32 |
- char *filename; |
|
33 |
-}; |
|
34 |
- |
|
35 |
-int optc(const struct optstruct *opt, char ch); |
|
36 |
-int optl(const struct optstruct *opt, const char *optname); |
|
37 |
-void register_char_option(struct optstruct *opt, char ch, const char *longname); |
|
38 |
-void register_long_option(struct optstruct *opt, const char *optname); |
|
39 |
-char *getargc(const struct optstruct *opt, char ch); |
|
40 |
-char *getargl(const struct optstruct *opt, const char *optname); |
|
41 |
-void free_opt(struct optstruct *opt); |
|
42 |
- |
|
43 |
-#endif |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
2 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -71,29 +71,60 @@ int listdir(const char *dirname); |
71 | 71 |
void listsigs(struct optstruct *opt); |
72 | 72 |
|
73 | 73 |
|
74 |
-void sigtool(struct optstruct *opt) |
|
74 |
+int main(int argc, char **argv) |
|
75 | 75 |
{ |
76 |
+ struct optstruct *opt; |
|
77 |
+ const char *short_options = "hvVb:i:u:l::"; |
|
78 |
+ static struct option long_options[] = { |
|
79 |
+ {"help", 0, 0, 'h'}, |
|
80 |
+ {"quiet", 0, 0, 0}, |
|
81 |
+ {"debug", 0, 0, 0}, |
|
82 |
+ {"verbose", 0, 0, 'v'}, |
|
83 |
+ {"stdout", 0, 0, 0}, |
|
84 |
+ {"version", 0, 0, 'V'}, |
|
85 |
+ {"tempdir", 1, 0, 0}, |
|
86 |
+ {"hex-dump", 0, 0, 0}, |
|
87 |
+ {"md5", 0, 0, 0}, |
|
88 |
+ {"html-normalise", 1, 0, 0}, |
|
89 |
+ {"build", 1, 0, 'b'}, |
|
90 |
+ {"server", 1, 0, 0}, |
|
91 |
+ {"unpack", 1, 0, 'u'}, |
|
92 |
+ {"unpack-current", 1, 0, 0}, |
|
93 |
+ {"info", 1, 0, 'i'}, |
|
94 |
+ {"list-sigs", 2, 0, 'l'}, |
|
95 |
+ {"vba", 1, 0 ,0}, |
|
96 |
+ {"vba-hex", 1, 0, 0}, |
|
97 |
+ {0, 0, 0, 0} |
|
98 |
+ }; |
|
99 |
+ |
|
100 |
+ |
|
101 |
+ opt = opt_parse(argc, argv, short_options, long_options, NULL); |
|
102 |
+ if(!opt) { |
|
103 |
+ mprintf("!Can't parse the command line\n"); |
|
104 |
+ return 1; |
|
105 |
+ } |
|
76 | 106 |
|
77 |
- if(optl(opt, "quiet")) |
|
107 |
+ if(opt_check(opt, "quiet")) |
|
78 | 108 |
mprintf_quiet = 1; |
79 | 109 |
|
80 |
- if(optl(opt, "stdout")) |
|
110 |
+ if(opt_check(opt, "stdout")) |
|
81 | 111 |
mprintf_stdout = 1; |
82 | 112 |
|
83 |
- if(optl(opt, "debug")) |
|
113 |
+ if(opt_check(opt, "debug")) |
|
84 | 114 |
cl_debug(); |
85 | 115 |
|
86 |
- if(optc(opt, 'V')) { |
|
116 |
+ if(opt_check(opt, "version")) { |
|
87 | 117 |
print_version(); |
118 |
+ opt_free(opt); |
|
88 | 119 |
exit(0); |
89 | 120 |
} |
90 | 121 |
|
91 |
- if(optc(opt, 'h')) { |
|
92 |
- free_opt(opt); |
|
122 |
+ if(opt_check(opt, "help")) { |
|
123 |
+ opt_free(opt); |
|
93 | 124 |
help(); |
94 | 125 |
} |
95 | 126 |
|
96 |
- if(optl(opt, "hex-dump")) { |
|
127 |
+ if(opt_check(opt, "hex-dump")) { |
|
97 | 128 |
char buffer[FILEBUFF]; |
98 | 129 |
int bytes; |
99 | 130 |
char *pt; |
... | ... |
@@ -104,7 +135,7 @@ void sigtool(struct optstruct *opt) |
104 | 104 |
free(pt); |
105 | 105 |
} |
106 | 106 |
|
107 |
- } else if(optl(opt, "md5")) { |
|
107 |
+ } else if(opt_check(opt, "md5")) { |
|
108 | 108 |
char *md5, *filename; |
109 | 109 |
int i; |
110 | 110 |
struct stat sb; |
... | ... |
@@ -137,11 +168,12 @@ void sigtool(struct optstruct *opt) |
137 | 137 |
free(md5); |
138 | 138 |
} |
139 | 139 |
|
140 |
- } else if(optl(opt, "html-normalise")) { |
|
140 |
+ } else if(opt_check(opt, "html-normalise")) { |
|
141 | 141 |
int fd; |
142 | 142 |
|
143 |
- if((fd = open(getargl(opt, "html-normalise"), O_RDONLY)) == -1) { |
|
144 |
- logg("Can't open file %s\n", getargl(opt, "html-normalise")); |
|
143 |
+ if((fd = open(opt_arg(opt, "html-normalise"), O_RDONLY)) == -1) { |
|
144 |
+ logg("Can't open file %s\n", opt_arg(opt, "html-normalise")); |
|
145 |
+ opt_free(opt); |
|
145 | 146 |
exit(1); |
146 | 147 |
} |
147 | 148 |
|
... | ... |
@@ -149,48 +181,52 @@ void sigtool(struct optstruct *opt) |
149 | 149 |
|
150 | 150 |
close(fd); |
151 | 151 |
|
152 |
- } else if(optc(opt, 'b')) { |
|
153 |
- if(!optl(opt, "server")) { |
|
152 |
+ } else if(opt_check(opt, "build")) { |
|
153 |
+ if(!opt_check(opt, "server")) { |
|
154 | 154 |
logg("!--server is required in this mode\n"); |
155 |
+ opt_free(opt); |
|
155 | 156 |
exit(10); |
156 | 157 |
} |
157 | 158 |
|
158 | 159 |
build(opt); |
159 | 160 |
|
160 |
- } else if(optc(opt, 'u')) { |
|
161 |
+ } else if(opt_check(opt, "unpack")) { |
|
161 | 162 |
|
162 | 163 |
unpack(opt); |
163 | 164 |
|
164 |
- } else if(optl(opt, "unpack-current")) { |
|
165 |
+ } else if(opt_check(opt, "unpack-current")) { |
|
165 | 166 |
|
166 | 167 |
unpack(opt); |
167 | 168 |
|
168 |
- } else if(optc(opt, 'i')) { |
|
169 |
+ } else if(opt_check(opt, "info")) { |
|
169 | 170 |
|
170 | 171 |
cvdinfo(opt); |
171 | 172 |
|
172 |
- } else if(optc(opt, 'l')) { |
|
173 |
+ } else if(opt_check(opt, "list-sigs")) { |
|
173 | 174 |
|
174 | 175 |
listsigs(opt); |
175 | 176 |
|
176 |
- } else if(optl(opt, "vba") || optl(opt, "vba-hex")) { |
|
177 |
+ } else if(opt_check(opt, "vba") || opt_check(opt, "vba-hex")) { |
|
177 | 178 |
int fd, hex_output=0; |
178 | 179 |
char *dir; |
179 | 180 |
|
180 | 181 |
|
181 |
- if (optl(opt, "vba-hex")) |
|
182 |
+ if (opt_check(opt, "vba-hex")) |
|
182 | 183 |
hex_output = 1; |
183 | 184 |
|
184 | 185 |
/* generate the temporary directory */ |
185 | 186 |
dir = cli_gentemp(NULL); |
186 | 187 |
if(mkdir(dir, 0700)) { |
187 | 188 |
logg("vba dump: Can't create temporary directory %s\n", dir); |
188 |
- return; |
|
189 |
+ free(dir); |
|
190 |
+ opt_free(opt); |
|
191 |
+ return 1; |
|
189 | 192 |
} |
190 | 193 |
|
191 |
- if((fd = open(getargl(opt, "vba"), O_RDONLY)) == -1) { |
|
192 |
- if((fd = open(getargl(opt, "vba-hex"), O_RDONLY)) == -1) { |
|
193 |
- logg("Can't open file %s\n", getargl(opt, "vba")); |
|
194 |
+ if((fd = open(opt_arg(opt, "vba"), O_RDONLY)) == -1) { |
|
195 |
+ if((fd = open(opt_arg(opt, "vba-hex"), O_RDONLY)) == -1) { |
|
196 |
+ logg("Can't open file %s\n", opt_arg(opt, "vba")); |
|
197 |
+ opt_free(opt); |
|
194 | 198 |
exit(1); |
195 | 199 |
} |
196 | 200 |
} |
... | ... |
@@ -199,7 +235,8 @@ void sigtool(struct optstruct *opt) |
199 | 199 |
cli_rmdirs(dir); |
200 | 200 |
free(dir); |
201 | 201 |
close(fd); |
202 |
- return; |
|
202 |
+ opt_free(opt); |
|
203 |
+ return 1; |
|
203 | 204 |
} |
204 | 205 |
|
205 | 206 |
close(fd); |
... | ... |
@@ -249,11 +286,13 @@ int build(struct optstruct *opt) |
249 | 249 |
|
250 | 250 |
if(stat("COPYING", &foo) == -1) { |
251 | 251 |
logg("COPYING file not found in current working directory.\n"); |
252 |
+ opt_free(opt); |
|
252 | 253 |
exit(1); |
253 | 254 |
} |
254 | 255 |
|
255 | 256 |
if(stat("main.db", &foo) == -1 && stat("daily.db", &foo) == -1 && stat("main.hdb", &foo) == -1 && stat("daily.hdb", &foo) == -1 && stat("main.ndb", &foo) == -1 && stat("daily.ndb", &foo) == -1 && stat("main.zmd", &foo) == -1 && stat("main.rmd", &foo) == -1 && stat("daily.zmd", &foo) == -1 && stat("daily.rmd", &foo) == -1) { |
256 | 257 |
logg("Virus database not found in current working directory.\n"); |
258 |
+ opt_free(opt); |
|
257 | 259 |
exit(1); |
258 | 260 |
} |
259 | 261 |
|
... | ... |
@@ -261,6 +300,7 @@ int build(struct optstruct *opt) |
261 | 261 |
|
262 | 262 |
if((ret = cl_loaddbdir(".", &root, &no))) { |
263 | 263 |
logg("!Can't load database: %s\n", cl_strerror(ret)); |
264 |
+ opt_free(opt); |
|
264 | 265 |
exit(1); |
265 | 266 |
} |
266 | 267 |
|
... | ... |
@@ -277,6 +317,7 @@ int build(struct optstruct *opt) |
277 | 277 |
logg("!Signatures in database: %d. Loaded: %d.\n", realno, no); |
278 | 278 |
logg("Please check the current directory and remove unnecessary databases\n"); |
279 | 279 |
logg("or install the latest ClamAV version.\n"); |
280 |
+ opt_free(opt); |
|
280 | 281 |
exit(1); |
281 | 282 |
} |
282 | 283 |
} |
... | ... |
@@ -286,6 +327,7 @@ int build(struct optstruct *opt) |
286 | 286 |
switch(fork()) { |
287 | 287 |
case -1: |
288 | 288 |
logg("!Can't fork.\n"); |
289 |
+ opt_free(opt); |
|
289 | 290 |
exit(1); |
290 | 291 |
case 0: |
291 | 292 |
{ |
... | ... |
@@ -294,6 +336,7 @@ int build(struct optstruct *opt) |
294 | 294 |
execv("/bin/tar", args); |
295 | 295 |
logg("!Can't execute tar\n"); |
296 | 296 |
perror("tar"); |
297 |
+ opt_free(opt); |
|
297 | 298 |
exit(1); |
298 | 299 |
} |
299 | 300 |
default: |
... | ... |
@@ -302,17 +345,20 @@ int build(struct optstruct *opt) |
302 | 302 |
|
303 | 303 |
if(stat(tarfile, &foo) == -1) { |
304 | 304 |
logg("!Can't generate tar file.\n"); |
305 |
+ opt_free(opt); |
|
305 | 306 |
exit(1); |
306 | 307 |
} |
307 | 308 |
|
308 | 309 |
if((tar = fopen(tarfile, "rb")) == NULL) { |
309 | 310 |
logg("!Can't open file %s\n", tarfile); |
311 |
+ opt_free(opt); |
|
310 | 312 |
exit(1); |
311 | 313 |
} |
312 | 314 |
|
313 | 315 |
gzfile = cli_gentemp("."); |
314 | 316 |
if((gz = gzopen(gzfile, "wb")) == NULL) { |
315 | 317 |
logg("!Can't open file %s to write.\n", gzfile); |
318 |
+ opt_free(opt); |
|
316 | 319 |
exit(1); |
317 | 320 |
} |
318 | 321 |
|
... | ... |
@@ -328,7 +374,7 @@ int build(struct optstruct *opt) |
328 | 328 |
|
329 | 329 |
/* try to read cvd header of old database */ |
330 | 330 |
dbdir = freshdbdir(); |
331 |
- sprintf(buffer, "%s/%s", dbdir, getargc(opt, 'b')); |
|
331 |
+ sprintf(buffer, "%s/%s", dbdir, opt_arg(opt, "build")); |
|
332 | 332 |
free(dbdir); |
333 | 333 |
if((oldcvd = cl_cvdhead(buffer)) == NULL) |
334 | 334 |
logg("^CAN'T READ CVD HEADER OF CURRENT DATABASE %s\n", buffer); |
... | ... |
@@ -385,9 +431,10 @@ int build(struct optstruct *opt) |
385 | 385 |
pt = cli_md5stream(fd, buffer); |
386 | 386 |
fclose(fd); |
387 | 387 |
free(pt); |
388 |
- if(!(pt = getdsig(getargl(opt, "server"), smbuff, buffer))) { |
|
388 |
+ if(!(pt = getdsig(opt_arg(opt, "server"), smbuff, buffer))) { |
|
389 | 389 |
logg("No digital signature - no CVD file...\n"); |
390 | 390 |
unlink(gzfile); |
391 |
+ opt_free(opt); |
|
391 | 392 |
exit(1); |
392 | 393 |
} |
393 | 394 |
|
... | ... |
@@ -408,10 +455,11 @@ int build(struct optstruct *opt) |
408 | 408 |
|
409 | 409 |
/* build the final database */ |
410 | 410 |
|
411 |
- pt = getargc(opt, 'b'); |
|
411 |
+ pt = opt_arg(opt, "build"); |
|
412 | 412 |
if((cvd = fopen(pt, "wb")) == NULL) { |
413 | 413 |
logg("!Can't write the final database %s\n", pt); |
414 | 414 |
unlink(gzfile); |
415 |
+ opt_free(opt); |
|
415 | 416 |
exit(1); |
416 | 417 |
} |
417 | 418 |
|
... | ... |
@@ -419,6 +467,7 @@ int build(struct optstruct *opt) |
419 | 419 |
|
420 | 420 |
if((tar = fopen(gzfile, "rb")) == NULL) { |
421 | 421 |
logg("!Can't open file %s for reading.\n", gzfile); |
422 |
+ opt_free(opt); |
|
422 | 423 |
exit(1); |
423 | 424 |
} |
424 | 425 |
|
... | ... |
@@ -443,9 +492,10 @@ void cvdinfo(struct optstruct *opt) |
443 | 443 |
char *pt; |
444 | 444 |
int ret; |
445 | 445 |
|
446 |
- pt = getargc(opt, 'i'); |
|
446 |
+ pt = opt_arg(opt, "info"); |
|
447 | 447 |
if((cvd = cl_cvdhead(pt)) == NULL) { |
448 | 448 |
logg("!Can't read/parse CVD header from %s\n", pt); |
449 |
+ opt_free(opt); |
|
449 | 450 |
exit(1); |
450 | 451 |
} |
451 | 452 |
|
... | ... |
@@ -541,17 +591,18 @@ int unpack(struct optstruct *opt) |
541 | 541 |
int fd; |
542 | 542 |
char *name, *dbdir; |
543 | 543 |
|
544 |
- if(optl(opt, "unpack-current")) { |
|
544 |
+ if(opt_check(opt, "unpack-current")) { |
|
545 | 545 |
dbdir = freshdbdir(); |
546 |
- name = mcalloc(strlen(dbdir) + strlen(getargl(opt, "unpack-current")) + 2, sizeof(char)); |
|
547 |
- sprintf(name, "%s/%s", dbdir, getargl(opt, "unpack-current")); |
|
546 |
+ name = mcalloc(strlen(dbdir) + strlen(opt_arg(opt, "unpack-current")) + 2, sizeof(char)); |
|
547 |
+ sprintf(name, "%s/%s", dbdir, opt_arg(opt, "unpack-current")); |
|
548 | 548 |
free(dbdir); |
549 | 549 |
} else |
550 |
- name = strdup(getargc(opt, 'u')); |
|
550 |
+ name = strdup(opt_arg(opt, "unpack")); |
|
551 | 551 |
|
552 | 552 |
if((fd = open(name, O_RDONLY|O_BINARY)) == -1) { |
553 | 553 |
logg("!Can't open CVD file %s\n", name); |
554 | 554 |
free(name); |
555 |
+ opt_free(opt); |
|
555 | 556 |
exit(1); |
556 | 557 |
} |
557 | 558 |
|
... | ... |
@@ -561,10 +612,12 @@ int unpack(struct optstruct *opt) |
561 | 561 |
if(cli_untgz(fd, ".")) { |
562 | 562 |
logg("!Can't unpack file.\n"); |
563 | 563 |
close(fd); |
564 |
+ opt_free(opt); |
|
564 | 565 |
exit(1); |
565 | 566 |
} |
566 | 567 |
|
567 | 568 |
close(fd); |
569 |
+ opt_free(opt); |
|
568 | 570 |
exit(0); |
569 | 571 |
} |
570 | 572 |
|
... | ... |
@@ -791,7 +844,7 @@ void listsigs(struct optstruct *opt) |
791 | 791 |
|
792 | 792 |
mprintf_stdout = 1; |
793 | 793 |
|
794 |
- if((name = getargc(opt, 'l'))) { |
|
794 |
+ if((name = opt_arg(opt, "list-sigs"))) { |
|
795 | 795 |
ret = listdb(name); |
796 | 796 |
} else { |
797 | 797 |
dbdir = freshdbdir(); |
... | ... |
@@ -799,6 +852,7 @@ void listsigs(struct optstruct *opt) |
799 | 799 |
free(dbdir); |
800 | 800 |
} |
801 | 801 |
|
802 |
+ opt_free(opt); |
|
802 | 803 |
ret ? exit(1) : exit(0); |
803 | 804 |
} |
804 | 805 |
|