From 1f9978f2f892caf2bb73cdf491129558b42687dc Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Thu, 22 Nov 2007 20:45:58 -0500 Subject: [PATCH] Added support for showing status messages sent from the server to pwmc. This adds command line option -X to suppress these messages which are normally printed to stderr. --- pwmc.1.in | 8 ++++++-- pwmc.c | 25 ++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pwmc.1.in b/pwmc.1.in index 17f5cd82..ff65174b 100644 --- a/pwmc.1.in +++ b/pwmc.1.in @@ -15,13 +15,13 @@ \\$2 \(laURL: \\$1 \(ra\\$3 .. .if \n[.g] .mso www.tmac -.TH PWMD 1 "3 Sep 2007" "Password Manager Client" "Password Manager Client" +.TH PWMD 1 "22 Nov 2007" "Password Manager Client" "Password Manager Client" .SH NAME pwmc \- send commands to pwmd .SH SYNOPSIS .B pwmc -[\-hv] [\-E] [\-s ] [\-a [\-P ] [\-D ] [\-T +[\-hvX] [\-E] [\-s ] [\-a [\-P ] [\-D ] [\-T ] [\-N ] [\-t ] | \-p ] [\-S] [\-d ] [filename] @@ -38,6 +38,10 @@ with the 'base64 -A' switch. .SH OPTIONS .TP +.I "\-X" +Disable showing of status messages from the server. By default they are +printed to stderr. +.TP .I "\-E" Exit after a command failure. .TP diff --git a/pwmc.c b/pwmc.c index c672915e..7cca93ff 100644 --- a/pwmc.c +++ b/pwmc.c @@ -81,8 +81,9 @@ static void usage(const char *pn) { fprintf(stderr, N_( "Reads PWMD protocol commands from standard input.\n\n" - "Usage: pwmc [-hv] [-E] [-s ] [[-a [-P -T -N -D] [-t ]] |\n" + "Usage: pwmc [-hvX] [-E] [-s ] [[-a [-P -T -N -D] [-t ]] |\n" " [-p ]] [-S] [-d ] [filename]\n" + " -X disable showing of status messages from the server\n" " -E exit after a command failure\n" " -s socket path\n" " -p password\n" @@ -99,7 +100,7 @@ static void usage(const char *pn) exit(EXIT_FAILURE); } -int set_pinentry_option(pwmd_option_t option, char *value) +int set_pinentry_option(pwmd_option_t option, void *value) { gpg_error_t error; @@ -114,6 +115,12 @@ int set_pinentry_option(pwmd_option_t option, char *value) return 0; } +static int status_msg_cb(void *data, const char *line) +{ + fprintf(stderr, "%s\n", line); + return 0; +} + int main(int argc, char *argv[]) { int opt; @@ -134,13 +141,17 @@ int main(int argc, char *argv[]) struct termios term; int outfd = STDOUT_FILENO; FILE *outfp = stdout; + int show_status = 1; setlocale(LC_ALL, ""); bindtextdomain("libpwmd", LOCALEDIR); timeout = -1; - while ((opt = getopt(argc, argv, "T:N:D:EhvaP:t:p:s:Sd:")) != EOF) { + while ((opt = getopt(argc, argv, "XT:N:D:EhvaP:t:p:s:Sd:")) != EOF) { switch (opt) { + case 'X': + show_status = 0; + break; case 'T': tty = optarg; break; @@ -246,6 +257,14 @@ int main(int argc, char *argv[]) } } + if (show_status) { + if (set_pinentry_option(PWMD_OPTION_STATUS_FUNC, status_msg_cb)) { + show_error(error); + pwmd_close(pwm); + exit(EXIT_FAILURE); + } + } + if (filename) { if (use_pinentry && timeout != -1) { tcgetattr(STDOUT_FILENO, &term); -- 2.11.4.GIT