unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Noam Postavsky <npostavs@users.sourceforge.net>
Cc: 30190@debbugs.gnu.org, Tino Calancha <tino.calancha@gmail.com>
Subject: bug#30190: 27.0.50; term run in line mode shows user passwords
Date: Sun, 4 Feb 2018 21:47:56 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1802042142340.24516@calancha-pc> (raw)
In-Reply-To: <87a7wpexm5.fsf@users.sourceforge.net>

[-- Attachment #1: Type: text/plain, Size: 5271 bytes --]



On Sun, 4 Feb 2018, Noam Postavsky wrote:

> Tino Calancha <tino.calancha@gmail.com> writes:
>
>> On Sat, 3 Feb 2018, Eli Zaretskii wrote:
>>
>>> My feedback is that such a radical solution with so many lines of code
>>> is a no-no for the release branch.  Please look for a simpler
>>> solution, perhaps don't create a new file?
>> A suitable patch for the next release for discussion below:
>>
>
>> +;; Stolen from comint.el
>> +(defcustom term-password-prompt-regexp
>
>> +  :version "27.1"
That's right.  Well catched, thank you!
Updated patch.
>
> I guess this should say "26.1".  Although maybe we should just use
> comint-password-prompt-regexp in term.el instead?
Part of the fun is to prevent term.el from requiring comint.el as
always has be done; just for using one variable I would not require
comint.el.
--8<-----------------------------cut here---------------start------------->8---
commit 6187b493ded4bdcfd3c6b6fa91333c381fba8913
Author: tino calancha <tino.calancha@gmail.com>
Date:   Sun Feb 4 21:43:43 2018 +0900

     Prevent term run in line mode from showing user passwords

     For buffers whose mode derive from comint-mode, the user
     password is read from the minibuffer and it's hidden.
     A buffer in term-mode and line submode, instead shows
     the passwords.
     This commit forces buffers in line term-mode to hide
     passwords (Bug#30190).

     * lisp/term.el (term-password-prompt-regexp): New user option.
     (term-watch-for-password-prompt): New function.

     (term-send-input, term-emulate-terminal): Call it.
     (term-output-filter-hook): New hook.  Add term-watch-for-password-prompt
     to it.

     (term-send-input, term-emulate-terminal): Call the new hook each time
     we receive output.

diff --git a/lisp/term.el b/lisp/term.el
index 3970e93cf1..6fddef6f82 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -558,6 +558,27 @@ term-suppress-hard-newline
  ;; indications of the current pc.
  (defvar term-pending-frame nil)

+;; Stolen from comint.el
+(defcustom term-password-prompt-regexp
+  (concat
+   "\\(^ *\\|"
+   (regexp-opt
+    '("Enter" "enter" "Enter same" "enter same" "Enter the" "enter the"
+      "Old" "old" "New" "new" "'s" "login"
+      "Kerberos" "CVS" "UNIX" " SMB" "LDAP" "PEM" "SUDO"
+      "[sudo]" "Repeat" "Bad" "Retype")
+    t)
+   " +\\)"
+   "\\(?:" (regexp-opt password-word-equivalents) "\\|Response\\)"
+   "\\(?:\\(?:, try\\)? *again\\| (empty for no passphrase)\\| (again)\\)?"
+   ;; "[[:alpha:]]" used to be "for", which fails to match non-English.
+   "\\(?: [[:alpha:]]+ .+\\)?[\\s  ]*[::៖][\\s  ]*\\'")
+  "Regexp matching prompts for passwords in the inferior process.
+This is used by `term-watch-for-password-prompt'."
+  :version "26.1"
+  :type 'regexp
+  :group 'comint)
+
  ;;; Here are the per-interpreter hooks.
  (defvar term-get-old-input (function term-get-old-input-default)
    "Function that submits old text in term mode.
@@ -586,6 +607,17 @@ term-input-filter-functions

  This variable is buffer-local.")

+;;; Stolen from comint.el
+;;;###autoload
+(defvar term-output-filter-hook '(term-watch-for-password-prompt)
+  "Functions to call after output is inserted into the buffer.
+One possible function is `term-watch-for-password-prompt'.
+These functions get one argument, a string containing the text as originally
+inserted.
+
+You can use `add-hook' to add functions to this list
+either globally or locally.")
+
  (defvar term-input-sender (function term-simple-send)
    "Function to actually send to PROCESS the STRING submitted by user.
  Usually this is just `term-simple-send', but if your mode needs to
@@ -2134,7 +2166,8 @@ term-send-input
  	  (set-marker term-pending-delete-marker pmark-val)
  	  (set-marker (process-mark proc) (point)))
  	(goto-char pmark)
-	(funcall term-input-sender proc input)))))
+	(funcall term-input-sender proc input)
+        (run-hook-with-args 'term-output-filter-hook "")))))

  (defun term-get-old-input-default ()
    "Default for `term-get-old-input'.
@@ -2264,6 +2297,21 @@ term-send-invisible
      (term-send-string proc str)
      (term-send-string proc "\n")))

