diff options
| author | Mark Oteiza | 2016-11-02 14:56:40 -0400 |
|---|---|---|
| committer | Mark Oteiza | 2016-11-02 14:56:40 -0400 |
| commit | 3f06795181fb09aebaadfe592e7741ddc8ff8adf (patch) | |
| tree | d69db57a67005bee15fa590cbd83a797f1114a57 /lisp/auth-source.el | |
| parent | 126c879df42f741fe486236aea538290a8c2ed64 (diff) | |
| download | emacs-3f06795181fb09aebaadfe592e7741ddc8ff8adf.tar.gz emacs-3f06795181fb09aebaadfe592e7741ddc8ff8adf.zip | |
Migrate auth-source to cl-lib
* lisp/auth-source.el: Use cl-lib.
(auth-source-read-char-choice, auth-source-backend-parse-parameters):
(auth-source-search): Replace cl calls with cl-lib ones.
(auth-source-netrc-cache):
(auth-source-forget+): Use cl-do-symbols instead.
(auth-source-specmatchp, auth-source-netrc-parse):
(auth-source-netrc-search, auth-source-netrc-create):
(auth-source-netrc-saver, auth-source-secrets-listify-pattern):
(auth-source-secrets-search, auth-source-secrets-create):
(auth-source-macos-keychain-search, auth-source--decode-octal-string):
(auth-source-macos-keychain-search-items, auth-source-plstore-search):
(auth-source-plstore-create): Replace cl calls with cl-lib ones.
Diffstat (limited to 'lisp/auth-source.el')
| -rw-r--r-- | lisp/auth-source.el | 218 |
1 files changed, 101 insertions, 117 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 9e1f46877bd..5254d77efe3 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el | |||
| @@ -41,8 +41,9 @@ | |||
| 41 | 41 | ||
| 42 | (require 'password-cache) | 42 | (require 'password-cache) |
| 43 | 43 | ||
| 44 | (eval-when-compile (require 'cl)) | 44 | (eval-when-compile |
| 45 | (require 'eieio) | 45 | (require 'cl-lib) |
| 46 | (require 'eieio)) | ||
| 46 | 47 | ||
| 47 | (autoload 'secrets-create-item "secrets") | 48 | (autoload 'secrets-create-item "secrets") |
| 48 | (autoload 'secrets-delete-item "secrets") | 49 | (autoload 'secrets-delete-item "secrets") |
| @@ -363,8 +364,8 @@ Only one of CHOICES will be returned. The PROMPT is augmented | |||
| 363 | with \"[a/b/c] \" if CHOICES is \(?a ?b ?c)." | 364 | with \"[a/b/c] \" if CHOICES is \(?a ?b ?c)." |
| 364 | (when choices | 365 | (when choices |
| 365 | (let* ((prompt-choices | 366 | (let* ((prompt-choices |
| 366 | (apply #'concat (loop for c in choices | 367 | (apply #'concat |
| 367 | collect (format "%c/" c)))) | 368 | (cl-loop for c in choices collect (format "%c/" c)))) |
| 368 | (prompt-choices (concat "[" (substring prompt-choices 0 -1) "] ")) | 369 | (prompt-choices (concat "[" (substring prompt-choices 0 -1) "] ")) |
| 369 | (full-prompt (concat prompt prompt-choices)) | 370 | (full-prompt (concat prompt prompt-choices)) |
| 370 | k) | 371 | k) |
| @@ -538,10 +539,9 @@ parameters." | |||
| 538 | 539 | ||
| 539 | ;; (mapcar 'auth-source-backend-parse auth-sources) | 540 | ;; (mapcar 'auth-source-backend-parse auth-sources) |
| 540 | 541 | ||
| 541 | (defun* auth-source-search (&rest spec | 542 | (cl-defun auth-source-search (&rest spec |
| 542 | &key max | 543 | &key max require create delete |
| 543 | require create delete | 544 | &allow-other-keys) |
| 544 | &allow-other-keys) | ||
| 545 | "Search or modify authentication backends according to SPEC. | 545 | "Search or modify authentication backends according to SPEC. |
| 546 | 546 | ||
| 547 | This function parses `auth-sources' for matches of the SPEC | 547 | This function parses `auth-sources' for matches of the SPEC |
| @@ -681,9 +681,9 @@ must call it to obtain the actual value." | |||
| 681 | (let* ((backends (mapcar #'auth-source-backend-parse auth-sources)) | 681 | (let* ((backends (mapcar #'auth-source-backend-parse auth-sources)) |
| 682 | (max (or max 1)) | 682 | (max (or max 1)) |
| 683 | (ignored-keys '(:require :create :delete :max)) | 683 | (ignored-keys '(:require :create :delete :max)) |
| 684 | (keys (loop for i below (length spec) by 2 | 684 | (keys (cl-loop for i below (length spec) by 2 |
| 685 | unless (memq (nth i spec) ignored-keys) | 685 | unless (memq (nth i spec) ignored-keys) |
| 686 | collect (nth i spec))) | 686 | collect (nth i spec))) |
| 687 | (cached (auth-source-remembered-p spec)) | 687 | (cached (auth-source-remembered-p spec)) |
| 688 | ;; note that we may have cached results but found is still nil | 688 | ;; note that we may have cached results but found is still nil |
| 689 | ;; (there were no results from the search) | 689 | ;; (there were no results from the search) |
| @@ -695,11 +695,11 @@ must call it to obtain the actual value." | |||
| 695 | "auth-source-search: found %d CACHED results matching %S" | 695 | "auth-source-search: found %d CACHED results matching %S" |
| 696 | (length found) spec) | 696 | (length found) spec) |
| 697 | 697 | ||
| 698 | (assert | 698 | (cl-assert |
| 699 | (or (eq t create) (listp create)) t | 699 | (or (eq t create) (listp create)) t |
| 700 | "Invalid auth-source :create parameter (must be t or a list): %s %s") | 700 | "Invalid auth-source :create parameter (must be t or a list): %s %s") |
| 701 | 701 | ||
| 702 | (assert | 702 | (cl-assert |
| 703 | (listp require) t | 703 | (listp require) t |
| 704 | "Invalid auth-source :require parameter (must be a list): %s") | 704 | "Invalid auth-source :require parameter (must be a list): %s") |
| 705 | 705 | ||
| @@ -712,7 +712,7 @@ must call it to obtain the actual value." | |||
| 712 | (plist-get spec key) | 712 | (plist-get spec key) |
| 713 | (slot-value backend key)) | 713 | (slot-value backend key)) |
| 714 | (setq filtered-backends (delq backend filtered-backends)) | 714 | (setq filtered-backends (delq backend filtered-backends)) |
| 715 | (return)) | 715 | (cl-return)) |
| 716 | (invalid-slot-name nil)))) | 716 | (invalid-slot-name nil)))) |
| 717 | 717 | ||
| 718 | (auth-source-do-trivia | 718 | (auth-source-do-trivia |
| @@ -812,12 +812,9 @@ Returns the deleted entries." | |||
| 812 | (defun auth-source-forget-all-cached () | 812 | (defun auth-source-forget-all-cached () |
| 813 | "Forget all cached auth-source data." | 813 | "Forget all cached auth-source data." |
| 814 | (interactive) | 814 | (interactive) |
| 815 | (loop for sym being the symbols of password-data | 815 | (cl-do-symbols (sym password-data) |
| 816 | ;; when the symbol name starts with auth-source-magic | 816 | (when (string-match (concat "^" auth-source-magic) (symbol-name sym)) |
| 817 | when (string-match (concat "^" auth-source-magic) | 817 | (password-cache-remove (symbol-name sym)))) |
| 818 | (symbol-name sym)) | ||
| 819 | ;; remove that key | ||
| 820 | do (password-cache-remove (symbol-name sym))) | ||
| 821 | (setq auth-source-netrc-cache nil)) | 818 | (setq auth-source-netrc-cache nil)) |
| 822 | 819 | ||
| 823 | (defun auth-source-format-cache-entry (spec) | 820 | (defun auth-source-format-cache-entry (spec) |
| @@ -866,27 +863,26 @@ cached data that was found with a search for those two hosts, | |||
| 866 | while \(:host t) would find all host entries." | 863 | while \(:host t) would find all host entries." |
| 867 | (let ((count 0) | 864 | (let ((count 0) |
| 868 | sname) | 865 | sname) |
| 869 | (loop for sym being the symbols of password-data | 866 | (cl-do-symbols (sym password-data) |
| 870 | ;; when the symbol name matches with auth-source-magic | 867 | ;; when the symbol name matches with auth-source-magic |
| 871 | when (and (setq sname (symbol-name sym)) | 868 | (when (and (setq sname (symbol-name sym)) |
| 872 | (string-match (concat "^" auth-source-magic "\\(.+\\)") | 869 | (string-match (concat "^" auth-source-magic "\\(.+\\)") |
| 873 | sname) | 870 | sname) |
| 874 | ;; and the spec matches what was stored in the cache | 871 | ;; and the spec matches what was stored in the cache |
| 875 | (auth-source-specmatchp spec (read (match-string 1 sname)))) | 872 | (auth-source-specmatchp spec (read (match-string 1 sname)))) |
| 876 | ;; remove that key | 873 | ;; remove that key |
| 877 | do (progn | 874 | (password-cache-remove sname) |
| 878 | (password-cache-remove sname) | 875 | (cl-incf count))) |
| 879 | (incf count))) | ||
| 880 | count)) | 876 | count)) |
| 881 | 877 | ||
| 882 | (defun auth-source-specmatchp (spec stored) | 878 | (defun auth-source-specmatchp (spec stored) |
| 883 | (let ((keys (loop for i below (length spec) by 2 | 879 | (let ((keys (cl-loop for i below (length spec) by 2 |
| 884 | collect (nth i spec)))) | 880 | collect (nth i spec)))) |
| 885 | (not (eq | 881 | (not (eq |
| 886 | (dolist (key keys) | 882 | (cl-dolist (key keys) |
| 887 | (unless (auth-source-search-collection (plist-get stored key) | 883 | (unless (auth-source-search-collection (plist-get stored key) |
| 888 | (plist-get spec key)) | 884 | (plist-get spec key)) |
| 889 | (return 'no))) | 885 | (cl-return 'no))) |
| 890 | 'no)))) | 886 | 'no)))) |
| 891 | 887 | ||
| 892 | ;; (auth-source-pick-first-password :host "z.lifelogs.com") | 888 | ;; (auth-source-pick-first-password :host "z.lifelogs.com") |
| @@ -941,8 +937,8 @@ while \(:host t) would find all host entries." | |||
| 941 | (cdr (assoc key alist))) | 937 | (cdr (assoc key alist))) |
| 942 | 938 | ||
| 943 | ;; (auth-source-netrc-parse :file "~/.authinfo.gpg") | 939 | ;; (auth-source-netrc-parse :file "~/.authinfo.gpg") |
| 944 | (defun* auth-source-netrc-parse (&key file max host user port require | 940 | (cl-defun auth-source-netrc-parse (&key file max host user port require |
| 945 | &allow-other-keys) | 941 | &allow-other-keys) |
| 946 | "Parse FILE and return a list of all entries in the file. | 942 | "Parse FILE and return a list of all entries in the file. |
| 947 | Note that the MAX parameter is used so we can exit the parse early." | 943 | Note that the MAX parameter is used so we can exit the parse early." |
| 948 | (if (listp file) | 944 | (if (listp file) |
| @@ -983,8 +979,8 @@ Note that the MAX parameter is used so we can exit the parse early." | |||
| 983 | ;; every element of require is in n(ormalized) | 979 | ;; every element of require is in n(ormalized) |
| 984 | (let ((n (nth 0 (auth-source-netrc-normalize | 980 | (let ((n (nth 0 (auth-source-netrc-normalize |
| 985 | (list alist) file)))) | 981 | (list alist) file)))) |
| 986 | (loop for req in require | 982 | (cl-loop for req in require |
| 987 | always (plist-get n req))))))) | 983 | always (plist-get n req))))))) |
| 988 | result) | 984 | result) |
| 989 | 985 | ||
| 990 | (if (and (functionp cached-secrets) | 986 | (if (and (functionp cached-secrets) |
| @@ -1199,16 +1195,15 @@ FILE is the file from which we obtained this token." | |||
| 1199 | ;; (setq secret (plist-get (nth 0 (auth-source-search :host t :type 'netrc :K 1 :max 1)) :secret)) | 1195 | ;; (setq secret (plist-get (nth 0 (auth-source-search :host t :type 'netrc :K 1 :max 1)) :secret)) |
| 1200 | ;; (funcall secret) | 1196 | ;; (funcall secret) |
| 1201 | 1197 | ||
| 1202 | (defun* auth-source-netrc-search (&rest | 1198 | (cl-defun auth-source-netrc-search (&rest spec |
| 1203 | spec | 1199 | &key backend require create |
| 1204 | &key backend require create | 1200 | type max host user port |
| 1205 | type max host user port | 1201 | &allow-other-keys) |
| 1206 | &allow-other-keys) | ||
| 1207 | "Given a property list SPEC, return search matches from the :backend. | 1202 | "Given a property list SPEC, return search matches from the :backend. |
| 1208 | See `auth-source-search' for details on SPEC." | 1203 | See `auth-source-search' for details on SPEC." |
| 1209 | ;; just in case, check that the type is correct (null or same as the backend) | 1204 | ;; just in case, check that the type is correct (null or same as the backend) |
| 1210 | (assert (or (null type) (eq type (oref backend type))) | 1205 | (cl-assert (or (null type) (eq type (oref backend type))) |
| 1211 | t "Invalid netrc search: %s %s") | 1206 | t "Invalid netrc search: %s %s") |
| 1212 | 1207 | ||
| 1213 | (let ((results (auth-source-netrc-normalize | 1208 | (let ((results (auth-source-netrc-normalize |
| 1214 | (auth-source-netrc-parse | 1209 | (auth-source-netrc-parse |
| @@ -1245,10 +1240,9 @@ See `auth-source-search' for details on SPEC." | |||
| 1245 | ;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t) | 1240 | ;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t) |
| 1246 | ;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t :create-extra-keys '((A "default A") (B))) | 1241 | ;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t :create-extra-keys '((A "default A") (B))) |
| 1247 | 1242 | ||
| 1248 | (defun* auth-source-netrc-create (&rest spec | 1243 | (cl-defun auth-source-netrc-create (&rest spec |
| 1249 | &key backend | 1244 | &key backend host port create |
| 1250 | host port create | 1245 | &allow-other-keys) |
| 1251 | &allow-other-keys) | ||
| 1252 | (let* ((base-required '(host user port secret)) | 1246 | (let* ((base-required '(host user port secret)) |
| 1253 | ;; we know (because of an assertion in auth-source-search) that the | 1247 | ;; we know (because of an assertion in auth-source-search) that the |
| 1254 | ;; :create parameter is either t or a list (which includes nil) | 1248 | ;; :create parameter is either t or a list (which includes nil) |
| @@ -1281,8 +1275,8 @@ See `auth-source-search' for details on SPEC." | |||
| 1281 | ;; for extra required elements, see if the spec includes a value for them | 1275 | ;; for extra required elements, see if the spec includes a value for them |
| 1282 | (dolist (er create-extra) | 1276 | (dolist (er create-extra) |
| 1283 | (let ((k (auth-source--symbol-keyword er)) | 1277 | (let ((k (auth-source--symbol-keyword er)) |
| 1284 | (keys (loop for i below (length spec) by 2 | 1278 | (keys (cl-loop for i below (length spec) by 2 |
| 1285 | collect (nth i spec)))) | 1279 | collect (nth i spec)))) |
| 1286 | (when (memq k keys) | 1280 | (when (memq k keys) |
| 1287 | (auth-source--aput valist er (plist-get spec k))))) | 1281 | (auth-source--aput valist er (plist-get spec k))))) |
| 1288 | 1282 | ||
| @@ -1323,7 +1317,7 @@ See `auth-source-search' for details on SPEC." | |||
| 1323 | (plist-get artificial :port) | 1317 | (plist-get artificial :port) |
| 1324 | "[any port]")))) | 1318 | "[any port]")))) |
| 1325 | (prompt (or (auth-source--aget auth-source-creation-prompts r) | 1319 | (prompt (or (auth-source--aget auth-source-creation-prompts r) |
| 1326 | (case r | 1320 | (cl-case r |
| 1327 | (secret "%p password for %u@%h: ") | 1321 | (secret "%p password for %u@%h: ") |
| 1328 | (user "%p user name for %h: ") | 1322 | (user "%p user name for %h: ") |
| 1329 | (host "%p host name for user %u: ") | 1323 | (host "%p host name for user %u: ") |
| @@ -1400,7 +1394,7 @@ See `auth-source-search' for details on SPEC." | |||
| 1400 | ;; prepend a space | 1394 | ;; prepend a space |
| 1401 | (if (zerop (length add)) "" " ") | 1395 | (if (zerop (length add)) "" " ") |
| 1402 | ;; remap auth-source tokens to netrc | 1396 | ;; remap auth-source tokens to netrc |
| 1403 | (case r | 1397 | (cl-case r |
| 1404 | (user "login") | 1398 | (user "login") |
| 1405 | (host "machine") | 1399 | (host "machine") |
| 1406 | (secret "password") | 1400 | (secret "password") |
| @@ -1454,7 +1448,7 @@ Respects `auth-source-save-behavior'. Uses | |||
| 1454 | k) | 1448 | k) |
| 1455 | (while (not done) | 1449 | (while (not done) |
| 1456 | (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ?e ??))) | 1450 | (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ?e ??))) |
| 1457 | (case k | 1451 | (cl-case k |
| 1458 | (?y (setq done t)) | 1452 | (?y (setq done t)) |
| 1459 | (?? (save-excursion | 1453 | (?? (save-excursion |
| 1460 | (with-output-to-temp-buffer bufname | 1454 | (with-output-to-temp-buffer bufname |
| @@ -1526,17 +1520,12 @@ list, it matches the original pattern." | |||
| 1526 | (heads (if (stringp value) | 1520 | (heads (if (stringp value) |
| 1527 | (list (list key value)) | 1521 | (list (list key value)) |
| 1528 | (mapcar (lambda (v) (list key v)) value)))) | 1522 | (mapcar (lambda (v) (list key v)) value)))) |
| 1529 | (loop | 1523 | (cl-loop for h in heads |
| 1530 | for h in heads | 1524 | nconc (cl-loop for tl in tails collect (append h tl)))))) |
| 1531 | nconc | 1525 | |
| 1532 | (loop | 1526 | (cl-defun auth-source-secrets-search (&rest spec |
| 1533 | for tl in tails | 1527 | &key backend create delete label max |
| 1534 | collect (append h tl)))))) | 1528 | &allow-other-keys) |
| 1535 | |||
| 1536 | (defun* auth-source-secrets-search (&rest | ||
| 1537 | spec | ||
| 1538 | &key backend create delete label max | ||
| 1539 | &allow-other-keys) | ||
| 1540 | "Search the Secrets API; spec is like `auth-source'. | 1529 | "Search the Secrets API; spec is like `auth-source'. |
| 1541 | 1530 | ||
| 1542 | The :label key specifies the item's label. It is the only key | 1531 | The :label key specifies the item's label. It is the only key |
| @@ -1569,19 +1558,19 @@ authentication tokens: | |||
| 1569 | " | 1558 | " |
| 1570 | 1559 | ||
| 1571 | ;; TODO | 1560 | ;; TODO |
| 1572 | (assert (not create) nil | 1561 | (cl-assert (not create) nil |
| 1573 | "The Secrets API auth-source backend doesn't support creation yet") | 1562 | "The Secrets API auth-source backend doesn't support creation yet") |
| 1574 | ;; TODO | 1563 | ;; TODO |
| 1575 | ;; (secrets-delete-item coll elt) | 1564 | ;; (secrets-delete-item coll elt) |
| 1576 | (assert (not delete) nil | 1565 | (cl-assert (not delete) nil |
| 1577 | "The Secrets API auth-source backend doesn't support deletion yet") | 1566 | "The Secrets API auth-source backend doesn't support deletion yet") |
| 1578 | 1567 | ||
| 1579 | (let* ((coll (oref backend source)) | 1568 | (let* ((coll (oref backend source)) |
| 1580 | (max (or max 5000)) ; sanity check: default to stop at 5K | 1569 | (max (or max 5000)) ; sanity check: default to stop at 5K |
| 1581 | (ignored-keys '(:create :delete :max :backend :label :require :type)) | 1570 | (ignored-keys '(:create :delete :max :backend :label :require :type)) |
| 1582 | (search-keys (loop for i below (length spec) by 2 | 1571 | (search-keys (cl-loop for i below (length spec) by 2 |
| 1583 | unless (memq (nth i spec) ignored-keys) | 1572 | unless (memq (nth i spec) ignored-keys) |
| 1584 | collect (nth i spec))) | 1573 | collect (nth i spec))) |
| 1585 | ;; build a search spec without the ignored keys | 1574 | ;; build a search spec without the ignored keys |
| 1586 | ;; if a search key is nil or t (match anything), we skip it | 1575 | ;; if a search key is nil or t (match anything), we skip it |
| 1587 | (search-specs (auth-source-secrets-listify-pattern | 1576 | (search-specs (auth-source-secrets-listify-pattern |
| @@ -1597,12 +1586,13 @@ authentication tokens: | |||
| 1597 | '(:host :login :port :secret) | 1586 | '(:host :login :port :secret) |
| 1598 | search-keys))) | 1587 | search-keys))) |
| 1599 | (items | 1588 | (items |
| 1600 | (loop for search-spec in search-specs | 1589 | (cl-loop |
| 1601 | nconc | 1590 | for search-spec in search-specs |
| 1602 | (loop for item in (apply #'secrets-search-items coll search-spec) | 1591 | nconc |
| 1603 | unless (and (stringp label) | 1592 | (cl-loop for item in (apply #'secrets-search-items coll search-spec) |
| 1604 | (not (string-match label item))) | 1593 | unless (and (stringp label) |
| 1605 | collect item))) | 1594 | (not (string-match label item))) |
| 1595 | collect item))) | ||
| 1606 | ;; TODO: respect max in `secrets-search-items', not after the fact | 1596 | ;; TODO: respect max in `secrets-search-items', not after the fact |
| 1607 | (items (butlast items (- (length items) max))) | 1597 | (items (butlast items (- (length items) max))) |
| 1608 | ;; convert the item name to a full plist | 1598 | ;; convert the item name to a full plist |
| @@ -1653,11 +1643,9 @@ authentication tokens: | |||
| 1653 | ;; (let ((auth-sources '("macos-keychain-generic:Login"))) (auth-source-search :max 1 :host "git.gnus.org")) | 1643 | ;; (let ((auth-sources '("macos-keychain-generic:Login"))) (auth-source-search :max 1 :host "git.gnus.org")) |
| 1654 | ;; (let ((auth-sources '("macos-keychain-generic:Login"))) (auth-source-search :max 1)) | 1644 | ;; (let ((auth-sources '("macos-keychain-generic:Login"))) (auth-source-search :max 1)) |
| 1655 | 1645 | ||
| 1656 | (defun* auth-source-macos-keychain-search (&rest | 1646 | (cl-defun auth-source-macos-keychain-search (&rest spec |
| 1657 | spec | 1647 | &key backend create delete type max |
| 1658 | &key backend create delete | 1648 | &allow-other-keys) |
| 1659 | type max | ||
| 1660 | &allow-other-keys) | ||
| 1661 | "Search the MacOS Keychain; spec is like `auth-source'. | 1649 | "Search the MacOS Keychain; spec is like `auth-source'. |
| 1662 | 1650 | ||
| 1663 | All search keys must match exactly. If you need substring | 1651 | All search keys must match exactly. If you need substring |
| @@ -1698,11 +1686,11 @@ entries for git.gnus.org: | |||
| 1698 | (auth-source-search :max 1 :host \"git.gnus.org\")) | 1686 | (auth-source-search :max 1 :host \"git.gnus.org\")) |
| 1699 | " | 1687 | " |
| 1700 | ;; TODO | 1688 | ;; TODO |
| 1701 | (assert (not create) nil | 1689 | (cl-assert (not create) nil |
| 1702 | "The MacOS Keychain auth-source backend doesn't support creation yet") | 1690 | "The MacOS Keychain auth-source backend doesn't support creation yet") |
| 1703 | ;; TODO | 1691 | ;; TODO |
| 1704 | ;; (macos-keychain-delete-item coll elt) | 1692 | ;; (macos-keychain-delete-item coll elt) |
| 1705 | (assert (not delete) nil | 1693 | (cl-assert (not delete) nil |
| 1706 | "The MacOS Keychain auth-source backend doesn't support deletion yet") | 1694 | "The MacOS Keychain auth-source backend doesn't support deletion yet") |
| 1707 | 1695 | ||
| 1708 | (let* ((coll (oref backend source)) | 1696 | (let* ((coll (oref backend source)) |
| @@ -1710,9 +1698,10 @@ entries for git.gnus.org: | |||
| 1710 | ;; Filter out ignored keys from the spec | 1698 | ;; Filter out ignored keys from the spec |
| 1711 | (ignored-keys '(:create :delete :max :backend :label :host :port)) | 1699 | (ignored-keys '(:create :delete :max :backend :label :host :port)) |
| 1712 | ;; Build a search spec without the ignored keys | 1700 | ;; Build a search spec without the ignored keys |
| 1713 | (search-keys (loop for i below (length spec) by 2 | 1701 | ;; FIXME make this loop a function? it's used in at least 3 places |
| 1714 | unless (memq (nth i spec) ignored-keys) | 1702 | (search-keys (cl-loop for i below (length spec) by 2 |
| 1715 | collect (nth i spec))) | 1703 | unless (memq (nth i spec) ignored-keys) |
| 1704 | collect (nth i spec))) | ||
| 1716 | ;; If a search key value is nil or t (match anything), we skip it | 1705 | ;; If a search key value is nil or t (match anything), we skip it |
| 1717 | (search-spec (apply #'append (mapcar | 1706 | (search-spec (apply #'append (mapcar |
| 1718 | (lambda (k) | 1707 | (lambda (k) |
| @@ -1765,21 +1754,19 @@ entries for git.gnus.org: | |||
| 1765 | (size (length string))) | 1754 | (size (length string))) |
| 1766 | (decode-coding-string | 1755 | (decode-coding-string |
| 1767 | (apply #'unibyte-string | 1756 | (apply #'unibyte-string |
| 1768 | (loop for i = 0 then (+ i (if (eq (nth i list) ?\\) 4 1)) | 1757 | (cl-loop for i = 0 then (+ i (if (eq (nth i list) ?\\) 4 1)) |
| 1769 | for var = (nth i list) | 1758 | for var = (nth i list) |
| 1770 | while (< i size) | 1759 | while (< i size) |
| 1771 | if (eq var ?\\) | 1760 | if (eq var ?\\) |
| 1772 | collect (string-to-number | 1761 | collect (string-to-number |
| 1773 | (concat (cl-subseq list (+ i 1) (+ i 4))) 8) | 1762 | (concat (cl-subseq list (+ i 1) (+ i 4))) 8) |
| 1774 | else | 1763 | else |
| 1775 | collect var)) | 1764 | collect var)) |
| 1776 | 'utf-8))) | 1765 | 'utf-8))) |
| 1777 | 1766 | ||
| 1778 | (defun* auth-source-macos-keychain-search-items (coll _type _max | 1767 | (cl-defun auth-source-macos-keychain-search-items (coll _type _max host port |
| 1779 | host port | 1768 | &key label type user |
| 1780 | &key label type | 1769 | &allow-other-keys) |
| 1781 | user | ||
| 1782 | &allow-other-keys) | ||
| 1783 | (let* ((keychain-generic (eq type 'macos-keychain-generic)) | 1770 | (let* ((keychain-generic (eq type 'macos-keychain-generic)) |
| 1784 | (args `(,(if keychain-generic | 1771 | (args `(,(if keychain-generic |
| 1785 | "find-generic-password" | 1772 | "find-generic-password" |
| @@ -1858,18 +1845,16 @@ entries for git.gnus.org: | |||
| 1858 | 1845 | ||
| 1859 | ;;; Backend specific parsing: PLSTORE backend | 1846 | ;;; Backend specific parsing: PLSTORE backend |
| 1860 | 1847 | ||
| 1861 | (defun* auth-source-plstore-search (&rest | 1848 | (cl-defun auth-source-plstore-search (&rest spec |
| 1862 | spec | 1849 | &key backend create delete max |
| 1863 | &key backend create delete | 1850 | &allow-other-keys) |
| 1864 | max | ||
| 1865 | &allow-other-keys) | ||
| 1866 | "Search the PLSTORE; spec is like `auth-source'." | 1851 | "Search the PLSTORE; spec is like `auth-source'." |
| 1867 | (let* ((store (oref backend data)) | 1852 | (let* ((store (oref backend data)) |
| 1868 | (max (or max 5000)) ; sanity check: default to stop at 5K | 1853 | (max (or max 5000)) ; sanity check: default to stop at 5K |
| 1869 | (ignored-keys '(:create :delete :max :backend :label :require :type)) | 1854 | (ignored-keys '(:create :delete :max :backend :label :require :type)) |
| 1870 | (search-keys (loop for i below (length spec) by 2 | 1855 | (search-keys (cl-loop for i below (length spec) by 2 |
| 1871 | unless (memq (nth i spec) ignored-keys) | 1856 | unless (memq (nth i spec) ignored-keys) |
| 1872 | collect (nth i spec))) | 1857 | collect (nth i spec))) |
| 1873 | ;; build a search spec without the ignored keys | 1858 | ;; build a search spec without the ignored keys |
| 1874 | ;; if a search key is nil or t (match anything), we skip it | 1859 | ;; if a search key is nil or t (match anything), we skip it |
| 1875 | (search-spec (apply #'append (mapcar | 1860 | (search-spec (apply #'append (mapcar |
| @@ -1934,10 +1919,9 @@ entries for git.gnus.org: | |||
| 1934 | (plstore-save store))) | 1919 | (plstore-save store))) |
| 1935 | items)) | 1920 | items)) |
| 1936 | 1921 | ||
| 1937 | (defun* auth-source-plstore-create (&rest spec | 1922 | (cl-defun auth-source-plstore-create (&rest spec |
| 1938 | &key backend | 1923 | &key backend host port create |
| 1939 | host port create | 1924 | &allow-other-keys) |
| 1940 | &allow-other-keys) | ||
| 1941 | (let* ((base-required '(host user port secret)) | 1925 | (let* ((base-required '(host user port secret)) |
| 1942 | (base-secret '(secret)) | 1926 | (base-secret '(secret)) |
| 1943 | ;; we know (because of an assertion in auth-source-search) that the | 1927 | ;; we know (because of an assertion in auth-source-search) that the |
| @@ -1970,8 +1954,8 @@ entries for git.gnus.org: | |||
| 1970 | ;; for extra required elements, see if the spec includes a value for them | 1954 | ;; for extra required elements, see if the spec includes a value for them |
| 1971 | (dolist (er create-extra) | 1955 | (dolist (er create-extra) |
| 1972 | (let ((k (auth-source--symbol-keyword er)) | 1956 | (let ((k (auth-source--symbol-keyword er)) |
| 1973 | (keys (loop for i below (length spec) by 2 | 1957 | (keys (cl-loop for i below (length spec) by 2 |
| 1974 | collect (nth i spec)))) | 1958 | collect (nth i spec)))) |
| 1975 | (when (memq k keys) | 1959 | (when (memq k keys) |
| 1976 | (auth-source--aput valist er (plist-get spec k))))) | 1960 | (auth-source--aput valist er (plist-get spec k))))) |
| 1977 | 1961 | ||
| @@ -2012,7 +1996,7 @@ entries for git.gnus.org: | |||
| 2012 | (plist-get artificial :port) | 1996 | (plist-get artificial :port) |
| 2013 | "[any port]")))) | 1997 | "[any port]")))) |
| 2014 | (prompt (or (auth-source--aget auth-source-creation-prompts r) | 1998 | (prompt (or (auth-source--aget auth-source-creation-prompts r) |
| 2015 | (case r | 1999 | (cl-case r |
| 2016 | (secret "%p password for %u@%h: ") | 2000 | (secret "%p password for %u@%h: ") |
| 2017 | (user "%p user name for %h: ") | 2001 | (user "%p user name for %h: ") |
| 2018 | (host "%p host name for user %u: ") | 2002 | (host "%p host name for user %u: ") |