Commit 35123c04 authored by Ted Zlatanov's avatar Ted Zlatanov Committed by Katsumi Yamaoka
Browse files

auth.texi (Help for users): Use :port instead of :protocol for all auth-source docs.

auth-source.el (auth-source-netrc-parse): Use :port instead of :protocol and accept a missing user, host, or port as a wildcard match.
 (auth-source-netrc-search, auth-source-netrc-create)
 (auth-source-secrets-search, auth-source-secrets-create)
 (auth-source-user-or-password, auth-source-backend, auth-sources)
 (auth-source-backend-parse-parameters, auth-source-search): Use :port instead of :protocol.
nnimap.el (nnimap-credentials): Pass a port default to `auth-source-search' in case an entry needs to be created.
 (nnimap-open-connection-1): Use :port instead of :protocol.
parent 73057ba9
2011-02-17 Teodor Zlatanov <tzz@lifelogs.com>
* auth.texi (Help for users): Use :port instead of :protocol for all
auth-source docs.
2011-02-16 Glenn Morris <rgm@gnu.org> 2011-02-16 Glenn Morris <rgm@gnu.org>
* dired-x.texi: Use emacsver.texi to get Emacs version. * dired-x.texi: Use emacsver.texi to get Emacs version.
......
...@@ -105,8 +105,7 @@ It's known as @var{:host} in @code{auth-source-search} queries. You ...@@ -105,8 +105,7 @@ It's known as @var{:host} in @code{auth-source-search} queries. You
can also use @code{host}. can also use @code{host}.
The @code{port} is the connection port or protocol. It's known as The @code{port} is the connection port or protocol. It's known as
@var{:port} in @code{auth-source-search} queries. You can also use @var{:port} in @code{auth-source-search} queries.
@code{protocol}.
The @code{user} is the user name. It's known as @var{:user} in The @code{user} is the user name. It's known as @var{:user} in
@code{auth-source-search} queries. You can also use @code{login} and @code{auth-source-search} queries. You can also use @code{login} and
...@@ -155,8 +154,8 @@ particular host and protocol. While you can get fancy, the default ...@@ -155,8 +154,8 @@ particular host and protocol. While you can get fancy, the default
and simplest configuration is: and simplest configuration is:
@lisp @lisp
;;; old default: required :host and :protocol, not needed anymore ;;; old default: required :host and :port, not needed anymore
(setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t))) (setq auth-sources '((:source "~/.authinfo.gpg" :host t :port t)))
;;; mostly equivalent (see below about fallbacks) but shorter: ;;; mostly equivalent (see below about fallbacks) but shorter:
(setq auth-sources '((:source "~/.authinfo.gpg"))) (setq auth-sources '((:source "~/.authinfo.gpg")))
;;; even shorter and the @emph{default}: ;;; even shorter and the @emph{default}:
......
2011-02-17 Teodor Zlatanov <tzz@lifelogs.com>
* auth-source.el (auth-source-netrc-parse): Use :port instead of
:protocol and accept a missing user, host, or port as a wildcard match.
(auth-source-netrc-search, auth-source-netrc-create)
(auth-source-secrets-search, auth-source-secrets-create)
(auth-source-user-or-password, auth-source-backend, auth-sources)
(auth-source-backend-parse-parameters, auth-source-search): Use :port
instead of :protocol.
* nnimap.el (nnimap-credentials): Pass a port default to
`auth-source-search' in case an entry needs to be created.
(nnimap-open-connection-1): Use :port instead of :protocol.
2011-02-17 Katsumi Yamaoka <yamaoka@jpl.org> 2011-02-17 Katsumi Yamaoka <yamaoka@jpl.org>
   
* auth-source.el (auth-source-secrets-search): Use mm-delete-duplicates * auth-source.el (auth-source-secrets-search): Use mm-delete-duplicates
......
...@@ -94,7 +94,7 @@ let-binding." ...@@ -94,7 +94,7 @@ let-binding."
:type t :type t
:custom string :custom string
:documentation "The backend user.") :documentation "The backend user.")
(protocol :initarg :protocol (port :initarg :port
:initform t :initform t
:type t :type t
:custom string :custom string
...@@ -213,7 +213,7 @@ can get pretty complex." ...@@ -213,7 +213,7 @@ can get pretty complex."
:tag "Regular expression"))) :tag "Regular expression")))
(list (list
:tag "Protocol" :tag "Protocol"
(const :format "" :value :protocol) (const :format "" :value :port)
(choice (choice
:tag "Protocol" :tag "Protocol"
(const :tag "Any" t) (const :tag "Any" t)
...@@ -266,19 +266,19 @@ If the value is not a list, symmetric encryption will be used." ...@@ -266,19 +266,19 @@ If the value is not a list, symmetric encryption will be used."
msg)) msg))
;; (auth-source-pick nil :host "any" :protocol 'imap :user "joe") ;; (auth-source-pick nil :host "any" :port 'imap :user "joe")
;; (auth-source-pick t :host "any" :protocol 'imap :user "joe") ;; (auth-source-pick t :host "any" :port 'imap :user "joe")
;; (setq auth-sources '((:source (:secrets default) :host t :protocol t :user "joe") ;; (setq auth-sources '((:source (:secrets default) :host t :port t :user "joe")
;; (:source (:secrets "session") :host t :protocol t :user "joe") ;; (:source (:secrets "session") :host t :port t :user "joe")
;; (:source (:secrets "Login") :host t :protocol t) ;; (:source (:secrets "Login") :host t :port t)
;; (:source "~/.authinfo.gpg" :host t :protocol t))) ;; (:source "~/.authinfo.gpg" :host t :port t)))
;; (setq auth-sources '((:source (:secrets default) :host t :protocol t :user "joe") ;; (setq auth-sources '((:source (:secrets default) :host t :port t :user "joe")
;; (:source (:secrets "session") :host t :protocol t :user "joe") ;; (:source (:secrets "session") :host t :port t :user "joe")
;; (:source (:secrets "Login") :host t :protocol t) ;; (:source (:secrets "Login") :host t :port t)
;; )) ;; ))
;; (setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t))) ;; (setq auth-sources '((:source "~/.authinfo.gpg" :host t :port t)))
;; (auth-source-backend-parse "myfile.gpg") ;; (auth-source-backend-parse "myfile.gpg")
;; (auth-source-backend-parse 'default) ;; (auth-source-backend-parse 'default)
...@@ -355,8 +355,8 @@ If the value is not a list, symmetric encryption will be used." ...@@ -355,8 +355,8 @@ If the value is not a list, symmetric encryption will be used."
(defun auth-source-backend-parse-parameters (entry backend) (defun auth-source-backend-parse-parameters (entry backend)
"Fills in the extra auth-source-backend parameters of ENTRY. "Fills in the extra auth-source-backend parameters of ENTRY.
Using the plist ENTRY, get the :host, :protocol, and :user search Using the plist ENTRY, get the :host, :port, and :user search
parameters. Accepts :port as an alias to :protocol." parameters."
(let ((entry (if (stringp entry) (let ((entry (if (stringp entry)
nil nil
entry)) entry))
...@@ -365,15 +365,14 @@ parameters. Accepts :port as an alias to :protocol." ...@@ -365,15 +365,14 @@ parameters. Accepts :port as an alias to :protocol."
(oset backend host val)) (oset backend host val))
(when (setq val (plist-get entry :user)) (when (setq val (plist-get entry :user))
(oset backend user val)) (oset backend user val))
;; accept :port as an alias for :protocol (when (setq val (plist-get entry :port))
(when (setq val (or (plist-get entry :protocol) (plist-get entry :port))) (oset backend port val)))
(oset backend protocol val)))
backend) backend)
;; (mapcar 'auth-source-backend-parse auth-sources) ;; (mapcar 'auth-source-backend-parse auth-sources)
(defun* auth-source-search (&rest spec (defun* auth-source-search (&rest spec
&key type max host user protocol secret &key type max host user port secret
create delete create delete
&allow-other-keys) &allow-other-keys)
"Search or modify authentication backends according to SPEC. "Search or modify authentication backends according to SPEC.
...@@ -386,7 +385,7 @@ other properties will always hold scalar values. ...@@ -386,7 +385,7 @@ other properties will always hold scalar values.
Typically the :secret property, if present, contains a password. Typically the :secret property, if present, contains a password.
Common search keys are :max, :host, :protocol, and :user. In Common search keys are :max, :host, :port, and :user. In
addition, :create specifies how tokens will be or created. addition, :create specifies how tokens will be or created.
Finally, :type can specify which backend types you want to check. Finally, :type can specify which backend types you want to check.
...@@ -400,7 +399,7 @@ any of the search terms matches). ...@@ -400,7 +399,7 @@ any of the search terms matches).
A new token will be created if no matching tokens were found. A new token will be created if no matching tokens were found.
The new token will have only the keys the backend requires. For The new token will have only the keys the backend requires. For
the netrc backend, for instance, that's the user, host, and the netrc backend, for instance, that's the user, host, and
protocol keys. port keys.
Here's an example: Here's an example:
...@@ -416,11 +415,11 @@ which says: ...@@ -416,11 +415,11 @@ which says:
'netrc', maximum one result. 'netrc', maximum one result.
Create a new entry if you found none. The netrc backend will Create a new entry if you found none. The netrc backend will
automatically require host, user, and protocol. The host will be automatically require host, user, and port. The host will be
'mine'. We prompt for the user with default 'defaultUser' and 'mine'. We prompt for the user with default 'defaultUser' and
for the protocol without a default. We will not prompt for A, Q, for the port without a default. We will not prompt for A, Q,
or P. The resulting token will only have keys user, host, and or P. The resulting token will only have keys user, host, and
protocol.\" port.\"
:create '(A B C) also means to create a token if possible. :create '(A B C) also means to create a token if possible.
...@@ -445,11 +444,11 @@ which says: ...@@ -445,11 +444,11 @@ which says:
or 'twosuch' in backends of type 'netrc', maximum one result. or 'twosuch' in backends of type 'netrc', maximum one result.
Create a new entry if you found none. The netrc backend will Create a new entry if you found none. The netrc backend will
automatically require host, user, and protocol. The host will be automatically require host, user, and port. The host will be
'nonesuch' and Q will be 'qqqq'. We prompt for A with default 'nonesuch' and Q will be 'qqqq'. We prompt for A with default
'default A', for B and protocol with default nil, and for the 'default A', for B and port with default nil, and for the
user with default 'defaultUser'. We will not prompt for Q. The user with default 'defaultUser'. We will not prompt for Q. The
resulting token will have keys user, host, protocol, A, B, and Q. resulting token will have keys user, host, port, A, B, and Q.
It will not have P with any value, even though P is used in the It will not have P with any value, even though P is used in the
search to find only entries that have P set to 'pppp'.\" search to find only entries that have P set to 'pppp'.\"
...@@ -481,14 +480,14 @@ the match rules above. Defaults to t. ...@@ -481,14 +480,14 @@ the match rules above. Defaults to t.
:user (X Y Z) means to match only users X, Y, or Z according to :user (X Y Z) means to match only users X, Y, or Z according to
the match rules above. Defaults to t. the match rules above. Defaults to t.
:protocol (P Q R) means to match only protocols P, Q, or R. :port (P Q R) means to match only protocols P, Q, or R.
Defaults to t. Defaults to t.
:K (V1 V2 V3) for any other key K will match values V1, V2, or :K (V1 V2 V3) for any other key K will match values V1, V2, or
V3 (note the match rules above). V3 (note the match rules above).
The return value is a list with at most :max tokens. Each token The return value is a list with at most :max tokens. Each token
is a plist with keys :backend :host :protocol :user, plus any other is a plist with keys :backend :host :port :user, plus any other
keys provided by the backend (notably :secret). But note the keys provided by the backend (notably :secret). But note the
exception for :max 0, which see above. exception for :max 0, which see above.
...@@ -662,7 +661,7 @@ while \(:host t) would find all host entries." ...@@ -662,7 +661,7 @@ while \(:host t) would find all host entries."
;;; (auth-source-netrc-parse "~/.authinfo.gpg") ;;; (auth-source-netrc-parse "~/.authinfo.gpg")
(defun* auth-source-netrc-parse (&rest (defun* auth-source-netrc-parse (&rest
spec spec
&key file max host user protocol delete &key file max host user port delete
&allow-other-keys) &allow-other-keys)
"Parse FILE and return a list of all entries in the file. "Parse FILE and return a list of all entries in the file.
Note that the MAX parameter is used so we can exit the parse early." Note that the MAX parameter is used so we can exit the parse early."
...@@ -724,18 +723,21 @@ Note that the MAX parameter is used so we can exit the parse early." ...@@ -724,18 +723,21 @@ Note that the MAX parameter is used so we can exit the parse early."
host host
(or (or
(aget alist "machine") (aget alist "machine")
(aget alist "host"))) (aget alist "host")
t))
(auth-source-search-collection (auth-source-search-collection
user user
(or (or
(aget alist "login") (aget alist "login")
(aget alist "account") (aget alist "account")
(aget alist "user"))) (aget alist "user")
t))
(auth-source-search-collection (auth-source-search-collection
protocol port
(or (or
(aget alist "port") (aget alist "port")
(aget alist "protocol")))) (aget alist "protocol")
t)))
(decf max) (decf max)
(push (nreverse alist) result) (push (nreverse alist) result)
;; to delete a line, we just comment it out ;; to delete a line, we just comment it out
...@@ -801,7 +803,7 @@ Note that the MAX parameter is used so we can exit the parse early." ...@@ -801,7 +803,7 @@ Note that the MAX parameter is used so we can exit the parse early."
(defun* auth-source-netrc-search (&rest (defun* auth-source-netrc-search (&rest
spec spec
&key backend create delete &key backend create delete
type max host user protocol type max host user port
&allow-other-keys) &allow-other-keys)
"Given a property list SPEC, return search matches from the :backend. "Given a property list SPEC, return search matches from the :backend.
See `auth-source-search' for details on SPEC." See `auth-source-search' for details on SPEC."
...@@ -816,7 +818,7 @@ See `auth-source-search' for details on SPEC." ...@@ -816,7 +818,7 @@ See `auth-source-search' for details on SPEC."
:file (oref backend source) :file (oref backend source)
:host (or host t) :host (or host t)
:user (or user t) :user (or user t)
:protocol (or protocol t))))) :port (or port t)))))
;; if we need to create an entry AND none were found to match ;; if we need to create an entry AND none were found to match
(when (and create (when (and create
...@@ -840,9 +842,9 @@ See `auth-source-search' for details on SPEC." ...@@ -840,9 +842,9 @@ See `auth-source-search' for details on SPEC."
(defun* auth-source-netrc-create (&rest spec (defun* auth-source-netrc-create (&rest spec
&key backend &key backend
secret host user protocol create secret host user port create
&allow-other-keys) &allow-other-keys)
(let* ((base-required '(host user protocol secret)) (let* ((base-required '(host user port secret))
;; we know (because of an assertion in auth-source-search) that the ;; we know (because of an assertion in auth-source-search) that the
;; :create parameter is either t or a list (which includes nil) ;; :create parameter is either t or a list (which includes nil)
(create-extra (if (eq t create) nil create)) (create-extra (if (eq t create) nil create))
...@@ -881,7 +883,7 @@ See `auth-source-search' for details on SPEC." ...@@ -881,7 +883,7 @@ See `auth-source-search' for details on SPEC."
((and (not given-default) (eq r 'user)) ((and (not given-default) (eq r 'user))
(user-login-name)) (user-login-name))
;; note we need this empty string ;; note we need this empty string
((and (not given-default) (eq r 'protocol)) ((and (not given-default) (eq r 'port))
"") "")
(t given-default))) (t given-default)))
;; the prompt's default string depends on the data so far ;; the prompt's default string depends on the data so far
...@@ -891,20 +893,20 @@ See `auth-source-search' for details on SPEC." ...@@ -891,20 +893,20 @@ See `auth-source-search' for details on SPEC."
;; the prompt should also show what's entered so far ;; the prompt should also show what's entered so far
(user-value (aget valist 'user)) (user-value (aget valist 'user))
(host-value (aget valist 'host)) (host-value (aget valist 'host))
(protocol-value (aget valist 'protocol)) (port-value (aget valist 'port))
(info-so-far (concat (if user-value (info-so-far (concat (if user-value
(format "%s@" user-value) (format "%s@" user-value)
"[USER?]") "[USER?]")
(if host-value (if host-value
(format "%s" host-value) (format "%s" host-value)
"[HOST?]") "[HOST?]")
(if protocol-value (if port-value
;; this distinguishes protocol between ;; this distinguishes protocol between
(if (zerop (length protocol-value)) (if (zerop (length port-value))
"" ; 'entered as "no default"' vs. "" ; 'entered as "no default"' vs.
(format ":%s" protocol-value)) ; given (format ":%s" port-value)) ; given
;; and this is when the protocol is unknown ;; and this is when the protocol is unknown
"[PROTOCOL?]")))) "[PORT?]"))))
;; now prompt if the search SPEC did not include a required key; ;; now prompt if the search SPEC did not include a required key;
;; take the result and put it in `data' AND store it in `valist' ;; take the result and put it in `data' AND store it in `valist'
...@@ -942,7 +944,7 @@ See `auth-source-search' for details on SPEC." ...@@ -942,7 +944,7 @@ See `auth-source-search' for details on SPEC."
('user "login") ('user "login")
('host "machine") ('host "machine")
('secret "password") ('secret "password")
('protocol "port") ('port "port") ; redundant but clearer
(t (symbol-name r))) (t (symbol-name r)))
;; the value will be printed in %S format ;; the value will be printed in %S format
data)))))) data))))))
...@@ -986,7 +988,7 @@ See `auth-source-search' for details on SPEC." ...@@ -986,7 +988,7 @@ See `auth-source-search' for details on SPEC."
(defun* auth-source-secrets-search (&rest (defun* auth-source-secrets-search (&rest
spec spec
&key backend create delete label &key backend create delete label
type max host user protocol type max host user port
&allow-other-keys) &allow-other-keys)
"Search the Secrets API; spec is like `auth-source'. "Search the Secrets API; spec is like `auth-source'.
...@@ -1042,9 +1044,9 @@ authentication tokens: ...@@ -1042,9 +1044,9 @@ authentication tokens:
nil nil
(list k (plist-get spec k)))) (list k (plist-get spec k))))
search-keys))) search-keys)))
;; needed keys (always including host, login, protocol, and secret) ;; needed keys (always including host, login, port, and secret)
(returned-keys (mm-delete-duplicates (append (returned-keys (mm-delete-duplicates (append
'(:host :login :protocol :secret) '(:host :login :port :secret)
search-keys))) search-keys)))
(items (loop for item in (apply 'secrets-search-items coll search-spec) (items (loop for item in (apply 'secrets-search-items coll search-spec)
unless (and (stringp label) unless (and (stringp label)
...@@ -1081,7 +1083,7 @@ authentication tokens: ...@@ -1081,7 +1083,7 @@ authentication tokens:
(defun* auth-source-secrets-create (&rest (defun* auth-source-secrets-create (&rest
spec spec
&key backend type max host user protocol &key backend type max host user port
&allow-other-keys) &allow-other-keys)
;; TODO ;; TODO
;; (apply 'secrets-create-item (auth-get-source entry) name passwd spec) ;; (apply 'secrets-create-item (auth-get-source entry) name passwd spec)
...@@ -1098,8 +1100,8 @@ authentication tokens: ...@@ -1098,8 +1100,8 @@ authentication tokens:
'auth-source-forget "Emacs 24.1") 'auth-source-forget "Emacs 24.1")
(defun auth-source-user-or-password (defun auth-source-user-or-password
(mode host protocol &optional username create-missing delete-existing) (mode host port &optional username create-missing delete-existing)
"Find MODE (string or list of strings) matching HOST and PROTOCOL. "Find MODE (string or list of strings) matching HOST and PORT.
DEPRECATED in favor of `auth-source-search'! DEPRECATED in favor of `auth-source-search'!
...@@ -1122,14 +1124,14 @@ stored in the password database which matches best (see ...@@ -1122,14 +1124,14 @@ stored in the password database which matches best (see
MODE can be \"login\" or \"password\"." MODE can be \"login\" or \"password\"."
(auth-source-do-debug (auth-source-do-debug
"auth-source-user-or-password: DEPRECATED get %s for %s (%s) + user=%s" "auth-source-user-or-password: DEPRECATED get %s for %s (%s) + user=%s"
mode host protocol username) mode host port username)
(let* ((listy (listp mode)) (let* ((listy (listp mode))
(mode (if listy mode (list mode))) (mode (if listy mode (list mode)))
(cname (if username (cname (if username
(format "%s %s:%s %s" mode host protocol username) (format "%s %s:%s %s" mode host port username)
(format "%s %s:%s" mode host protocol))) (format "%s %s:%s" mode host port)))
(search (list :host host :protocol protocol)) (search (list :host host :port port))
(search (if username (append search (list :user username)) search)) (search (if username (append search (list :user username)) search))
(search (if create-missing (search (if create-missing
(append search (list :create t)) (append search (list :create t))
...@@ -1151,7 +1153,7 @@ MODE can be \"login\" or \"password\"." ...@@ -1151,7 +1153,7 @@ MODE can be \"login\" or \"password\"."
(if (and (member "password" mode) t) (if (and (member "password" mode) t)
"SECRET" "SECRET"
found) found)
host protocol username) host port username)
found) ; return the found data found) ; return the found data
;; else, if not found, search with a max of 1 ;; else, if not found, search with a max of 1
(let ((choice (nth 0 (apply 'auth-source-search (let ((choice (nth 0 (apply 'auth-source-search
......
...@@ -277,7 +277,8 @@ textual parts.") ...@@ -277,7 +277,8 @@ textual parts.")
(current-buffer))) (current-buffer)))
(defun nnimap-credentials (address ports) (defun nnimap-credentials (address ports)
(let* ((found (nth 0 (auth-source-search :max 1 (let* ((auth-source-creation-defaults `((port . ,(nth 0 ports))))
(found (nth 0 (auth-source-search :max 1
:host address :host address
:port ports :port ports
:create t))) :create t)))
...@@ -398,7 +399,7 @@ textual parts.") ...@@ -398,7 +399,7 @@ textual parts.")
(dolist (host (list (nnoo-current-server 'nnimap) (dolist (host (list (nnoo-current-server 'nnimap)
nnimap-address)) nnimap-address))
(dolist (port ports) (dolist (port ports)
(auth-source-forget+ :host host :protocol port))) (auth-source-forget+ :host host :port port)))
(delete-process (nnimap-process nnimap-object)) (delete-process (nnimap-process nnimap-object))
(setq nnimap-object nil)))) (setq nnimap-object nil))))
(when nnimap-object (when nnimap-object
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment