From 57e53b78ea8dcb123ec37b4dbe8afac351c1d711 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 4 Dec 2015 07:31:55 -0500 Subject: [PATCH] swtpm: Add option to only display version info Signed-off-by: Stefan Berger --- src/swtpm_bios/tpm_bios.c | 19 +++++++++++++++---- src/swtpm_cert/ek-cert.c | 19 +++++++++++++++---- src/swtpm_ioctl/tpm_ioctl.c | 21 +++++++++++++++++++-- src/swtpm_setup/swtpm_setup.c | 2 ++ src/swtpm_setup/swtpm_setup.sh.in | 12 +++++++++++- 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/swtpm_bios/tpm_bios.c b/src/swtpm_bios/tpm_bios.c index f48f8a3..9c17717 100644 --- a/src/swtpm_bios/tpm_bios.c +++ b/src/swtpm_bios/tpm_bios.c @@ -205,10 +205,17 @@ static int TPM_ContinueSelfTest(int *tpm_errcode) return talk(tpm_cst, sizeof(tpm_cst), tpm_errcode); } +static void versioninfo(void) +{ + printf( +"TPM emulator BIOS emulator version %d.%d.%d, Copyright (c) 2015 IBM Corp.\n" +,SWTPM_VER_MAJOR, SWTPM_VER_MINOR, SWTPM_VER_MICRO); +} + static void print_usage(const char *prgname) { + versioninfo(); printf( -"TPM emulator BIOS emulator version %d.%d.%d, Copyright (c) 2015 IBM Corp.\n" "\n" "%s [options]\n" "\n" @@ -220,9 +227,10 @@ static void print_usage(const char *prgname) "\t-d startup deactivate\n" "\t-n no startup\n" "\t-o startup only\n" -"\t-cs run TPM_ContinueSelfTest\n", -SWTPM_VER_MAJOR, SWTPM_VER_MINOR, SWTPM_VER_MICRO, prgname); - return; +"\t-cs run TPM_ContinueSelfTest\n" +"\t-v display version and exit\n" +"\t-h display this help screen and exit\n" +, prgname); } int main(int argc, char *argv[]) @@ -246,6 +254,9 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[i],"-h") == 0) { print_usage(argv[0]); exit(EXIT_SUCCESS); + } else if (strcmp(argv[i],"-v") == 0) { + versioninfo(); + exit(EXIT_SUCCESS); } else if (strcmp(argv[i],"-n") == 0) { startupparm = 0xff; do_more = 1; diff --git a/src/swtpm_cert/ek-cert.c b/src/swtpm_cert/ek-cert.c index 11f1a71..b401667 100644 --- a/src/swtpm_cert/ek-cert.c +++ b/src/swtpm_cert/ek-cert.c @@ -68,12 +68,19 @@ extern const ASN1_ARRAY_TYPE tpm_asn1_tab[]; ASN1_TYPE _tpm_asn; static void -usage(const char *prg) +versioninfo(const char *prg) { fprintf(stdout, "TPM certificate tool version %d.%d.%d, Copyright (c) 2015 IBM Corp.\n" - "\n" - "Usage: %s [options]\n" + ,SWTPM_VER_MAJOR, SWTPM_VER_MINOR, SWTPM_VER_MICRO); +} + +static void +usage(const char *prg) +{ + versioninfo(prg); + fprintf(stdout, + "\nUsage: %s [options]\n" "\n" "Create TPM certificates without requiring the EK private key.\n" "\n" @@ -97,9 +104,10 @@ usage(const char *prg) "--platform-version : The Platform version (firmware version)\n" "--subject : Subject such as location in format\n" " C=US,ST=NY,L=NewYork\n" + "--version : Display version and exit\n" "--help : Display this help screen and exit\n" "\n", - SWTPM_VER_MAJOR, SWTPM_VER_MINOR, SWTPM_VER_MICRO, prg); + prg); } static char @@ -583,6 +591,9 @@ main(int argc, char *argv[]) platf_version = argv[i]; } else if (!strcmp(argv[i], "--pem")) { write_pem = true; + } else if (!strcmp(argv[i], "--version")) { + versioninfo(argv[0]); + exit(0); } else if (!strcmp(argv[i], "--help")) { usage(argv[0]); exit(0); diff --git a/src/swtpm_ioctl/tpm_ioctl.c b/src/swtpm_ioctl/tpm_ioctl.c index e1b39d1..0302841 100644 --- a/src/swtpm_ioctl/tpm_ioctl.c +++ b/src/swtpm_ioctl/tpm_ioctl.c @@ -447,10 +447,17 @@ static int do_load_state_blob(int fd, const char *blobtype, return 0; } -static void usage(const char *prgname) +static void versioninfo(const char *prgname) { fprintf(stdout, "TPM emulator control tool version %d.%d.%d, Copyright (c) 2015 IBM Corp.\n" +,SWTPM_VER_MAJOR, SWTPM_VER_MINOR, SWTPM_VER_MICRO); +} + +static void usage(const char *prgname) +{ + versioninfo(prgname); + fprintf(stdout, "\n" "Usage: %s command \n" "\n" @@ -472,8 +479,10 @@ static void usage(const char *prgname) "--load : load the TPM state blob of given type from a file;\n" " type may be one of volatile, permanent, or savestate\n" "-g : get configuration flags indicating which keys are in use\n" +"--version: display version and exit\n" +"-h|--help: display help screen and exit\n" "\n" -,SWTPM_VER_MAJOR, SWTPM_VER_MINOR, SWTPM_VER_MICRO, prgname); +, prgname); } int main(int argc, char *argv[]) @@ -496,6 +505,14 @@ int main(int argc, char *argv[]) return 1; } + if (!strcmp(argv[1], "--version")) { + versioninfo(argv[0]); + exit(0); + } else if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) { + usage(argv[0]); + exit(0); + } + if (!strcmp(argv[1], "--save") || !strcmp(argv[1], "--load")) { devindex = 4; diff --git a/src/swtpm_setup/swtpm_setup.c b/src/swtpm_setup/swtpm_setup.c index e0370b1..ae723fb 100755 --- a/src/swtpm_setup/swtpm_setup.c +++ b/src/swtpm_setup/swtpm_setup.c @@ -88,6 +88,8 @@ int main(int argc, char *argv[]) userid = argv[i]; } else if (!strcmp("--help", argv[i]) || !strcmp("-h", argv[i])) { show_help = true; + } else if (!strcmp("--version", argv[i])) { + show_help = true; } for (j = 0; one_arg_params[j] != NULL; j++) { if (!strcmp(one_arg_params[j], argv[i])) { diff --git a/src/swtpm_setup/swtpm_setup.sh.in b/src/swtpm_setup/swtpm_setup.sh.in index 371619f..e821482 100755 --- a/src/swtpm_setup/swtpm_setup.sh.in +++ b/src/swtpm_setup/swtpm_setup.sh.in @@ -589,10 +589,17 @@ init_tpm() return 0 } -usage() +versioninfo() { cat <'. +--verion : Display version and exit + --help,-h,-? : Display this help screen EOF } @@ -686,6 +695,7 @@ main() --pwdfile) shift; pwdfile="$1";; --runas) shift;; # ignore here --logfile) shift; LOGFILE="$1";; + --version) versioninfo $0; exit 0;; --help|-h|-?) usage $0; exit 0;; *) logerr "Unknown option $1"; usage $0; exit 1;; esac -- 2.39.5