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)
{
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 directories as d ON d.id = f.dir "
"WHERE fh.product = ? AND fh.algo = ? AND d.id = ? "
"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
{
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 "
"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;
}
+56 -28
View File
@@ -184,47 +184,75 @@ METHOD(pts_file_meas_t, check, bool,
METHOD(pts_file_meas_t, verify, bool,
private_pts_file_meas_t *this, enumerator_t *e_hash, bool is_dir)
{
int fid, fid_last = 0;
char *filename;
chunk_t measurement;
entry_t *entry;
enumerator_t *enumerator;
bool found, success = TRUE;
enumerator_t *enumerator = NULL;
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;
enumerator = this->list->create_enumerator(this->list);
while (enumerator->enumerate(enumerator, &entry))
if (fid != fid_last)
{
if (!is_dir || streq(filename, entry->filename))
if (found && !match)
{
found = TRUE;
break;
/* no matching hash value found for last filename */
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);
success = FALSE;
continue;
}
if (chunk_equals(measurement, entry->measurement))
{
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 (chunk_equals(measurement, entry->measurement))
{
match = TRUE;
DBG2(DBG_PTS, " %#B for '%s' is ok",
&entry->measurement, entry->filename);
enumerator->destroy(enumerator);
}
}
}
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;
}