aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2013-12-13 14:37:31 +0100
committerAndreas Steffen <andreas.steffen@strongswan.org>2013-12-13 14:37:31 +0100
commitf5fd12b9320fa7c5f8c9d8a08963c33c5e229ed2 (patch)
tree147b1ec9b79d19e2b1d625ce5df8b2c8755d3a77
parent953a922e9b8b3b859d59b5b7e00b717fa97eea1b (diff)
downloadstrongswan-f5fd12b9320fa7c5f8c9d8a08963c33c5e229ed2.tar.bz2
strongswan-f5fd12b9320fa7c5f8c9d8a08963c33c5e229ed2.tar.xz
Fixed check_file_measurement method in pts_database_t
-rw-r--r--src/libpts/pts/pts_database.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/src/libpts/pts/pts_database.c b/src/libpts/pts/pts_database.c
index e5a06cc8d..95b1114f6 100644
--- a/src/libpts/pts/pts_database.c
+++ b/src/libpts/pts/pts_database.c
@@ -15,6 +15,7 @@
#define _GNU_SOURCE
#include <stdio.h>
+#include <libgen.h>
#include "pts_database.h"
@@ -248,13 +249,60 @@ METHOD(pts_database_t, check_file_measurement, status_t,
enumerator_t *e;
chunk_t hash;
status_t status = NOT_FOUND;
+ char *path, *dir, *file;
+
+ if (strlen(filename) < 1)
+ {
+ return INVALID_ARG;
+ }
+
+ /* separate filename into directory and basename components */
+ path = strdup(filename);
+ dir = dirname(path);
+ file = basename(filename);
+
+ if (*dir == '.')
+ { /* relative pathname */
+ e = this->db->query(this->db,
+ "SELECT fh.hash FROM file_hashes AS fh "
+ "JOIN files AS f ON f.id = fh.file "
+ "JOIN products AS p ON p.id = fh.product "
+ "WHERE p.name = ? AND f.name = ? AND fh.algo = ?",
+ DB_TEXT, product, DB_TEXT, file, DB_INT, algo, DB_BLOB);
+ }
+ else
+ { /* absolute pathname */
+ bool dir_found;
+ int did;
+
+ /* find directory entry first */
+ e = this->db->query(this->db,
+ "SELECT id FROM directories WHERE path = ?",
+ DB_TEXT, dir, DB_INT);
+ if (!e)
+ {
+ free(path);
+ return FAILED;
+ }
+ dir_found = e->enumerate(e, &did);
+ e->destroy(e);
+
+ if (!dir_found)
+ {
+ free(path);
+ return NOT_FOUND;
+ }
+
+ e = this->db->query(this->db,
+ "SELECT fh.hash FROM file_hashes AS fh "
+ "JOIN files AS f ON f.id = fh.file "
+ "JOIN products AS p ON p.id = fh.product "
+ "WHERE p.name = ? AND f.dir = ? AND f.name = ? AND fh.algo = ?",
+ DB_TEXT, product, DB_INT, did, DB_TEXT, file, DB_INT, algo,
+ DB_BLOB);
+ }
+ free(path);
- e = this->db->query(this->db,
- "SELECT fh.hash FROM file_hashes AS fh "
- "JOIN files AS f ON f.id = fh.file "
- "JOIN products AS p ON p.id = fh.product "
- "WHERE p.name = ? AND f.path = ? AND fh.algo = ?",
- DB_TEXT, product, DB_TEXT, filename, DB_INT, algo, DB_BLOB);
if (!e)
{
return FAILED;