[PATCH 3/4] pinentry-tty: make confirm actions work

Daniel Kahn Gillmor dkg at fifthhorseman.net
Tue Apr 28 19:01:15 CEST 2015


* tty/pinentry-tty.c: treat the situation where no PIN is requested
  and one_button is not set as a confirmation prompt.

--

When user confirmation is requested on a dumb terminal, we use the
value of the "OK" button followed with [y/N]? as the confirmation
prompt.  User typing is echoed as normal, since a confirmation prompt
is not a password entry.
---
 tty/pinentry-tty.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/tty/pinentry-tty.c b/tty/pinentry-tty.c
index e2e0871..bd58ae0 100644
--- a/tty/pinentry-tty.c
+++ b/tty/pinentry-tty.c
@@ -59,6 +59,24 @@ cbreak (int fd)
 }
 
 static int
+confirm (pinentry_t pinentry, FILE *ttyfi, FILE *ttyfo)
+{
+  char buf[32], *ret;
+  pinentry->canceled = 1;
+  fprintf (ttyfo, "%s [y/N]? ", pinentry->ok ? pinentry->ok : "OK");
+  fflush (ttyfo);
+  buf[0] = '\0';
+  ret = fgets (buf, sizeof(buf), ttyfi);
+  if (ret && (buf[0] == 'y' || buf[0] == 'Y'))
+    {
+      pinentry->canceled = 0;
+      return 1;
+    }
+  return 0;
+}
+  
+
+static int
 read_password (pinentry_t pinentry, FILE *ttyfi, FILE *ttyfo)
 {
   int count;
@@ -170,11 +188,13 @@ tty_cmd_handler(pinentry_t pinentry)
     {
       if (pinentry->pin)
         rc = read_password (pinentry, ttyfi, ttyfo);
-      else 
+      else
         {
           fprintf (ttyfo, "%s\n",
                    pinentry->description? pinentry->description:"");
           fflush (ttyfo);
+          if (! pinentry->one_button)
+            rc = confirm (pinentry, ttyfi, ttyfo);
         }
       do_touch_file (pinentry);
     }
-- 
2.1.4




More information about the Gnupg-devel mailing list