decoupled request ID from files table primary key
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 10 Sep 2011 09:24:39 +0000 (11:24 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 10 Sep 2011 20:39:56 +0000 (22:39 +0200)
src/libimcv/plugins/imv_attestation/imv_attestation.c
src/libimcv/plugins/imv_attestation/imv_attestation_state.c
src/libimcv/plugins/imv_attestation/imv_attestation_state.h

index f4c5383..096ee5a 100644 (file)
@@ -233,6 +233,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
                        enumerator_t *enumerator;
                        u_int32_t delimiter = SOLIDUS_UTF;
                        char *platform_info, *pathname;
+                       u_int16_t request_id;
                        int id, type;
                        bool is_dir;
 
@@ -277,11 +278,12 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
                                is_dir = (type != 0);
                                DBG2(DBG_IMV, "measurement request %d for %s '%s'",
                                         id, is_dir ? "directory" : "file", pathname);
-                               attr = tcg_pts_attr_req_file_meas_create(is_dir, id, delimiter,
-                                                                                                                pathname);
+                               request_id = attestation_state->add_request(attestation_state,
+                                                                                                                       id, is_dir);
+                               attr = tcg_pts_attr_req_file_meas_create(is_dir, request_id,
+                                                                                                        delimiter, pathname);
                                attr->set_noskip_flag(attr, TRUE);
                                msg->add_attribute(msg, attr);
-                               attestation_state->add_request(attestation_state, id , is_dir);
                        }
                        enumerator->destroy(enumerator);
                        break;
@@ -486,7 +488,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
                                {
                                        tcg_pts_attr_file_meas_t *attr_cast;
                                        u_int16_t request_id;
-                                       int file_count;
+                                       int file_count, file_id;
                                        pts_meas_algorithms_t algo;
                                        pts_file_meas_t *measurements;
                                        char *platform_info;
@@ -509,7 +511,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
                                                 request_id, file_count, (file_count == 1) ? "":"s");
 
                                        if (!attestation_state->check_off_request(attestation_state,
-                                               request_id, &is_dir))
+                                               request_id, &file_id, &is_dir))
                                        {
                                                DBG1(DBG_IMV, "  no entry found for this request"); 
                                                break;
@@ -517,7 +519,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
 
                                        /* check hashes from database against measurements */
                                        e_hash = pts_db->create_hash_enumerator(pts_db, 
-                                                                       platform_info, algo, request_id, is_dir);
+                                                                       platform_info, algo, file_id, is_dir);
                                        if (!measurements->verify(measurements, e_hash, is_dir))
                                        {
                                                measurement_error = TRUE;
index 0e11f75..6305dac 100644 (file)
@@ -26,7 +26,8 @@ typedef struct request_t request_t;
  * PTS File/Directory Measurement request entry
  */
 struct request_t {
-       int id;
+       u_int16_t id;
+       int file_id;
        bool is_dir;
 };
 
@@ -66,6 +67,11 @@ struct private_imv_attestation_state_t {
        TNC_IMV_Evaluation_Result eval;
 
        /**
+        * Request counter
+        */
+       u_int16_t request_counter;
+
+       /**
         * List of PTS File/Directory Measurement requests
         */
        linked_list_t *requests;
@@ -194,19 +200,23 @@ METHOD(imv_attestation_state_t, get_pts, pts_t*,
        return this->pts;
 }
 
-METHOD(imv_attestation_state_t, add_request, void,
-       private_imv_attestation_state_t *this, int id, bool is_dir)
+METHOD(imv_attestation_state_t, add_request, u_int16_t,
+       private_imv_attestation_state_t *this, int file_id, bool is_dir)
 {
        request_t *request;
 
        request = malloc_thing(request_t);
-       request->id = id;
+       request->id = ++this->request_counter;
+       request->file_id = file_id;
        request->is_dir = is_dir;
        this->requests->insert_last(this->requests, request);
+
+       return this->request_counter;
 }
 
 METHOD(imv_attestation_state_t, check_off_request, bool,
-       private_imv_attestation_state_t *this, int id, bool* is_dir)
+       private_imv_attestation_state_t *this, u_int16_t id, int *file_id,
+       bool* is_dir)
 {
        enumerator_t *enumerator;
        request_t *request;
@@ -218,6 +228,7 @@ METHOD(imv_attestation_state_t, check_off_request, bool,
                if (request->id == id)
                {
                        found = TRUE;
+                       *file_id = request->file_id;
                        *is_dir = request->is_dir;
                        this->requests->remove_at(this->requests, enumerator);
                        free(request);
index 58f25fa..d4bba5f 100644 (file)
@@ -75,10 +75,12 @@ struct imv_attestation_state_t {
        /**
         * Add an entry to the list of pending file/directory measurement requests
         *
-        * @param id                            unique request ID
-        * @param is_dir                        TRUE if directory 
+        * @param file_id                       primary key into file table
+        * @param is_dir                        TRUE if directory
+        * @return                                      unique request ID 
         */
-       void (*add_request)(imv_attestation_state_t *this, int id, bool is_dir);
+       u_int16_t (*add_request)(imv_attestation_state_t *this, int file_id,
+                                                        bool is_dir);
 
        /**
         * Returns the number of pending file/directory measurement requests
@@ -91,11 +93,12 @@ struct imv_attestation_state_t {
         * Check for presence of request_id and if found remove it from the list
         *
         * @param id                            unique request ID
+        * @param file_id                       primary key into file table
         * @param is_dir                        return TRUE if request was for a directory
         * @return                                      TRUE if request ID found, FALSE otherwise
         */
-       bool (*check_off_request)(imv_attestation_state_t *this, int id,
-                                                         bool *is_dir);
+       bool (*check_off_request)(imv_attestation_state_t *this, u_int16_t id,
+                                                         int *file_id, bool *is_dir);
 
 };