Store device with product ID
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 11 Jun 2013 20:15:27 +0000 (22:15 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 21 Jun 2013 21:25:24 +0000 (23:25 +0200)
src/libimcv/imv/imv_database.c
src/libimcv/plugins/imv_os/imv_os_agent.c
src/libimcv/plugins/imv_os/imv_os_state.c
src/libimcv/plugins/imv_os/imv_os_state.h
src/libpts/plugins/imv_attestation/attest_db.c

index 6c4ec07..2acb7f2 100644 (file)
@@ -180,11 +180,22 @@ METHOD(imv_database_t, add_device, int,
        private_imv_database_t *this, imv_session_t *session, chunk_t device)
 {
        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 */
        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)
        {
                e->enumerate(e, &did);
@@ -195,7 +206,8 @@ METHOD(imv_database_t, add_device, int,
        if (!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 */
index 86692ed..b22bf70 100644 (file)
@@ -345,21 +345,13 @@ static TNC_Result receive_msg(private_imv_os_agent_t *this, imv_state_t *state,
                                }
                                case ITA_ATTR_DEVICE_ID:
                                {
-                                       imv_session_t *session;
-                                       int device_id;
                                        chunk_t value;
 
                                        state->set_action_flags(state, IMV_OS_ATTR_DEVICE_ID);
 
                                        value = attr->get_value(attr);
+                                       os_state->set_device_id(os_state, value);
                                        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;
                                }
                                case ITA_ATTR_START_ANGEL:
@@ -556,6 +548,9 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
                {
                        if (imcv_db)
                        {
+                               imcv_db->add_device(imcv_db, session,
+                                                               os_state->get_device_id(os_state));
+
                                /* trigger the policy manager */
                                imcv_db->policy_script(imcv_db, session, TRUE);
                        }
index 4ab8a81..f6d904c 100644 (file)
@@ -140,9 +140,9 @@ struct private_imv_os_state_t {
        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
@@ -511,6 +511,7 @@ METHOD(imv_state_t, destroy, void,
        free(this->name.ptr);
        free(this->version.ptr);
        free(this->ar_id_value.ptr);
+       free(this->device_id.ptr);
        free(this);
 }
 
@@ -593,12 +594,12 @@ METHOD(imv_os_state_t, get_count, 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)
 {
        return this->device_id;
index 3ff482b..97f6953 100644 (file)
@@ -123,16 +123,16 @@ struct imv_os_state_t {
        /**
         * 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
         *
-        * @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
index cb1220e..005857f 100644 (file)
@@ -833,13 +833,13 @@ METHOD(attest_db_t, list_devices, void,
                {
                        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++;
                                last_id = id;
                        }
                        timestamp = tstamp;
-                       printf("%4d:   %T, %-20s", session_id, &timestamp, this->utc,
-                                                                          product);
+                       printf("%4d:   %T", session_id, &timestamp, this->utc);
                        if (ar_id)
                        {
                                if (ar_id != last_ar_id)