aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorfoudfou2017-02-16 09:34:17 +0100
committerTed Zlatanov2017-04-27 17:37:58 -0400
commitb206b95ce3c598a5f3c62cfe83030da14952c81d (patch)
tree3e5f55f6ac25ab78d9a270241ae5cace3638a07a /lisp
parent0e066efe3b84ee9ecfc0a075e0ce289311f6d160 (diff)
downloademacs-b206b95ce3c598a5f3c62cfe83030da14952c81d.tar.gz
emacs-b206b95ce3c598a5f3c62cfe83030da14952c81d.zip
auth-source-pass: Enable finding entries by "host/username"
* lisp/auth-source-pass.el: Enable finding entries by "host/username". * test/lisp/auth-source-pass-tests.el: Adjust tests to check it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/auth-source-pass.el21
1 files changed, 12 insertions, 9 deletions
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index a9d61cf58c3..e59cfa2d25f 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -206,25 +206,28 @@ often."
206 (lambda (file) (file-name-sans-extension (file-relative-name file store-dir))) 206 (lambda (file) (file-name-sans-extension (file-relative-name file store-dir)))
207 (directory-files-recursively store-dir "\.gpg$")))) 207 (directory-files-recursively store-dir "\.gpg$"))))
208 208
209(defun auth-source-pass--find-all-by-entry-name (name) 209(defun auth-source-pass--find-all-by-entry-name (entryname user)
210 "Search the store for all entries matching NAME. 210 "Search the store for all entries either matching ENTRYNAME/USER or ENTRYNAME.
211Only return valid entries as of `auth-source-pass--entry-valid-p'." 211Only return valid entries as of `auth-source-pass--entry-valid-p'."
212 (seq-filter (lambda (entry) 212 (seq-filter (lambda (entry)
213 (and 213 (and
214 (string-equal 214 (or
215 name 215 (let ((components-host-user
216 (auth-source-pass--remove-directory-name entry)) 216 (member entryname (split-string entry "/"))))
217 (and (= (length components-host-user) 2)
218 (string-equal user (cadr components-host-user))))
219 (string-equal entryname (auth-source-pass--remove-directory-name entry)))
217 (auth-source-pass--entry-valid-p entry))) 220 (auth-source-pass--entry-valid-p entry)))
218 (auth-source-pass-entries))) 221 (auth-source-pass-entries)))
219 222
220(defun auth-source-pass--find-one-by-entry-name (name user) 223(defun auth-source-pass--find-one-by-entry-name (entryname user)
221 "Search the store for an entry matching NAME. 224 "Search the store for an entry matching ENTRYNAME.
222If USER is non nil, give precedence to entries containing a user field 225If USER is non nil, give precedence to entries containing a user field
223matching USER." 226matching USER."
224 (auth-source-pass--do-debug "searching for '%s' in entry names (user: %s)" 227 (auth-source-pass--do-debug "searching for '%s' in entry names (user: %s)"
225 name 228 entryname
226 user) 229 user)
227 (let ((matching-entries (auth-source-pass--find-all-by-entry-name name))) 230 (let ((matching-entries (auth-source-pass--find-all-by-entry-name entryname user)))
228 (pcase (length matching-entries) 231 (pcase (length matching-entries)
229 (0 (auth-source-pass--do-debug "no match found") 232 (0 (auth-source-pass--do-debug "no match found")
230 nil) 233 nil)