aboutsummaryrefslogtreecommitdiffstats
path: root/src/libimcv/plugins/imv_attestation/attest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libimcv/plugins/imv_attestation/attest.c')
-rw-r--r--src/libimcv/plugins/imv_attestation/attest.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/libimcv/plugins/imv_attestation/attest.c b/src/libimcv/plugins/imv_attestation/attest.c
index 30563364c..aa8d1f797 100644
--- a/src/libimcv/plugins/imv_attestation/attest.c
+++ b/src/libimcv/plugins/imv_attestation/attest.c
@@ -19,15 +19,64 @@
#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
*/
attest_db_t *attest;
@@ -46,6 +95,7 @@ static void do_args(int argc, char *argv[])
OP_UNDEF,
OP_USAGE,
OP_FILES,
+ OP_COMPONENTS,
OP_PRODUCTS,
OP_HASHES,
OP_ADD,
@@ -61,6 +111,7 @@ static void do_args(int argc, char *argv[])
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' },
@@ -93,6 +144,9 @@ static void do_args(int argc, char *argv[])
case 'h':
op = OP_USAGE;
break;
+ case 'c':
+ op = OP_COMPONENTS;
+ continue;
case 'f':
op = OP_FILES;
continue;
@@ -180,6 +234,9 @@ static void do_args(int argc, char *argv[])
case OP_PRODUCTS:
attest->list_products(attest);
break;
+ case OP_COMPONENTS:
+ attest->list_components(attest);
+ break;
case OP_FILES:
attest->list_files(attest);
break;
@@ -205,6 +262,10 @@ int main(int argc, char *argv[])
{
char *uri;
+ /* enable attest debugging hook */
+ dbg = attest_dbg;
+ openlog("attest", 0, LOG_DEBUG);
+
atexit(library_deinit);
/* initialize library */
@@ -230,9 +291,15 @@ int main(int argc, char *argv[])
exit(SS_RC_INITIALIZATION_FAILED);
}
atexit(cleanup);
+ libimcv_init();
+ libpts_init();
do_args(argc, argv);
+ libpts_deinit();
+ libimcv_deinit();
+ closelog();
+
exit(EXIT_SUCCESS);
}