aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaiki Ueno2011-07-01 14:05:59 +0000
committerKatsumi Yamaoka2011-07-01 14:05:59 +0000
commite9cb4479f5a80de75d79ea957502e59c87992c9c (patch)
treedbb2571ae03c5928b47199ecdbe8c7f9b93bca85
parent26bde865f6cd7bd636029e756c46f80a6ce40574 (diff)
downloademacs-e9cb4479f5a80de75d79ea957502e59c87992c9c.tar.gz
emacs-e9cb4479f5a80de75d79ea957502e59c87992c9c.zip
auth-source.el (auth-source-token-passphrase-callback-function): Simplify and remove EPA dependency.
-rw-r--r--lisp/gnus/ChangeLog5
-rw-r--r--lisp/gnus/auth-source.el260
2 files changed, 131 insertions, 134 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 088d5a426f0..1567bfaddd2 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,8 @@
12011-07-01 Daiki Ueno <ueno@unixuser.org>
2
3 * auth-source.el (auth-source-token-passphrase-callback-function):
4 Simplify and remove EPA dependency.
5
12011-07-01 Andrew Cohen <cohen@andy.bu.edu> 62011-07-01 Andrew Cohen <cohen@andy.bu.edu>
2 7
3 * nnir.el (nnir-request-article): Fix error message text. 8 * nnir.el (nnir-request-article): Fix error message text.
diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el
index 1b5b4840085..677698ebc96 100644
--- a/lisp/gnus/auth-source.el
+++ b/lisp/gnus/auth-source.el
@@ -45,7 +45,17 @@
45(require 'assoc) 45(require 'assoc)
46 46
47(eval-when-compile (require 'cl)) 47(eval-when-compile (require 'cl))
48(require 'eieio) 48(eval-and-compile
49 (or (ignore-errors (require 'eieio))
50 ;; gnus-fallback-lib/ from gnus/lisp/gnus-fallback-lib
51 (ignore-errors
52 (let ((load-path (cons (expand-file-name
53 "gnus-fallback-lib/eieio"
54 (file-name-directory (locate-library "gnus")))
55 load-path)))
56 (require 'eieio)))
57 (error
58 "eieio not found in `load-path' or gnus-fallback-lib/ directory.")))
49 59
50(autoload 'secrets-create-item "secrets") 60(autoload 'secrets-create-item "secrets")
51(autoload 'secrets-delete-item "secrets") 61(autoload 'secrets-delete-item "secrets")
@@ -64,8 +74,6 @@
64(autoload 'plstore-save "plstore") 74(autoload 'plstore-save "plstore")
65(autoload 'plstore-get-file "plstore") 75(autoload 'plstore-get-file "plstore")
66 76
67(autoload 'epa-passphrase-callback-function "epa")
68
69(autoload 'epg-context-operation "epg") 77(autoload 'epg-context-operation "epg")
70(autoload 'epg-make-context "epg") 78(autoload 'epg-make-context "epg")
71(autoload 'epg-context-set-passphrase-callback "epg") 79(autoload 'epg-context-set-passphrase-callback "epg")
@@ -92,6 +100,9 @@ let-binding."
92 (const :tag "30 Minutes" 1800) 100 (const :tag "30 Minutes" 1800)
93 (integer :tag "Seconds"))) 101 (integer :tag "Seconds")))
94 102
103;;; The slots below correspond with the `auth-source-search' spec,
104;;; so a backend with :host set, for instance, would match only
105;;; searches for that host. Normally they are nil.
95(defclass auth-source-backend () 106(defclass auth-source-backend ()
96 ((type :initarg :type 107 ((type :initarg :type
97 :initform 'netrc 108 :initform 'netrc
@@ -285,9 +296,9 @@ can get pretty complex."
285 (const :format "" :value :user) 296 (const :format "" :value :user)
286 (choice 297 (choice
287 :tag "Personality/Username" 298 :tag "Personality/Username"
288 (const :tag "Any" t) 299 (const :tag "Any" t)
289 (string 300 (string
290 :tag "Name"))))))))) 301 :tag "Name")))))))))
291 302
292(defcustom auth-source-gpg-encrypt-to t 303(defcustom auth-source-gpg-encrypt-to t
293 "List of recipient keys that `authinfo.gpg' encrypted to. 304 "List of recipient keys that `authinfo.gpg' encrypted to.
@@ -328,8 +339,8 @@ If the value is not a list, symmetric encryption will be used."
328 339
329(defun auth-source-do-warn (&rest msg) 340(defun auth-source-do-warn (&rest msg)
330 (apply 341 (apply
331 ;; set logger to either the function in auth-source-debug or 'message 342 ;; set logger to either the function in auth-source-debug or 'message
332 ;; note that it will be 'message if auth-source-debug is nil 343 ;; note that it will be 'message if auth-source-debug is nil
333 (if (functionp auth-source-debug) 344 (if (functionp auth-source-debug)
334 auth-source-debug 345 auth-source-debug
335 'message) 346 'message)
@@ -397,19 +408,19 @@ with \"[a/b/c] \" if CHOICES is '\(?a ?b ?c\)."
397 ;; a file name with parameters 408 ;; a file name with parameters
398 ((stringp (plist-get entry :source)) 409 ((stringp (plist-get entry :source))
399 (if (equal (file-name-extension (plist-get entry :source)) "plist") 410 (if (equal (file-name-extension (plist-get entry :source)) "plist")
400 (auth-source-backend 411 (auth-source-backend
401 (plist-get entry :source) 412 (plist-get entry :source)
402 :source (plist-get entry :source) 413 :source (plist-get entry :source)
403 :type 'plstore 414 :type 'plstore
404 :search-function 'auth-source-plstore-search 415 :search-function 'auth-source-plstore-search
405 :create-function 'auth-source-plstore-create 416 :create-function 'auth-source-plstore-create
406 :data (plstore-open (plist-get entry :source))) 417 :data (plstore-open (plist-get entry :source)))
407 (auth-source-backend 418 (auth-source-backend
408 (plist-get entry :source) 419 (plist-get entry :source)
409 :source (plist-get entry :source) 420 :source (plist-get entry :source)
410 :type 'netrc 421 :type 'netrc
411 :search-function 'auth-source-netrc-search 422 :search-function 'auth-source-netrc-search
412 :create-function 'auth-source-netrc-create))) 423 :create-function 'auth-source-netrc-create)))
413 424
414 ;; the Secrets API. We require the package, in order to have a 425 ;; the Secrets API. We require the package, in order to have a
415 ;; defined value for `secrets-enabled'. 426 ;; defined value for `secrets-enabled'.
@@ -683,7 +694,7 @@ must call it to obtain the actual value."
683 (when auth-source-do-cache 694 (when auth-source-do-cache
684 (auth-source-remember spec found))) 695 (auth-source-remember spec found)))
685 696
686 found)) 697 found))
687 698
688(defun auth-source-search-backends (backends spec max create delete require) 699(defun auth-source-search-backends (backends spec max create delete require)
689 (let (matches) 700 (let (matches)
@@ -805,7 +816,7 @@ while \(:host t) would find all host entries."
805 816
806(defun auth-source-specmatchp (spec stored) 817(defun auth-source-specmatchp (spec stored)
807 (let ((keys (loop for i below (length spec) by 2 818 (let ((keys (loop for i below (length spec) by 2
808 collect (nth i spec)))) 819 collect (nth i spec))))
809 (not (eq 820 (not (eq
810 (dolist (key keys) 821 (dolist (key keys)
811 (unless (auth-source-search-collection (plist-get stored key) 822 (unless (auth-source-search-collection (plist-get stored key)
@@ -840,10 +851,10 @@ while \(:host t) would find all host entries."
840 (unless (listp values) 851 (unless (listp values)
841 (setq values (list values))) 852 (setq values (list values)))
842 (mapcar (lambda (value) 853 (mapcar (lambda (value)
843 (if (numberp value) 854 (if (numberp value)
844 (format "%s" value) 855 (format "%s" value)
845 value)) 856 value))
846 values)) 857 values))
847 858
848;;; Backend specific parsing: netrc/authinfo backend 859;;; Backend specific parsing: netrc/authinfo backend
849 860
@@ -888,7 +899,7 @@ Note that the MAX parameter is used so we can exit the parse early."
888 (base64-encode-string 899 (base64-encode-string
889 (buffer-string))))) 900 (buffer-string)))))
890 (lambda () (base64-decode-string 901 (lambda () (base64-decode-string
891 (rot13-string v))))))) 902 (rot13-string v)))))))
892 (goto-char (point-min)) 903 (goto-char (point-min))
893 ;; Go through the file, line by line. 904 ;; Go through the file, line by line.
894 (while (and (not (eobp)) 905 (while (and (not (eobp))
@@ -955,7 +966,7 @@ Note that the MAX parameter is used so we can exit the parse early."
955 (null require) 966 (null require)
956 ;; every element of require is in the normalized list 967 ;; every element of require is in the normalized list
957 (let ((normalized (nth 0 (auth-source-netrc-normalize 968 (let ((normalized (nth 0 (auth-source-netrc-normalize
958 (list alist) file)))) 969 (list alist) file))))
959 (loop for req in require 970 (loop for req in require
960 always (plist-get normalized req))))) 971 always (plist-get normalized req)))))
961 (decf max) 972 (decf max)
@@ -993,25 +1004,7 @@ Note that the MAX parameter is used so we can exit the parse early."
993 1004
994(defvar auth-source-passphrase-alist nil) 1005(defvar auth-source-passphrase-alist nil)
995 1006
996(defun auth-source-passphrase-callback-function (context key-id handback
997 &optional sym-detail)
998 "Exactly like `epa-passphrase-callback-function' but takes an
999extra SYM-DETAIL parameter which will be printed at the end of
1000the symmetric passphrase prompt, and assumes symmetric
1001encryption."
1002 (read-passwd
1003 (format "Passphrase for symmetric encryption%s%s: "
1004 ;; Add the file name to the prompt, if any.
1005 (if (stringp handback)
1006 (format " for %s" handback)
1007 "")
1008 (if (stringp sym-detail)
1009 sym-detail
1010 ""))
1011 (eq (epg-context-operation context) 'encrypt)))
1012
1013(defun auth-source-token-passphrase-callback-function (context key-id file) 1007(defun auth-source-token-passphrase-callback-function (context key-id file)
1014 (if (eq key-id 'SYM)
1015 (let* ((file (file-truename file)) 1008 (let* ((file (file-truename file))
1016 (entry (assoc file auth-source-passphrase-alist)) 1009 (entry (assoc file auth-source-passphrase-alist))
1017 passphrase) 1010 passphrase)
@@ -1023,14 +1016,13 @@ encryption."
1023 (unless entry 1016 (unless entry
1024 (setq entry (list file)) 1017 (setq entry (list file))
1025 (push entry auth-source-passphrase-alist)) 1018 (push entry auth-source-passphrase-alist))
1026 (setq passphrase (auth-source-passphrase-callback-function context 1019 (setq passphrase
1027 key-id 1020 (read-passwd
1028 file 1021 (format "Passphrase for %s tokens: " file)
1029 " tokens")) 1022 t))
1030 (setcdr entry (lexical-let ((p (copy-sequence passphrase))) 1023 (setcdr entry (lexical-let ((p (copy-sequence passphrase)))
1031 (lambda () p))) 1024 (lambda () p)))
1032 passphrase))) 1025 passphrase))))
1033 (epa-passphrase-callback-function context key-id file)))
1034 1026
1035;; (auth-source-epa-extract-gpg-token "gpg:LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tClZlcnNpb246IEdudVBHIHYxLjQuMTEgKEdOVS9MaW51eCkKCmpBMEVBd01DT25qMjB1ak9rZnRneVI3K21iNm9aZWhuLzRad3cySkdlbnVaKzRpeEswWDY5di9icDI1U1dsQT0KPS9yc2wKLS0tLS1FTkQgUEdQIE1FU1NBR0UtLS0tLQo=" "~/.netrc") 1027;; (auth-source-epa-extract-gpg-token "gpg:LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tClZlcnNpb246IEdudVBHIHYxLjQuMTEgKEdOVS9MaW51eCkKCmpBMEVBd01DT25qMjB1ak9rZnRneVI3K21iNm9aZWhuLzRad3cySkdlbnVaKzRpeEswWDY5di9icDI1U1dsQT0KPS9yc2wKLS0tLS1FTkQgUEdQIE1FU1NBR0UtLS0tLQo=" "~/.netrc")
1036(defun auth-source-epa-extract-gpg-token (secret file) 1028(defun auth-source-epa-extract-gpg-token (secret file)
@@ -1096,11 +1088,11 @@ FILE is the file from which we obtained this token."
1096 (when token-decoder 1088 (when token-decoder
1097 (setq lexv (funcall token-decoder lexv))) 1089 (setq lexv (funcall token-decoder lexv)))
1098 lexv)))) 1090 lexv))))
1099 (setq ret (plist-put ret 1091 (setq ret (plist-put ret
1100 (intern (concat ":" k)) 1092 (intern (concat ":" k))
1101 v)))) 1093 v))))
1102 ret)) 1094 ret))
1103 alist)) 1095 alist))
1104 1096
1105;;; (setq secret (plist-get (nth 0 (auth-source-search :host t :type 'netrc :K 1 :max 1)) :secret)) 1097;;; (setq secret (plist-get (nth 0 (auth-source-search :host t :type 'netrc :K 1 :max 1)) :secret))
1106;;; (funcall secret) 1098;;; (funcall secret)
@@ -1110,7 +1102,7 @@ FILE is the file from which we obtained this token."
1110 &key backend require create delete 1102 &key backend require create delete
1111 type max host user port 1103 type max host user port
1112 &allow-other-keys) 1104 &allow-other-keys)
1113"Given a property list SPEC, return search matches from the :backend. 1105 "Given a property list SPEC, return search matches from the :backend.
1114See `auth-source-search' for details on SPEC." 1106See `auth-source-search' for details on SPEC."
1115 ;; just in case, check that the type is correct (null or same as the backend) 1107 ;; just in case, check that the type is correct (null or same as the backend)
1116 (assert (or (null type) (eq type (oref backend type))) 1108 (assert (or (null type) (eq type (oref backend type)))
@@ -1160,9 +1152,9 @@ See `auth-source-search' for details on SPEC."
1160 ;; we know (because of an assertion in auth-source-search) that the 1152 ;; we know (because of an assertion in auth-source-search) that the
1161 ;; :create parameter is either t or a list (which includes nil) 1153 ;; :create parameter is either t or a list (which includes nil)
1162 (create-extra (if (eq t create) nil create)) 1154 (create-extra (if (eq t create) nil create))
1163 (current-data (car (auth-source-search :max 1 1155 (current-data (car (auth-source-search :max 1
1164 :host host 1156 :host host
1165 :port port))) 1157 :port port)))
1166 (required (append base-required create-extra)) 1158 (required (append base-required create-extra))
1167 (file (oref backend source)) 1159 (file (oref backend source))
1168 (add "") 1160 (add "")
@@ -1198,8 +1190,8 @@ See `auth-source-search' for details on SPEC."
1198 (let* ((data (aget valist r)) 1190 (let* ((data (aget valist r))
1199 ;; take the first element if the data is a list 1191 ;; take the first element if the data is a list
1200 (data (or (auth-source-netrc-element-or-first data) 1192 (data (or (auth-source-netrc-element-or-first data)
1201 (plist-get current-data 1193 (plist-get current-data
1202 (intern (format ":%s" r) obarray)))) 1194 (intern (format ":%s" r) obarray))))
1203 ;; this is the default to be offered 1195 ;; this is the default to be offered
1204 (given-default (aget auth-source-creation-defaults r)) 1196 (given-default (aget auth-source-creation-defaults r))
1205 ;; the default supplementals are simple: 1197 ;; the default supplementals are simple:
@@ -1246,8 +1238,8 @@ See `auth-source-search' for details on SPEC."
1246 (cond 1238 (cond
1247 ((and (null data) (eq r 'secret)) 1239 ((and (null data) (eq r 'secret))
1248 ;; Special case prompt for passwords. 1240 ;; Special case prompt for passwords.
1249;; TODO: make the default (setq auth-source-netrc-use-gpg-tokens `((,(if (boundp 'epa-file-auto-mode-alist-entry) (car (symbol-value 'epa-file-auto-mode-alist-entry)) "\\.gpg\\'") nil) (t gpg))) 1241 ;; TODO: make the default (setq auth-source-netrc-use-gpg-tokens `((,(if (boundp 'epa-file-auto-mode-alist-entry) (car (symbol-value 'epa-file-auto-mode-alist-entry)) "\\.gpg\\'") nil) (t gpg)))
1250;; TODO: or maybe leave as (setq auth-source-netrc-use-gpg-tokens 'never) 1242 ;; TODO: or maybe leave as (setq auth-source-netrc-use-gpg-tokens 'never)
1251 (let* ((ep (format "Use GPG password tokens in %s?" file)) 1243 (let* ((ep (format "Use GPG password tokens in %s?" file))
1252 (gpg-encrypt 1244 (gpg-encrypt
1253 (cond 1245 (cond
@@ -1264,7 +1256,7 @@ See `auth-source-search' for details on SPEC."
1264 (setq ret (cdr item)) 1256 (setq ret (cdr item))
1265 (setq check nil))))) 1257 (setq check nil)))))
1266 (t 'never))) 1258 (t 'never)))
1267 (plain (read-passwd prompt))) 1259 (plain (read-passwd prompt)))
1268 ;; ask if we don't know what to do (in which case 1260 ;; ask if we don't know what to do (in which case
1269 ;; auth-source-netrc-use-gpg-tokens must be a list) 1261 ;; auth-source-netrc-use-gpg-tokens must be a list)
1270 (unless gpg-encrypt 1262 (unless gpg-encrypt
@@ -1312,9 +1304,9 @@ See `auth-source-search' for details on SPEC."
1312 (secret "password") 1304 (secret "password")
1313 (port "port") ; redundant but clearer 1305 (port "port") ; redundant but clearer
1314 (t (symbol-name r))) 1306 (t (symbol-name r)))
1315 (if (string-match "[\" ]" data) 1307 (if (string-match "[\" ]" data)
1316 (format "%S" data) 1308 (format "%S" data)
1317 data))))) 1309 data)))))
1318 (setq add (concat add (funcall printer))))))) 1310 (setq add (concat add (funcall printer)))))))
1319 1311
1320 (plist-put 1312 (plist-put
@@ -1377,9 +1369,9 @@ Respects `auth-source-save-behavior'. Uses
1377 (?n (setq add "" 1369 (?n (setq add ""
1378 done t)) 1370 done t))
1379 (?N 1371 (?N
1380 (setq add "" 1372 (setq add ""
1381 done t) 1373 done t)
1382 (customize-save-variable 'auth-source-save-behavior nil)) 1374 (customize-save-variable 'auth-source-save-behavior nil))
1383 (?e (setq add (read-string "Line to add: " add))) 1375 (?e (setq add (read-string "Line to add: " add)))
1384 (t nil))) 1376 (t nil)))
1385 1377
@@ -1470,11 +1462,11 @@ authentication tokens:
1470 (eq t (plist-get spec k))) 1462 (eq t (plist-get spec k)))
1471 nil 1463 nil
1472 (list k (plist-get spec k)))) 1464 (list k (plist-get spec k))))
1473 search-keys))) 1465 search-keys)))
1474 ;; needed keys (always including host, login, port, and secret) 1466 ;; needed keys (always including host, login, port, and secret)
1475 (returned-keys (mm-delete-duplicates (append 1467 (returned-keys (mm-delete-duplicates (append
1476 '(:host :login :port :secret) 1468 '(:host :login :port :secret)
1477 search-keys))) 1469 search-keys)))
1478 (items (loop for item in (apply 'secrets-search-items coll search-spec) 1470 (items (loop for item in (apply 'secrets-search-items coll search-spec)
1479 unless (and (stringp label) 1471 unless (and (stringp label)
1480 (not (string-match label item))) 1472 (not (string-match label item)))
@@ -1534,31 +1526,31 @@ authentication tokens:
1534 ;; if a search key is nil or t (match anything), we skip it 1526 ;; if a search key is nil or t (match anything), we skip it
1535 (search-spec (apply 'append (mapcar 1527 (search-spec (apply 'append (mapcar
1536 (lambda (k) 1528 (lambda (k)
1537 (let ((v (plist-get spec k))) 1529 (let ((v (plist-get spec k)))
1538 (if (or (null v) 1530 (if (or (null v)
1539 (eq t v)) 1531 (eq t v))
1540 nil 1532 nil
1541 (if (stringp v) 1533 (if (stringp v)
1542 (setq v (list v))) 1534 (setq v (list v)))
1543 (list k v)))) 1535 (list k v))))
1544 search-keys))) 1536 search-keys)))
1545 ;; needed keys (always including host, login, port, and secret) 1537 ;; needed keys (always including host, login, port, and secret)
1546 (returned-keys (mm-delete-duplicates (append 1538 (returned-keys (mm-delete-duplicates (append
1547 '(:host :login :port :secret) 1539 '(:host :login :port :secret)
1548 search-keys))) 1540 search-keys)))
1549 (items (plstore-find store search-spec)) 1541 (items (plstore-find store search-spec))
1550 (item-names (mapcar #'car items)) 1542 (item-names (mapcar #'car items))
1551 (items (butlast items (- (length items) max))) 1543 (items (butlast items (- (length items) max)))
1552 ;; convert the item to a full plist 1544 ;; convert the item to a full plist
1553 (items (mapcar (lambda (item) 1545 (items (mapcar (lambda (item)
1554 (let* ((plist (copy-tree (cdr item))) 1546 (let* ((plist (copy-tree (cdr item)))
1555 (secret (plist-member plist :secret))) 1547 (secret (plist-member plist :secret)))
1556 (if secret 1548 (if secret
1557 (setcar 1549 (setcar
1558 (cdr secret) 1550 (cdr secret)
1559 (lexical-let ((v (car (cdr secret)))) 1551 (lexical-let ((v (car (cdr secret))))
1560 (lambda () v)))) 1552 (lambda () v))))
1561 plist)) 1553 plist))
1562 items)) 1554 items))
1563 ;; ensure each item has each key in `returned-keys' 1555 ;; ensure each item has each key in `returned-keys'
1564 (items (mapcar (lambda (plist) 1556 (items (mapcar (lambda (plist)
@@ -1574,38 +1566,38 @@ authentication tokens:
1574 (cond 1566 (cond
1575 ;; if we need to create an entry AND none were found to match 1567 ;; if we need to create an entry AND none were found to match
1576 ((and create 1568 ((and create
1577 (not items)) 1569 (not items))
1578 1570
1579 ;; create based on the spec and record the value 1571 ;; create based on the spec and record the value
1580 (setq items (or 1572 (setq items (or
1581 ;; if the user did not want to create the entry 1573 ;; if the user did not want to create the entry
1582 ;; in the file, it will be returned 1574 ;; in the file, it will be returned
1583 (apply (slot-value backend 'create-function) spec) 1575 (apply (slot-value backend 'create-function) spec)
1584 ;; if not, we do the search again without :create 1576 ;; if not, we do the search again without :create
1585 ;; to get the updated data. 1577 ;; to get the updated data.
1586 1578
1587 ;; the result will be returned, even if the search fails 1579 ;; the result will be returned, even if the search fails
1588 (apply 'auth-source-plstore-search 1580 (apply 'auth-source-plstore-search
1589 (plist-put spec :create nil))))) 1581 (plist-put spec :create nil)))))
1590 ((and delete 1582 ((and delete
1591 item-names) 1583 item-names)
1592 (dolist (item-name item-names) 1584 (dolist (item-name item-names)
1593 (plstore-delete store item-name)) 1585 (plstore-delete store item-name))
1594 (plstore-save store))) 1586 (plstore-save store)))
1595 items)) 1587 items))
1596 1588
1597(defun* auth-source-plstore-create (&rest spec 1589(defun* auth-source-plstore-create (&rest spec
1598 &key backend 1590 &key backend
1599 secret host user port create 1591 secret host user port create
1600 &allow-other-keys) 1592 &allow-other-keys)
1601 (let* ((base-required '(host user port secret)) 1593 (let* ((base-required '(host user port secret))
1602 (base-secret '(secret)) 1594 (base-secret '(secret))
1603 ;; we know (because of an assertion in auth-source-search) that the 1595 ;; we know (because of an assertion in auth-source-search) that the
1604 ;; :create parameter is either t or a list (which includes nil) 1596 ;; :create parameter is either t or a list (which includes nil)
1605 (create-extra (if (eq t create) nil create)) 1597 (create-extra (if (eq t create) nil create))
1606 (current-data (car (auth-source-search :max 1 1598 (current-data (car (auth-source-search :max 1
1607 :host host 1599 :host host
1608 :port port))) 1600 :port port)))
1609 (required (append base-required create-extra)) 1601 (required (append base-required create-extra))
1610 (file (oref backend source)) 1602 (file (oref backend source))
1611 (add "") 1603 (add "")
@@ -1613,7 +1605,7 @@ authentication tokens:
1613 valist 1605 valist
1614 ;; `artificial' will be returned if no creation is needed 1606 ;; `artificial' will be returned if no creation is needed
1615 artificial 1607 artificial
1616 secret-artificial) 1608 secret-artificial)
1617 1609
1618 ;; only for base required elements (defined as function parameters): 1610 ;; only for base required elements (defined as function parameters):
1619 ;; fill in the valist with whatever data we may have from the search 1611 ;; fill in the valist with whatever data we may have from the search
@@ -1642,8 +1634,8 @@ authentication tokens:
1642 (let* ((data (aget valist r)) 1634 (let* ((data (aget valist r))
1643 ;; take the first element if the data is a list 1635 ;; take the first element if the data is a list
1644 (data (or (auth-source-netrc-element-or-first data) 1636 (data (or (auth-source-netrc-element-or-first data)
1645 (plist-get current-data 1637 (plist-get current-data
1646 (intern (format ":%s" r) obarray)))) 1638 (intern (format ":%s" r) obarray))))
1647 ;; this is the default to be offered 1639 ;; this is the default to be offered
1648 (given-default (aget auth-source-creation-defaults r)) 1640 (given-default (aget auth-source-creation-defaults r))
1649 ;; the default supplementals are simple: 1641 ;; the default supplementals are simple:
@@ -1702,23 +1694,23 @@ authentication tokens:
1702 (t (or data default)))) 1694 (t (or data default))))
1703 1695
1704 (when data 1696 (when data
1705 (if (member r base-secret) 1697 (if (member r base-secret)
1706 (setq secret-artificial 1698 (setq secret-artificial
1707 (plist-put secret-artificial 1699 (plist-put secret-artificial
1708 (intern (concat ":" (symbol-name r))) 1700 (intern (concat ":" (symbol-name r)))
1709 data)) 1701 data))
1710 (setq artificial (plist-put artificial 1702 (setq artificial (plist-put artificial
1711 (intern (concat ":" (symbol-name r))) 1703 (intern (concat ":" (symbol-name r)))
1712 data)))))) 1704 data))))))
1713 (plstore-put (oref backend data) 1705 (plstore-put (oref backend data)
1714 (sha1 (format "%s@%s:%s" 1706 (sha1 (format "%s@%s:%s"
1715 (plist-get artificial :user) 1707 (plist-get artificial :user)
1716 (plist-get artificial :host) 1708 (plist-get artificial :host)
1717 (plist-get artificial :port))) 1709 (plist-get artificial :port)))
1718 artificial secret-artificial) 1710 artificial secret-artificial)
1719 (if (y-or-n-p (format "Save auth info to file %s? " 1711 (if (y-or-n-p (format "Save auth info to file %s? "
1720 (plstore-get-file (oref backend data)))) 1712 (plstore-get-file (oref backend data))))
1721 (plstore-save (oref backend data))))) 1713 (plstore-save (oref backend data)))))
1722 1714
1723;;; older API 1715;;; older API
1724 1716
@@ -1794,14 +1786,14 @@ MODE can be \"login\" or \"password\"."
1794 (cond 1786 (cond
1795 ((equal "password" m) 1787 ((equal "password" m)
1796 (push (if (plist-get choice :secret) 1788 (push (if (plist-get choice :secret)
1797 (funcall (plist-get choice :secret)) 1789 (funcall (plist-get choice :secret))
1798 nil) found)) 1790 nil) found))
1799 ((equal "login" m) 1791 ((equal "login" m)
1800 (push (plist-get choice :user) found))))) 1792 (push (plist-get choice :user) found)))))
1801 (setq found (nreverse found)) 1793 (setq found (nreverse found))
1802 (setq found (if listy found (car-safe found))))) 1794 (setq found (if listy found (car-safe found)))))
1803 1795
1804 found)) 1796 found))
1805 1797
1806(provide 'auth-source) 1798(provide 'auth-source)
1807 1799