emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r116522: Build correct secrets pattern from auth-sou


From: Daniel Colascione
Subject: [Emacs-diffs] trunk r116522: Build correct secrets pattern from auth-source pattern
Date: Sat, 22 Feb 2014 01:45:12 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116522
revision-id: address@hidden
parent: address@hidden
committer: Daniel Colascione <address@hidden>
branch nick: trunk
timestamp: Fri 2014-02-21 17:44:59 -0800
message:
  Build correct secrets pattern from auth-source pattern
modified:
  lisp/gnus/ChangeLog            changelog-20091113204419-o5vbwnq5f7feedwu-1433
  lisp/gnus/auth-source.el       
authsource.el-20091113204419-o5vbwnq5f7feedwu-8608
=== modified file 'lisp/gnus/ChangeLog'
--- a/lisp/gnus/ChangeLog       2014-02-13 22:52:51 +0000
+++ b/lisp/gnus/ChangeLog       2014-02-22 01:44:59 +0000
@@ -1,3 +1,9 @@
+2014-02-22  Daniel Colascione  <address@hidden>
+
+       * auth-source.el (auth-source-secrets-listify-pattern): New function.
+       (auth-source-secrets-search): Don't pass invalid patterns to secrets.el;
+       instead, build list of patterns.
+
 2014-02-13  Teodor Zlatanov  <address@hidden>
 
        * auth-source.el (auth-sources): Add pointer to what the .gpg extension

=== modified file 'lisp/gnus/auth-source.el'
--- a/lisp/gnus/auth-source.el  2014-02-13 22:52:51 +0000
+++ b/lisp/gnus/auth-source.el  2014-02-22 01:44:59 +0000
@@ -1506,6 +1506,31 @@
 ;; (let ((auth-sources '("secrets:Login"))) (auth-source-search :max 1))
 ;; (let ((auth-sources '("secrets:Login"))) (auth-source-search :max 1 
:signon_realm "https://git.gnus.org/Git";))
 
+(defun auth-source-secrets-listify-pattern (pattern)
+  "Convert a pattern with lists to a list of string patterns.
+
+auth-source patterns can have values of the form :foo (\"bar\"
+\"qux\"), which means to match any secret with :foo equal to
+\"bar\" otr :foo equal to \"qux\".  The secrets backend supports
+only string values for patterns, so this routine returns a list
+of patterns that is equivalent to the single original pattern
+when interpreted such that if a secret matches any pattern in the
+list, it mathces the original pattern."
+  (if (null pattern)
+      '(nil)
+    (let* ((key (pop pattern))
+           (value (pop pattern))
+           (tails (auth-source-secrets-listify-pattern pattern))
+           (heads (if (stringp value)
+                      (list (list key value))
+                    (mapcar (lambda (v) (list key v)) value))))
+      (cl-loop
+         for h in heads
+         nconc
+           (cl-loop
+              for tl in tails
+              collect (append h tl))))))
+
 (defun* auth-source-secrets-search (&rest
                                     spec
                                     &key backend create delete label
@@ -1558,21 +1583,25 @@
                             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
-         (search-spec (apply 'append (mapcar
+         (search-specs (auth-source-secrets-listify-pattern
+                        (apply 'append (mapcar
                                       (lambda (k)
                                         (if (or (null (plist-get spec k))
                                                 (eq t (plist-get spec k)))
                                             nil
                                           (list k (plist-get spec k))))
-                                      search-keys)))
+                                      search-keys))))
          ;; needed keys (always including host, login, port, and secret)
          (returned-keys (mm-delete-duplicates (append
                                                '(:host :login :port :secret)
                                                search-keys)))
-         (items (loop for item in (apply 'secrets-search-items coll 
search-spec)
-                      unless (and (stringp label)
-                                  (not (string-match label item)))
-                      collect item))
+         (items
+          (loop for search-spec in search-specs
+               nconc
+               (loop for item in (apply 'secrets-search-items coll search-spec)
+                  unless (and (stringp label)
+                              (not (string-match label item)))
+                  collect item)))
          ;; TODO: respect max in `secrets-search-items', not after the fact
          (items (butlast items (- (length items) max)))
          ;; convert the item name to a full plist


reply via email to

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