sbkeysync: Add --verbose option and conditionally print debug output
Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
parent
d5ce9e3f36
commit
a151ffdb9d
1 changed files with 27 additions and 11 deletions
|
@ -125,6 +125,7 @@ struct sync_context {
|
||||||
struct key_database *db;
|
struct key_database *db;
|
||||||
struct key_database *dbx;
|
struct key_database *dbx;
|
||||||
struct keystore *keystore;
|
struct keystore *keystore;
|
||||||
|
bool verbose;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GUID_STRLEN (8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1)
|
#define GUID_STRLEN (8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1)
|
||||||
|
@ -341,7 +342,7 @@ static void print_key_database(struct key_database *kdb)
|
||||||
struct key *key;
|
struct key *key;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("kdb %s\n", kdb->name);
|
printf(" %s\n", kdb->name);
|
||||||
|
|
||||||
list_for_each(&kdb->keys, key, list) {
|
list_for_each(&kdb->keys, key, list) {
|
||||||
printf(" %d bytes: [ ", key->id_len);
|
printf(" %d bytes: [ ", key->id_len);
|
||||||
|
@ -351,11 +352,18 @@ static void print_key_database(struct key_database *kdb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
static int read_key_databases(struct sync_context *ctx)
|
||||||
{
|
{
|
||||||
struct efi_sigdb_desc *desc;
|
struct efi_sigdb_desc *desc;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int rc;
|
|
||||||
struct {
|
struct {
|
||||||
enum sigdb_type type;
|
enum sigdb_type type;
|
||||||
struct key_database **kdb;
|
struct key_database **kdb;
|
||||||
|
@ -374,10 +382,7 @@ static int read_key_databases(struct sync_context *ctx)
|
||||||
kdb->name = desc->name;
|
kdb->name = desc->name;
|
||||||
list_head_init(&kdb->keys);
|
list_head_init(&kdb->keys);
|
||||||
|
|
||||||
rc = read_efivars_key_database(ctx, databases[i].type, kdb);
|
read_efivars_key_database(ctx, databases[i].type, kdb);
|
||||||
|
|
||||||
if (!rc)
|
|
||||||
print_key_database(kdb);
|
|
||||||
|
|
||||||
*databases[i].kdb = kdb;
|
*databases[i].kdb = kdb;
|
||||||
}
|
}
|
||||||
|
@ -502,6 +507,8 @@ static void print_keystore(struct keystore *keystore)
|
||||||
{
|
{
|
||||||
struct keystore_entry *ke;
|
struct keystore_entry *ke;
|
||||||
|
|
||||||
|
printf("Filesystem keystore:\n");
|
||||||
|
|
||||||
list_for_each(&keystore->keys, ke, list)
|
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);
|
||||||
}
|
}
|
||||||
|
@ -510,6 +517,7 @@ static struct option options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
{ "efivars-path", required_argument, NULL, 'e' },
|
{ "efivars-path", required_argument, NULL, 'e' },
|
||||||
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
{ NULL, 0, NULL, 0 },
|
{ NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -520,7 +528,8 @@ static void usage(void)
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t--efivars-path <dir> Path to efivars mountpoint\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);
|
toolname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +546,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int idx, c;
|
int idx, c;
|
||||||
c = getopt_long(argc, argv, "e:hV", options, &idx);
|
c = getopt_long(argc, argv, "e:vhV", options, &idx);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -545,6 +554,9 @@ int main(int argc, char **argv)
|
||||||
case 'e':
|
case 'e':
|
||||||
ctx->efivars_dir = optarg;
|
ctx->efivars_dir = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
ctx->verbose = true;
|
||||||
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
version();
|
version();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -574,7 +586,11 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
read_key_databases(ctx);
|
read_key_databases(ctx);
|
||||||
read_keystore(ctx);
|
read_keystore(ctx);
|
||||||
|
|
||||||
|
if (ctx->verbose) {
|
||||||
|
print_key_databases(ctx);
|
||||||
print_keystore(ctx->keystore);
|
print_keystore(ctx->keystore);
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue