aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/auth-source.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/auth-source.el')
-rw-r--r--lisp/auth-source.el77
1 files changed, 37 insertions, 40 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 2494040457b..14cae8a52c7 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -581,14 +581,15 @@ default value. If the user, host, or port are missing, the alist
581`auth-source-creation-prompts' will be used to look up the 581`auth-source-creation-prompts' will be used to look up the
582prompts IN THAT ORDER (so the `user' prompt will be queried first, 582prompts IN THAT ORDER (so the `user' prompt will be queried first,
583then `host', then `port', and finally `secret'). Each prompt string 583then `host', then `port', and finally `secret'). Each prompt string
584can use %u, %h, and %p to show the user, host, and port. 584can use %u, %h, and %p to show the user, host, and port. The prompt
585is formatted with `format-prompt', a trailing \": \" is removed.
585 586
586Here's an example: 587Here's an example:
587 588
588\(let ((auth-source-creation-defaults \\='((user . \"defaultUser\") 589\(let ((auth-source-creation-defaults \\='((user . \"defaultUser\")
589 (A . \"default A\"))) 590 (A . \"default A\")))
590 (auth-source-creation-prompts 591 (auth-source-creation-prompts
591 \\='((secret . \"Enter IMAP password for %h:%p: \")))) 592 \\='((secret . \"Enter IMAP password for %h:%p\"))))
592 (auth-source-search :host \\='(\"nonesuch\" \"twosuch\") :type \\='netrc :max 1 593 (auth-source-search :host \\='(\"nonesuch\" \"twosuch\") :type \\='netrc :max 1
593 :P \"pppp\" :Q \"qqqq\" 594 :P \"pppp\" :Q \"qqqq\"
594 :create \\='(A B Q))) 595 :create \\='(A B Q)))
@@ -860,7 +861,9 @@ while \(:host t) would find all host entries."
860 secret))) 861 secret)))
861 862
862(defun auth-source-format-prompt (prompt alist) 863(defun auth-source-format-prompt (prompt alist)
863 "Format PROMPT using %x (for any character x) specifiers in ALIST." 864 "Format PROMPT using %x (for any character x) specifiers in ALIST.
865Remove trailing \": \"."
866 (setq prompt (replace-regexp-in-string ":\\s-*$" "" prompt))
864 (dolist (cell alist) 867 (dolist (cell alist)
865 (let ((c (nth 0 cell)) 868 (let ((c (nth 0 cell))
866 (v (nth 1 cell))) 869 (v (nth 1 cell)))
@@ -1344,11 +1347,11 @@ See `auth-source-search' for details on SPEC."
1344 "[any port]")))) 1347 "[any port]"))))
1345 (prompt (or (auth-source--aget auth-source-creation-prompts r) 1348 (prompt (or (auth-source--aget auth-source-creation-prompts r)
1346 (cl-case r 1349 (cl-case r
1347 (secret "%p password for %u@%h: ") 1350 (secret "%p password for %u@%h")
1348 (user "%p user name for %h: ") 1351 (user "%p user name for %h")
1349 (host "%p host name for user %u: ") 1352 (host "%p host name for user %u")
1350 (port "%p port for %u@%h: ")) 1353 (port "%p port for %u@%h"))
1351 (format "Enter %s (%%u@%%h:%%p): " r))) 1354 (format "Enter %s (%%u@%%h:%%p)" r)))
1352 (prompt (auth-source-format-prompt 1355 (prompt (auth-source-format-prompt
1353 prompt 1356 prompt
1354 `((?u ,(auth-source--aget printable-defaults 'user)) 1357 `((?u ,(auth-source--aget printable-defaults 'user))
@@ -1378,7 +1381,9 @@ See `auth-source-search' for details on SPEC."
1378 (setq check nil))) 1381 (setq check nil)))
1379 ret)) 1382 ret))
1380 (t 'never))) 1383 (t 'never)))
1381 (plain (or (eval default) (read-passwd prompt)))) 1384 (plain
1385 (or (eval default)
1386 (read-passwd (format-prompt prompt nil)))))
1382 ;; ask if we don't know what to do (in which case 1387 ;; ask if we don't know what to do (in which case
1383 ;; auth-source-netrc-use-gpg-tokens must be a list) 1388 ;; auth-source-netrc-use-gpg-tokens must be a list)
1384 (unless gpg-encrypt 1389 (unless gpg-encrypt
@@ -1390,12 +1395,9 @@ See `auth-source-search' for details on SPEC."
1390 (if (eq gpg-encrypt 'gpg) 1395 (if (eq gpg-encrypt 'gpg)
1391 (auth-source-epa-make-gpg-token plain file) 1396 (auth-source-epa-make-gpg-token plain file)
1392 plain)) 1397 plain))
1393 (if (stringp default) 1398 (if (and (stringp default) auth-source-save-behavior)
1394 (read-string (if (string-match ": *\\'" prompt) 1399 (read-string
1395 (concat (substring prompt 0 (match-beginning 0)) 1400 (format-prompt prompt default) nil nil default)
1396 " (default " default "): ")
1397 (concat prompt "(default " default ") "))
1398 nil nil default)
1399 (eval default))))) 1401 (eval default)))))
1400 1402
1401 (when data 1403 (when data
@@ -1745,12 +1747,12 @@ authentication tokens:
1745 "[any label]")))) 1747 "[any label]"))))
1746 (prompt (or (auth-source--aget auth-source-creation-prompts r) 1748 (prompt (or (auth-source--aget auth-source-creation-prompts r)
1747 (cl-case r 1749 (cl-case r
1748 (secret "%p password for %u@%h: ") 1750 (secret "%p password for %u@%h")
1749 (user "%p user name for %h: ") 1751 (user "%p user name for %h")
1750 (host "%p host name for user %u: ") 1752 (host "%p host name for user %u")
1751 (port "%p port for %u@%h: ") 1753 (port "%p port for %u@%h")
1752 (label "Enter label for %u@%h: ")) 1754 (label "Enter label for %u@%h"))
1753 (format "Enter %s (%%u@%%h:%%p): " r))) 1755 (format "Enter %s (%%u@%%h:%%p)" r)))
1754 (prompt (auth-source-format-prompt 1756 (prompt (auth-source-format-prompt
1755 prompt 1757 prompt
1756 `((?u ,(auth-source--aget printable-defaults 'user)) 1758 `((?u ,(auth-source--aget printable-defaults 'user))
@@ -1760,13 +1762,11 @@ authentication tokens:
1760 ;; Store the data, prompting for the password if needed. 1762 ;; Store the data, prompting for the password if needed.
1761 (setq data (or data 1763 (setq data (or data
1762 (if (eq r 'secret) 1764 (if (eq r 'secret)
1763 (or (eval default) (read-passwd prompt)) 1765 (or (eval default)
1764 (if (stringp default) 1766 (read-passwd (format-prompt prompt nil)))
1765 (read-string (if (string-match ": *\\'" prompt) 1767 (if (and (stringp default) auth-source-save-behavior)
1766 (concat (substring prompt 0 (match-beginning 0)) 1768 (read-string
1767 " (default " default "): ") 1769 (format-prompt prompt default) nil nil default)
1768 (concat prompt "(default " default ") "))
1769 nil nil default)
1770 (eval default))))) 1770 (eval default)))))
1771 1771
1772 (when data 1772 (when data
@@ -2190,11 +2190,11 @@ entries for git.gnus.org:
2190 "[any port]")))) 2190 "[any port]"))))
2191 (prompt (or (auth-source--aget auth-source-creation-prompts r) 2191 (prompt (or (auth-source--aget auth-source-creation-prompts r)
2192 (cl-case r 2192 (cl-case r
2193 (secret "%p password for %u@%h: ") 2193 (secret "%p password for %u@%h")
2194 (user "%p user name for %h: ") 2194 (user "%p user name for %h")
2195 (host "%p host name for user %u: ") 2195 (host "%p host name for user %u")
2196 (port "%p port for %u@%h: ")) 2196 (port "%p port for %u@%h"))
2197 (format "Enter %s (%%u@%%h:%%p): " r))) 2197 (format "Enter %s (%%u@%%h:%%p)" r)))
2198 (prompt (auth-source-format-prompt 2198 (prompt (auth-source-format-prompt
2199 prompt 2199 prompt
2200 `((?u ,(auth-source--aget printable-defaults 'user)) 2200 `((?u ,(auth-source--aget printable-defaults 'user))
@@ -2204,14 +2204,11 @@ entries for git.gnus.org:
2204 ;; Store the data, prompting for the password if needed. 2204 ;; Store the data, prompting for the password if needed.
2205 (setq data (or data 2205 (setq data (or data
2206 (if (eq r 'secret) 2206 (if (eq r 'secret)
2207 (or (eval default) (read-passwd prompt)) 2207 (or (eval default)
2208 (if (stringp default) 2208 (read-passwd (format-prompt prompt nil)))
2209 (if (and (stringp default) auth-source-save-behavior)
2209 (read-string 2210 (read-string
2210 (if (string-match ": *\\'" prompt) 2211 (format-prompt prompt default) nil nil default)
2211 (concat (substring prompt 0 (match-beginning 0))
2212 " (default " default "): ")
2213 (concat prompt "(default " default ") "))
2214 nil nil default)
2215 (eval default))))) 2212 (eval default)))))
2216 2213
2217 (when data 2214 (when data