Skip to content

Commit

Permalink
secvarctl: display enabled backends in --help, allow empty -m to quer…
Browse files Browse the repository at this point in the history
…y enabled backends

Currently, there is no way to know which backends are enabled in a given
binary. Therefore, add the enabled backends to the --help output, as
well as display the enabled backends if -m is called without any
following argument.

This also fixes a bug where argv was checked for NULL instead of *argv,
which could have led to a segmentation fault.

Signed-off-by: Eric Richter <[email protected]>
  • Loading branch information
erichte-ibm committed Sep 7, 2023
1 parent c27febe commit bf0ddb9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions secvarctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ void version()
printf("secvarctl v%s\n", secvarctl_version);
}

void enabled_backends()
{
printf("Enabled backends:\n");
for (enum backends back = 0; back < BACKEND_UNKNOWN; back++) {
printf(" - %s\n", backends[back].format);
}
}

void usage()
{
version();
Expand All @@ -86,7 +94,8 @@ void usage()
"management,\n\t\t\t"
"use 'secvarctl [MODE] generate --usage/help' for more information\n"
#endif
);
"\n");
enabled_backends();
}

void help()
Expand Down Expand Up @@ -195,9 +204,9 @@ int main(int argc, char *argv[])
} else if (!strcmp("-m", *argv) || !strcmp("--mode", *argv)) {
argv++;
argc--;
if (argv == NULL) {
prlog(PR_WARNING, "No mode name supplied\n");
return UNKNOWN_COMMAND;
if (*argv == NULL) {
enabled_backends();
return SUCCESS;
}
for (i = 0; i < sizeof(backend_names) / sizeof(backend_names[0]); i++) {
if (!strcmp(*argv, backend_names[i].name)) {
Expand Down

0 comments on commit bf0ddb9

Please sign in to comment.