diff options
| author | Michael Albinus <michael.albinus@gmx.de> | 2014-07-11 11:09:54 +0200 |
|---|---|---|
| committer | Michael Albinus <michael.albinus@gmx.de> | 2014-07-11 11:09:54 +0200 |
| commit | c0ada759210b090944e0a23ed4879ca1a3ad38a7 (patch) | |
| tree | 5bc957f5d30cc16af9add35e301e02c5c22bf89a /src | |
| parent | 644656aa562a78edf384abd6f4ce80bc930d5547 (diff) | |
| download | emacs-c0ada759210b090944e0a23ed4879ca1a3ad38a7.tar.gz | |
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.
Fixes: debbugs:17839
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 10 | ||||
| -rw-r--r-- | src/minibuf.c | 35 | ||||
| -rw-r--r-- | src/sysdep.c | 8 |
3 files changed, 49 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 93ad0ded350..e2a7bb8a0f0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2014-07-11 Michael Albinus <michael.albinus@gmx.de> + + * 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 <eliz@gnu.org> Implement memory-info for MS-Windows. diff --git a/src/minibuf.c b/src/minibuf.c index 3042b13b7d6..122f77fff96 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -35,6 +35,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #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 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, 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 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, } else { + if (hide_char) + fprintf (stdout, "%c", hide_char); if (len == size) { if (STRING_BYTES_BOUND / 2 < size) @@ -253,6 +275,13 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, } } + /* 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 @@ properties. */); 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); diff --git a/src/sysdep.c b/src/sysdep.c index 211a3bb706f..14d9f43c4db 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -105,8 +105,8 @@ int _cdecl _getpid (void); #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 @@ widen_foreground_group (int fd) /* 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 @@ emacs_get_tty (int fd, struct emacs_tty *settings) *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. */ |
