emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117511: Hide password in batch mode


From: Michael Albinus
Subject: [Emacs-diffs] trunk r117511: Hide password in batch mode
Date: Fri, 11 Jul 2014 09:10:09 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117511
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17839
committer: Michael Albinus <address@hidden>
branch nick: trunk
timestamp: Fri 2014-07-11 11:09:54 +0200
message:
  Hide password in batch mode
  
  * doc/lispref/minibuf.texi (Intro to Minibuffers, Reading a Password):
  Password hiding is available in batch mode, do not mention it in
  the exclusion list.  Mention `read-hide-char'. 
  
  * lisp/subr.el (read-passwd): Use `read-hide-char' if non-nil.  Bind it
  when calling `read-string'.
  
  * src/minibuf.c (top): Include systty.h.  Declare external
  emacs_get_tty and emacs_set_tty.
  (Vread_hide_char): New lisp variable.
  (read_minibuf_noninteractive): Hide characters with
  Vread_hide_char if it is a character.
  
  * src/sysdep.c (emacs_get_tty, emacs_set_tty): Make them externally visible.
modified:
  doc/lispref/ChangeLog          changelog-20091113204419-o5vbwnq5f7feedwu-6155
  doc/lispref/minibuf.texi       
minibuf.texi-20091113204419-o5vbwnq5f7feedwu-6199
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/subr.el                   subr.el-20091113204419-o5vbwnq5f7feedwu-151
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/minibuf.c                  minibuf.c-20091113204419-o5vbwnq5f7feedwu-242
  src/sysdep.c                   sysdep.c-20091113204419-o5vbwnq5f7feedwu-448
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog     2014-07-09 02:04:12 +0000
+++ b/doc/lispref/ChangeLog     2014-07-11 09:09:54 +0000
@@ -1,3 +1,9 @@
+2014-07-11  Michael Albinus  <address@hidden>
+
+       * minibuf.texi (Intro to Minibuffers, Reading a Password):
+       Password hiding is available in batch mode, do not mention it in
+       the exclusion list.  Mention `read-hide-char'.  (Bug#17839)
+
 2014-07-09  Stefan Monnier  <address@hidden>
 
        * debugging.texi (Function Debugging, Debugger Commands):

=== modified file 'doc/lispref/minibuf.texi'
--- a/doc/lispref/minibuf.texi  2014-06-28 17:27:29 +0000
+++ b/doc/lispref/minibuf.texi  2014-07-11 09:09:54 +0000
@@ -102,8 +102,8 @@
   When Emacs is running in batch mode, any request to read from the
 minibuffer actually reads a line from the standard input descriptor that
 was supplied when Emacs was started.  This supports only basic input:
-none of the special minibuffer features (history, completion,
-password hiding, etc.) are available in batch mode.
+none of the special minibuffer features (history, completion, etc.)
+are available in batch mode.
 
 @node Text from Minibuffer
 @section Reading Text Strings with the Minibuffer
@@ -2147,9 +2147,10 @@
 
 @defun read-passwd prompt &optional confirm default
 This function reads a password, prompting with @var{prompt}.  It does
-not echo the password as the user types it; instead, it echoes @samp{.}
-for each character in the password.  (Note that in batch mode, the
-input is not hidden.)
+not echo the password as the user types it; instead, it echoes
address@hidden  for each character in the password.  If you want to apply
+another character to hide the password, let-bind the variable
address@hidden with that character.
 
 The optional argument @var{confirm}, if address@hidden, says to read the
 password twice and insist it must be the same both times.  If it isn't

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-07-10 18:19:37 +0000
+++ b/lisp/ChangeLog    2014-07-11 09:09:54 +0000
@@ -1,3 +1,8 @@
+2014-07-11  Michael Albinus  <address@hidden>
+
+       * subr.el (read-passwd): Use `read-hide-char' if non-nil.  Bind it
+       when calling `read-string'.  (Bug#17839)
+
 2014-07-10  Eli Zaretskii  <address@hidden>
 
        * files.el (warn-maybe-out-of-memory): Fix the wording of the

=== modified file 'lisp/subr.el'
--- a/lisp/subr.el      2014-06-28 17:27:29 +0000
+++ b/lisp/subr.el      2014-07-11 09:09:54 +0000
@@ -2016,7 +2016,7 @@
 Optional DEFAULT is a default password to use instead of empty input.
 
 This function echoes `.' for each character that the user types.
-Note that in batch mode, the input is not hidden!
+You could let-bind `read-hide-char' to another hiding character, though.
 
 Once the caller uses the password, it can erase the password
 by doing (clear-string STRING)."
