added generation time to package versions

This commit is contained in:
Andreas Steffen
2012-11-04 17:47:06 +01:00
parent 1bb6a086a5
commit d598f2db75
2 changed files with 17 additions and 11 deletions
+15 -10
View File
@@ -21,6 +21,7 @@
#include "pts/components/pts_comp_func_name.h" #include "pts/components/pts_comp_func_name.h"
#include <libgen.h> #include <libgen.h>
#include <time.h>
#define IMA_MAX_NAME_LEN 255 #define IMA_MAX_NAME_LEN 255
@@ -897,17 +898,18 @@ METHOD(attest_db_t, list_packages, void,
enumerator_t *e; enumerator_t *e;
char *package, *version; char *package, *version;
int gid, gid_old = 0, security, spaces, count = 0; int gid, gid_old = 0, security, spaces, count = 0;
time_t t;
if (this->pid) if (this->pid)
{ {
e = this->db->query(this->db, e = this->db->query(this->db,
"SELECT p.id, p.name, v.release, v.security FROM packages AS p " "SELECT p.id, p.name, v.release, v.security, v.time "
"JOIN versions AS v ON v.package = p.id " "FROM packages AS p JOIN versions AS v ON v.package = p.id "
"Where v.product = ? ORDER BY p.name, v.release", "WHERE v.product = ? ORDER BY p.name, v.release",
DB_INT, this->pid, DB_INT, DB_TEXT, DB_TEXT, DB_INT); DB_INT, this->pid, DB_INT, DB_TEXT, DB_TEXT, DB_INT, DB_INT);
if (e) if (e)
{ {
while (e->enumerate(e, &gid, &package, &version, &security)) while (e->enumerate(e, &gid, &package, &version, &security, &t))
{ {
if (gid != gid_old) if (gid != gid_old)
{ {
@@ -922,7 +924,7 @@ METHOD(attest_db_t, list_packages, void,
printf(" "); printf(" ");
} }
} }
printf(" (%s) %s\n", version, security ? "[s]" : ""); printf(" %T (%s) %s\n", &t, TRUE, version, security ? "[s]" : "");
count++; count++;
} }
e->destroy(e); e->destroy(e);
@@ -1482,11 +1484,14 @@ METHOD(attest_db_t, add, bool,
/* insert package version */ /* insert package version */
if (this->version_set && this->gid && this->pid) if (this->version_set && this->gid && this->pid)
{ {
time_t t = time(NULL);
success = this->db->execute(this->db, NULL, success = this->db->execute(this->db, NULL,
"INSERT INTO versions (package, product, release, security) " "INSERT INTO versions "
"VALUES (?, ?, ?, ?)", "(package, product, release, security, time) "
DB_UINT, this->gid, DB_UINT, this->pid, "VALUES (?, ?, ?, ?, ?)",
DB_TEXT, this->version, DB_UINT, this->security) == 1; DB_UINT, this->gid, DB_UINT, this->pid, DB_TEXT,
this->version, DB_UINT, this->security, DB_INT, t) == 1;
printf("'%s' package %s (%s) %s%sinserted into database\n", printf("'%s' package %s (%s) %s%sinserted into database\n",
this->product, this->package, this->version, this->product, this->package, this->version,
@@ -102,7 +102,8 @@ CREATE TABLE versions (
package INTEGER NOT NULL, package INTEGER NOT NULL,
product INTEGER NOT NULL, product INTEGER NOT NULL,
release TEXT NOT NULL, release TEXT NOT NULL,
security INTEGER DEFAULT 0 security INTEGER DEFAULT 0,
time INTEGER DEFAULT 0
); );
DROP INDEX IF EXISTS versions_release; DROP INDEX IF EXISTS versions_release;
CREATE INDEX versions_release ON versions ( CREATE INDEX versions_release ON versions (