From e8b5115f1ad1cab25c105a94b96fed28cbfeceaa Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Mon, 23 Jan 2017 18:18:59 -0500 Subject: [PATCH] swtpm: Expose logging level to command line Expose the logging level to the command line by extending the log option with a level parameter. Extend the man swtpm man page with the level parameter. Signed-off-by: Stefan Berger --- man/man8/swtpm.8 | 11 +++++++---- man/man8/swtpm.pod | 5 ++++- src/swtpm/common.c | 6 ++++++ src/swtpm/swtpm.c | 3 ++- src/swtpm/swtpm_chardev.c | 3 ++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/man/man8/swtpm.8 b/man/man8/swtpm.8 index 0b6333d..b42ed8e 100644 --- a/man/man8/swtpm.8 +++ b/man/man8/swtpm.8 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) +.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "swtpm 8" -.TH swtpm 8 "2017-01-13" "swtpm" "" +.TH swtpm 8 "2017-01-23" "swtpm" "" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -278,10 +278,13 @@ The following options are support by all interfaces: .IP "\fB\-\-tpmstate dir=\fR" 4 .IX Item "--tpmstate dir=" Use the given path rather than using the environment variable \s-1TPM_PATH.\s0 -.IP "\fB\-\-log fd=|file=\fR" 4 -.IX Item "--log fd=|file=" +.IP "\fB\-\-log [fd=|file=\fR][,level=n]" 4 +.IX Item "--log [fd=|file=][,level=n]" Enable logging to a file given its file descriptor or its path. Use '\-' for path to suppress the logging. +.Sp +The level parameter allows to choose the level of logging. Starting at log +level 5, libtpms debug logging is activated. .IP "\fB\-\-key file=[,format=][,mode=aes\-cbc],[remove[=true|false]]\fR" 4 .IX Item "--key file=[,format=][,mode=aes-cbc],[remove[=true|false]]" Enable encryption of the state files of the \s-1TPM.\s0 The keyfile must contain diff --git a/man/man8/swtpm.pod b/man/man8/swtpm.pod index 5768e49..5af310f 100644 --- a/man/man8/swtpm.pod +++ b/man/man8/swtpm.pod @@ -184,11 +184,14 @@ The following options are support by all interfaces: Use the given path rather than using the environment variable TPM_PATH. -=item B<--log fd=EfdE|file=EpathE> +=item B<--log [fd=EfdE|file=EpathE>][,level=n] Enable logging to a file given its file descriptor or its path. Use '-' for path to suppress the logging. +The level parameter allows to choose the level of logging. Starting at log +level 5, libtpms debug logging is activated. + =item B<--key file=EkeyfileE[,format=Ehex|binaryE][,mode=aes-cbc],[remove[=true|false]]> Enable encryption of the state files of the TPM. The keyfile must contain diff --git a/src/swtpm/common.c b/src/swtpm/common.c index 019930e..da619cb 100644 --- a/src/swtpm/common.c +++ b/src/swtpm/common.c @@ -71,6 +71,9 @@ static const OptionDesc logging_opt_desc[] = { }, { .name = "fd", .type = OPT_TYPE_INT, + }, { + .name = "level", + .type = OPT_TYPE_UINT, }, END_OPTION_DESC }; @@ -176,6 +179,7 @@ handle_log_options(char *options) char *error = NULL; const char *logfile = NULL; int logfd; + unsigned int loglevel; OptionValues *ovs = NULL; if (!options) @@ -189,6 +193,7 @@ handle_log_options(char *options) } logfile = option_get_string(ovs, "file", NULL); logfd = option_get_int(ovs, "fd", -1); + loglevel = option_get_uint(ovs, "level", 0); if (logfile && (log_init(logfile) < 0)) { fprintf(stderr, "Could not open logfile for writing: %s\n", @@ -200,6 +205,7 @@ handle_log_options(char *options) logfd, strerror(errno)); goto error; } + log_set_level(loglevel); option_values_free(ovs); diff --git a/src/swtpm/swtpm.c b/src/swtpm/swtpm.c index 8bdb120..50a5ae5 100644 --- a/src/swtpm/swtpm.c +++ b/src/swtpm/swtpm.c @@ -104,9 +104,10 @@ static void usage(FILE *file, const char *prgname, const char *iface) " be given in case the type is TCP; the TCP socket is bound\n" " to 127.0.0.1 by default and other bind addresses can be\n" " given with the bindaddr parameter\n" - "--log file=|fd=\n" + "--log file=|fd=[,level=n]\n" " : write the TPM's log into the given file rather than\n" " to the console; provide '-' for path to avoid logging\n" + " log level 5 and higher will enable libtpms logging\n" "--key file=[,mode=aes-cbc][,format=hex|binary][,remove=[true|false]]\n" " : use an AES key for the encryption of the TPM's state\n" " files; use the given mode for the block encryption;\n" diff --git a/src/swtpm/swtpm_chardev.c b/src/swtpm/swtpm_chardev.c index 82c2353..779eca2 100644 --- a/src/swtpm/swtpm_chardev.c +++ b/src/swtpm/swtpm_chardev.c @@ -132,9 +132,10 @@ static void usage(FILE *file, const char *prgname, const char *iface) " be given in case the type is TCP; the TCP socket is bound\n" " to 127.0.0.1 by default and other bind addresses can be\n" " given with the bindaddr parameter\n" - "--log file=|fd=\n" + "--log file=|fd=[,level=n]\n" " : write the TPM's log into the given file rather than\n" " to the console; provide '-' for path to avoid logging\n" + " log level 5 and higher will enable libtpms logging\n" "--key file=[,mode=aes-cbc][,format=hex|binary][,remove=[true|false]]\n" " : use an AES key for the encryption of the TPM's state\n" " files; use the given mode for the block encryption;\n" -- 2.39.5