aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.in6
-rw-r--r--src/Makefile.am10
-rw-r--r--src/conftest/.gitignore1
-rw-r--r--src/conftest/Makefile.am14
-rw-r--r--src/conftest/conftest.c224
-rw-r--r--src/conftest/conftest.h50
6 files changed, 303 insertions, 2 deletions
diff --git a/configure.in b/configure.in
index 321499285..7e05fb4ee 100644
--- a/configure.in
+++ b/configure.in
@@ -143,6 +143,7 @@ ARG_DISBL_SET([threads], [disable the use of threads in pluto. Charon alw
ARG_DISBL_SET([charon], [disable the IKEv2 keying daemon charon.])
ARG_DISBL_SET([tools], [disable additional utilities (openac, scepclient and pki).])
ARG_DISBL_SET([scripts], [disable additional utilities (found in directory scripts).])
+ARG_ENABL_SET([conftest], [enforce Suite B conformance test framework.])
ARG_DISBL_SET([updown], [disable updown firewall script plugin.])
ARG_DISBL_SET([attr], [disable strongswan.conf based configuration attribute plugin.])
ARG_ENABL_SET([attr-sql], [enable SQL based configuration attribute plugin.])
@@ -916,8 +917,10 @@ AM_CONDITIONAL(USE_THREADS, test x$threads = xtrue)
AM_CONDITIONAL(USE_CHARON, test x$charon = xtrue)
AM_CONDITIONAL(USE_TOOLS, test x$tools = xtrue)
AM_CONDITIONAL(USE_SCRIPTS, test x$scripts = xtrue)
-AM_CONDITIONAL(USE_LIBSTRONGSWAN, test x$charon = xtrue -o x$pluto = xtrue -o x$tools = xtrue)
+AM_CONDITIONAL(USE_CONFTEST, test x$conftest = xtrue)
+AM_CONDITIONAL(USE_LIBSTRONGSWAN, test x$charon = xtrue -o x$pluto = xtrue -o x$tools = xtrue -o x$conftest = xtrue)
AM_CONDITIONAL(USE_LIBHYDRA, test x$charon = xtrue -o x$pluto = xtrue)
+AM_CONDITIONAL(USE_LIBCHARON, test x$charon = xtrue -o x$conftest = xtrue)
AM_CONDITIONAL(USE_FILE_CONFIG, test x$pluto = xtrue -o x$stroke = xtrue)
AM_CONDITIONAL(USE_LIBCAP, test x$capabilities = xlibcap)
AM_CONDITIONAL(USE_VSTR, test x$vstr = xtrue)
@@ -1053,6 +1056,7 @@ AC_OUTPUT(
src/manager/Makefile
src/medsrv/Makefile
src/checksum/Makefile
+ src/conftest/Makefile
scripts/Makefile
testing/Makefile
)
diff --git a/src/Makefile.am b/src/Makefile.am
index 0edddc9fc..2da2ab4f5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,10 @@ if USE_LIBHYDRA
SUBDIRS += libhydra
endif
+if USE_LIBCHARON
+ SUBDIRS += libcharon
+endif
+
if USE_SIMAKA
SUBDIRS += libsimaka
endif
@@ -25,7 +29,7 @@ if USE_PLUTO
endif
if USE_CHARON
- SUBDIRS += libcharon charon
+ SUBDIRS += charon
endif
if USE_STROKE
@@ -40,6 +44,10 @@ if USE_TOOLS
SUBDIRS += libfreeswan openac scepclient pki
endif
+if USE_CONFTEST
+ SUBDIRS += conftest
+endif
+
if USE_DUMM
SUBDIRS += dumm
endif
diff --git a/src/conftest/.gitignore b/src/conftest/.gitignore
new file mode 100644
index 000000000..a20f141d9
--- /dev/null
+++ b/src/conftest/.gitignore
@@ -0,0 +1 @@
+conftest
diff --git a/src/conftest/Makefile.am b/src/conftest/Makefile.am
new file mode 100644
index 000000000..d975810cb
--- /dev/null
+++ b/src/conftest/Makefile.am
@@ -0,0 +1,14 @@
+ipsec_PROGRAMS = conftest
+
+conftest_SOURCES = conftest.c
+
+INCLUDES = \
+ -I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libhydra \
+ -I$(top_srcdir)/src/libcharon
+
+conftest_LDADD = \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la \
+ $(top_builddir)/src/libhydra/libhydra.la \
+ $(top_builddir)/src/libcharon/libcharon.la \
+ -lm $(PTHREADLIB) $(DLLIB)
diff --git a/src/conftest/conftest.c b/src/conftest/conftest.c
new file mode 100644
index 000000000..45da34bad
--- /dev/null
+++ b/src/conftest/conftest.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * 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 <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <signal.h>
+#include <getopt.h>
+
+#include "conftest.h"
+
+#include <threading/thread.h>
+
+/**
+ * Conftest globals struct
+ */
+conftest_t *conftest;
+
+/**
+ * Print usage information
+ */
+static void usage(char *error)
+{
+ FILE *out = stdout;
+
+ if (error)
+ {
+ out = stderr;
+ fprintf(out, "%s\n", error);
+ }
+ else
+ {
+ fprintf(out, "strongSwan %s conftest\n", VERSION);
+ }
+ fprintf(out, "Usage:\n");
+ fprintf(out, " --help show usage information\n");
+ fprintf(out, " --version show conftest version\n");
+ fprintf(out, " --suite <file> global testsuite configuration "
+ "(default: ./suite.conf)\n");
+ fprintf(out, " --test <file> test specific configuration\n");
+}
+
+/**
+ * Handle SIGSEGV/SIGILL signals raised by threads
+ */
+static void segv_handler(int signal)
+{
+ fprintf(stderr, "thread %u received %d", thread_current_id(), signal);
+ abort();
+}
+
+/**
+ * Load suite and test specific configurations
+ */
+static bool load_configs(char *suite_file, char *test_file)
+{
+ if (!test_file)
+ {
+ fprintf(stderr, "Missing test configuration file.\n");
+ return FALSE;
+ }
+ if (access(suite_file, R_OK) != 0)
+ {
+ fprintf(stderr, "Reading suite configuration file '%s' failed: %s.\n",
+ suite_file, strerror(errno));
+ return FALSE;
+ }
+ if (access(test_file, R_OK) != 0)
+ {
+ fprintf(stderr, "Reading test configuration file '%s' failed: %s.\n",
+ test_file, strerror(errno));
+ return FALSE;
+ }
+ conftest->suite = settings_create(suite_file);
+ conftest->test = settings_create(test_file);
+ return TRUE;
+}
+
+/**
+ * atexit() cleanup handler
+ */
+static void cleanup()
+{
+ DESTROY_IF(conftest->suite);
+ DESTROY_IF(conftest->test);
+ free(conftest);
+ libcharon_deinit();
+ libhydra_deinit();
+ library_deinit();
+}
+
+/**
+ * Main function, starts the conftest daemon.
+ */
+int main(int argc, char *argv[])
+{
+ struct sigaction action;
+ int status = 0;
+ sigset_t set;
+ int sig;
+ char *suite_file = "suite.conf", *test_file = NULL;
+ file_logger_t *logger;
+
+ if (!library_init(NULL))
+ {
+ library_deinit();
+ return SS_RC_LIBSTRONGSWAN_INTEGRITY;
+ }
+ if (!libhydra_init("conftest"))
+ {
+ libhydra_deinit();
+ library_deinit();
+ return SS_RC_INITIALIZATION_FAILED;
+ }
+ if (!libcharon_init())
+ {
+ libcharon_deinit();
+ libhydra_deinit();
+ library_deinit();
+ return SS_RC_INITIALIZATION_FAILED;
+ }
+
+ INIT(conftest,
+ );
+ logger = file_logger_create(stdout, NULL, FALSE);
+ logger->set_level(logger, DBG_ANY, LEVEL_CTRL);
+ charon->bus->add_listener(charon->bus, &logger->listener);
+ charon->file_loggers->insert_last(charon->file_loggers, logger);
+
+ atexit(cleanup);
+
+ while (TRUE)
+ {
+ struct option long_opts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'v' },
+ { "suite", required_argument, NULL, 's' },
+ { "test", required_argument, NULL, 't' },
+ { 0,0,0,0 }
+ };
+ switch (getopt_long(argc, argv, "", long_opts, NULL))
+ {
+ case EOF:
+ break;
+ case 'h':
+ usage(NULL);
+ return 0;
+ case 'v':
+ printf("strongSwan %s conftest\n", VERSION);
+ return 0;
+ case 's':
+ suite_file = optarg;
+ continue;
+ case 't':
+ test_file = optarg;
+ continue;
+ default:
+ usage("Invalid option.");
+ return 1;
+ }
+ break;
+ }
+
+ if (!load_configs(suite_file, test_file))
+ {
+ return 1;
+ }
+
+ if (!charon->initialize(charon))
+ {
+ return 1;
+ }
+
+ /* set up thread specific handlers */
+ action.sa_handler = segv_handler;
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ sigaddset(&action.sa_mask, SIGINT);
+ sigaddset(&action.sa_mask, SIGTERM);
+ sigaddset(&action.sa_mask, SIGHUP);
+ sigaction(SIGSEGV, &action, NULL);
+ sigaction(SIGILL, &action, NULL);
+ sigaction(SIGBUS, &action, NULL);
+ action.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &action, NULL);
+ pthread_sigmask(SIG_SETMASK, &action.sa_mask, NULL);
+
+ /* start thread pool */
+ charon->start(charon);
+
+ /* handle SIGINT/SIGTERM in main thread */
+ sigemptyset(&set);
+ sigaddset(&set, SIGINT);
+ sigaddset(&set, SIGHUP);
+ sigaddset(&set, SIGTERM);
+ sigprocmask(SIG_BLOCK, &set, NULL);
+
+ while (sigwait(&set, &sig) == 0)
+ {
+ switch (sig)
+ {
+ case SIGINT:
+ case SIGTERM:
+ fprintf(stderr, "\nshutting down...\n");
+ break;
+ default:
+ continue;
+ }
+ break;
+ }
+ return status;
+}
diff --git a/src/conftest/conftest.h b/src/conftest/conftest.h
new file mode 100644
index 000000000..f318fd9f8
--- /dev/null
+++ b/src/conftest/conftest.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * 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 conftest conftest
+ */
+
+#ifndef CONFTEST_H_
+#define CONFTEST_H_
+
+#include <library.h>
+#include <hydra.h>
+#include <daemon.h>
+
+typedef struct conftest_t conftest_t;
+
+/**
+ * Global conftest variables.
+ */
+struct conftest_t {
+
+ /**
+ * Global testsuite configuration
+ */
+ settings_t *suite;
+
+ /**
+ * Test specific configuration
+ */
+ settings_t *test;
+};
+
+/**
+ * Conftest globals
+ */
+extern conftest_t *conftest;
+
+#endif /** CONFTEST_H_ */