@@ -2041,7 +2041,7 @@
                                      beg)))
              (dotimes (i (- end beg))
                (put-text-property (+ i beg) (+ 1 i beg)
-                                  'display (string ?.)))))
+                                  'display (string (or read-hide-char ?.))))))
           minibuf)
       (minibuffer-with-setup-hook
           (lambda ()
@@ -2055,12 +2055,9 @@
            (setq-local show-paren-mode nil)            ;bug#16091.
             (add-hook 'after-change-functions hide-chars-fun nil 'local))
         (unwind-protect
-            (let ((enable-recursive-minibuffers t))
-              (read-string
-               (if noninteractive
-                   (format "%s[INPUT WILL NOT BE HIDDEN!] " prompt) ; bug#17839
-                 prompt)
-               nil t default)) ; t = "no history"
+            (let ((enable-recursive-minibuffers t)
+                 (read-hide-char (or read-hide-char ?.)))
+              (read-string prompt nil t default)) ; t = "no history"
           (when (buffer-live-p minibuf)
             (with-current-buffer minibuf
               ;; Not sure why but it seems that there might be cases where the

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-07-10 19:09:26 +0000
+++ b/src/ChangeLog     2014-07-11 09:09:54 +0000
@@ -1,3 +1,13 @@
+2014-07-11  Michael Albinus  <address@hidden>
+
+       * sysdep.c (emacs_get_tty, emacs_set_tty): Make them externally visible.
+
+       * minibuf.c (top): Include systty.h.  Declare external
+       emacs_get_tty and emacs_set_tty.
+       (Vread_hide_char): New lisp variable.
+       (read_minibuf_noninteractive): Hide characters with
+       Vread_hide_char if it is a character.  (Bug#17839)
+
 2014-07-10  Eli Zaretskii  <address@hidden>
 
        Implement memory-info for MS-Windows.

=== modified file 'src/minibuf.c'
--- a/src/minibuf.c     2014-05-26 02:28:09 +0000
+++ b/src/minibuf.c     2014-07-11 09:09:54 +0000
@@ -35,6 +35,10 @@
 #include "keymap.h"
 #include "termhooks.h"
 
+#include "systty.h"
+extern void emacs_get_tty (int, struct emacs_tty *);
+extern int emacs_set_tty (int, struct emacs_tty *, bool);
+
 /* List of buffers for use as minibuffers.
    The first element of the list is used for the outermost minibuffer
    invocation, the next element is used for a recursive minibuffer
@@ -224,6 +228,22 @@
   char *line;
   Lisp_Object val;
   int c;
+  unsigned char hide_char = 0;
+  struct emacs_tty old, new;
+
+  /* Check, whether we need to suppress echoing.  */
+  if (CHARACTERP (Vread_hide_char))
+    hide_char = XFASTINT (Vread_hide_char);
+
+  /* Manipulate tty.  */
+  if (hide_char)
+    {
+      emacs_get_tty (fileno (stdin), &old);
+      new = old;
+      new.main.c_lflag &= ~ICANON;     /* Disable buffering */
+      new.main.c_lflag &= ~ECHO;       /* Disable echoing */
+      emacs_set_tty (fileno (stdin), &new, 0);
+    }
 
   fprintf (stdout, "%s", SDATA (prompt));
   fflush (stdout);
@@ -242,6 +262,8 @@
        }
       else
        {
+         if (hide_char)
+           fprintf (stdout, "%c", hide_char);
          if (len == size)
            {
              if (STRING_BYTES_BOUND / 2 < size)
@@ -253,6 +275,13 @@
        }
     }
 
+  /* Reset tty.  */
+  if (hide_char)
+    {
+      fprintf (stdout, "\n");
+      emacs_set_tty (fileno (stdin), &old, 0);
+    }
+
   if (len || c == '\n')
     {
       val = make_string (line, len);
@@ -2079,6 +2108,12 @@
      initialization-order problems.  */
   Vminibuffer_prompt_properties = list2 (intern_c_string ("read-only"), Qt);
 
+  DEFVAR_LISP ("read-hide-char", Vread_hide_char,
+              doc: /* Whether to hide input characters in noninteractive mode.
+It must be a character, which will be used to mask the input
+characters.  This variable should never be set globally.  */);
+  Vread_hide_char = Qnil;
+
   defsubr (&Sactive_minibuffer_window);
   defsubr (&Sset_minibuffer_window);
   defsubr (&Sread_from_minibuffer);

=== modified file 'src/sysdep.c'
--- a/src/sysdep.c      2014-06-09 14:50:57 +0000
+++ b/src/sysdep.c      2014-07-11 09:09:54 +0000
@@ -105,8 +105,8 @@
 #include "syssignal.h"
 #include "systime.h"
 
-static void emacs_get_tty (int, struct emacs_tty *);
-static int emacs_set_tty (int, struct emacs_tty *, bool);
+void emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE;
+int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE;
 
 /* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781.  */
 #ifndef ULLONG_MAX
@@ -779,7 +779,7 @@
 
 /* Set *TC to the parameters associated with the terminal FD,
    or clear it if the parameters are not available.  */
-static void
+void
 emacs_get_tty (int fd, struct emacs_tty *settings)
 {
   /* Retrieve the primary parameters - baud rate, character size, etcetera.  */
@@ -795,7 +795,7 @@
    *SETTINGS.  If FLUSHP, discard input.
    Return 0 if all went well, and -1 (setting errno) if anything failed.  */
 
-static int
+int
 emacs_set_tty (int fd, struct emacs_tty *settings, bool flushp)
 {
   /* Set the primary parameters - baud rate, character size, etcetera.  */


reply via email to

[Prev in Thread] Current Thread [Next in Thread]