Commit 893111f4 authored by Lars Ingebrigtsen's avatar Lars Ingebrigtsen

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.
parent 2c7224f8
Pipeline #3234 passed with stage
in 56 minutes and 6 seconds
......@@ -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
+++
......
......@@ -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
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment