]> code.delx.au - gnu-emacs/blobdiff - lisp/gnus/auth-source.el
Fix encoding problem introduced by previous patch series
[gnu-emacs] / lisp / gnus / auth-source.el
index 9d842c04f642c235ef186cfee38123557759c995..32b39b924f9c4184b6dc6ee584351fb80dc68922 100644 (file)
@@ -1,6 +1,6 @@
 ;;; auth-source.el --- authentication sources for Gnus and Emacs
 
-;; Copyright (C) 2008-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2016 Free Software Foundation, Inc.
 
 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
 ;; Keywords: news
@@ -919,13 +919,15 @@ while \(:host t) would find all host entries."
   prompt)
 
 (defun auth-source-ensure-strings (values)
-  (unless (listp values)
-    (setq values (list values)))
-  (mapcar (lambda (value)
-            (if (numberp value)
-                (format "%s" value)
-              value))
-          values))
+  (if (eq values t)
+      values
+    (unless (listp values)
+      (setq values (list values)))
+    (mapcar (lambda (value)
+             (if (numberp value)
+                 (format "%s" value)
+               value))
+           values)))
 
 ;;; Backend specific parsing: netrc/authinfo backend
 
@@ -1599,9 +1601,9 @@ authentication tokens:
                                           (list k (plist-get spec k))))
                                       search-keys))))
          ;; needed keys (always including host, login, port, and secret)
-         (returned-keys (mm-delete-duplicates (append
-                                               '(:host :login :port :secret)
-                                               search-keys)))
+         (returned-keys (delete-dups (append
+                                     '(:host :login :port :secret)
+                                     search-keys)))
          (items
           (loop for search-spec in search-specs
                nconc
@@ -1713,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))
@@ -1727,14 +1730,28 @@ entries for git.gnus.org:
                                           (list k (plist-get spec k))))
                                       search-keys)))
          ;; needed keys (always including host, login, port, and secret)
-         (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))
+         (returned-keys (delete-dups (append
+                                     '(:host :login :port :secret)
+                                     search-keys)))
+         ;; 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)
@@ -1750,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))
@@ -1854,9 +1872,9 @@ entries for git.gnus.org:
                                             (list k v))))
                                       search-keys)))
          ;; needed keys (always including host, login, port, and secret)
-         (returned-keys (mm-delete-duplicates (append
-                                               '(:host :login :port :secret)
-                                               search-keys)))
+         (returned-keys (delete-dups (append
+                                     '(:host :login :port :secret)
+                                     search-keys)))
          (items (plstore-find store search-spec))
          (item-names (mapcar #'car items))
          (items (butlast items (- (length items) max)))