emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2008777 2/2: Search for host/port combinations in a


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 2008777 2/2: Search for host/port combinations in auth-source on OS X
Date: Sat, 06 Feb 2016 06:18:38 +0000

branch: master
commit 20087772d63192a2ef443cc2ea6ac48423db5ed6
Author: Martin Jesper Low Madsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Search for host/port combinations in auth-source on OS X
    
    * lisp/gnus/auth-source.el (auth-source-macos-keychain-search):
    Search for all host/port (or protocol) combinations for a match in
    the OS X keychain.
---
 lisp/gnus/auth-source.el |   34 +++++++++++++++++++++++++---------
 1 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el
index 52765ce..da3d670 100644
--- a/lisp/gnus/auth-source.el
+++ b/lisp/gnus/auth-source.el
@@ -1715,12 +1715,13 @@ entries for git.gnus.org:
 
   (let* ((coll (oref backend source))
          (max (or max 5000))     ; sanity check: default to stop at 5K
-         (ignored-keys '(:create :delete :max :backend :label))
+         ;; Filter out ignored keys from the spec
+         (ignored-keys '(:create :delete :max :backend :label :host :port))
+         ;; Build a search spec without the ignored keys
          (search-keys (loop for i below (length spec) by 2
                             unless (memq (nth i spec) ignored-keys)
                             collect (nth i spec)))
-         ;; build a search spec without the ignored keys
-         ;; if a search key is nil or t (match anything), we skip it
+         ;; If a search key value is nil or t (match anything), we skip it
          (search-spec (apply #'append (mapcar
                                       (lambda (k)
                                         (if (or (null (plist-get spec k))
@@ -1732,11 +1733,25 @@ entries for git.gnus.org:
          (returned-keys (mm-delete-duplicates (append
                                                '(:host :login :port :secret)
                                                search-keys)))
-         (items (apply #'auth-source-macos-keychain-search-items
-                       coll
-                       type
-                       max
-                       search-spec))
+         ;; Extract host and port from spec
+         (hosts (plist-get spec :host))
+         (hosts (if (and hosts (listp hosts)) hosts `(,hosts)))
+         (ports (plist-get spec :port))
+         (ports (if (and ports (listp ports)) ports `(,ports)))
+         ;; Loop through all combinations of host/port and pass each of these 
to
+         ;; auth-source-macos-keychain-search-items
+         (items (catch 'match
+                  (dolist (host hosts)
+                    (dolist (port ports)
+                      (let* ((port (format "%S" port))
+                             (items (apply 
#'auth-source-macos-keychain-search-items
+                                           coll
+                                           type
+                                           max
+                                           host port
+                                           search-spec)))
+                        (when items
+                          (throw 'match items)))))))
 
          ;; ensure each item has each key in `returned-keys'
          (items (mapcar (lambda (plist)
@@ -1752,8 +1767,9 @@ entries for git.gnus.org:
     items))
 
 (defun* auth-source-macos-keychain-search-items (coll _type _max
+                                                      host port
                                                       &key label type
-                                                      host user port
+                                                      user
                                                       &allow-other-keys)
 
   (let* ((keychain-generic (eq type 'macos-keychain-generic))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]