store unique device_id in database
This commit is contained in:
@@ -122,23 +122,6 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* print multi-line values to debug output
|
||||
*/
|
||||
static void dbg_imv_multi_line(chunk_t value)
|
||||
{
|
||||
chunk_t line;
|
||||
|
||||
while (extract_token(&line, '\n', &value))
|
||||
{
|
||||
DBG2(DBG_IMV, " %.*s", line.len, line.ptr);
|
||||
}
|
||||
if (value.len)
|
||||
{
|
||||
DBG2(DBG_IMV, " %.*s", value.len, value.ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
|
||||
{
|
||||
imv_msg_t *out_msg;
|
||||
@@ -151,6 +134,8 @@ 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;
|
||||
char non_market_apps_str[] = "install_non_market_apps";
|
||||
char android_id_str[] = "android_id";
|
||||
char machine_id_str[] = "/var/lib/dbus/machine-id";
|
||||
|
||||
os_state = (imv_os_state_t*)state;
|
||||
|
||||
@@ -318,8 +303,14 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
|
||||
os_state->set_os_settings(os_state,
|
||||
OS_SETTINGS_NON_MARKET_APPS);
|
||||
}
|
||||
DBG1(DBG_IMV, "setting '%s'", name);
|
||||
dbg_imv_multi_line(value);
|
||||
else if ((streq(name, android_id_str) ||
|
||||
streq(name, machine_id_str)) && os_db)
|
||||
{
|
||||
os_state->set_device_id(os_state,
|
||||
os_db->get_device_id(os_db, value));
|
||||
}
|
||||
DBG1(DBG_IMV, "setting '%s'\n %.*s",
|
||||
name, value.len, value.ptr);
|
||||
}
|
||||
e->destroy(e);
|
||||
break;
|
||||
@@ -358,12 +349,12 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
|
||||
|
||||
if (os_type == OS_TYPE_ANDROID)
|
||||
{
|
||||
attr_cast->add(attr_cast, "android_id");
|
||||
attr_cast->add(attr_cast, android_id_str);
|
||||
attr_cast->add(attr_cast, non_market_apps_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr_cast->add(attr_cast, "/proc/sys/kernel/random/boot_id");
|
||||
attr_cast->add(attr_cast, machine_id_str);
|
||||
attr_cast->add(attr_cast, "/proc/sys/kernel/tainted");
|
||||
}
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
|
||||
@@ -187,6 +187,32 @@ METHOD(imv_os_database_t, check_packages, status_t,
|
||||
return status;
|
||||
}
|
||||
|
||||
METHOD(imv_os_database_t, get_device_id, int,
|
||||
private_imv_os_database_t *this, chunk_t value)
|
||||
{
|
||||
enumerator_t *e;
|
||||
int id;
|
||||
|
||||
/* get primary key of device ID */
|
||||
e = this->db->query(this->db, "SELECT id FROM devices WHERE value = ?",
|
||||
DB_BLOB, value, DB_INT);
|
||||
if (!e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (e->enumerate(e, &id))
|
||||
{
|
||||
/* device ID already exists in database - return primary key */
|
||||
e->destroy(e);
|
||||
return id;
|
||||
}
|
||||
|
||||
/* register new device ID in database and return primary key */
|
||||
return (this->db->execute(this->db, &id,
|
||||
"INSERT INTO devices (value) VALUES (?)", DB_BLOB, value) == 1) ?
|
||||
id : 0;
|
||||
}
|
||||
|
||||
METHOD(imv_os_database_t, destroy, void,
|
||||
private_imv_os_database_t *this)
|
||||
{
|
||||
@@ -204,6 +230,7 @@ imv_os_database_t *imv_os_database_create(char *uri)
|
||||
INIT(this,
|
||||
.public = {
|
||||
.check_packages = _check_packages,
|
||||
.get_device_id = _get_device_id,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.db = lib->db->create(lib->db, uri),
|
||||
|
||||
@@ -42,6 +42,13 @@ struct imv_os_database_t {
|
||||
status_t (*check_packages)(imv_os_database_t *this, imv_os_state_t *state,
|
||||
enumerator_t *package_enumerator);
|
||||
|
||||
/**
|
||||
* Get the primary database key of the device ID
|
||||
*
|
||||
* @param value Device ID value
|
||||
*/
|
||||
int (*get_device_id)(imv_os_database_t *this, chunk_t value);
|
||||
|
||||
/**
|
||||
* Destroys an imv_os_database_t object.
|
||||
*/
|
||||
|
||||
@@ -111,6 +111,11 @@ struct private_imv_os_state_t {
|
||||
*/
|
||||
imv_remediation_string_t *remediation_string;
|
||||
|
||||
/**
|
||||
* Primary database key of device ID
|
||||
*/
|
||||
int device_id;
|
||||
|
||||
/**
|
||||
* Number of processed packages
|
||||
*/
|
||||
@@ -179,7 +184,7 @@ static imv_lang_string_t reason_packages[] = {
|
||||
static imv_lang_string_t instr_update_packages_title[] = {
|
||||
{ "en", "Software Security Updates" },
|
||||
{ "de", "Software Sicherheitsupdates" },
|
||||
{ "pl", "aktualizacja softwaru zabezpieczającego" },
|
||||
{ "pl", "Aktualizacja softwaru zabezpieczającego" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -513,6 +518,18 @@ METHOD(imv_os_state_t, get_package_request, bool,
|
||||
return this->package_request;
|
||||
}
|
||||
|
||||
METHOD(imv_os_state_t, set_device_id, void,
|
||||
private_imv_os_state_t *this, int id)
|
||||
{
|
||||
this->device_id = id;
|
||||
}
|
||||
|
||||
METHOD(imv_os_state_t, get_device_id, int,
|
||||
private_imv_os_state_t *this)
|
||||
{
|
||||
return this->device_id;
|
||||
}
|
||||
|
||||
METHOD(imv_os_state_t, set_os_settings, void,
|
||||
private_imv_os_state_t *this, u_int settings)
|
||||
{
|
||||
@@ -582,6 +599,8 @@ imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id)
|
||||
.get_count = _get_count,
|
||||
.set_package_request = _set_package_request,
|
||||
.get_package_request = _get_package_request,
|
||||
.set_device_id = _set_device_id,
|
||||
.get_device_id = _get_device_id,
|
||||
.set_os_settings = _set_os_settings,
|
||||
.get_os_settings = _get_os_settings,
|
||||
.set_angel_count = _set_angel_count,
|
||||
|
||||
@@ -101,6 +101,20 @@ struct imv_os_state_t {
|
||||
*/
|
||||
bool (*get_package_request)(imv_os_state_t *this);
|
||||
|
||||
/**
|
||||
* Set device ID
|
||||
*
|
||||
* @param device_id Device ID primary database key
|
||||
*/
|
||||
void (*set_device_id)(imv_os_state_t *this, int id);
|
||||
|
||||
/**
|
||||
* Get device ID
|
||||
*
|
||||
* @return Device ID primary database key
|
||||
*/
|
||||
int (*get_device_id)(imv_os_state_t *this);
|
||||
|
||||
/**
|
||||
* Set OS settings
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user