#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <syslog.h>
#include <library.h>
+#include <debug.h>
+#include <imcv.h>
+#include <libpts.h>
#include <pts/pts_meas_algo.h>
#include "attest_db.h"
#include "attest_usage.h"
+/**
+ * global debug output variables
+ */
+static int debug_level = 0;
+static bool stderr_quiet = TRUE;
+
+/**
+ * attest dbg function
+ */
+static void attest_dbg(debug_t group, level_t level, char *fmt, ...)
+{
+ int priority = LOG_INFO;
+ char buffer[8192];
+ char *current = buffer, *next;
+ va_list args;
+
+ if (level <= debug_level)
+ {
+ if (!stderr_quiet)
+ {
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+ }
+
+ /* write in memory buffer first */
+ va_start(args, fmt);
+ vsnprintf(buffer, sizeof(buffer), fmt, args);
+ va_end(args);
+
+ /* do a syslog with every line */
+ while (current)
+ {
+ next = strchr(current, '\n');
+ if (next)
+ {
+ *(next++) = '\0';
+ }
+ syslog(priority, "%s\n", current);
+ current = next;
+ }
+ }
+}
+
/**
* global attestation database object
*/
OP_UNDEF,
OP_USAGE,
OP_FILES,
+ OP_COMPONENTS,
OP_PRODUCTS,
OP_HASHES,
OP_ADD,
struct option long_opts[] = {
{ "help", no_argument, NULL, 'h' },
+ { "components", no_argument, NULL, 'c' },
{ "files", no_argument, NULL, 'f' },
{ "products", no_argument, NULL, 'p' },
{ "hashes", no_argument, NULL, 'H' },
case 'h':
op = OP_USAGE;
break;
+ case 'c':
+ op = OP_COMPONENTS;
+ continue;
case 'f':
op = OP_FILES;
continue;
case OP_PRODUCTS:
attest->list_products(attest);
break;
+ case OP_COMPONENTS:
+ attest->list_components(attest);
+ break;
case OP_FILES:
attest->list_files(attest);
break;
{
char *uri;
+ /* enable attest debugging hook */
+ dbg = attest_dbg;
+ openlog("attest", 0, LOG_DEBUG);
+
atexit(library_deinit);
/* initialize library */
exit(SS_RC_INITIALIZATION_FAILED);
}
atexit(cleanup);
+ libimcv_init();
+ libpts_init();
do_args(argc, argv);
+ libpts_deinit();
+ libimcv_deinit();
+ closelog();
+
exit(EXIT_SUCCESS);
}
#include "attest_db.h"
+#include "libpts.h"
+#include "pts/components/pts_comp_func_name.h"
+
typedef struct private_attest_db_t private_attest_db_t;
/**
this->algo = algo;
}
+METHOD(attest_db_t, list_components, void,
+ private_attest_db_t *this)
+{
+ enumerator_t *e;
+ enum_name_t *names, *types;
+ pts_comp_func_name_t *cfn;
+ int type, cid, vid, name, qualifier, count = 0;
+ char flags[8];
+
+ if (this->pid)
+ {
+ e = this->db->query(this->db,
+ "SELECT c.id, c.vendor_id, c.name, c.qualifier "
+ "FROM components AS c "
+ "JOIN product_component AS pc ON c.id = pc.component "
+ "WHERE pc.product = ? ORDER BY c.vendor_id, c.name, c.qualifier",
+ DB_INT, this->pid, DB_INT, DB_INT, DB_INT, DB_INT);
+ }
+ else
+ {
+ e = this->db->query(this->db,
+ "SELECT id, vendor_id, name, qualifier FROM components "
+ "ORDER BY vendor_id, name, qualifier",
+ DB_INT, DB_INT, DB_INT, DB_INT);
+ }
+ if (e)
+ {
+ while (e->enumerate(e, &cid, &vid, &name, &qualifier))
+ {
+ printf("%3d: 0x%06x/0x%08x-0x%02x", cid, vid, name, qualifier);
+
+ cfn = pts_comp_func_name_create(vid, name, qualifier);
+ names = pts_components->get_comp_func_names(pts_components, vid);
+ types = pts_components->get_qualifier_type_names(pts_components, vid);
+ type = pts_components->get_qualifier(pts_components, cfn, flags);
+ if (names && types)
+ {
+ printf(" %N '%N' [%s] '%N'", pen_names, vid, names, name, flags,
+ types, type);
+ }
+ printf("\n");
+ cfn->destroy(cfn);
+
+ count++;
+ }
+ e->destroy(e);
+
+ printf("%d component%s found", count, (count == 1) ? "" : "s");
+ if (this->product)
+ {
+ printf(" for product '%s'", this->product);
+ }
+ printf("\n");
+ }
+}
+
METHOD(attest_db_t, list_files, void,
private_attest_db_t *this)
{
{
while (e->enumerate(e, &pid, &product))
{
- printf("%3d: %s\n", pid, product);
+ printf("%3d: %s\n", pid, product);
count++;
}
e->destroy(e);
.set_algo = _set_algo,
.list_products = _list_products,
.list_files = _list_files,
+ .list_components = _list_components,
.list_hashes = _list_hashes,
.add = _add,
.delete = _delete,