shared, clamconf: drop old stuff; replace getopt.[ch] with my_getopt

git-svn: trunk@4589
This commit is contained in:
Tomasz Kojm 2009-01-02 17:04:11 +00:00
parent 278dc6b3d9
commit b61db429fc
15 changed files with 378 additions and 2722 deletions

22
COPYING.getopt Normal file
View file

@ -0,0 +1,22 @@
getopt.c - my re-implementation of getopt.
Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View file

@ -1,3 +1,7 @@
Fri Jan 2 18:16:45 CET 2009 (tk)
---------------------------------
* shared, clamconf: drop old stuff; replace getopt.[ch] with my_getopt
Fri Jan 2 13:08:09 CET 2009 (tk) Fri Jan 2 13:08:09 CET 2009 (tk)
--------------------------------- ---------------------------------
* shared/optparser.c, clamav-milter: use the new option parser (bb#1215) * shared/optparser.c, clamav-milter: use the new option parser (bb#1215)

View file

@ -19,7 +19,7 @@
ACLOCAL_AMFLAGS=-I m4 ACLOCAL_AMFLAGS=-I m4
SUBDIRS = libltdl libclamav clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test unit_tests SUBDIRS = libltdl libclamav clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test unit_tests
EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD COPYING.getopt
bin_SCRIPTS=clamav-config bin_SCRIPTS=clamav-config

View file

@ -282,7 +282,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
SUBDIRS = libltdl libclamav clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test unit_tests SUBDIRS = libltdl libclamav clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test unit_tests
EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD COPYING.getopt
bin_SCRIPTS = clamav-config bin_SCRIPTS = clamav-config
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libclamav.pc pkgconfig_DATA = libclamav.pc

View file

@ -16,16 +16,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. # MA 02110-1301, USA.
bin_PROGRAMS = clamconf #bin_PROGRAMS = clamconf
clamconf_SOURCES = \ #clamconf_SOURCES = \
$(top_srcdir)/shared/cfgparser.c \ # $(top_srcdir)/shared/cfgparser.c \
$(top_srcdir)/shared/cfgparser.h \ # $(top_srcdir)/shared/cfgparser.h \
$(top_srcdir)/shared/misc.c \ # $(top_srcdir)/shared/misc.c \
$(top_srcdir)/shared/misc.h \ # $(top_srcdir)/shared/misc.h \
$(top_srcdir)/shared/getopt.c \ # $(top_srcdir)/shared/getopt.c \
$(top_srcdir)/shared/getopt.h \ # $(top_srcdir)/shared/getopt.h \
clamconf.c # clamconf.c
DEFS = @DEFS@ -DCL_NOTHREADS DEFS = @DEFS@ -DCL_NOTHREADS
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav

View file

@ -32,6 +32,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. # MA 02110-1301, USA.
#bin_PROGRAMS = clamconf
#clamconf_SOURCES = \
# $(top_srcdir)/shared/cfgparser.c \
# $(top_srcdir)/shared/cfgparser.h \
# $(top_srcdir)/shared/misc.c \
# $(top_srcdir)/shared/misc.h \
# $(top_srcdir)/shared/getopt.c \
# $(top_srcdir)/shared/getopt.h \
# clamconf.c
VPATH = @srcdir@ VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@ pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@
@ -51,7 +61,6 @@ POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
target_triplet = @target@ target_triplet = @target@
bin_PROGRAMS = clamconf$(EXEEXT)
subdir = clamconf subdir = clamconf
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -68,29 +77,8 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
mkinstalldirs = $(install_sh) -d mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/clamav-config.h CONFIG_HEADER = $(top_builddir)/clamav-config.h
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
am__installdirs = "$(DESTDIR)$(bindir)" SOURCES =
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) DIST_SOURCES =
PROGRAMS = $(bin_PROGRAMS)
am_clamconf_OBJECTS = cfgparser.$(OBJEXT) misc.$(OBJEXT) \
getopt.$(OBJEXT) clamconf.$(OBJEXT)
clamconf_OBJECTS = $(am_clamconf_OBJECTS)
clamconf_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(clamconf_SOURCES)
DIST_SOURCES = $(clamconf_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@ ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@ AMTAR = @AMTAR@
@ -248,21 +236,11 @@ target_os = @target_os@
target_vendor = @target_vendor@ target_vendor = @target_vendor@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
clamconf_SOURCES = \
$(top_srcdir)/shared/cfgparser.c \
$(top_srcdir)/shared/cfgparser.h \
$(top_srcdir)/shared/misc.c \
$(top_srcdir)/shared/misc.h \
$(top_srcdir)/shared/getopt.c \
$(top_srcdir)/shared/getopt.h \
clamconf.c
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
CLEANFILES = *.gcda *.gcno CLEANFILES = *.gcda *.gcno
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \ @for dep in $?; do \
case '$(am__configure_deps)' in \ case '$(am__configure_deps)' in \
@ -292,180 +270,18 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
|| test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
installcheck-binPROGRAMS: $(bin_PROGRAMS)
bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \
case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \
*" $$p "* | *" $(srcdir)/$$p "*) continue;; \
esac; \
f=`echo "$$p" | \
sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
for opt in --help --version; do \
if "$(DESTDIR)$(bindir)/$$f" $$opt >c$${pid}_.out \
2>c$${pid}_.err </dev/null \
&& test -n "`cat c$${pid}_.out`" \
&& test -z "`cat c$${pid}_.err`"; then :; \
else echo "$$f does not support $$opt" 1>&2; bad=1; fi; \
done; \
done; rm -f c$${pid}_.???; exit $$bad
clamconf$(EXEEXT): $(clamconf_OBJECTS) $(clamconf_DEPENDENCIES)
@rm -f clamconf$(EXEEXT)
$(LINK) $(clamconf_OBJECTS) $(clamconf_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamconf.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@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
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@
@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
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@
@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`
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
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/misc.Tpo $(DEPDIR)/misc.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/misc.c' object='misc.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 misc.o `test -f '$(top_srcdir)/shared/misc.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/misc.c
misc.obj: $(top_srcdir)/shared/misc.c
@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`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/misc.Tpo $(DEPDIR)/misc.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/misc.c' object='misc.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 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`
getopt.o: $(top_srcdir)/shared/getopt.c
@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
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/getopt.Tpo $(DEPDIR)/getopt.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.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 getopt.o `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c
getopt.obj: $(top_srcdir)/shared/getopt.c
@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`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/getopt.Tpo $(DEPDIR)/getopt.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.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 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`
mostlyclean-libtool: mostlyclean-libtool:
-rm -f *.lo -rm -f *.lo
clean-libtool: clean-libtool:
-rm -rf .libs _libs -rm -rf .libs _libs
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS tags: TAGS
TAGS:
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ CTAGS:
$(TAGS_FILES) $(LISP)
tags=; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES) distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
@ -495,11 +311,8 @@ distdir: $(DISTFILES)
done done
check-am: all-am check-am: all-am
check: check-am check: check-am
all-am: Makefile $(PROGRAMS) all-am: Makefile
installdirs: installdirs:
for dir in "$(DESTDIR)$(bindir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am install: install-am
install-exec: install-exec-am install-exec: install-exec-am
install-data: install-data-am install-data: install-data-am
@ -527,13 +340,11 @@ maintainer-clean-generic:
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
clean: clean-am clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile -rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \ distclean-am: clean-am distclean-generic
distclean-tags
dvi: dvi-am dvi: dvi-am
@ -549,7 +360,7 @@ install-data-am:
install-dvi: install-dvi-am install-dvi: install-dvi-am
install-exec-am: install-binPROGRAMS install-exec-am:
install-html: install-html-am install-html: install-html-am
@ -561,17 +372,15 @@ install-pdf: install-pdf-am
install-ps: install-ps-am install-ps: install-ps-am
installcheck-am: installcheck-binPROGRAMS installcheck-am:
maintainer-clean: maintainer-clean-am maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-am: mostlyclean-generic mostlyclean-libtool
mostlyclean-libtool
pdf: pdf-am pdf: pdf-am
@ -581,23 +390,20 @@ ps: ps-am
ps-am: ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-am:
.MAKE: install-am install-strip .MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ .PHONY: all all-am check check-am clean clean-generic clean-libtool \
clean-generic clean-libtool ctags distclean distclean-compile \ distclean distclean-generic distclean-libtool distdir dvi \
distclean-generic distclean-libtool distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \ dvi-am html html-am info info-am install install-am \
install-binPROGRAMS install-data install-data-am install-dvi \ install-data install-data-am install-dvi install-dvi-am \
install-dvi-am install-exec install-exec-am install-html \ install-exec install-exec-am install-html install-html-am \
install-html-am install-info install-info-am install-man \ install-info install-info-am install-man install-pdf \
install-pdf install-pdf-am install-ps install-ps-am \ install-pdf-am install-ps install-ps-am install-strip \
install-strip installcheck installcheck-am \ installcheck installcheck-am installdirs maintainer-clean \
installcheck-binPROGRAMS installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \
maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-binPROGRAMS
# Tell versions [3.59,3.63) of GNU make to not export all variables. # Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded. # Otherwise a system limit (for SysV at least) may be exceeded.

