shared/optparser.c, sigtool: use the new option parser (bb#1215)

git-svn: trunk@4587
0.95
Tomasz Kojm 17 years ago
parent 62f3e4e421
commit d6af38e75e
  1. 4
      ChangeLog
  2. 38
      shared/optparser.c
  3. 3
      shared/optparser.h
  4. 8
      sigtool/Makefile.am
  5. 50
      sigtool/Makefile.in
  6. 234
      sigtool/sigtool.c

@ -1,3 +1,7 @@
Fri Jan 2 13:08:09 CET 2009 (tk)
---------------------------------
* shared/optparser.c, sigtool: use the new option parser (bb#1215)
Thu Jan 1 22:56:40 EET 2009 (edwin)
------------------------------------
* Makefile.am, Makefile.in: add -Wformat-security to 'make

@ -75,16 +75,16 @@ static const struct clam_option {
/* name, longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
/* cmdline only */
{ NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
{ NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN, "", "" },
{ NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR"/freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
{ NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
{ NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN, "", "" },
{ NULL, "verbose", 'v', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
{ NULL, "quiet", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
{ NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
{ NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" },
{ NULL, "verbose", 'v', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
{ NULL, "quiet", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
{ NULL, "leave-temps", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
{ NULL, "no-warnings", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
{ NULL, "stdout", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
{ NULL, "stdout", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
{ NULL, "daemon", 'd', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
{ NULL, "no-dns", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
{ NULL, "list-mirrors", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
@ -105,6 +105,22 @@ static const struct clam_option {
{ NULL, "include", 0, TYPE_STRING, NULL, -1, NULL, FLAG_MULTIPLE, OPT_CLAMSCAN, "", "" },
{ NULL, "include-dir", 0, TYPE_STRING, NULL, -1, NULL, FLAG_MULTIPLE, OPT_CLAMSCAN, "", "" },
{ NULL, "structured-ssn-format", 0, TYPE_NUMBER, MATCH_NUMBER, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
{ NULL, "hex-dump", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "md5", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "mdb", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "html-normalise", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "utf16-decode", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "build", 'b', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "server", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "unpack", 'u', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "unpack-current", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "info", 'i', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "list-sigs", 'l', TYPE_STRING, NULL, -1, DATADIR, 0, OPT_SIGTOOL, "", "" },
{ NULL, "vba", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "vba-hex", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "diff", 'd', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "run-cdiff", 'r', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
{ NULL, "verify-cdiff", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
/* cmdline only - deprecated */
{ NULL, "http-proxy", 0, TYPE_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
@ -155,7 +171,7 @@ static const struct clam_option {
{ "PidFile", "pid", 'p', TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Save the process ID to a file.", "/var/run/clamd.pid" },
{ "TemporaryDirectory", "tempdir", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN, "This option allows you to change the default temporary directory.", "/tmp" },
{ "TemporaryDirectory", "tempdir", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN | OPT_SIGTOOL, "This option allows you to change the default temporary directory.", "/tmp" },
{ "DatabaseDirectory", "datadir", 0, TYPE_STRING, NULL, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM, "This option allows you to change the default database directory.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/var/lib/clamav" },
@ -627,16 +643,14 @@ struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, in
longopts[lc++].val = optentry->shortopt;
}
if(optentry->shortopt) {
if(sc + 1 >= MAXCMDOPTS) {
if(sc + 2 >= MAXCMDOPTS) {
fprintf(stderr, "ERROR: optparse: shortopts[] is too small\n");
optfree(opts);
return NULL;
}
shortopts[sc++] = optentry->shortopt;
/* FIXME: we may need to handle optional args for short
* BOOL opts
*/
if(optentry->argtype != TYPE_BOOL)
shortopts[sc++] = ':';
if(!(optentry->flags & FLAG_REQUIRED) && (optentry->argtype == TYPE_BOOL || optentry->strarg))
shortopts[sc++] = ':';
}
}

@ -27,7 +27,8 @@
#define OPT_MILTER 4
#define OPT_CLAMSCAN 8
#define OPT_CLAMDSCAN 16
#define OPT_DEPRECATED 32
#define OPT_SIGTOOL 32
#define OPT_DEPRECATED 64
struct optstruct {
char *name;

@ -23,12 +23,10 @@ sigtool_SOURCES = \
$(top_srcdir)/shared/output.h \
$(top_srcdir)/shared/getopt.c \
$(top_srcdir)/shared/getopt.h \
$(top_srcdir)/shared/cfgparser.c \
$(top_srcdir)/shared/cfgparser.h \
$(top_srcdir)/shared/optparser.c \
$(top_srcdir)/shared/optparser.h \
$(top_srcdir)/shared/misc.c \
$(top_srcdir)/shared/misc.h \
$(top_srcdir)/shared/options.c \
$(top_srcdir)/shared/options.h \
$(top_srcdir)/shared/sha256.c \
$(top_srcdir)/shared/cdiff.c \
$(top_srcdir)/shared/cdiff.h \
@ -38,8 +36,6 @@ sigtool_SOURCES = \
vba.h \
sigtool.c
#sigtool_LDADD = $(top_builddir)/clamscan/others.o
DEFS = @DEFS@ -DCL_NOTHREADS
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
LIBS = $(top_builddir)/libclamav/libclamav.la @FRESHCLAM_LIBS@ @THREAD_LIBS@

@ -72,9 +72,8 @@ am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_sigtool_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) \
cfgparser.$(OBJEXT) misc.$(OBJEXT) options.$(OBJEXT) \
sha256.$(OBJEXT) cdiff.$(OBJEXT) tar.$(OBJEXT) vba.$(OBJEXT) \
sigtool.$(OBJEXT)
optparser.$(OBJEXT) misc.$(OBJEXT) sha256.$(OBJEXT) \
cdiff.$(OBJEXT) tar.$(OBJEXT) vba.$(OBJEXT) sigtool.$(OBJEXT)
sigtool_OBJECTS = $(am_sigtool_OBJECTS)
sigtool_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@ -116,8 +115,6 @@ CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DBDIR = @DBDIR@
#sigtool_LDADD = $(top_builddir)/clamscan/others.o
DEFS = @DEFS@ -DCL_NOTHREADS
DEPDIR = @DEPDIR@
DSYMUTIL = @DSYMUTIL@
@ -257,12 +254,10 @@ sigtool_SOURCES = \
$(top_srcdir)/shared/output.h \
$(top_srcdir)/shared/getopt.c \
$(top_srcdir)/shared/getopt.h \
$(top_srcdir)/shared/cfgparser.c \
$(top_srcdir)/shared/cfgparser.h \
$(top_srcdir)/shared/optparser.c \
$(top_srcdir)/shared/optparser.h \
$(top_srcdir)/shared/misc.c \
$(top_srcdir)/shared/misc.h \
$(top_srcdir)/shared/options.c \
$(top_srcdir)/shared/options.h \
$(top_srcdir)/shared/sha256.c \
$(top_srcdir)/shared/cdiff.c \
$(top_srcdir)/shared/cdiff.h \
@ -362,10 +357,9 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdiff.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/optparser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha256.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigtool.Po@am__quote@
@ -421,19 +415,19 @@ getopt.obj: $(top_srcdir)/shared/getopt.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@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`
cfgparser.o: $(top_srcdir)/shared/cfgparser.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cfgparser.o -MD -MP -MF $(DEPDIR)/cfgparser.Tpo -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@
optparser.o: $(top_srcdir)/shared/optparser.c
@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
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/optparser.c' object='optparser.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
@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
cfgparser.obj: $(top_srcdir)/shared/cfgparser.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cfgparser.obj -MD -MP -MF $(DEPDIR)/cfgparser.Tpo -c -o cfgparser.obj `if test -f '$(top_srcdir)/shared/cfgparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/cfgparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/cfgparser.c'; fi`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@
optparser.obj: $(top_srcdir)/shared/optparser.c
@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`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/optparser.c' object='optparser.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `if test -f '$(top_srcdir)/shared/cfgparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/cfgparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/cfgparser.c'; fi`
@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`
misc.o: $(top_srcdir)/shared/misc.c
@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
@ -449,20 +443,6 @@ misc.obj: $(top_srcdir)/shared/misc.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@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`
options.o: $(top_srcdir)/shared/options.c
@am__fastdepCC_TRUE@ $(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
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@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
options.obj: $(top_srcdir)/shared/options.c
@am__fastdepCC_TRUE@ $(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`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@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`
sha256.o: $(top_srcdir)/shared/sha256.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sha256.o -MD -MP -MF $(DEPDIR)/sha256.Tpo -c -o sha256.o `test -f '$(top_srcdir)/shared/sha256.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/sha256.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/sha256.Tpo $(DEPDIR)/sha256.Po

@ -47,9 +47,8 @@
#include "vba.h"
#include "shared/options.h"
#include "shared/output.h"
#include "shared/cfgparser.h"
#include "shared/optparser.h"
#include "shared/misc.h"
#include "shared/cdiff.h"
#include "shared/sha256.h"
@ -118,15 +117,15 @@ static int hexdump(void)
return 0;
}
static int md5sig(struct optstruct *opt, unsigned int mdb)
static int md5sig(const struct optstruct *opts, unsigned int mdb)
{
char *md5, *filename;
unsigned int i;
struct stat sb;
if(opt->filename) {
for(i = 0; (filename = cli_strtok(opt->filename, i, "\t")); i++) {
if(opts->filename) {
for(i = 0; (filename = cli_strtok(opts->filename, i, "\t")); i++) {
if(stat(filename, &sb) == -1) {
mprintf("!md5sig: Can't access file %s\n", filename);
perror("md5sig");
@ -163,13 +162,13 @@ static int md5sig(struct optstruct *opt, unsigned int mdb)
return 0;
}
static int htmlnorm(struct optstruct *opt)
static int htmlnorm(const struct optstruct *opts)
{
int fd;
if((fd = open(opt_arg(opt, "html-normalise"), O_RDONLY)) == -1) {
mprintf("!htmlnorm: Can't open file %s\n", opt_arg(opt, "html-normalise"));
if((fd = open(optget(opts, "html-normalise")->strarg, O_RDONLY)) == -1) {
mprintf("!htmlnorm: Can't open file %s\n", optget(opts, "html-normalise")->strarg);
return -1;
}
@ -179,14 +178,14 @@ static int htmlnorm(struct optstruct *opt)
return 0;
}
static int utf16decode(struct optstruct *opt)
static int utf16decode(const struct optstruct *opts)
{
const char *fname;
char *newname, buff[512], *decoded;
int fd1, fd2, bytes;
fname = opt_arg(opt, "utf16-decode");
fname = optget(opts, "utf16-decode")->strarg;
if((fd1 = open(fname, O_RDONLY)) == -1) {
mprintf("!utf16decode: Can't open file %s\n", fname);
return -1;
@ -411,7 +410,7 @@ static int writeinfo(const char *dbname, const char *header)
static int diffdirs(const char *old, const char *new, const char *patch);
static int verifydiff(const char *diff, const char *cvd, const char *incdir);
static int script2cdiff(const char *script, const char *builder, struct optstruct *opt)
static int script2cdiff(const char *script, const char *builder, const struct optstruct *opts)
{
char *cdiff, *pt, buffer[FILEBUFF];
unsigned char digest[32];
@ -508,7 +507,7 @@ static int script2cdiff(const char *script, const char *builder, struct optstruc
sha256_final(&ctx);
sha256_digest(&ctx, digest);
if(!(pt = getdsig(opt_arg(opt, "server"), builder, digest, 32, 1))) {
if(!(pt = getdsig(optget(opts, "server")->strarg, builder, digest, 32, 1))) {
mprintf("!script2cdiff: Can't get digital signature from remote server\n");
unlink(cdiff);
free(cdiff);
@ -531,7 +530,7 @@ static int script2cdiff(const char *script, const char *builder, struct optstruc
return 0;
}
static int build(struct optstruct *opt)
static int build(const struct optstruct *opts)
{
int ret;
size_t bytes;
@ -548,7 +547,7 @@ static int build(struct optstruct *opt)
struct cl_cvd *oldcvd;
if(!opt_check(opt, "server")) {
if(!optget(opts, "server")->enabled) {
mprintf("!build: --server is required for --build\n");
return -1;
}
@ -558,7 +557,7 @@ static int build(struct optstruct *opt)
return -1;
}
dbname = strstr(opt_arg(opt, "build"), "main") ? "main" : "daily";
dbname = strstr(optget(opts, "build")->strarg, "main") ? "main" : "daily";
if(!(engine = cl_engine_new())) {
mprintf("!build: Can't initialize antivirus engine\n");
@ -589,9 +588,9 @@ static int build(struct optstruct *opt)
}
/* try to read cvd header of current database */
if(opt->filename) {
if(cli_strbcasestr(opt->filename, ".cvd") || cli_strbcasestr(opt->filename, ".cld")) {
strncpy(olddb, opt->filename, sizeof(olddb));
if(opts->filename) {
if(cli_strbcasestr(opts->filename, ".cvd") || cli_strbcasestr(opts->filename, ".cld")) {
strncpy(olddb, opts->filename, sizeof(olddb));
olddb[sizeof(olddb)-1]='\0';
} else {
mprintf("!build: Not a CVD/CLD file\n");
@ -736,7 +735,7 @@ static int build(struct optstruct *opt)
sprintf(header + strlen(header), "%s:", pt);
free(pt);
if(!(pt = getdsig(opt_arg(opt, "server"), builder, buffer, 16, 0))) {
if(!(pt = getdsig(optget(opts, "server")->strarg, builder, buffer, 16, 0))) {
mprintf("!build: Can't get digital signature from remote server\n");
fclose(fh);
unlink(tarfile);
@ -757,7 +756,7 @@ static int build(struct optstruct *opt)
strcat(header, " ");
/* build the final database */
newcvd = opt_arg(opt, "build");
newcvd = optget(opts, "build")->strarg;
if(!(cvd = fopen(newcvd, "wb"))) {
mprintf("!build: Can't create final database %s\n", newcvd);
fclose(fh);
@ -879,24 +878,24 @@ static int build(struct optstruct *opt)
mprintf("!Generated file is incorrect, renamed to %s\n", broken);
}
} else {
ret = script2cdiff(patch, builder, opt);
ret = script2cdiff(patch, builder, opts);
}
return ret;
}
static int unpack(struct optstruct *opt)
static int unpack(const struct optstruct *opts)
{
char name[512], *dbdir;
if(opt_check(opt, "unpack-current")) {
if(optget(opts, "unpack-current")->enabled) {
dbdir = freshdbdir();
snprintf(name, sizeof(name), "%s/%s.cvd", dbdir, opt_arg(opt, "unpack-current"));
snprintf(name, sizeof(name), "%s/%s.cvd", dbdir, optget(opts, "unpack-current")->strarg);
if(access(name, R_OK)) {
snprintf(name, sizeof(name), "%s/%s.cld", dbdir, opt_arg(opt, "unpack-current"));
snprintf(name, sizeof(name), "%s/%s.cld", dbdir, optget(opts, "unpack-current")->strarg);
if(access(name, R_OK)) {
mprintf("!unpack: Couldn't find %s CLD/CVD database\n", opt_arg(opt, "unpack-current"));
mprintf("!unpack: Couldn't find %s CLD/CVD database\n", optget(opts, "unpack-current")->strarg);
free(dbdir);
return -1;
}
@ -904,7 +903,7 @@ static int unpack(struct optstruct *opt)
free(dbdir);
} else {
strncpy(name, opt_arg(opt, "unpack"), sizeof(name));
strncpy(name, optget(opts, "unpack")->strarg, sizeof(name));
name[sizeof(name)-1]='\0';
}
@ -916,14 +915,14 @@ static int unpack(struct optstruct *opt)
return 0;
}
static int cvdinfo(struct optstruct *opt)
static int cvdinfo(const struct optstruct *opts)
{
struct cl_cvd *cvd;
char *pt;
int ret;
pt = opt_arg(opt, "info");
pt = optget(opts, "info")->strarg;
if((cvd = cl_cvdhead(pt)) == NULL) {
mprintf("!cvdinfo: Can't read/parse CVD header of %s\n", pt);
return -1;
@ -938,7 +937,7 @@ static int cvdinfo(struct optstruct *opt)
mprintf("Functionality level: %u\n", cvd->fl);
mprintf("Builder: %s\n", cvd->builder);
pt = opt_arg(opt, "info");
pt = optget(opts, "info")->strarg;
if(cli_strbcasestr(pt, ".cvd")) {
mprintf("MD5: %s\n", cvd->md5);
mprintf("Digital signature: %s\n", cvd->dsig);
@ -1162,27 +1161,37 @@ static int listdb(const char *filename)
return 0;
}
static int listsigs(struct optstruct *opt)
static int listsigs(const struct optstruct *opts)
{
int ret;
const char *name;
char *dbdir;
struct stat sb;
mprintf_stdout = 1;
name = optget(opts, "list-sigs")->strarg;
if(stat(name, &sb) == -1) {
mprintf("--list-sigs: Can't get status of %s\n", name);
return -1;
}
if((name = opt_arg(opt, "list-sigs"))) {
ret = listdb(name);
mprintf_stdout = 1;
if(S_ISDIR(sb.st_mode)) {
if(!strcmp(name, DATADIR)) {
dbdir = freshdbdir();
ret = listdir(dbdir);
free(dbdir);
} else {
ret = listdir(name);
}
} else {
dbdir = freshdbdir();
ret = listdir(dbdir);
free(dbdir);
ret = listdb(name);
}
return ret;
}
static int vbadump(struct optstruct *opt)
static int vbadump(const struct optstruct *opts)
{
int fd, hex_output;
char *dir;
@ -1190,12 +1199,12 @@ static int vbadump(struct optstruct *opt)
struct uniq *vba = NULL;
if(opt_check(opt, "vba-hex")) {
if(optget(opts, "vba-hex")->enabled) {
hex_output = 1;
pt = opt_arg(opt, "vba-hex");
pt = optget(opts, "vba-hex")->strarg;
} else {
hex_output = 0;
pt = opt_arg(opt, "vba");
pt = optget(opts, "vba")->strarg;
}
if((fd = open(pt, O_RDONLY)) == -1) {
@ -1281,14 +1290,14 @@ static int comparemd5(const char *dbname)
}
static int rundiff(struct optstruct *opt)
static int rundiff(const struct optstruct *opts)
{
int fd, ret;
unsigned short mode;
const char *diff;
diff = opt_arg(opt, "run-cdiff");
diff = optget(opts, "run-cdiff")->strarg;
if(strstr(diff, ".cdiff")) {
mode = 1;
} else if(strstr(diff, ".script")) {
@ -1589,7 +1598,7 @@ static int diffdirs(const char *old, const char *new, const char *patch)
return 0;
}
static int makediff(struct optstruct *opt)
static int makediff(const struct optstruct *opts)
{
char *odir, *ndir, name[32], broken[32];
struct cl_cvd *cvd;
@ -1597,20 +1606,20 @@ static int makediff(struct optstruct *opt)
int ret;
if(!opt->filename) {
if(!opts->filename) {
mprintf("!makediff: --diff requires two arguments\n");
return -1;
}
if(!(cvd = cl_cvdhead(opt->filename))) {
mprintf("!makediff: Can't read CVD header from %s\n", opt->filename);
if(!(cvd = cl_cvdhead(opts->filename))) {
mprintf("!makediff: Can't read CVD header from %s\n", opts->filename);
return -1;
}
newver = cvd->version;
free(cvd);
if(!(cvd = cl_cvdhead(opt_arg(opt, "diff")))) {
mprintf("!makediff: Can't read CVD header from %s\n", opt_arg(opt, "diff"));
if(!(cvd = cl_cvdhead(optget(opts, "diff")->strarg))) {
mprintf("!makediff: Can't read CVD header from %s\n", optget(opts, "diff")->strarg);
return -1;
}
oldver = cvd->version;
@ -1633,8 +1642,8 @@ static int makediff(struct optstruct *opt)
return -1;
}
if(cvd_unpack(opt_arg(opt, "diff"), odir) == -1) {
mprintf("!makediff: Can't unpack CVD file %s\n", opt_arg(opt, "diff"));
if(cvd_unpack(optget(opts, "diff")->strarg, odir) == -1) {
mprintf("!makediff: Can't unpack CVD file %s\n", optget(opts, "diff")->strarg);
cli_rmdirs(odir);
free(odir);
return -1;
@ -1656,8 +1665,8 @@ static int makediff(struct optstruct *opt)
return -1;
}
if(cvd_unpack(opt->filename, ndir) == -1) {
mprintf("!makediff: Can't unpack CVD file %s\n", opt->filename);
if(cvd_unpack(opts->filename, ndir) == -1) {
mprintf("!makediff: Can't unpack CVD file %s\n", opts->filename);
cli_rmdirs(odir);
cli_rmdirs(ndir);
free(odir);
@ -1665,7 +1674,7 @@ static int makediff(struct optstruct *opt)
return -1;
}
if(strstr(opt->filename, "main"))
if(strstr(opts->filename, "main"))
snprintf(name, sizeof(name), "main-%u.script", newver);
else
snprintf(name, sizeof(name), "daily-%u.script", newver);
@ -1680,7 +1689,7 @@ static int makediff(struct optstruct *opt)
if(ret == -1)
return -1;
if(verifydiff(name, opt_arg(opt, "diff"), NULL) == -1) {
if(verifydiff(name, optget(opts, "diff")->strarg, NULL) == -1) {
snprintf(broken, sizeof(broken), "%s.broken", name);
if(rename(name, broken)) {
unlink(name);
@ -1731,107 +1740,80 @@ static void help(void)
int main(int argc, char **argv)
{
int ret = 1;
struct optstruct *opt;
struct optstruct *opts;
struct stat sb;
const char *short_options = "hvVb:i:u:l::r:d:";
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"quiet", 0, 0, 0},
{"debug", 0, 0, 0},
{"verbose", 0, 0, 'v'},
{"stdout", 0, 0, 0},
{"version", 0, 0, 'V'},
{"tempdir", 1, 0, 0},
{"hex-dump", 0, 0, 0},
{"md5", 0, 0, 0},
{"mdb", 0, 0, 0},
{"html-normalise", 1, 0, 0},
{"utf16-decode", 1, 0, 0},
{"build", 1, 0, 'b'},
{"server", 1, 0, 0},
{"unpack", 1, 0, 'u'},
{"unpack-current", 1, 0, 0},
{"info", 1, 0, 'i'},
{"list-sigs", 2, 0, 'l'},
{"vba", 1, 0 ,0},
{"vba-hex", 1, 0, 0},
{"diff", 1, 0, 'd'},
{"run-cdiff", 1, 0, 'r'},
{"verify-cdiff", 1, 0, 0},
{0, 0, 0, 0}
};
opt = opt_parse(argc, argv, short_options, long_options, NULL, NULL);
if(!opt) {
mprintf("!Can't parse the command line\n");
opts = optparse(NULL, argc, argv, 1, OPT_SIGTOOL, 0, NULL);
if(!opts) {
mprintf("!Can't parse command line options\n");
return 1;
}
if(opt_check(opt, "quiet"))
if(optget(opts, "quiet")->enabled)
mprintf_quiet = 1;
if(opt_check(opt, "stdout"))
if(optget(opts, "stdout")->enabled)
mprintf_stdout = 1;
if(opt_check(opt, "debug"))
if(optget(opts, "debug")->enabled)
cl_debug();
if(opt_check(opt, "version")) {
if(optget(opts, "version")->enabled) {
print_version(NULL);
opt_free(opt);
optfree(opts);
return 0;
}
if(opt_check(opt, "help")) {
opt_free(opt);
if(optget(opts, "help")->enabled) {
optfree(opts);
help();
return 0;
}
if(opt_check(opt, "hex-dump"))
if(optget(opts, "hex-dump")->enabled)
ret = hexdump();
else if(opt_check(opt, "md5"))
ret = md5sig(opt, 0);
else if(opt_check(opt, "mdb"))
ret = md5sig(opt, 1);
else if(opt_check(opt, "html-normalise"))
ret = htmlnorm(opt);
else if(opt_check(opt, "utf16-decode"))
ret = utf16decode(opt);
else if(opt_check(opt, "build"))
ret = build(opt);
else if(opt_check(opt, "unpack"))
ret = unpack(opt);
else if(opt_check(opt, "unpack-current"))
ret = unpack(opt);
else if(opt_check(opt, "info"))
ret = cvdinfo(opt);
else if(opt_check(opt, "list-sigs"))
ret = listsigs(opt);
else if(opt_check(opt, "vba") || opt_check(opt, "vba-hex"))
ret = vbadump(opt);
else if(opt_check(opt, "diff"))
ret = makediff(opt);
else if(opt_check(opt, "run-cdiff"))
ret = rundiff(opt);
else if(opt_check(opt, "verify-cdiff")) {
if(!opt->filename) {
else if(optget(opts, "md5")->enabled)
ret = md5sig(opts, 0);
else if(optget(opts, "mdb")->enabled)
ret = md5sig(opts, 1);
else if(optget(opts, "html-normalise")->enabled)
ret = htmlnorm(opts);
else if(optget(opts, "utf16-decode")->enabled)
ret = utf16decode(opts);
else if(optget(opts, "build")->enabled)
ret = build(opts);
else if(optget(opts, "unpack")->enabled)
ret = unpack(opts);
else if(optget(opts, "unpack-current")->enabled)
ret = unpack(opts);
else if(optget(opts, "info")->enabled)
ret = cvdinfo(opts);
else if(optget(opts, "list-sigs")->active)
ret = listsigs(opts);
else if(optget(opts, "vba")->enabled || optget(opts, "vba-hex")->enabled)
ret = vbadump(opts);
else if(optget(opts, "diff")->enabled)
ret = makediff(opts);
else if(optget(opts, "run-cdiff")->enabled)
ret = rundiff(opts);
else if(optget(opts, "verify-cdiff")->enabled) {
if(!opts->filename) {
mprintf("!--verify-cdiff requires two arguments\n");
ret = -1;
} else {
if(stat(opt->filename, &sb) == -1) {
mprintf("--verify-cdiff: Can't get status of %s\n", opt->filename);
if(stat(opts->filename, &sb) == -1) {
mprintf("--verify-cdiff: Can't get status of %s\n", opts->filename);
ret = -1;
} else {
if(S_ISDIR(sb.st_mode))
ret = verifydiff(opt_arg(opt, "verify-cdiff"), NULL, opt->filename);
ret = verifydiff(optget(opts, "verify-cdiff")->strarg, NULL, opts->filename);
else
ret = verifydiff(opt_arg(opt, "verify-cdiff"), opt->filename, NULL);
ret = verifydiff(optget(opts, "verify-cdiff")->strarg, opts->filename, NULL);
}
}
} else
help();
opt_free(opt);
optfree(opts);
return ret ? 1 : 0;
}

Loading…
Cancel
Save