From 0dcddc0e564e8e2e2310ca50b50fdbd8fe961a47 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 13 Aug 2016 21:22:29 -0400 Subject: [PATCH] pwmc: Fix passphrase file logic in inquire callback. --- src/pwmc.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/pwmc.c b/src/pwmc.c index 8cf4b18d..98ad6376 100644 --- a/src/pwmc.c +++ b/src/pwmc.c @@ -301,7 +301,7 @@ inquire_cb (void *user, const char *keyword, gpg_error_t rc, if (!strcmp (keyword, "PASSPHRASE")) is_password = 1; else if (!strcmp (keyword, "SIGN_PASSPHRASE")) - is_password = sign = 1; + sign = 1; else if (!strcmp (keyword, "NEW_PASSPHRASE")) is_newpassword = 1; #ifdef HAVE_LIBREADLINE @@ -335,7 +335,22 @@ inquire_cb (void *user, const char *keyword, gpg_error_t rc, is_keyparam = 1; } - if ((is_newpassword && new_keyfile) || (is_password && keyfile) + if ((is_password && !keyfile) || (is_newpassword && !new_keyfile) + || (sign && !sign_keyfile)) + { + char *tmp; + + rc = pwmd_password (pwm, keyword, &tmp, &inq->len); + if (rc && gpg_err_code (rc) != GPG_ERR_EOF) + return rc; + + pwmd_free (inq->line); + inq->line = tmp; + *data = inq->line; + *size = inq->len; + return gpg_error (GPG_ERR_EOF); + } + else if ((is_newpassword && new_keyfile) || (is_password && keyfile) || (sign && sign_keyfile)) { int fd; @@ -343,7 +358,7 @@ inquire_cb (void *user, const char *keyword, gpg_error_t rc, if (sign) fd = open (sign_keyfile, O_RDONLY); else - fd = open (is_password ? keyfile : new_keyfile, O_RDONLY); + fd = open (is_password || sign ? keyfile : new_keyfile, O_RDONLY); if (fd == -1) { @@ -367,21 +382,6 @@ inquire_cb (void *user, const char *keyword, gpg_error_t rc, sign ? sign_keyfile : is_newpassword ? new_keyfile : keyfile, keyword); } - else if ((is_password && !keyfile) || (is_newpassword && !new_keyfile) - || (sign && !sign_keyfile)) - { - char *tmp; - - rc = pwmd_password (pwm, keyword, &tmp, &inq->len); - if (rc && gpg_err_code (rc) != GPG_ERR_EOF) - return rc; - - pwmd_free (inq->line); - inq->line = tmp; - *data = inq->line; - *size = inq->len; - return gpg_error (GPG_ERR_EOF); - } #ifdef HAVE_LIBREADLINE else if ((!inq->last_keyword || strcmp (keyword, inq->last_keyword)) && interactive) @@ -413,7 +413,7 @@ inquire_cb (void *user, const char *keyword, gpg_error_t rc, else if (*size) *data = inq->line; else if (inq->fd != STDIN_FILENO && - (is_newpassword || is_password || is_keyparam)) + (is_newpassword || is_password || sign || is_keyparam)) { *inq->line = 0; inq->size = 1; -- 2.11.4.GIT