diff options
author | Jeremy Kerr <jeremy.kerr@canonical.com> | 2012-08-21 11:32:29 +0800 |
---|---|---|
committer | Jeremy Kerr <jeremy.kerr@canonical.com> | 2012-08-24 20:02:15 +0800 |
commit | a151ffdb9d085122e0e9a18e44f79f8587478346 (patch) | |
tree | 3729176ad760586e1db4093e2b8f6e4251e639cb | |
parent | d5ce9e3f366d7ff30d458a6625706220bcb589a1 (diff) | |
download | sbsigntools-a151ffdb9d085122e0e9a18e44f79f8587478346.tar.gz |
sbkeysync: Add --verbose option and conditionally print debug output
Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
-rw-r--r-- | src/sbkeysync.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/sbkeysync.c b/src/sbkeysync.c index 91b3ea9..b354739 100644 --- a/src/sbkeysync.c +++ b/src/sbkeysync.c @@ -125,6 +125,7 @@ struct sync_context { struct key_database *db; struct key_database *dbx; struct keystore *keystore; + bool verbose; }; #define GUID_STRLEN (8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1) @@ -341,21 +342,28 @@ static void print_key_database(struct key_database *kdb) struct key *key; int i; - printf("kdb %s\n", kdb->name); + printf(" %s\n", kdb->name); list_for_each(&kdb->keys, key, list) { - printf(" %d bytes: [ ", key->id_len); + printf(" %d bytes: [ ", key->id_len); for (i = 0; i < key->id_len; i++) printf("0x%02x ", key->id[i]); printf("]\n"); } } +static void print_key_databases(struct sync_context *ctx) +{ + printf("EFI key databases:\n"); + print_key_database(ctx->kek); + print_key_database(ctx->db); + print_key_database(ctx->dbx); +} + static int read_key_databases(struct sync_context *ctx) { struct efi_sigdb_desc *desc; unsigned int i; - int rc; struct { enum sigdb_type type; struct key_database **kdb; @@ -374,10 +382,7 @@ static int read_key_databases(struct sync_context *ctx) kdb->name = desc->name; list_head_init(&kdb->keys); - rc = read_efivars_key_database(ctx, databases[i].type, kdb); - - if (!rc) - print_key_database(kdb); + read_efivars_key_database(ctx, databases[i].type, kdb); *databases[i].kdb = kdb; } @@ -502,14 +507,17 @@ static void print_keystore(struct keystore *keystore) { struct keystore_entry *ke; + printf("Filesystem keystore:\n"); + list_for_each(&keystore->keys, ke, list) - printf(" %s [%zd bytes]\n", ke->name, ke->len); + printf(" %s [%zd bytes]\n", ke->name, ke->len); } static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { "efivars-path", required_argument, NULL, 'e' }, + { "verbose", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 }, }; @@ -520,7 +528,8 @@ static void usage(void) "\n" "Options:\n" "\t--efivars-path <dir> Path to efivars mountpoint\n" - " (or regular directory for testing)\n", + " (or regular directory for testing)\n" + "\t--verbose Print verbose progress information\n", toolname); } @@ -537,7 +546,7 @@ int main(int argc, char **argv) for (;;) { int idx, c; - c = getopt_long(argc, argv, "e:hV", options, &idx); + c = getopt_long(argc, argv, "e:vhV", options, &idx); if (c == -1) break; @@ -545,6 +554,9 @@ int main(int argc, char **argv) case 'e': ctx->efivars_dir = optarg; break; + case 'v': + ctx->verbose = true; + break; case 'V': version(); return EXIT_SUCCESS; @@ -574,7 +586,11 @@ int main(int argc, char **argv) read_key_databases(ctx); read_keystore(ctx); - print_keystore(ctx->keystore); + + if (ctx->verbose) { + print_key_databases(ctx); + print_keystore(ctx->keystore); + } return EXIT_SUCCESS; } |