From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#17839: 24.4.50; read-passwd echoes password input in non-interactive sessions Date: Thu, 10 Jul 2014 16:36:43 +0200 Message-ID: <87fvi9jn5w.fsf@gmx.de> References: <53FA2CB5-2009-4F77-B10D-03B16CE6D715@lunaryorn.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1405003118 5590 80.91.229.3 (10 Jul 2014 14:38:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Jul 2014 14:38:38 +0000 (UTC) Cc: Andreas Schwab , 17839@debbugs.gnu.org, Sebastian Wiesner To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 10 16:38:29 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X5FUM-0002og-7n for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Jul 2014 16:38:22 +0200 Original-Received: from localhost ([::1]:38364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5FUL-0006Bf-I7 for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Jul 2014 10:38:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5FUA-0006AH-Uo for bug-gnu-emacs@gnu.org; Thu, 10 Jul 2014 10:38:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X5FU4-0003QT-9F for bug-gnu-emacs@gnu.org; Thu, 10 Jul 2014 10:38:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37479) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5FU4-0003QN-2O for bug-gnu-emacs@gnu.org; Thu, 10 Jul 2014 10:38:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1X5FU3-0004hT-E7 for bug-gnu-emacs@gnu.org; Thu, 10 Jul 2014 10:38:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 10 Jul 2014 14:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17839 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17839-submit@debbugs.gnu.org id=B17839.140500302617963 (code B ref 17839); Thu, 10 Jul 2014 14:38:02 +0000 Original-Received: (at 17839) by debbugs.gnu.org; 10 Jul 2014 14:37:06 +0000 Original-Received: from localhost ([127.0.0.1]:52277 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X5FT4-0004e8-1J for submit@debbugs.gnu.org; Thu, 10 Jul 2014 10:37:06 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:63020) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X5FSx-0004dk-NX for 17839@debbugs.gnu.org; Thu, 10 Jul 2014 10:36:59 -0400 Original-Received: from detlef.gmx.de ([93.202.59.34]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0M7DVi-1WhXs80i0c-00x3VV; Thu, 10 Jul 2014 16:36:47 +0200 In-Reply-To: (Stefan Monnier's message of "Wed, 25 Jun 2014 10:32:51 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-Provags-ID: V03:K0:iFaaDR4pvfJLFgmlwvmHUVyKmVJDo75bCTZA/JQTxOhFYXz33Zw urRSbt7pWIN9bD6LX7IDufnav/+wzgQ2oOOCMzZdhA7Fl1q4cl45ysLzY5eB9y8bNFGMoE6 BoyqH1gt3oRcrwxr+bDGBif6xwLGeR3Hwik42i0eMN38h6xWk042qB+PfID4DpG1QYZlgAv lcRf4ZwqvvjL3SNOLd71g== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:91382 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=diff === 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. */ --=-=-=--