aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-09-21 12:03:55 +0200
committerLars Ingebrigtsen2019-09-21 12:04:00 +0200
commit893111f48abd504208408904ea54bc487641756d (patch)
treebecee12bc572cdf8644abf947f5997bfde257915
parent2c7224f8942e6338ea9dce727a7b573bf4f3f5a6 (diff)
downloademacs-893111f48abd504208408904ea54bc487641756d.tar.gz
emacs-893111f48abd504208408904ea54bc487641756d.zip
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.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/auth-source.el32
-rw-r--r--lisp/files.el1
3 files changed, 38 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 02fe93a782d..82b8506ae0c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1488,6 +1488,11 @@ To recover the previous behavior, set new user option
1488--- 1488---
1489*** The Secret Service backend supports the ':create' key now. 1489*** The Secret Service backend supports the ':create' key now.
1490 1490
1491*** .authinfo and .netrc files now use a new mode: 'authinfo-mode'.
1492This is just like 'fundamental-mode', except that it hides passwords
1493under a "****" display property. When the cursor moves to this text,
1494the real password is revealed (via `reveal-mode').
1495
1491** Tramp 1496** Tramp
1492 1497
1493+++ 1498+++
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 2164a550b0a..9669ae976cc 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -2397,6 +2397,38 @@ MODE can be \"login\" or \"password\"."
2397 (setq password (funcall password))) 2397 (setq password (funcall password)))
2398 (list user password auth-info))) 2398 (list user password auth-info)))
2399 2399
2400;;; Tiny mode for editing .netrc/.authinfo modes (that basically just
2401;;; hides passwords).
2402
2403;;;###autoload
2404(define-derived-mode authinfo-mode fundamental-mode "Authinfo"
2405 "Mode for editing .authinfo/.netrc files.
2406
2407This is just like `fundamental-mode', but hides passwords. The
2408passwords are revealed when point moved into the password.
2409
2410\\{authinfo-mode-map}"
2411 (authinfo--hide-passwords (point-min) (point-max))
2412 (reveal-mode))
2413
2414(defun authinfo--hide-passwords (start end)
2415 (save-excursion
2416 (save-restriction
2417 (narrow-to-region start end)
2418 (goto-char start)
2419 (while (re-search-forward "\\bpassword +\\([^\n\t ]+\\)"
2420 nil t)
2421 (let ((overlay (make-overlay (match-beginning 1) (match-end 1))))
2422 (overlay-put overlay 'display (propertize "****"
2423 'face 'warning))
2424 (overlay-put overlay 'reveal-toggle-invisible
2425 #'authinfo--toggle-display))))))
2426
2427(defun authinfo--toggle-display (overlay hide)
2428 (if hide
2429 (overlay-put overlay 'display (propertize "****" 'face 'warning))
2430 (overlay-put overlay 'display nil)))
2431
2400(provide 'auth-source) 2432(provide 'auth-source)
2401 2433
2402;;; auth-source.el ends here 2434;;; auth-source.el ends here
diff --git a/lisp/files.el b/lisp/files.el
index 0c3da1fe3cc..8c355b02aa1 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
2811 ("\\.docbook\\'" . sgml-mode) 2811 ("\\.docbook\\'" . sgml-mode)
2812 ("\\.com\\'" . dcl-mode) 2812 ("\\.com\\'" . dcl-mode)
2813 ("/config\\.\\(?:bat\\|log\\)\\'" . fundamental-mode) 2813 ("/config\\.\\(?:bat\\|log\\)\\'" . fundamental-mode)
2814 ("/\\.\\(authinfo\\|netrc\\)\\'" . authinfo-mode)
2814 ;; Windows candidates may be opened case sensitively on Unix 2815 ;; Windows candidates may be opened case sensitively on Unix
2815 ("\\.\\(?:[iI][nN][iI]\\|[lL][sS][tT]\\|[rR][eE][gG]\\|[sS][yY][sS]\\)\\'" . conf-mode) 2816 ("\\.\\(?:[iI][nN][iI]\\|[lL][sS][tT]\\|[rR][eE][gG]\\|[sS][yY][sS]\\)\\'" . conf-mode)
2816 ("\\.la\\'" . conf-unix-mode) 2817 ("\\.la\\'" . conf-unix-mode)