+;;; Stolen from comint.el
+;; TODO: This file share plenty of code with comint.el; it might be worth
+;; to extract the common functionality into a new file.
+(defun term-watch-for-password-prompt (string)
+  "Prompt in the minibuffer for password and send without echoing.
+This function uses `term-send-invisible' to read and send a password to the buffer's
+process if STRING contains a password prompt defined by
+`term-password-prompt-regexp'.
+
+This function could be in the list `term-emulate-terminal'."
+  (when (term-in-line-mode)
+    (when (let ((case-fold-search t))
+	    (string-match term-password-prompt-regexp string))
+      (term-send-invisible nil))))
+

  ;;; Low-level process communication

@@ -3121,6 +3169,8 @@ term-emulate-terminal
  	  (term-handle-deferred-scroll))

  	(set-marker (process-mark proc) (point))
+        ;; Run these hooks with point where the user had it.
+        (run-hook-with-args 'term-output-filter-hook str)
  	(when save-point
  	  (goto-char save-point)
  	  (set-marker save-point nil))
--8<-----------------------------cut here---------------end--------------->8---

  reply	other threads:[~2018-02-04 12:47 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-21 12:16 bug#30190: 27.0.50; term run in line mode shows user passwords Tino Calancha
2018-01-21 14:01 ` Noam Postavsky
2018-01-21 21:08   ` Tino Calancha
2018-02-03 16:15   ` Tino Calancha
2018-02-03 16:44     ` Noam Postavsky
2018-02-04  2:23       ` Tino Calancha
2018-02-04  2:29         ` Noam Postavsky
2018-02-04  3:37           ` Tino Calancha
2018-02-05  1:07         ` Richard Stallman
2018-02-03 17:08     ` Eli Zaretskii
2018-02-04  2:26       ` Tino Calancha
2018-02-04  3:40       ` Tino Calancha
2018-02-04 12:40         ` Noam Postavsky
2018-02-04 12:47           ` Tino Calancha [this message]
2018-02-15  0:09         ` Tino Calancha
2018-02-21 10:18           ` Tino Calancha
2018-02-21 17:47             ` Eli Zaretskii
2018-03-10  8:52               ` Tino Calancha
2018-03-10 10:25                 ` Eli Zaretskii
2018-03-10 10:44                   ` Tino Calancha
2018-03-10 12:07                     ` Eli Zaretskii
2018-03-10 13:17                       ` Tino Calancha
2018-03-10 15:50                         ` Eli Zaretskii
2018-03-11 11:02                           ` Tino Calancha
2018-03-11 17:04                             ` Eli Zaretskii
2018-06-20  4:09                 ` Noam Postavsky
2018-06-20 16:27                   ` Eli Zaretskii
2018-06-20 23:28                     ` Noam Postavsky
2018-06-21  1:31                       ` Tino Calancha
2018-06-21  2:44                       ` Eli Zaretskii
2018-06-21  3:07                         ` Tino Calancha
2018-06-21 19:17                           ` Stefan Monnier
2018-06-22  3:34                             ` Tino Calancha
2018-06-22 12:44                               ` Stefan Monnier
2018-07-18 11:56                                 ` Noam Postavsky
2018-07-18 12:32                                   ` Tino Calancha
2018-07-18 14:24                                   ` Stefan Monnier
2018-07-18 14:56                                     ` Tino Calancha
2018-07-18 15:54                                       ` Stefan Monnier
2018-07-18 23:28                                         ` Tino Calancha
2018-07-19  1:58                                           ` Stefan Monnier
2018-07-19  2:27                                             ` Noam Postavsky
2018-07-19 12:45                                               ` Stefan Monnier
2018-07-20  7:34                                               ` Tino Calancha
2018-07-19  0:02                                     ` Noam Postavsky
2018-07-19  2:00                                       ` Stefan Monnier
2018-07-22 18:33                                         ` Noam Postavsky
2018-07-22 18:44                                           ` Eli Zaretskii
2018-07-23 12:22                                             ` Noam Postavsky
2018-07-23 12:46                                           ` Stefan Monnier
2018-07-23 12:56                                             ` Tino Calancha
2018-07-24  0:28                                               ` Noam Postavsky
2018-07-24  2:35                                                 ` Eli Zaretskii
2018-07-30  1:15                                                   ` Noam Postavsky

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1802042142340.24516@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=30190@debbugs.gnu.org \
    --cc=npostavs@users.sourceforge.net \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).