Store device with product ID
This commit is contained in:
@@ -180,11 +180,22 @@ METHOD(imv_database_t, add_device, int,
|
|||||||
private_imv_database_t *this, imv_session_t *session, chunk_t device)
|
private_imv_database_t *this, imv_session_t *session, chunk_t device)
|
||||||
{
|
{
|
||||||
enumerator_t *e;
|
enumerator_t *e;
|
||||||
int did = 0;
|
int pid = 0, did = 0;
|
||||||
|
|
||||||
|
/* get primary key of product from session */
|
||||||
|
e = this->db->query(this->db,
|
||||||
|
"SELECT product FROM sessions WHERE id = ?",
|
||||||
|
DB_INT, session->get_session_id(session), DB_INT);
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
|
e->enumerate(e, &pid);
|
||||||
|
e->destroy(e);
|
||||||
|
}
|
||||||
|
|
||||||
/* get primary key of device identification if it exists */
|
/* get primary key of device identification if it exists */
|
||||||
e = this->db->query(this->db,
|
e = this->db->query(this->db,
|
||||||
"SELECT id FROM devices WHERE value = ?", DB_BLOB, device, DB_INT);
|
"SELECT id FROM devices WHERE value = ? AND product = ?",
|
||||||
|
DB_BLOB, device, DB_INT, pid, DB_INT);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->enumerate(e, &did);
|
e->enumerate(e, &did);
|
||||||
@@ -195,7 +206,8 @@ METHOD(imv_database_t, add_device, int,
|
|||||||
if (!did)
|
if (!did)
|
||||||
{
|
{
|
||||||
this->db->execute(this->db, &did,
|
this->db->execute(this->db, &did,
|
||||||
"INSERT INTO devices (value) VALUES (?)", DB_BLOB, device);
|
"INSERT INTO devices (value, product) VALUES (?, ?)",
|
||||||
|
DB_BLOB, device, DB_INT, pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add device reference to session */
|
/* add device reference to session */
|
||||||
|
|||||||
@@ -345,21 +345,13 @@ static TNC_Result receive_msg(private_imv_os_agent_t *this, imv_state_t *state,
|
|||||||
}
|
}
|
||||||
case ITA_ATTR_DEVICE_ID:
|
case ITA_ATTR_DEVICE_ID:
|
||||||
{
|
{
|
||||||
imv_session_t *session;
|
|
||||||
int device_id;
|
|
||||||
chunk_t value;
|
chunk_t value;
|
||||||
|
|
||||||
state->set_action_flags(state, IMV_OS_ATTR_DEVICE_ID);
|
state->set_action_flags(state, IMV_OS_ATTR_DEVICE_ID);
|
||||||
|
|
||||||
value = attr->get_value(attr);
|
value = attr->get_value(attr);
|
||||||
|
os_state->set_device_id(os_state, value);
|
||||||
DBG1(DBG_IMV, "device ID is %.*s", value.len, value.ptr);
|
DBG1(DBG_IMV, "device ID is %.*s", value.len, value.ptr);
|
||||||
|
|
||||||
if (imcv_db)
|
|
||||||
{
|
|
||||||
session = state->get_session(state);
|
|
||||||
device_id = imcv_db->add_device(imcv_db, session, value);
|
|
||||||
os_state->set_device_id(os_state, device_id);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ITA_ATTR_START_ANGEL:
|
case ITA_ATTR_START_ANGEL:
|
||||||
@@ -556,6 +548,9 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
|
|||||||
{
|
{
|
||||||
if (imcv_db)
|
if (imcv_db)
|
||||||
{
|
{
|
||||||
|
imcv_db->add_device(imcv_db, session,
|
||||||
|
os_state->get_device_id(os_state));
|
||||||
|
|
||||||
/* trigger the policy manager */
|
/* trigger the policy manager */
|
||||||
imcv_db->policy_script(imcv_db, session, TRUE);
|
imcv_db->policy_script(imcv_db, session, TRUE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,9 +140,9 @@ struct private_imv_os_state_t {
|
|||||||
imv_remediation_string_t *remediation_string;
|
imv_remediation_string_t *remediation_string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary database key of device ID
|
* Dgevice ID
|
||||||
*/
|
*/
|
||||||
int device_id;
|
chunk_t device_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of processed packages
|
* Number of processed packages
|
||||||
@@ -511,6 +511,7 @@ METHOD(imv_state_t, destroy, void,
|
|||||||
free(this->name.ptr);
|
free(this->name.ptr);
|
||||||
free(this->version.ptr);
|
free(this->version.ptr);
|
||||||
free(this->ar_id_value.ptr);
|
free(this->ar_id_value.ptr);
|
||||||
|
free(this->device_id.ptr);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,12 +594,12 @@ METHOD(imv_os_state_t, get_count, void,
|
|||||||
}
|
}
|
||||||
|
|
||||||
METHOD(imv_os_state_t, set_device_id, void,
|
METHOD(imv_os_state_t, set_device_id, void,
|
||||||
private_imv_os_state_t *this, int id)
|
private_imv_os_state_t *this, chunk_t id)
|
||||||
{
|
{
|
||||||
this->device_id = id;
|
this->device_id = chunk_clone(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(imv_os_state_t, get_device_id, int,
|
METHOD(imv_os_state_t, get_device_id, chunk_t,
|
||||||
private_imv_os_state_t *this)
|
private_imv_os_state_t *this)
|
||||||
{
|
{
|
||||||
return this->device_id;
|
return this->device_id;
|
||||||
|
|||||||
@@ -123,16 +123,16 @@ struct imv_os_state_t {
|
|||||||
/**
|
/**
|
||||||
* Set device ID
|
* Set device ID
|
||||||
*
|
*
|
||||||
* @param device_id Device ID primary database key
|
* @param device_id Device ID
|
||||||
*/
|
*/
|
||||||
void (*set_device_id)(imv_os_state_t *this, int id);
|
void (*set_device_id)(imv_os_state_t *this, chunk_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get device ID
|
* Get device ID
|
||||||
*
|
*
|
||||||
* @return Device ID primary database key
|
* @return Device ID
|
||||||
*/
|
*/
|
||||||
int (*get_device_id)(imv_os_state_t *this);
|
chunk_t (*get_device_id)(imv_os_state_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set OS settings
|
* Set OS settings
|
||||||
|
|||||||
@@ -833,13 +833,13 @@ METHOD(attest_db_t, list_devices, void,
|
|||||||
{
|
{
|
||||||
if (id != last_id)
|
if (id != last_id)
|
||||||
{
|
{
|
||||||
printf("%4d: %.*s\n", id, (int)value.len, value.ptr);
|
printf("%4d: %.*s - %s\n", id, (int)value.len, value.ptr,
|
||||||
|
product);
|
||||||
device_count++;
|
device_count++;
|
||||||
last_id = id;
|
last_id = id;
|
||||||
}
|
}
|
||||||
timestamp = tstamp;
|
timestamp = tstamp;
|
||||||
printf("%4d: %T, %-20s", session_id, ×tamp, this->utc,
|
printf("%4d: %T", session_id, ×tamp, this->utc);
|
||||||
product);
|
|
||||||
if (ar_id)
|
if (ar_id)
|
||||||
{
|
{
|
||||||
if (ar_id != last_ar_id)
|
if (ar_id != last_ar_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user