From 907418634525a89f860c0c5292794dc50edf65f3 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Sun, 4 Nov 2012 18:55:37 +0100 Subject: [PATCH] add generation time to package versions --- src/libimcv/plugins/imv_os/pacman.c | 32 ++++++++++--------- .../plugins/imv_attestation/attest_db.c | 4 +-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/libimcv/plugins/imv_os/pacman.c b/src/libimcv/plugins/imv_os/pacman.c index 1b8e53d1a..26e808838 100644 --- a/src/libimcv/plugins/imv_os/pacman.c +++ b/src/libimcv/plugins/imv_os/pacman.c @@ -185,11 +185,11 @@ static void process_packages(char *filename, char *product, bool update) while (fgets(line, sizeof(line), file)) { - char *package, *version, *current_version; + char *package, *version, *cur_version; bool security, update_version = TRUE; - int current_security; + int cur_security; u_int32_t gid = 0, vid = 0; - time_t generation_time; + time_t gen_time, cur_time; count++; if (count == 1) @@ -198,16 +198,16 @@ static void process_packages(char *filename, char *product, bool update) } if (count == 3) { - generation_time = extract_time(line); + gen_time = extract_time(line); - if (generation_time == UNDEFINED_TIME) + if (gen_time == UNDEFINED_TIME) { fprintf(stderr, "could not extract generation time\n"); fclose(file); db->destroy(db); exit(EXIT_FAILURE); } - printf("Generated: %T\n", &generation_time, TRUE); + printf("Generated: %T\n", &gen_time, TRUE); } if (count < 7) { @@ -286,14 +286,15 @@ static void process_packages(char *filename, char *product, bool update) } /* check for package versions already in database */ - e = db->query(db, "SELECT id, release, security FROM versions " - "WHERE package = ? AND product = ?", - DB_INT, gid, DB_INT, pid, DB_INT, DB_TEXT, DB_INT); + e = db->query(db, + "SELECT id, release, security, time FROM versions " + "WHERE package = ? AND product = ?", + DB_INT, gid, DB_INT, pid, DB_INT, DB_TEXT, DB_INT, DB_INT); if (e) { - while (e->enumerate(e, &vid, ¤t_version, ¤t_security)) + while (e->enumerate(e, &vid, &cur_version, &cur_security, &cur_time)) { - if (streq(version, current_version)) + if (streq(version, cur_version)) { update_version = FALSE; } @@ -302,12 +303,13 @@ static void process_packages(char *filename, char *product, bool update) } if ((!vid && security) || (vid && update_version)) { - printf("'%s' (%s) %s\n", package, version, security ? "[s]" : ""); + printf("%s (%s) %s\n", package, version, security ? "[s]" : ""); if (db->execute(db, &gid, - "INSERT INTO versions (package, product, release, security) " - "VALUES (?, ?, ?, ?)", DB_INT, gid, DB_INT, pid, - DB_TEXT, version, DB_INT, security) != 1) + "INSERT INTO versions " + "(package, product, release, security, time) " + "VALUES (?, ?, ?, ?, ?)", DB_INT, gid, DB_INT, pid, + DB_TEXT, version, DB_INT, security, DB_INT, gen_time) != 1) { fprintf(stderr, "could not store version '%s' to database\n", version); diff --git a/src/libpts/plugins/imv_attestation/attest_db.c b/src/libpts/plugins/imv_attestation/attest_db.c index e56da64ba..6be7093a8 100644 --- a/src/libpts/plugins/imv_attestation/attest_db.c +++ b/src/libpts/plugins/imv_attestation/attest_db.c @@ -913,12 +913,12 @@ METHOD(attest_db_t, list_packages, void, { if (gid != gid_old) { - printf("%5d: %s", gid, package); + printf("%5d: %s,", gid, package); gid_old = gid; } else { - spaces = 7 + strlen(package); + spaces = 8 + strlen(package); while (spaces--) { printf(" ");