Added ITA Start/Stop Angel attributes to split bulk data into multiple attributes

This commit is contained in:
Andreas Steffen
2012-11-05 10:24:12 +01:00
parent 3b057d66cf
commit 6ac6dbd3fb
9 changed files with 357 additions and 20 deletions
+22 -1
View File
@@ -30,6 +30,7 @@
#include <ita/ita_attr.h>
#include <ita/ita_attr_get_settings.h>
#include <ita/ita_attr_settings.h>
#include <ita/ita_attr_angel.h>
#include <os_info/os_info.h>
#include <tncif_pa_subtypes.h>
@@ -235,11 +236,12 @@ static void add_default_pwd_enabled(imc_msg_t *msg)
*/
static void add_installed_packages(imc_msg_t *msg)
{
pa_tnc_attr_t *attr = NULL;
pa_tnc_attr_t *attr = NULL, *attr_angel;
ietf_attr_installed_packages_t *attr_cast;
enumerator_t *enumerator;
chunk_t name, version;
size_t attr_size = 0;
bool first = TRUE;
enumerator = os->create_package_enumerator(os);
if (!enumerator)
@@ -259,6 +261,16 @@ static void add_installed_packages(imc_msg_t *msg)
attr_size += 2 + name.len + version.len;
if (attr_size > 20000)
{
if (first)
{
/**
* Send an ITA Start Angel attribute to the IMV signalling that
* there are multiple ITA Installed Package attributes to come.
*/
attr_angel = ita_attr_angel_create(TRUE);
msg->add_attribute(msg, attr_angel);
first = FALSE;
}
msg->add_attribute(msg, attr);
attr_size = 0;
}
@@ -269,6 +281,15 @@ static void add_installed_packages(imc_msg_t *msg)
{
msg->add_attribute(msg, attr);
}
if (!first)
{
/**
* If we sent an ITA Start Angel attribute in the first place,
* terminate by appending a matching ITA Stop Angel attribute.
*/
attr_angel = ita_attr_angel_create(FALSE);
msg->add_attribute(msg, attr_angel);
}
}
/**
+41 -17
View File
@@ -31,6 +31,7 @@
#include <ita/ita_attr.h>
#include <ita/ita_attr_get_settings.h>
#include <ita/ita_attr_settings.h>
#include <ita/ita_attr_angel.h>
#include <tncif_names.h>
#include <tncif_pa_subtypes.h>
@@ -134,6 +135,7 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
chunk_t os_version = chunk_empty;
bool fatal_error = FALSE, assessment = FALSE;
os_state = (imv_os_state_t*)state;
/* parse received PA-TNC message and handle local and remote errors */
result = in_msg->receive(in_msg, &fatal_error);
@@ -251,31 +253,44 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
}
e->destroy(e);
state->set_recommendation(state,
TNC_IMV_ACTION_RECOMMENDATION_ALLOW,
TNC_IMV_EVALUATION_RESULT_COMPLIANT);
assessment = TRUE;
/* Received at least one Installed Packages attribute */
os_state->set_package_request(os_state, FALSE);
break;
}
default:
break;
}
}
else if (type.vendor_id == PEN_ITA && type.type == ITA_ATTR_SETTINGS)
else if (type.vendor_id == PEN_ITA)
{
ita_attr_settings_t *attr_cast;
enumerator_t *e;
char *name;
chunk_t value;
attr_cast = (ita_attr_settings_t*)attr;
e = attr_cast->create_enumerator(attr_cast);
while (e->enumerate(e, &name, &value))
switch (type.type)
{
DBG1(DBG_IMV, "setting '%s'", name);
dbg_imv_multi_line(value);
case ITA_ATTR_SETTINGS:
{
ita_attr_settings_t *attr_cast;
enumerator_t *e;
char *name;
chunk_t value;
attr_cast = (ita_attr_settings_t*)attr;
e = attr_cast->create_enumerator(attr_cast);
while (e->enumerate(e, &name, &value))
{
DBG1(DBG_IMV, "setting '%s'", name);
dbg_imv_multi_line(value);
}
e->destroy(e);
break;
}
case ITA_ATTR_START_ANGEL:
os_state->set_angel_count(os_state, TRUE);
break;
case ITA_ATTR_STOP_ANGEL:
os_state->set_angel_count(os_state, FALSE);
break;
default:
break;
}
e->destroy(e);
}
}
enumerator->destroy(enumerator);
@@ -287,7 +302,6 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
char *string = "use a Linux operating system instead of Windows 1.2.3";
char *lang_code = "en";
os_state = (imv_os_state_t*)state;
os_state->set_info(os_state, os_name, os_version);
product_info = os_state->get_info(os_state);
@@ -314,6 +328,7 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
DBG1(DBG_IMV, "requesting installed packages for '%s'",
product_info);
os_state->set_package_request(os_state, TRUE);
attr = ietf_attr_attr_request_create(PEN_IETF,
IETF_ATTR_INSTALLED_PACKAGES);
out_msg->add_attribute(out_msg, attr);
@@ -344,6 +359,15 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
assessment = TRUE;
}
/* If all Installed Packages attributes were received, go to assessment */
if (!os_state->get_package_request(os_state) &&
!os_state->get_angel_count(os_state))
{
state->set_recommendation(state, TNC_IMV_ACTION_RECOMMENDATION_ALLOW,
TNC_IMV_EVALUATION_RESULT_COMPLIANT);
assessment = TRUE;
}
if (assessment)
{
result = out_msg->send_assessment(out_msg);
+39
View File
@@ -68,6 +68,17 @@ struct private_imv_os_state_t {
* OS Product Information
*/
char *info;
/**
* OS Installed Package request sent - mandatory response expected
*/
bool package_request;
/**
* Angel count
*/
int angel_count;
};
typedef struct entry_t entry_t;
@@ -181,6 +192,30 @@ METHOD(imv_os_state_t, get_info, char*,
return this->info;
}
METHOD(imv_os_state_t, set_package_request, void,
private_imv_os_state_t *this, bool set)
{
this->package_request = set;
}
METHOD(imv_os_state_t, get_package_request, bool,
private_imv_os_state_t *this)
{
return this->package_request;
}
METHOD(imv_os_state_t, set_angel_count, void,
private_imv_os_state_t *this, bool start)
{
this->angel_count += start ? 1 : -1;
}
METHOD(imv_os_state_t, get_angel_count, int,
private_imv_os_state_t *this)
{
return this->angel_count;
}
/**
* Described in header.
*/
@@ -205,6 +240,10 @@ imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id)
},
.set_info = _set_info,
.get_info = _get_info,
.set_package_request = _set_package_request,
.get_package_request = _get_package_request,
.set_angel_count = _set_angel_count,
.get_angel_count = _get_angel_count,
},
.state = TNC_CONNECTION_STATE_CREATE,
.rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
+28
View File
@@ -52,6 +52,34 @@ struct imv_os_state_t {
*/
char* (*get_info)(imv_os_state_t *this);
/**
* Set/reset OS Installed Packages request status
*
* @param set TRUE to set, FALSE to clear
*/
void (*set_package_request)(imv_os_state_t *this, bool set);
/**
* Get OS Installed Packages request status
*
* @result TRUE if set, FALSE if unset
*/
bool (*get_package_request)(imv_os_state_t *this);
/**
* Increase/Decrease the ITA Angel count
*
* @param start TRUE increases and FALSE decreases count by one
*/
void (*set_angel_count)(imv_os_state_t *this, bool start);
/**
* Get the ITA Angel count
*
* @result ITA Angel count
*/
int (*get_angel_count)(imv_os_state_t *this);
};
/**