[PINENTRY PATCH 2/8] gnome3: Propagate GError messages to pinentry.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Fri Nov 4 23:57:46 CET 2016
* gnome3/pinentry-gnome3.c (_propagate_g_error_to_pinentry): New. Send
GError messages back out to pinentry error reporting.
(create_prompt): Use _propagate_g_error_to_pinentry on error.
(gnome3_cmd_handler): Use _propagate_g_error_to_pinentry on error.
Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
---
gnome3/pinentry-gnome3.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/gnome3/pinentry-gnome3.c b/gnome3/pinentry-gnome3.c
index 1205300..40be2a4 100644
--- a/gnome3/pinentry-gnome3.c
+++ b/gnome3/pinentry-gnome3.c
@@ -69,6 +69,17 @@ pinentry_utf8_validate (gchar *text)
return result;
}
+static void
+_propagate_g_error_to_pinentry (pinentry_t pe, GError *error, gpg_err_code_t code, const char *loc)
+{
+ size_t infolen = strlen(error->message) + 20;
+ pe->specific_err = gpg_error (code);
+ pe->specific_err_info = malloc (infolen);
+ pe->specific_err_info[infolen-1] = '\0';
+ snprintf (pe->specific_err_info, infolen, "%d: %s", error->code, error->message);
+ pe->specific_err_loc = loc;
+}
+
static GcrPrompt *
create_prompt (pinentry_t pe, int confirm)
{
@@ -81,11 +92,8 @@ create_prompt (pinentry_t pe, int confirm)
prompt = GCR_PROMPT (gcr_system_prompt_open (-1, NULL, &error));
if (! prompt)
{
- fprintf (stderr, "couldn't create prompt for gnupg passphrase: %s\n",
- error->message);
- pe->specific_err_loc = "gcr_prompt";
- pe->specific_err_info = strdup (error->message);
- pe->specific_err = gpg_error (GPG_ERR_CONFIGURATION);
+ _propagate_g_error_to_pinentry (pe, error, GPG_ERR_CONFIGURATION,
+ "gcr_system_prompt_open");
g_error_free (error);
return NULL;
}
@@ -196,7 +204,8 @@ gnome3_cmd_handler (pinentry_t pe)
if (error)
/* Error. */
{
- pe->specific_err = gpg_error (GPG_ERR_ASS_GENERAL);
+ _propagate_g_error_to_pinentry (state->pinentry, error, GPG_ERR_PIN_ENTRY,
+ "gcr_system_password_finish");
g_error_free (error);
ret = -1;
}
@@ -238,7 +247,8 @@ gnome3_cmd_handler (pinentry_t pe)
reply = gcr_prompt_confirm_run (prompt, NULL, &error);
if (error)
{
- pe->specific_err = gpg_error (GPG_ERR_ASS_GENERAL);
+ _propagate_g_error_to_pinentry (state->pinentry, error, GPG_ERR_PIN_ENTRY,
+ "gcr_system_confirm_finish");
ret = 0;
}
else if (reply == GCR_PROMPT_REPLY_CONTINUE
--
2.10.1
More information about the Gnupg-devel
mailing list