[PINENTRY PATCH v2 2/2] pinentry-gnome3: fall back to curses if gcr prompt creation fails

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Sep 9 10:43:46 CEST 2016


* gnome3/pinentry-gnome3.c (create_prompt): if gcr_prompt_prompt_open
  fails, fall back to using curses for this phase.
  (gnome3_cmd_handler): pass through responses from curses, if used.

In some cases, the user is running in a session that has an active
D-Bus session, but that session is not attached to a graphical desktop
environment (e.g. sshing into a machine whose login stack initializes
a D-Bus session).  In that case, gcr can be reached over dbus, but it
will complain that it does not know how to prompt the user.

In this case, pinentry-gnome3 should fall back to curses for prompting
the user.

Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
---
 gnome3/pinentry-gnome3.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/gnome3/pinentry-gnome3.c b/gnome3/pinentry-gnome3.c
index 95449da..3aabb91 100644
--- a/gnome3/pinentry-gnome3.c
+++ b/gnome3/pinentry-gnome3.c
@@ -69,12 +69,20 @@ pinentry_utf8_validate (gchar *text)
   return result;
 }
 
+struct curses_ret
+{
+  int curses_used;
+  int curses_returned;
+};
+
 static GcrPrompt *
-create_prompt (pinentry_t pe, int confirm)
+create_prompt (pinentry_t pe, int confirm, struct curses_ret *c)
 {
   GcrPrompt *prompt;
   GError *error = NULL;
   char *msg;
+  if (c)
+    c->curses_used = 0;
 
   /* Create the prompt.  */
   prompt = GCR_PROMPT (gcr_system_prompt_open (-1, NULL, &error));
@@ -83,6 +91,10 @@ create_prompt (pinentry_t pe, int confirm)
       fprintf (stderr, "couldn't create prompt for gnupg passphrase: %s",
 		 error->message);
       g_error_free (error);
+      if (c) {
+        c->curses_used = 1;
+        c->curses_returned = curses_cmd_handler (pe);
+      }
       return NULL;
     }
 
@@ -169,16 +181,20 @@ gnome3_cmd_handler (pinentry_t pe)
   GcrPrompt *prompt = NULL;
   GError *error = NULL;
   int ret = -1;
+  struct curses_ret c;
+  c.curses_used = 0;
 
   if (pe->pin)
     /* Passphrase mode.  */
     {
       const char *password;
 
-      prompt = create_prompt (pe, 0);
+      prompt = create_prompt (pe, 0, &c);
       if (! prompt)
 	/* Something went wrong.  */
 	{
+          if (c.curses_used)
+            return c.curses_returned;
 	  pe->canceled = 1;
 	  return -1;
 	}
@@ -218,10 +234,12 @@ gnome3_cmd_handler (pinentry_t pe)
     {
       GcrPromptReply reply;
 
-      prompt = create_prompt (pe, 1);
+      prompt = create_prompt (pe, 1, &c);
       if (! prompt)
 	/* Something went wrong.  */
 	{
+          if (c.curses_used)
+            return c.curses_returned;
 	  pe->canceled = 1;
 	  return -1;
 	}
-- 
2.9.3




More information about the Gnupg-devel mailing list