implemented os_info_t class
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <ietf/ietf_attr_pa_tnc_error.h>
|
||||
#include <ietf/ietf_attr_product_info.h>
|
||||
#include <ietf/ietf_attr_string_version.h>
|
||||
#include <os_info/os_info.h>
|
||||
|
||||
#include <tncif_pa_subtypes.h>
|
||||
|
||||
@@ -40,6 +41,7 @@ static const char imc_name[] = "OS";
|
||||
#define IMC_SUBTYPE PA_SUBTYPE_IETF_OPERATING_SYSTEM
|
||||
|
||||
static imc_agent_t *imc_os;
|
||||
static os_info_t *os;
|
||||
|
||||
/**
|
||||
* see section 3.8.1 of TCG TNC IF-IMC Specification 1.3
|
||||
@@ -60,6 +62,16 @@ TNC_Result TNC_IMC_Initialize(TNC_IMCID imc_id,
|
||||
{
|
||||
return TNC_RESULT_FATAL;
|
||||
}
|
||||
|
||||
os = os_info_create();
|
||||
if (!os)
|
||||
{
|
||||
imc_os->destroy(imc_os);
|
||||
imc_os = NULL;
|
||||
|
||||
return TNC_RESULT_FATAL;
|
||||
}
|
||||
|
||||
if (min_version > TNC_IFIMC_VERSION_1 || max_version < TNC_IFIMC_VERSION_1)
|
||||
{
|
||||
DBG1(DBG_IMC, "no common IF-IMC version");
|
||||
@@ -110,9 +122,8 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
|
||||
static void add_product_info(linked_list_t *attr_list)
|
||||
{
|
||||
pa_tnc_attr_t *attr;
|
||||
char *os_name = "Ubuntu";
|
||||
|
||||
attr = ietf_attr_product_info_create(PEN_IETF, 0, os_name);
|
||||
attr = ietf_attr_product_info_create(PEN_IETF, 0, os->get_name(os));
|
||||
attr_list->insert_last(attr_list, attr);
|
||||
}
|
||||
|
||||
@@ -122,9 +133,9 @@ static void add_product_info(linked_list_t *attr_list)
|
||||
static void add_string_version(linked_list_t *attr_list)
|
||||
{
|
||||
pa_tnc_attr_t *attr;
|
||||
chunk_t os_version = { "12.04", 5};
|
||||
|
||||
attr = ietf_attr_string_version_create(os_version, chunk_empty, chunk_empty);
|
||||
attr = ietf_attr_string_version_create(os->get_version(os),
|
||||
chunk_empty, chunk_empty);
|
||||
attr_list->insert_last(attr_list, attr);
|
||||
}
|
||||
|
||||
@@ -362,6 +373,9 @@ TNC_Result TNC_IMC_Terminate(TNC_IMCID imc_id)
|
||||
imc_os->destroy(imc_os);
|
||||
imc_os = NULL;
|
||||
|
||||
os->destroy(os);
|
||||
os = NULL;
|
||||
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
|
||||
imv_os_state_t *os_state;
|
||||
enumerator_t *enumerator;
|
||||
TNC_Result result;
|
||||
char *os_name = NULL;
|
||||
chunk_t os_name = chunk_empty;
|
||||
chunk_t os_version = chunk_empty;
|
||||
bool fatal_error, assessment = FALSE;
|
||||
|
||||
@@ -161,7 +161,8 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
|
||||
|
||||
attr_cast = (ietf_attr_product_info_t*)attr;
|
||||
os_name = attr_cast->get_info(attr_cast, NULL, NULL);
|
||||
DBG1(DBG_IMV, "operating system name is '%s'", os_name);
|
||||
DBG1(DBG_IMV, "operating system name is '%.*s'",
|
||||
os_name.len, os_name.ptr);
|
||||
break;
|
||||
}
|
||||
case IETF_ATTR_STRING_VERSION:
|
||||
@@ -204,15 +205,30 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
if (os_name && os_version.len)
|
||||
if (os_name.len && os_version.len)
|
||||
{
|
||||
os_state->set_info(os_state, os_name, os_version);
|
||||
char *product_info;
|
||||
|
||||
DBG1(DBG_IMV, "requesting installed packages for '%s'",
|
||||
os_state->get_info(os_state));
|
||||
attr = ietf_attr_attr_request_create(PEN_IETF,
|
||||
IETF_ATTR_INSTALLED_PACKAGES);
|
||||
attr_list->insert_last(attr_list, attr);
|
||||
os_state->set_info(os_state, os_name, os_version);
|
||||
product_info = os_state->get_info(os_state);
|
||||
|
||||
if (streq(product_info, "Windows 1.2.3"))
|
||||
{
|
||||
DBG1(DBG_IMV, "OS '%s' is not supported", product_info);
|
||||
|
||||
state->set_recommendation(state,
|
||||
TNC_IMV_ACTION_RECOMMENDATION_ISOLATE,
|
||||
TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR);
|
||||
assessment = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(DBG_IMV, "requesting installed packages for '%s'",
|
||||
product_info);
|
||||
attr = ietf_attr_attr_request_create(PEN_IETF,
|
||||
IETF_ATTR_INSTALLED_PACKAGES);
|
||||
attr_list->insert_last(attr_list, attr);
|
||||
}
|
||||
}
|
||||
pa_tnc_msg->destroy(pa_tnc_msg);
|
||||
|
||||
|
||||
@@ -164,14 +164,15 @@ METHOD(imv_state_t, destroy, void,
|
||||
}
|
||||
|
||||
METHOD(imv_os_state_t, set_info, void,
|
||||
private_imv_os_state_t *this, char *name, chunk_t version)
|
||||
private_imv_os_state_t *this, chunk_t name, chunk_t version)
|
||||
{
|
||||
int len = strlen(name) + 1 + version.len + 1;
|
||||
int len = name.len + 1 + version.len + 1;
|
||||
|
||||
/* OS info is a concatenation of OS name and OS version */
|
||||
free(this->info);
|
||||
this->info = malloc(len);
|
||||
snprintf(this->info, len, "%s %.*s", name, version.len, version.ptr);
|
||||
snprintf(this->info, len, "%.*s %.*s", name.len, name.ptr,
|
||||
version.len, version.ptr);
|
||||
}
|
||||
|
||||
METHOD(imv_os_state_t, get_info, char*,
|
||||
|
||||
@@ -43,7 +43,7 @@ struct imv_os_state_t {
|
||||
* @param name OS name
|
||||
* @param version OS version
|
||||
*/
|
||||
void (*set_info)(imv_os_state_t *this, char *name, chunk_t version);
|
||||
void (*set_info)(imv_os_state_t *this, chunk_t name, chunk_t version);
|
||||
|
||||
/**
|
||||
* Get OS Product Information
|
||||
|
||||
Reference in New Issue
Block a user