Allow multiple hash values in the file reference database

This commit is contained in:
Andreas Steffen
2014-06-10 16:48:15 +02:00
parent c621847395
commit 3a9602d58b
2 changed files with 60 additions and 32 deletions
+4 -4
View File
@@ -101,20 +101,20 @@ METHOD(pts_database_t, create_file_hash_enumerator, enumerator_t*,
if (is_dir) if (is_dir)
{ {
e = this->db->query(this->db, e = this->db->query(this->db,
"SELECT f.name, fh.hash FROM file_hashes AS fh " "SELECT f.id, f.name, fh.hash FROM file_hashes AS fh "
"JOIN files AS f ON f.id = fh.file " "JOIN files AS f ON f.id = fh.file "
"JOIN directories as d ON d.id = f.dir " "JOIN directories as d ON d.id = f.dir "
"WHERE fh.product = ? AND fh.algo = ? AND d.id = ? " "WHERE fh.product = ? AND fh.algo = ? AND d.id = ? "
"ORDER BY f.name", "ORDER BY f.name",
DB_INT, pid, DB_INT, algo, DB_INT, id, DB_TEXT, DB_BLOB); DB_INT, pid, DB_INT, algo, DB_INT, id, DB_INT, DB_TEXT, DB_BLOB);
} }
else else
{ {
e = this->db->query(this->db, e = this->db->query(this->db,
"SELECT f.name, fh.hash FROM file_hashes AS fh " "SELECT f.id, f.name, fh.hash FROM file_hashes AS fh "
"JOIN files AS f ON f.id = fh.file " "JOIN files AS f ON f.id = fh.file "
"WHERE fh.product = ? AND fh.algo = ? AND fh.file = ?", "WHERE fh.product = ? AND fh.algo = ? AND fh.file = ?",
DB_INT, pid, DB_INT, algo, DB_INT, id, DB_TEXT, DB_BLOB); DB_INT, pid, DB_INT, algo, DB_INT, id, DB_INT, DB_TEXT, DB_BLOB);
} }
return e; return e;
} }
+56 -28
View File
@@ -184,47 +184,75 @@ METHOD(pts_file_meas_t, check, bool,
METHOD(pts_file_meas_t, verify, bool, METHOD(pts_file_meas_t, verify, bool,
private_pts_file_meas_t *this, enumerator_t *e_hash, bool is_dir) private_pts_file_meas_t *this, enumerator_t *e_hash, bool is_dir)
{ {
int fid, fid_last = 0;
char *filename; char *filename;
chunk_t measurement; chunk_t measurement;
entry_t *entry; entry_t *entry;
enumerator_t *enumerator; enumerator_t *enumerator = NULL;
bool found, success = TRUE; bool found = FALSE, match = FALSE, success = TRUE;
while (e_hash->enumerate(e_hash, &filename, &measurement)) while (e_hash->enumerate(e_hash, &fid, &filename, &measurement))
{ {
found = FALSE; if (fid != fid_last)
enumerator = this->list->create_enumerator(this->list);
while (enumerator->enumerate(enumerator, &entry))
{ {
if (!is_dir || streq(filename, entry->filename)) if (found && !match)
{ {
found = TRUE; /* no matching hash value found for last filename */
break; success = FALSE;
DBG1(DBG_PTS, " %#B for '%s' is incorrect",
&entry->measurement, entry->filename);
enumerator->destroy(enumerator);
}
/* get a new filename from the database */
found = FALSE;
match = FALSE;
fid_last = fid;
/**
* check if we find an entry for this filename
* in the PTS measurement list
*/
enumerator = this->list->create_enumerator(this->list);
while (enumerator->enumerate(enumerator, &entry))
{
if (!is_dir || streq(filename, entry->filename))
{
found = TRUE;
break;
}
}
/* no PTS measurement returned for this filename */
if (!found)
{
success = FALSE;
DBG1(DBG_PTS, " no measurement found for '%s'", filename);
enumerator->destroy(enumerator);
} }
} }
enumerator->destroy(enumerator);
if (!found) if (found && !match)
{ {
DBG1(DBG_PTS, " no measurement found for '%s'", filename); if (chunk_equals(measurement, entry->measurement))
success = FALSE; {
continue; match = TRUE;
} DBG2(DBG_PTS, " %#B for '%s' is ok",
if (chunk_equals(measurement, entry->measurement)) &entry->measurement, entry->filename);
{ enumerator->destroy(enumerator);
DBG2(DBG_PTS, " %#B for '%s' is ok", &measurement, filename); }
}
else
{
DBG1(DBG_PTS, " %#B for '%s' is incorrect", &measurement, filename);
success = FALSE;
}
if (!is_dir)
{
break;
} }
} }
if (found && !match)
{
/* no matching hash value found for the very last filename */
success = FALSE;
DBG1(DBG_PTS, " %#B for '%s' is incorrect",
&entry->measurement, entry->filename);
enumerator->destroy(enumerator);
}
return success; return success;
} }