From d41d4aed5462cc39f58348fb72b01b210c586515 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 26 Nov 2007 18:37:40 -0500 Subject: [PATCH] Added pwmc command line option -I to read inquire data from the specified file descriptor. This can save alot of memory for large inquires that previously used a pipe. --- po/libpwmd.pot | 22 +++++++++++----------- pwmc.c | 26 ++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/po/libpwmd.pot b/po/libpwmd.pot index d3b5116f..22514c53 100644 --- a/po/libpwmd.pot +++ b/po/libpwmd.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bjk@luxsci.net\n" -"POT-Creation-Date: 2007-11-22 21:07-0500\n" +"POT-Creation-Date: 2007-11-26 18:36-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -40,23 +40,23 @@ msgstr "" msgid "File modified" msgstr "" -#: libpwmd.c:308 +#: libpwmd.c:344 msgid "LibPWMD" msgstr "" -#: libpwmd.c:311 +#: libpwmd.c:347 msgid "Password:" msgstr "" -#: libpwmd.c:314 +#: libpwmd.c:350 msgid "Enter a password." msgstr "" -#: libpwmd.c:317 +#: libpwmd.c:353 msgid "Invalid password, please try again." msgstr "" -#: libpwmd.c:321 +#: libpwmd.c:357 msgid "Please type the password again for confirmation." msgstr "" @@ -69,10 +69,9 @@ msgstr "" msgid "" "Reads PWMD protocol commands from standard input.\n" "\n" -"Usage: pwmc [-hvX] [-E] [-s ] [[-a [-P -T -N -D] [-t ]] |\n" -" [-p ]] [-S] [-d ] [filename]\n" +"Usage: pwmc [-hvX] [-s ] [[-a [-P -T -N -D] [-t ]] |\n" +" [-p ]] [-S] [-d ] [-I ] [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" " -a use pinentry(1) for password retrieval\n" @@ -82,16 +81,17 @@ msgid "" " -D pinentry display\n" " -t pinentry timeout\n" " -d redirect command output to the specified file descriptor\n" +" -I read inquire data from the specified file descriptor\n" " -S send the SAVE command after all others\n" " -v version\n" " -h this help text\n" msgstr "" -#: pwmc.c:235 +#: pwmc.c:295 msgid "Password Manager Daemon" msgstr "" -#: pwmc.c:238 +#: pwmc.c:298 #, c-format msgid "" "A password is required for the file \"%s\". Please\n" diff --git a/pwmc.c b/pwmc.c index f6e9298a..22d04c3b 100644 --- a/pwmc.c +++ b/pwmc.c @@ -82,7 +82,7 @@ static void usage(const char *pn) fprintf(stderr, N_( "Reads PWMD protocol commands from standard input.\n\n" "Usage: pwmc [-hvX] [-s ] [[-a [-P -T -N -D] [-t ]] |\n" - " [-p ]] [-S] [-d ] [filename]\n" + " [-p ]] [-S] [-d ] [-I ] [filename]\n" " -X disable showing of status messages from the server\n" " -s socket path\n" " -p password\n" @@ -93,6 +93,7 @@ static void usage(const char *pn) " -D pinentry display\n" " -t pinentry timeout\n" " -d redirect command output to the specified file descriptor\n" + " -I read inquire data from the specified file descriptor\n" " -S send the SAVE command after all others\n" " -v version\n" " -h this help text\n"), PINENTRY_PATH); @@ -115,6 +116,7 @@ int set_pinentry_option(pwmd_option_t option, void *value) } struct inquire_s { + FILE *fp; char *data; }; @@ -143,7 +145,7 @@ static int do_inquire(void *data, const char *keyword, gpg_error_t rc, goto done; } - while ((c = fgetc(stdin)) != EOF) { + while ((c = fgetc(inq->fp)) != EOF) { if (len >= sizeof(buf)) { ungetc(c, stdin); break; @@ -187,13 +189,15 @@ int main(int argc, char *argv[]) struct termios term; int outfd = STDOUT_FILENO; FILE *outfp = stdout; + int inquirefd = STDIN_FILENO; + FILE *inquirefp = stdin; int show_status = 1; setlocale(LC_ALL, ""); bindtextdomain("libpwmd", LOCALEDIR); timeout = -1; - while ((opt = getopt(argc, argv, "XT:N:D:hvaP:t:p:s:Sd:")) != EOF) { + while ((opt = getopt(argc, argv, "I:XT:N:D:hvaP:t:p:s:Sd:")) != EOF) { switch (opt) { case 'X': show_status = 0; @@ -207,12 +211,23 @@ int main(int argc, char *argv[]) case 'D': display = optarg; break; + case 'I': + inquirefd = atoi(optarg); + inquirefp = fdopen(inquirefd, "r"); + + if (!inquirefp) { + xfree(password); + err(EXIT_FAILURE, "%i", inquirefd); + } + break; case 'd': outfd = atoi(optarg); outfp = fdopen(outfd, "w"); - if (!outfp) + if (!outfp) { + xfree(password); err(EXIT_FAILURE, "%i", outfd); + } break; case 'S': save = 1; @@ -233,10 +248,12 @@ int main(int argc, char *argv[]) timeout = atoi(optarg); break; case 'v': + xfree(password); printf("%s (pwmc)\n%s\n", PACKAGE_STRING, PACKAGE_BUGREPORT); exit(EXIT_SUCCESS); case 'h': default: + xfree(password); usage(argv[0]); } } @@ -347,6 +364,7 @@ int main(int argc, char *argv[]) struct inquire_s *inq = malloc(sizeof(struct inquire_s)); inq->data = xstrdup(p+6); + inq->fp = inquirefp; if (set_pinentry_option(PWMD_OPTION_INQUIRE_DATA, inq)) { xfree(inq->data); -- 2.11.4.GIT