summaryrefslogtreecommitdiff
path: root/lisp/auth-source.el
diff options
context:
space:
mode:
authorSam Steingold <sds@gnu.org>2022-01-06 14:42:10 -0500
committerSam Steingold <sds@gnu.org>2022-01-07 14:48:59 -0500
commitad5cf84fa737d26ed12e75e09e5f079df0efe5f6 (patch)
tree0d437cdfc791c9742850118edfc8927a7992b76f /lisp/auth-source.el
parent19c6cad1821eb896b2ddd0f6eab030f0880ea254 (diff)
downloademacs-ad5cf84fa737d26ed12e75e09e5f079df0efe5f6.tar.gz
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).
Diffstat (limited to 'lisp/auth-source.el')
-rw-r--r--lisp/auth-source.el23
1 files changed, 11 insertions, 12 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."
(cl-return 'no)))
'no))))
-(defun auth-source-pick-first-password (&rest spec)
- "Pick the first secret found from applying SPEC to `auth-source-search'."
- (let* ((result (nth 0 (apply #'auth-source-search (plist-put spec :max 1))))
- (secret (plist-get result :secret)))
-
+(defun auth-info-password (auth-info)
+ "Return the :secret password from the AUTH-INFO."
+ (let ((secret (plist-get auth-info :secret)))
(if (functionp secret)
(funcall secret)
secret)))
+(defun auth-source-pick-first-password (&rest spec)
+ "Pick the first secret found from applying SPEC to `auth-source-search'."
+ (auth-info-password (car (apply #'auth-source-search (plist-put spec :max 1)))))
+
(defun auth-source-format-prompt (prompt alist)
"Format PROMPT using %x (for any character x) specifiers in ALIST.
Remove trailing \": \"."
@@ -1800,10 +1802,9 @@ authentication tokens:
(plist-put
artificial
:save-function
- (let* ((collection collection)
- (item (plist-get artificial :label))
- (secret (plist-get artificial :secret))
- (secret (if (functionp secret) (funcall secret) secret)))
+ (let ((collection collection)
+ (item (plist-get artificial :label))
+ (secret (auth-info-password artificial)))
(lambda ()
(auth-source-secrets-saver collection item secret args)))))
@@ -2410,9 +2411,7 @@ MODE can be \"login\" or \"password\"."
:require '(:user :secret)
:create nil))))
(user (plist-get auth-info :user))
- (password (plist-get auth-info :secret)))
- (when (functionp password)
- (setq password (funcall password)))
+ (password (auth-info-password auth-info)))
(list user password auth-info)))
;;; Tiny mode for editing .netrc/.authinfo modes (that basically just