[PATCH pinentry 1/4] curses: Disable echoing if backspace is pressed first.

Damien Goutte-Gattat dgouttegattat at incenp.org
Sat Aug 4 23:24:08 CEST 2018


* pinentry/pinentry-curses.c (struct dialog): New fields got_input,
no_echo.
(dialog_input): Disable echoing and display instead "[no echo]" if
the backspace key is pressed first.

GnuPG-bug-id: 3428
Signed-off-by: Damien Goutte-Gattat <dgouttegattat at incenp.org>
---
 pinentry/pinentry-curses.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/pinentry/pinentry-curses.c b/pinentry/pinentry-curses.c
index 89bb5b6..cfc1abd 100644
--- a/pinentry/pinentry-curses.c
+++ b/pinentry/pinentry-curses.c
@@ -94,6 +94,8 @@ struct dialog
   int pin_max;
   /* Length of PIN.  */
   int pin_len;
+  int got_input;
+  int no_echo;
 
   int ok_y;
   int ok_x;
@@ -596,6 +598,9 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
       addstr (dialog->ok);
     }
 
+  dialog->got_input = 0;
+  dialog->no_echo = 0;
+
  out:
   if (description)
     free (description);
@@ -730,6 +735,12 @@ dialog_input (dialog_t diag, int alt, int chr)
 		diag->pin_loc = diag->pin_len;
 	    }
 	}
+      else if (!diag->got_input)
+	{
+	  diag->no_echo = 1;
+	  move (diag->pin_y, diag->pin_x);
+	  addstr ("[no echo]");
+	}
       break;
 
     case 'l' - 'a' + 1: /* control-l */
@@ -801,19 +812,24 @@ dialog_input (dialog_t diag, int alt, int chr)
       break;
     }
 
-  if (old_loc < diag->pin_loc)
-    {
-      move (diag->pin_y, diag->pin_x + old_loc);
-      while (old_loc++ < diag->pin_loc)
-	addch ('*');
-    }
-  else if (old_loc > diag->pin_loc)
+  diag->got_input = 1;
+
+  if (!diag->no_echo)
     {
+      if (old_loc < diag->pin_loc)
+	{
+	  move (diag->pin_y, diag->pin_x + old_loc);
+	  while (old_loc++ < diag->pin_loc)
+	    addch ('*');
+	}
+      else if (old_loc > diag->pin_loc)
+	{
+	  move (diag->pin_y, diag->pin_x + diag->pin_loc);
+	  while (old_loc-- > diag->pin_loc)
+	    addch ('_');
+	}
       move (diag->pin_y, diag->pin_x + diag->pin_loc);
-      while (old_loc-- > diag->pin_loc)
-	addch ('_');
     }
-  move (diag->pin_y, diag->pin_x + diag->pin_loc);
 }
 
 static int
-- 
2.14.4


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20180804/3ed01a55/attachment.sig>


More information about the Gnupg-devel mailing list