diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2013-02-07 13:27:27 +0100 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2013-02-07 13:27:27 +0100 |
commit | 7585facf05d927eb6df3929ce09ed5e60d905437 (patch) | |
tree | e4d14b4dc180db20356b6b01ce0112f3a2d7897e /src/libimcv/plugins/imv_os | |
parent | c1343b3278cdf99533b7902744d15969f9d6fdc1 (diff) | |
download | vyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.tar.gz vyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.zip |
Imported Upstream version 5.0.2
Diffstat (limited to 'src/libimcv/plugins/imv_os')
-rw-r--r-- | src/libimcv/plugins/imv_os/Makefile.am | 24 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/Makefile.in | 684 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/imv_os.c | 590 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/imv_os_database.c | 311 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/imv_os_database.h | 80 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/imv_os_state.c | 621 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/imv_os_state.h | 164 | ||||
-rw-r--r-- | src/libimcv/plugins/imv_os/pacman.c | 498 | ||||
-rwxr-xr-x | src/libimcv/plugins/imv_os/pacman.sh | 40 |
9 files changed, 3012 insertions, 0 deletions
diff --git a/src/libimcv/plugins/imv_os/Makefile.am b/src/libimcv/plugins/imv_os/Makefile.am new file mode 100644 index 000000000..58edc6963 --- /dev/null +++ b/src/libimcv/plugins/imv_os/Makefile.am @@ -0,0 +1,24 @@ + +INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libtncif \ + -I$(top_srcdir)/src/libimcv + +AM_CFLAGS = -rdynamic + +imcv_LTLIBRARIES = imv-os.la + +imv_os_la_LIBADD = $(top_builddir)/src/libimcv/libimcv.la \ + $(top_builddir)/src/libstrongswan/libstrongswan.la + +imv_os_la_SOURCES = \ + imv_os.c imv_os_state.h imv_os_state.c \ + imv_os_database.c imv_os_database.h + +imv_os_la_LDFLAGS = -module -avoid-version + +ipsec_PROGRAMS = pacman +pacman_SOURCES = pacman.c +pacman_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la +pacman.o : $(top_builddir)/config.status + +EXTRA_DIST = pacman.sh + diff --git a/src/libimcv/plugins/imv_os/Makefile.in b/src/libimcv/plugins/imv_os/Makefile.in new file mode 100644 index 000000000..53a547a4d --- /dev/null +++ b/src/libimcv/plugins/imv_os/Makefile.in @@ -0,0 +1,684 @@ +# Makefile.in generated by automake 1.11.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +ipsec_PROGRAMS = pacman$(EXEEXT) +subdir = src/libimcv/plugins/imv_os +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/config/libtool.m4 \ + $(top_srcdir)/m4/config/ltoptions.m4 \ + $(top_srcdir)/m4/config/ltsugar.m4 \ + $(top_srcdir)/m4/config/ltversion.m4 \ + $(top_srcdir)/m4/config/lt~obsolete.m4 \ + $(top_srcdir)/m4/macros/with.m4 \ + $(top_srcdir)/m4/macros/enable-disable.m4 \ + $(top_srcdir)/m4/macros/add-plugin.m4 \ + $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(imcvdir)" "$(DESTDIR)$(ipsecdir)" +LTLIBRARIES = $(imcv_LTLIBRARIES) +imv_os_la_DEPENDENCIES = $(top_builddir)/src/libimcv/libimcv.la \ + $(top_builddir)/src/libstrongswan/libstrongswan.la +am_imv_os_la_OBJECTS = imv_os.lo imv_os_state.lo imv_os_database.lo +imv_os_la_OBJECTS = $(am_imv_os_la_OBJECTS) +imv_os_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(imv_os_la_LDFLAGS) $(LDFLAGS) -o $@ +PROGRAMS = $(ipsec_PROGRAMS) +am_pacman_OBJECTS = pacman.$(OBJEXT) +pacman_OBJECTS = $(am_pacman_OBJECTS) +pacman_DEPENDENCIES = \ + $(top_builddir)/src/libstrongswan/libstrongswan.la +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(imv_os_la_SOURCES) $(pacman_SOURCES) +DIST_SOURCES = $(imv_os_la_SOURCES) $(pacman_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BFDLIB = @BFDLIB@ +BTLIB = @BTLIB@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLIB = @DLLIB@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GPERF = @GPERF@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MYSQLCFLAG = @MYSQLCFLAG@ +MYSQLCONFIG = @MYSQLCONFIG@ +MYSQLLIB = @MYSQLLIB@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PTHREADLIB = @PTHREADLIB@ +RANLIB = @RANLIB@ +RTLIB = @RTLIB@ +RUBY = @RUBY@ +RUBYINCLUDE = @RUBYINCLUDE@ +RUBYLIB = @RUBYLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SOCKLIB = @SOCKLIB@ +STRIP = @STRIP@ +VERSION = @VERSION@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +attest_plugins = @attest_plugins@ +axis2c_CFLAGS = @axis2c_CFLAGS@ +axis2c_LIBS = @axis2c_LIBS@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +c_plugins = @c_plugins@ +charon_natt_port = @charon_natt_port@ +charon_plugins = @charon_plugins@ +charon_udp_port = @charon_udp_port@ +clearsilver_LIBS = @clearsilver_LIBS@ +datadir = @datadir@ +datarootdir = @datarootdir@ +dbusservicedir = @dbusservicedir@ +dev_headers = @dev_headers@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +gtk_CFLAGS = @gtk_CFLAGS@ +gtk_LIBS = @gtk_LIBS@ +h_plugins = @h_plugins@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +imcvdir = @imcvdir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +ipsec_script = @ipsec_script@ +ipsec_script_upper = @ipsec_script_upper@ +ipsecdir = @ipsecdir@ +ipsecgroup = @ipsecgroup@ +ipseclibdir = @ipseclibdir@ +ipsecuser = @ipsecuser@ +libdir = @libdir@ +libexecdir = @libexecdir@ +linux_headers = @linux_headers@ +localedir = @localedir@ +localstatedir = @localstatedir@ +maemo_CFLAGS = @maemo_CFLAGS@ +maemo_LIBS = @maemo_LIBS@ +manager_plugins = @manager_plugins@ +mandir = @mandir@ +medsrv_plugins = @medsrv_plugins@ +mkdir_p = @mkdir_p@ +nm_CFLAGS = @nm_CFLAGS@ +nm_LIBS = @nm_LIBS@ +nm_ca_dir = @nm_ca_dir@ +nm_plugins = @nm_plugins@ +oldincludedir = @oldincludedir@ +openac_plugins = @openac_plugins@ +p_plugins = @p_plugins@ +pcsclite_CFLAGS = @pcsclite_CFLAGS@ +pcsclite_LIBS = @pcsclite_LIBS@ +pdfdir = @pdfdir@ +piddir = @piddir@ +pki_plugins = @pki_plugins@ +plugindir = @plugindir@ +pool_plugins = @pool_plugins@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +random_device = @random_device@ +resolv_conf = @resolv_conf@ +routing_table = @routing_table@ +routing_table_prio = @routing_table_prio@ +s_plugins = @s_plugins@ +sbindir = @sbindir@ +scepclient_plugins = @scepclient_plugins@ +scripts_plugins = @scripts_plugins@ +sharedstatedir = @sharedstatedir@ +soup_CFLAGS = @soup_CFLAGS@ +soup_LIBS = @soup_LIBS@ +srcdir = @srcdir@ +starter_plugins = @starter_plugins@ +strongswan_conf = @strongswan_conf@ +sysconfdir = @sysconfdir@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +urandom_device = @urandom_device@ +xml_CFLAGS = @xml_CFLAGS@ +xml_LIBS = @xml_LIBS@ +INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libtncif \ + -I$(top_srcdir)/src/libimcv + +AM_CFLAGS = -rdynamic +imcv_LTLIBRARIES = imv-os.la +imv_os_la_LIBADD = $(top_builddir)/src/libimcv/libimcv.la \ + $(top_builddir)/src/libstrongswan/libstrongswan.la + +imv_os_la_SOURCES = \ + imv_os.c imv_os_state.h imv_os_state.c \ + imv_os_database.c imv_os_database.h + +imv_os_la_LDFLAGS = -module -avoid-version +pacman_SOURCES = pacman.c +pacman_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la +EXTRA_DIST = pacman.sh +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libimcv/plugins/imv_os/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/libimcv/plugins/imv_os/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-imcvLTLIBRARIES: $(imcv_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(imcvdir)" || $(MKDIR_P) "$(DESTDIR)$(imcvdir)" + @list='$(imcv_LTLIBRARIES)'; test -n "$(imcvdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(imcvdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(imcvdir)"; \ + } + +uninstall-imcvLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(imcv_LTLIBRARIES)'; test -n "$(imcvdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(imcvdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(imcvdir)/$$f"; \ + done + +clean-imcvLTLIBRARIES: + -test -z "$(imcv_LTLIBRARIES)" || rm -f $(imcv_LTLIBRARIES) + @list='$(imcv_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +imv-os.la: $(imv_os_la_OBJECTS) $(imv_os_la_DEPENDENCIES) $(EXTRA_imv_os_la_DEPENDENCIES) + $(imv_os_la_LINK) -rpath $(imcvdir) $(imv_os_la_OBJECTS) $(imv_os_la_LIBADD) $(LIBS) +install-ipsecPROGRAMS: $(ipsec_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(ipsecdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsecdir)" + @list='$(ipsec_PROGRAMS)'; test -n "$(ipsecdir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(ipsecdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(ipsecdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-ipsecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_PROGRAMS)'; test -n "$(ipsecdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(ipsecdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(ipsecdir)" && rm -f $$files + +clean-ipsecPROGRAMS: + @list='$(ipsec_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +pacman$(EXEEXT): $(pacman_OBJECTS) $(pacman_DEPENDENCIES) $(EXTRA_pacman_DEPENDENCIES) + @rm -f pacman$(EXEEXT) + $(LINK) $(pacman_OBJECTS) $(pacman_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imv_os.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imv_os_database.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imv_os_state.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pacman.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$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) +installdirs: + for dir in "$(DESTDIR)$(imcvdir)" "$(DESTDIR)$(ipsecdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +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: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_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-imcvLTLIBRARIES clean-ipsecPROGRAMS \ + clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-imcvLTLIBRARIES install-ipsecPROGRAMS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-imcvLTLIBRARIES uninstall-ipsecPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-imcvLTLIBRARIES clean-ipsecPROGRAMS clean-libtool ctags \ + distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am \ + install-imcvLTLIBRARIES install-info install-info-am \ + install-ipsecPROGRAMS install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-imcvLTLIBRARIES \ + uninstall-ipsecPROGRAMS + +pacman.o : $(top_builddir)/config.status + +# 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: diff --git a/src/libimcv/plugins/imv_os/imv_os.c b/src/libimcv/plugins/imv_os/imv_os.c new file mode 100644 index 000000000..65538df07 --- /dev/null +++ b/src/libimcv/plugins/imv_os/imv_os.c @@ -0,0 +1,590 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#include "imv_os_state.h" +#include "imv_os_database.h" + +#include <imv/imv_agent.h> +#include <imv/imv_msg.h> +#include <ietf/ietf_attr.h> +#include <ietf/ietf_attr_attr_request.h> +#include <ietf/ietf_attr_default_pwd_enabled.h> +#include <ietf/ietf_attr_fwd_enabled.h> +#include <ietf/ietf_attr_installed_packages.h> +#include <ietf/ietf_attr_numeric_version.h> +#include <ietf/ietf_attr_op_status.h> +#include <ietf/ietf_attr_pa_tnc_error.h> +#include <ietf/ietf_attr_product_info.h> +#include <ietf/ietf_attr_remediation_instr.h> +#include <ietf/ietf_attr_string_version.h> +#include <ita/ita_attr.h> +#include <ita/ita_attr_get_settings.h> +#include <ita/ita_attr_settings.h> +#include <ita/ita_attr_angel.h> + +#include <tncif_names.h> +#include <tncif_pa_subtypes.h> + +#include <pen/pen.h> +#include <collections/linked_list.h> +#include <utils/debug.h> +#include <utils/lexparser.h> + +/* IMV definitions */ + +static const char imv_name[] = "OS"; + +static pen_type_t msg_types[] = { + { PEN_IETF, PA_SUBTYPE_IETF_OPERATING_SYSTEM } +}; + +static imv_agent_t *imv_os; + +/** + * IMV OS database + */ +static imv_os_database_t *os_db; + +/* + * see section 3.8.1 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_Initialize(TNC_IMVID imv_id, + TNC_Version min_version, + TNC_Version max_version, + TNC_Version *actual_version) +{ + char *uri; + + if (imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has already been initialized", imv_name); + return TNC_RESULT_ALREADY_INITIALIZED; + } + imv_os = imv_agent_create(imv_name, msg_types, countof(msg_types), + imv_id, actual_version); + if (!imv_os) + { + return TNC_RESULT_FATAL; + } + if (min_version > TNC_IFIMV_VERSION_1 || max_version < TNC_IFIMV_VERSION_1) + { + DBG1(DBG_IMV, "no common IF-IMV version"); + return TNC_RESULT_NO_COMMON_VERSION; + } + + /* attach OS database */ + uri = lib->settings->get_str(lib->settings, + "libimcv.plugins.imv-os.database", NULL); + if (uri) + { + os_db = imv_os_database_create(uri); + } + + return TNC_RESULT_SUCCESS; +} + +/** + * see section 3.8.2 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id, + TNC_ConnectionID connection_id, + TNC_ConnectionState new_state) +{ + imv_state_t *state; + + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + switch (new_state) + { + case TNC_CONNECTION_STATE_CREATE: + state = imv_os_state_create(connection_id); + return imv_os->create_state(imv_os, state); + case TNC_CONNECTION_STATE_DELETE: + return imv_os->delete_state(imv_os, connection_id); + default: + return imv_os->change_state(imv_os, connection_id, + new_state, NULL); + } +} + +static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg) +{ + imv_msg_t *out_msg; + imv_os_state_t *os_state; + enumerator_t *enumerator; + pa_tnc_attr_t *attr; + pen_type_t type; + TNC_Result result; + chunk_t os_name = chunk_empty; + chunk_t os_version = chunk_empty; + bool fatal_error = FALSE, assessment = FALSE; + char non_market_apps_str[] = "install_non_market_apps"; + char android_id_str[] = "android_id"; + char machine_id_str[] = "/var/lib/dbus/machine-id"; + + os_state = (imv_os_state_t*)state; + + /* parse received PA-TNC message and handle local and remote errors */ + result = in_msg->receive(in_msg, &fatal_error); + if (result != TNC_RESULT_SUCCESS) + { + return result; + } + + out_msg = imv_msg_create_as_reply(in_msg); + + /* analyze PA-TNC attributes */ + enumerator = in_msg->create_attribute_enumerator(in_msg); + while (enumerator->enumerate(enumerator, &attr)) + { + type = attr->get_type(attr); + + if (type.vendor_id == PEN_IETF) + { + switch (type.type) + { + case IETF_ATTR_PRODUCT_INFORMATION: + { + ietf_attr_product_info_t *attr_cast; + pen_t vendor_id; + + attr_cast = (ietf_attr_product_info_t*)attr; + os_name = attr_cast->get_info(attr_cast, &vendor_id, NULL); + if (vendor_id != PEN_IETF) + { + DBG1(DBG_IMV, "operating system name is '%.*s' " + "from vendor %N", os_name.len, os_name.ptr, + pen_names, vendor_id); + } + else + { + DBG1(DBG_IMV, "operating system name is '%.*s'", + os_name.len, os_name.ptr); + } + break; + } + case IETF_ATTR_STRING_VERSION: + { + ietf_attr_string_version_t *attr_cast; + + attr_cast = (ietf_attr_string_version_t*)attr; + os_version = attr_cast->get_version(attr_cast, NULL, NULL); + if (os_version.len) + { + DBG1(DBG_IMV, "operating system version is '%.*s'", + os_version.len, os_version.ptr); + } + break; + } + case IETF_ATTR_NUMERIC_VERSION: + { + ietf_attr_numeric_version_t *attr_cast; + u_int32_t major, minor; + + attr_cast = (ietf_attr_numeric_version_t*)attr; + attr_cast->get_version(attr_cast, &major, &minor); + DBG1(DBG_IMV, "operating system numeric version is %d.%d", + major, minor); + break; + } + case IETF_ATTR_OPERATIONAL_STATUS: + { + ietf_attr_op_status_t *attr_cast; + op_status_t op_status; + op_result_t op_result; + time_t last_boot; + + attr_cast = (ietf_attr_op_status_t*)attr; + op_status = attr_cast->get_status(attr_cast); + op_result = attr_cast->get_result(attr_cast); + last_boot = attr_cast->get_last_use(attr_cast); + DBG1(DBG_IMV, "operational status: %N, result: %N", + op_status_names, op_status, op_result_names, op_result); + DBG1(DBG_IMV, "last boot: %T", &last_boot, TRUE); + break; + } + case IETF_ATTR_FORWARDING_ENABLED: + { + ietf_attr_fwd_enabled_t *attr_cast; + os_fwd_status_t fwd_status; + + attr_cast = (ietf_attr_fwd_enabled_t*)attr; + fwd_status = attr_cast->get_status(attr_cast); + DBG1(DBG_IMV, "IPv4 forwarding status: %N", + os_fwd_status_names, fwd_status); + if (fwd_status == OS_FWD_ENABLED) + { + os_state->set_os_settings(os_state, + OS_SETTINGS_FWD_ENABLED); + } + break; + } + case IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED: + { + ietf_attr_default_pwd_enabled_t *attr_cast; + bool default_pwd_status; + + attr_cast = (ietf_attr_default_pwd_enabled_t*)attr; + default_pwd_status = attr_cast->get_status(attr_cast); + DBG1(DBG_IMV, "factory default password: %sabled", + default_pwd_status ? "en":"dis"); + if (default_pwd_status) + { + os_state->set_os_settings(os_state, + OS_SETTINGS_DEFAULT_PWD_ENABLED); + } + break; + } + case IETF_ATTR_INSTALLED_PACKAGES: + { + ietf_attr_installed_packages_t *attr_cast; + enumerator_t *e; + status_t status; + + /* Received at least one Installed Packages attribute */ + os_state->set_package_request(os_state, FALSE); + + if (!os_db) + { + break; + } + attr_cast = (ietf_attr_installed_packages_t*)attr; + + e = attr_cast->create_enumerator(attr_cast); + status = os_db->check_packages(os_db, os_state, e); + e->destroy(e); + + if (status == FAILED) + { + state->set_recommendation(state, + TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION, + TNC_IMV_EVALUATION_RESULT_ERROR); + assessment = TRUE; + } + break; + } + default: + break; + } + } + else if (type.vendor_id == PEN_ITA) + { + switch (type.type) + { + case ITA_ATTR_SETTINGS: + { + ita_attr_settings_t *attr_cast; + enumerator_t *e; + char *name; + chunk_t value; + + attr_cast = (ita_attr_settings_t*)attr; + e = attr_cast->create_enumerator(attr_cast); + while (e->enumerate(e, &name, &value)) + { + if (streq(name, non_market_apps_str) && + chunk_equals(value, chunk_from_chars('1'))) + { + os_state->set_os_settings(os_state, + OS_SETTINGS_NON_MARKET_APPS); + } + else if ((streq(name, android_id_str) || + streq(name, machine_id_str)) && os_db) + { + os_state->set_device_id(os_state, + os_db->get_device_id(os_db, value)); + } + DBG1(DBG_IMV, "setting '%s'\n %.*s", + name, value.len, value.ptr); + } + e->destroy(e); + break; + } + case ITA_ATTR_START_ANGEL: + os_state->set_angel_count(os_state, TRUE); + break; + case ITA_ATTR_STOP_ANGEL: + os_state->set_angel_count(os_state, FALSE); + break; + default: + break; + } + } + } + enumerator->destroy(enumerator); + + if (os_name.len && os_version.len) + { + os_type_t os_type; + ita_attr_get_settings_t *attr_cast; + + /* set the OS type, name and version */ + os_type = os_type_from_name(os_name); + os_state->set_info(os_state,os_type, os_name, os_version); + + /* requesting installed packages */ + os_state->set_package_request(os_state, TRUE); + attr = ietf_attr_attr_request_create(PEN_IETF, + IETF_ATTR_INSTALLED_PACKAGES); + out_msg->add_attribute(out_msg, attr); + + /* requesting Android or Linux settings */ + attr = ita_attr_get_settings_create(); + attr_cast = (ita_attr_get_settings_t*)attr; + + if (os_type == OS_TYPE_ANDROID) + { + attr_cast->add(attr_cast, android_id_str); + attr_cast->add(attr_cast, non_market_apps_str); + } + else + { + attr_cast->add(attr_cast, machine_id_str); + attr_cast->add(attr_cast, "/proc/sys/kernel/tainted"); + } + out_msg->add_attribute(out_msg, attr); + } + + if (fatal_error) + { + state->set_recommendation(state, + TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION, + TNC_IMV_EVALUATION_RESULT_ERROR); + assessment = TRUE; + } + + /* If all Installed Packages attributes were received, go to assessment */ + if (!assessment && + !os_state->get_package_request(os_state) && + !os_state->get_angel_count(os_state)) + { + int device_id, count, count_update, count_blacklist, count_ok; + u_int os_settings; + + os_settings = os_state->get_os_settings(os_state); + os_state->get_count(os_state, &count, &count_update, &count_blacklist, + &count_ok); + DBG1(DBG_IMV, "processed %d packages: %d not updated, %d blacklisted, " + "%d ok, %d not found", count, count_update, count_blacklist, + count_ok, count - count_update - count_blacklist - count_ok); + + /* Store device information in database */ + device_id = os_state->get_device_id(os_state); + if (os_db && device_id) + { + os_db->set_device_info(os_db, device_id, + os_state->get_info(os_state, NULL, NULL, NULL), + count, count_update, count_blacklist, os_settings); + } + + if (count_update || count_blacklist || os_settings) + { + state->set_recommendation(state, + TNC_IMV_ACTION_RECOMMENDATION_ISOLATE, + TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR); + } + else + { + state->set_recommendation(state, + TNC_IMV_ACTION_RECOMMENDATION_ALLOW, + TNC_IMV_EVALUATION_RESULT_COMPLIANT); + } + assessment = TRUE; + } + + if (assessment) + { + result = out_msg->send_assessment(out_msg); + out_msg->destroy(out_msg); + if (result != TNC_RESULT_SUCCESS) + { + return result; + } + return imv_os->provide_recommendation(imv_os, state); + } + + /* send PA-TNC message with excl flag set */ + result = out_msg->send(out_msg, TRUE); + out_msg->destroy(out_msg); + + return result; + } + +/** + * see section 3.8.4 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id, + TNC_ConnectionID connection_id, + TNC_BufferReference msg, + TNC_UInt32 msg_len, + TNC_MessageType msg_type) +{ + imv_state_t *state; + imv_msg_t *in_msg; + TNC_Result result; + + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + if (!imv_os->get_state(imv_os, connection_id, &state)) + { + return TNC_RESULT_FATAL; + } + in_msg = imv_msg_create_from_data(imv_os, state, connection_id, msg_type, + chunk_create(msg, msg_len)); + result = receive_message(state, in_msg); + in_msg->destroy(in_msg); + + return result; +} + +/** + * see section 3.8.6 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_ReceiveMessageLong(TNC_IMVID imv_id, + TNC_ConnectionID connection_id, + TNC_UInt32 msg_flags, + TNC_BufferReference msg, + TNC_UInt32 msg_len, + TNC_VendorID msg_vid, + TNC_MessageSubtype msg_subtype, + TNC_UInt32 src_imc_id, + TNC_UInt32 dst_imv_id) +{ + imv_state_t *state; + imv_msg_t *in_msg; + TNC_Result result; + + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + if (!imv_os->get_state(imv_os, connection_id, &state)) + { + return TNC_RESULT_FATAL; + } + in_msg = imv_msg_create_from_long_data(imv_os, state, connection_id, + src_imc_id, dst_imv_id, msg_vid, msg_subtype, + chunk_create(msg, msg_len)); + result =receive_message(state, in_msg); + in_msg->destroy(in_msg); + + return result; +} + +/** + * see section 3.8.7 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_SolicitRecommendation(TNC_IMVID imv_id, + TNC_ConnectionID connection_id) +{ + imv_state_t *state; + + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + if (!imv_os->get_state(imv_os, connection_id, &state)) + { + return TNC_RESULT_FATAL; + } + return imv_os->provide_recommendation(imv_os, state); +} + +/** + * see section 3.8.8 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_BatchEnding(TNC_IMVID imv_id, + TNC_ConnectionID connection_id) +{ + imv_state_t *state; + imv_os_state_t *os_state; + TNC_Result result = TNC_RESULT_SUCCESS; + + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + if (!imv_os->get_state(imv_os, connection_id, &state)) + { + return TNC_RESULT_FATAL; + } + os_state = (imv_os_state_t*)state; + + if (os_state->get_info(os_state, NULL, NULL, NULL) == NULL) + { + imv_msg_t *out_msg; + pa_tnc_attr_t *attr; + ietf_attr_attr_request_t *attr_cast; + + out_msg = imv_msg_create(imv_os, state, connection_id, imv_id, + TNC_IMCID_ANY, msg_types[0]); + attr = ietf_attr_attr_request_create(PEN_IETF, + IETF_ATTR_PRODUCT_INFORMATION); + attr_cast = (ietf_attr_attr_request_t*)attr; + attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_STRING_VERSION); + attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_NUMERIC_VERSION); + attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_OPERATIONAL_STATUS); + attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_FORWARDING_ENABLED); + attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED); + out_msg->add_attribute(out_msg, attr); + + /* send PA-TNC message with excl flag not set */ + result = out_msg->send(out_msg, FALSE); + out_msg->destroy(out_msg); + } + + return result; +} + +/** + * see section 3.8.9 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_Terminate(TNC_IMVID imv_id) +{ + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + DESTROY_IF(os_db); + + imv_os->destroy(imv_os); + imv_os = NULL; + + return TNC_RESULT_SUCCESS; +} + +/** + * see section 4.2.8.1 of TCG TNC IF-IMV Specification 1.3 + */ +TNC_Result TNC_IMV_ProvideBindFunction(TNC_IMVID imv_id, + TNC_TNCS_BindFunctionPointer bind_function) +{ + if (!imv_os) + { + DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); + return TNC_RESULT_NOT_INITIALIZED; + } + return imv_os->bind_functions(imv_os, bind_function); +} diff --git a/src/libimcv/plugins/imv_os/imv_os_database.c b/src/libimcv/plugins/imv_os/imv_os_database.c new file mode 100644 index 000000000..c6db9953f --- /dev/null +++ b/src/libimcv/plugins/imv_os/imv_os_database.c @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#include "imv_os_database.h" + +#include <utils/debug.h> + +#include <string.h> + +typedef struct private_imv_os_database_t private_imv_os_database_t; + +/** + * Private data of a imv_os_database_t object. + * + */ +struct private_imv_os_database_t { + + /** + * Public imv_os_database_t interface. + */ + imv_os_database_t public; + + /** + * database instance + */ + database_t *db; + +}; + +METHOD(imv_os_database_t, check_packages, status_t, + private_imv_os_database_t *this, imv_os_state_t *state, + enumerator_t *package_enumerator) +{ + char *product, *package, *release, *cur_release; + u_char *pos; + chunk_t os_name, os_version, name, version; + os_type_t os_type; + size_t os_version_len; + os_package_state_t package_state; + int pid, gid; + int count = 0, count_ok = 0, count_no_match = 0, count_blacklist = 0; + enumerator_t *e; + status_t status = SUCCESS; + bool found, match; + + state->get_info(state, &os_type, &os_name, &os_version); + + if (os_type == OS_TYPE_ANDROID) + { + /*no package dependency on Android version */ + product = strdup(enum_to_name(os_type_names, os_type)); + } + else + { + /* remove appended platform info */ + pos = memchr(os_version.ptr, ' ', os_version.len); + os_version_len = pos ? (pos - os_version.ptr) : os_version.len; + product = malloc(os_name.len + 1 + os_version_len + 1); + sprintf(product, "%.*s %.*s", (int)os_name.len, os_name.ptr, + (int)os_version_len, os_version.ptr); + } + DBG1(DBG_IMV, "processing installed '%s' packages", product); + + /* Get primary key of product */ + e = this->db->query(this->db, + "SELECT id FROM products WHERE name = ?", + DB_TEXT, product, DB_INT); + if (!e) + { + free(product); + return FAILED; + } + if (!e->enumerate(e, &pid)) + { + e->destroy(e); + free(product); + return NOT_FOUND; + } + e->destroy(e); + + while (package_enumerator->enumerate(package_enumerator, &name, &version)) + { + /* Convert package name chunk to a string */ + package = strndup(name.ptr, name.len); + count++; + + /* Get primary key of package */ + e = this->db->query(this->db, + "SELECT id FROM packages WHERE name = ?", + DB_TEXT, package, DB_INT); + if (!e) + { + free(product); + free(package); + return FAILED; + } + if (!e->enumerate(e, &gid)) + { + /* package not present in database for any product - skip */ + if (os_type == OS_TYPE_ANDROID) + { + DBG2(DBG_IMV, "package '%s' (%.*s) not found", + package, version.len, version.ptr); + } + free(package); + e->destroy(e); + continue; + } + e->destroy(e); + + /* Convert package version chunk to a string */ + release = strndup(version.ptr, version.len); + + /* Enumerate over all acceptable versions */ + e = this->db->query(this->db, + "SELECT release, security FROM versions " + "WHERE product = ? AND package = ?", + DB_INT, pid, DB_INT, gid, DB_TEXT, DB_INT); + if (!e) + { + free(product); + free(package); + free(release); + return FAILED; + } + found = FALSE; + match = FALSE; + + while (e->enumerate(e, &cur_release, &package_state)) + { + found = TRUE; + if (streq(release, cur_release) || streq("*", cur_release)) + { + match = TRUE; + break; + } + } + e->destroy(e); + + if (found) + { + if (match) + { + if (package_state == OS_PACKAGE_STATE_BLACKLIST) + { + DBG2(DBG_IMV, "package '%s' (%s) is blacklisted", + package, release); + count_blacklist++; + state->add_bad_package(state, package, package_state); + } + else + { + DBG2(DBG_IMV, "package '%s' (%s)%N is ok", package, release, + os_package_state_names, package_state); + count_ok++; + } + } + else + { + DBG1(DBG_IMV, "package '%s' (%s) no match", package, release); + count_no_match++; + state->add_bad_package(state, package, package_state); + } + } + else + { + /* package not present in database for this product - skip */ + } + free(package); + free(release); + } + free(product); + state->set_count(state, count, count_no_match, count_blacklist, count_ok); + + return status; +} + +METHOD(imv_os_database_t, get_device_id, int, + private_imv_os_database_t *this, chunk_t value) +{ + enumerator_t *e; + int id; + + /* get primary key of device ID */ + e = this->db->query(this->db, "SELECT id FROM devices WHERE value = ?", + DB_BLOB, value, DB_INT); + if (!e) + { + return 0; + } + if (e->enumerate(e, &id)) + { + /* device ID already exists in database - return primary key */ + e->destroy(e); + return id; + } + + /* register new device ID in database and return primary key */ + return (this->db->execute(this->db, &id, + "INSERT INTO devices (value) VALUES (?)", DB_BLOB, value) == 1) ? + id : 0; +} + +METHOD(imv_os_database_t, set_device_info, void, + private_imv_os_database_t *this, int device_id, char *os_info, + int count, int count_update, int count_blacklist, u_int flags) +{ + enumerator_t *e; + time_t last_time; + int pid = 0, last_pid = 0, last_count_update = 0, last_count_blacklist = 0; + u_int last_flags; + bool found = FALSE; + + /* get primary key of OS info string if it exists */ + e = this->db->query(this->db, + "SELECT id FROM products WHERE name = ?", DB_TEXT, os_info, + DB_INT); + if (e) + { + e->enumerate(e, &pid); + e->destroy(e); + } + + /* if OS ifo string has not been found - register it */ + if (!pid) + { + this->db->execute(this->db, &pid, + "INSERT INTO products (name) VALUES (?)", DB_TEXT, os_info); + } + + /* get latest device info record if it exists */ + e = this->db->query(this->db, + "SELECT time, product, count_update, count_blacklist, flags " + "FROM device_infos WHERE device = ? ORDER BY time DESC", + DB_INT, device_id, DB_UINT, DB_INT, DB_INT, DB_INT, DB_UINT); + if (e) + { + found = e->enumerate(e, &last_time, &last_pid, &last_count_update, + &last_count_blacklist, &last_flags); + e->destroy(e); + } + if (found && !last_count_update && !last_count_blacklist && !last_flags && + pid == last_pid) + { + /* update device info */ + this->db->execute(this->db, NULL, + "UPDATE device_infos SET time = ?, count = ?, count_update = ?, " + "count_blacklist = ?, flags = ? WHERE device = ? AND time = ?", + DB_UINT, time(NULL), DB_INT, count, DB_INT, count_update, + DB_INT, count_blacklist, DB_UINT, flags, + DB_INT, device_id, DB_UINT, last_time); + } + else + { + /* insert device info */ + this->db->execute(this->db, NULL, + "INSERT INTO device_infos (device, time, product, count, " + "count_update, count_blacklist, flags) VALUES (?, ?, ?, ?, ?, ?, ?)", + DB_INT, device_id, DB_UINT, time(NULL), DB_INT, pid, + DB_INT, count, DB_INT, count_update, DB_INT, count_blacklist, + DB_UINT, flags); + } +} + +METHOD(imv_os_database_t, destroy, void, + private_imv_os_database_t *this) +{ + this->db->destroy(this->db); + free(this); +} + +/** + * See header + */ +imv_os_database_t *imv_os_database_create(char *uri) +{ + private_imv_os_database_t *this; + + INIT(this, + .public = { + .check_packages = _check_packages, + .get_device_id = _get_device_id, + .set_device_info = _set_device_info, + .destroy = _destroy, + }, + .db = lib->db->create(lib->db, uri), + ); + + if (!this->db) + { + DBG1(DBG_IMV, + "failed to connect to OS database '%s'", uri); + free(this); + return NULL; + } + + return &this->public; +} + diff --git a/src/libimcv/plugins/imv_os/imv_os_database.h b/src/libimcv/plugins/imv_os/imv_os_database.h new file mode 100644 index 000000000..9ce748f9b --- /dev/null +++ b/src/libimcv/plugins/imv_os/imv_os_database.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +/** + * + * @defgroup imv_os_database_t imv_os_database + * @{ @ingroup imv_os_database + */ + +#ifndef IMV_OS_DATABASE_H_ +#define IMV_OS_DATABASE_H_ + +#include "imv_os_state.h" + +#include <library.h> + +typedef struct imv_os_database_t imv_os_database_t; + +/** + * Internal state of an imv_os_database_t instance + */ +struct imv_os_database_t { + + /** + * Check Installed Packages for a given OS + * + * @param state OS IMV state + * @param package_enumerator enumerates over installed packages + */ + status_t (*check_packages)(imv_os_database_t *this, imv_os_state_t *state, + enumerator_t *package_enumerator); + + /** + * Get the primary database key of the device ID + * + * @param value Device ID value + */ + int (*get_device_id)(imv_os_database_t *this, chunk_t value); + + /** + * Set health infos for a given device + * + * @param device_id Device ID primary key + * @param os_info OS info string + * @param count Number of installed packages + * @param count_update Number of packages to be updated + * @param count_blacklist Number of blacklisted packages + * @param flags Various flags, e.g. illegal OS settings + */ + void (*set_device_info)(imv_os_database_t *this, int device_id, char *os_info, + int count, int count_update, int count_blacklist, + u_int flags); + + /** + * Destroys an imv_os_database_t object. + */ + void (*destroy)(imv_os_database_t *this); + +}; + +/** + * Create an imv_os_database_t instance + * + * @param uri database uri + */ +imv_os_database_t* imv_os_database_create(char *uri); + +#endif /** IMV_OS_DATABASE_H_ @}*/ diff --git a/src/libimcv/plugins/imv_os/imv_os_state.c b/src/libimcv/plugins/imv_os/imv_os_state.c new file mode 100644 index 000000000..ca6e050f7 --- /dev/null +++ b/src/libimcv/plugins/imv_os/imv_os_state.c @@ -0,0 +1,621 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#include "imv_os_state.h" +#include "imv/imv_lang_string.h" +#include "imv/imv_reason_string.h" +#include "imv/imv_remediation_string.h" + +#include <utils/debug.h> +#include <collections/linked_list.h> + +typedef struct private_imv_os_state_t private_imv_os_state_t; +typedef struct package_entry_t package_entry_t; +typedef struct entry_t entry_t; +typedef struct instruction_entry_t instruction_entry_t; + +/** + * Private data of an imv_os_state_t object. + */ +struct private_imv_os_state_t { + + /** + * Public members of imv_os_state_t + */ + imv_os_state_t public; + + /** + * TNCCS connection ID + */ + TNC_ConnectionID connection_id; + + /** + * TNCCS connection state + */ + TNC_ConnectionState state; + + /** + * Does the TNCCS connection support long message types? + */ + bool has_long; + + /** + * Does the TNCCS connection support exclusive delivery? + */ + bool has_excl; + + /** + * Maximum PA-TNC message size for this TNCCS connection + */ + u_int32_t max_msg_len; + + /** + * IMV action recommendation + */ + TNC_IMV_Action_Recommendation rec; + + /** + * IMV evaluation result + */ + TNC_IMV_Evaluation_Result eval; + + /** + * OS Product Information (concatenation of OS Name and Version) + */ + char *info; + + /** + * OS Type + */ + os_type_t type; + + /** + * OS Name + */ + chunk_t name; + + /** + * OS Version + */ + chunk_t version; + + /** + * List of blacklisted packages to be removed + */ + linked_list_t *remove_packages; + + /** + * List of vulnerable packages to be updated + */ + linked_list_t *update_packages; + + /** + * TNC Reason String + */ + imv_reason_string_t *reason_string; + + /** + * IETF Remediation Instructions String + */ + imv_remediation_string_t *remediation_string; + + /** + * Primary database key of device ID + */ + int device_id; + + /** + * Number of processed packages + */ + int count; + + /** + * Number of not updated packages + */ + int count_update; + + /** + * Number of blacklisted packages + */ + int count_blacklist; + + /** + * Number of whitelisted packages + */ + int count_ok; + + /** + * OS Installed Package request sent - mandatory response expected + */ + bool package_request; + + /** + * OS Settings + */ + u_int os_settings; + + /** + * Angel count + */ + int angel_count; + +}; + +/** + * Supported languages + */ +static char* languages[] = { "en", "de", "pl" }; + +/** + * Reason strings for "OS settings" + */ +static imv_lang_string_t reason_settings[] = { + { "en", "Improper OS settings were detected" }, + { "de", "Unzulässige OS Einstellungen wurden festgestellt" }, + { "pl", "Stwierdzono niewłaściwe ustawienia OS" }, + { NULL, NULL } +}; + +/** + * Reason strings for "installed software packages" + */ +static imv_lang_string_t reason_packages[] = { + { "en", "Vulnerable or blacklisted software packages were found" }, + { "de", "Schwachstellenbehaftete oder gesperrte Softwarepakete wurden gefunden" }, + { "pl", "Znaleziono pakiety podatne na atak lub będące na czarnej liście" }, + { NULL, NULL } +}; + +/** + * Instruction strings for "Software Security Updates" + */ +static imv_lang_string_t instr_update_packages_title[] = { + { "en", "Software Security Updates" }, + { "de", "Software Sicherheitsupdates" }, + { "pl", "Aktualizacja softwaru zabezpieczającego" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_update_packages_descr[] = { + { "en", "Packages with security vulnerabilities were found" }, + { "de", "Softwarepakete mit Sicherheitsschwachstellen wurden gefunden" }, + { "pl", "Znaleziono pakiety podatne na atak" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_update_packages_header[] = { + { "en", "Please update the following software packages:" }, + { "de", "Bitte updaten Sie die folgenden Softwarepakete:" }, + { "pl", "Proszę zaktualizować następujące pakiety:" }, + { NULL, NULL } +}; + +/** + * Instruction strings for "Blacklisted Software Packages" + */ +static imv_lang_string_t instr_remove_packages_title[] = { + { "en", "Blacklisted Software Packages" }, + { "de", "Gesperrte Softwarepakete" }, + { "pl", "Pakiety będące na czarnej liście" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_remove_packages_descr[] = { + { "en", "Dangerous software packages were found" }, + { "de", "Gefährliche Softwarepakete wurden gefunden" }, + { "pl", "Znaleziono niebezpieczne pakiety" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_remove_packages_header[] = { + { "en", "Please remove the following software packages:" }, + { "de", "Bitte entfernen Sie die folgenden Softwarepakete:" }, + { "pl", "Proszę usunąć następujące pakiety:" }, + { NULL, NULL } +}; + +;/** + * Instruction strings for "Forwarding Enabled" + */ +static imv_lang_string_t instr_fwd_enabled_title[] = { + { "en", "IP Packet Forwarding" }, + { "de", "Weiterleitung von IP Paketen" }, + { "pl", "Przekazywanie pakietów IP" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_fwd_enabled_descr[] = { + { "en", "Please disable the forwarding of IP packets" }, + { "de", "Bitte deaktivieren Sie das Forwarding von IP Paketen" }, + { "pl", "Proszę zdezaktywować przekazywanie pakietów IP" }, + { NULL, NULL } +}; + +/** + * Instruction strings for "Default Password Enabled" + */ +static imv_lang_string_t instr_default_pwd_enabled_title[] = { + { "en", "Default Password" }, + { "de", "Default Passwort" }, + { "pl", "Hasło domyślne" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_default_pwd_enabled_descr[] = { + { "en", "Please change the default password" }, + { "de", "Bitte ändern Sie das Default Passwort" }, + { "pl", "Proszę zmienić domyślne hasło" }, + { NULL, NULL } +}; + +/** + * Instruction strings for "Install Non-Market Apps" + */ +static imv_lang_string_t instr_non_market_apps_title[] = { + { "en", "Unknown Software Origin" }, + { "de", "Unbekannte Softwareherkunft" }, + { "pl", "Nieznane pochodzenie softwaru" }, + { NULL, NULL } +}; + +static imv_lang_string_t instr_non_market_apps_descr[] = { + { "en", "Do not allow the installation of apps from unknown sources" }, + { "de", "Erlauben Sie nicht die Installation von Apps aus unbekannten Quellen" }, + { "pl", "Proszę nie dopuszczać do instalacji Apps z nieznanych źródeł" }, + { NULL, NULL } +}; + +METHOD(imv_state_t, get_connection_id, TNC_ConnectionID, + private_imv_os_state_t *this) +{ + return this->connection_id; +} + +METHOD(imv_state_t, has_long, bool, + private_imv_os_state_t *this) +{ + return this->has_long; +} + +METHOD(imv_state_t, has_excl, bool, + private_imv_os_state_t *this) +{ + return this->has_excl; +} + +METHOD(imv_state_t, set_flags, void, + private_imv_os_state_t *this, bool has_long, bool has_excl) +{ + this->has_long = has_long; + this->has_excl = has_excl; +} + +METHOD(imv_state_t, set_max_msg_len, void, + private_imv_os_state_t *this, u_int32_t max_msg_len) +{ + this->max_msg_len = max_msg_len; +} + +METHOD(imv_state_t, get_max_msg_len, u_int32_t, + private_imv_os_state_t *this) +{ + return this->max_msg_len; +} + +METHOD(imv_state_t, change_state, void, + private_imv_os_state_t *this, TNC_ConnectionState new_state) +{ + this->state = new_state; +} + +METHOD(imv_state_t, get_recommendation, void, + private_imv_os_state_t *this, TNC_IMV_Action_Recommendation *rec, + TNC_IMV_Evaluation_Result *eval) +{ + *rec = this->rec; + *eval = this->eval; +} + +METHOD(imv_state_t, set_recommendation, void, + private_imv_os_state_t *this, TNC_IMV_Action_Recommendation rec, + TNC_IMV_Evaluation_Result eval) +{ + this->rec = rec; + this->eval = eval; +} + +METHOD(imv_state_t, get_reason_string, bool, + private_imv_os_state_t *this, enumerator_t *language_enumerator, + chunk_t *reason_string, char **reason_language) +{ + if (!this->count_update && !this->count_blacklist & !this->os_settings) + { + return FALSE; + } + *reason_language = imv_lang_string_select_lang(language_enumerator, + languages, countof(languages)); + + /* Instantiate a TNC Reason String object */ + DESTROY_IF(this->reason_string); + this->reason_string = imv_reason_string_create(*reason_language); + + if (this->count_update || this->count_blacklist) + { + this->reason_string->add_reason(this->reason_string, reason_packages); + } + if (this->os_settings) + { + this->reason_string->add_reason(this->reason_string, reason_settings); + } + *reason_string = this->reason_string->get_encoding(this->reason_string); + + return TRUE; +} + +METHOD(imv_state_t, get_remediation_instructions, bool, + private_imv_os_state_t *this, enumerator_t *language_enumerator, + chunk_t *string, char **lang_code, char **uri) +{ + if (!this->count_update && !this->count_blacklist & !this->os_settings) + { + return FALSE; + } + *lang_code = imv_lang_string_select_lang(language_enumerator, + languages, countof(languages)); + + /* Instantiate an IETF Remediation Instructions String object */ + DESTROY_IF(this->remediation_string); + this->remediation_string = imv_remediation_string_create( + this->type == OS_TYPE_ANDROID, *lang_code); + + /* List of blacklisted packages to be removed, if any */ + if (this->count_blacklist) + { + this->remediation_string->add_instruction(this->remediation_string, + instr_remove_packages_title, + instr_remove_packages_descr, + instr_remove_packages_header, + this->remove_packages); + } + + /* List of packages in need of an update, if any */ + if (this->count_update) + { + this->remediation_string->add_instruction(this->remediation_string, + instr_update_packages_title, + instr_update_packages_descr, + instr_update_packages_header, + this->update_packages); + } + + /* Add instructions concerning improper OS settings */ + if (this->os_settings & OS_SETTINGS_FWD_ENABLED) + { + this->remediation_string->add_instruction(this->remediation_string, + instr_fwd_enabled_title, + instr_fwd_enabled_descr, NULL, NULL); + } + if (this->os_settings & OS_SETTINGS_DEFAULT_PWD_ENABLED) + { + this->remediation_string->add_instruction(this->remediation_string, + instr_default_pwd_enabled_title, + instr_default_pwd_enabled_descr, NULL, NULL); + } + if (this->os_settings & OS_SETTINGS_NON_MARKET_APPS) + { + this->remediation_string->add_instruction(this->remediation_string, + instr_non_market_apps_title, + instr_non_market_apps_descr, NULL, NULL); + } + + *string = this->remediation_string->get_encoding(this->remediation_string); + *uri = lib->settings->get_str(lib->settings, + "libimcv.plugins.imv-os.remediation_uri", NULL); + + return TRUE; +} + +METHOD(imv_state_t, destroy, void, + private_imv_os_state_t *this) +{ + DESTROY_IF(this->reason_string); + DESTROY_IF(this->remediation_string); + this->update_packages->destroy_function(this->update_packages, free); + this->remove_packages->destroy_function(this->remove_packages, free); + free(this->info); + free(this->name.ptr); + free(this->version.ptr); + free(this); +} + +METHOD(imv_os_state_t, set_info, void, + private_imv_os_state_t *this, os_type_t type, chunk_t name, chunk_t version) +{ + int len = name.len + 1 + version.len + 1; + + /* OS info is a concatenation of OS name and OS version */ + free(this->info); + this->info = malloc(len); + snprintf(this->info, len, "%.*s %.*s", (int)name.len, name.ptr, + (int)version.len, version.ptr); + this->type = type; + this->name = chunk_clone(name); + this->version = chunk_clone(version); +} + +METHOD(imv_os_state_t, get_info, char*, + private_imv_os_state_t *this, os_type_t *type, chunk_t *name, + chunk_t *version) +{ + if (type) + { + *type = this->type; + } + if (name) + { + *name = this->name; + } + if (version) + { + *version = this->version; + } + return this->info; +} + +METHOD(imv_os_state_t, set_count, void, + private_imv_os_state_t *this, int count, int count_update, + int count_blacklist, int count_ok) +{ + this->count += count; + this->count_update += count_update; + this->count_blacklist += count_blacklist; + this->count_ok += count_ok; +} + +METHOD(imv_os_state_t, get_count, void, + private_imv_os_state_t *this, int *count, int *count_update, + int *count_blacklist, int *count_ok) +{ + if (count) + { + *count = this->count; + } + if (count_update) + { + *count_update = this->count_update; + } + if (count_blacklist) + { + *count_blacklist = this->count_blacklist; + } + if (count_ok) + { + *count_ok = this->count_ok; + } +} + +METHOD(imv_os_state_t, set_package_request, void, + private_imv_os_state_t *this, bool set) +{ + this->package_request = set; +} + +METHOD(imv_os_state_t, get_package_request, bool, + private_imv_os_state_t *this) +{ + return this->package_request; +} + +METHOD(imv_os_state_t, set_device_id, void, + private_imv_os_state_t *this, int id) +{ + this->device_id = id; +} + +METHOD(imv_os_state_t, get_device_id, int, + private_imv_os_state_t *this) +{ + return this->device_id; +} + +METHOD(imv_os_state_t, set_os_settings, void, + private_imv_os_state_t *this, u_int settings) +{ + this->os_settings |= settings; +} + +METHOD(imv_os_state_t, get_os_settings, u_int, + private_imv_os_state_t *this) +{ + return this->os_settings; +} + +METHOD(imv_os_state_t, set_angel_count, void, + private_imv_os_state_t *this, bool start) +{ + this->angel_count += start ? 1 : -1; +} + +METHOD(imv_os_state_t, get_angel_count, int, + private_imv_os_state_t *this) +{ + return this->angel_count; +} + +METHOD(imv_os_state_t, add_bad_package, void, + private_imv_os_state_t *this, char *package, + os_package_state_t package_state) +{ + package = strdup(package); + + if (package_state == OS_PACKAGE_STATE_BLACKLIST) + { + this->remove_packages->insert_last(this->remove_packages, package); + } + else + { + this->update_packages->insert_last(this->update_packages, package); + } +} + +/** + * Described in header. + */ +imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id) +{ + private_imv_os_state_t *this; + + INIT(this, + .public = { + .interface = { + .get_connection_id = _get_connection_id, + .has_long = _has_long, + .has_excl = _has_excl, + .set_flags = _set_flags, + .set_max_msg_len = _set_max_msg_len, + .get_max_msg_len = _get_max_msg_len, + .change_state = _change_state, + .get_recommendation = _get_recommendation, + .set_recommendation = _set_recommendation, + .get_reason_string = _get_reason_string, + .get_remediation_instructions = _get_remediation_instructions, + .destroy = _destroy, + }, + .set_info = _set_info, + .get_info = _get_info, + .set_count = _set_count, + .get_count = _get_count, + .set_package_request = _set_package_request, + .get_package_request = _get_package_request, + .set_device_id = _set_device_id, + .get_device_id = _get_device_id, + .set_os_settings = _set_os_settings, + .get_os_settings = _get_os_settings, + .set_angel_count = _set_angel_count, + .get_angel_count = _get_angel_count, + .add_bad_package = _add_bad_package, + }, + .state = TNC_CONNECTION_STATE_CREATE, + .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION, + .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW, + .connection_id = connection_id, + .update_packages = linked_list_create(), + .remove_packages = linked_list_create(), + ); + + return &this->public.interface; +} + + diff --git a/src/libimcv/plugins/imv_os/imv_os_state.h b/src/libimcv/plugins/imv_os/imv_os_state.h new file mode 100644 index 000000000..05abdbb6c --- /dev/null +++ b/src/libimcv/plugins/imv_os/imv_os_state.h @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +/** + * + * @defgroup imv_os_state_t imv_os_state + * @{ @ingroup imv_os_state + */ + +#ifndef IMV_OS_STATE_H_ +#define IMV_OS_STATE_H_ + +#include "os_info/os_info.h" +#include <imv/imv_state.h> +#include <library.h> + +typedef struct imv_os_state_t imv_os_state_t; +typedef enum os_settings_t os_settings_t; + +enum os_settings_t { + OS_SETTINGS_FWD_ENABLED = 1, + OS_SETTINGS_DEFAULT_PWD_ENABLED = 2, + OS_SETTINGS_NON_MARKET_APPS = 4 +}; + +/** + * Internal state of an imv_os_t connection instance + */ +struct imv_os_state_t { + + /** + * imv_state_t interface + */ + imv_state_t interface; + + /** + * Set OS Product Information + * + * @param type OS type (enumerated) + * @param name OS name (string) + * @param version OS version + */ + void (*set_info)(imv_os_state_t *this, os_type_t os_type, + chunk_t name, chunk_t version); + + /** + * Get OS Product Information + * + * @param type OS type (enumerated) + * @param name OS name (string) + * @param version OS version + * @return OS name & version as a concatenated string + */ + char* (*get_info)(imv_os_state_t *this, os_type_t *os_type, + chunk_t *name, chunk_t *version); + + /** + * Set [or with multiple attributes increment] package counters + * + * @param count Number of processed packages + * @param count_update Number of not updated packages + * @param count_blacklist Number of blacklisted packages + * @param count_ok Number of whitelisted packages + */ + void (*set_count)(imv_os_state_t *this, int count, int count_update, + int count_blacklist, int count_ok); + + /** + * Set [or with multiple attributes increment] package counters + * + * @param count Number of processed packages + * @param count_update Number of not updated packages + * @param count_blacklist Number of blacklisted packages + * @param count_ok Number of whitelisted packages + */ + void (*get_count)(imv_os_state_t *this, int *count, int *count_update, + int *count_blacklist, int *count_ok); + /** + * Set/reset OS Installed Packages request status + * + * @param set TRUE to set, FALSE to clear + */ + void (*set_package_request)(imv_os_state_t *this, bool set); + + /** + * Get OS Installed Packages request status + * + * @return TRUE if set, FALSE if unset + */ + bool (*get_package_request)(imv_os_state_t *this); + + /** + * Set device ID + * + * @param device_id Device ID primary database key + */ + void (*set_device_id)(imv_os_state_t *this, int id); + + /** + * Get device ID + * + * @return Device ID primary database key + */ + int (*get_device_id)(imv_os_state_t *this); + + /** + * Set OS settings + * + * @param settings OS settings + */ + void (*set_os_settings)(imv_os_state_t *this, u_int settings); + + /** + * Get OS settings + * + * @return OS settings + */ + u_int (*get_os_settings)(imv_os_state_t *this); + + /** + * Increase/Decrease the ITA Angel count + * + * @param start TRUE increases and FALSE decreases count by one + */ + void (*set_angel_count)(imv_os_state_t *this, bool start); + + /** + * Get the ITA Angel count + * + * @return ITA Angel count + */ + int (*get_angel_count)(imv_os_state_t *this); + + /** + * Store a bad package that has to be updated or removed + * + * @param package Name of software package + * @param package_state Security state of software package + */ + void (*add_bad_package)(imv_os_state_t *this, char *package, + os_package_state_t package_state); + +}; + +/** + * Create an imv_os_state_t instance + * + * @param id connection ID + */ +imv_state_t* imv_os_state_create(TNC_ConnectionID id); + +#endif /** IMV_OS_STATE_H_ @}*/ diff --git a/src/libimcv/plugins/imv_os/pacman.c b/src/libimcv/plugins/imv_os/pacman.c new file mode 100644 index 000000000..f5f52885d --- /dev/null +++ b/src/libimcv/plugins/imv_os/pacman.c @@ -0,0 +1,498 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#define _GNU_SOURCE +#include <getopt.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <syslog.h> +#include <time.h> + +#include "imv_os_state.h" + +#include <library.h> +#include <utils/debug.h> + +/** + * global debug output variables + */ +static int debug_level = 1; +static bool stderr_quiet = TRUE; + +/** + * pacman dbg function + */ +static void pacman_dbg(debug_t group, level_t level, char *fmt, ...) +{ + int priority = LOG_INFO; + char buffer[8192]; + char *current = buffer, *next; + va_list args; + + if (level <= debug_level) + { + if (!stderr_quiet) + { + va_start(args, fmt); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); + } + + /* write in memory buffer first */ + va_start(args, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, args); + va_end(args); + + /* do a syslog with every line */ + while (current) + { + next = strchr(current, '\n'); + if (next) + { + *(next++) = '\0'; + } + syslog(priority, "%s\n", current); + current = next; + } + } +} + +/** + * atexit handler to close everything on shutdown + */ +static void cleanup(void) +{ + closelog(); + library_deinit(); +} + +static void usage(void) +{ + printf("Usage:\n" + "ipsec pacman --product <name> --file <filename> [--update]\n"); +} + +/** + * Extract the time the package file was generated + */ +static time_t extract_time(char *line) +{ + struct tm t; + char wday[4], mon[4]; + char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + int i; + + if (sscanf(line, "Generated: %3s %3s %2d %2d:%2d:%2d %4d UTC", wday, mon, + &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec, &t.tm_year) != 7) + { + return UNDEFINED_TIME; + } + t.tm_isdst = 0; + t.tm_year -= 1900; + t.tm_mon = 12; + + for (i = 0; i < countof(months); i++) + { + if (streq(mon, months[i])) + { + t.tm_mon = i; + break; + } + } + if (t.tm_mon == 12) + { + return UNDEFINED_TIME; + } + + return mktime(&t) - timezone; +} + +/** + * Process a package file and store updates in the database + */ +static void process_packages(char *filename, char *product, bool update) +{ + char *uri, line[12288], *pos; + int count = 0, errored = 0, vulnerable = 0, new_packages = 0; + int new_versions = 0, updated_versions = 0, deleted_versions = 0; + u_int32_t pid = 0; + enumerator_t *e; + database_t *db; + FILE *file; + + /* opening package file */ + printf("loading\"%s\"\n", filename); + file = fopen(filename, "r"); + if (!file) + { + fprintf(stderr, "could not open \"%s\"\n", filename); + exit(EXIT_FAILURE); + } + + /* connect package database */ + uri = lib->settings->get_str(lib->settings, "pacman.database", NULL); + if (!uri) + { + fprintf(stderr, "database URI pacman.database not set\n"); + fclose(file); + exit(EXIT_FAILURE); + } + db = lib->db->create(lib->db, uri); + if (!db) + { + fprintf(stderr, "could not connect to database '%s'\n", uri); + fclose(file); + exit(EXIT_FAILURE); + } + + /* check if product is already in database */ + e = db->query(db, "SELECT id FROM products WHERE name = ?", + DB_TEXT, product, DB_INT); + if (e) + { + if (!e->enumerate(e, &pid)) + { + pid = 0; + } + e->destroy(e); + } + if (!pid) + { + if (db->execute(db, &pid, "INSERT INTO products (name) VALUES (?)", + DB_TEXT, product) != 1) + { + fprintf(stderr, "could not store product '%s' to database\n", + product); + fclose(file); + db->destroy(db); + exit(EXIT_FAILURE); + } + } + + while (fgets(line, sizeof(line), file)) + { + char *package, *version; + char *cur_version, *version_update = NULL, *version_delete = NULL; + bool security, add_version = TRUE; + int cur_security, security_update = 0, security_delete = 0; + u_int32_t gid = 0, vid = 0, vid_update = 0, vid_delete = 0; + time_t gen_time, cur_time; + + count++; + if (count == 1) + { + printf("%s", line); + } + if (count == 3) + { + gen_time = extract_time(line); + + if (gen_time == UNDEFINED_TIME) + { + fprintf(stderr, "could not extract generation time\n"); + fclose(file); + db->destroy(db); + exit(EXIT_FAILURE); + } + printf("Generated: %T\n", &gen_time, TRUE); + } + if (count < 7) + { + continue; + } + + /* look for the package name */ + pos = strchr(line, ' '); + if (!pos) + { + fprintf(stderr, "could not extract package name from '%.*s'\n", + (int)(strlen(line)-1), line); + errored++; + continue; + } + *pos++ = '\0'; + package = line; + + /* look for version string in parentheses */ + if (*pos == '(') + { + version = ++pos; + pos = strchr(pos, ')'); + if (pos) + { + *pos++ = '\0'; + } + else + { + fprintf(stderr, "could not extract package version from " + "'%.*s'\n", (int)(strlen(line)-1), line); + errored++; + continue; + } + } + else + { + /* no version information, skip entry */ + continue; + } + security = (strstr(pos, "[security]") != NULL); + if (security) + { + vulnerable++; + } + + /* handle non-security packages in update mode only */ + if (!update && !security) + { + continue; + } + + /* check if package is already in database */ + e = db->query(db, "SELECT id FROM packages WHERE name = ?", + DB_TEXT, package, DB_INT); + if (e) + { + if (!e->enumerate(e, &gid)) + { + gid = 0; + } + e->destroy(e); + } + if (!gid && security) + { + if (db->execute(db, &gid, "INSERT INTO packages (name) VALUES (?)", + DB_TEXT, package) != 1) + { + fprintf(stderr, "could not store package '%s' to database\n", + package); + fclose(file); + db->destroy(db); + exit(EXIT_FAILURE); + } + new_packages++; + } + + /* check for package versions already in database */ + e = db->query(db, + "SELECT id, release, security, time FROM versions " + "WHERE package = ? AND product = ?", + DB_INT, gid, DB_INT, pid, DB_INT, DB_TEXT, DB_INT, DB_INT); + if (!e) + { + break; + } + while (e->enumerate(e, &vid, &cur_version, &cur_security, &cur_time)) + { + if (streq(version, cur_version)) + { + /* already in data base */ + add_version = FALSE; + break; + } + else if (gen_time > cur_time) + { + if (security) + { + if (cur_security) + { + vid_update = vid; + version_update = strdup(cur_version); + security_update = cur_security; + } + else + { + vid_delete = vid; + version_delete = strdup(cur_version); + security_delete = cur_security; + } + } + else + { + if (!cur_security) + { + vid_update = vid; + version_update = strdup(cur_version); + security_update = cur_security; + } + } + } + else + { + if (security == cur_security) + { + add_version = FALSE; + } + } + } + e->destroy(e); + + if ((!vid && !security) || (vid && !add_version)) + { + free(version_update); + free(version_delete); + continue; + } + + if ((!vid && security) || (vid && !vid_update)) + { + printf("%s (%s) %s\n", package, version, security ? "[s]" : ""); + + if (db->execute(db, &vid, + "INSERT INTO versions " + "(package, product, release, security, time) " + "VALUES (?, ?, ?, ?, ?)", DB_INT, gid, DB_INT, pid, + DB_TEXT, version, DB_INT, security, DB_INT, gen_time) != 1) + { + fprintf(stderr, "could not store version '%s' to database\n", + version); + free(version_update); + free(version_delete); + fclose(file); + db->destroy(db); + exit(EXIT_FAILURE); + } + new_versions++; + } + else + { + printf("%s (%s) %s updated by\n", + package, version_update, security_update ? "[s]" : ""); + printf("%s (%s) %s\n", package, version, security ? "[s]" : ""); + + if (db->execute(db, NULL, + "UPDATE versions SET release = ?, time = ? WHERE id = ?", + DB_TEXT, version, DB_INT, gen_time, DB_INT, vid_update) <= 0) + { + fprintf(stderr, "could not update version '%s' to database\n", + version); + free(version_update); + free(version_delete); + fclose(file); + db->destroy(db); + exit(EXIT_FAILURE); + } + updated_versions++; + } + + if (vid_delete) + { + printf("%s (%s) %s deleted\n", + package, version_delete, security_delete ? "[s]" : ""); + + if (db->execute(db, NULL, + "DELETE FROM versions WHERE id = ?", + DB_INT, vid_delete) <= 0) + { + fprintf(stderr, "could not delete version '%s' from database\n", + version_delete); + free(version_update); + free(version_delete); + fclose(file); + db->destroy(db); + exit(EXIT_FAILURE); + } + deleted_versions++; + } + free(version_update); + free(version_delete); + } + fclose(file); + db->destroy(db); + + printf("processed %d packages, %d security, %d new packages, " + "%d new versions, %d updated versions, %d deleted versions, " + "%d errored\n", count - 6, vulnerable, new_packages, new_versions, + updated_versions, deleted_versions, errored); +} + +static void do_args(int argc, char *argv[]) +{ + char *filename = NULL, *product = NULL; + bool update = FALSE; + + /* reinit getopt state */ + optind = 0; + + while (TRUE) + { + int c; + + struct option long_opts[] = { + { "help", no_argument, NULL, 'h' }, + { "file", required_argument, NULL, 'f' }, + { "product", required_argument, NULL, 'p' }, + { "update", no_argument, NULL, 'u' }, + { 0,0,0,0 } + }; + + c = getopt_long(argc, argv, "", long_opts, NULL); + switch (c) + { + case EOF: + break; + case 'h': + usage(); + exit(EXIT_SUCCESS); + case 'f': + filename = optarg; + continue; + case 'p': + product = optarg; + continue; + case 'u': + update = TRUE; + continue; + } + break; + } + + if (filename && product) + { + process_packages(filename, product, update); + } + else + { + usage(); + exit(EXIT_FAILURE); + } +} + +int main(int argc, char *argv[]) +{ + /* enable attest debugging hook */ + dbg = pacman_dbg; + openlog("pacman", 0, LOG_DEBUG); + + atexit(cleanup); + + /* initialize library */ + if (!library_init(NULL)) + { + exit(SS_RC_LIBSTRONGSWAN_INTEGRITY); + } + if (!lib->plugins->load(lib->plugins, NULL, + lib->settings->get_str(lib->settings, "attest.load", "sqlite"))) + { + exit(SS_RC_INITIALIZATION_FAILED); + } + do_args(argc, argv); + + exit(EXIT_SUCCESS); +} + diff --git a/src/libimcv/plugins/imv_os/pacman.sh b/src/libimcv/plugins/imv_os/pacman.sh new file mode 100755 index 000000000..e9134ea5d --- /dev/null +++ b/src/libimcv/plugins/imv_os/pacman.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +DATE=`date +%Y%m%d` +DEBIAN=http://packages.debian.org +UBUNTU=http://packages.ubuntu.com +UBUNTU_VERSIONS="quantal precise oneiric lucid" +PACKAGES=allpackages?format=txt.gz +PACMAN=/usr/libexec/ipsec/pacman +DIR=/etc/pts + +cd $DIR + +for v in $UBUNTU_VERSIONS +do + wget $UBUNTU/$v/$PACKAGES -O $DATE-$v.txt.gz + wget $UBUNTU/$v-updates/$PACKAGES -O $DATE-$v-updates.txt.gz +done + +wget $DEBIAN/stable/$PACKAGES -O $DATE-squeeze.txt.gz +gunzip *.gz + +$PACMAN --product "Ubuntu 12.10" --file $DATE-quantal.txt +echo +$PACMAN --product "Ubuntu 12.10" --file $DATE-quantal-updates.txt --update +echo +$PACMAN --product "Ubuntu 12.04" --file $DATE-precise.txt +echo +$PACMAN --product "Ubuntu 12.04" --file $DATE-precise-updates.txt --update +echo +$PACMAN --product "Ubuntu 11.10" --file $DATE-oneiric.txt +echo +$PACMAN --product "Ubuntu 11.10" --file $DATE-oneiric-updates.txt --update +echo +$PACMAN --product "Ubuntu 10.04" --file $DATE-lucid.txt +echo +$PACMAN --product "Ubuntu 10.04" --file $DATE-lucid-updates.txt --update +echo +$PACMAN --product "Debian squeeze" --file $DATE-squeeze.txt + +cp config.db config.db-$DATE |