summaryrefslogtreecommitdiff
path: root/src/libimcv/plugins/imv_test
diff options
context:
space:
mode:
Diffstat (limited to 'src/libimcv/plugins/imv_test')
-rw-r--r--src/libimcv/plugins/imv_test/Makefile.in32
-rw-r--r--src/libimcv/plugins/imv_test/imv_test.c177
-rw-r--r--src/libimcv/plugins/imv_test/imv_test_state.c88
3 files changed, 161 insertions, 136 deletions
diff --git a/src/libimcv/plugins/imv_test/Makefile.in b/src/libimcv/plugins/imv_test/Makefile.in
index e395f8187..04b750973 100644
--- a/src/libimcv/plugins/imv_test/Makefile.in
+++ b/src/libimcv/plugins/imv_test/Makefile.in
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -73,6 +73,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
am__installdirs = "$(DESTDIR)$(imcvdir)"
LTLIBRARIES = $(imcv_LTLIBRARIES)
imv_test_la_DEPENDENCIES = $(top_builddir)/src/libimcv/libimcv.la \
@@ -119,6 +125,7 @@ CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLIB = @DLLIB@
+DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
@@ -146,6 +153,7 @@ LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MYSQLCFLAG = @MYSQLCFLAG@
MYSQLCONFIG = @MYSQLCONFIG@
@@ -173,6 +181,7 @@ RANLIB = @RANLIB@
RTLIB = @RTLIB@
RUBY = @RUBY@
RUBYINCLUDE = @RUBYINCLUDE@
+RUBYLIB = @RUBYLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
@@ -185,6 +194,7 @@ abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
@@ -238,7 +248,6 @@ libexecdir = @libexecdir@
linux_headers = @linux_headers@
localedir = @localedir@
localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
maemo_CFLAGS = @maemo_CFLAGS@
maemo_LIBS = @maemo_LIBS@
manager_plugins = @manager_plugins@
@@ -360,7 +369,7 @@ clean-imcvLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
-imv-test.la: $(imv_test_la_OBJECTS) $(imv_test_la_DEPENDENCIES)
+imv-test.la: $(imv_test_la_OBJECTS) $(imv_test_la_DEPENDENCIES) $(EXTRA_imv_test_la_DEPENDENCIES)
$(imv_test_la_LINK) -rpath $(imcvdir) $(imv_test_la_OBJECTS) $(imv_test_la_LIBADD) $(LIBS)
mostlyclean-compile:
@@ -498,10 +507,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- `test -z '$(STRIP)' || \
- echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+ 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:
diff --git a/src/libimcv/plugins/imv_test/imv_test.c b/src/libimcv/plugins/imv_test/imv_test.c
index 5ea82e97c..df45ce69a 100644
--- a/src/libimcv/plugins/imv_test/imv_test.c
+++ b/src/libimcv/plugins/imv_test/imv_test.c
@@ -16,7 +16,7 @@
#include "imv_test_state.h"
#include <imv/imv_agent.h>
-#include <pa_tnc/pa_tnc_msg.h>
+#include <imv/imv_msg.h>
#include <ietf/ietf_attr.h>
#include <ietf/ietf_attr_pa_tnc_error.h>
#include <ita/ita_attr.h>
@@ -27,14 +27,15 @@
#include <tncif_pa_subtypes.h>
#include <pen/pen.h>
-#include <debug.h>
+#include <utils/debug.h>
/* IMV definitions */
static const char imv_name[] = "Test";
-#define IMV_VENDOR_ID PEN_ITA
-#define IMV_SUBTYPE PA_SUBTYPE_ITA_TEST
+static pen_type_t msg_types[] = {
+ { PEN_ITA, PA_SUBTYPE_ITA_TEST }
+};
static imv_agent_t *imv_test;
@@ -51,7 +52,7 @@ TNC_Result TNC_IMV_Initialize(TNC_IMVID imv_id,
DBG1(DBG_IMV, "IMV \"%s\" has already been initialized", imv_name);
return TNC_RESULT_ALREADY_INITIALIZED;
}
- imv_test = imv_agent_create(imv_name, IMV_VENDOR_ID, IMV_SUBTYPE,
+ imv_test = imv_agent_create(imv_name, msg_types, countof(msg_types),
imv_id, actual_version);
if (!imv_test)
{
@@ -92,59 +93,32 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id,
}
}
-static TNC_Result receive_message(TNC_IMVID imv_id,
- TNC_ConnectionID connection_id,
- TNC_UInt32 msg_flags,
- chunk_t msg,
- TNC_VendorID msg_vid,
- TNC_MessageSubtype msg_subtype,
- TNC_UInt32 src_imc_id,
- TNC_UInt32 dst_imv_id)
+static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
{
- pa_tnc_msg_t *pa_tnc_msg;
- pa_tnc_attr_t *attr;
- pen_type_t attr_type;
- linked_list_t *attr_list;
- imv_state_t *state;
+ imv_msg_t *out_msg;
imv_test_state_t *test_state;
enumerator_t *enumerator;
+ pa_tnc_attr_t *attr;
+ pen_type_t attr_type;
TNC_Result result;
int rounds;
- bool fatal_error, received_command = FALSE, retry = FALSE;
-
- if (!imv_test)
- {
- DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
- return TNC_RESULT_NOT_INITIALIZED;
- }
-
- /* get current IMV state */
- if (!imv_test->get_state(imv_test, connection_id, &state))
- {
- return TNC_RESULT_FATAL;
- }
- test_state = (imv_test_state_t*)state;
-
- /* parse received PA-TNC message and automatically handle any errors */
- result = imv_test->receive_message(imv_test, state, msg, msg_vid,
- msg_subtype, src_imc_id, dst_imv_id, &pa_tnc_msg);
+ bool fatal_error = FALSE, received_command = FALSE, retry = FALSE;
- /* no parsed PA-TNC attributes available if an error occurred */
- if (!pa_tnc_msg)
+ /* parse received PA-TNC message and handle local and remote errors */
+ result = in_msg->receive(in_msg, &fatal_error);
+ if (result != TNC_RESULT_SUCCESS)
{
return result;
}
- /* preprocess any IETF standard error attributes */
- fatal_error = pa_tnc_msg->process_ietf_std_errors(pa_tnc_msg);
-
/* add any new IMC and set its number of rounds */
rounds = lib->settings->get_int(lib->settings,
"libimcv.plugins.imv-test.rounds", 0);
- test_state->add_imc(test_state, src_imc_id, rounds);
+ test_state = (imv_test_state_t*)state;
+ test_state->add_imc(test_state, in_msg->get_src_id(in_msg), rounds);
/* analyze PA-TNC attributes */
- enumerator = pa_tnc_msg->create_attribute_enumerator(pa_tnc_msg);
+ enumerator = in_msg->create_attribute_enumerator(in_msg);
while (enumerator->enumerate(enumerator, &attr))
{
attr_type = attr->get_type(attr);
@@ -157,7 +131,7 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
{
ita_attr_command_t *ita_attr;
char *command;
-
+
received_command = TRUE;
ita_attr = (ita_attr_command_t*)attr;
command = ita_attr->get_command(ita_attr);
@@ -166,19 +140,19 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
{
state->set_recommendation(state,
TNC_IMV_ACTION_RECOMMENDATION_ALLOW,
- TNC_IMV_EVALUATION_RESULT_COMPLIANT);
+ TNC_IMV_EVALUATION_RESULT_COMPLIANT);
}
else if (streq(command, "isolate"))
{
state->set_recommendation(state,
TNC_IMV_ACTION_RECOMMENDATION_ISOLATE,
- TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR);
+ TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR);
}
else if (streq(command, "block") || streq(command, "none"))
{
state->set_recommendation(state,
TNC_IMV_ACTION_RECOMMENDATION_NO_ACCESS,
- TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR);
+ TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR);
}
else if (streq(command, "retry"))
{
@@ -189,7 +163,7 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
DBG1(DBG_IMV, "unsupported ITA Command '%s'", command);
state->set_recommendation(state,
TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
- TNC_IMV_EVALUATION_RESULT_ERROR);
+ TNC_IMV_EVALUATION_RESULT_ERROR);
}
}
else if (attr_type.type == ITA_ATTR_DUMMY)
@@ -202,40 +176,60 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
}
}
enumerator->destroy(enumerator);
- pa_tnc_msg->destroy(pa_tnc_msg);
if (fatal_error)
{
state->set_recommendation(state,
- TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
- TNC_IMV_EVALUATION_RESULT_ERROR);
- return imv_test->provide_recommendation(imv_test, connection_id,
- src_imc_id);
+ TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
+ TNC_IMV_EVALUATION_RESULT_ERROR);
+ out_msg = imv_msg_create_as_reply(in_msg);
+ result = out_msg->send_assessment(out_msg);
+ out_msg->destroy(out_msg);
+ if (result != TNC_RESULT_SUCCESS)
+ {
+ return result;
+ }
+ return imv_test->provide_recommendation(imv_test, state);
}
/* request a handshake retry ? */
if (retry)
{
test_state->set_rounds(test_state, rounds);
- return imv_test->request_handshake_retry(imv_id, connection_id,
- TNC_RETRY_REASON_IMV_SERIOUS_EVENT);
+ return imv_test->request_handshake_retry(imv_test->get_id(imv_test),
+ state->get_connection_id(state),
+ TNC_RETRY_REASON_IMV_SERIOUS_EVENT);
}
-
+
/* repeat the measurement ? */
- if (test_state->another_round(test_state, src_imc_id))
+ if (test_state->another_round(test_state, in_msg->get_src_id(in_msg)))
{
- attr_list = linked_list_create();
+ out_msg = imv_msg_create_as_reply(in_msg);
attr = ita_attr_command_create("repeat");
- attr_list->insert_last(attr_list, attr);
- result = imv_test->send_message(imv_test, connection_id, TRUE, imv_id,
- src_imc_id, attr_list);
- attr_list->destroy(attr_list);
+ out_msg->add_attribute(out_msg, attr);
+
+ /* send PA-TNC message with excl flag set */
+ result = out_msg->send(out_msg, TRUE);
+ out_msg->destroy(out_msg);
return result;
}
- return received_command ? imv_test->provide_recommendation(imv_test,
- connection_id, src_imc_id) : TNC_RESULT_SUCCESS;
+ if (received_command)
+ {
+ out_msg = imv_msg_create_as_reply(in_msg);
+ result = out_msg->send_assessment(out_msg);
+ out_msg->destroy(out_msg);
+ if (result != TNC_RESULT_SUCCESS)
+ {
+ return result;
+ }
+ return imv_test->provide_recommendation(imv_test, state);
+ }
+ else
+ {
+ return TNC_RESULT_SUCCESS;
+ }
}
/**
@@ -247,14 +241,25 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
TNC_UInt32 msg_len,
TNC_MessageType msg_type)
{
- TNC_VendorID msg_vid;
- TNC_MessageSubtype msg_subtype;
+ imv_state_t *state;
+ imv_msg_t *in_msg;
+ TNC_Result result;
- msg_vid = msg_type >> 8;
- msg_subtype = msg_type & TNC_SUBTYPE_ANY;
+ if (!imv_test)
+ {
+ DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
+ return TNC_RESULT_NOT_INITIALIZED;
+ }
+ if (!imv_test->get_state(imv_test, connection_id, &state))
+ {
+ return TNC_RESULT_FATAL;
+ }
+ in_msg = imv_msg_create_from_data(imv_test, state, connection_id, msg_type,
+ chunk_create(msg, msg_len));
+ result = receive_message(state, in_msg);
+ in_msg->destroy(in_msg);
- return receive_message(imv_id, connection_id, 0, chunk_create(msg, msg_len),
- msg_vid, msg_subtype, 0, TNC_IMVID_ANY);
+ return result;
}
/**
@@ -270,9 +275,26 @@ TNC_Result TNC_IMV_ReceiveMessageLong(TNC_IMVID imv_id,
TNC_UInt32 src_imc_id,
TNC_UInt32 dst_imv_id)
{
- return receive_message(imv_id, connection_id, msg_flags,
- chunk_create(msg, msg_len), msg_vid, msg_subtype,
- src_imc_id, dst_imv_id);
+ imv_state_t *state;
+ imv_msg_t *in_msg;
+ TNC_Result result;
+
+ if (!imv_test)
+ {
+ DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
+ return TNC_RESULT_NOT_INITIALIZED;
+ }
+ if (!imv_test->get_state(imv_test, connection_id, &state))
+ {
+ return TNC_RESULT_FATAL;
+ }
+ in_msg = imv_msg_create_from_long_data(imv_test, state, connection_id,
+ src_imc_id, dst_imv_id, msg_vid, msg_subtype,
+ chunk_create(msg, msg_len));
+ result =receive_message(state, in_msg);
+ in_msg->destroy(in_msg);
+
+ return result;
}
/**
@@ -281,13 +303,18 @@ TNC_Result TNC_IMV_ReceiveMessageLong(TNC_IMVID imv_id,
TNC_Result TNC_IMV_SolicitRecommendation(TNC_IMVID imv_id,
TNC_ConnectionID connection_id)
{
+ imv_state_t *state;
+
if (!imv_test)
{
DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
return TNC_RESULT_NOT_INITIALIZED;
}
- return imv_test->provide_recommendation(imv_test, connection_id,
- TNC_IMCID_ANY);
+ if (!imv_test->get_state(imv_test, connection_id, &state))
+ {
+ return TNC_RESULT_FATAL;
+ }
+ return imv_test->provide_recommendation(imv_test, state);
}
/**
diff --git a/src/libimcv/plugins/imv_test/imv_test_state.c b/src/libimcv/plugins/imv_test/imv_test_state.c
index 67f22c062..9b9344bf6 100644
--- a/src/libimcv/plugins/imv_test/imv_test_state.c
+++ b/src/libimcv/plugins/imv_test/imv_test_state.c
@@ -14,10 +14,12 @@
*/
#include "imv_test_state.h"
+#include "imv/imv_lang_string.h"
+#include "imv/imv_reason_string.h"
#include <utils/lexparser.h>
-#include <utils/linked_list.h>
-#include <debug.h>
+#include <collections/linked_list.h>
+#include <utils/debug.h>
typedef struct private_imv_test_state_t private_imv_test_state_t;
@@ -67,6 +69,11 @@ struct private_imv_test_state_t {
TNC_IMV_Evaluation_Result eval;
/**
+ * TNC Reason String
+ */
+ imv_reason_string_t *reason_string;
+
+ /**
* List of IMCs
*/
linked_list_t *imcs;
@@ -83,24 +90,20 @@ struct imc_entry_t {
int rounds;
};
-typedef struct entry_t entry_t;
-
/**
- * Define an internal reason string entry
+ * Supported languages
*/
-struct entry_t {
- char *lang;
- char *string;
-};
+static char* languages[] = { "en", "de", "fr", "pl" };
/**
- * Table of multi-lingual reason string entries
+ * Table of reason strings
*/
-static entry_t reasons[] = {
+static imv_lang_string_t reasons[] = {
{ "en", "IMC Test was not configured with \"command = allow\"" },
{ "de", "IMC Test wurde nicht mit \"command = allow\" konfiguriert" },
{ "fr", "IMC Test n'etait pas configuré avec \"command = allow\"" },
- { "pl", "IMC Test nie zostało skonfigurowany z \"command = allow\"" }
+ { "pl", "IMC Test nie zostało skonfigurowany z \"command = allow\"" },
+ { NULL, NULL }
};
METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
@@ -163,52 +166,32 @@ METHOD(imv_state_t, set_recommendation, void,
}
METHOD(imv_state_t, get_reason_string, bool,
- private_imv_test_state_t *this, chunk_t preferred_language,
- chunk_t *reason_string, chunk_t *reason_language)
+ private_imv_test_state_t *this, enumerator_t *language_enumerator,
+ chunk_t *reason_string, char **reason_language)
{
- chunk_t pref_lang, lang;
- u_char *pos;
- int i;
-
- while (eat_whitespace(&preferred_language))
- {
- if (!extract_token(&pref_lang, ',', &preferred_language))
- {
- /* last entry in a comma-separated list or single entry */
- pref_lang = preferred_language;
- }
-
- /* eat trailing whitespace */
- pos = pref_lang.ptr + pref_lang.len - 1;
- while (pref_lang.len && *pos-- == ' ')
- {
- pref_lang.len--;
- }
+ *reason_language = imv_lang_string_select_lang(language_enumerator,
+ languages, countof(languages));
- for (i = 0 ; i < countof(reasons); i++)
- {
- lang = chunk_create(reasons[i].lang, strlen(reasons[i].lang));
- if (chunk_equals(lang, pref_lang))
- {
- *reason_language = lang;
- *reason_string = chunk_create(reasons[i].string,
- strlen(reasons[i].string));
- return TRUE;
- }
- }
- }
+ /* Instantiate a TNC Reason String object */
+ DESTROY_IF(this->reason_string);
+ this->reason_string = imv_reason_string_create(*reason_language);
+ this->reason_string->add_reason(this->reason_string, reasons);
+ *reason_string = this->reason_string->get_encoding(this->reason_string);
- /* no preferred language match found - use the default language */
- *reason_string = chunk_create(reasons[0].string,
- strlen(reasons[0].string));
- *reason_language = chunk_create(reasons[0].lang,
- strlen(reasons[0].lang));
return TRUE;
}
+METHOD(imv_state_t, get_remediation_instructions, bool,
+ private_imv_test_state_t *this, enumerator_t *language_enumerator,
+ chunk_t *string, char **lang_code, char **uri)
+{
+ return FALSE;
+}
+
METHOD(imv_state_t, destroy, void,
private_imv_test_state_t *this)
{
+ DESTROY_IF(this->reason_string);
this->imcs->destroy_function(this->imcs, free);
free(this);
}
@@ -274,8 +257,8 @@ METHOD(imv_test_state_t, another_round, bool,
}
}
enumerator->destroy(enumerator);
-
- return not_finished;
+
+ return not_finished;
}
/**
@@ -298,6 +281,7 @@ imv_state_t *imv_test_state_create(TNC_ConnectionID connection_id)
.get_recommendation = _get_recommendation,
.set_recommendation = _set_recommendation,
.get_reason_string = _get_reason_string,
+ .get_remediation_instructions = _get_remediation_instructions,
.destroy = _destroy,
},
.add_imc = _add_imc,
@@ -310,7 +294,7 @@ imv_state_t *imv_test_state_create(TNC_ConnectionID connection_id)
.connection_id = connection_id,
.imcs = linked_list_create(),
);
-
+
return &this->public.interface;
}