[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 893111f 2/2: Hide passwords in .authinfo and .netrc
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master 893111f 2/2: Hide passwords in .authinfo and .netrc files |
Date: |
Sat, 21 Sep 2019 06:04:10 -0400 (EDT) |
branch: master
commit 893111f48abd504208408904ea54bc487641756d
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Hide passwords in .authinfo and .netrc files
* lisp/auth-source.el (authinfo-mode): New mode (bug#28785).
(authinfo--hide-passwords, authinfo--toggle-display): New functions.
* lisp/files.el (auto-mode-alist): Use authinfo-mode for .authinfo
and .netrc files.
---
etc/NEWS | 5 +++++
lisp/auth-source.el | 32 ++++++++++++++++++++++++++++++++
lisp/files.el | 1 +
3 files changed, 38 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 02fe93a..82b8506 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1488,6 +1488,11 @@ To recover the previous behavior, set new user option
---
*** The Secret Service backend supports the ':create' key now.
+*** .authinfo and .netrc files now use a new mode: 'authinfo-mode'.
+This is just like 'fundamental-mode', except that it hides passwords
+under a "****" display property. When the cursor moves to this text,
+the real password is revealed (via `reveal-mode').
+
** Tramp
+++
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 2164a55..9669ae9 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -2397,6 +2397,38 @@ MODE can be \"login\" or \"password\"."
(setq password (funcall password)))
(list user password auth-info)))
+;;; Tiny mode for editing .netrc/.authinfo modes (that basically just
+;;; hides passwords).
+
+;;;###autoload
+(define-derived-mode authinfo-mode fundamental-mode "Authinfo"
+ "Mode for editing .authinfo/.netrc files.
+
+This is just like `fundamental-mode', but hides passwords. The
+passwords are revealed when point moved into the password.
+
+\\{authinfo-mode-map}"
+ (authinfo--hide-passwords (point-min) (point-max))
+ (reveal-mode))
+
+(defun authinfo--hide-passwords (start end)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char start)
+ (while (re-search-forward "\\bpassword +\\([^\n\t ]+\\)"
+ nil t)
+ (let ((overlay (make-overlay (match-beginning 1) (match-end 1))))
+ (overlay-put overlay 'display (propertize "****"
+ 'face 'warning))
+ (overlay-put overlay 'reveal-toggle-invisible
+ #'authinfo--toggle-display))))))
+
+(defun authinfo--toggle-display (overlay hide)
+ (if hide
+ (overlay-put overlay 'display (propertize "****" 'face 'warning))
+ (overlay-put overlay 'display nil)))
+
(provide 'auth-source)
;;; auth-source.el ends here
diff --git a/lisp/files.el b/lisp/files.el
index 0c3da1f..8c355b0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2811,6 +2811,7 @@
ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|CBR\\|7Z\\)\\'" . archive-mo
("\\.docbook\\'" . sgml-mode)
("\\.com\\'" . dcl-mode)
("/config\\.\\(?:bat\\|log\\)\\'" . fundamental-mode)
+ ("/\\.\\(authinfo\\|netrc\\)\\'" . authinfo-mode)
;; Windows candidates may be opened case sensitively on Unix
("\\.\\(?:[iI][nN][iI]\\|[lL][sS][tT]\\|[rR][eE][gG]\\|[sS][yY][sS]\\)\\'" .
conf-mode)
("\\.la\\'" . conf-unix-mode)