summaryrefslogtreecommitdiff
path: root/lisp/auth-source.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-09-21 12:03:55 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-09-21 12:04:00 +0200
commit893111f48abd504208408904ea54bc487641756d (patch)
treebecee12bc572cdf8644abf947f5997bfde257915 /lisp/auth-source.el
parent2c7224f8942e6338ea9dce727a7b573bf4f3f5a6 (diff)
downloademacs-893111f48abd504208408904ea54bc487641756d.tar.gz
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.
Diffstat (limited to 'lisp/auth-source.el')
-rw-r--r--lisp/auth-source.el32
1 files changed, 32 insertions, 0 deletions
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\"."
(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