From 4bebd650e43e9b3f30d6f51c4fc5a49882bb2d72 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Tue, 14 Aug 2007 18:41:37 -0400 Subject: [PATCH] Use the new EXISTS protocol command to determine whether a file is new or not. --- libpwmd.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libpwmd.c b/libpwmd.c index 0ab08d6b..f6659cfa 100644 --- a/libpwmd.c +++ b/libpwmd.c @@ -677,9 +677,19 @@ static int do_pwmd_open(pwm_t *pwm, gpg_error_t *error, const char *filename, #endif /* - * Avoid calling pinentry if the password is cached on the server. + * Avoid calling pinentry if the password is cached on the server or if + * this is a new file. */ - *error = pwmd_command(pwm, &result, "ISCACHED %s", filename); + *error = pwmd_command(pwm, &result, "EXISTS %s", filename); + + if (!*error) + *error = pwmd_command(pwm, &result, "ISCACHED %s", filename); + else { + if (gpg_err_code(*error) != gpg_err_code_from_errno(ENOENT)) + return nb ? -1 : 1; + + goto gotpassword; + } if (*error == EPWMD_CACHE_NOT_FOUND) { if (pwm->passfunc) { @@ -813,8 +823,8 @@ getpin_again: #endif } } - else if (*error && *error != EPWMD_FILE_NOT_FOUND) - return 1; + else if (*error) + return nb ? -1 : 1; gotpassword: *error = do_open_command(pwm, filename, password); @@ -832,7 +842,7 @@ gotpassword: goto getpin_again; pinentry_disconnect(pwm); - return 1; + return nb ? -1 : 1; } #endif @@ -952,7 +962,7 @@ static int do_pwmd_save(pwm_t *pwm, gpg_error_t *error, int nb) if (!pwm) { *error = GPG_ERR_INV_ARG; - return 1; + return nb ? -1 : 1; } if (pwm->use_pinentry || pwm->passfunc) { @@ -1041,8 +1051,8 @@ static int do_pwmd_save(pwm_t *pwm, gpg_error_t *error, int nb) } } else { - if (*error && *error != EPWMD_FILE_NOT_FOUND) - return 1; + if (*error) + return nb ? -1 : 1; } } else -- 2.11.4.GIT