aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeodor Zlatanov2011-03-13 04:07:38 +0000
committerKatsumi Yamaoka2011-03-13 04:07:38 +0000
commit4248cca2de96a6732a233e9c1d13c6336b215705 (patch)
tree808e2d99401ed0d77cbe21a9815a35b62988946f
parent8d9101d850b5ad006ce41a231f294ea6de93986a (diff)
downloademacs-4248cca2de96a6732a233e9c1d13c6336b215705.tar.gz
emacs-4248cca2de96a6732a233e9c1d13c6336b215705.zip
Merge changes made in Gnus trunk.
auth.texi (Help for developers): Update docs to explain that the :save-function will only run the first time. auth-source.el (auth-source-format-prompt): Always convert the value to a string to avoid evaluating non-string arguments. (auth-source-netrc-create): Offer default properly, not as initial content in `read-string'. (auth-source-netrc-saver): Use a cache keyed by file name and MD5 hash of line to determine if we've been run before. If so, don't run again, but print a trivial message to indicate the cache was hit instead.
-rw-r--r--doc/misc/ChangeLog5
-rw-r--r--doc/misc/auth.texi12
-rw-r--r--lisp/gnus/ChangeLog10
-rw-r--r--lisp/gnus/auth-source.el141
4 files changed, 103 insertions, 65 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index 1a1ca1d6296..db3a944c160 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,8 @@
12011-03-12 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * auth.texi (Help for developers): Update docs to explain that the
4 :save-function will only run the first time.
5
12011-03-12 Glenn Morris <rgm@gnu.org> 62011-03-12 Glenn Morris <rgm@gnu.org>
2 7
3 * Makefile.in (emacs-faq.html): Fix some more cross-refs. 8 * Makefile.in (emacs-faq.html): Fix some more cross-refs.
diff --git a/doc/misc/auth.texi b/doc/misc/auth.texi
index 85a3f098131..a16da92343e 100644
--- a/doc/misc/auth.texi
+++ b/doc/misc/auth.texi
@@ -289,11 +289,21 @@ Later, after a successful login, @code{nnimal.el} calls the
289 (funcall (nth 2 credentials))) 289 (funcall (nth 2 credentials)))
290@end example 290@end example
291 291
292Which will work whether the @code{:save-function} was provided or not. 292This will work whether the @code{:save-function} was provided or not.
293@code{:save-function} will be provided only when a new entry was 293@code{:save-function} will be provided only when a new entry was
294created, so this effectively says ``after a successful login, save the 294created, so this effectively says ``after a successful login, save the
295authentication information we just used, if it was newly created.'' 295authentication information we just used, if it was newly created.''
296 296
297After the first time it's called, the @code{:save-function} will not
298run again (but it will log something if you have set
299@code{auth-source-debug} to @code{'trivia}). This is so it won't ask
300the same question again, which is annoying. This is so it won't ask
301the same question again, which is annoying. This is so it won't ask
302the same question again, which is annoying.
303
304So the responsibility of the API user that specified @code{:create t}
305is to call the @code{:save-function} if it's provided.
306
297@defun auth-source-delete SPEC 307@defun auth-source-delete SPEC
298 308
299TODO: how to include docstring? 309TODO: how to include docstring?
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 2737004615e..ec12faada98 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,13 @@
12011-03-12 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * auth-source.el (auth-source-format-prompt): Always convert the value
4 to a string to avoid evaluating non-string arguments.
5 (auth-source-netrc-create): Offer default properly, not as initial
6 content in `read-string'.
7 (auth-source-netrc-saver): Use a cache keyed by file name and MD5 hash
8 of line to determine if we've been run before. If so, don't run again,
9 but print a trivial message to indicate the cache was hit instead.
10
12011-03-11 Teodor Zlatanov <tzz@lifelogs.com> 112011-03-11 Teodor Zlatanov <tzz@lifelogs.com>
2 12
3 * gnus-sync.el (gnus-sync-install-hooks, gnus-sync-unload-hook): Don't 13 * gnus-sync.el (gnus-sync-install-hooks, gnus-sync-unload-hook): Don't
diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el
index b7e0c97ce50..0fb153ad09b 100644
--- a/lisp/gnus/auth-source.el
+++ b/lisp/gnus/auth-source.el
@@ -54,6 +54,8 @@
54(autoload 'secrets-list-collections "secrets") 54(autoload 'secrets-list-collections "secrets")
55(autoload 'secrets-search-items "secrets") 55(autoload 'secrets-search-items "secrets")
56 56
57(autoload 'rfc2104-hash "rfc2104")
58
57(defvar secrets-enabled) 59(defvar secrets-enabled)
58 60
59(defgroup auth-source nil 61(defgroup auth-source nil
@@ -770,7 +772,9 @@ while \(:host t) would find all host entries."
770 (let ((c (nth 0 cell)) 772 (let ((c (nth 0 cell))
771 (v (nth 1 cell))) 773 (v (nth 1 cell)))
772 (when (and c v) 774 (when (and c v)
773 (setq prompt (replace-regexp-in-string (format "%%%c" c) v prompt))))) 775 (setq prompt (replace-regexp-in-string (format "%%%c" c)
776 (format "%s" v)
777 prompt)))))
774 prompt) 778 prompt)
775 779
776(defun auth-source-ensure-strings (values) 780(defun auth-source-ensure-strings (values)
@@ -1096,7 +1100,7 @@ See `auth-source-search' for details on SPEC."
1096 ;; special case prompt for passwords 1100 ;; special case prompt for passwords
1097 (read-passwd prompt)) 1101 (read-passwd prompt))
1098 ((null data) 1102 ((null data)
1099 (read-string prompt default)) 1103 (read-string prompt nil nil default))
1100 (t (or data default)))) 1104 (t (or data default))))
1101 1105
1102 (when data 1106 (when data
@@ -1138,70 +1142,79 @@ See `auth-source-search' for details on SPEC."
1138 1142
1139 (list artificial))) 1143 (list artificial)))
1140 1144
1141;;(funcall (plist-get (nth 0 (auth-source-search :host '("nonesuch") :user "tzz" :port "imap" :create t :max 1)) :save-function)) 1145;;(funcall (plist-get (nth 0 (auth-source-search :host '("nonesuch2") :user "tzz" :port "imap" :create t :max 1)) :save-function))
1142(defun auth-source-netrc-saver (file add) 1146(defun auth-source-netrc-saver (file add)
1143 "Save a line ADD in FILE, prompting along the way. 1147 "Save a line ADD in FILE, prompting along the way.
1144Respects `auth-source-save-behavior'." 1148Respects `auth-source-save-behavior'. Uses
1145 (with-temp-buffer 1149`auth-source-netrc-cache' to avoid prompting more than once."
1146 (when (file-exists-p file) 1150 (let* ((key (format "%s %s" file (rfc2104-hash 'md5 64 16 file add)))
1147 (insert-file-contents file)) 1151 (cached (assoc key auth-source-netrc-cache)))
1148 (when auth-source-gpg-encrypt-to 1152
1149 ;; (see bug#7487) making `epa-file-encrypt-to' local to 1153 (if cached
1150 ;; this buffer lets epa-file skip the key selection query 1154 (auth-source-do-trivia
1151 ;; (see the `local-variable-p' check in 1155 "auth-source-netrc-saver: found previous run for key %s, returning"
1152 ;; `epa-file-write-region'). 1156 key)
1153 (unless (local-variable-p 'epa-file-encrypt-to (current-buffer)) 1157 (with-temp-buffer
1154 (make-local-variable 'epa-file-encrypt-to)) 1158 (when (file-exists-p file)
1155 (if (listp auth-source-gpg-encrypt-to) 1159 (insert-file-contents file))
1156 (setq epa-file-encrypt-to auth-source-gpg-encrypt-to))) 1160 (when auth-source-gpg-encrypt-to
1157 ;; we want the new data to be found first, so insert at beginning 1161 ;; (see bug#7487) making `epa-file-encrypt-to' local to
1158 (goto-char (point-min)) 1162 ;; this buffer lets epa-file skip the key selection query
1159 1163 ;; (see the `local-variable-p' check in
1160 ;; ask AFTER we've successfully opened the file 1164 ;; `epa-file-write-region').
1161 (let ((prompt (format "Save auth info to file %s? " file)) 1165 (unless (local-variable-p 'epa-file-encrypt-to (current-buffer))
1162 (done (not (eq auth-source-save-behavior 'ask))) 1166 (make-local-variable 'epa-file-encrypt-to))
1163 (bufname "*auth-source Help*") 1167 (if (listp auth-source-gpg-encrypt-to)
1164 k) 1168 (setq epa-file-encrypt-to auth-source-gpg-encrypt-to)))
1165 (while (not done) 1169 ;; we want the new data to be found first, so insert at beginning
1166 (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ?e ??))) 1170 (goto-char (point-min))
1167 (case k 1171
1168 (?y (setq done t)) 1172 ;; ask AFTER we've successfully opened the file
1169 (?? (save-excursion 1173 (let ((prompt (format "Save auth info to file %s? " file))
1170 (with-output-to-temp-buffer bufname 1174 (done (not (eq auth-source-save-behavior 'ask)))
1171 (princ 1175 (bufname "*auth-source Help*")
1172 (concat "(y)es, save\n" 1176 k)
1173 "(n)o but use the info\n" 1177 (while (not done)
1174 "(N)o and don't ask to save again\n" 1178 (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ?e ??)))
1175 "(e)dit the line\n" 1179 (case k
1176 "(?) for help as you can see.\n")) 1180 (?y (setq done t))
1177 (set-buffer standard-output) 1181 (?? (save-excursion
1178 (help-mode)))) 1182 (with-output-to-temp-buffer bufname
1179 (?n (setq add "" 1183 (princ
1180 done t)) 1184 (concat "(y)es, save\n"
1181 (?N (setq add "" 1185 "(n)o but use the info\n"
1182 done t 1186 "(N)o and don't ask to save again\n"
1183 auth-source-save-behavior nil)) 1187 "(e)dit the line\n"
1184 (?e (setq add (read-string "Line to add: " add))) 1188 "(?) for help as you can see.\n"))
1185 (t nil))) 1189 (set-buffer standard-output)
1186 1190 (help-mode))))
1187 (when (get-buffer-window bufname) 1191 (?n (setq add ""
1188 (delete-window (get-buffer-window bufname))) 1192 done t))
1189 1193 (?N (setq add ""
1190 ;; make sure the info is not saved 1194 done t
1191 (when (null auth-source-save-behavior) 1195 auth-source-save-behavior nil))
1192 (setq add "")) 1196 (?e (setq add (read-string "Line to add: " add)))
1193 1197 (t nil)))
1194 (when (< 0 (length add)) 1198
1195 (progn 1199 (when (get-buffer-window bufname)
1196 (unless (bolp) 1200 (delete-window (get-buffer-window bufname)))
1197 (insert "\n")) 1201
1198 (insert add "\n") 1202 ;; make sure the info is not saved
1199 (write-region (point-min) (point-max) file nil 'silent) 1203 (when (null auth-source-save-behavior)
1200 (auth-source-do-debug 1204 (setq add ""))
1201 "auth-source-netrc-create: wrote 1 new line to %s" 1205
1202 file) 1206 (when (< 0 (length add))
1203 (message "Saved new authentication information to %s" file) 1207 (progn
1204 nil))))) 1208 (unless (bolp)
1209 (insert "\n"))
1210 (insert add "\n")
1211 (write-region (point-min) (point-max) file nil 'silent)
1212 (auth-source-do-debug
1213 "auth-source-netrc-create: wrote 1 new line to %s"
1214 file)
1215 (message "Saved new authentication information to %s" file)
1216 nil))))
1217 (aput 'auth-source-netrc-cache key "ran"))))
1205 1218
1206;;; Backend specific parsing: Secrets API backend 1219;;; Backend specific parsing: Secrets API backend
1207 1220