mirror of
git://git.gnupg.org/gnupg.git
synced 2025-06-13 18:21:03 +02:00
common: Remove simple password query error codes.
* common/simple-pwquery.h: Remove mapping function. Move all definitions of status codes... * common/simple-pwquery.c: ... here, and define them to meaningful gpg error values. * agent/preset-passphrase.c (preset_passphrase): Use error code as-is. (forget_passphrase): Likewise. * tools/symcryptrun.c (confucius_get_pass): Likewise. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
ed5c1b0b8a
commit
9e6503b7ce
@ -111,10 +111,6 @@ my_strusage (int level)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Include the implementation of map_spwq_error. */
|
|
||||||
MAP_SPWQ_ERROR_IMPL
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
preset_passphrase (const char *keygrip)
|
preset_passphrase (const char *keygrip)
|
||||||
{
|
{
|
||||||
@ -170,7 +166,7 @@ preset_passphrase (const char *keygrip)
|
|||||||
if (!opt_passphrase)
|
if (!opt_passphrase)
|
||||||
wipememory (passphrase, sizeof (passphrase));
|
wipememory (passphrase, sizeof (passphrase));
|
||||||
|
|
||||||
rc = map_spwq_error (simple_query (line));
|
rc = simple_query (line);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
log_error ("caching passphrase failed: %s\n", gpg_strerror (rc));
|
log_error ("caching passphrase failed: %s\n", gpg_strerror (rc));
|
||||||
@ -192,7 +188,7 @@ forget_passphrase (const char *keygrip)
|
|||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
rc = gpg_error_from_syserror ();
|
rc = gpg_error_from_syserror ();
|
||||||
else
|
else
|
||||||
rc = map_spwq_error (simple_query (line));
|
rc = simple_query (line);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
log_error ("clearing passphrase failed: %s\n", gpg_strerror (rc));
|
log_error ("clearing passphrase failed: %s\n", gpg_strerror (rc));
|
||||||
|
@ -50,6 +50,15 @@
|
|||||||
#define SIMPLE_PWQUERY_IMPLEMENTATION 1
|
#define SIMPLE_PWQUERY_IMPLEMENTATION 1
|
||||||
#include "simple-pwquery.h"
|
#include "simple-pwquery.h"
|
||||||
|
|
||||||
|
#define SPWQ_OUT_OF_CORE gpg_error_from_errno (ENOMEM)
|
||||||
|
#define SPWQ_IO_ERROR gpg_error_from_errno (EIO)
|
||||||
|
#define SPWQ_PROTOCOL_ERROR gpg_error (GPG_ERR_PROTOCOL_VIOLATION)
|
||||||
|
#define SPWQ_ERR_RESPONSE gpg_error (GPG_ERR_INV_RESPONSE)
|
||||||
|
#define SPWQ_NO_AGENT gpg_error (GPG_ERR_NO_AGENT)
|
||||||
|
#define SPWQ_SYS_ERROR gpg_error_from_syserror ()
|
||||||
|
#define SPWQ_GENERAL_ERROR gpg_error (GPG_ERR_GENERAL)
|
||||||
|
#define SPWQ_NO_PIN_ENTRY gpg_error (GPG_ERR_NO_PIN_ENTRY)
|
||||||
|
|
||||||
#ifndef _
|
#ifndef _
|
||||||
#define _(a) (a)
|
#define _(a) (a)
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,47 +67,4 @@ int simple_query (const char *query);
|
|||||||
to be called before any other function. Returns 0 on success. */
|
to be called before any other function. Returns 0 on success. */
|
||||||
int simple_pw_set_socket (const char *name);
|
int simple_pw_set_socket (const char *name);
|
||||||
|
|
||||||
#define SPWQ_OUT_OF_CORE 1
|
|
||||||
#define SPWQ_IO_ERROR 2
|
|
||||||
#define SPWQ_PROTOCOL_ERROR 3
|
|
||||||
#define SPWQ_ERR_RESPONSE 4
|
|
||||||
#define SPWQ_NO_AGENT 5
|
|
||||||
#define SPWQ_SYS_ERROR 6
|
|
||||||
#define SPWQ_GENERAL_ERROR 7
|
|
||||||
#define SPWQ_NO_PIN_ENTRY 8
|
|
||||||
|
|
||||||
|
|
||||||
/* We often need to map error codes to gpg-error style error codes.
|
|
||||||
To have a consistent mapping this macro may be used to implemt the
|
|
||||||
mapping function. */
|
|
||||||
#define MAP_SPWQ_ERROR_IMPL \
|
|
||||||
static gpg_error_t \
|
|
||||||
map_spwq_error (int err) \
|
|
||||||
{ \
|
|
||||||
switch (err) \
|
|
||||||
{ \
|
|
||||||
case 0: \
|
|
||||||
return 0; \
|
|
||||||
case SPWQ_OUT_OF_CORE: \
|
|
||||||
return gpg_error_from_errno (ENOMEM); \
|
|
||||||
case SPWQ_IO_ERROR: \
|
|
||||||
return gpg_error_from_errno (EIO); \
|
|
||||||
case SPWQ_PROTOCOL_ERROR: \
|
|
||||||
return gpg_error (GPG_ERR_PROTOCOL_VIOLATION); \
|
|
||||||
case SPWQ_ERR_RESPONSE: \
|
|
||||||
return gpg_error (GPG_ERR_INV_RESPONSE); \
|
|
||||||
case SPWQ_NO_AGENT: \
|
|
||||||
return gpg_error (GPG_ERR_NO_AGENT); \
|
|
||||||
case SPWQ_SYS_ERROR: \
|
|
||||||
return gpg_error_from_syserror (); \
|
|
||||||
case SPWQ_NO_PIN_ENTRY: \
|
|
||||||
return gpg_error (GPG_ERR_NO_PIN_ENTRY); \
|
|
||||||
case SPWQ_GENERAL_ERROR: \
|
|
||||||
default: \
|
|
||||||
return gpg_error (GPG_ERR_GENERAL); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
/* End of MAP_SPWQ_ERROR_IMPL. */
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*SIMPLE_PWQUERY_H*/
|
#endif /*SIMPLE_PWQUERY_H*/
|
||||||
|
@ -238,9 +238,6 @@ my_strusage (int level)
|
|||||||
__result; }))
|
__result; }))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Include the implementation of map_spwq_error. */
|
|
||||||
MAP_SPWQ_ERROR_IMPL
|
|
||||||
|
|
||||||
/* Unlink a file, and shred it if SHRED is true. */
|
/* Unlink a file, and shred it if SHRED is true. */
|
||||||
int
|
int
|
||||||
remove_file (char *name, int shred)
|
remove_file (char *name, int shred)
|
||||||
@ -441,7 +438,6 @@ confucius_get_pass (const char *cacheid, int again, int *canceled)
|
|||||||
pw = simple_pwquery (cacheid,
|
pw = simple_pwquery (cacheid,
|
||||||
again ? _("does not match - try again"):NULL,
|
again ? _("does not match - try again"):NULL,
|
||||||
_("Passphrase:"), NULL, 0, &err);
|
_("Passphrase:"), NULL, 0, &err);
|
||||||
err = map_spwq_error (err);
|
|
||||||
i18n_switchback (orig_codeset);
|
i18n_switchback (orig_codeset);
|
||||||
|
|
||||||
if (!pw)
|
if (!pw)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user