View file

@ -1,330 +0,0 @@
/*
* Copyright (C) 2006 Sensory Networks, Inc.
* (C) 2007 Tomasz Kojm <tkojm@clamav.net>
* Written by Tomasz Kojm
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <time.h>
#include "shared/misc.h"
#include "libclamav/clamav.h"
#include "libclamav/version.h"
#include "cfgparser.h"
#define _GNU_SOURCE
#include "getopt.h"
static void printopt(const struct cfgoption *opt, const struct cfgstruct *cpt, int nondef)
{
if(!cpt->enabled && opt->numarg == -1) {
if(!nondef || (opt->numarg != cpt->numarg))
printf("%s not set\n", opt->name);
return;
}
while(cpt) {
if(opt->owner & OPT_DEPRECATED) {
printf("*** %s is DEPRECATED ***\n", opt->name);
} else switch(opt->argtype) {
case OPT_STR:
case OPT_FULLSTR:
case OPT_QUOTESTR:
if(!nondef || !opt->strarg || strcmp(opt->strarg, cpt->strarg))
printf("%s = \"%s\"\n", opt->name, cpt->strarg);
break;
case OPT_NUM:
case OPT_COMPSIZE:
if(!nondef || (opt->numarg != cpt->numarg))
printf("%s = %u\n", opt->name, cpt->numarg);
break;
case OPT_BOOL:
if(!nondef || (opt->numarg != cpt->numarg))
printf("%s = %s\n", opt->name, cpt->enabled ? "yes" : "no");
break;
default:
printf("%s: UNKNOWN ARGUMENT TYPE\n", opt->name);
}
cpt = cpt->nextarg;
}
}
static void printcfg(const char *cfgfile, int nondef)
{
const struct cfgoption *opt;
const struct cfgstruct *cpt;
struct cfgstruct *cfg;
int i;
unsigned short cfgowner = 0;
if(!(cfg = getcfg(cfgfile, 1, OPT_FRESHCLAM|OPT_CLAMD))) {
printf("Can't parse %s\n", cfgfile);
return;
}
/* pre loop to detect merged config */
for(i = 0; ; i++) {
opt = &cfg_options[i];
if(!opt->name)
break;
if(!(opt->owner & (OPT_CLAMD|OPT_FRESHCLAM)))
continue;
cpt = cfgopt(cfg, opt->name);
if((cpt->numarg != opt->numarg) || (cpt->strarg && opt->strarg && strcmp(cpt->strarg, opt->strarg))) {
if((opt->owner & OPT_CLAMD) && !(opt->owner & OPT_FRESHCLAM))
cfgowner |= OPT_CLAMD;
else if((opt->owner & OPT_FRESHCLAM) && !(opt->owner & OPT_CLAMD))
cfgowner |= OPT_FRESHCLAM;
}
}
if((cfgowner & OPT_CLAMD) && (cfgowner & OPT_FRESHCLAM)) { /* merged cfg */
printf("%s: clamd and freshclam directives\n", cfgfile);
printf("------------------------------\n");
printf("\n[common]\n");
for(i = 0; ; i++) {
opt = &cfg_options[i];
if(!opt->name)
break;
if((opt->owner & OPT_CLAMD) && (opt->owner & OPT_FRESHCLAM)) {
cpt = cfgopt(cfg, opt->name);
printopt(opt, cpt, nondef);
}
}
printf("\n[clamd]\n");
for(i = 0; ; i++) {
opt = &cfg_options[i];
if(!opt->name)
break;
if((opt->owner & OPT_CLAMD) && !(opt->owner & OPT_FRESHCLAM)) {
cpt = cfgopt(cfg, opt->name);
printopt(opt, cpt, nondef);
}
}
printf("\n[freshclam]\n");
for(i = 0; ; i++) {
opt = &cfg_options[i];
if(!opt->name)
break;
if((opt->owner & OPT_FRESHCLAM) && !(opt->owner & OPT_CLAMD)) {
cpt = cfgopt(cfg, opt->name);
printopt(opt, cpt, nondef);
}
}
} else { /* separate cfg */
if(cfgowner & OPT_CLAMD) {
printf("%s: clamd directives\n", cfgfile);
printf("------------------------------\n");
for(i = 0; ; i++) {
opt = &cfg_options[i];
if(!opt->name)
break;
if(opt->owner & OPT_CLAMD) {
cpt = cfgopt(cfg, opt->name);
printopt(opt, cpt, nondef);
}
}
} else {
printf("%s: freshclam directives\n", cfgfile);
printf("------------------------------\n");
for(i = 0; ; i++) {
opt = &cfg_options[i];
if(!opt->name)
break;
if(opt->owner & OPT_FRESHCLAM) {
cpt = cfgopt(cfg, opt->name);
printopt(opt, cpt, nondef);
}
}
}
}
freecfg(cfg);
}
static void printdb(const char *dir, const char *db)
{
struct cl_cvd *cvd;
char path[256];
unsigned int cld = 0;
time_t t;
snprintf(path, sizeof(path), "%s/%s.cvd", dir, db);
if(access(path, R_OK) == -1) {
snprintf(path, sizeof(path), "%s/%s.cld", dir, db);
cld = 1;
if(access(path, R_OK) == -1) {
printf("%s db: Not found\n", db);
return;
}
}
if((cvd = cl_cvdhead(path))) {
t = (time_t) cvd->stime;
printf("%s db: Format: %s, Version: %u, Build time: %s", db, cld ? ".cld" : ".cvd", cvd->version, ctime(&t));
cl_cvdfree(cvd);
}
}
static void version(void)
{
printf("Clam AntiVirus Configuration Tool %s\n", get_version());
}
static void help(void)
{
printf("\n");
printf(" Clam AntiVirus: Configuration Tool %s\n", get_version());
printf(" (C) 2006 - 2007 ClamAV Team - http://www.clamav.net/team\n\n");
printf(" --help -h show help\n");
printf(" --version -v show version\n");
printf(" --config-dir DIR -c DIR search for config files in DIR\n");
printf(" --non-default -n only print non-default settings\n");
printf("\n");
}
#ifndef REPO_VERSION
#define REPO_VERSION VERSION
#endif
int main(int argc, char **argv)
{
char path[1024];
struct stat sb;
int ret, opt_index, nondef = 0;
const char *getopt_parameters = "hVc:n";
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"config-dir", 1, 0, 'c'},
{"non-default", 0, 0, 'n'},
{0, 0, 0, 0}
};
char *confdir = strdup(CONFDIR), *dbdir;
int found = 0;
while(1) {
opt_index = 0;
ret = getopt_long(argc, argv, getopt_parameters, long_options, &opt_index);
if (ret == -1)
break;
switch (ret) {
case 0:
break;
case 'c':
free(confdir);
confdir = strdup(optarg);
break;
case 'h':
help();
free(confdir);
exit(0);
case 'n':
nondef = 1;
break;
case 'V':
version();
free(confdir);
exit(0);
default:
printf("ERROR: Unknown option passed\n");
free(confdir);
exit(1);
}
}
snprintf(path, sizeof(path), "%s/clamd.conf", confdir);
if(stat(path, &sb) != -1) {
printcfg(path, nondef);
found = 1;
printf("\n");
}
snprintf(path, sizeof(path), "%s/freshclam.conf", confdir);
if(stat(path, &sb) != -1) {
printcfg(path, nondef);
found = 1;
}
if(!found) {
printf("No config files found in %s\n", confdir);
free(confdir);
return 1;
}
free(confdir);
printf("\nEngine and signature databases\n");
printf("------------------------------\n");
#ifdef CL_EXPERIMENTAL
printf("Engine version: %s (with experimental code)\n", get_version());
#else
printf("Engine version: %s\n", get_version());
#endif
if(strcmp(REPO_VERSION, cl_retver()))
printf("WARNING: Version mismatch: clamconf: "REPO_VERSION", libclamav: %s\n", cl_retver());
printf("Database directory: ");
dbdir = freshdbdir();
if(!dbdir) {
printf("Failed to retrieve\n");
return 1;
} else printf("%s\n", dbdir);
if(dbdir) {
printdb(dbdir, "main");
printdb(dbdir, "daily");
free(dbdir);
}
return 0;
}

