X-Git-Url: https://cgit.sxemacs.org/?p=gnus;a=blobdiff_plain;f=lisp%2Fauth-source.el;h=caead4fabfaba53b5dfb1d00235b1cfd25959736;hp=89b2ef3d11dbad72a89380344347b63ad0bc42a9;hb=279d0ae06b909d067ce7f4a756a7872087adf667;hpb=667353f915c5b5aff65a9b0a81bc7da606ad3d7d diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 89b2ef3d1..caead4fab 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -32,9 +32,9 @@ ;;; Code: (require 'gnus-util) +(require 'netrc) (eval-when-compile (require 'cl)) -(autoload 'netrc-machine-user-or-password "netrc") (autoload 'secrets-create-item "secrets") (autoload 'secrets-delete-item "secrets") (autoload 'secrets-get-alias "secrets") @@ -107,7 +107,8 @@ Only relevant if `auth-source-debug' is not nil." :version "23.2" ;; No Gnus :type `boolean) -(defcustom auth-sources '((:source "~/.authinfo.gpg")) +(defcustom auth-sources '((:source "~/.authinfo.gpg") + (:source "~/.authinfo")) "List of authentication sources. The default will get login and password information from a .gpg @@ -229,7 +230,8 @@ matched as a regex." ;; Check keywords. (dolist (k keys match) (let* ((v (plist-get spec k)) - (choicev (plist-get choice k))) + (choicev (if (plist-member choice k) + (plist-get choice k) t))) (setq match (and match (or @@ -310,22 +312,41 @@ Return structure as specified by MODE." (setq result (mapcar (lambda (m) - (if (equal "password" m) - (let ((passwd (read-passwd "Password: "))) - (cond - ;; Secret Service API. - ((consp source) - (apply - 'secrets-create-item - (auth-get-source entry) name passwd spec)) - (t)) ;; netrc not implemented yes. - passwd) - (or - ;; the originally requested :user - user - "unknown-user"))) + (cons + m + (cond + ((equal "password" m) + (let ((passwd (read-passwd + (format "Password for %s on %s: " prot host)))) + (cond + ;; Secret Service API. + ((consp source) + (apply + 'secrets-create-item + (auth-get-source entry) name passwd spec)) + (t)) ;; netrc not implemented yes. + passwd)) + ((equal "login" m) + (or user + (read-string (format "User name for %s on %s: " prot host)))) + (t + "unknownuser")))) (if (consp mode) mode (list mode)))) - (if (consp mode) result (car result)))) + ;; Allow the source to save the data. + (cond + ((consp source) + ;; Secret Service API -- not implemented. + ) + (t + ;; netrc interface. + (when (y-or-n-p (format "Do you want to save this password in %s? " + source)) + (netrc-store-data source host prot + (or user (cdr (assoc "login" result))) + (cdr (assoc "password" result)))))) + (if (consp mode) + (mapcar #'cdr result) + (cdar result)))) (defun auth-source-delete (entry &rest spec) "Delete credentials according to SPEC in ENTRY." @@ -425,8 +446,12 @@ MODE can be \"login\" or \"password\"." (and found (return found))) ;; We haven't found something, so we will create it interactively. - (when (and (not found) choices create-missing) - (setq found (apply 'auth-source-create mode (car choices) search))) + (when (and (not found) create-missing) + (setq found (apply 'auth-source-create + mode (if choices + (car choices) + (car auth-sources)) + search))) ;; Cache the result. (when found @@ -464,5 +489,4 @@ MODE can be \"login\" or \"password\"." (provide 'auth-source) -;; arch-tag: ff1afe78-06e9-42c2-b693-e9f922cbe4ab ;;; auth-source.el ends here