From: Michael Albinus <michael.albinus@gmx.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Andreas Schwab <schwab@suse.de>,
17839@debbugs.gnu.org, Sebastian Wiesner <swiesner@lunaryorn.com>
Subject: bug#17839: 24.4.50; read-passwd echoes password input in non-interactive sessions
Date: Thu, 10 Jul 2014 16:36:43 +0200 [thread overview]
Message-ID: <87fvi9jn5w.fsf@gmx.de> (raw)
In-Reply-To: <jwvfvitt63l.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Wed, 25 Jun 2014 10:32:51 -0400")
[-- Attachment #1: Type: text/plain, Size: 707 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> If someone is motivated, I would even accept a patch that turns echo off
> temporarily.
Well, I've tried this 'cos I believe it is important. The idea is to
give the prompt in read-passwd the text property 'hide-chars. In
noninteractive mode, emacs writes "." instead of echoing the password
while typing. You can test it with
# emacs -batch -eval '(progn (message (read-string "Prompt1: ")) (message (read-passwd "Prompt2: ")) (message (read-string "Prompt3: ")))'
The patch is not perfect (it doesn't handled multi-byte chars, and I
have tested it only under Gnu/Linux), but it is a first step.
Comments?
> Stefan
Best regards, Michael.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: diff --]
[-- Type: text/x-patch, Size: 3943 bytes --]
=== modified file 'lisp/subr.el'
--- lisp/subr.el 2014-06-28 17:27:29 +0000
+++ lisp/subr.el 2014-07-10 13:53:13 +0000
@@ -2058,7 +2058,7 @@
(let ((enable-recursive-minibuffers t))
(read-string
(if noninteractive
- (format "%s[INPUT WILL NOT BE HIDDEN!] " prompt) ; bug#17839
+ (propertize prompt 'hide-chars t) ; bug#17839
prompt)
nil t default)) ; t = "no history"
(when (buffer-live-p minibuf)
=== modified file 'src/minibuf.c'
--- src/minibuf.c 2014-05-26 02:28:09 +0000
+++ src/minibuf.c 2014-07-10 14:19:50 +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
@@ -209,6 +213,8 @@
}
+static Lisp_Object Qhide_chars;
+
/* Like read_minibuf but reading from stdin. This function is called
from read_minibuf to do the job if noninteractive. */
@@ -224,6 +230,20 @@
char *line;
Lisp_Object val;
int c;
+ bool hide_chars;
+ struct emacs_tty old, new;
+
+ /* Check, whether we need to suppress echoing. */
+ hide_chars = ! (NILP (Fget_text_property
+ (make_number (0), Qhide_chars, prompt)));
+ if (hide_chars)
+ {
+ 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);
@@ -240,8 +260,17 @@
if (errno != EINTR)
break;
}
+ else if (hide_chars && (c == 127)) /* DEL */
+ {
+ /* Unfortunately, we cannot edit stdout. */
+ // fprintf (stdout, "%c", c);
+ /* Hmm, this doesn't work for multi-byte characters. */
+ (len > 0) && len--;
+ }
else
{
+ if (hide_chars)
+ fprintf (stdout, ".");
if (len == size)
{
if (STRING_BYTES_BOUND / 2 < size)
@@ -253,6 +282,13 @@
}
}
+ /* Reset tty. */
+ if (hide_chars)
+ {
+ fprintf (stdout, "\n");
+ emacs_set_tty (fileno (stdin), &old, 0);
+ }
+
if (len || c == '\n')
{
val = make_string (line, len);
@@ -1935,6 +1971,7 @@
DEFSYM (Qactivate_input_method, "activate-input-method");
DEFSYM (Qcase_fold_search, "case-fold-search");
DEFSYM (Qmetadata, "metadata");
+ DEFSYM (Qhide_chars, "hide-chars");
DEFVAR_LISP ("read-expression-history", Vread_expression_history,
doc: /* A history list for arguments that are Lisp expressions to evaluate.
=== modified file 'src/sysdep.c'
--- src/sysdep.c 2014-06-09 14:50:57 +0000
+++ src/sysdep.c 2014-07-10 10:07:05 +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. */
next prev parent reply other threads:[~2014-07-10 14:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-23 13:51 bug#17839: 24.4.50; read-passwd echoes password input in non-interactive sessions Sebastian Wiesner
2014-06-23 15:46 ` Andreas Schwab
2014-06-23 16:52 ` Sebastian Wiesner
2014-06-24 18:41 ` Glenn Morris
2014-06-24 22:55 ` Sebastian Wiesner
2014-06-25 7:47 ` Andreas Schwab
2014-06-25 8:01 ` Michael Albinus
2014-06-25 8:15 ` Andreas Schwab
2014-06-25 9:20 ` Michael Albinus
2014-06-25 9:26 ` Andreas Schwab
2014-06-25 10:03 ` Michael Albinus
2014-06-25 9:52 ` Sebastian Wiesner
2014-06-25 14:32 ` Stefan Monnier
2014-06-26 19:01 ` Glenn Morris
2014-07-10 14:36 ` Michael Albinus [this message]
2014-07-10 16:43 ` Stefan Monnier
2014-07-11 9:15 ` Michael Albinus
2014-07-11 9:41 ` Michael Albinus
2014-07-11 9:45 ` Eli Zaretskii
2014-07-11 9:58 ` Michael Albinus
2014-07-11 10:13 ` Eli Zaretskii
2014-07-11 11:32 ` Michael Albinus
2014-07-11 12:43 ` Michael Albinus
2014-07-11 14:02 ` Eli Zaretskii
2014-07-11 14:57 ` Michael Albinus
2014-07-11 15:46 ` Eli Zaretskii
2014-08-05 20:25 ` Sebastian Wiesner
2014-08-06 17:39 ` Stefan Monnier
2014-08-07 11:12 ` Sebastian Wiesner
2014-08-07 13:01 ` Stefan Monnier
2014-08-07 13:12 ` Sebastian Wiesner
2014-08-07 15:30 ` Eli Zaretskii
2014-08-07 16:08 ` Sebastian Wiesner
2014-08-07 16:38 ` Eli Zaretskii
2014-07-11 10:03 ` Eli Zaretskii
2014-07-11 10:15 ` Michael Albinus
2014-07-10 21:46 ` Sebastian Wiesner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fvi9jn5w.fsf@gmx.de \
--to=michael.albinus@gmx.de \
--cc=17839@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=schwab@suse.de \
--cc=swiesner@lunaryorn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.