View file

@ -1,576 +0,0 @@
/*
* Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <ctype.h>
#include "shared/cfgparser.h"
#include "shared/misc.h"
#include "libclamav/str.h"
struct cfgoption cfg_options[] = {
{"LogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"ScanELF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"MailFollowURLs", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"ScanPartialMessages", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"PhishingSignatures", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"PhishingScanURLs",OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
/* these are FP prone options, if default isn't used */
{"PhishingAlwaysBlockCloak", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"PhishingAlwaysBlockSSLMismatch", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"HeuristicScanPrecedence", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
/* end of FP prone options */
{"DetectPUA", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"ExcludePUA", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
{"IncludePUA", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
{"StructuredDataDetection", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"StructuredMinCreditCardCount", OPT_NUM, 3, NULL, 0, OPT_CLAMD},
{"StructuredMinSSNCount", OPT_NUM, 3, NULL, 0, OPT_CLAMD},
{"StructuredSSNFormatNormal", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"StructuredSSNFormatStripped", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"AlgorithmicDetection", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"ScanHTML", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"ScanOLE2", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"ScanPDF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD},
{"MaxFileSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
{"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
{"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM},
{"TCPAddr", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
{"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
{"LocalSocket", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
{"MaxConnectionQueueLength", OPT_NUM, 15, NULL, 0, OPT_CLAMD},
{"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD},
{"StreamMinPort", OPT_NUM, 1024, NULL, 0, OPT_CLAMD},
{"StreamMaxPort", OPT_NUM, 2048, NULL, 0, OPT_CLAMD},
{"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"IdleTimeout", OPT_NUM, 30, NULL, 0, OPT_CLAMD},
{"MaxDirectoryRecursion", OPT_NUM, 15, NULL, 0, OPT_CLAMD},
{"ExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
{"FollowDirectorySymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"FollowFileSymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"ExitOnOOM", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"Foreground", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"Debug", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
{"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"SelfCheck", OPT_NUM, 1800, NULL, 0, OPT_CLAMD},
{"VirusEvent", OPT_FULLSTR, -1, NULL, 0, OPT_CLAMD},
{"ClamukoScanOnAccess", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
{"ClamukoScanOnOpen", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
{"ClamukoScanOnClose", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
{"ClamukoScanOnExec", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
{"ClamukoIncludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
{"ClamukoExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
{"ClamukoMaxFileSize", OPT_COMPSIZE, 5242880, NULL, 0, OPT_CLAMD},
{"DatabaseOwner", OPT_QUOTESTR, -1, CLAMAVUSER, 0, OPT_FRESHCLAM},
{"Checks", OPT_NUM, 12, NULL, 0, OPT_FRESHCLAM},
{"UpdateLogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"DNSDatabaseInfo", OPT_QUOTESTR, -1, "current.cvd.clamav.net", 0, OPT_FRESHCLAM},
{"DatabaseMirror", OPT_QUOTESTR, -1, NULL, 1, OPT_FRESHCLAM},
{"MaxAttempts", OPT_NUM, 3, NULL, 0, OPT_FRESHCLAM},
{"ScriptedUpdates", OPT_BOOL, 1, NULL, 0, OPT_FRESHCLAM},
{"CompressLocalDatabase", OPT_BOOL, 0, NULL, 0, OPT_FRESHCLAM},
{"HTTPProxyServer", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"HTTPProxyPort", OPT_NUM, -1, NULL, 0, OPT_FRESHCLAM},
{"HTTPProxyUsername", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"HTTPProxyPassword", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"HTTPUserAgent", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM},
{"NotifyClamd", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"OnUpdateExecute", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM},
{"OnErrorExecute", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM},
{"OnOutdatedExecute", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM},
{"LocalIPAddress", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"ConnectTimeout", OPT_NUM, 30, NULL, 0, OPT_FRESHCLAM},
{"ReceiveTimeout", OPT_NUM, 30, NULL, 0, OPT_FRESHCLAM},
{"SubmitDetectionStats", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"DetectionStatsCountry", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
{"DevACOnly", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
{"DevACDepth", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
/* Deprecated options */
{"MailMaxRecursion", OPT_NUM, 64, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveMaxScanSize", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveMaxRecursion", OPT_NUM, 8, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveMaxFiles", OPT_NUM, 1000, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveMaxCompressionRatio", OPT_NUM, 250, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED },
/* Milter specific options */
{"ClamdSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER},
{"MilterSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER},
{"LocalNet", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER},
{"OnClean", OPT_QUOTESTR, -1, "Accept", 0, OPT_MILTER},
{"OnInfected", OPT_QUOTESTR, -1, "Quarantine", 0, OPT_MILTER},
{"OnFail", OPT_QUOTESTR, -1, "Defer", 0, OPT_MILTER},
{"AddHeader", OPT_BOOL, 0, NULL, 0, OPT_MILTER},
{"Chroot", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER},
{"Whitelist", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER},
/* Deprecated milter options */
{"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_MILTER | OPT_DEPRECATED},
{"Debug", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"LocalSocket", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"MailFollowURLs", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"PhishingSignatures", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"ScanHTML", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"ScanOLE2", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"TCPAddr", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
{NULL, 0, 0, NULL, 0, 0}
};
static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple);
struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask)
{
char buff[LINE_LENGTH], *name, *arg, *c;
FILE *fs;
int line = 0, i, found, ctype, calc, val;
struct cfgstruct *copt = NULL;
struct cfgoption *pt;
for(i = 0; ; i++) {
pt = &cfg_options[i];
if(!pt->name)
break;
if((pt->owner & toolmask) && regcfg(&copt, pt->name, pt->strarg ? strdup(pt->strarg) : NULL, pt->numarg, pt->multiple) < 0) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
freecfg(copt);
return NULL;
}
}
if((fs = fopen(cfgfile, "rb")) == NULL) {
/* do not print error message here! */
freecfg(copt);
return NULL;
}
while(fgets(buff, LINE_LENGTH, fs)) {
line++;
if(buff[0] == '#')
continue;
if(!strncmp("Example", buff, 7)) {
if(verbose)
fprintf(stderr, "ERROR: Please edit the example config file %s.\n", cfgfile);
fclose(fs);
freecfg(copt);
return NULL;
}
if((name = cli_strtok(buff, 0, " \r\n"))) {
arg = cli_strtok(buff, 1, " \r\n");
found = 0;
for(i = 0; ; i++) {
pt = &cfg_options[i];
if(pt->name) {
if((pt->owner & toolmask) && !strcmp(name, pt->name)) {
found = 1;
if(pt->owner & OPT_DEPRECATED) {
fprintf(stderr, "WARNING: Ignoring deprecated option %s at line %u\n", pt->name, line);
break;
}
switch(pt->argtype) {
case OPT_STR:
/* deprecated. Use OPT_QUOTESTR instead since it behaves like this, but supports quotes to allow values to contain whitespace */
if(!arg) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name);
fclose(fs);
free(name);
freecfg(copt);
return NULL;
}
if(regcfg(&copt, name, arg, -1, pt->multiple) < 0) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
break;
case OPT_FULLSTR:
/* an ugly hack of the above case */
if(!arg) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name);
fclose(fs);
free(name);
freecfg(copt);
return NULL;
}
free(arg);
arg = strstr(buff, " ");
arg = strdup(++arg);
if((arg) && (c = strpbrk(arg, "\n\r")))
*c = '\0';
if((!arg) || (regcfg(&copt, name, arg, -1, pt->multiple) < 0)) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
break;
case OPT_QUOTESTR:
/* an ugly hack of the above case */
if(!arg) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name);
fclose(fs);
free(name);
freecfg(copt);
return NULL;
}
if((*arg == '\'') || (*arg == '"')) {
free(arg);
c = strstr(buff, " ");
arg = strdup(c+2);
if(arg) {
if((c = strchr(arg, c[1])))
*c = '\0';
else {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s missing closing quote.\n", line, name);
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
}
}
if((!arg) || (regcfg(&copt, name, arg, -1, pt->multiple) < 0)) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
break;
case OPT_NUM:
if(!arg || !cli_isnumber(arg)) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical argument.\n", line, name);
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
if(regcfg(&copt, name, NULL, atoi(arg), pt->multiple) < 0) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
free(arg);
break;
case OPT_COMPSIZE:
if(!arg) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires argument.\n", line, name);
fclose(fs);
free(name);
freecfg(copt);
return NULL;
}
ctype = tolower(arg[strlen(arg) - 1]);
if(ctype == 'm' || ctype == 'k') {
char *cpy = strdup(arg);
if(!cpy) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
freecfg(copt);
return NULL;
}
cpy[strlen(arg) - 1] = '\0';
if(!cli_isnumber(cpy)) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name);
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
if(ctype == 'm')
calc = atoi(cpy) * 1024 * 1024;
else
calc = atoi(cpy) * 1024;
free(cpy);
} else {
if(!cli_isnumber(arg)) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name);
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
calc = atoi(arg);
}
free(arg);
if(regcfg(&copt, name, NULL, calc, pt->multiple) < 0) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
break;
case OPT_BOOL:
if(!arg) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires boolean argument.\n", line, name);
fclose(fs);
free(name);
freecfg(copt);
return NULL;
}
if(!strcasecmp(arg, "yes") || !strcmp(arg, "1") || !strcasecmp(arg, "true")) {
val = 1;
} else if(!strcasecmp(arg, "no") || !strcmp(arg, "0") || !strcasecmp(arg, "false")) {
val = 0;
} else {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires boolean argument.\n", line, name);
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
free(arg);
if(regcfg(&copt, name, NULL, val, pt->multiple) < 0) {
fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
break;
default:
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Option %s is of unknown type %d\n", line, name, pt->argtype);
fclose(fs);
free(name);
free(arg);
freecfg(copt);
return NULL;
}
}
} else
break;
}
if(!found) {
if(verbose)
fprintf(stderr, "ERROR: Parse error at line %d: Unknown option %s.\n", line, name);
free(name);
fclose(fs);
freecfg(copt);
return NULL;
}
free(name);
}
}
fclose(fs);
return copt;
}
void freecfg(struct cfgstruct *copt)
{
struct cfgstruct *handler;
struct cfgstruct *arg;
while(copt) {
arg = copt->nextarg;
while(arg) {
if(arg->strarg) {
free(arg->optname);
free(arg->strarg);
handler = arg;
arg = arg->nextarg;
free(handler);
} else
arg = arg->nextarg;
}
if(copt->optname)
free(copt->optname);
if(copt->strarg)
free(copt->strarg);
handler = copt;
copt = copt->next;
free(handler);
}
return;
}
const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname)
{
while(copt) {
if(copt->optname && !strcmp(copt->optname, optname))
return copt;
copt = copt->next;
}
return NULL;
}
static struct cfgstruct *cfgopt_i(struct cfgstruct *copt, const char *optname)
{
while(copt) {
if(copt->optname && !strcmp(copt->optname, optname))
return copt;
copt = copt->next;
}
return NULL;
}
static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple)
{
struct cfgstruct *newnode, *pt;
newnode = (struct cfgstruct *) malloc(sizeof(struct cfgstruct));
if(!newnode)
return -1;
newnode->optname = optname ? strdup(optname) : NULL;
newnode->nextarg = NULL;
newnode->next = NULL;
newnode->enabled = 0;
newnode->multiple = multiple;
if(strarg) {
newnode->strarg = strarg;
newnode->enabled = 1;
} else {
newnode->strarg = NULL;
}
newnode->numarg = numarg;
if(numarg != -1 && numarg != 0)
newnode->enabled = 1;
if((pt = cfgopt_i(*copt, optname))) {
if(pt->multiple) {
if(pt->enabled) {
while(pt->nextarg)
pt = pt->nextarg;
pt->nextarg = newnode;
} else {
if(pt->strarg)
free(pt->strarg);
pt->strarg = newnode->strarg;
pt->numarg = newnode->numarg;
pt->enabled = newnode->enabled;
if(newnode->optname)
free(newnode->optname);
free(newnode);
}
return 3; /* registered additional argument */
} else {
if(pt->strarg)
free(pt->strarg);
pt->strarg = newnode->strarg;
pt->numarg = newnode->numarg;
pt->enabled = newnode->enabled;
if(newnode->optname)
free(newnode->optname);
free(newnode);
return 2;
}
} else {
newnode->next = *copt;
*copt = newnode;
return 1;
}
}

View file

@ -1,63 +0,0 @@
/*
* Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef __CFGPARSER_H
#define __CFGPARSER_H
#define LINE_LENGTH 1024
#define OPT_STR 1 /* string argument (space delimited) */
#define OPT_NUM 2 /* numerical argument */
#define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */
#define OPT_BOOL 4 /* boolean value */
#define OPT_FULLSTR 5 /* string argument, but get a full line */
#define OPT_QUOTESTR 6 /* string argument, (space delimited unless the argument starts with ' or ". If the argument starts with a quote character, then the argument data is what appears between the starting quote character and the matching ending quote character.) */
/* don't share bits! */
#define OPT_CLAMD 1
#define OPT_FRESHCLAM 2
#define OPT_MILTER 4
#define OPT_DEPRECATED 16
struct cfgoption {
const char *name;
unsigned short argtype;
int numarg;
const char *strarg;
short multiple;
unsigned short owner;
};
struct cfgstruct {
char *optname;
char *strarg;
int numarg;
unsigned int enabled;
unsigned int multiple;
struct cfgstruct *nextarg;
struct cfgstruct *next;
};
extern struct cfgoption cfg_options[];
struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask);
const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname);
void freecfg(struct cfgstruct *copt);
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,180 +1,72 @@
/* Declarations for getopt. /*
Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc. * getopt.h - interface to my re-implementation of getopt.
This file is part of the GNU C Library. * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
The GNU C Library is free software; you can redistribute it and/or #ifndef _GETOPT_H_INCLUDED
modify it under the terms of the GNU Library General Public License as #define _GETOPT_H_INCLUDED
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _GETOPT_H
#ifndef __need_getopt
# define _GETOPT_H 1
#endif
/* If __GNU_LIBRARY__ is not already defined, either we are being used
standalone, or this is the first header included in the source file.
If we are being used with glibc, we need to include <features.h>, but
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
not defined, include <ctype.h>, which will pull in <features.h> for us
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
doesn't flood the namespace with stuff the way some other headers do.) */
#if !defined __GNU_LIBRARY__
# include <ctype.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* For communication from `getopt' to the caller. /* reset argument parser to start-up values */
When `getopt' finds an option that takes an argument, extern int getopt_reset(void);
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
/* UNIX-style short-argument parser */
extern int getopt(int argc, char * argv[], const char *opts);
extern int optind, opterr, optopt;
extern char *optarg; extern char *optarg;
/* Index in ARGV of the next element to be scanned. struct option {
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
# if defined __STDC__ && __STDC__
const char *name; const char *name;
# else
char *name;
# endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg; int has_arg;
int *flag; int *flag;
int val; int val;
}; };
/* Names for the values of the `has_arg' field of `struct option'. */ /* human-readable values for has_arg */
#undef no_argument
#define no_argument 0
#undef required_argument
#define required_argument 1
#undef optional_argument
#define optional_argument 2
# define no_argument 0 /* GNU-style long-argument parsers */
# define required_argument 1 extern int getopt_long(int argc, char * argv[], const char *shortopts,
# define optional_argument 2 const struct option *longopts, int *longind);
#endif /* need getopt */
extern int getopt_long_only(int argc, char * argv[], const char *shortopts,
const struct option *longopts, int *longind);
/* Get definitions and prototypes for functions to process the extern int _getopt_internal(int argc, char * argv[], const char *shortopts,
arguments in ARGV (ARGC of them, minus the program name) for const struct option *longopts, int *longind,
options given in OPTS. int long_only);
Return the option character from OPTS just read. Return -1 when
there are no more options. For unrecognized options, or options
missing arguments, `optopt' is set to the option letter, and '?' is
returned.
The OPTS string is a list of characters which are recognized option
letters, optionally followed by colons, specifying that that letter
takes an argument, to be placed in `optarg'.
If a letter in OPTS is followed by two colons, its argument is
optional. This behavior is specific to the GNU `getopt'.
The argument `--' causes premature termination of argument
scanning, explicitly telling `getopt' that there are no more
options.
If OPTS begins with `--', then non-option arguments are treated as
arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */
#if defined __STDC__ && __STDC__
# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
# else /* not __GNU_LIBRARY__ */
extern int getopt ();
# endif /* __GNU_LIBRARY__ */
# ifndef __need_getopt
extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
const struct option *__longopts, int *__longind);
extern int getopt_long_only (int __argc, char *const *__argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int __argc, char *const *__argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only);
# endif
#else /* not __STDC__ */
extern int getopt ();
# ifndef __need_getopt
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
# endif
#endif /* __STDC__ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/* Make sure we later can get all the definitions and declarations. */ #endif /* _GETOPT_H_INCLUDED */
#undef __need_getopt
#endif /* getopt.h */

View file

@ -1,309 +0,0 @@
/*
* Copyright (C) 2001 - 2007 Tomasz Kojm <tkojm@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE
#include "getopt.h"
#include "options.h"
#include "output.h"
static int register_option(struct optstruct *opt, const char *optlong, char optshort, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long)
{
struct optnode *newnode;
int i, found;
const char *longname = NULL;
if(optshort) {
for(i = 0; options_long[i].name; i++) {
if(options_long[i].val == optshort) {
longname = options_long[i].name;
break;
}
}
} else
longname = optlong;
if(!longname) {
mprintf("!register_option: No long option for -%c\n", optshort);
return -1;
}
if(accepted_long) {
found = 0;
for(i = 0; accepted_long[i]; i++)
if(!strcmp(accepted_long[i], longname)) {
found = 1;
break;
}
if(!found) {
if(optshort)
mprintf("WARNING: Ignoring option --%s (-%c)\n", longname, optshort);
else
mprintf("WARNING: Ignoring option --%s\n", longname);
return 0;
}
}
if(deprecated_long) {
found = 0;
for(i = 0; deprecated_long[i]; i++) {
if(!strcmp(deprecated_long[i], longname)) {
found = 1;
break;
}
}
if(found) {
if(optshort)
mprintf("WARNING: Ignoring deprecated option --%s (-%c)\n", longname, optshort);
else
mprintf("WARNING: Ignoring deprecated option --%s\n", longname);
return 0;
}
}
newnode = (struct optnode *) malloc(sizeof(struct optnode));
if(!newnode) {
mprintf("!register_long_option: malloc failed\n");
return -1;
}
newnode->optshort = optshort;
if(optarg) {
newnode->optarg = (char *) malloc(strlen(optarg) + 1);
if(!newnode->optarg) {
mprintf("!register_long_option: malloc failed\n");
free(newnode);
return -1;
}
strcpy(newnode->optarg, optarg);
} else
newnode->optarg = NULL;
newnode->optlong = (char *) malloc(strlen(longname) + 1);
if(!newnode->optlong) {
mprintf("ERROR: register_long_option: malloc failed\n");
free(newnode->optarg);
free(newnode);
return -1;
}
strcpy(newnode->optlong, longname);
newnode->next = opt->optlist;
opt->optlist = newnode;
return 0;
}
void opt_free(struct optstruct *opt)
{
struct optnode *handler, *prev;
if(!opt)
return;
handler = opt->optlist;
while(handler) {
if(handler->optarg)
free(handler->optarg);
if(handler->optlong)
free(handler->optlong);
prev = handler;
handler = handler->next;
free(prev);
}
if(opt->filename)
free(opt->filename);
free(opt);
}
struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long)
{
int ret, opt_index, i, len;
struct optstruct *opt;
const char *longname;
opt = (struct optstruct *) calloc(1, sizeof(struct optstruct));
if(!opt) {
mprintf("!opt_parse: calloc failed\n");
return NULL;
}
while(1) {
opt_index = 0;
ret = getopt_long(argc, argv, getopt_short, options_long, &opt_index);
if(ret == -1)
break;
switch(ret) {
case 0:
if(register_option(opt, options_long[opt_index].name, 0, options_long, accepted_long, deprecated_long) == -1) {
opt_free(opt);
return NULL;
}
break;
default:
if(strchr(getopt_short, ret)) {
if(opt_index)
longname = options_long[opt_index].name;
else
longname = NULL;
if(register_option(opt, longname, ret, options_long, accepted_long, deprecated_long) == -1) {
opt_free(opt);
return NULL;
}
} else {
mprintf("!Unknown option passed.\n");
opt_free(opt);
return NULL;
}
}
}
if(optind < argc) {
len = 0;
/* count length of non-option arguments */
for(i = optind; i < argc; i++)
len += strlen(argv[i]);
len += argc - optind - 1;
opt->filename = (char *) calloc(len + 64, sizeof(char));
if(!opt->filename) {
mprintf("!opt_parse: calloc failed\n");
opt_free(opt);
return NULL;
}
for(i = optind; i < argc; i++) {
strncat(opt->filename, argv[i], strlen(argv[i]));
if(i != argc - 1)
strncat(opt->filename, "\t", 1);
}
}
return opt;
}
int opt_check(const struct optstruct *opt, const char *optlong)
{
struct optnode *handler;
if(!opt) {
mprintf("!opt_check: opt == NULL\n");
return 0;
}
handler = opt->optlist;
while(handler) {
if(handler->optlong && !strcmp(handler->optlong, optlong))
return 1;
handler = handler->next;
}
return 0;
}
char *opt_arg(const struct optstruct *opt, const char *optlong)
{
struct optnode *handler;
if(!opt) {
mprintf("!opt_arg: opt == NULL\n");
return 0;
}
handler = opt->optlist;
while(handler) {
if(handler->optlong && !strcmp(handler->optlong, optlong))
return handler->optarg;
handler = handler->next;
}
return NULL;
}
char *opt_firstarg(const struct optstruct *opt, const char *optlong, const struct optnode **optnode)
{
const struct optnode *handler;
if(!opt) {
mprintf("!opt_firstarg: opt == NULL\n");
return 0;
}
handler = opt->optlist;
while(handler) {
if(handler->optlong && !strcmp(handler->optlong, optlong)) {
*optnode = handler;
return handler->optarg;
}
handler = handler->next;
}
*optnode = NULL;
return NULL;
}
char *opt_nextarg(const struct optnode **optnode, const char *optlong)
{
struct optnode *handler;
if(!optnode || !*optnode) {
mprintf("!opt_nextarg: *optnode == NULL\n");
return 0;
}
handler = (*optnode)->next;
while(handler) {
if(handler->optlong && !strcmp(handler->optlong, optlong)) {
*optnode = handler;
return handler->optarg;
}
handler = handler->next;
}
*optnode = NULL;
return NULL;
}

View file

@ -1,49 +0,0 @@
/*
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef __OPTIONS_H
#define __OPTIONS_H
#define _GNU_SOURCE
#include "getopt.h"
struct optnode {
char optshort;
char *optlong;
char *optarg;
struct optnode *next;
};
struct optstruct {
struct optnode *optlist;
char *filename;
};
void opt_free(struct optstruct *opt);
struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long);
int opt_check(const struct optstruct *opt, const char *optlong);
char *opt_arg(const struct optstruct *opt, const char *optlong);
char *opt_firstarg(const struct optstruct *opt, const char *optlong, const struct optnode **optnode);
char *opt_nextarg(const struct optnode **optnode, const char *optlong);
#endif

View file

@ -606,7 +606,7 @@ void optfree(struct optstruct *opts)
return; return;
} }
struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts) struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts)
{ {
FILE *fs = NULL; FILE *fs = NULL;
const struct clam_option *optentry; const struct clam_option *optentry;

View file

@ -49,6 +49,6 @@ const struct optstruct *optget(const struct optstruct *opts, const char *name);
void optfree(struct optstruct *opts); void optfree(struct optstruct *opts);
struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts); struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts);
#endif #endif