... | ... |
@@ -1,5 +1,11 @@ |
1 | 1 |
bin_PROGRAMS = clambc |
2 | 2 |
clambc_SOURCES = \ |
3 |
+ $(top_srcdir)/shared/optparser.c \ |
|
4 |
+ $(top_srcdir)/shared/optparser.h \ |
|
5 |
+ $(top_srcdir)/shared/getopt.c \ |
|
6 |
+ $(top_srcdir)/shared/getopt.h \ |
|
7 |
+ $(top_srcdir)/shared/misc.c \ |
|
8 |
+ $(top_srcdir)/shared/misc.h \ |
|
3 | 9 |
bcrun.c |
4 | 10 |
|
5 | 11 |
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav |
... | ... |
@@ -54,7 +54,8 @@ CONFIG_CLEAN_FILES = |
54 | 54 |
am__installdirs = "$(DESTDIR)$(bindir)" |
55 | 55 |
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) |
56 | 56 |
PROGRAMS = $(bin_PROGRAMS) |
57 |
-am_clambc_OBJECTS = bcrun.$(OBJEXT) |
|
57 |
+am_clambc_OBJECTS = optparser.$(OBJEXT) getopt.$(OBJEXT) \ |
|
58 |
+ misc.$(OBJEXT) bcrun.$(OBJEXT) |
|
58 | 59 |
clambc_OBJECTS = $(am_clambc_OBJECTS) |
59 | 60 |
clambc_LDADD = $(LDADD) |
60 | 61 |
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) |
... | ... |
@@ -230,6 +231,12 @@ top_build_prefix = @top_build_prefix@ |
230 | 230 |
top_builddir = @top_builddir@ |
231 | 231 |
top_srcdir = @top_srcdir@ |
232 | 232 |
clambc_SOURCES = \ |
233 |
+ $(top_srcdir)/shared/optparser.c \ |
|
234 |
+ $(top_srcdir)/shared/optparser.h \ |
|
235 |
+ $(top_srcdir)/shared/getopt.c \ |
|
236 |
+ $(top_srcdir)/shared/getopt.h \ |
|
237 |
+ $(top_srcdir)/shared/misc.c \ |
|
238 |
+ $(top_srcdir)/shared/misc.h \ |
|
233 | 239 |
bcrun.c |
234 | 240 |
|
235 | 241 |
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav |
... | ... |
@@ -322,6 +329,9 @@ distclean-compile: |
322 | 322 |
-rm -f *.tab.c |
323 | 323 |
|
324 | 324 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bcrun.Po@am__quote@ |
325 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ |
|
326 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@ |
|
327 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/optparser.Po@am__quote@ |
|
325 | 328 |
|
326 | 329 |
.c.o: |
327 | 330 |
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |
... | ... |
@@ -344,6 +354,48 @@ distclean-compile: |
344 | 344 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
345 | 345 |
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< |
346 | 346 |
|
347 |
+optparser.o: $(top_srcdir)/shared/optparser.c |
|
348 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT optparser.o -MD -MP -MF $(DEPDIR)/optparser.Tpo -c -o optparser.o `test -f '$(top_srcdir)/shared/optparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/optparser.c |
|
349 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po |
|
350 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/optparser.c' object='optparser.o' libtool=no @AMDEPBACKSLASH@ |
|
351 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
352 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o optparser.o `test -f '$(top_srcdir)/shared/optparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/optparser.c |
|
353 |
+ |
|
354 |
+optparser.obj: $(top_srcdir)/shared/optparser.c |
|
355 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT optparser.obj -MD -MP -MF $(DEPDIR)/optparser.Tpo -c -o optparser.obj `if test -f '$(top_srcdir)/shared/optparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/optparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/optparser.c'; fi` |
|
356 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po |
|
357 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/optparser.c' object='optparser.obj' libtool=no @AMDEPBACKSLASH@ |
|
358 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
359 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o optparser.obj `if test -f '$(top_srcdir)/shared/optparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/optparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/optparser.c'; fi` |
|
360 |
+ |
|
361 |
+getopt.o: $(top_srcdir)/shared/getopt.c |
|
362 |
+@am__fastdepCC_TRUE@ $(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 |
|
363 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/getopt.Tpo $(DEPDIR)/getopt.Po |
|
364 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@ |
|
365 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
366 |
+@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 |
|
367 |
+ |
|
368 |
+getopt.obj: $(top_srcdir)/shared/getopt.c |
|
369 |
+@am__fastdepCC_TRUE@ $(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` |
|
370 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/getopt.Tpo $(DEPDIR)/getopt.Po |
|
371 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@ |
|
372 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
373 |
+@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` |
|
374 |
+ |
|
375 |
+misc.o: $(top_srcdir)/shared/misc.c |
|
376 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT misc.o -MD -MP -MF $(DEPDIR)/misc.Tpo -c -o misc.o `test -f '$(top_srcdir)/shared/misc.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/misc.c |
|
377 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/misc.Tpo $(DEPDIR)/misc.Po |
|
378 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/misc.c' object='misc.o' libtool=no @AMDEPBACKSLASH@ |
|
379 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
380 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.o `test -f '$(top_srcdir)/shared/misc.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/misc.c |
|
381 |
+ |
|
382 |
+misc.obj: $(top_srcdir)/shared/misc.c |
|
383 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT misc.obj -MD -MP -MF $(DEPDIR)/misc.Tpo -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` |
|
384 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/misc.Tpo $(DEPDIR)/misc.Po |
|
385 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/misc.c' object='misc.obj' libtool=no @AMDEPBACKSLASH@ |
|
386 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
387 |
+@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` |
|
388 |
+ |
|
347 | 389 |
mostlyclean-libtool: |
348 | 390 |
-rm -f *.lo |
349 | 391 |
|
... | ... |
@@ -24,21 +24,47 @@ |
24 | 24 |
#endif |
25 | 25 |
#include "bytecode.h" |
26 | 26 |
#include "clamav.h" |
27 |
+#include "shared/optparser.h" |
|
27 | 28 |
|
28 | 29 |
#include <stdlib.h> |
29 | 30 |
|
31 |
+static void help(void) |
|
32 |
+{ |
|
33 |
+ printf("\n"); |
|
34 |
+ printf(" Clam AntiVirus: Bytecode Test Tool %s\n", get_version()); |
|
35 |
+ printf(" By The ClamAV Team: http://www.clamav.net/team\n"); |
|
36 |
+ printf(" (C) 2009 Sourcefire, Inc.\n\n"); |
|
37 |
+ printf("clambc <file>\n\n"); |
|
38 |
+ printf(" --help -h Show help\n"); |
|
39 |
+ printf(" --version -V Show version\n"); |
|
40 |
+ printf(" file file to test\n"); |
|
41 |
+ printf("\n"); |
|
42 |
+ return; |
|
43 |
+} |
|
44 |
+ |
|
30 | 45 |
int main(int argc, char *argv[]) |
31 | 46 |
{ |
32 | 47 |
FILE *f; |
33 | 48 |
struct cli_bc *bc; |
34 | 49 |
struct cli_bc_ctx *ctx; |
35 | 50 |
int rc; |
36 |
- /* TODO: use optparser */ |
|
37 |
- if (argc != 2) { |
|
38 |
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]); |
|
51 |
+ struct optstruct *opts; |
|
52 |
+ |
|
53 |
+ opts = optparse(NULL, argc, argv, 1, OPT_CLAMBC, 0, NULL); |
|
54 |
+ if (!opts) { |
|
55 |
+ fprintf(stderr, "ERROR: Can't parse command line options\n"); |
|
39 | 56 |
exit(1); |
40 | 57 |
} |
41 |
- |
|
58 |
+ if(optget(opts, "help")->enabled) { |
|
59 |
+ optfree(opts); |
|
60 |
+ help(); |
|
61 |
+ exit(0); |
|
62 |
+ } |
|
63 |
+ if(optget(opts, "version")->enabled) { |
|
64 |
+ printf("Clam AntiVirus Monitoring Tool %s\n", get_version()); |
|
65 |
+ optfree(opts); |
|
66 |
+ exit(0); |
|
67 |
+ } |
|
42 | 68 |
f = fopen(argv[1], "r"); |
43 | 69 |
if (!f) { |
44 | 70 |
fprintf(stderr, "Unable to load %s\n", argv[1]); |
... | ... |
@@ -62,11 +62,11 @@ const struct clam_option clam_options[] = { |
62 | 62 |
/* name, longopt, sopt, argtype, regex, num, str, flags, owner, description, suggested */ |
63 | 63 |
|
64 | 64 |
/* cmdline only */ |
65 |
- { NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP, "", "" }, |
|
65 |
+ { NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP | OPT_CLAMBC, "", "" }, |
|
66 | 66 |
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" }, |
67 | 67 |
{ NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR"/freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" }, |
68 | 68 |
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamav-milter.conf", FLAG_REQUIRED, OPT_MILTER, "", "" }, |
69 |
- { NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP, "", "" }, |
|
69 |
+ { NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP | OPT_CLAMBC, "", "" }, |
|
70 | 70 |
{ NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" }, |
71 | 71 |
{ NULL, "verbose", 'v', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" }, |
72 | 72 |
{ NULL, "quiet", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" }, |
... | ... |
@@ -30,7 +30,8 @@ |
30 | 30 |
#define OPT_SIGTOOL 32 |
31 | 31 |
#define OPT_CLAMCONF 64 |
32 | 32 |
#define OPT_CLAMDTOP 128 |
33 |
-#define OPT_DEPRECATED 256 |
|
33 |
+#define OPT_CLAMBC 256 |
|
34 |
+#define OPT_DEPRECATED 512 |
|
34 | 35 |
|
35 | 36 |
#define TYPE_STRING 1 /* quoted/regular string */ |
36 | 37 |
#define TYPE_NUMBER 2 /* raw number */ |