fixed measurement of directory contents
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 1 Sep 2011 14:27:18 +0000 (16:27 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 8 Sep 2011 10:08:15 +0000 (12:08 +0200)
src/libimcv/plugins/imv_attestation/imv_attestation.c
src/libimcv/tcg/pts/pts.c
src/libimcv/tcg/tcg_pts_attr_file_meas.c

index 619c97c..ceb4b89 100644 (file)
@@ -454,14 +454,14 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
                                                if (!e)
                                                {
                                                        DBG1(DBG_IMV, "  database enumerator failed");
-                                                       break;
+                                                       continue;
                                                }
                                                if (!e->enumerate(e, &db_measurement))
                                                {
                                                        DBG1(DBG_IMV, "  measurement for '%s' not found"
                                                                                  " in database", filename);
                                                        e->destroy(e);
-                                                       break;
+                                                       continue;
                                                }
                                                if (chunk_equals(db_measurement, measurement))
                                                {
index bd38922..0f055b3 100644 (file)
@@ -606,8 +606,7 @@ static char* get_filename(char *pathname)
 }
 
 METHOD(pts_t, do_measurements, pts_file_meas_t*,
-       private_pts_t *this, u_int16_t request_id, char *pathname,
-       bool directory_flag)
+       private_pts_t *this, u_int16_t request_id, char *pathname, bool is_directory)
 {
        hasher_t *hasher;
        hash_algorithm_t hash_alg;
@@ -630,7 +629,7 @@ METHOD(pts_t, do_measurements, pts_file_meas_t*,
        /* Link the hash to the measurement and set the measurement length */
        measurement = chunk_create(hash, hasher->get_hash_size(hasher));
 
-       if (directory_flag)
+       if (is_directory)
        {
                enumerator_t *enumerator;
                char *rel_name, *abs_name;
@@ -647,7 +646,8 @@ METHOD(pts_t, do_measurements, pts_file_meas_t*,
                }
                while (enumerator->enumerate(enumerator, &rel_name, &abs_name, &st))
                {
-                       if (S_ISDIR(st.st_mode) && *rel_name != '.')
+                       /* measure regular files only */
+                       if (S_ISREG(st.st_mode) && *rel_name != '.')
                        {
                                if (!hash_file(hasher, abs_name, hash))
                                {
@@ -656,8 +656,7 @@ METHOD(pts_t, do_measurements, pts_file_meas_t*,
                                        measurements->destroy(measurements);
                                        return NULL;    
                                }
-                               DBG2(DBG_IMC, "  %#B for '%s'",
-                                        &measurement, rel_name);
+                               DBG2(DBG_IMC, "  %#B for '%s'", &measurement, rel_name);
                                measurements->add(measurements, rel_name, measurement);
                        }       
                }
index d2fcb54..b265ca1 100644 (file)
@@ -156,6 +156,12 @@ METHOD(pa_tnc_attr_t, build, void,
        }
        enumerator->destroy(enumerator);
 
+       if (first)
+       {
+               /* no attached measurements */
+               writer->write_uint16(writer, 0);
+       }
+
        this->value = chunk_clone(writer->get_buf(writer));
        writer->destroy(writer);
 }