import libopm into opsb trunk
This commit is contained in:
parent
a413e33f66
commit
365871d30d
27 changed files with 5034 additions and 0 deletions
26
.gitattributes
vendored
26
.gitattributes
vendored
|
@ -6,6 +6,32 @@
|
||||||
/configure -text
|
/configure -text
|
||||||
/configure.in -text
|
/configure.in -text
|
||||||
/install-sh -text
|
/install-sh -text
|
||||||
|
libopm/.cvsignore -text
|
||||||
|
libopm/Makefile.am -text
|
||||||
|
libopm/Makefile.in -text
|
||||||
|
libopm/compat.c -text
|
||||||
|
libopm/compat.h -text
|
||||||
|
libopm/config.c -text
|
||||||
|
libopm/config.h -text
|
||||||
|
libopm/inet.c -text
|
||||||
|
libopm/inet.h -text
|
||||||
|
libopm/libopm.c -text
|
||||||
|
libopm/libopm.h -text
|
||||||
|
libopm/list.c -text
|
||||||
|
libopm/list.h -text
|
||||||
|
libopm/make -text
|
||||||
|
libopm/malloc.c -text
|
||||||
|
libopm/malloc.h -text
|
||||||
|
libopm/opm.h -text
|
||||||
|
libopm/opm_common.h -text
|
||||||
|
libopm/opm_error.h -text
|
||||||
|
libopm/opm_types.h -text
|
||||||
|
libopm/proxy.c -text
|
||||||
|
libopm/proxy.h -text
|
||||||
|
libopm/setup.h.in -text
|
||||||
|
libopm/snprintf.c -text
|
||||||
|
libopm/snprintf.h -text
|
||||||
|
libopm/test.c -text
|
||||||
/modconfig.h.in -text
|
/modconfig.h.in -text
|
||||||
/opsb.c -text
|
/opsb.c -text
|
||||||
/opsb.h -text
|
/opsb.h -text
|
||||||
|
|
10
libopm/.cvsignore
Normal file
10
libopm/.cvsignore
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
*.sw[op]
|
||||||
|
Makefile
|
||||||
|
*.lo
|
||||||
|
*.la
|
||||||
|
setup.h
|
||||||
|
stamp-h*
|
||||||
|
.deps
|
||||||
|
.libs
|
||||||
|
test
|
||||||
|
test_debug
|
19
libopm/Makefile.am
Normal file
19
libopm/Makefile.am
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
lib_LTLIBRARIES = libopm.la
|
||||||
|
|
||||||
|
libopm_la_SOURCES = compat.c compat.h config.c config.h inet.c inet.h \
|
||||||
|
libopm.c libopm.h list.c list.h malloc.c malloc.h opm_common.h \
|
||||||
|
opm_error.h opm.h opm_types.h proxy.c proxy.h setup.h
|
||||||
|
|
||||||
|
include_HEADERS = opm.h opm_error.h opm_types.h opm_common.h
|
||||||
|
|
||||||
|
libopm_la_LIBADD = @ETR_SOCKET_LIBS@ @LTLIBOBJS@
|
||||||
|
|
||||||
|
noinst_PROGRAMS = test test_debug
|
||||||
|
test_SOURCES = test.c
|
||||||
|
test_LDADD = libopm.la compat.o @LIBOBJS@
|
||||||
|
|
||||||
|
# An easier-to-debug version of test
|
||||||
|
|
||||||
|
test_debug_SOURCES = test.c
|
||||||
|
test_debug_LDADD = libopm.la compat.o @LIBOBJS@
|
||||||
|
test_debug_LDFLAGS = -static
|
452
libopm/Makefile.in
Normal file
452
libopm/Makefile.in
Normal file
|
@ -0,0 +1,452 @@
|
||||||
|
# Makefile.in generated by automake 1.6.3 from Makefile.am.
|
||||||
|
# @configure_input@
|
||||||
|
|
||||||
|
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
|
||||||
|
# Free Software Foundation, Inc.
|
||||||
|
# This Makefile.in is free software; the Free Software Foundation
|
||||||
|
# gives unlimited permission to copy and/or distribute it,
|
||||||
|
# with or without modifications, as long as this notice is preserved.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||||
|
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
# PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
@SET_MAKE@
|
||||||
|
SHELL = @SHELL@
|
||||||
|
|
||||||
|
srcdir = @srcdir@
|
||||||
|
top_srcdir = @top_srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
prefix = @prefix@
|
||||||
|
exec_prefix = @exec_prefix@
|
||||||
|
|
||||||
|
bindir = @bindir@
|
||||||
|
sbindir = @sbindir@
|
||||||
|
libexecdir = @libexecdir@
|
||||||
|
datadir = @datadir@
|
||||||
|
sysconfdir = @sysconfdir@
|
||||||
|
sharedstatedir = @sharedstatedir@
|
||||||
|
localstatedir = @localstatedir@
|
||||||
|
libdir = @libdir@
|
||||||
|
infodir = @infodir@
|
||||||
|
mandir = @mandir@
|
||||||
|
includedir = @includedir@
|
||||||
|
oldincludedir = /usr/include
|
||||||
|
pkgdatadir = $(datadir)/@PACKAGE@
|
||||||
|
pkglibdir = $(libdir)/@PACKAGE@
|
||||||
|
pkgincludedir = $(includedir)/@PACKAGE@
|
||||||
|
top_builddir = ..
|
||||||
|
|
||||||
|
ACLOCAL = @ACLOCAL@
|
||||||
|
AUTOCONF = @AUTOCONF@
|
||||||
|
AUTOMAKE = @AUTOMAKE@
|
||||||
|
AUTOHEADER = @AUTOHEADER@
|
||||||
|
|
||||||
|
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||||
|
INSTALL = @INSTALL@
|
||||||
|
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||||
|
INSTALL_DATA = @INSTALL_DATA@
|
||||||
|
install_sh_DATA = $(install_sh) -c -m 644
|
||||||
|
install_sh_PROGRAM = $(install_sh) -c
|
||||||
|
install_sh_SCRIPT = $(install_sh) -c
|
||||||
|
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||||
|
INSTALL_HEADER = $(INSTALL_DATA)
|
||||||
|
transform = @program_transform_name@
|
||||||
|
NORMAL_INSTALL = :
|
||||||
|
PRE_INSTALL = :
|
||||||
|
POST_INSTALL = :
|
||||||
|
NORMAL_UNINSTALL = :
|
||||||
|
PRE_UNINSTALL = :
|
||||||
|
POST_UNINSTALL = :
|
||||||
|
host_alias = @host_alias@
|
||||||
|
host_triplet = @host@
|
||||||
|
|
||||||
|
EXEEXT = @EXEEXT@
|
||||||
|
OBJEXT = @OBJEXT@
|
||||||
|
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||||
|
AMTAR = @AMTAR@
|
||||||
|
AS = @AS@
|
||||||
|
AWK = @AWK@
|
||||||
|
CC = @CC@
|
||||||
|
DEPDIR = @DEPDIR@
|
||||||
|
DLLTOOL = @DLLTOOL@
|
||||||
|
DOX_DIR_HTML = @DOX_DIR_HTML@
|
||||||
|
DOX_DIR_LATEX = @DOX_DIR_LATEX@
|
||||||
|
DOX_DIR_MAN = @DOX_DIR_MAN@
|
||||||
|
ECHO = @ECHO@
|
||||||
|
ETR_SOCKET_LIBS = @ETR_SOCKET_LIBS@
|
||||||
|
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||||
|
LIBTOOL = @LIBTOOL@
|
||||||
|
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||||
|
LNSL = @LNSL@
|
||||||
|
LN_S = @LN_S@
|
||||||
|
LSOCKET = @LSOCKET@
|
||||||
|
LTLIBOBJS = @LTLIBOBJS@
|
||||||
|
MAINT = @MAINT@
|
||||||
|
OBJDUMP = @OBJDUMP@
|
||||||
|
PACKAGE = @PACKAGE@
|
||||||
|
RANLIB = @RANLIB@
|
||||||
|
STRIP = @STRIP@
|
||||||
|
VERSION = @VERSION@
|
||||||
|
am__include = @am__include@
|
||||||
|
am__quote = @am__quote@
|
||||||
|
install_sh = @install_sh@
|
||||||
|
lib_LTLIBRARIES = libopm.la
|
||||||
|
|
||||||
|
libopm_la_SOURCES = compat.c compat.h config.c config.h inet.c inet.h \
|
||||||
|
libopm.c libopm.h list.c list.h malloc.c malloc.h opm_common.h \
|
||||||
|
opm_error.h opm.h opm_types.h proxy.c proxy.h setup.h
|
||||||
|
|
||||||
|
|
||||||
|
include_HEADERS = opm.h opm_error.h opm_types.h opm_common.h
|
||||||
|
|
||||||
|
libopm_la_LIBADD = @ETR_SOCKET_LIBS@ @LTLIBOBJS@
|
||||||
|
|
||||||
|
noinst_PROGRAMS = test test_debug
|
||||||
|
test_SOURCES = test.c
|
||||||
|
test_LDADD = libopm.la compat.o @LIBOBJS@
|
||||||
|
|
||||||
|
|
||||||
|
# An easier-to-debug version of test
|
||||||
|
test_debug_SOURCES = test.c
|
||||||
|
test_debug_LDADD = libopm.la compat.o @LIBOBJS@
|
||||||
|
test_debug_LDFLAGS = -static
|
||||||
|
subdir = src
|
||||||
|
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||||
|
CONFIG_HEADER = setup.h
|
||||||
|
CONFIG_CLEAN_FILES =
|
||||||
|
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||||
|
|
||||||
|
libopm_la_LDFLAGS =
|
||||||
|
libopm_la_DEPENDENCIES = @LTLIBOBJS@
|
||||||
|
am_libopm_la_OBJECTS = compat.lo config.lo inet.lo libopm.lo list.lo \
|
||||||
|
malloc.lo proxy.lo
|
||||||
|
libopm_la_OBJECTS = $(am_libopm_la_OBJECTS)
|
||||||
|
noinst_PROGRAMS = test$(EXEEXT) test_debug$(EXEEXT)
|
||||||
|
PROGRAMS = $(noinst_PROGRAMS)
|
||||||
|
|
||||||
|
am_test_OBJECTS = test.$(OBJEXT)
|
||||||
|
test_OBJECTS = $(am_test_OBJECTS)
|
||||||
|
test_DEPENDENCIES = libopm.la compat.o @LIBOBJS@
|
||||||
|
test_LDFLAGS =
|
||||||
|
am_test_debug_OBJECTS = test.$(OBJEXT)
|
||||||
|
test_debug_OBJECTS = $(am_test_debug_OBJECTS)
|
||||||
|
test_debug_DEPENDENCIES = libopm.la compat.o @LIBOBJS@
|
||||||
|
|
||||||
|
DEFS = @DEFS@
|
||||||
|
DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
|
||||||
|
CPPFLAGS = @CPPFLAGS@
|
||||||
|
LDFLAGS = @LDFLAGS@
|
||||||
|
LIBS = @LIBS@
|
||||||
|
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||||
|
am__depfiles_maybe = depfiles
|
||||||
|
@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/snprintf.Plo $(DEPDIR)/snprintf.Po \
|
||||||
|
@AMDEP_TRUE@ ./$(DEPDIR)/compat.Plo ./$(DEPDIR)/config.Plo \
|
||||||
|
@AMDEP_TRUE@ ./$(DEPDIR)/inet.Plo ./$(DEPDIR)/libopm.Plo \
|
||||||
|
@AMDEP_TRUE@ ./$(DEPDIR)/list.Plo ./$(DEPDIR)/malloc.Plo \
|
||||||
|
@AMDEP_TRUE@ ./$(DEPDIR)/proxy.Plo ./$(DEPDIR)/test.Po
|
||||||
|
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||||
|
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||||
|
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
|
||||||
|
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||||
|
CCLD = $(CC)
|
||||||
|
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||||
|
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||||
|
CFLAGS = @CFLAGS@
|
||||||
|
DIST_SOURCES = $(libopm_la_SOURCES) $(test_SOURCES) \
|
||||||
|
$(test_debug_SOURCES)
|
||||||
|
HEADERS = $(include_HEADERS)
|
||||||
|
|
||||||
|
DIST_COMMON = $(include_HEADERS) Makefile.am Makefile.in setup.h.in \
|
||||||
|
snprintf.c
|
||||||
|
SOURCES = $(libopm_la_SOURCES) $(test_SOURCES) $(test_debug_SOURCES)
|
||||||
|
|
||||||
|
all: setup.h
|
||||||
|
$(MAKE) $(AM_MAKEFLAGS) all-am
|
||||||
|
|
||||||
|
.SUFFIXES:
|
||||||
|
.SUFFIXES: .c .lo .o .obj
|
||||||
|
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||||
|
cd $(top_srcdir) && \
|
||||||
|
$(AUTOMAKE) --gnu src/Makefile
|
||||||
|
Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||||
|
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
|
||||||
|
|
||||||
|
setup.h: stamp-h1
|
||||||
|
@if test ! -f $@; then \
|
||||||
|
rm -f stamp-h1; \
|
||||||
|
$(MAKE) stamp-h1; \
|
||||||
|
else :; fi
|
||||||
|
|
||||||
|
stamp-h1: $(srcdir)/setup.h.in $(top_builddir)/config.status
|
||||||
|
@rm -f stamp-h1
|
||||||
|
cd $(top_builddir) && $(SHELL) ./config.status src/setup.h
|
||||||
|
|
||||||
|
$(srcdir)/setup.h.in: @MAINTAINER_MODE_TRUE@ $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||||
|
cd $(top_srcdir) && $(AUTOHEADER)
|
||||||
|
touch $(srcdir)/setup.h.in
|
||||||
|
|
||||||
|
distclean-hdr:
|
||||||
|
-rm -f setup.h stamp-h1
|
||||||
|
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||||
|
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||||
|
@$(NORMAL_INSTALL)
|
||||||
|
$(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||||
|
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||||
|
if test -f $$p; then \
|
||||||
|
f="`echo $$p | sed -e 's|^.*/||'`"; \
|
||||||
|
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(libdir)/$$f"; \
|
||||||
|
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(libdir)/$$f; \
|
||||||
|
else :; fi; \
|
||||||
|
done
|
||||||
|
|
||||||
|
uninstall-libLTLIBRARIES:
|
||||||
|
@$(NORMAL_UNINSTALL)
|
||||||
|
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||||
|
p="`echo $$p | sed -e 's|^.*/||'`"; \
|
||||||
|
echo " $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p"; \
|
||||||
|
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
|
||||||
|
done
|
||||||
|
|
||||||
|
clean-libLTLIBRARIES:
|
||||||
|
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||||
|
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||||
|
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||||
|
test -z "$dir" && dir=.; \
|
||||||
|
echo "rm -f \"$${dir}/so_locations\""; \
|
||||||
|
rm -f "$${dir}/so_locations"; \
|
||||||
|
done
|
||||||
|
libopm.la: $(libopm_la_OBJECTS) $(libopm_la_DEPENDENCIES)
|
||||||
|
$(LINK) -rpath $(libdir) $(libopm_la_LDFLAGS) $(libopm_la_OBJECTS) $(libopm_la_LIBADD) $(LIBS)
|
||||||
|
|
||||||
|
clean-noinstPROGRAMS:
|
||||||
|
@list='$(noinst_PROGRAMS)'; for p in $$list; do \
|
||||||
|
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||||
|
echo " rm -f $$p $$f"; \
|
||||||
|
rm -f $$p $$f ; \
|
||||||
|
done
|
||||||
|
test$(EXEEXT): $(test_OBJECTS) $(test_DEPENDENCIES)
|
||||||
|
@rm -f test$(EXEEXT)
|
||||||
|
$(LINK) $(test_LDFLAGS) $(test_OBJECTS) $(test_LDADD) $(LIBS)
|
||||||
|
test_debug$(EXEEXT): $(test_debug_OBJECTS) $(test_debug_DEPENDENCIES)
|
||||||
|
@rm -f test_debug$(EXEEXT)
|
||||||
|
$(LINK) $(test_debug_LDFLAGS) $(test_debug_OBJECTS) $(test_debug_LDADD) $(LIBS)
|
||||||
|
|
||||||
|
mostlyclean-compile:
|
||||||
|
-rm -f *.$(OBJEXT) core *.core
|
||||||
|
|
||||||
|
distclean-compile:
|
||||||
|
-rm -f *.tab.c
|
||||||
|
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/snprintf.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/snprintf.Po@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compat.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libopm.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/malloc.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proxy.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test.Po@am__quote@
|
||||||
|
|
||||||
|
distclean-depend:
|
||||||
|
-rm -rf $(DEPDIR) ./$(DEPDIR)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
|
||||||
|
|
||||||
|
.c.obj:
|
||||||
|
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
$(COMPILE) -c `cygpath -w $<`
|
||||||
|
|
||||||
|
.c.lo:
|
||||||
|
@AMDEP_TRUE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
|
||||||
|
CCDEPMODE = @CCDEPMODE@
|
||||||
|
|
||||||
|
mostlyclean-libtool:
|
||||||
|
-rm -f *.lo
|
||||||
|
|
||||||
|
clean-libtool:
|
||||||
|
-rm -rf .libs _libs
|
||||||
|
|
||||||
|
distclean-libtool:
|
||||||
|
-rm -f libtool
|
||||||
|
uninstall-info-am:
|
||||||
|
includeHEADERS_INSTALL = $(INSTALL_HEADER)
|
||||||
|
install-includeHEADERS: $(include_HEADERS)
|
||||||
|
@$(NORMAL_INSTALL)
|
||||||
|
$(mkinstalldirs) $(DESTDIR)$(includedir)
|
||||||
|
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||||
|
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||||
|
f="`echo $$p | sed -e 's|^.*/||'`"; \
|
||||||
|
echo " $(includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(includedir)/$$f"; \
|
||||||
|
$(includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(includedir)/$$f; \
|
||||||
|
done
|
||||||
|
|
||||||
|
uninstall-includeHEADERS:
|
||||||
|
@$(NORMAL_UNINSTALL)
|
||||||
|
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||||
|
f="`echo $$p | sed -e 's|^.*/||'`"; \
|
||||||
|
echo " rm -f $(DESTDIR)$(includedir)/$$f"; \
|
||||||
|
rm -f $(DESTDIR)$(includedir)/$$f; \
|
||||||
|
done
|
||||||
|
|
||||||
|
ETAGS = etags
|
||||||
|
ETAGSFLAGS =
|
||||||
|
|
||||||
|
tags: TAGS
|
||||||
|
|
||||||
|
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; } \
|
||||||
|
END { for (i in files) print i; }'`; \
|
||||||
|
mkid -fID $$unique
|
||||||
|
|
||||||
|
TAGS: $(HEADERS) $(SOURCES) setup.h.in $(TAGS_DEPENDENCIES) \
|
||||||
|
$(TAGS_FILES) $(LISP)
|
||||||
|
tags=; \
|
||||||
|
here=`pwd`; \
|
||||||
|
list='$(SOURCES) $(HEADERS) setup.h.in $(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; } \
|
||||||
|
END { for (i in files) print i; }'`; \
|
||||||
|
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|
||||||
|
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_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
|
||||||
|
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||||
|
|
||||||
|
top_distdir = ..
|
||||||
|
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
|
||||||
|
|
||||||
|
distdir: $(DISTFILES)
|
||||||
|
@list='$(DISTFILES)'; for file in $$list; do \
|
||||||
|
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||||
|
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||||
|
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||||
|
dir="/$$dir"; \
|
||||||
|
$(mkinstalldirs) "$(distdir)$$dir"; \
|
||||||
|
else \
|
||||||
|
dir=''; \
|
||||||
|
fi; \
|
||||||
|
if test -d $$d/$$file; then \
|
||||||
|
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||||
|
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||||
|
fi; \
|
||||||
|
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||||
|
else \
|
||||||
|
test -f $(distdir)/$$file \
|
||||||
|
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||||
|
|| exit 1; \
|
||||||
|
fi; \
|
||||||
|
done
|
||||||
|
check-am: all-am
|
||||||
|
check: check-am
|
||||||
|
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) setup.h
|
||||||
|
|
||||||
|
installdirs:
|
||||||
|
$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
|
||||||
|
|
||||||
|
install: install-am
|
||||||
|
install-exec: install-exec-am
|
||||||
|
install-data: install-data-am
|
||||||
|
uninstall: uninstall-am
|
||||||
|
|
||||||
|
install-am: all-am
|
||||||
|
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||||
|
|
||||||
|
installcheck: installcheck-am
|
||||||
|
install-strip:
|
||||||
|
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||||
|
INSTALL_STRIP_FLAG=-s \
|
||||||
|
`test -z '$(STRIP)' || \
|
||||||
|
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||||
|
mostlyclean-generic:
|
||||||
|
|
||||||
|
clean-generic:
|
||||||
|
|
||||||
|
distclean-generic:
|
||||||
|
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||||
|
|
||||||
|
maintainer-clean-generic:
|
||||||
|
@echo "This command is intended for maintainers to use"
|
||||||
|
@echo "it deletes files that may require special tools to rebuild."
|
||||||
|
clean: clean-am
|
||||||
|
|
||||||
|
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
|
||||||
|
clean-noinstPROGRAMS mostlyclean-am
|
||||||
|
|
||||||
|
distclean: distclean-am
|
||||||
|
|
||||||
|
distclean-am: clean-am distclean-compile distclean-depend \
|
||||||
|
distclean-generic distclean-hdr distclean-libtool \
|
||||||
|
distclean-tags
|
||||||
|
|
||||||
|
dvi: dvi-am
|
||||||
|
|
||||||
|
dvi-am:
|
||||||
|
|
||||||
|
info: info-am
|
||||||
|
|
||||||
|
info-am:
|
||||||
|
|
||||||
|
install-data-am: install-includeHEADERS
|
||||||
|
|
||||||
|
install-exec-am: install-libLTLIBRARIES
|
||||||
|
|
||||||
|
install-info: install-info-am
|
||||||
|
|
||||||
|
install-man:
|
||||||
|
|
||||||
|
installcheck-am:
|
||||||
|
|
||||||
|
maintainer-clean: maintainer-clean-am
|
||||||
|
|
||||||
|
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||||
|
|
||||||
|
mostlyclean: mostlyclean-am
|
||||||
|
|
||||||
|
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||||
|
mostlyclean-libtool
|
||||||
|
|
||||||
|
uninstall-am: uninstall-includeHEADERS uninstall-info-am \
|
||||||
|
uninstall-libLTLIBRARIES
|
||||||
|
|
||||||
|
.PHONY: GTAGS all all-am check check-am clean clean-generic \
|
||||||
|
clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS \
|
||||||
|
distclean distclean-compile distclean-depend distclean-generic \
|
||||||
|
distclean-hdr distclean-libtool distclean-tags distdir dvi \
|
||||||
|
dvi-am info info-am install install-am install-data \
|
||||||
|
install-data-am install-exec install-exec-am \
|
||||||
|
install-includeHEADERS install-info install-info-am \
|
||||||
|
install-libLTLIBRARIES install-man install-strip installcheck \
|
||||||
|
installcheck-am installdirs maintainer-clean \
|
||||||
|
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||||
|
mostlyclean-generic mostlyclean-libtool tags uninstall \
|
||||||
|
uninstall-am uninstall-includeHEADERS uninstall-info-am \
|
||||||
|
uninstall-libLTLIBRARIES
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
.NOEXPORT:
|
70
libopm/compat.c
Normal file
70
libopm/compat.c
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/* vim: set shiftwidth=3 softtabstop=3 expandtab: */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002 Andy Smith
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef STDC_HEADERS
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_INET_ATON
|
||||||
|
# include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
#include "opm.h"
|
||||||
|
|
||||||
|
RCSID("$Id: compat.c,v 1.3 2003/01/11 06:18:41 andy Exp $");
|
||||||
|
|
||||||
|
#ifndef HAVE_INET_ATON
|
||||||
|
/*
|
||||||
|
* An implementation of inet_aton for those systems that don't have it
|
||||||
|
* (Solaris, ...)
|
||||||
|
*/
|
||||||
|
int libopm_inet_aton(const char *cp, struct in_addr *inp)
|
||||||
|
{
|
||||||
|
unsigned int a1, a2, a3, a4;
|
||||||
|
unsigned long ret;
|
||||||
|
|
||||||
|
if (strcmp(cp, "255.255.255.255") == 0) {
|
||||||
|
inp->s_addr = (unsigned) -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 ||
|
||||||
|
a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4;
|
||||||
|
|
||||||
|
inp->s_addr = htonl(ret);
|
||||||
|
|
||||||
|
if (inp->s_addr == (unsigned) -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
29
libopm/compat.h
Normal file
29
libopm/compat.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef COMPAT_H
|
||||||
|
#define COMPAT_H
|
||||||
|
|
||||||
|
#ifndef INADDR_NONE
|
||||||
|
#define INADDR_NONE 0xffffffff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_INET_ATON
|
||||||
|
#undef inet_aton
|
||||||
|
#define inet_aton libopm_inet_aton
|
||||||
|
extern int libopm_inet_aton(const char *cp, struct in_addr *inp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_SNPRINTF
|
||||||
|
#undef snprintf
|
||||||
|
#define snprintf libopm_snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_VSNPRINTF
|
||||||
|
#undef vsnprintf
|
||||||
|
#define vsnprintf libopm_vsnprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_INET_PTON
|
||||||
|
#undef inet_pton
|
||||||
|
#define inet_pton libopm_inet_pton
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
264
libopm/config.c
Normal file
264
libopm/config.c
Normal file
|
@ -0,0 +1,264 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002 Erik Fears
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include "malloc.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "inet.h"
|
||||||
|
#include "opm_error.h"
|
||||||
|
#include "opm_types.h"
|
||||||
|
#include "opm_common.h"
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
|
#ifdef STDC_HEADERS
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RCSID("$Id: config.c,v 1.27 2003/06/20 04:18:44 andy Exp $");
|
||||||
|
|
||||||
|
static OPM_CONFIG_HASH_T HASH[] = {
|
||||||
|
{OPM_CONFIG_FD_LIMIT, OPM_TYPE_INT},
|
||||||
|
{OPM_CONFIG_BIND_IP , OPM_TYPE_ADDRESS},
|
||||||
|
{OPM_CONFIG_DNSBL_HOST, OPM_TYPE_STRING},
|
||||||
|
{OPM_CONFIG_TARGET_STRING, OPM_TYPE_STRINGLIST},
|
||||||
|
{OPM_CONFIG_SCAN_IP, OPM_TYPE_STRING},
|
||||||
|
{OPM_CONFIG_SCAN_PORT, OPM_TYPE_INT},
|
||||||
|
{OPM_CONFIG_MAX_READ, OPM_TYPE_INT},
|
||||||
|
{OPM_CONFIG_TIMEOUT, OPM_TYPE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* config_create
|
||||||
|
*
|
||||||
|
* Create an OPM_CONFIG_T struct, set default values and return it
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* None;
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* Pointer to allocated OPM_CONFIG_T struct
|
||||||
|
*/
|
||||||
|
|
||||||
|
OPM_CONFIG_T *libopm_config_create()
|
||||||
|
{
|
||||||
|
int num, i;
|
||||||
|
OPM_CONFIG_T *ret;
|
||||||
|
|
||||||
|
num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T);
|
||||||
|
|
||||||
|
ret = MyMalloc(sizeof(OPM_CONFIG_T));
|
||||||
|
ret->vars = MyMalloc(sizeof(void *) * num);
|
||||||
|
|
||||||
|
|
||||||
|
/* Set default config items. This in the future would be much better
|
||||||
|
if it could set realistic defaults for each individual config item.
|
||||||
|
|
||||||
|
OPM_TYPE_INT = 0
|
||||||
|
OPM_TYPE_STRING = ""
|
||||||
|
OPM_TYPE_ADDRESS = 0.0.0.0
|
||||||
|
OPM_TYPE_STRINGLIST = empty list
|
||||||
|
*/
|
||||||
|
|
||||||
|
for(i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
switch(libopm_config_gettype(i))
|
||||||
|
{
|
||||||
|
case OPM_TYPE_INT:
|
||||||
|
ret->vars[i] = MyMalloc(sizeof(int));
|
||||||
|
*(int *) ret->vars[i] = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPM_TYPE_STRING:
|
||||||
|
(char *) ret->vars[i] = strdup("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPM_TYPE_ADDRESS:
|
||||||
|
(opm_sockaddr *) ret->vars[i] = MyMalloc(sizeof(opm_sockaddr));
|
||||||
|
memset((opm_sockaddr *) ret->vars[i], 0, sizeof(opm_sockaddr));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPM_TYPE_STRINGLIST:
|
||||||
|
(OPM_LIST_T *) ret->vars[i] = libopm_list_create();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret->vars[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* config_free
|
||||||
|
*
|
||||||
|
* Free config structure and clean up
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* config: Structure to free/cleanup
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void libopm_config_free(OPM_CONFIG_T *config)
|
||||||
|
{
|
||||||
|
int num, i;
|
||||||
|
OPM_NODE_T *p, *next;
|
||||||
|
OPM_LIST_T *list;
|
||||||
|
|
||||||
|
num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T);
|
||||||
|
|
||||||
|
for(i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
if(config->vars[i] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
switch(libopm_config_gettype(i))
|
||||||
|
{
|
||||||
|
case OPM_TYPE_STRINGLIST:
|
||||||
|
list = (OPM_LIST_T *) config->vars[i];
|
||||||
|
LIST_FOREACH_SAFE(p, next, list->head)
|
||||||
|
{
|
||||||
|
MyFree(p->data);
|
||||||
|
MyFree(p);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
MyFree(config->vars[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MyFree(config->vars);
|
||||||
|
MyFree(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* config_set
|
||||||
|
*
|
||||||
|
* Set configuration options on config struct.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* config: Config struct to set parameters on
|
||||||
|
* key: Variable within the struct to set
|
||||||
|
* value: Address of value to set
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* 1: Variable was set
|
||||||
|
* 0: Some error occured
|
||||||
|
*/
|
||||||
|
|
||||||
|
OPM_ERR_T libopm_config_set(OPM_CONFIG_T *config, int key, void *value)
|
||||||
|
{
|
||||||
|
|
||||||
|
int num;
|
||||||
|
OPM_NODE_T *node;
|
||||||
|
|
||||||
|
num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T);
|
||||||
|
|
||||||
|
if(key < 0 || key >= num)
|
||||||
|
return OPM_ERR_BADKEY; /* Return appropriate error code eventually */
|
||||||
|
|
||||||
|
switch(libopm_config_gettype(key))
|
||||||
|
{
|
||||||
|
case OPM_TYPE_STRING:
|
||||||
|
if((char *) config->vars[key] != NULL)
|
||||||
|
MyFree(config->vars[key]);
|
||||||
|
(char *) config->vars[key] = strdup((char *) value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPM_TYPE_INT:
|
||||||
|
*(int *) config->vars[key] = *(int *) value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPM_TYPE_ADDRESS:
|
||||||
|
if( inet_pton(AF_INET, (char *) value, &( ((opm_sockaddr *)config->vars[key])->sa4.sin_addr))
|
||||||
|
<= 0)
|
||||||
|
return OPM_ERR_BADVALUE; /* return appropriate err code */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPM_TYPE_STRINGLIST:
|
||||||
|
node = libopm_node_create(strdup((char *) value));
|
||||||
|
libopm_list_add((OPM_LIST_T *) config->vars[key], node);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return OPM_ERR_BADKEY; /* return appropriate err code */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* config_gettype
|
||||||
|
*
|
||||||
|
* Get type of key.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* key: Key to get type of.
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* TYPE_? of key
|
||||||
|
*/
|
||||||
|
|
||||||
|
int libopm_config_gettype(int key)
|
||||||
|
{
|
||||||
|
int num, i;
|
||||||
|
|
||||||
|
num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T);
|
||||||
|
|
||||||
|
for(i = 0; i < num; i++)
|
||||||
|
if(HASH[i].key == key)
|
||||||
|
return HASH[i].type;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* config
|
||||||
|
*
|
||||||
|
* Retrieve a specific config variable from
|
||||||
|
* an OPM_CONFIG_T struct. This is basically a
|
||||||
|
* wrapper to extracting the variable from the
|
||||||
|
* array.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* config: Config struct to extract from
|
||||||
|
* key: Value to extract
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* -ADDRESS- to extracted value in array. This address
|
||||||
|
* will have to be cast on the return end to be any use.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *libopm_config(OPM_CONFIG_T *config, int key)
|
||||||
|
{
|
||||||
|
return config->vars[key];
|
||||||
|
}
|
20
libopm/config.h
Normal file
20
libopm/config.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#include "libopm.h"
|
||||||
|
|
||||||
|
typedef struct _opm_config_hash OPM_CONFIG_HASH_T;
|
||||||
|
|
||||||
|
struct _opm_config_hash {
|
||||||
|
int key;
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
void libopm_config_free(OPM_CONFIG_T *);
|
||||||
|
void *libopm_config(OPM_CONFIG_T *, int);
|
||||||
|
int libopm_config_gettype(int);
|
||||||
|
OPM_CONFIG_T *libopm_config_create(void);
|
||||||
|
OPM_ERR_T libopm_config_set(OPM_CONFIG_T *, int , void *);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CONFIG_H */
|
534
libopm/inet.c
Normal file
534
libopm/inet.c
Normal file
|
@ -0,0 +1,534 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2002 by the past and present ircd coders, and others.
|
||||||
|
|
||||||
|
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.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This code is borrowed from ircd-hybrid version 7
|
||||||
|
* -TimeMr14C
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#if STDC_HEADERS
|
||||||
|
# include <string.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#include "inet.h"
|
||||||
|
#include "opm.h"
|
||||||
|
|
||||||
|
#ifndef INADDRSZ
|
||||||
|
#define INADDRSZ 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IPV6
|
||||||
|
#ifndef IN6ADDRSZ
|
||||||
|
#define IN6ADDRSZ 16
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef INT16SZ
|
||||||
|
#define INT16SZ 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IPV6
|
||||||
|
#define HOSTIPLEN 53
|
||||||
|
#else
|
||||||
|
#define HOSTIPLEN 15
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RCSID("$Id: inet.c,v 1.7 2003/06/20 04:18:44 andy Exp $");
|
||||||
|
|
||||||
|
extern const unsigned char ToLowerTab[];
|
||||||
|
#define ToLower(c) (ToLowerTab[(unsigned char)(c)])
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From: Thomas Helvey <tomh@inxpress.net>
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
static const char *IpQuadTab[] = {
|
||||||
|
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||||
|
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
|
||||||
|
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
|
||||||
|
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
|
||||||
|
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
|
||||||
|
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
|
||||||
|
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
|
||||||
|
"70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
|
||||||
|
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
|
||||||
|
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
|
||||||
|
"100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
|
||||||
|
"110", "111", "112", "113", "114", "115", "116", "117", "118", "119",
|
||||||
|
"120", "121", "122", "123", "124", "125", "126", "127", "128", "129",
|
||||||
|
"130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
|
||||||
|
"140", "141", "142", "143", "144", "145", "146", "147", "148", "149",
|
||||||
|
"150", "151", "152", "153", "154", "155", "156", "157", "158", "159",
|
||||||
|
"160", "161", "162", "163", "164", "165", "166", "167", "168", "169",
|
||||||
|
"170", "171", "172", "173", "174", "175", "176", "177", "178", "179",
|
||||||
|
"180", "181", "182", "183", "184", "185", "186", "187", "188", "189",
|
||||||
|
"190", "191", "192", "193", "194", "195", "196", "197", "198", "199",
|
||||||
|
"200", "201", "202", "203", "204", "205", "206", "207", "208", "209",
|
||||||
|
"210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
|
||||||
|
"220", "221", "222", "223", "224", "225", "226", "227", "228", "229",
|
||||||
|
"230", "231", "232", "233", "234", "235", "236", "237", "238", "239",
|
||||||
|
"240", "241", "242", "243", "244", "245", "246", "247", "248", "249",
|
||||||
|
"250", "251", "252", "253", "254", "255"
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* inetntoa - in_addr to string
|
||||||
|
* changed name to remove collision possibility and
|
||||||
|
* so behaviour is guaranteed to take a pointer arg.
|
||||||
|
* -avalon 23/11/92
|
||||||
|
* inet_ntoa -- returned the dotted notation of a given
|
||||||
|
* internet number
|
||||||
|
* argv 11/90).
|
||||||
|
* inet_ntoa -- its broken on some Ultrix/Dynix too. -avalon
|
||||||
|
*
|
||||||
|
* XXX - Again not used anywhere?
|
||||||
|
* -grifferz
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static char *inetntoa(char *in)
|
||||||
|
{
|
||||||
|
static char buf[16];
|
||||||
|
register char *bufptr = buf;
|
||||||
|
register const unsigned char *a = (const unsigned char *) in;
|
||||||
|
register const char *n;
|
||||||
|
|
||||||
|
n = IpQuadTab[*a++];
|
||||||
|
while (*n)
|
||||||
|
*bufptr++ = *n++;
|
||||||
|
*bufptr++ = '.';
|
||||||
|
n = IpQuadTab[*a++];
|
||||||
|
while (*n)
|
||||||
|
*bufptr++ = *n++;
|
||||||
|
*bufptr++ = '.';
|
||||||
|
n = IpQuadTab[*a++];
|
||||||
|
while (*n)
|
||||||
|
*bufptr++ = *n++;
|
||||||
|
*bufptr++ = '.';
|
||||||
|
n = IpQuadTab[*a];
|
||||||
|
while (*n)
|
||||||
|
*bufptr++ = *n++;
|
||||||
|
*bufptr = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1996-1999 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING: Don't even consider trying to compile this on a system where
|
||||||
|
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX - this does not seem to be used anywhere currently.
|
||||||
|
* -grifferz
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
static const char *inet_ntop4(const u_char *src, char *dst, unsigned int size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IPV6
|
||||||
|
static const char *inet_ntop6(const u_char *src, char *dst, unsigned int size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* const char *
|
||||||
|
* inet_ntop4(src, dst, size)
|
||||||
|
* format an IPv4 address
|
||||||
|
* return:
|
||||||
|
* `dst' (as a const)
|
||||||
|
* notes:
|
||||||
|
* (1) uses no statics
|
||||||
|
* (2) takes a u_char* not an in_addr as input
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*
|
||||||
|
* XXX - this does not seem to be used anywhere currently.
|
||||||
|
* -grifferz
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
static const char *inet_ntop4(const unsigned char *src, char *dst, unsigned int size)
|
||||||
|
{
|
||||||
|
if (size < 15)
|
||||||
|
return NULL;
|
||||||
|
return strcpy(dst, inetntoa((char *) src));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* const char *
|
||||||
|
* inet_ntop6(src, dst, size)
|
||||||
|
* convert IPv6 binary address into presentation (printable) format
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
#ifdef IPV6
|
||||||
|
static const char *inet_ntop6(const unsigned char *src, char *dst, unsigned int size)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Note that int32_t and int16_t need only be "at least" large enough
|
||||||
|
* to contain a value of the specified size. On some systems, like
|
||||||
|
* Crays, there is no such thing as an integer variable with 16 bits.
|
||||||
|
* Keep this in mind if you think this function should have been coded
|
||||||
|
* to use pointer overlays. All the world's not a VAX.
|
||||||
|
*/
|
||||||
|
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
|
||||||
|
struct {
|
||||||
|
int base, len;
|
||||||
|
} best, cur;
|
||||||
|
u_int words[IN6ADDRSZ / INT16SZ];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Preprocess:
|
||||||
|
* Copy the input (bytewise) array into a wordwise array.
|
||||||
|
* Find the longest run of 0x00's in src[] for :: shorthanding.
|
||||||
|
*/
|
||||||
|
memset(words, '\0', sizeof words);
|
||||||
|
for (i = 0; i < IN6ADDRSZ; i += 2)
|
||||||
|
words[i / 2] = (src[i] << 8) | src[i + 1];
|
||||||
|
best.base = -1;
|
||||||
|
cur.base = -1;
|
||||||
|
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
|
||||||
|
if (words[i] == 0) {
|
||||||
|
if (cur.base == -1)
|
||||||
|
cur.base = i, cur.len = 1;
|
||||||
|
else
|
||||||
|
cur.len++;
|
||||||
|
} else {
|
||||||
|
if (cur.base != -1) {
|
||||||
|
if (best.base == -1 || cur.len > best.len)
|
||||||
|
best = cur;
|
||||||
|
cur.base = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cur.base != -1) {
|
||||||
|
if (best.base == -1 || cur.len > best.len)
|
||||||
|
best = cur;
|
||||||
|
}
|
||||||
|
if (best.base != -1 && best.len < 2)
|
||||||
|
best.base = -1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Format the result.
|
||||||
|
*/
|
||||||
|
tp = tmp;
|
||||||
|
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
|
||||||
|
/* Are we inside the best run of 0x00's? */
|
||||||
|
if (best.base != -1 && i >= best.base && i < (best.base + best.len)) {
|
||||||
|
if (i == best.base)
|
||||||
|
*tp++ = ':';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* Are we following an initial run of 0x00s or any real hex? */
|
||||||
|
if (i != 0)
|
||||||
|
*tp++ = ':';
|
||||||
|
/* Is this address an encapsulated IPv4? */
|
||||||
|
if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
|
||||||
|
if (!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp)))
|
||||||
|
return (NULL);
|
||||||
|
tp += strlen(tp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tp += sprintf(tp, "%x", words[i]);
|
||||||
|
}
|
||||||
|
/* Was it a trailing run of 0x00's? */
|
||||||
|
if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
|
||||||
|
*tp++ = ':';
|
||||||
|
|
||||||
|
*tp++ = '\0';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for overflow, copy, and we're done.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((tp - tmp) > size) {
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return strcpy(dst, tmp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This code doesn't seem to be used anywhere currently?
|
||||||
|
* -grifferz
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* char *
|
||||||
|
* inetntop(af, src, dst, size)
|
||||||
|
* convert a network format address to presentation format.
|
||||||
|
* return:
|
||||||
|
* pointer to presentation format address (`dst'), or NULL (see errno).
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
const char *inetntop(int af, const void *src, char *dst, unsigned int size)
|
||||||
|
{
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
return (inet_ntop4(src, dst, size));
|
||||||
|
#ifdef IPV6
|
||||||
|
case AF_INET6:
|
||||||
|
if (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *) src) ||
|
||||||
|
IN6_IS_ADDR_V4COMPAT((const struct in6_addr *) src))
|
||||||
|
return (inet_ntop4
|
||||||
|
((unsigned char *) &((struct in6_addr *) src)->s6_addr[12], dst, size));
|
||||||
|
else
|
||||||
|
return (inet_ntop6(src, dst, size));
|
||||||
|
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING: Don't even consider trying to compile this on a system where
|
||||||
|
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* inet_pton(af, src, dst)
|
||||||
|
* convert from presentation format (which usually means ASCII printable)
|
||||||
|
* to network format (which is usually some kind of binary format).
|
||||||
|
* return:
|
||||||
|
* 1 if the address was valid for the specified address family
|
||||||
|
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
||||||
|
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* inet_pton4(src, dst)
|
||||||
|
* like inet_aton() but without all the hexadecimal and shorthand.
|
||||||
|
* return:
|
||||||
|
* 1 if `src' is a valid dotted quad, else 0.
|
||||||
|
* notice:
|
||||||
|
* does not touch `dst' unless it's returning 1.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAVE_INET_PTON
|
||||||
|
|
||||||
|
static int inet_pton4(src, dst)
|
||||||
|
const char *src;
|
||||||
|
unsigned char *dst;
|
||||||
|
{
|
||||||
|
int saw_digit, octets, ch;
|
||||||
|
unsigned char tmp[INADDRSZ], *tp;
|
||||||
|
|
||||||
|
saw_digit = 0;
|
||||||
|
octets = 0;
|
||||||
|
*(tp = tmp) = 0;
|
||||||
|
while ((ch = *src++) != '\0') {
|
||||||
|
|
||||||
|
if (ch >= '0' && ch <= '9') {
|
||||||
|
unsigned int new = *tp * 10 + (ch - '0');
|
||||||
|
|
||||||
|
if (new > 255)
|
||||||
|
return (0);
|
||||||
|
*tp = new;
|
||||||
|
if (!saw_digit) {
|
||||||
|
if (++octets > 4)
|
||||||
|
return (0);
|
||||||
|
saw_digit = 1;
|
||||||
|
}
|
||||||
|
} else if (ch == '.' && saw_digit) {
|
||||||
|
if (octets == 4)
|
||||||
|
return (0);
|
||||||
|
*++tp = 0;
|
||||||
|
saw_digit = 0;
|
||||||
|
} else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (octets < 4)
|
||||||
|
return (0);
|
||||||
|
memcpy(dst, tmp, INADDRSZ);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef IPV6
|
||||||
|
/* int
|
||||||
|
* inet_pton6(src, dst)
|
||||||
|
* convert presentation level address to network order binary form.
|
||||||
|
* return:
|
||||||
|
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
||||||
|
* notice:
|
||||||
|
* (1) does not touch `dst' unless it's returning 1.
|
||||||
|
* (2) :: in a full address is silently ignored.
|
||||||
|
* credit:
|
||||||
|
* inspired by Mark Andrews.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int inet_pton6(src, dst)
|
||||||
|
const char *src;
|
||||||
|
unsigned char *dst;
|
||||||
|
{
|
||||||
|
static const char xdigits[] = "0123456789abcdef";
|
||||||
|
unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
|
||||||
|
const char *curtok;
|
||||||
|
int ch, saw_xdigit;
|
||||||
|
unsigned int val;
|
||||||
|
|
||||||
|
tp = memset(tmp, '\0', IN6ADDRSZ);
|
||||||
|
endp = tp + IN6ADDRSZ;
|
||||||
|
colonp = NULL;
|
||||||
|
/* Leading :: requires some special handling. */
|
||||||
|
if (*src == ':')
|
||||||
|
if (*++src != ':')
|
||||||
|
return (0);
|
||||||
|
curtok = src;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
val = 0;
|
||||||
|
while ((ch = ToLower(*src++)) != '\0') {
|
||||||
|
const char *pch;
|
||||||
|
|
||||||
|
pch = strchr(xdigits, ch);
|
||||||
|
if (pch != NULL) {
|
||||||
|
val <<= 4;
|
||||||
|
val |= (pch - xdigits);
|
||||||
|
if (val > 0xffff)
|
||||||
|
return (0);
|
||||||
|
saw_xdigit = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch == ':') {
|
||||||
|
curtok = src;
|
||||||
|
if (!saw_xdigit) {
|
||||||
|
if (colonp)
|
||||||
|
return (0);
|
||||||
|
colonp = tp;
|
||||||
|
continue;
|
||||||
|
} else if (*src == '\0') {
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (tp + INT16SZ > endp)
|
||||||
|
return (0);
|
||||||
|
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||||
|
*tp++ = (unsigned char) val & 0xff;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
val = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*src != '\0' && ch == '.') {
|
||||||
|
if (((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) {
|
||||||
|
tp += INADDRSZ;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
break; /* '\0' was seen by inet_pton4(). */
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
continue;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (saw_xdigit) {
|
||||||
|
if (tp + INT16SZ > endp)
|
||||||
|
return (0);
|
||||||
|
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||||
|
*tp++ = (unsigned char) val & 0xff;
|
||||||
|
}
|
||||||
|
if (colonp != NULL) {
|
||||||
|
/*
|
||||||
|
* Since some memmove()'s erroneously fail to handle
|
||||||
|
* overlapping regions, we'll do the shift by hand.
|
||||||
|
*/
|
||||||
|
const int n = tp - colonp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (tp == endp)
|
||||||
|
return (0);
|
||||||
|
for (i = 1; i <= n; i++) {
|
||||||
|
endp[-i] = colonp[n - i];
|
||||||
|
colonp[n - i] = 0;
|
||||||
|
}
|
||||||
|
tp = endp;
|
||||||
|
}
|
||||||
|
if (tp != endp)
|
||||||
|
return (0);
|
||||||
|
memcpy(dst, tmp, IN6ADDRSZ);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
#endif /* IPv6 */
|
||||||
|
|
||||||
|
int inet_pton(af, src, dst)
|
||||||
|
int af;
|
||||||
|
const char *src;
|
||||||
|
void *dst;
|
||||||
|
{
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
return (inet_pton4(src, dst));
|
||||||
|
#ifdef IPV6
|
||||||
|
case AF_INET6:
|
||||||
|
/* Somebody might have passed as an IPv4 address this is sick but it works */
|
||||||
|
if (inet_pton4(src, dst)) {
|
||||||
|
char tmp[HOSTIPLEN];
|
||||||
|
sprintf(tmp, "::ffff:%s", src);
|
||||||
|
return (inet_pton6(tmp, dst));
|
||||||
|
} else
|
||||||
|
return (inet_pton6(src, dst));
|
||||||
|
#endif /* IPv6 */
|
||||||
|
default:
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
40
libopm/inet.h
Normal file
40
libopm/inet.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef INET_H
|
||||||
|
#define INET_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#ifdef HAVE_FCNTL_H
|
||||||
|
# include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_POLL_H
|
||||||
|
# include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef AF_INET6
|
||||||
|
# define AF_INET6 10
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct _opm_sockaddr opm_sockaddr;
|
||||||
|
typedef struct _opm_inaddr opm_inaddr;
|
||||||
|
|
||||||
|
struct _opm_sockaddr {
|
||||||
|
struct sockaddr_in sa4;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _opm_inaddr {
|
||||||
|
struct in_addr in4;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef HAVE_INET_PTON
|
||||||
|
extern int inet_pton(int, const char *, void *);
|
||||||
|
#endif
|
||||||
|
extern const char *inetntop(int, const void *, char *, unsigned int);
|
||||||
|
extern struct hostent *opm_gethostbyname(const char *);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* INET_H */
|
1432
libopm/libopm.c
Normal file
1432
libopm/libopm.c
Normal file
File diff suppressed because it is too large
Load diff
58
libopm/libopm.h
Normal file
58
libopm/libopm.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef LIBOPM_H
|
||||||
|
#define LIBOPM_H
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "inet.h"
|
||||||
|
#include "opm_common.h"
|
||||||
|
#include "opm.h"
|
||||||
|
|
||||||
|
#define CBLEN 5 /* Number of callback functions */
|
||||||
|
#define READBUFLEN 128 /* Size of conn->readbuf */
|
||||||
|
#define SENDBUFLEN 512 /* Size of sendbuffer in proxy.c */
|
||||||
|
|
||||||
|
typedef struct _OPM_SCAN OPM_SCAN_T;
|
||||||
|
typedef struct _OPM_CONNECTION OPM_CONNECTION_T;
|
||||||
|
typedef struct _OPM_PROTOCOL_CONFIG OPM_PROTOCOL_CONFIG_T;
|
||||||
|
typedef struct _OPM_PROTOCOL OPM_PROTOCOL_T;
|
||||||
|
|
||||||
|
/* Types of hard coded proxy READ/WRITE functions which are
|
||||||
|
setup in a table in libopm.c */
|
||||||
|
|
||||||
|
typedef int OPM_PROXYWRITE_T (OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
typedef int OPM_PROXYREAD_T (OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
|
||||||
|
struct _OPM_SCAN {
|
||||||
|
opm_sockaddr addr; /* Address in byte order of remote client */
|
||||||
|
OPM_REMOTE_T *remote; /* Pointed to the OPM_REMOTE_T for this scan, passed by client */
|
||||||
|
OPM_LIST_T *connections; /* List of individual connections of this scan (1 for each protocol) */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _OPM_CONNECTION {
|
||||||
|
|
||||||
|
OPM_PROTOCOL_T *protocol; /* Pointer to specific protocol this connection handles */
|
||||||
|
unsigned short int port; /* Some protocols have multiple ports, eg. HTTP */
|
||||||
|
|
||||||
|
int fd; /* Allocated file descriptor, 0 if not yet allocated */
|
||||||
|
unsigned short int bytes_read; /* Bytes read so far in this connection */
|
||||||
|
char readbuf[READBUFLEN + 1]; /* 128 byte read buffer, anything over 128 is probably not of use */
|
||||||
|
unsigned short int readlen; /* Length of readbuf */
|
||||||
|
unsigned short int state; /* State of connection */
|
||||||
|
time_t creation; /* When this connection was established */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _OPM_PROTOCOL_CONFIG
|
||||||
|
{
|
||||||
|
OPM_PROTOCOL_T *type; /* Protocol type */
|
||||||
|
unsigned short int port; /* Port to connect on */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _OPM_PROTOCOL
|
||||||
|
{
|
||||||
|
int type; /* Protocol type */
|
||||||
|
|
||||||
|
OPM_PROXYWRITE_T *write_function; /* Write function handler for this protocol */
|
||||||
|
OPM_PROXYREAD_T *read_function; /* Read function handler for this protocol */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* LIBOPM_H */
|
119
libopm/list.c
Normal file
119
libopm/list.c
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002-2003 Erik Fears
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include "opm_common.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "malloc.h"
|
||||||
|
#include "opm.h"
|
||||||
|
|
||||||
|
RCSID("$Id: list.c,v 1.11 2003/06/27 18:51:02 strtok Exp $");
|
||||||
|
|
||||||
|
OPM_NODE_T *libopm_node_create(void *data)
|
||||||
|
{
|
||||||
|
OPM_NODE_T *node = MyMalloc(sizeof *node);
|
||||||
|
node->next = NULL;
|
||||||
|
node->prev = NULL;
|
||||||
|
node->data = (void *) data;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
OPM_LIST_T *libopm_list_create()
|
||||||
|
{
|
||||||
|
OPM_LIST_T *list = MyMalloc(sizeof *list);
|
||||||
|
|
||||||
|
list->head = NULL;
|
||||||
|
list->tail = NULL;
|
||||||
|
|
||||||
|
list->elements = 0;
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
OPM_NODE_T *libopm_list_add(OPM_LIST_T *list, OPM_NODE_T *node)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(list == NULL || node == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(list->tail == NULL)
|
||||||
|
{
|
||||||
|
list->head = node;
|
||||||
|
list->tail = node;
|
||||||
|
|
||||||
|
node->next = NULL;
|
||||||
|
node->prev = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node->prev = list->tail;
|
||||||
|
list->tail->next = node;
|
||||||
|
list->tail = node;
|
||||||
|
node->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
list->elements++;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
OPM_NODE_T *libopm_list_remove(OPM_LIST_T *list, OPM_NODE_T *node)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(list == NULL || node == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(node == list->head)
|
||||||
|
{
|
||||||
|
list->head = node->next;
|
||||||
|
|
||||||
|
if(node->next)
|
||||||
|
node->next->prev = NULL;
|
||||||
|
else
|
||||||
|
list->tail = NULL;
|
||||||
|
}
|
||||||
|
else if(node == list->tail)
|
||||||
|
{
|
||||||
|
list->tail = list->tail->prev;
|
||||||
|
list->tail->next = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node->prev->next = node->next;
|
||||||
|
node->next->prev = node->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
list->elements--;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void libopm_list_free(OPM_LIST_T *list)
|
||||||
|
{
|
||||||
|
MyFree(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void libopm_node_free(OPM_NODE_T *node)
|
||||||
|
{
|
||||||
|
MyFree(node);
|
||||||
|
}
|
42
libopm/list.h
Normal file
42
libopm/list.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#ifndef LIST_H
|
||||||
|
#define LIST_H
|
||||||
|
|
||||||
|
|
||||||
|
/* Copyright (C) 2002 by the past and present ircd coders, and others.
|
||||||
|
* Adapted from Hybrid7 DLINK macros
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LIST_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next)
|
||||||
|
#define LIST_FOREACH_SAFE(pos, n, head) for (pos = (head), n = pos ? pos->next : NULL; pos != NULL; pos = n, n = pos ? pos->next : NULL)
|
||||||
|
#define LIST_FOREACH_PREV(pos, head) for (pos = (head); pos != NULL; pos = pos->prev)
|
||||||
|
#define LIST_SIZE(list) list->elements
|
||||||
|
/* End Copyright */
|
||||||
|
|
||||||
|
OPM_NODE_T *libopm_node_create(void *);
|
||||||
|
OPM_LIST_T *libopm_list_create(void);
|
||||||
|
|
||||||
|
OPM_NODE_T *libopm_list_add(OPM_LIST_T *, OPM_NODE_T *);
|
||||||
|
OPM_NODE_T *libopm_list_remove(OPM_LIST_T *, OPM_NODE_T *);
|
||||||
|
|
||||||
|
void libopm_list_free(OPM_LIST_T *);
|
||||||
|
void libopm_node_free(OPM_NODE_T *);
|
||||||
|
|
||||||
|
#endif /* LIST_H */
|
10
libopm/make
Executable file
10
libopm/make
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
gcc -g -o libopm.o -c libopm.c
|
||||||
|
gcc -g -o malloc.o -c malloc.c
|
||||||
|
gcc -g -o list.o -c list.c
|
||||||
|
gcc -g -o config.o -c config.c
|
||||||
|
gcc -g -o inet.o -c inet.c
|
||||||
|
gcc -g -o proxy.o -c proxy.c
|
||||||
|
ar rcs libopm.a libopm.o malloc.o list.o config.o inet.o proxy.o
|
||||||
|
gcc -g test.c -o test -L. -lopm
|
||||||
|
|
72
libopm/malloc.c
Normal file
72
libopm/malloc.c
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002 Erik Fears
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include "malloc.h"
|
||||||
|
#include "opm.h"
|
||||||
|
|
||||||
|
RCSID("$Id: malloc.c,v 1.10 2002/11/07 20:19:06 strtok Exp $");
|
||||||
|
|
||||||
|
|
||||||
|
/* MyMalloc
|
||||||
|
*
|
||||||
|
* A wrapper function for malloc(), for catching memory issues
|
||||||
|
* and error handling.
|
||||||
|
*
|
||||||
|
* Parameters
|
||||||
|
* bytes: amount in bytes to allocate
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* Pointer to allocated memory
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *libopm_MyMalloc(size_t bytes)
|
||||||
|
{
|
||||||
|
void *ret = calloc(1, bytes);
|
||||||
|
|
||||||
|
assert(ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* MyFree
|
||||||
|
*
|
||||||
|
* Free memory allocated with MyMalloc
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* var: pointer to memory to free
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void libopm_MyFree(void **var)
|
||||||
|
{
|
||||||
|
if(*var != NULL)
|
||||||
|
free(*var);
|
||||||
|
*var = NULL;
|
||||||
|
}
|
16
libopm/malloc.h
Normal file
16
libopm/malloc.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef MALLOC_H
|
||||||
|
#define MALLOC_H
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#ifdef STDC_HEADERS
|
||||||
|
# include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MyMalloc(SIZE) libopm_MyMalloc(SIZE)
|
||||||
|
#define MyFree(X) libopm_MyFree((void **) &X)
|
||||||
|
|
||||||
|
void *libopm_MyMalloc(size_t bytes);
|
||||||
|
void libopm_MyFree(void **var);
|
||||||
|
|
||||||
|
#endif /* MALLOC_H */
|
80
libopm/opm.h
Normal file
80
libopm/opm.h
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/* vim: set shiftwidth=3 softtabstop=3 expandtab: */
|
||||||
|
|
||||||
|
/** \file opm.h
|
||||||
|
* \brief Main header for libopm.
|
||||||
|
* \author Erik Fears
|
||||||
|
* \version $Id: opm.h,v 1.26 2003/06/20 04:18:44 andy Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OPM_H
|
||||||
|
#define OPM_H
|
||||||
|
|
||||||
|
#include "opm_common.h"
|
||||||
|
|
||||||
|
/* Stuff to shut up warnings about rcsid being unused. */
|
||||||
|
#define USE_VAR(var) static char sizeof##var = sizeof(sizeof##var) + sizeof(var)
|
||||||
|
/* RCS tag. */
|
||||||
|
#define RCSID(x) static char rcsid[] = x; USE_VAR(rcsid);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _OPM_CONFIG OPM_CONFIG_T;
|
||||||
|
typedef struct _OPM OPM_T;
|
||||||
|
typedef struct _OPM_REMOTE OPM_REMOTE_T;
|
||||||
|
typedef struct _OPM_CALLBACK OPM_CALLBACK_T;
|
||||||
|
|
||||||
|
typedef int OPM_ERR_T;
|
||||||
|
|
||||||
|
typedef void OPM_CALLBACK_FUNC (OPM_T *, OPM_REMOTE_T *, int, void *);
|
||||||
|
|
||||||
|
struct _OPM_CALLBACK {
|
||||||
|
OPM_CALLBACK_FUNC *func;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _OPM_CONFIG {
|
||||||
|
void **vars;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _OPM {
|
||||||
|
OPM_CONFIG_T *config; /* Individual scanner configuration */
|
||||||
|
OPM_LIST_T *queue; /* List of scans in the queue (not yet established) */
|
||||||
|
OPM_LIST_T *scans; /* List of scans (each scan containing a list of connections) */
|
||||||
|
OPM_LIST_T *protocols; /* List of protocols this scanner handles */
|
||||||
|
unsigned int fd_use; /* Number of file descriptors in use */
|
||||||
|
|
||||||
|
OPM_CALLBACK_T *callbacks; /* Scanner wide callbacks */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _OPM_REMOTE {
|
||||||
|
|
||||||
|
char *ip; /* Readable IP address */
|
||||||
|
|
||||||
|
unsigned short int port; /* Port passed back on certain callbacks */
|
||||||
|
unsigned short int protocol; /* Protocol passed back on certain callbacks */
|
||||||
|
unsigned short int bytes_read; /* Bytes read passed back on certain callbacks */
|
||||||
|
|
||||||
|
OPM_LIST_T *protocols; /* Remote specific protocols */
|
||||||
|
|
||||||
|
void *data; /* Arbitrary data that the client can point to for any purpose*/
|
||||||
|
};
|
||||||
|
|
||||||
|
OPM_T *opm_create(void);
|
||||||
|
void opm_free(OPM_T *);
|
||||||
|
|
||||||
|
OPM_REMOTE_T *opm_remote_create(const char *);
|
||||||
|
void opm_remote_free(OPM_REMOTE_T *);
|
||||||
|
|
||||||
|
OPM_ERR_T opm_config(OPM_T *, int, void *);
|
||||||
|
OPM_ERR_T opm_scan(OPM_T *, OPM_REMOTE_T *);
|
||||||
|
void opm_end(OPM_T *, OPM_REMOTE_T *);
|
||||||
|
void opm_endscan(OPM_T *, OPM_REMOTE_T *);
|
||||||
|
|
||||||
|
OPM_ERR_T opm_addtype(OPM_T *, int, unsigned short int);
|
||||||
|
OPM_ERR_T opm_remote_addtype(OPM_REMOTE_T *, int, unsigned short int);
|
||||||
|
OPM_ERR_T opm_callback(OPM_T *, int, OPM_CALLBACK_FUNC *, void *);
|
||||||
|
|
||||||
|
void opm_cycle(OPM_T *);
|
||||||
|
|
||||||
|
size_t opm_active(OPM_T *);
|
||||||
|
|
||||||
|
#endif /* OPM_H */
|
24
libopm/opm_common.h
Normal file
24
libopm/opm_common.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef OPM_COMMON_H
|
||||||
|
#define OPM_COMMON_H
|
||||||
|
|
||||||
|
typedef struct _libopm_node OPM_NODE_T;
|
||||||
|
typedef struct _libopm_list OPM_LIST_T;
|
||||||
|
|
||||||
|
|
||||||
|
struct _libopm_list {
|
||||||
|
|
||||||
|
struct _libopm_node *head;
|
||||||
|
struct _libopm_node *tail;
|
||||||
|
|
||||||
|
int elements;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _libopm_node {
|
||||||
|
|
||||||
|
struct _libopm_node *next;
|
||||||
|
struct _libopm_node *prev;
|
||||||
|
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* OPM_COMMON_H */
|
26
libopm/opm_error.h
Normal file
26
libopm/opm_error.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef LIBOPM_ERROR_H
|
||||||
|
#define LIBOPM_ERROR_H
|
||||||
|
|
||||||
|
/* Success */
|
||||||
|
#define OPM_SUCCESS 1
|
||||||
|
|
||||||
|
/* Configuration Errors */
|
||||||
|
#define OPM_ERR_BADKEY 2 /* Unknown or bad key value */
|
||||||
|
#define OPM_ERR_BADVALUE 3 /* Bad value matching key */
|
||||||
|
#define OPM_ERR_BADPROTOCOL 4 /* Unknown protocol in config */
|
||||||
|
|
||||||
|
/* Read Errors */
|
||||||
|
#define OPM_ERR_MAX_READ 5 /* Socket reached MAX_READ */
|
||||||
|
|
||||||
|
/* Callback Registration Errors */
|
||||||
|
#define OPM_ERR_CBNOTFOUND 6 /* Callback is out of range */
|
||||||
|
|
||||||
|
/* opm_scan errors */
|
||||||
|
#define OPM_ERR_BADADDR 7 /* IP in remote struct is bad */
|
||||||
|
#define OPM_ERR_NOPROTOCOLS 8 /* No protocols to scan! */
|
||||||
|
|
||||||
|
/* bind/connect errors */
|
||||||
|
#define OPM_ERR_BIND 9 /* Error binding to BIND_IP */
|
||||||
|
#define OPM_ERR_NOFD 10/* Unable to allocate file descriptor */
|
||||||
|
|
||||||
|
#endif /* LIBOPM_ERROR_H */
|
44
libopm/opm_types.h
Normal file
44
libopm/opm_types.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef OPM_TYPES_H
|
||||||
|
#define OPM_TYPES_H
|
||||||
|
|
||||||
|
/* Configuration Directives */
|
||||||
|
#define OPM_CONFIG_FD_LIMIT 0
|
||||||
|
#define OPM_CONFIG_BIND_IP 1
|
||||||
|
#define OPM_CONFIG_DNSBL_HOST 2
|
||||||
|
#define OPM_CONFIG_TARGET_STRING 3
|
||||||
|
#define OPM_CONFIG_SCAN_IP 4
|
||||||
|
#define OPM_CONFIG_SCAN_PORT 5
|
||||||
|
#define OPM_CONFIG_MAX_READ 6
|
||||||
|
#define OPM_CONFIG_TIMEOUT 7
|
||||||
|
|
||||||
|
/* Configuration Variable Types */
|
||||||
|
#define OPM_TYPE_INT 1
|
||||||
|
#define OPM_TYPE_STRING 2
|
||||||
|
#define OPM_TYPE_ADDRESS 3
|
||||||
|
#define OPM_TYPE_STRINGLIST 4
|
||||||
|
|
||||||
|
/* Protocols */
|
||||||
|
#define OPM_TYPE_HTTP 1
|
||||||
|
#define OPM_TYPE_SOCKS4 2
|
||||||
|
#define OPM_TYPE_SOCKS5 3
|
||||||
|
#define OPM_TYPE_WINGATE 4
|
||||||
|
#define OPM_TYPE_ROUTER 5
|
||||||
|
#define OPM_TYPE_HTTPPOST 6
|
||||||
|
|
||||||
|
/* States */
|
||||||
|
#define OPM_STATE_UNESTABLISHED 1
|
||||||
|
#define OPM_STATE_ESTABLISHED 2
|
||||||
|
#define OPM_STATE_NEGSENT 3
|
||||||
|
#define OPM_STATE_CLOSED 4
|
||||||
|
|
||||||
|
|
||||||
|
/* Callbacks -- If more callback types are added,
|
||||||
|
CBLEN will need to be changed in libopm.h accordingly */
|
||||||
|
|
||||||
|
#define OPM_CALLBACK_OPENPROXY 0 /* An open proxy has been found REMOTE/SCANNER */
|
||||||
|
#define OPM_CALLBACK_NEGFAIL 1 /* Negotiation to a proxy has failed REMOTE/SCANNER */
|
||||||
|
#define OPM_CALLBACK_END 2 /* A scan has ended REMOTE/SCANNER */
|
||||||
|
#define OPM_CALLBACK_ERROR 3 /* An unrecoverable error has occured */
|
||||||
|
#define OPM_CALLBACK_TIMEOUT 4 /* Specific scan (protocol) on host has timed out */
|
||||||
|
|
||||||
|
#endif /* OPM_TYPES_H */
|
243
libopm/proxy.c
Normal file
243
libopm/proxy.c
Normal file
|
@ -0,0 +1,243 @@
|
||||||
|
/* vim: set shiftwidth=3 softtabstop=3 expandtab: */
|
||||||
|
|
||||||
|
/* Copyright (C) 2002 Erik Fears
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef STDC_HEADERS
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "inet.h"
|
||||||
|
#include "compat.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "proxy.h"
|
||||||
|
#include "opm_common.h"
|
||||||
|
#include "opm_types.h"
|
||||||
|
#include "opm_error.h"
|
||||||
|
#include "libopm.h"
|
||||||
|
|
||||||
|
RCSID("$Id: proxy.c,v 1.16 2003/06/21 04:27:32 andy Exp $");
|
||||||
|
|
||||||
|
static char SENDBUF[SENDBUFLEN + 1];
|
||||||
|
|
||||||
|
int libopm_proxy_http_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
|
||||||
|
{
|
||||||
|
USE_VAR(scan);
|
||||||
|
|
||||||
|
snprintf(SENDBUF, SENDBUFLEN, "CONNECT %s:%d HTTP/1.0\r\n\r\n",
|
||||||
|
(char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP),
|
||||||
|
*(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT));
|
||||||
|
|
||||||
|
if(send(conn->fd, SENDBUF, strlen(SENDBUF), 0) == -1)
|
||||||
|
return 0; /* Return error code ? */
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CONNECT request byte order for socks4
|
||||||
|
*
|
||||||
|
* +----+----+----+----+----+----+----+----+----+----+....+----+
|
||||||
|
* | VN | CD | DSTPORT | DSTIP | USERID |NULL|
|
||||||
|
* +----+----+----+----+----+----+----+----+----+----+....+----+
|
||||||
|
* # of bytes: 1 1 2 4 variable 1
|
||||||
|
*
|
||||||
|
* VN = Version, CD = Command Code (1 is connect request)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int libopm_proxy_socks4_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
|
||||||
|
{
|
||||||
|
struct in_addr addr;
|
||||||
|
unsigned long laddr;
|
||||||
|
int len, scan_port;
|
||||||
|
char *scan_ip;
|
||||||
|
USE_VAR(scan);
|
||||||
|
|
||||||
|
scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
|
||||||
|
scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
|
||||||
|
|
||||||
|
laddr = htonl(addr.s_addr);
|
||||||
|
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c%c%c%c%c%c%c", 4, 1,
|
||||||
|
(((unsigned short) scan_port) >> 8) & 0xFF,
|
||||||
|
(((unsigned short) scan_port) & 0xFF),
|
||||||
|
(char) (laddr >> 24) & 0xFF, (char) (laddr >> 16) & 0xFF,
|
||||||
|
(char) (laddr >> 8) & 0xFF, (char) laddr & 0xFF, 0);
|
||||||
|
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send version authentication selection message to socks5
|
||||||
|
*
|
||||||
|
* +----+----------+----------+
|
||||||
|
* |VER | NMETHODS | METHODS |
|
||||||
|
* +----+----------+----------+
|
||||||
|
* | 1 | 1 | 1 to 255 |
|
||||||
|
* +----+----------+----------+
|
||||||
|
*
|
||||||
|
* VER always contains 5, for socks version 5
|
||||||
|
* Method 0 is 'No authentication required'
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The SOCKS request is formed as follows:
|
||||||
|
*
|
||||||
|
* +----+-----+-------+------+----------+----------+
|
||||||
|
* |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
|
||||||
|
* +----+-----+-------+------+----------+----------+
|
||||||
|
* | 1 | 1 | X'00' | 1 | Variable | 2 |
|
||||||
|
* +----+-----+-------+------+----------+----------+
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* o VER protocol version: X'05'
|
||||||
|
* o CMD
|
||||||
|
* o CONNECT X'01'
|
||||||
|
* o BIND X'02'
|
||||||
|
* o UDP ASSOCIATE X'03'
|
||||||
|
* o RSV RESERVED
|
||||||
|
* o ATYP address type of following address
|
||||||
|
* o IP V4 address: X'01'
|
||||||
|
* o DOMAINNAME: X'03'
|
||||||
|
* o IP V6 address: X'04'
|
||||||
|
* o DST.ADDR desired destination address
|
||||||
|
* o DST.PORT desired destination port in network octet
|
||||||
|
* order
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
int libopm_proxy_socks5_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
|
||||||
|
{
|
||||||
|
struct in_addr addr;
|
||||||
|
unsigned long laddr;
|
||||||
|
int len, scan_port;
|
||||||
|
char *scan_ip;
|
||||||
|
USE_VAR(scan);
|
||||||
|
|
||||||
|
scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
|
||||||
|
scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
|
||||||
|
|
||||||
|
laddr = htonl(addr.s_addr);
|
||||||
|
|
||||||
|
/* Form authentication string */
|
||||||
|
/* Version 5, 1 number of methods, 0 method (no auth). */
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c", 5, 1, 0);
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
/* Form request string */
|
||||||
|
|
||||||
|
/* Will need to write ipv6 support here in future
|
||||||
|
* as socks5 is ipv6 compatible
|
||||||
|
*/
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c%c%c%c%c%c%c%c", 5, 1, 0, 1,
|
||||||
|
(char) (laddr >> 24) & 0xFF, (char) (laddr >> 16) & 0xFF,
|
||||||
|
(char) (laddr >> 8) & 0xFF, (char) laddr & 0xFF,
|
||||||
|
(((unsigned short) scan_port) >> 8) & 0xFF,
|
||||||
|
(((unsigned short) scan_port) & 0xFF));
|
||||||
|
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open wingates require no authentication, they will send a prompt when
|
||||||
|
* connect.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int libopm_proxy_wingate_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
|
||||||
|
{
|
||||||
|
int scan_port, len;
|
||||||
|
char *scan_ip;
|
||||||
|
USE_VAR(scan);
|
||||||
|
|
||||||
|
scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
|
||||||
|
scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
|
||||||
|
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "%s:%d\r\n", scan_ip, scan_port);
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cisco scanning
|
||||||
|
*
|
||||||
|
* Some cisco routers have 'cisco' set as password which allow open telnet
|
||||||
|
* relay. Attempt to connect using cisco as a password, then give command for
|
||||||
|
* telnet to the scanip/scanport
|
||||||
|
*/
|
||||||
|
|
||||||
|
int libopm_proxy_router_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
|
||||||
|
{
|
||||||
|
int len, scan_port;
|
||||||
|
char *scan_ip;
|
||||||
|
USE_VAR(scan);
|
||||||
|
|
||||||
|
scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
|
||||||
|
scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
|
||||||
|
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "cisco\r\n");
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "telnet %s %d\r\n", scan_ip, scan_port);
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* HTTP POST Scanning
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
int libopm_proxy_httppost_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
|
||||||
|
{
|
||||||
|
int len, scan_port;
|
||||||
|
char *scan_ip;
|
||||||
|
USE_VAR(scan);
|
||||||
|
|
||||||
|
scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
|
||||||
|
scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
|
||||||
|
|
||||||
|
len = snprintf(SENDBUF, SENDBUFLEN, "POST http://%s:%d/ HTTP/1.0\r\n"
|
||||||
|
"Content-type: text/plain\r\n"
|
||||||
|
"Content-length: 5\r\n\r\n"
|
||||||
|
"quit\r\n\r\n",
|
||||||
|
scan_ip, scan_port);
|
||||||
|
|
||||||
|
send(conn->fd, SENDBUF, (unsigned int)len, 0);
|
||||||
|
|
||||||
|
return OPM_SUCCESS;
|
||||||
|
}
|
14
libopm/proxy.h
Normal file
14
libopm/proxy.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef PROXY_H
|
||||||
|
#define PROXY_H
|
||||||
|
|
||||||
|
#include "libopm.h"
|
||||||
|
|
||||||
|
int libopm_proxy_http_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
int libopm_proxy_socks4_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
int libopm_proxy_socks5_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
int libopm_proxy_wingate_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
int libopm_proxy_router_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
int libopm_proxy_httppost_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* PROXY_H */
|
101
libopm/setup.h.in
Normal file
101
libopm/setup.h.in
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
/* src/setup.h.in. Generated from configure.in by autoheader. */
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
|
#undef HAVE_DLFCN_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||||
|
#undef HAVE_FCNTL_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `gethostbyname' function. */
|
||||||
|
#undef HAVE_GETHOSTBYNAME
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `gethostbyname2' function. */
|
||||||
|
#undef HAVE_GETHOSTBYNAME2
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `inet_aton' function. */
|
||||||
|
#undef HAVE_INET_ATON
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `inet_pton' function. */
|
||||||
|
#undef HAVE_INET_PTON
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#undef HAVE_INTTYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
|
#undef HAVE_MEMORY_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `select' function. */
|
||||||
|
#undef HAVE_SELECT
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `snprintf' function. */
|
||||||
|
#undef HAVE_SNPRINTF
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdint.h> header file. */
|
||||||
|
#undef HAVE_STDINT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||||
|
#undef HAVE_STDLIB_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <strings.h> header file. */
|
||||||
|
#undef HAVE_STRINGS_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <string.h> header file. */
|
||||||
|
#undef HAVE_STRING_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/poll.h> header file. */
|
||||||
|
#undef HAVE_SYS_POLL_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
|
#undef HAVE_SYS_STAT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||||
|
#undef HAVE_SYS_TIME_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||||
|
#undef HAVE_SYS_TYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
|
#undef HAVE_UNISTD_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vsnprintf' function. */
|
||||||
|
#undef HAVE_VSNPRINTF
|
||||||
|
|
||||||
|
/* Name of package */
|
||||||
|
#undef PACKAGE
|
||||||
|
|
||||||
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
|
#undef PACKAGE_BUGREPORT
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#undef PACKAGE_NAME
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#undef PACKAGE_STRING
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#undef PACKAGE_TARNAME
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#undef PACKAGE_VERSION
|
||||||
|
|
||||||
|
/* "enable replacement (v)snprintf if system (v)snprintf is broken" */
|
||||||
|
#undef PREFER_PORTABLE_SNPRINTF
|
||||||
|
|
||||||
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
|
#undef STDC_HEADERS
|
||||||
|
|
||||||
|
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||||
|
#undef TIME_WITH_SYS_TIME
|
||||||
|
|
||||||
|
/* Version number of package */
|
||||||
|
#undef VERSION
|
||||||
|
|
||||||
|
/* Define to 1 if your processor stores words with the most significant byte
|
||||||
|
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||||
|
#undef WORDS_BIGENDIAN
|
||||||
|
|
||||||
|
/* Define to empty if `const' does not conform to ANSI C. */
|
||||||
|
#undef const
|
||||||
|
|
||||||
|
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||||
|
#undef size_t
|
1031
libopm/snprintf.c
Normal file
1031
libopm/snprintf.c
Normal file
File diff suppressed because it is too large
Load diff
34
libopm/snprintf.h
Normal file
34
libopm/snprintf.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef _PORTABLE_SNPRINTF_H_
|
||||||
|
#define _PORTABLE_SNPRINTF_H_
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#define PORTABLE_SNPRINTF_VERSION_MAJOR 2
|
||||||
|
#define PORTABLE_SNPRINTF_VERSION_MINOR 2
|
||||||
|
|
||||||
|
#ifdef HAVE_SNPRINTF
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
extern int libopm_snprintf(char *, size_t, const char *, /*args*/ ...);
|
||||||
|
extern int libopm_vsnprintf(char *, size_t, const char *, va_list);
|
||||||
|
#undef snprintf
|
||||||
|
#undef vsnprintf
|
||||||
|
#define snprintf libopm_snprintf
|
||||||
|
#define vsnprintf libopm_vsnprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
|
||||||
|
extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
|
||||||
|
extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
|
||||||
|
#undef snprintf
|
||||||
|
#undef vsnprintf
|
||||||
|
#define snprintf portable_snprintf
|
||||||
|
#define vsnprintf portable_vsnprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern int asprintf (char **ptr, const char *fmt, /*args*/ ...);
|
||||||
|
extern int vasprintf (char **ptr, const char *fmt, va_list ap);
|
||||||
|
extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
|
||||||
|
extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
|
||||||
|
|
||||||
|
#endif
|
224
libopm/test.c
Normal file
224
libopm/test.c
Normal file
|
@ -0,0 +1,224 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002 Erik Fears
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* 59 Temple Place - Suite 330
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "opm.h"
|
||||||
|
#include "opm_error.h"
|
||||||
|
#include "opm_types.h"
|
||||||
|
#include "compat.h"
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RCSID("$Id: test.c,v 1.36 2003/06/20 04:55:14 andy Exp $");
|
||||||
|
|
||||||
|
#define ARRAY_SIZEOF(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
void open_proxy(OPM_T *, OPM_REMOTE_T *, int, void *);
|
||||||
|
void negotiation_failed(OPM_T *, OPM_REMOTE_T *, int, void *);
|
||||||
|
void timeout(OPM_T *, OPM_REMOTE_T *, int, void *);
|
||||||
|
void end(OPM_T *, OPM_REMOTE_T *, int, void *);
|
||||||
|
void handle_error(OPM_T *, OPM_REMOTE_T *, int, void *);
|
||||||
|
|
||||||
|
int complete = 0;
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
OPM_ERR_T err;
|
||||||
|
int fdlimit = 1024;
|
||||||
|
int scan_port = 6667;
|
||||||
|
int max_read = 4096;
|
||||||
|
int scantimeout = 10;
|
||||||
|
unsigned int i, s;
|
||||||
|
|
||||||
|
unsigned short http_ports[] = {
|
||||||
|
8000, 8080, 3128, 80
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short wingate_ports[] = {
|
||||||
|
23
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short router_ports[] = {
|
||||||
|
23
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short socks4_ports[] = {
|
||||||
|
1080
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short socks5_ports[] = {
|
||||||
|
1080
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short httppost_ports[] = {
|
||||||
|
80, 8090, 3128
|
||||||
|
};
|
||||||
|
|
||||||
|
OPM_T *scanner;
|
||||||
|
OPM_REMOTE_T *remote;
|
||||||
|
|
||||||
|
scanner = opm_create();
|
||||||
|
|
||||||
|
if(argc >= 2)
|
||||||
|
remote = opm_remote_create(argv[1]);
|
||||||
|
else
|
||||||
|
remote = opm_remote_create("127.0.0.1");
|
||||||
|
|
||||||
|
/* Setup callbacks */
|
||||||
|
opm_callback(scanner, OPM_CALLBACK_OPENPROXY, &open_proxy, NULL);
|
||||||
|
opm_callback(scanner, OPM_CALLBACK_NEGFAIL, &negotiation_failed, NULL);
|
||||||
|
opm_callback(scanner, OPM_CALLBACK_TIMEOUT, &timeout, NULL);
|
||||||
|
opm_callback(scanner, OPM_CALLBACK_END, &end, NULL);
|
||||||
|
opm_callback(scanner, OPM_CALLBACK_ERROR, &handle_error, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/* Setup the scanner configuration */
|
||||||
|
opm_config(scanner, OPM_CONFIG_FD_LIMIT, &fdlimit);
|
||||||
|
opm_config(scanner, OPM_CONFIG_SCAN_IP, "216.175.104.202");
|
||||||
|
opm_config(scanner, OPM_CONFIG_SCAN_PORT, &scan_port);
|
||||||
|
opm_config(scanner, OPM_CONFIG_TARGET_STRING, "*** Looking up your hostname...");
|
||||||
|
opm_config(scanner, OPM_CONFIG_TARGET_STRING, "ERROR :Trying to reconnect too fast.");
|
||||||
|
opm_config(scanner, OPM_CONFIG_TIMEOUT, &scantimeout);
|
||||||
|
opm_config(scanner, OPM_CONFIG_MAX_READ, &max_read);
|
||||||
|
|
||||||
|
/* Setup the protocol configuration */
|
||||||
|
for (s = ARRAY_SIZEOF(http_ports), i = 0; i < s; i++) {
|
||||||
|
opm_addtype(scanner, OPM_TYPE_HTTP, http_ports[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (s = ARRAY_SIZEOF(wingate_ports), i = 0; i < s; i++) {
|
||||||
|
opm_addtype(scanner, OPM_TYPE_WINGATE, wingate_ports[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (s = ARRAY_SIZEOF(router_ports), i = 0; i < s; i++) {
|
||||||
|
opm_addtype(scanner, OPM_TYPE_ROUTER, router_ports[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (s = ARRAY_SIZEOF(socks4_ports), i = 0; i < s; i++) {
|
||||||
|
opm_addtype(scanner, OPM_TYPE_SOCKS4, socks4_ports[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (s = ARRAY_SIZEOF(socks5_ports), i = 0; i < s; i++) {
|
||||||
|
opm_addtype(scanner, OPM_TYPE_SOCKS5, socks5_ports[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (s = ARRAY_SIZEOF(httppost_ports), i = 0; i < s; i++) {
|
||||||
|
opm_addtype(scanner, OPM_TYPE_HTTPPOST, httppost_ports[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remote structs can also have their own extended protocol configurations. For instance
|
||||||
|
if the target hostname contains strings such as 'proxy' or 'www', extended ports could
|
||||||
|
be scanned. */
|
||||||
|
opm_remote_addtype(remote, OPM_TYPE_HTTP, 8001);
|
||||||
|
opm_remote_addtype(remote, OPM_TYPE_HTTP, 8002);
|
||||||
|
|
||||||
|
switch(err = opm_scan(scanner, remote))
|
||||||
|
{
|
||||||
|
case OPM_SUCCESS:
|
||||||
|
break;
|
||||||
|
case OPM_ERR_BADADDR:
|
||||||
|
printf("Bad address\n");
|
||||||
|
opm_free(scanner);
|
||||||
|
opm_remote_free(remote);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
printf("Unknown Error %d\n", err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while(!complete)
|
||||||
|
opm_cycle(scanner);
|
||||||
|
|
||||||
|
opm_free(scanner);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
|
USE_VAR(notused);
|
||||||
|
USE_VAR(data);
|
||||||
|
|
||||||
|
printf("Open proxy on %s:%d [%d bytes read]\n", remote->ip,
|
||||||
|
remote->port, remote->bytes_read);
|
||||||
|
opm_end(scanner, remote);
|
||||||
|
}
|
||||||
|
|
||||||
|
void negotiation_failed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
|
USE_VAR(scanner);
|
||||||
|
USE_VAR(notused);
|
||||||
|
USE_VAR(data);
|
||||||
|
|
||||||
|
printf("Negotiation on %s:%d failed [%d bytes read]\n", remote->ip,
|
||||||
|
remote->port, remote->bytes_read);
|
||||||
|
}
|
||||||
|
|
||||||
|
void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data)
|
||||||
|
{
|
||||||
|
USE_VAR(scanner);
|
||||||
|
USE_VAR(notused);
|
||||||
|
USE_VAR(data);
|
||||||
|
|
||||||
|
printf("Negotiation timed out on %s:%d\n", remote->ip, remote->port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data)
|
||||||
|
{
|
||||||
|
USE_VAR(scanner);
|
||||||
|
USE_VAR(notused);
|
||||||
|
USE_VAR(data);
|
||||||
|
|
||||||
|
printf("Scan on %s has ended\n", remote->ip);
|
||||||
|
opm_remote_free(remote);
|
||||||
|
complete = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_error(OPM_T *scanner, OPM_REMOTE_T *remote, int err, void *data)
|
||||||
|
{
|
||||||
|
USE_VAR(scanner);
|
||||||
|
USE_VAR(data);
|
||||||
|
|
||||||
|
switch(err)
|
||||||
|
{
|
||||||
|
case OPM_ERR_MAX_READ:
|
||||||
|
printf("Reached MAX READ on %s:%d\n", remote->ip, remote->port);
|
||||||
|
break;
|
||||||
|
case OPM_ERR_BIND:
|
||||||
|
printf("Unable to bind for %s:%d\n", remote->ip, remote->port);
|
||||||
|
break;
|
||||||
|
case OPM_ERR_NOFD:
|
||||||
|
printf("Unable to allocate file descriptor for %s:%d\n",
|
||||||
|
remote->ip, remote->port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Unknown error on %s:%d, err = %d\n", remote->ip,
|
||||||
|
remote->port, err);
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue