Gnus development mailing list
 help / color / mirror / Atom feed
From: Martin Jesper Low Madsen <martin@martinjlowm.dk>
To: ding@gnus.org
Cc: Martin Jesper Low Madsen <martin@martinjlowm.dk>
Subject: [PATCH] Support host/port lists in auth-source OS X keychain search
Date: Wed, 23 Dec 2015 01:43:14 +0100	[thread overview]
Message-ID: <1450831394-46262-1-git-send-email-martin@martinjlowm.dk> (raw)

* lisp/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/auth-source.el | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 45ff3b7..8c634fa 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -1725,12 +1725,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))
@@ -1742,11 +1743,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)
@@ -1762,8 +1777,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))
-- 
2.3.3




             reply	other threads:[~2015-12-23  0:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-23  0:43 Martin Jesper Low Madsen [this message]
2016-02-06  6:17 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450831394-46262-1-git-send-email-martin@martinjlowm.dk \
    --to=martin@martinjlowm.dk \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).