From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/86448 Path: news.gmane.org!not-for-mail From: Martin Jesper Low Madsen Newsgroups: gmane.emacs.gnus.general Subject: [PATCH] Support host/port lists in auth-source OS X keychain search Date: Wed, 23 Dec 2015 01:43:14 +0100 Message-ID: <1450831394-46262-1-git-send-email-martin@martinjlowm.dk> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1450841143 8614 80.91.229.3 (23 Dec 2015 03:25:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Dec 2015 03:25:43 +0000 (UTC) Cc: Martin Jesper Low Madsen To: ding@gnus.org Original-X-From: ding-owner+M34680@lists.math.uh.edu Wed Dec 23 04:25:31 2015 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from lists1.math.uh.edu ([129.7.128.208]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aBa3O-0000l4-13 for ding-account@gmane.org; Wed, 23 Dec 2015 04:25:30 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.85) (envelope-from ) id 1aBa2H-0007Wh-HV; Tue, 22 Dec 2015 21:24:21 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by lists1.math.uh.edu with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1aBXbZ-0006pV-4i for ding@lists.math.uh.edu; Tue, 22 Dec 2015 18:48:37 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.85) (envelope-from ) id 1aBXbX-0005ge-A9 for ding@lists.math.uh.edu; Tue, 22 Dec 2015 18:48:36 -0600 Original-Received: from mail-wm0-f65.google.com ([74.125.82.65]) by quimby.gnus.org with esmtps (TLS1.2:RSA_ARCFOUR_SHA1:128) (Exim 4.80) (envelope-from ) id 1aBXbV-0006zX-Ir for ding@gnus.org; Wed, 23 Dec 2015 01:48:33 +0100 Original-Received: by mail-wm0-f65.google.com with SMTP id u188so6491865wmu.0 for ; Tue, 22 Dec 2015 16:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martinjlowm-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=3tjFvwM0mAp80Uq0O75RlOSFkthEXHu9kWV6pKW8D00=; b=wDN/KL0kMrXk2FHcM8crAmBocA6jkca6gTpdIxb7GHbop2+qHDJDNePc44riqgPAhm NidAV9BeSIBTOJf3+bkDXOr55ZRGUo5rCcmbohU+z3I16qIR4mizbE1YD7BU154KGhzb SUyyj+YtqtmPponP8hUHHDUsG68XskFbcGlrtHwn1SSKs9kvK86uT86yt8DHdp9PnX2j vRQx5Pldo3qrOw059/XTih+9bv31ojEuwV1GdsC/9eyabBziddrXjDEYfAFphhIObBzk ligzEkiVrKOly71xXY4encUOCSDx1uMunF4UGMQNafcDlNHSiJJdfeBfGOrWHu08vuEw GzhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3tjFvwM0mAp80Uq0O75RlOSFkthEXHu9kWV6pKW8D00=; b=Jt3+DOfxKrWsvGjY+r/sGdhEdsPrWJLr/55vp6+8FQ69pZGTWHJ3JGVVH4/GpsQU5y 9I6L3p7V6wkLlPzojgXMCi9HUUe8kbML+zMPzs2A1KSWV3IlhoOpLpKWBuGpsT0Qi5Tl MDVgdd4CGifF4ndBDB20U6YrsTAYK7rlE+zowxFmzSToIy7fwAmaLgLBxca1/Ypxs2z4 PR1MltuEd6FWbBo+dftTUTWncU1S3YNeWx7HPZ8adMDsbe2tLFHmCwDXgmziv2QieNe6 GJ3UOLL4gEpTmVk6MUMeLByVr5LHaLWs6d5I8T68EEo3Yze43va3b9Ozwvia1WbFp5z+ Mm0A== X-Gm-Message-State: ALoCoQnMr+kxDcS3h9dAYIIX6LpDVbWfUDAiLAN1SveqLcJhkJxyJjKQystRKPHXRZxWtbF1nJIoqCVrRMRsavZggWe0y/Y/1Q== X-Received: by 10.28.1.202 with SMTP id 193mr22516713wmb.51.1450831707698; Tue, 22 Dec 2015 16:48:27 -0800 (PST) Original-Received: from localhost.localdomain (52d3c2a1.dynamic-ip.k-net.dk. [82.211.194.161]) by smtp.gmail.com with ESMTPSA id u12sm1195592wmu.10.2015.12.22.16.48.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Dec 2015 16:48:27 -0800 (PST) X-Mailer: git-send-email 2.3.3 X-Spam-Score: -2.9 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:86448 Archived-At: * 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