diff options
| author | Sam Steingold | 2022-01-06 14:42:10 -0500 |
|---|---|---|
| committer | Sam Steingold | 2022-01-07 14:48:59 -0500 |
| commit | ad5cf84fa737d26ed12e75e09e5f079df0efe5f6 (patch) | |
| tree | 0d437cdfc791c9742850118edfc8927a7992b76f | |
| parent | 19c6cad1821eb896b2ddd0f6eab030f0880ea254 (diff) | |
| download | emacs-ad5cf84fa737d26ed12e75e09e5f079df0efe5f6.tar.gz emacs-ad5cf84fa737d26ed12e75e09e5f079df0efe5f6.zip | |
Add `auth-info-password' and use it instead of ad hoc code
* lisp/auth-source.el (auth-info-password):
Extract from `auth-source-pick-first-password'.
(auth-source-pick-first-password, auth-source-secrets-create)
(auth-source-user-and-password): Use `auth-info-password'.
* lisp/erc/erc-services.el (erc-nickserv-get-password):
Use `auth-source-pick-first-password'.
* lisp/erc/erc.el (erc-open, erc-server-join-channel): Likewise.
* lisp/gnus/mail-source.el (mail-source-set-1): Add a comment.
* lisp/gnus/nnimap.el (nnimap-credentials): Use `auth-info-password'.
* lisp/gnus/nntp.el (nntp-send-authinfo): Likewise.
* lisp/mail/rmail.el (rmail-get-remote-password): Likewise.
* lisp/mail/smtpmail.el (smtpmail-try-auth-methods): Likewise.
* lisp/net/sieve-manage.el (sieve-sasl-auth): Likewise.
* lisp/net/tramp.el (tramp-read-passwd): Likewise.
* lisp/net/rcirc.el (rcirc): Likewise (fixes a bug: the possibility
that password might be a function was not handled).
| -rw-r--r-- | lisp/auth-source.el | 23 | ||||
| -rw-r--r-- | lisp/erc/erc-services.el | 15 | ||||
| -rw-r--r-- | lisp/erc/erc.el | 35 | ||||
| -rw-r--r-- | lisp/gnus/mail-source.el | 2 | ||||
| -rw-r--r-- | lisp/gnus/nnimap.el | 6 | ||||
| -rw-r--r-- | lisp/gnus/nntp.el | 6 | ||||
| -rw-r--r-- | lisp/mail/rmail.el | 5 | ||||
| -rw-r--r-- | lisp/mail/smtpmail.el | 8 | ||||
| -rw-r--r-- | lisp/net/rcirc.el | 4 | ||||
| -rw-r--r-- | lisp/net/sieve-manage.el | 6 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 5 |
11 files changed, 42 insertions, 73 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 80c220561a6..046a685d744 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el | |||
| @@ -853,15 +853,17 @@ while \(:host t) would find all host entries." | |||
| 853 | (cl-return 'no))) | 853 | (cl-return 'no))) |
| 854 | 'no)))) | 854 | 'no)))) |
| 855 | 855 | ||
| 856 | (defun auth-source-pick-first-password (&rest spec) | 856 | (defun auth-info-password (auth-info) |
| 857 | "Pick the first secret found from applying SPEC to `auth-source-search'." | 857 | "Return the :secret password from the AUTH-INFO." |
| 858 | (let* ((result (nth 0 (apply #'auth-source-search (plist-put spec :max 1)))) | 858 | (let ((secret (plist-get auth-info :secret))) |
| 859 | (secret (plist-get result :secret))) | ||
| 860 | |||
| 861 | (if (functionp secret) | 859 | (if (functionp secret) |
| 862 | (funcall secret) | 860 | (funcall secret) |
| 863 | secret))) | 861 | secret))) |
| 864 | 862 | ||
| 863 | (defun auth-source-pick-first-password (&rest spec) | ||
| 864 | "Pick the first secret found from applying SPEC to `auth-source-search'." | ||
| 865 | (auth-info-password (car (apply #'auth-source-search (plist-put spec :max 1))))) | ||
| 866 | |||
| 865 | (defun auth-source-format-prompt (prompt alist) | 867 | (defun auth-source-format-prompt (prompt alist) |
| 866 | "Format PROMPT using %x (for any character x) specifiers in ALIST. | 868 | "Format PROMPT using %x (for any character x) specifiers in ALIST. |
| 867 | Remove trailing \": \"." | 869 | Remove trailing \": \"." |
| @@ -1800,10 +1802,9 @@ authentication tokens: | |||
| 1800 | (plist-put | 1802 | (plist-put |
| 1801 | artificial | 1803 | artificial |
| 1802 | :save-function | 1804 | :save-function |
| 1803 | (let* ((collection collection) | 1805 | (let ((collection collection) |
| 1804 | (item (plist-get artificial :label)) | 1806 | (item (plist-get artificial :label)) |
| 1805 | (secret (plist-get artificial :secret)) | 1807 | (secret (auth-info-password artificial))) |
| 1806 | (secret (if (functionp secret) (funcall secret) secret))) | ||
| 1807 | (lambda () | 1808 | (lambda () |
| 1808 | (auth-source-secrets-saver collection item secret args))))) | 1809 | (auth-source-secrets-saver collection item secret args))))) |
| 1809 | 1810 | ||
| @@ -2410,9 +2411,7 @@ MODE can be \"login\" or \"password\"." | |||
| 2410 | :require '(:user :secret) | 2411 | :require '(:user :secret) |
| 2411 | :create nil)))) | 2412 | :create nil)))) |
| 2412 | (user (plist-get auth-info :user)) | 2413 | (user (plist-get auth-info :user)) |
| 2413 | (password (plist-get auth-info :secret))) | 2414 | (password (auth-info-password auth-info))) |
| 2414 | (when (functionp password) | ||
| 2415 | (setq password (funcall password))) | ||
| 2416 | (list user password auth-info))) | 2415 | (list user password auth-info))) |
| 2417 | 2416 | ||
| 2418 | ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just | 2417 | ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just |
diff --git a/lisp/erc/erc-services.el b/lisp/erc/erc-services.el index dcd786411f2..4b3ca7d23f7 100644 --- a/lisp/erc/erc-services.el +++ b/lisp/erc/erc-services.el | |||
| @@ -444,15 +444,12 @@ it returns nil." | |||
| 444 | (cl-second (assoc network | 444 | (cl-second (assoc network |
| 445 | erc-nickserv-passwords))))) | 445 | erc-nickserv-passwords))))) |
| 446 | (when erc-use-auth-source-for-nickserv-password | 446 | (when erc-use-auth-source-for-nickserv-password |
| 447 | (let ((secret (cl-first (auth-source-search | 447 | (auth-source-pick-first-password |
| 448 | :max 1 :require '(:secret) | 448 | :require '(:secret) |
| 449 | :host server | 449 | :host server |
| 450 | ;; Ensure a string for :port | 450 | ;; Ensure a string for :port |
| 451 | :port (format "%s" port) | 451 | :port (format "%s" port) |
| 452 | :user nick)))) | 452 | :user nick)) |
| 453 | (when secret | ||
| 454 | (let ((passwd (plist-get secret :secret))) | ||
| 455 | (if (functionp passwd) (funcall passwd) passwd))))) | ||
| 456 | (when erc-prompt-for-nickserv-password | 453 | (when erc-prompt-for-nickserv-password |
| 457 | (read-passwd | 454 | (read-passwd |
| 458 | (format "NickServ password for %s on %s (RET to cancel): " | 455 | (format "NickServ password for %s on %s (RET to cancel): " |
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 24f47625711..5faeda9a132 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -2062,19 +2062,12 @@ Returns the buffer for the given server or channel." | |||
| 2062 | ;; password stuff | 2062 | ;; password stuff |
| 2063 | (setq erc-session-password | 2063 | (setq erc-session-password |
| 2064 | (or passwd | 2064 | (or passwd |
| 2065 | (let ((secret | 2065 | (auth-source-pick-first-password |
| 2066 | (plist-get | 2066 | :host server |
| 2067 | (nth 0 | 2067 | :user nick |
| 2068 | (auth-source-search :host server | 2068 | ;; secrets.el wouldn’t accept a number |
| 2069 | :max 1 | 2069 | :port (if (numberp port) (number-to-string port) port) |
| 2070 | :user nick | 2070 | :require '(:secret)))) |
| 2071 | ;; secrets.el wouldn’t accept a number | ||
| 2072 | :port (if (numberp port) (number-to-string port) port) | ||
| 2073 | :require '(:secret))) | ||
| 2074 | :secret))) | ||
| 2075 | (if (functionp secret) | ||
| 2076 | (funcall secret) | ||
| 2077 | secret)))) | ||
| 2078 | ;; client certificate (only useful if connecting over TLS) | 2071 | ;; client certificate (only useful if connecting over TLS) |
| 2079 | (setq erc-session-client-certificate client-certificate) | 2072 | (setq erc-session-client-certificate client-certificate) |
| 2080 | ;; debug output buffer | 2073 | ;; debug output buffer |
| @@ -3187,16 +3180,12 @@ For a list of user commands (/join /part, ...): | |||
| 3187 | (put 'erc-cmd-HELP 'process-not-needed t) | 3180 | (put 'erc-cmd-HELP 'process-not-needed t) |
| 3188 | 3181 | ||
| 3189 | (defun erc-server-join-channel (server channel &optional secret) | 3182 | (defun erc-server-join-channel (server channel &optional secret) |
| 3190 | (let* ((secret (or secret | 3183 | (let ((password |
| 3191 | (plist-get (nth 0 (auth-source-search | 3184 | (or secret |
| 3192 | :max 1 | 3185 | (auth-source-pick-first-password |
| 3193 | :host server | 3186 | :host server |
| 3194 | :port "irc" | 3187 | :port "irc" |
| 3195 | :user channel)) | 3188 | :user channel)))) |
| 3196 | :secret))) | ||
| 3197 | (password (if (functionp secret) | ||
| 3198 | (funcall secret) | ||
| 3199 | secret))) | ||
| 3200 | (erc-log (format "cmd: JOIN: %s" channel)) | 3189 | (erc-log (format "cmd: JOIN: %s" channel)) |
| 3201 | (erc-server-send (concat "JOIN " channel | 3190 | (erc-server-send (concat "JOIN " channel |
| 3202 | (if password | 3191 | (if password |
diff --git a/lisp/gnus/mail-source.el b/lisp/gnus/mail-source.el index d2f5b9a97e2..9a48f710e55 100644 --- a/lisp/gnus/mail-source.el +++ b/lisp/gnus/mail-source.el | |||
| @@ -454,7 +454,7 @@ the `mail-source-keyword-map' variable." | |||
| 454 | search)))) | 454 | search)))) |
| 455 | :user))) | 455 | :user))) |
| 456 | user-auth) | 456 | user-auth) |
| 457 | ((and | 457 | ((and ; cf. 'auth-source-pick-first-password' |
| 458 | (eq keyword :password) | 458 | (eq keyword :password) |
| 459 | (setq pass-auth | 459 | (setq pass-auth |
| 460 | (plist-get | 460 | (plist-get |
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el index ab4243e867f..090cb9b245b 100644 --- a/lisp/gnus/nnimap.el +++ b/lisp/gnus/nnimap.el | |||
| @@ -40,6 +40,7 @@ | |||
| 40 | 40 | ||
| 41 | (autoload 'auth-source-forget+ "auth-source") | 41 | (autoload 'auth-source-forget+ "auth-source") |
| 42 | (autoload 'auth-source-search "auth-source") | 42 | (autoload 'auth-source-search "auth-source") |
| 43 | (autoload 'auth-info-password "auth-source") | ||
| 43 | 44 | ||
| 44 | (nnoo-declare nnimap) | 45 | (nnoo-declare nnimap) |
| 45 | 46 | ||
| @@ -407,10 +408,7 @@ during splitting, which may be slow." | |||
| 407 | :create t)))) | 408 | :create t)))) |
| 408 | (if found | 409 | (if found |
| 409 | (list (plist-get found :user) | 410 | (list (plist-get found :user) |
| 410 | (let ((secret (plist-get found :secret))) | 411 | (auth-info-password found) |
| 411 | (if (functionp secret) | ||
| 412 | (funcall secret) | ||
| 413 | secret)) | ||
| 414 | (plist-get found :save-function)) | 412 | (plist-get found :save-function)) |
| 415 | nil))) | 413 | nil))) |
| 416 | 414 | ||
diff --git a/lisp/gnus/nntp.el b/lisp/gnus/nntp.el index 990bb4426f4..624c64d4d75 100644 --- a/lisp/gnus/nntp.el +++ b/lisp/gnus/nntp.el | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | (eval-when-compile (require 'cl-lib)) | 36 | (eval-when-compile (require 'cl-lib)) |
| 37 | 37 | ||
| 38 | (autoload 'auth-source-search "auth-source") | 38 | (autoload 'auth-source-search "auth-source") |
| 39 | (autoload 'auth-info-password "auth-source") | ||
| 39 | 40 | ||
| 40 | (defgroup nntp nil | 41 | (defgroup nntp nil |
| 41 | "NNTP access for Gnus." | 42 | "NNTP access for Gnus." |
| @@ -1175,10 +1176,7 @@ If SEND-IF-FORCE, only send authinfo to the server if the | |||
| 1175 | "563" "nntps" "snews")))) | 1176 | "563" "nntps" "snews")))) |
| 1176 | (auth-user (plist-get auth-info :user)) | 1177 | (auth-user (plist-get auth-info :user)) |
| 1177 | (auth-force (plist-get auth-info :force)) | 1178 | (auth-force (plist-get auth-info :force)) |
| 1178 | (auth-passwd (plist-get auth-info :secret)) | 1179 | (auth-passwd (auth-info-password auth-info)) |
| 1179 | (auth-passwd (if (functionp auth-passwd) | ||
| 1180 | (funcall auth-passwd) | ||
| 1181 | auth-passwd)) | ||
| 1182 | (force (or (netrc-get alist "force") | 1180 | (force (or (netrc-get alist "force") |
| 1183 | nntp-authinfo-force | 1181 | nntp-authinfo-force |
| 1184 | auth-force)) | 1182 | auth-force)) |
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 55921eca685..3795377cd2b 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el | |||
| @@ -4489,10 +4489,7 @@ password." | |||
| 4489 | :max 1 :user user :host host | 4489 | :max 1 :user user :host host |
| 4490 | :require '(:secret))))) | 4490 | :require '(:secret))))) |
| 4491 | (if found | 4491 | (if found |
| 4492 | (let ((secret (plist-get found :secret))) | 4492 | (auth-info-password found) |
| 4493 | (if (functionp secret) | ||
| 4494 | (funcall secret) | ||
| 4495 | secret)) | ||
| 4496 | (read-passwd (if imap | 4493 | (read-passwd (if imap |
| 4497 | "IMAP password: " | 4494 | "IMAP password: " |
| 4498 | "POP password: ")))))) | 4495 | "POP password: ")))))) |
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el index 8ac0cd7e7c0..88e55e968c4 100644 --- a/lisp/mail/smtpmail.el +++ b/lisp/mail/smtpmail.el | |||
| @@ -554,11 +554,9 @@ for `smtpmail-try-auth-method'.") | |||
| 554 | :create ask-for-password))) | 554 | :create ask-for-password))) |
| 555 | (mech (or (plist-get auth-info :smtp-auth) (car mechs))) | 555 | (mech (or (plist-get auth-info :smtp-auth) (car mechs))) |
| 556 | (user (plist-get auth-info :user)) | 556 | (user (plist-get auth-info :user)) |
| 557 | (password (plist-get auth-info :secret)) | 557 | (password (auth-info-password auth-info)) |
| 558 | (save-function (and ask-for-password | 558 | (save-function (and ask-for-password |
| 559 | (plist-get auth-info :save-function)))) | 559 | (plist-get auth-info :save-function)))) |
| 560 | (when (functionp password) | ||
| 561 | (setq password (funcall password))) | ||
| 562 | (when (and user | 560 | (when (and user |
| 563 | (not password)) | 561 | (not password)) |
| 564 | ;; The user has stored the user name, but not the password, so | 562 | ;; The user has stored the user name, but not the password, so |
| @@ -573,9 +571,7 @@ for `smtpmail-try-auth-method'.") | |||
| 573 | :user smtpmail-smtp-user | 571 | :user smtpmail-smtp-user |
| 574 | :require '(:user :secret) | 572 | :require '(:user :secret) |
| 575 | :create t)) | 573 | :create t)) |
| 576 | password (plist-get auth-info :secret))) | 574 | password (auth-info-password auth-info))) |
| 577 | (when (functionp password) | ||
| 578 | (setq password (funcall password))) | ||
| 579 | (let ((result (catch 'done | 575 | (let ((result (catch 'done |
| 580 | (if (and mech user password) | 576 | (if (and mech user password) |
| 581 | (smtpmail-try-auth-method process mech user password) | 577 | (smtpmail-try-auth-method process mech user password) |
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index 9a1153b3c6a..9d1600ed72f 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el | |||
| @@ -560,8 +560,8 @@ If ARG is non-nil, instead prompt for connection parameters." | |||
| 560 | (auth (auth-source-search :host server | 560 | (auth (auth-source-search :host server |
| 561 | :user user-name | 561 | :user user-name |
| 562 | :port port)) | 562 | :port port)) |
| 563 | (fn (plist-get (car auth) :secret))) | 563 | (pwd (auth-info-password (car auth)))) |
| 564 | (setq password (funcall fn))) | 564 | (setq password pwd)) |
| 565 | (when server | 565 | (when server |
| 566 | (let (connected) | 566 | (let (connected) |
| 567 | (dolist (p (rcirc-process-list)) | 567 | (dolist (p (rcirc-process-list)) |
diff --git a/lisp/net/sieve-manage.el b/lisp/net/sieve-manage.el index 468bc90a9d7..50342b9105a 100644 --- a/lisp/net/sieve-manage.el +++ b/lisp/net/sieve-manage.el | |||
| @@ -79,6 +79,7 @@ | |||
| 79 | (require 'sasl) | 79 | (require 'sasl) |
| 80 | (autoload 'sasl-find-mechanism "sasl") | 80 | (autoload 'sasl-find-mechanism "sasl") |
| 81 | (autoload 'auth-source-search "auth-source") | 81 | (autoload 'auth-source-search "auth-source") |
| 82 | (autoload 'auth-info-password "auth-source") | ||
| 82 | 83 | ||
| 83 | ;; User customizable variables: | 84 | ;; User customizable variables: |
| 84 | 85 | ||
| @@ -230,10 +231,7 @@ Return the buffer associated with the connection." | |||
| 230 | :max 1 | 231 | :max 1 |
| 231 | :create t)) | 232 | :create t)) |
| 232 | (user-name (or (plist-get (nth 0 auth-info) :user) "")) | 233 | (user-name (or (plist-get (nth 0 auth-info) :user) "")) |
| 233 | (user-password (or (plist-get (nth 0 auth-info) :secret) "")) | 234 | (user-password (or (auth-info-password (nth 0 auth-info)) "")) |
| 234 | (user-password (if (functionp user-password) | ||
| 235 | (funcall user-password) | ||
| 236 | user-password)) | ||
| 237 | (client (sasl-make-client (sasl-find-mechanism (list mech)) | 235 | (client (sasl-make-client (sasl-find-mechanism (list mech)) |
| 238 | user-name "sieve" sieve-manage-server)) | 236 | user-name "sieve" sieve-manage-server)) |
| 239 | (sasl-read-passphrase | 237 | (sasl-read-passphrase |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index adde443fdd6..fdbb78123df 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -5756,10 +5756,7 @@ Invokes `password-read' if available, `read-passwd' else." | |||
| 5756 | :create t)) | 5756 | :create t)) |
| 5757 | tramp-password-save-function | 5757 | tramp-password-save-function |
| 5758 | (plist-get auth-info :save-function) | 5758 | (plist-get auth-info :save-function) |
| 5759 | auth-passwd (plist-get auth-info :secret))) | 5759 | auth-passwd (auth-info-password auth-info)))) |
| 5760 | (while (functionp auth-passwd) | ||
| 5761 | (setq auth-passwd (funcall auth-passwd))) | ||
| 5762 | auth-passwd) | ||
| 5763 | 5760 | ||
| 5764 | ;; Try the password cache. | 5761 | ;; Try the password cache. |
| 5765 | (progn | 5762 | (progn |