summaryrefslogtreecommitdiff
path: root/src/sw-collector
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw-collector')
-rw-r--r--src/sw-collector/Makefile.am32
-rw-r--r--src/sw-collector/Makefile.in894
-rw-r--r--src/sw-collector/sw-collector.8.in124
-rw-r--r--src/sw-collector/sw-collector.c652
-rw-r--r--src/sw-collector/sw_collector_db.c427
-rw-r--r--src/sw-collector/sw_collector_db.h155
-rw-r--r--src/sw-collector/sw_collector_dpkg.c152
-rw-r--r--src/sw-collector/sw_collector_dpkg.h53
-rw-r--r--src/sw-collector/sw_collector_history.c519
-rw-r--r--src/sw-collector/sw_collector_history.h91
-rw-r--r--src/sw-collector/sw_collector_rest_api.c200
-rw-r--r--src/sw-collector/sw_collector_rest_api.h57
-rw-r--r--src/sw-collector/sw_collector_tables.sql31
13 files changed, 3387 insertions, 0 deletions
diff --git a/src/sw-collector/Makefile.am b/src/sw-collector/Makefile.am
new file mode 100644
index 000000000..4ed73c925
--- /dev/null
+++ b/src/sw-collector/Makefile.am
@@ -0,0 +1,32 @@
+sbin_PROGRAMS = sw-collector
+
+sw_collector_SOURCES = \
+ sw-collector.c \
+ sw_collector_db.h sw_collector_db.c \
+ sw_collector_dpkg.h sw_collector_dpkg.c \
+ sw_collector_history.h sw_collector_history.c \
+ sw_collector_rest_api.h sw_collector_rest_api.c
+
+sw-collector.o : $(top_builddir)/config.status
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libtncif \
+ -I$(top_srcdir)/src/libimcv \
+ -DPLUGINS=\""random openssl sqlite curl"\"
+
+AM_CFLAGS = $(json_CFLAGS)
+
+sw_collector_LDADD = \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la \
+ $(top_builddir)/src/libimcv/libimcv.la \
+ $(json_LIBS)
+
+templatesdir = $(pkgdatadir)/templates/database/sw-collector
+dist_templates_DATA = sw_collector_tables.sql
+
+man8_MANS = sw-collector.8
+
+CLEANFILES = $(man8_MANS)
+
+
diff --git a/src/sw-collector/Makefile.in b/src/sw-collector/Makefile.in
new file mode 100644
index 000000000..73016ad72
--- /dev/null
+++ b/src/sw-collector/Makefile.in
@@ -0,0 +1,894 @@
+# Makefile.in generated by automake 1.15 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2014 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@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+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@
+sbin_PROGRAMS = sw-collector$(EXEEXT)
+subdir = src/sw-collector
+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/split-package-version.m4 \
+ $(top_srcdir)/m4/macros/with.m4 \
+ $(top_srcdir)/m4/macros/enable-disable.m4 \
+ $(top_srcdir)/m4/macros/add-plugin.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(dist_templates_DATA) \
+ $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES = sw-collector.8
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" \
+ "$(DESTDIR)$(templatesdir)"
+PROGRAMS = $(sbin_PROGRAMS)
+am_sw_collector_OBJECTS = sw-collector.$(OBJEXT) \
+ sw_collector_db.$(OBJEXT) sw_collector_dpkg.$(OBJEXT) \
+ sw_collector_history.$(OBJEXT) sw_collector_rest_api.$(OBJEXT)
+sw_collector_OBJECTS = $(am_sw_collector_OBJECTS)
+am__DEPENDENCIES_1 =
+sw_collector_DEPENDENCIES = \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la \
+ $(top_builddir)/src/libimcv/libimcv.la $(am__DEPENDENCIES_1)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+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) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(sw_collector_SOURCES)
+DIST_SOURCES = $(sw_collector_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+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; }; \
+ }
+man8dir = $(mandir)/man8
+NROFF = nroff
+MANS = $(man8_MANS)
+DATA = $(dist_templates_DATA)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/sw-collector.8.in \
+ $(top_srcdir)/depcomp
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+ATOMICLIB = @ATOMICLIB@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BFDLIB = @BFDLIB@
+BTLIB = @BTLIB@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+COVERAGE_CFLAGS = @COVERAGE_CFLAGS@
+COVERAGE_LDFLAGS = @COVERAGE_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLIB = @DLLIB@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+EASY_INSTALL = @EASY_INSTALL@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GEM = @GEM@
+GENHTML = @GENHTML@
+GPERF = @GPERF@
+GPRBUILD = @GPRBUILD@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LCOV = @LCOV@
+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@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MYSQLCFLAG = @MYSQLCFLAG@
+MYSQLCONFIG = @MYSQLCONFIG@
+MYSQLLIB = @MYSQLLIB@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OPENSSL_LIB = @OPENSSL_LIB@
+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@
+PACKAGE_VERSION_BUILD = @PACKAGE_VERSION_BUILD@
+PACKAGE_VERSION_MAJOR = @PACKAGE_VERSION_MAJOR@
+PACKAGE_VERSION_MINOR = @PACKAGE_VERSION_MINOR@
+PACKAGE_VERSION_REVIEW = @PACKAGE_VERSION_REVIEW@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PERL = @PERL@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PLUGIN_CFLAGS = @PLUGIN_CFLAGS@
+PTHREADLIB = @PTHREADLIB@
+PYTHON = @PYTHON@
+PYTHONEGGINSTALLDIR = @PYTHONEGGINSTALLDIR@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PACKAGE_VERSION = @PYTHON_PACKAGE_VERSION@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+PY_TEST = @PY_TEST@
+RANLIB = @RANLIB@
+RTLIB = @RTLIB@
+RUBY = @RUBY@
+RUBYGEMDIR = @RUBYGEMDIR@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SOCKLIB = @SOCKLIB@
+STRIP = @STRIP@
+UNWINDLIB = @UNWINDLIB@
+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@
+aikgen_plugins = @aikgen_plugins@
+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@
+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@
+cmd_plugins = @cmd_plugins@
+datadir = @datadir@
+datarootdir = @datarootdir@
+dev_headers = @dev_headers@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+fips_mode = @fips_mode@
+fuzz_plugins = @fuzz_plugins@
+gtk_CFLAGS = @gtk_CFLAGS@
+gtk_LIBS = @gtk_LIBS@
+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@
+json_CFLAGS = @json_CFLAGS@
+json_LIBS = @json_LIBS@
+libdir = @libdir@
+libexecdir = @libexecdir@
+libfuzzer = @libfuzzer@
+libiptc_CFLAGS = @libiptc_CFLAGS@
+libiptc_LIBS = @libiptc_LIBS@
+linux_headers = @linux_headers@
+localedir = @localedir@
+localstatedir = @localstatedir@
+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@
+p_plugins = @p_plugins@
+pcsclite_CFLAGS = @pcsclite_CFLAGS@
+pcsclite_LIBS = @pcsclite_LIBS@
+pdfdir = @pdfdir@
+piddir = @piddir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+pki_plugins = @pki_plugins@
+plugindir = @plugindir@
+pool_plugins = @pool_plugins@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+random_device = @random_device@
+resolv_conf = @resolv_conf@
+routing_table = @routing_table@
+routing_table_prio = @routing_table_prio@
+ruby_CFLAGS = @ruby_CFLAGS@
+ruby_LIBS = @ruby_LIBS@
+runstatedir = @runstatedir@
+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@
+strongswan_options = @strongswan_options@
+swanctldir = @swanctldir@
+sysconfdir = @sysconfdir@
+systemd_CFLAGS = @systemd_CFLAGS@
+systemd_LIBS = @systemd_LIBS@
+systemd_daemon_CFLAGS = @systemd_daemon_CFLAGS@
+systemd_daemon_LIBS = @systemd_daemon_LIBS@
+systemd_journal_CFLAGS = @systemd_journal_CFLAGS@
+systemd_journal_LIBS = @systemd_journal_LIBS@
+systemdsystemunitdir = @systemdsystemunitdir@
+t_plugins = @t_plugins@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+tss2_CFLAGS = @tss2_CFLAGS@
+tss2_LIBS = @tss2_LIBS@
+tss2_socket_CFLAGS = @tss2_socket_CFLAGS@
+tss2_socket_LIBS = @tss2_socket_LIBS@
+tss2_tabrmd_CFLAGS = @tss2_tabrmd_CFLAGS@
+tss2_tabrmd_LIBS = @tss2_tabrmd_LIBS@
+urandom_device = @urandom_device@
+xml_CFLAGS = @xml_CFLAGS@
+xml_LIBS = @xml_LIBS@
+sw_collector_SOURCES = \
+ sw-collector.c \
+ sw_collector_db.h sw_collector_db.c \
+ sw_collector_dpkg.h sw_collector_dpkg.c \
+ sw_collector_history.h sw_collector_history.c \
+ sw_collector_rest_api.h sw_collector_rest_api.c
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libtncif \
+ -I$(top_srcdir)/src/libimcv \
+ -DPLUGINS=\""random openssl sqlite curl"\"
+
+AM_CFLAGS = $(json_CFLAGS)
+sw_collector_LDADD = \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la \
+ $(top_builddir)/src/libimcv/libimcv.la \
+ $(json_LIBS)
+
+templatesdir = $(pkgdatadir)/templates/database/sw-collector
+dist_templates_DATA = sw_collector_tables.sql
+man8_MANS = sw-collector.8
+CLEANFILES = $(man8_MANS)
+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/sw-collector/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src/sw-collector/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):
+sw-collector.8: $(top_builddir)/config.status $(srcdir)/sw-collector.8.in
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+install-sbinPROGRAMS: $(sbin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \
+ fi; \
+ 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)$(sbindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-sbinPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || 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)$(sbindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(sbindir)" && rm -f $$files
+
+clean-sbinPROGRAMS:
+ @list='$(sbin_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
+
+sw-collector$(EXEEXT): $(sw_collector_OBJECTS) $(sw_collector_DEPENDENCIES) $(EXTRA_sw_collector_DEPENDENCIES)
+ @rm -f sw-collector$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(sw_collector_OBJECTS) $(sw_collector_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sw-collector.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sw_collector_db.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sw_collector_dpkg.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sw_collector_history.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sw_collector_rest_api.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+install-man8: $(man8_MANS)
+ @$(NORMAL_INSTALL)
+ @list1='$(man8_MANS)'; \
+ list2=''; \
+ test -n "$(man8dir)" \
+ && test -n "`echo $$list1$$list2`" \
+ || exit 0; \
+ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \
+ { for i in $$list1; do echo "$$i"; done; \
+ if test -n "$$list2"; then \
+ for i in $$list2; do echo "$$i"; done \
+ | sed -n '/\.8[a-z]*$$/p'; \
+ fi; \
+ } | while read p; do \
+ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; echo "$$p"; \
+ done | \
+ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+ sed 'N;N;s,\n, ,g' | { \
+ list=; while read file base inst; do \
+ if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \
+ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \
+ fi; \
+ done; \
+ for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+ while read files; do \
+ test -z "$$files" || { \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \
+ done; }
+
+uninstall-man8:
+ @$(NORMAL_UNINSTALL)
+ @list='$(man8_MANS)'; test -n "$(man8dir)" || exit 0; \
+ files=`{ for i in $$list; do echo "$$i"; done; \
+ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir)
+install-dist_templatesDATA: $(dist_templates_DATA)
+ @$(NORMAL_INSTALL)
+ @list='$(dist_templates_DATA)'; test -n "$(templatesdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(templatesdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(templatesdir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(templatesdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(templatesdir)" || exit $$?; \
+ done
+
+uninstall-dist_templatesDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(dist_templates_DATA)'; test -n "$(templatesdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(templatesdir)'; $(am__uninstall_files_from_dir)
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ 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-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ 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"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+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 $(PROGRAMS) $(MANS) $(DATA)
+installdirs:
+ for dir in "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" "$(DESTDIR)$(templatesdir)"; 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:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+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-libtool clean-sbinPROGRAMS \
+ 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-dist_templatesDATA install-man
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-sbinPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man: install-man8
+
+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-dist_templatesDATA uninstall-man \
+ uninstall-sbinPROGRAMS
+
+uninstall-man: uninstall-man8
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-sbinPROGRAMS cscopelist-am ctags ctags-am \
+ 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-dist_templatesDATA install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-man8 install-pdf install-pdf-am install-ps \
+ install-ps-am install-sbinPROGRAMS 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 tags-am uninstall uninstall-am \
+ uninstall-dist_templatesDATA uninstall-man uninstall-man8 \
+ uninstall-sbinPROGRAMS
+
+.PRECIOUS: Makefile
+
+
+sw-collector.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/sw-collector/sw-collector.8.in b/src/sw-collector/sw-collector.8.in
new file mode 100644
index 000000000..8560ba095
--- /dev/null
+++ b/src/sw-collector/sw-collector.8.in
@@ -0,0 +1,124 @@
+.TH SW-COLLECTOR 1 "2017-07-15" "@PACKAGE_VERSION@" "strongSwan"
+.
+.SH "NAME"
+.
+sw-collector \- Extracts software installation events from dpkg history log
+.
+.SH "SYNOPSIS"
+.
+.SY "sw-collector"
+.OP \-\-debug level
+.OP \-\-quiet
+.OP \-\-count event-count
+.YS
+.
+.SY "sw-collector"
+.OP \-\-debug level
+.OP \-\-quiet
+.OP \-\-installed\fR|\fB\--removed
+.BR \-\-list |\fB\-\-unregistered
+.YS
+.
+.SY "sw-collector"
+.OP \-\-debug level
+.OP \-\-quiet
+.OP \-\-installed\fR|\fB\--removed
+.OP \-\-full
+.BR \-\-generate
+.YS
+.
+.SY "sw-collector"
+.OP \-\-debug level
+.OP \-\-quiet
+.BR \-\-migrate
+.YS
+.
+.SY "sw-collector"
+.B \-h
+|
+.B \-\-help
+.YS
+.
+.SH "DESCRIPTION"
+.
+.B sw-collector
+extracts information about software package installation, update or removal
+events from the apt history log and stores the software events in an SQLite
+database. The retrieved history information is then merged and made consistent
+with the actual list of installed software packages obtained with dpkg-query.
+.
+.SH "OPTIONS"
+.
+.TP
+.B "\-h, \-\-help"
+Prints usage information and a short summary of the available commands.
+.TP
+.BI "\-v, \-\-debug " level
+Set debug level, default: 2.
+.TP
+.B "\-q, \-\-quiet
+Disable debug output to stderr.
+.TP
+.B "\-i, \-\-installed
+Apply command to installed software packages, only.
+.TP
+.B "\-r, \-\-removed
+Apply command to removed software packages, only.
+.TP
+.B "\-f, \-\-full
+Generate ISO 19770-2:2015 SWID tags with full file information (possible for
+installed software packages, only).
+.TP
+.B "\-l, \-\-list
+Lists all software packages stored in the collector database showing their
+installation status.
+.TP
+.B "\-u, \-\-unregistered
+Lists all software packages residing in the local collector database but for
+which no SWID tags exist yet in a central collector database reachable via a
+REST interface.
+.TP
+.B "\-g, \-\-generate
+Generates ISO 19770-2:2015 SWID tags for all software packages residing in the
+local collector database but for which no SWID tags exist in a central collector
+database reachable via a REST interface.
+.TP
+.B "\-m, \-\-migrate
+Can be used to migrate collector database versions. Currently all architecture
+suffixes are removed from dpkg package names.
+.
+.SH "CONFIGURATION"
+.
+The following parameters can be configured in strongswan.conf:
+.P
+ sw-collector {
+ database = sqlite:///etc/pts/collector.db
+ history = /var/log/apt/history.log
+ first_time = 2016-04-22T20:55:14Z
+ rest_api {
+ uri = https://admin-user:ietf99hackathon@tnc.strongswan.org/api/
+ timeout = 120
+ }
+ }
+.P
+The parameters of the swid_generator used with the \-\-generate command can
+be changed in the libimcv section of strongswan.conf:
+.P
+ libimcv {
+ swid_gen {
+ command = /usr/local/bin/swid_generator
+ tag_creator {
+ name = strongSwan Project
+ regid = strongswan.org
+ }
+ }
+ }
+.
+.SH "FILES"
+.
+@PKGDATADIR@/templates/database/sw-collector/sw_collector_tables.sql
+.
+.SH "SEE ALSO"
+.
+.BR strongswan.conf (5)
+
diff --git a/src/sw-collector/sw-collector.c b/src/sw-collector/sw-collector.c
new file mode 100644
index 000000000..e673dd657
--- /dev/null
+++ b/src/sw-collector/sw-collector.c
@@ -0,0 +1,652 @@
+/*
+ * Copyright (C) 2017 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 <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <getopt.h>
+#include <unistd.h>
+#ifdef HAVE_SYSLOG
+# include <syslog.h>
+#endif
+
+#include "sw_collector_db.h"
+#include "sw_collector_history.h"
+#include "sw_collector_rest_api.h"
+#include "sw_collector_dpkg.h"
+#
+#include <library.h>
+#include <utils/debug.h>
+#include <utils/lexparser.h>
+
+#include <swid_gen/swid_gen.h>
+
+/**
+ * global debug output variables
+ */
+static int debug_level = 2;
+static bool stderr_quiet = FALSE;
+static int count = 0;
+
+typedef enum collector_op_t collector_op_t;
+
+enum collector_op_t {
+ COLLECTOR_OP_EXTRACT,
+ COLLECTOR_OP_LIST,
+ COLLECTOR_OP_UNREGISTERED,
+ COLLECTOR_OP_GENERATE,
+ COLLECTOR_OP_MIGRATE
+};
+
+/**
+ * sw_collector dbg function
+ */
+static void sw_collector_dbg(debug_t group, level_t level, char *fmt, ...)
+{
+ va_list args;
+
+ if (level <= debug_level)
+ {
+ if (!stderr_quiet)
+ {
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+ }
+
+#ifdef HAVE_SYSLOG
+ {
+ int priority = LOG_INFO;
+ char buffer[8192];
+ char *current = buffer, *next;
+
+ /* 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;
+ }
+ }
+#endif /* HAVE_SYSLOG */
+ }
+}
+
+/**
+ * atexit handler
+ */
+static void cleanup(void)
+{
+ library_deinit();
+#ifdef HAVE_SYSLOG
+ closelog();
+#endif
+}
+
+/**
+ * Display usage of sw-collector command
+ */
+static void usage(void)
+{
+ printf("\
+Usage:\n\
+ sw-collector --help\n\
+ sw-collector [--debug <level>] [--quiet] [--count <event count>]\n\
+ sw-collector [--debug <level>] [--quiet] [--installed|--removed] \
+--list|-unregistered\n\
+ sw-collector [--debug <level>] [--quiet] [--installed|--removed] \
+[--full] --generate\n\
+ sw-collector [--debug <level>] [--quiet] --migrate\n");
+}
+
+/**
+ * Parse command line options
+ */
+static collector_op_t do_args(int argc, char *argv[], bool *full_tags,
+ sw_collector_db_query_t *query_type)
+{
+ collector_op_t op = COLLECTOR_OP_EXTRACT;
+ bool installed = FALSE, removed = FALSE, full = FALSE;
+
+ /* reinit getopt state */
+ optind = 0;
+
+ while (TRUE)
+ {
+ int c;
+
+ struct option long_opts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "count", required_argument, NULL, 'c' },
+ { "debug", required_argument, NULL, 'd' },
+ { "full", no_argument, NULL, 'f' },
+ { "generate", no_argument, NULL, 'g' },
+ { "installed", no_argument, NULL, 'i' },
+ { "list", no_argument, NULL, 'l' },
+ { "migrate", no_argument, NULL, 'm' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "removed", no_argument, NULL, 'r' },
+ { "unregistered", no_argument, NULL, 'u' },
+ { 0,0,0,0 }
+ };
+
+ c = getopt_long(argc, argv, "hc:d:fgilmqru", long_opts, NULL);
+ switch (c)
+ {
+ case EOF:
+ break;
+ case 'h':
+ usage();
+ exit(SUCCESS);
+ break;
+ case 'c':
+ count = atoi(optarg);
+ continue;
+ case 'd':
+ debug_level = atoi(optarg);
+ continue;
+ case 'f':
+ full = TRUE;
+ continue;
+ case 'g':
+ op = COLLECTOR_OP_GENERATE;
+ continue;
+ case 'i':
+ installed = TRUE;
+ continue;
+ case 'l':
+ op = COLLECTOR_OP_LIST;
+ continue;
+ case 'm':
+ op = COLLECTOR_OP_MIGRATE;
+ continue;
+ case 'q':
+ stderr_quiet = TRUE;
+ continue;
+ case 'r':
+ removed = TRUE;
+ continue;
+ case 'u':
+ op = COLLECTOR_OP_UNREGISTERED;
+ continue;
+ default:
+ usage();
+ exit(EXIT_FAILURE);
+ }
+ break;
+ }
+
+ if ((!installed && !removed) || (installed && removed))
+ {
+ *query_type = SW_QUERY_ALL;
+ }
+ else if (installed)
+ {
+ *query_type = SW_QUERY_INSTALLED;
+ }
+ else
+ {
+ *query_type = SW_QUERY_REMOVED;
+ }
+ *full_tags = full;
+
+ return op;
+}
+
+/**
+ * Extract software events from apt history log files
+ */
+static int extract_history(sw_collector_db_t *db)
+{
+ sw_collector_history_t *history = NULL;
+ uint32_t epoch, last_eid, eid = 0;
+ char *history_path, *last_time = NULL, rfc_time[21];
+ chunk_t *h, history_chunk, line, cmd;
+ int status = EXIT_FAILURE;
+ bool skip = TRUE;
+
+ /* open history file for reading */
+ history_path = lib->settings->get_str(lib->settings, "%s.history", NULL,
+ lib->ns);
+ if (!history_path)
+ {
+ fprintf(stderr, "sw-collector.history path not set.\n");
+ return EXIT_FAILURE;
+ }
+ h = chunk_map(history_path, FALSE);
+ if (!h)
+ {
+ fprintf(stderr, "opening '%s' failed: %s", history_path,
+ strerror(errno));
+ return EXIT_FAILURE;
+ }
+ history_chunk = *h;
+
+ /* Instantiate history extractor */
+ history = sw_collector_history_create(db, 1);
+ if (!history)
+ {
+ return EXIT_FAILURE;
+ }
+
+ /* retrieve last event in database */
+ if (!db->get_last_event(db, &last_eid, &epoch, &last_time) || !last_eid)
+ {
+ goto end;
+ }
+ DBG0(DBG_IMC, "Last-Event: %s, eid = %u, epoch = %u",
+ last_time, last_eid, epoch);
+
+ /* parse history file */
+ while (fetchline(&history_chunk, &line))
+ {
+ if (line.len == 0)
+ {
+ continue;
+ }
+ if (!extract_token(&cmd, ':', &line))
+ {
+ fprintf(stderr, "terminator symbol ':' not found.\n");
+ goto end;
+ }
+ if (match("Start-Date", &cmd))
+ {
+ if (!history->extract_timestamp(history, line, rfc_time))
+ {
+ goto end;
+ }
+
+ /* have we reached new history entries? */
+ if (skip && strcmp(rfc_time, last_time) > 0)
+ {
+ skip = FALSE;
+ }
+ if (skip)
+ {
+ continue;
+ }
+
+ /* insert new event into database */
+ eid = db->add_event(db, rfc_time);
+ if (!eid)
+ {
+ goto end;
+ }
+ DBG1(DBG_IMC, "Start-Date: %s, eid = %u, epoch = %u",
+ rfc_time, eid, epoch);
+ }
+ else if (skip)
+ {
+ /* skip old history entries which have already been processed */
+ continue;
+ }
+ else if (match("Install", &cmd))
+ {
+ DBG1(DBG_IMC, " Install:");
+ if (!history->extract_packages(history, line, eid, SW_OP_INSTALL))
+ {
+ goto end;
+ }
+ }
+ else if (match("Upgrade", &cmd))
+ {
+ DBG1(DBG_IMC, " Upgrade:");
+ if (!history->extract_packages(history, line, eid, SW_OP_UPGRADE))
+ {
+ goto end;
+ }
+ }
+ else if (match("Remove", &cmd))
+ {
+ DBG1(DBG_IMC, " Remove:");
+ if (!history->extract_packages(history, line, eid, SW_OP_REMOVE))
+ {
+ goto end;
+ }
+ }
+ else if (match("Purge", &cmd))
+ {
+ DBG1(DBG_IMC, " Purge:");
+ if (!history->extract_packages(history, line, eid, SW_OP_REMOVE))
+ {
+ goto end;
+ }
+ }
+ else if (match("End-Date", &cmd))
+ {
+ /* Process 'count' events at a time */
+ if (count > 0 && eid - last_eid == count)
+ {
+ fprintf(stderr, "added %d events\n", count);
+ goto end;
+ }
+ }
+ }
+
+ if (history->merge_installed_packages(history))
+ {
+ status = EXIT_SUCCESS;
+ }
+
+end:
+ free(last_time);
+ history->destroy(history);
+ chunk_unmap(h);
+
+ return status;
+}
+
+/**
+ * List all endpoint software identifiers stored in local collector database
+ */
+static int list_identifiers(sw_collector_db_t *db, sw_collector_db_query_t type)
+{
+ enumerator_t *e;
+ char *name, *package, *version;
+ uint32_t sw_id, count = 0, installed_count = 0, removed_count, installed;
+
+ e = db->create_sw_enumerator(db, type, NULL);
+ if (!e)
+ {
+ return EXIT_FAILURE;
+ }
+ while (e->enumerate(e, &sw_id, &name, &package, &version, &installed))
+ {
+ printf("%s,%s,%s,%d\n", name, package, version, installed);
+ if (installed)
+ {
+ installed_count++;
+ }
+ count++;
+ }
+ removed_count = count - installed_count;
+ e->destroy(e);
+
+ switch (type)
+ {
+ case SW_QUERY_ALL:
+ DBG1(DBG_IMC, "retrieved %u software identities with %u installed "
+ "and %u removed", count, installed_count, removed_count);
+ break;
+ case SW_QUERY_INSTALLED:
+ DBG1(DBG_IMC, "retrieved %u installed software identities", count);
+ break;
+ case SW_QUERY_REMOVED:
+ DBG1(DBG_IMC, "retrieved %u removed software identities", count);
+ break;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+static bool query_registry(sw_collector_rest_api_t *rest_api, bool installed)
+{
+ sw_collector_db_query_t type;
+ enumerator_t *enumerator;
+ char *sw_id;
+ int count = 0;
+
+ type = installed ? SW_QUERY_INSTALLED : SW_QUERY_REMOVED;
+ enumerator = rest_api->create_sw_enumerator(rest_api, type);
+ if (!enumerator)
+ {
+ return FALSE;
+ }
+ while (enumerator->enumerate(enumerator, &sw_id))
+ {
+ printf("%s,%s\n", sw_id, installed ? "1" : "0");
+ count++;
+ }
+ enumerator->destroy(enumerator);
+ DBG1(DBG_IMC, "%d %s software identifiers not registered", count,
+ installed ? "installed" : "removed");
+ return TRUE;
+}
+
+
+/**
+ * List all endpoint software identifiers stored in local collector database
+ * that are not registered yet in central collelector database
+ */
+static int unregistered_identifiers(sw_collector_db_t *db,
+ sw_collector_db_query_t type)
+{
+ sw_collector_rest_api_t *rest_api;
+ int status = EXIT_SUCCESS;
+
+ rest_api = sw_collector_rest_api_create(db);
+ if (!rest_api)
+ {
+ return EXIT_FAILURE;
+ }
+
+ /* List installed software identifiers not registered centrally */
+ if (type != SW_QUERY_REMOVED && !query_registry(rest_api, TRUE))
+ {
+ status = EXIT_FAILURE;
+ }
+
+ /* List removed software identifiers not registered centrally */
+ if (type != SW_QUERY_INSTALLED && !query_registry(rest_api, FALSE))
+ {
+ status = EXIT_FAILURE;
+ }
+ rest_api->destroy(rest_api);
+
+ return status;
+}
+
+/**
+ * Generate ISO 19770-2:2015 SWID tags for [installed|removed|all]
+ * SW identifiers that are not registered centrally
+ */
+static int generate_tags(sw_collector_db_t *db, bool full_tags,
+ sw_collector_db_query_t type)
+{
+ swid_gen_t * swid_gen;
+ sw_collector_rest_api_t *rest_api;
+ char *name, *package, *version, *tag;
+ enumerator_t *enumerator;
+ uint32_t sw_id;
+ bool installed;
+ int count = 0, installed_count = 0, status = EXIT_FAILURE;
+
+ swid_gen = swid_gen_create();
+ rest_api = sw_collector_rest_api_create(db);
+ if (!rest_api)
+ {
+ goto end;
+ }
+
+ enumerator = rest_api->create_sw_enumerator(rest_api, type);
+ if (!enumerator)
+ {
+ goto end;
+ }
+ while (enumerator->enumerate(enumerator, &name))
+ {
+ sw_id = db->get_sw_id(db, name, &package, &version, NULL, &installed);
+ if (sw_id)
+ {
+ tag = swid_gen->generate_tag(swid_gen, name, package, version,
+ full_tags && installed, FALSE);
+ if (tag)
+ {
+ DBG2(DBG_IMC, " creating %s", name);
+ printf("%s\n", tag);
+ free(tag);
+ count++;
+ if (installed)
+ {
+ installed_count++;
+ }
+ }
+ free(package);
+ free(version);
+ }
+ }
+ enumerator->destroy(enumerator);
+ status = EXIT_SUCCESS;
+
+ switch (type)
+ {
+ case SW_QUERY_ALL:
+ DBG1(DBG_IMC, "created %d tags for unregistered software "
+ "identifiers with %d installed and %d removed", count,
+ installed_count, count - installed_count);
+ break;
+ case SW_QUERY_INSTALLED:
+ DBG1(DBG_IMC, "created %d tags for unregistered installed software "
+ "identifiers", count);
+ break;
+ case SW_QUERY_REMOVED:
+ DBG1(DBG_IMC, "created %d tags for unregistered removed software "
+ "identifiers", count);
+ break;
+ }
+
+end:
+ swid_gen->destroy(swid_gen);
+ DESTROY_IF(rest_api);
+
+ return status;
+}
+
+/**
+ * Append missing architecture suffix to package entries in the database
+ */
+static int migrate(sw_collector_db_t *db)
+{
+ sw_collector_dpkg_t *dpkg;
+
+ char *package, *arch, *version;
+ char package_filter[BUF_LEN];
+ int res, count = 0;
+ int status = EXIT_SUCCESS;
+ enumerator_t *enumerator;
+
+ dpkg = sw_collector_dpkg_create();
+ if (!dpkg)
+ {
+ return FAILED;
+ }
+
+ enumerator = dpkg->create_sw_enumerator(dpkg);
+ while (enumerator->enumerate(enumerator, &package, &arch, &version))
+ {
+
+ /* Look for package names with architecture suffix */
+ snprintf(package_filter, BUF_LEN, "%s:%%", package);
+
+ res = db->update_package(db, package_filter, package);
+ if (res < 0)
+ {
+ status = EXIT_FAILURE;
+ break;
+ }
+ else if (res > 0)
+ {
+ count += res;
+ DBG2(DBG_IMC, "%s: removed arch suffix %d times", package, res);
+ }
+ }
+ enumerator->destroy(enumerator);
+ dpkg->destroy(dpkg);
+
+ DBG1(DBG_IMC, "migrated %d sw identifier records", count);
+
+ return status;
+}
+
+
+int main(int argc, char *argv[])
+{
+ sw_collector_db_t *db = NULL;
+ sw_collector_db_query_t query_type;
+ collector_op_t op;
+ bool full_tags;
+ char *uri;
+ int status = EXIT_FAILURE;
+
+ op = do_args(argc, argv, &full_tags, &query_type);
+
+ /* enable sw_collector debugging hook */
+ dbg = sw_collector_dbg;
+#ifdef HAVE_SYSLOG
+ openlog("sw-collector", 0, LOG_DEBUG);
+#endif
+
+ atexit(cleanup);
+
+ /* initialize library */
+ if (!library_init(NULL, "sw-collector"))
+ {
+ exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
+ }
+
+ /* load sw-collector plugins */
+ if (!lib->plugins->load(lib->plugins,
+ lib->settings->get_str(lib->settings, "%s.load", PLUGINS, lib->ns)))
+ {
+ exit(SS_RC_INITIALIZATION_FAILED);
+ }
+
+ /* connect to sw-collector database */
+ uri = lib->settings->get_str(lib->settings, "%s.database", NULL, lib->ns);
+ if (!uri)
+ {
+ fprintf(stderr, "sw-collector.database URI not set.\n");
+ exit(EXIT_FAILURE);
+ }
+ db = sw_collector_db_create(uri);
+ if (!db)
+ {
+ fprintf(stderr, "connection to sw-collector database failed.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ switch (op)
+ {
+ case COLLECTOR_OP_EXTRACT:
+ status = extract_history(db);
+ break;
+ case COLLECTOR_OP_LIST:
+ status = list_identifiers(db, query_type);
+ break;
+ case COLLECTOR_OP_UNREGISTERED:
+ status = unregistered_identifiers(db, query_type);
+ break;
+ case COLLECTOR_OP_GENERATE:
+ status = generate_tags(db, full_tags, query_type);
+ break;
+ case COLLECTOR_OP_MIGRATE:
+ status = migrate(db);
+ break;
+ }
+ db->destroy(db);
+
+ exit(status);
+}
diff --git a/src/sw-collector/sw_collector_db.c b/src/sw-collector/sw_collector_db.c
new file mode 100644
index 000000000..554c3d624
--- /dev/null
+++ b/src/sw-collector/sw_collector_db.c
@@ -0,0 +1,427 @@
+/*
+ * Copyright (C) 2017 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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "sw_collector_db.h"
+
+#include "swima/swima_event.h"
+
+typedef struct private_sw_collector_db_t private_sw_collector_db_t;
+
+/**
+ * Private data of an sw_collector_db_t object.
+ */
+struct private_sw_collector_db_t {
+
+ /**
+ * Public members of sw_collector_db_state_t
+ */
+ sw_collector_db_t public;
+
+ /**
+ * Epoch
+ */
+ uint32_t epoch;
+
+ /**
+ * Event ID of last event stored in database
+ */
+ uint32_t last_eid;
+
+ /**
+ * Software collector database
+ */
+ database_t *db;
+
+};
+
+METHOD(sw_collector_db_t, add_event, uint32_t,
+ private_sw_collector_db_t *this, char *timestamp)
+{
+ uint32_t eid = 0;
+
+ if (this->db->execute(this->db, &eid,
+ "INSERT INTO events (epoch, timestamp) VALUES (?, ?)",
+ DB_UINT, this->epoch, DB_TEXT, timestamp) != 1)
+ {
+ DBG1(DBG_IMC, "unable to insert event into database");
+ return 0;
+ }
+
+ return eid;
+}
+
+METHOD(sw_collector_db_t, get_last_event, bool,
+ private_sw_collector_db_t *this, uint32_t *eid, uint32_t *epoch,
+ char **last_time)
+{
+ char *timestamp;
+ enumerator_t *e;
+
+ e = this->db->query(this->db,
+ "SELECT id, epoch, timestamp FROM events ORDER BY timestamp DESC",
+ DB_UINT, DB_UINT, DB_TEXT);
+ if (!e)
+ {
+ DBG1(DBG_IMC, "database query for event failed");
+ return FALSE;
+ }
+ if (e->enumerate(e, eid, epoch, &timestamp))
+ {
+ if (last_time)
+ {
+ *last_time = strdup(timestamp);
+ }
+ }
+ else
+ {
+ *eid = 0;
+ }
+ e->destroy(e);
+
+ return TRUE;
+}
+
+METHOD(sw_collector_db_t, add_sw_event, bool,
+ private_sw_collector_db_t *this, uint32_t eid, uint32_t sw_id,
+ uint8_t action)
+{
+ if (this->db->execute(this->db, NULL,
+ "INSERT INTO sw_events (eid, sw_id, action) VALUES (?, ?, ?)",
+ DB_UINT, eid, DB_UINT, sw_id, DB_UINT, action) != 1)
+ {
+ DBG1(DBG_IMC, "unable to insert sw_event into database");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+METHOD(sw_collector_db_t, set_sw_id, uint32_t,
+ private_sw_collector_db_t *this, char *name, char *package, char *version,
+ uint8_t source, bool installed)
+{
+ uint32_t sw_id;
+
+ if (this->db->execute(this->db, &sw_id,
+ "INSERT INTO sw_identifiers "
+ "(name, package, version, source, installed) VALUES (?, ?, ?, ?, ?)",
+ DB_TEXT, name, DB_TEXT, package, DB_TEXT, version, DB_UINT, source,
+ DB_UINT, installed) != 1)
+ {
+ DBG1(DBG_IMC, "unable to insert sw_id into database");
+ return 0;
+ }
+
+ return sw_id;
+}
+
+METHOD(sw_collector_db_t, get_sw_id, uint32_t,
+ private_sw_collector_db_t *this, char *name, char **package, char **version,
+ uint8_t *source, bool *installed)
+{
+ char *sw_package, *sw_version;
+ uint32_t sw_id = 0, sw_source, sw_installed;
+ enumerator_t *e;
+
+ /* Does software identifier already exist in database? */
+ e = this->db->query(this->db,
+ "SELECT id, package, version, source, installed "
+ "FROM sw_identifiers WHERE name = ?",
+ DB_TEXT, name, DB_UINT, DB_TEXT, DB_TEXT, DB_UINT, DB_UINT);
+ if (!e)
+ {
+ DBG1(DBG_IMC, "database query for sw_identifier failed");
+ return 0;
+ }
+ if (e->enumerate(e, &sw_id, &sw_package, &sw_version, &sw_source,
+ &sw_installed))
+ {
+ if (package)
+ {
+ *package = strdup(sw_package);
+ }
+ if (version)
+ {
+ *version = strdup(sw_version);
+ }
+ if (source)
+ {
+ *source = sw_source;
+ }
+ if (installed)
+ {
+ *installed = sw_installed;
+ }
+ }
+ e->destroy(e);
+
+ return sw_id;
+}
+
+METHOD(sw_collector_db_t, get_sw_id_count, uint32_t,
+ private_sw_collector_db_t *this, sw_collector_db_query_t type)
+{
+ uint32_t count, installed;
+ enumerator_t *e;
+
+ if (type == SW_QUERY_ALL)
+ {
+ e = this->db->query(this->db,
+ "SELECT COUNT(installed) FROM sw_identifiers", DB_UINT);
+ }
+ else
+ {
+ installed = (type == SW_QUERY_INSTALLED);
+ e = this->db->query(this->db,
+ "SELECT COUNT(installed) FROM sw_identifiers WHERE installed = ?",
+ DB_UINT, installed, DB_UINT);
+ }
+
+ if (!e)
+ {
+ DBG1(DBG_IMC, "database query for sw_identifier count failed");
+ return 0;
+ }
+ if (!e->enumerate(e, &count))
+ {
+ count = 0;
+ }
+ e->destroy(e);
+
+ return count;
+}
+
+METHOD(sw_collector_db_t, update_sw_id, bool,
+ private_sw_collector_db_t *this, uint32_t sw_id, char *name, char *version,
+ bool installed)
+{
+ int res;
+
+ if (name && version)
+ {
+ res = this->db->execute(this->db, NULL,
+ "UPDATE sw_identifiers SET name = ?, version = ?, installed = ? "
+ "WHERE id = ?", DB_TEXT, name, DB_TEXT, version, DB_UINT, installed,
+ DB_UINT, sw_id);
+ }
+ else
+ {
+ res = this->db->execute(this->db, NULL,
+ "UPDATE sw_identifiers SET installed = ? WHERE id = ?",
+ DB_UINT, installed, DB_UINT, sw_id);
+ }
+ if (res != 1)
+ {
+ DBG1(DBG_IMC, "unable to update software identifier in database");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+METHOD(sw_collector_db_t, update_package, int,
+ private_sw_collector_db_t *this, char *package_filter, char *package)
+{
+ int count;
+
+ count = this->db->execute(this->db, NULL,
+ "UPDATE sw_identifiers SET package = ? WHERE package LIKE ?",
+ DB_TEXT, package, DB_TEXT, package_filter);
+ if (count < 0)
+ {
+ DBG1(DBG_IMC, "unable to update package name in database");
+ }
+
+ return count;
+}
+
+METHOD(sw_collector_db_t, create_sw_enumerator, enumerator_t*,
+ private_sw_collector_db_t *this, sw_collector_db_query_t type, char *package)
+{
+ enumerator_t *e;
+ u_int installed;
+
+ if (type == SW_QUERY_ALL)
+ {
+ if (package)
+ {
+ e = this->db->query(this->db,
+ "SELECT id, name, package, version, installed "
+ "FROM sw_identifiers WHERE package = ? ORDER BY name ASC",
+ DB_TEXT, package, DB_UINT, DB_TEXT, DB_TEXT, DB_TEXT, DB_UINT);
+ }
+ else
+ {
+ e = this->db->query(this->db,
+ "SELECT id, name, package, version, installed "
+ "FROM sw_identifiers ORDER BY name ASC",
+ DB_UINT, DB_TEXT, DB_TEXT, DB_TEXT, DB_UINT);
+ }
+ }
+ else
+ {
+ installed = (type == SW_QUERY_INSTALLED);
+
+ if (package)
+ {
+ e = this->db->query(this->db,
+ "SELECT id, name, package, version, installed "
+ "FROM sw_identifiers WHERE package = ? AND installed = ? "
+ "ORDER BY name ASC", DB_TEXT, package, DB_UINT, installed,
+ DB_UINT, DB_TEXT, DB_TEXT, DB_TEXT, DB_UINT);
+ }
+ else
+ {
+ e = this->db->query(this->db,
+ "SELECT id, name, package, version, installed "
+ "FROM sw_identifiers WHERE installed = ? ORDER BY name ASC",
+ DB_UINT, installed, DB_UINT, DB_TEXT, DB_TEXT, DB_TEXT, DB_UINT);
+ }
+ }
+ if (!e)
+ {
+ DBG1(DBG_IMC, "database query for sw_identifier count failed");
+ return NULL;
+ }
+
+ return e;
+}
+
+METHOD(sw_collector_db_t, destroy, void,
+ private_sw_collector_db_t *this)
+{
+ this->db->destroy(this->db);
+ free(this);
+}
+
+/**
+ * Determine file creation data and convert it into RFC 3339 format
+ */
+bool get_file_creation_date(char *pathname, char *timestamp)
+{
+ struct stat st;
+ struct tm ct;
+
+ if (stat(pathname, &st))
+ {
+ DBG1(DBG_IMC, "unable to obtain statistics on '%s'", pathname);
+ return FALSE;
+ }
+
+ /* Convert from local time to UTC */
+ gmtime_r(&st.st_mtime, &ct);
+ ct.tm_year += 1900;
+ ct.tm_mon += 1;
+
+ /* Form timestamp according to RFC 3339 (20 characters) */
+ snprintf(timestamp, 21, "%4d-%02d-%02dT%02d:%02d:%02dZ",
+ ct.tm_year, ct.tm_mon, ct.tm_mday,
+ ct.tm_hour, ct.tm_min, ct.tm_sec);
+
+ return TRUE;
+}
+
+/**
+ * Described in header.
+ */
+sw_collector_db_t *sw_collector_db_create(char *uri)
+{
+ private_sw_collector_db_t *this;
+ uint32_t first_eid, last_eid;
+ char first_time_buf[21], *first_time, *first_file;
+
+ INIT(this,
+ .public = {
+ .add_event = _add_event,
+ .get_last_event = _get_last_event,
+ .add_sw_event = _add_sw_event,
+ .set_sw_id = _set_sw_id,
+ .get_sw_id = _get_sw_id,
+ .get_sw_id_count = _get_sw_id_count,
+ .update_sw_id = _update_sw_id,
+ .update_package = _update_package,
+ .create_sw_enumerator = _create_sw_enumerator,
+ .destroy = _destroy,
+ },
+ .db = lib->db->create(lib->db, uri),
+ );
+
+ if (!this->db)
+ {
+ DBG1(DBG_IMC, "opening database URI '%s' failed", uri);
+ free(this);
+ return NULL;
+ }
+
+ /* Retrieve last event in database */
+ if (!get_last_event(this, &last_eid, &this->epoch, NULL))
+ {
+ destroy(this);
+ return NULL;
+ }
+
+ /* Create random epoch and first event if no events exist yet */
+ if (!last_eid)
+ {
+ rng_t *rng;
+
+ rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
+ if (!rng ||
+ !rng->get_bytes(rng, sizeof(uint32_t), (uint8_t*)&this->epoch))
+ {
+ DESTROY_IF(rng);
+ destroy(this);
+ DBG1(DBG_IMC, "generating random epoch value failed");
+ return NULL;
+ }
+ rng->destroy(rng);
+
+ /* strongTNC workaround - limit epoch to 31 bit unsigned integer */
+ this->epoch &= 0x7fffffff;
+
+ /* Create first event when the OS was installed */
+ first_file = lib->settings->get_str(lib->settings,
+ "sw-collector.first_file", "/var/log/bootstrap.log");
+ first_time = lib->settings->get_str(lib->settings,
+ "sw-collector.first_time", NULL);
+ if (!first_time)
+ {
+ if (get_file_creation_date(first_file, first_time_buf))
+ {
+ first_time = first_time_buf;
+ }
+ else
+ {
+ first_time = "0000-00-00T00:00:00Z";
+ }
+ }
+ first_eid = add_event(this, first_time);
+
+ if (!first_eid)
+ {
+ destroy(this);
+ return NULL;
+ }
+ DBG0(DBG_IMC, "First-Date: %s, eid = %u, epoch = %u",
+ first_time, first_eid, this->epoch);
+ }
+
+ return &this->public;
+}
diff --git a/src/sw-collector/sw_collector_db.h b/src/sw-collector/sw_collector_db.h
new file mode 100644
index 000000000..e3b56af93
--- /dev/null
+++ b/src/sw-collector/sw_collector_db.h
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2017 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 sw_collector_db_t sw_collector_db
+ * @{ @ingroup sw_collector
+ */
+
+#ifndef SW_COLLECTOR_DB_H_
+#define SW_COLLECTOR_DB_H_
+
+#include <library.h>
+
+typedef struct sw_collector_db_t sw_collector_db_t;
+typedef enum sw_collector_db_query_t sw_collector_db_query_t;
+
+/**
+ * Type of software identifier queries
+ */
+enum sw_collector_db_query_t {
+ SW_QUERY_ALL,
+ SW_QUERY_INSTALLED,
+ SW_QUERY_REMOVED
+};
+
+/**
+ * Software collector database object
+ */
+struct sw_collector_db_t {
+
+ /**
+ * bAdd event to database
+ *
+ * @param timestamp Timestamp in 20 octet RFC 3339 format
+ * @return Primary key pointing to event ID or 0 if failed
+ */
+ uint32_t (*add_event)(sw_collector_db_t *this, char *timestamp);
+
+ /**
+ * Get last event, zero EID if none exists
+ *
+ * @param eid Primary key pointing to last event
+ * @param epoch Epoch
+ * @param last_time Timestamp in 20 octet RFC 3339 format of last event
+ * @return
+ */
+ bool (*get_last_event)(sw_collector_db_t *this, uint32_t *eid,
+ uint32_t *epoch, char **last_time);
+
+ /**
+ * Add software identifier event to database
+ *
+ * @param eid Foreign key pointing to an event ID
+ * @param sw_id Foreign key pointing to a software identifier
+ * @param action 1 for CREATION, 2 for deletion
+ * @return TRUE if successful
+ */
+ bool (*add_sw_event)(sw_collector_db_t *this, uint32_t eid, uint32_t sw_id,
+ uint8_t action);
+
+ /**
+ * Set software_identifier, checking if the identifier already exists
+ *
+ * @param name Software identifier
+ * @param package Software package
+ * @param version Version of software package
+ * @param source Source ID of the software collector
+ * @param installed Installation status to be set, TRUE if installed
+ * @return Primary key pointing to SW ID or 0 if failed
+ */
+ uint32_t (*set_sw_id)(sw_collector_db_t *this, char *name, char *package,
+ char *version, uint8_t source, bool installed);
+
+ /**
+ * Get software_identifier record
+ *
+ * @param name Software identifier
+ * @param package Software package
+ * @param version Version of software package
+ * @param source Source ID of the software collector
+ * @param installed Installation status
+ * @return Primary key pointing to SW ID or 0 if failed
+ */
+ uint32_t (*get_sw_id)(sw_collector_db_t *this, char *name, char **package,
+ char **version, uint8_t *source, bool *installed);
+
+ /**
+ * Get number of installed or removed software identifiers
+ *
+ * @param type Query type (ALL, INSTALLED, REMOVED)
+ * @return Count
+ */
+ uint32_t (*get_sw_id_count)(sw_collector_db_t *this,
+ sw_collector_db_query_t type);
+
+ /**
+ * Update the software identifier version
+ *
+ * @param sw_id Primary key of software identifier
+ * @param name Software identifier
+ * @param version Package version
+ * @param installed Installation status
+ * @return TRUE if update successful
+ */
+ bool (*update_sw_id)(sw_collector_db_t *this, uint32_t sw_id, char *name,
+ char *version, bool installed);
+
+ /**
+ * Update the package name
+ *
+ * @param package_filter Package name[s] to be changed
+ * @param package New package name
+ * @return TRUE if update successful
+ */
+ int (*update_package)(sw_collector_db_t *this, char *package_filter,
+ char *package);
+
+ /**
+ * Enumerate over all collected [installed] software identities
+ *
+ * @param type Query type (ALL, INSTALLED, REMOVED)
+ * @param package If not NULL enumerate over all package versions
+ * @return Enumerator
+ */
+ enumerator_t* (*create_sw_enumerator)(sw_collector_db_t *this,
+ sw_collector_db_query_t type,
+ char *package);
+
+ /**
+ * Destroy sw_collector_db_t object
+ */
+ void (*destroy)(sw_collector_db_t *this);
+
+};
+
+/**
+ * Create an sw_collector_db_t instance
+ *
+ * @param uri database URI
+ */
+sw_collector_db_t* sw_collector_db_create(char *uri);
+
+#endif /** SW_COLLECTOR_DB_H_ @}*/
diff --git a/src/sw-collector/sw_collector_dpkg.c b/src/sw-collector/sw_collector_dpkg.c
new file mode 100644
index 000000000..b5a858297
--- /dev/null
+++ b/src/sw-collector/sw_collector_dpkg.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2017 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 <stdio.h>
+
+#include "sw_collector_dpkg.h"
+
+typedef struct private_sw_collector_dpkg_t private_sw_collector_dpkg_t;
+
+/**
+ * Private data of an sw_collector_dpkg_t object.
+ */
+struct private_sw_collector_dpkg_t {
+
+ /**
+ * Public members of sw_collector_dpkg_state_t
+ */
+ sw_collector_dpkg_t public;
+
+};
+
+typedef struct {
+ /** public enumerator interface */
+ enumerator_t public;
+ /** dpkg output stream */
+ FILE *file;
+ /** current dpkg output line */
+ char line[BUF_LEN];
+} dpkg_enumerator_t;
+
+METHOD(enumerator_t, enumerate, bool,
+ dpkg_enumerator_t *this, va_list args)
+{
+ char **package, **arch, **version, *state, *pos;
+
+ VA_ARGS_VGET(args, package, arch, version);
+
+ while (TRUE)
+ {
+ if (!fgets(this->line, BUF_LEN, this->file))
+ {
+ return FALSE;
+ }
+
+ *package = this->line;
+ pos = strchr(this->line, '\t');
+ if (!pos)
+ {
+ return FALSE;
+ }
+ *pos = '\0';
+
+ *arch = ++pos;
+ pos = strchr(pos, '\t');
+ if (!pos)
+ {
+ return FALSE;
+ }
+ *pos = '\0';
+
+ *version = ++pos;
+ pos = strchr(pos, '\t');
+ if (!pos)
+ {
+ return FALSE;
+ }
+ *pos = '\0';
+
+ state = ++pos;
+ pos = strchr(pos, '\n');
+ if (!pos)
+ {
+ return FALSE;
+ }
+ *pos = '\0';
+
+ if (streq(state, "install ok installed"))
+ {
+ return TRUE;
+ }
+ }
+}
+
+METHOD(enumerator_t, enumerator_destroy, void,
+ dpkg_enumerator_t *this)
+{
+ pclose(this->file);
+ free(this);
+}
+
+METHOD(sw_collector_dpkg_t, create_sw_enumerator, enumerator_t*,
+ private_sw_collector_dpkg_t *this)
+{
+ dpkg_enumerator_t *enumerator;
+ char cmd[] = "dpkg-query -W -f="
+ "\'${Package}\t${Architecture}\t${Version}\t${Status}\n\'";
+ FILE *file;
+
+ file = popen(cmd, "r");
+ if (!file)
+ {
+ DBG1(DBG_IMC, "failed to run dpgk-query command");
+ return NULL;
+ }
+
+ INIT(enumerator,
+ .public = {
+ .enumerate = enumerator_enumerate_default,
+ .venumerate = _enumerate,
+ .destroy = _enumerator_destroy,
+ },
+ .file = file,
+ );
+
+ return &enumerator->public;
+}
+
+METHOD(sw_collector_dpkg_t, destroy, void,
+ private_sw_collector_dpkg_t *this)
+{
+ free(this);
+}
+
+/**
+ * Described in header.
+ */
+sw_collector_dpkg_t *sw_collector_dpkg_create(void)
+{
+ private_sw_collector_dpkg_t *this;
+
+ INIT(this,
+ .public = {
+ .create_sw_enumerator = _create_sw_enumerator,
+ .destroy = _destroy,
+ },
+ );
+
+ return &this->public;
+}
diff --git a/src/sw-collector/sw_collector_dpkg.h b/src/sw-collector/sw_collector_dpkg.h
new file mode 100644
index 000000000..eab792e8a
--- /dev/null
+++ b/src/sw-collector/sw_collector_dpkg.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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 sw_collector_dpkg_t sw_collector_dpkg
+ * @{ @ingroup sw_collector
+ */
+
+#ifndef SW_COLLECTOR_DPKG_H_
+#define SW_COLLECTOR_DPKG_H_
+
+#include <library.h>
+
+typedef struct sw_collector_dpkg_t sw_collector_dpkg_t;
+
+/**
+ * Software collector dpkg object
+ */
+struct sw_collector_dpkg_t {
+
+ /**
+ * List of installed software identifiers managed by the
+ * Debian "dpkg" package manager
+ *
+ * @return Enumerator
+ */
+ enumerator_t* (*create_sw_enumerator)(sw_collector_dpkg_t *this);
+
+ /**
+ * Destroy sw_collector_dpkg_t object
+ */
+ void (*destroy)(sw_collector_dpkg_t *this);
+
+};
+
+/**
+ * Create an sw_collector_dpkg_t instance
+ */
+sw_collector_dpkg_t* sw_collector_dpkg_create(void);
+
+#endif /** SW_COLLECTOR_DPKG_H_ @}*/
diff --git a/src/sw-collector/sw_collector_history.c b/src/sw-collector/sw_collector_history.c
new file mode 100644
index 000000000..f1fd9f60f
--- /dev/null
+++ b/src/sw-collector/sw_collector_history.c
@@ -0,0 +1,519 @@
+/*
+ * Copyright (C) 2017 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 <stdio.h>
+#include <time.h>
+
+#include "sw_collector_history.h"
+#include "sw_collector_dpkg.h"
+
+#include <swima/swima_event.h>
+#include <swid_gen/swid_gen_info.h>
+
+typedef struct private_sw_collector_history_t private_sw_collector_history_t;
+
+/**
+ * Private data of an sw_collector_history_t object.
+ */
+struct private_sw_collector_history_t {
+
+ /**
+ * Public members of sw_collector_history_state_t
+ */
+ sw_collector_history_t public;
+
+ /**
+ * Software Event Source Number
+ */
+ uint8_t source;
+
+ /**
+ * Reference to OS info object
+ */
+ swid_gen_info_t *info;
+
+ /**
+ * Reference to collector database
+ */
+ sw_collector_db_t *db;
+
+};
+
+/**
+ * Define auxiliary package_t list item object
+ */
+typedef struct package_t package_t;
+
+struct package_t {
+ char *package;
+ char *version;
+ char *old_version;
+ char *sw_id;
+ char *old_sw_id;
+};
+
+/**
+ * Create package_t list item object
+ */
+static package_t* create_package(swid_gen_info_t *info, chunk_t package,
+ chunk_t version, chunk_t old_version)
+{
+ package_t *this;
+
+ INIT(this,
+ .package = strndup(package.ptr, package.len),
+ .version = strndup(version.ptr, version.len),
+ .old_version = strndup(old_version.ptr, old_version.len),
+ )
+
+ this->sw_id = info->create_sw_id(info, this->package, this->version);
+ if (old_version.len)
+ {
+ this->old_sw_id = info->create_sw_id(info, this->package,
+ this->old_version);
+ }
+
+ return this;
+}
+
+/**
+ * Free package_t list item object
+ */
+static void free_package(package_t *this)
+{
+ if (this)
+ {
+ free(this->package);
+ free(this->version);
+ free(this->old_version);
+ free(this->sw_id);
+ free(this->old_sw_id);
+ free(this);
+ }
+}
+
+/**
+ * Extract and parse a single package item
+ */
+static package_t* extract_package(chunk_t item, swid_gen_info_t *info,
+ sw_collector_history_op_t op)
+{
+ chunk_t package, package_stripped, version, old_version;
+ package_t *p;
+
+ /* extract package name */
+ if (!extract_token(&package, ' ', &item))
+ {
+ fprintf(stderr, "version not found.\n");
+ return NULL;
+ }
+ item = chunk_skip(item, 1);
+
+ /* strip architecture suffix if present */
+ if (extract_token(&package_stripped, ':', &package))
+ {
+ package = package_stripped;
+ }
+
+ /* extract versions */
+ version = old_version = chunk_empty;
+
+ if (item.len > 0)
+ {
+ if (extract_token(&version, ',', &item))
+ {
+ eat_whitespace(&item);
+ if (!match("automatic", &item))
+ {
+ old_version = version;
+ version = item;
+ }
+ }
+ else
+ {
+ version = item;
+ }
+ }
+ p = create_package(info, package, version, old_version);
+
+ /* generate log entry */
+ if (op == SW_OP_UPGRADE)
+ {
+ DBG2(DBG_IMC, " %s (%s, %s)", p->package, p->old_version, p->version);
+ DBG2(DBG_IMC, " +%s", p->sw_id);
+ DBG2(DBG_IMC, " -%s", p->old_sw_id);
+ }
+ else
+ {
+ DBG2(DBG_IMC, " %s (%s)", p->package, p->version);
+ DBG2(DBG_IMC, " %s%s", (op == SW_OP_INSTALL) ? "+" : "-", p->sw_id);
+ }
+
+ return p;
+}
+
+METHOD(sw_collector_history_t, extract_timestamp, bool,
+ private_sw_collector_history_t *this, chunk_t args, char *buf)
+{
+ struct tm loc, utc;
+ chunk_t t1, t2;
+ time_t t;
+
+ /* Break down local time with format t1 = yyyy-mm-dd and t2 = hh:mm:ss */
+ if (!eat_whitespace(&args) || !extract_token(&t1, ' ', &args) ||
+ !eat_whitespace(&args) || t1.len != 10 || args.len != 8)
+ {
+ DBG1(DBG_IMC, "unable to parse start-date");
+ return FALSE;
+ }
+ t2 = args;
+
+ if (sscanf(t1.ptr, "%4d-%2d-%2d",
+ &loc.tm_year, &loc.tm_mon, &loc.tm_mday) != 3)
+ {
+ DBG1(DBG_IMC, "unable to parse date format yyyy-mm-dd");
+ return FALSE;
+ }
+ loc.tm_year -= 1900;
+ loc.tm_mon -= 1;
+ loc.tm_isdst = -1;
+
+ if (sscanf(t2.ptr, "%2d:%2d:%2d",
+ &loc.tm_hour, &loc.tm_min, &loc.tm_sec) != 3)
+ {
+ DBG1(DBG_IMC, "unable to parse time format hh:mm:ss");
+ return FALSE;
+ }
+
+ /* Convert from local time to UTC */
+ t = mktime(&loc);
+ gmtime_r(&t, &utc);
+ utc.tm_year += 1900;
+ utc.tm_mon += 1;
+
+ /* Form timestamp according to RFC 3339 (20 characters) */
+ snprintf(buf, 21, "%4d-%02d-%02dT%02d:%02d:%02dZ",
+ utc.tm_year, utc.tm_mon, utc.tm_mday,
+ utc.tm_hour, utc.tm_min, utc.tm_sec);
+
+ return TRUE;
+}
+
+METHOD(sw_collector_history_t, extract_packages, bool,
+ private_sw_collector_history_t *this, chunk_t args, uint32_t eid,
+ sw_collector_history_op_t op)
+{
+ bool success = FALSE;
+ package_t *p = NULL;
+ chunk_t item;
+
+ eat_whitespace(&args);
+
+ while (extract_token(&item, ')', &args))
+ {
+ char *del_sw_id = NULL, *del_version = NULL;
+ char *nx, *px, *vx, *v1;
+ bool installed;
+ u_int sw_idx, ix;
+ uint32_t sw_id, sw_id_epoch_less = 0;
+ enumerator_t *e;
+
+ p = extract_package(item, this->info, op);
+ if (!p)
+ {
+ goto end;
+ }
+
+ /* packages without version information cannot be handled */
+ if (strlen(p->version) == 0)
+ {
+ free_package(p);
+ continue;
+ }
+
+ switch (op)
+ {
+ case SW_OP_REMOVE:
+ /* prepare subsequent deletion sw event */
+ del_sw_id = p->sw_id;
+ del_version = p->version;
+ break;
+ case SW_OP_UPGRADE:
+ /* prepare subsequent deletion sw event */
+ del_sw_id = p->old_sw_id;
+ del_version = p->old_version;
+ /* fall through to next case */
+ case SW_OP_INSTALL:
+ sw_id = this->db->get_sw_id(this->db, p->sw_id, NULL, NULL,
+ NULL, &installed);
+ if (sw_id)
+ {
+ /* sw identifier exists - update state to 'installed' */
+ if (installed)
+ {
+ /* this case should not occur */
+ DBG1(DBG_IMC, " warning: sw_id %d is already "
+ "installed", sw_id);
+ }
+ else if (!this->db->update_sw_id(this->db, sw_id, NULL,
+ NULL, TRUE))
+ {
+ goto end;
+ }
+ }
+ else
+ {
+ /* new sw identifier - create with state 'installed' */
+ sw_id = this->db->set_sw_id(this->db, p->sw_id, p->package,
+ p->version, this->source, TRUE);
+ if (!sw_id)
+ {
+ goto end;
+ }
+ }
+
+ /* add creation sw event with current eid */
+ if (!this->db->add_sw_event(this->db, eid, sw_id,
+ SWIMA_EVENT_ACTION_CREATION))
+ {
+ goto end;
+ }
+ break;
+ }
+
+ if (op != SW_OP_INSTALL)
+ {
+ sw_id = 0;
+
+ /* look for existing installed package versions */
+ e = this->db->create_sw_enumerator(this->db, SW_QUERY_INSTALLED,
+ p->package);
+ if (!e)
+ {
+ goto end;
+ }
+
+ while (e->enumerate(e, &sw_idx, &nx, &px, &vx, &ix))
+ {
+ if (streq(vx, del_version))
+ {
+ /* full match with epoch */
+ sw_id = sw_idx;
+ break;
+ }
+ v1 = strchr(vx, ':');
+ if (v1 && streq(++v1, del_version))
+ {
+ /* match with stripped epoch */
+ sw_id_epoch_less = sw_idx;
+ }
+ }
+ e->destroy(e);
+
+ if (!sw_id && sw_id_epoch_less)
+ {
+ /* no full match - fall back to epoch-less match */
+ sw_id = sw_id_epoch_less;
+ }
+ if (sw_id)
+ {
+ /* sw identifier exists - update state to 'removed' */
+ if (!this->db->update_sw_id(this->db, sw_id, NULL, NULL, FALSE))
+ {
+ goto end;
+ }
+ }
+ else
+ {
+ /* new sw identifier - create with state 'removed' */
+ sw_id = this->db->set_sw_id(this->db, del_sw_id, p->package,
+ del_version, this->source, FALSE);
+
+ /* add creation sw event with eid = 1 */
+ if (!sw_id || !this->db->add_sw_event(this->db, 1, sw_id,
+ SWIMA_EVENT_ACTION_CREATION))
+ {
+ goto end;
+ }
+ }
+
+ /* add creation sw event with current eid */
+ if (!this->db->add_sw_event(this->db, eid, sw_id,
+ SWIMA_EVENT_ACTION_DELETION))
+ {
+ goto end;
+ }
+ }
+ free_package(p);
+
+ if (args.len < 2)
+ {
+ break;
+ }
+ args = chunk_skip(args, 2);
+ }
+ p = NULL;
+ success = TRUE;
+
+end:
+ free_package(p);
+
+ return success;
+}
+
+METHOD(sw_collector_history_t, merge_installed_packages, bool,
+ private_sw_collector_history_t *this)
+{
+ uint32_t sw_id, count = 0;
+ char *package, *arch, *version, *v1, *name, *n1;
+ bool installed, success = FALSE;
+ sw_collector_dpkg_t *dpkg;
+ enumerator_t *enumerator;
+
+ DBG1(DBG_IMC, "Merging:");
+
+ dpkg = sw_collector_dpkg_create();
+ if (!dpkg)
+ {
+ return FALSE;
+ }
+
+ enumerator = dpkg->create_sw_enumerator(dpkg);
+ while (enumerator->enumerate(enumerator, &package, &arch, &version))
+ {
+ name = this->info->create_sw_id(this->info, package, version);
+ DBG3(DBG_IMC, " %s merged", name);
+
+ sw_id = this->db->get_sw_id(this->db, name, NULL, NULL, NULL,
+ &installed);
+ if (sw_id)
+ {
+ if (!installed)
+ {
+ DBG1(DBG_IMC, " warning: existing sw_id %u"
+ " is not installed", sw_id);
+
+ if (!this->db->update_sw_id(this->db, sw_id, name, version,
+ TRUE))
+ {
+ free(name);
+ goto end;
+ }
+ }
+ }
+ else
+ {
+ /* check for a Debian epoch number */
+ v1 = strchr(version, ':');
+ if (v1)
+ {
+ /* check for existing and installed epoch-less version */
+ n1 = this->info->create_sw_id(this->info, package, ++v1);
+ sw_id = this->db->get_sw_id(this->db, n1, NULL, NULL, NULL,
+ &installed);
+ free(n1);
+
+ if (sw_id && installed)
+ {
+ /* add epoch to existing version */
+ if (!this->db->update_sw_id(this->db, sw_id, name, version,
+ installed))
+ {
+ free(name);
+ goto end;
+ }
+ }
+ else
+ {
+ sw_id = 0;
+ }
+ }
+ }
+
+ if (!sw_id)
+ {
+ /* new sw identifier - create with state 'installed' */
+ sw_id = this->db->set_sw_id(this->db, name, package, version,
+ this->source, TRUE);
+
+ /* add creation sw event with eid = 1 */
+ if (!sw_id || !this->db->add_sw_event(this->db, 1, sw_id,
+ SWIMA_EVENT_ACTION_CREATION))
+ {
+ free(name);
+ goto end;
+ }
+
+ }
+ free(name);
+ count++;
+ }
+ success = TRUE;
+
+ DBG1(DBG_IMC, " merged %u installed packages, %u registered in database",
+ count, this->db->get_sw_id_count(this->db, SW_QUERY_INSTALLED));
+
+end:
+ enumerator->destroy(enumerator);
+ dpkg->destroy(dpkg);
+
+ return success;
+}
+
+METHOD(sw_collector_history_t, destroy, void,
+ private_sw_collector_history_t *this)
+{
+ this->info->destroy(this->info);
+ free(this);
+}
+
+/**
+ * Described in header.
+ */
+sw_collector_history_t *sw_collector_history_create(sw_collector_db_t *db,
+ uint8_t source)
+{
+ private_sw_collector_history_t *this;
+ swid_gen_info_t *info;
+ os_type_t os_type;
+ char *os;
+
+ info = swid_gen_info_create();
+
+ /* check if OS supports apg/dpkg history logs */
+ info->get_os(info, &os);
+ os_type = info->get_os_type(info);
+ if (os_type != OS_TYPE_DEBIAN && os_type != OS_TYPE_UBUNTU)
+ {
+ DBG1(DBG_IMC, "%.*s not supported", os);
+ info->destroy(info);
+ return NULL;
+ }
+
+ INIT(this,
+ .public = {
+ .extract_timestamp = _extract_timestamp,
+ .extract_packages = _extract_packages,
+ .merge_installed_packages = _merge_installed_packages,
+ .destroy = _destroy,
+ },
+ .source = source,
+ .info = info,
+ .db = db,
+ );
+
+ return &this->public;
+}
diff --git a/src/sw-collector/sw_collector_history.h b/src/sw-collector/sw_collector_history.h
new file mode 100644
index 000000000..aa354e8f4
--- /dev/null
+++ b/src/sw-collector/sw_collector_history.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2017 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 sw_collector_history_t sw_collector_history
+ * @{ @ingroup sw_collector
+ */
+
+#ifndef SW_COLLECTOR_HISTORY_H_
+#define SW_COLLECTOR_HISTORY_H_
+
+#include "sw_collector_db.h"
+
+#include <library.h>
+#include <utils/debug.h>
+#include <utils/lexparser.h>
+
+typedef struct sw_collector_history_t sw_collector_history_t;
+typedef enum sw_collector_history_op_t sw_collector_history_op_t;
+
+/**
+ * Define major history event operations
+ */
+enum sw_collector_history_op_t {
+ SW_OP_INSTALL,
+ SW_OP_UPGRADE,
+ SW_OP_REMOVE
+};
+
+/**
+ * Software collector history object
+ */
+struct sw_collector_history_t {
+
+ /**
+ * Extract timestamp from event in installation history
+ *
+ * @param args Arguments to be processed
+ * @param buf timestamp buffer for 21 byte RFC 3339 string
+ * @return TRUE if extraction succeeded
+ */
+ bool (*extract_timestamp)(sw_collector_history_t *this, chunk_t args,
+ char *buf);
+
+ /**
+ * Extract packages from event in installation history
+ *
+ * @param args Arguments to be processed
+ * @param eid Primary key pointing to current event
+ * @param op Extraction operation
+ * @return TRUE if extraction succeeded
+ */
+ bool (*extract_packages)(sw_collector_history_t *this, chunk_t args,
+ uint32_t eid, sw_collector_history_op_t op);
+
+ /**
+ * Merge packages from initial installation
+ *
+ * @return TRUE if merge succeeded
+ */
+ bool (*merge_installed_packages)(sw_collector_history_t *this);
+
+ /**
+ * Destroy sw_collector_history_t object
+ */
+ void (*destroy)(sw_collector_history_t *this);
+
+};
+
+/**
+ * Create an sw_collector_history_t instance
+ *
+ * @param db Internal reference to collector database
+ * @param source Software event source number
+ */
+sw_collector_history_t* sw_collector_history_create(sw_collector_db_t *db,
+ uint8_t source);
+
+#endif /** SW_COLLECTOR_HISTORY_H_ @}*/
diff --git a/src/sw-collector/sw_collector_rest_api.c b/src/sw-collector/sw_collector_rest_api.c
new file mode 100644
index 000000000..6b9b7b96a
--- /dev/null
+++ b/src/sw-collector/sw_collector_rest_api.c
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2017 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 "sw_collector_rest_api.h"
+
+#include <rest/rest.h>
+#include <utils/debug.h>
+
+typedef struct private_sw_collector_rest_api_t private_sw_collector_rest_api_t;
+
+/**
+ * Private data of an sw_collector_rest_api_t object.
+ */
+struct private_sw_collector_rest_api_t {
+
+ /**
+ * Public members of sw_collector_rest_api_state_t
+ */
+ sw_collector_rest_api_t public;
+
+ /**
+ * Software collector database
+ */
+ sw_collector_db_t *db;
+
+ /**
+ * REST API of central collector database
+ */
+ rest_t *rest_api;
+
+};
+
+/**
+ * Put all locally retrieved software identifiers into a json object
+ */
+static json_object* create_rest_request(private_sw_collector_rest_api_t *this,
+ sw_collector_db_query_t type)
+{
+ json_object *jrequest, *jarray, *jstring;
+ char *name, *package, *version;
+ uint32_t sw_id, i;
+ enumerator_t *e;
+
+ jrequest = json_object_new_object();
+ jarray = json_object_new_array();
+ json_object_object_add(jrequest, "data", jarray);
+
+ e = this->db->create_sw_enumerator(this->db, type, NULL);
+ if (!e)
+ {
+ return NULL;
+ }
+ while (e->enumerate(e, &sw_id, &name, &package, &version, &i))
+ {
+ jstring = json_object_new_string(name);
+ json_object_array_add(jarray, jstring);
+ }
+ e->destroy(e);
+
+ return jrequest;
+}
+
+typedef struct {
+ /** public enumerator interface */
+ enumerator_t public;
+ /** enumerated json array */
+ json_object *jarray;
+ /** current index +1, initialized at 0 */
+ int idx;
+} json_array_enumerator_t;
+
+METHOD(enumerator_t, enumerate, bool,
+ json_array_enumerator_t *this, va_list args)
+{
+ json_object *jvalue;
+ char **out;
+
+ VA_ARGS_VGET(args, out);
+
+ if (this->idx >= json_object_array_length(this->jarray))
+ {
+ return FALSE;
+ }
+
+ jvalue = json_object_array_get_idx(this->jarray, this->idx++);
+ if (json_object_get_type(jvalue) != json_type_string)
+ {
+ DBG1(DBG_IMC, "json_string element expected in json_array");
+ return FALSE;
+ }
+ *out = (char*)json_object_get_string(jvalue);
+
+ return TRUE;
+}
+
+METHOD(enumerator_t, enumerator_destroy, void,
+ json_array_enumerator_t *this)
+{
+ json_object_put(this->jarray);
+ free(this);
+}
+
+METHOD(sw_collector_rest_api_t, create_sw_enumerator, enumerator_t*,
+ private_sw_collector_rest_api_t *this, sw_collector_db_query_t type)
+{
+ json_array_enumerator_t *enumerator;
+ json_object *jrequest, *jresponse;
+ char cmd[BUF_LEN];
+ status_t status;
+
+ jrequest = create_rest_request(this, type);
+ if (!jrequest)
+ {
+ return NULL;
+ }
+ snprintf(cmd, BUF_LEN, "sessions/0/swid-measurement/");
+
+ status = this->rest_api->post(this->rest_api, cmd, jrequest, &jresponse);
+ json_object_put(jrequest);
+
+ switch (status)
+ {
+ case SUCCESS:
+ case NOT_FOUND:
+ jresponse = json_object_new_array();
+ break;
+ case NEED_MORE:
+ if (json_object_get_type(jresponse) != json_type_array)
+ {
+ DBG1(DBG_IMC, "REST response was not a json_array");
+ json_object_put(jresponse);
+ return NULL;
+ }
+ break;
+ case FAILED:
+ default:
+ return NULL;
+ }
+
+ INIT(enumerator,
+ .public = {
+ .enumerate = enumerator_enumerate_default,
+ .venumerate = _enumerate,
+ .destroy = _enumerator_destroy,
+ },
+ .jarray = jresponse,
+ );
+
+ return &enumerator->public;
+}
+
+METHOD(sw_collector_rest_api_t, destroy, void,
+ private_sw_collector_rest_api_t *this)
+{
+ this->rest_api->destroy(this->rest_api);
+ free(this);
+}
+
+/**
+ * Described in header.
+ */
+sw_collector_rest_api_t *sw_collector_rest_api_create(sw_collector_db_t *db)
+{
+ private_sw_collector_rest_api_t *this;
+ int timeout;
+ char *uri;
+
+ uri = lib->settings->get_str(lib->settings, "%s.rest_api.uri", NULL,
+ lib->ns);
+ timeout = lib->settings->get_int(lib->settings, "%s.rest_api.timeout", 120,
+ lib->ns);
+ if (!uri)
+ {
+ DBG1(DBG_IMC, "REST URI to central collector database not set");
+ return NULL;
+ }
+
+ INIT(this,
+ .public = {
+ .create_sw_enumerator = _create_sw_enumerator,
+ .destroy = _destroy,
+ },
+ .db = db,
+ .rest_api = rest_create(uri, timeout),
+ );
+
+ return &this->public;
+}
diff --git a/src/sw-collector/sw_collector_rest_api.h b/src/sw-collector/sw_collector_rest_api.h
new file mode 100644
index 000000000..fe142fc66
--- /dev/null
+++ b/src/sw-collector/sw_collector_rest_api.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 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 sw_collector_rest_api_t sw_collector_rest_api
+ * @{ @ingroup sw_collector
+ */
+
+#ifndef SW_COLLECTOR_REST_API_H_
+#define SW_COLLECTOR_REST_API_H_
+
+#include "sw_collector_db.h"
+
+typedef struct sw_collector_rest_api_t sw_collector_rest_api_t;
+
+/**
+ * Software collector REST API object
+ */
+struct sw_collector_rest_api_t {
+
+ /**
+ * List of locally stored software identifiers that are not registered
+ * in a central collector database
+ *
+ * @param type Query type (ALL, INSTALLED, REMOVED)
+ * @return Enumerator
+ */
+ enumerator_t* (*create_sw_enumerator)(sw_collector_rest_api_t *this,
+ sw_collector_db_query_t type);
+
+ /**
+ * Destroy sw_collector_rest_api_t object
+ */
+ void (*destroy)(sw_collector_rest_api_t *this);
+
+};
+
+/**
+ * Create an sw_collector_rest_api_t instance
+ *
+ * @param db Software collector database to be used
+ */
+sw_collector_rest_api_t* sw_collector_rest_api_create(sw_collector_db_t *db);
+
+#endif /** SW_COLLECTOR_REST_API_H_ @}*/
diff --git a/src/sw-collector/sw_collector_tables.sql b/src/sw-collector/sw_collector_tables.sql
new file mode 100644
index 000000000..b7b430b3c
--- /dev/null
+++ b/src/sw-collector/sw_collector_tables.sql
@@ -0,0 +1,31 @@
+/* SQLit database for an Endpoint Collector */
+
+DROP TABLE IF EXISTS "events";
+CREATE TABLE "events" (
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ "epoch" INTEGER NOT NULL,
+ "timestamp" CHAR(20) NOT NULL
+);
+
+DROP TABLE IF EXISTS "sw_identifiers";
+CREATE TABLE "sw_identifiers" (
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ "name" VARCHAR(255) NOT NULL,
+ "package" VARCHAR(255) NOT NULL,
+ "version" VARCHAR(255) NOT NULL,
+ "source" INTEGER DEFAULT 0,
+ "installed" INTEGER DEFAULT 1,
+ "tag" TEXT
+ );
+DROP INDEX IF EXISTS "sw_identifiers_name";
+CREATE INDEX "sw_identifiers_name" ON "sw_identifiers" (
+ "name"
+);
+
+DROP TABLE IF EXISTS "sw_events";
+CREATE TABLE "sw_events" (
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ "eid" INTEGER REFERENCES "events" ("id"),
+ "sw_id" INTEGER NOT NULL REFERENCES "sw_identifiers" ("id"),
+ "action" INTEGER NOT NULL
+);