diff options
| author | Lars Ingebrigtsen | 2019-09-21 12:03:55 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-21 12:04:00 +0200 |
| commit | 893111f48abd504208408904ea54bc487641756d (patch) | |
| tree | becee12bc572cdf8644abf947f5997bfde257915 /lisp/auth-source.el | |
| parent | 2c7224f8942e6338ea9dce727a7b573bf4f3f5a6 (diff) | |
| download | emacs-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.
Diffstat (limited to 'lisp/auth-source.el')
| -rw-r--r-- | lisp/auth-source.el | 32 |
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\"." | |||
| 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 | |||
| 2407 | This is just like `fundamental-mode', but hides passwords. The | ||
| 2408 | passwords 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 |