annotate lisp/gnus/auth-source.el @ 110718:38ee498456a4

* lisp/gnus/smime.el (smime-cert-by-ldap-1): Drop Emacs 21 code.
author Glenn Morris <rgm@gnu.org>
date Sat, 02 Oct 2010 19:09:53 -0700
parents 867180d035b0
children d2b45bb936b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
1 ;;; auth-source.el --- authentication sources for Gnus and Emacs
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 103944
diff changeset
3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
4
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
5 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Keywords: news
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
7
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
9
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
13 ;; (at your option) any later version.
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
14
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
19
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
22
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
24
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
25 ;; This is the auth-source.el package. It lets users tell Gnus how to
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
26 ;; authenticate in a single place. Simplicity is the goal. Instead
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
27 ;; of providing 5000 options, we'll stick to simple, easy to
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
28 ;; understand options.
94209
0ffd6dd0f75d Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93386
diff changeset
29
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
30 ;; See the auth.info Info documentation for details.
94980
51e9d65c90fc Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94837
diff changeset
31
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
32 ;;; Code:
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
33
94837
55eb2a3c59b4 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
34 (require 'gnus-util)
110586
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
35 (require 'netrc)
94837
55eb2a3c59b4 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
36
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
37 (eval-when-compile (require 'cl))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
38 (autoload 'secrets-create-item "secrets")
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
39 (autoload 'secrets-delete-item "secrets")
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
40 (autoload 'secrets-get-alias "secrets")
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
41 (autoload 'secrets-get-attribute "secrets")
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
42 (autoload 'secrets-get-secret "secrets")
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
43 (autoload 'secrets-list-collections "secrets")
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
44 (autoload 'secrets-search-items "secrets")
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
45
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
46 (defgroup auth-source nil
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
47 "Authentication sources."
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
48 :version "23.1" ;; No Gnus
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
49 :group 'gnus)
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
50
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
51 (defcustom auth-source-protocols '((imap "imap" "imaps" "143" "993")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
52 (pop3 "pop3" "pop" "pop3s" "110" "995")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
53 (ssh "ssh" "22")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
54 (sftp "sftp" "115")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
55 (smtp "smtp" "25"))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
56 "List of authentication protocols and their names"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
57
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
58 :group 'auth-source
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
59 :version "23.2" ;; No Gnus
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
60 :type '(repeat :tag "Authentication Protocols"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
61 (cons :tag "Protocol Entry"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
62 (symbol :tag "Protocol")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
63 (repeat :tag "Names"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
64 (string :tag "Name")))))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
65
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
66 ;;; generate all the protocols in a format Customize can use
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
67 ;;; TODO: generate on the fly from auth-source-protocols
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
68 (defconst auth-source-protocols-customize
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
69 (mapcar (lambda (a)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
70 (let ((p (car-safe a)))
95665
20496e1c594a * auth-source.el: Precise Tramp doc.
Michael Albinus <michael.albinus@gmx.de>
parents: 95193
diff changeset
71 (list 'const
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
72 :tag (upcase (symbol-name p))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
73 p)))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
74 auth-source-protocols))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
75
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
76 (defvar auth-source-cache (make-hash-table :test 'equal)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
77 "Cache for auth-source data")
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
78
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
79 (defcustom auth-source-do-cache t
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
80 "Whether auth-source should cache information."
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
81 :group 'auth-source
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
82 :version "23.2" ;; No Gnus
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
83 :type `boolean)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
84
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
85 (defcustom auth-source-debug nil
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
86 "Whether auth-source should log debug messages.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
87 Also see `auth-source-hide-passwords'.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
88
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
89 If the value is nil, debug messages are not logged.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
90 If the value is t, debug messages are logged with `message'.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
91 In that case, your authentication data will be in the
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
92 clear (except for passwords, which are always stripped out).
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
93 If the value is a function, debug messages are logged by calling
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
94 that function using the same arguments as `message'."
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
95 :group 'auth-source
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
96 :version "23.2" ;; No Gnus
107433
02eb32da1fbb * auth-source.el (netrc-machine-user-or-password): Autoload.
Michael Albinus <michael.albinus@gmx.de>
parents: 106815
diff changeset
97 :type `(choice
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
98 :tag "auth-source debugging mode"
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
99 (const :tag "Log using `message' to the *Messages* buffer" t)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
100 (function :tag "Function that takes arguments like `message'")
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
101 (const :tag "Don't log anything" nil)))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
102
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
103 (defcustom auth-source-hide-passwords t
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
104 "Whether auth-source should hide passwords in log messages.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
105 Only relevant if `auth-source-debug' is not nil."
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
106 :group 'auth-source
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
107 :version "23.2" ;; No Gnus
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
108 :type `boolean)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
109
110410
f2e111723c3a Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
110 (defcustom auth-sources '((:source "~/.authinfo.gpg")
f2e111723c3a Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
111 (:source "~/.authinfo"))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
112 "List of authentication sources.
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
113
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
114 The default will get login and password information from a .gpg
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
115 file, which you should set up with the EPA/EPG packages to be
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
116 encrypted. See the auth.info manual for details.
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
117
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
118 Each entry is the authentication type with optional properties.
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
119
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
120 It's best to customize this with `M-x customize-variable' because the choices
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
121 can get pretty complex."
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
122 :group 'auth-source
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
123 :version "23.2" ;; No Gnus
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
124 :type `(repeat :tag "Authentication Sources"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
125 (list :tag "Source definition"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
126 (const :format "" :value :source)
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
127 (choice :tag "Authentication backend choice"
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
128 (string :tag "Authentication Source (file)")
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
129 (list :tag "secrets.el (Secret Service API/KWallet/GNOME Keyring)"
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
130 (const :format "" :value :secrets)
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
131 (choice :tag "Collection to use"
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
132 (string :tag "Collection name")
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
133 (const :tag "Default" 'default)
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
134 (const :tag "Login" "login")
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
135 (const :tag "Temporary" "session"))))
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
136 (repeat :tag "Extra Parameters" :inline t
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
137 (choice :tag "Extra parameter"
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
138 (list :tag "Host (omit to match as a fallback)"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
139 (const :format "" :value :host)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
140 (choice :tag "Host (machine) choice"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
141 (const :tag "Any" t)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
142 (regexp :tag "Host (machine) regular expression")))
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
143 (list :tag "Protocol (omit to match as a fallback)"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
144 (const :format "" :value :protocol)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
145 (choice :tag "Protocol"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
146 (const :tag "Any" t)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
147 ,@auth-source-protocols-customize))
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
148 (list :tag "User (omit to match as a fallback)" :inline t
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
149 (const :format "" :value :user)
107473
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
150 (choice :tag "Personality or username"
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
151 (const :tag "Any" t)
0fe940324254 Synch with Gnus trunk
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107433
diff changeset
152 (string :tag "Specific user name"))))))))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
153
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
154 ;; temp for debugging
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
155 ;; (unintern 'auth-source-protocols)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
156 ;; (unintern 'auth-sources)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
157 ;; (customize-variable 'auth-sources)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
158 ;; (setq auth-sources nil)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
159 ;; (format "%S" auth-sources)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
160 ;; (customize-variable 'auth-source-protocols)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
161 ;; (setq auth-source-protocols nil)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
162 ;; (format "%S" auth-source-protocols)
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
163 ;; (auth-source-pick nil :host "a" :port 'imap)
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
164 ;; (auth-source-user-or-password "login" "imap.myhost.com" 'imap)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
165 ;; (auth-source-user-or-password "password" "imap.myhost.com" 'imap)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
166 ;; (auth-source-user-or-password-imap "login" "imap.myhost.com")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
167 ;; (auth-source-user-or-password-imap "password" "imap.myhost.com")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
168 ;; (auth-source-protocol-defaults 'imap)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
169
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
170 ;; (let ((auth-source-debug 'debug)) (auth-source-debug "hello"))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
171 ;; (let ((auth-source-debug t)) (auth-source-debug "hello"))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
172 ;; (let ((auth-source-debug nil)) (auth-source-debug "hello"))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
173 (defun auth-source-do-debug (&rest msg)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
174 ;; set logger to either the function in auth-source-debug or 'message
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
175 ;; note that it will be 'message if auth-source-debug is nil, so
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
176 ;; we also check the value
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
177 (when auth-source-debug
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
178 (let ((logger (if (functionp auth-source-debug)
107433
02eb32da1fbb * auth-source.el (netrc-machine-user-or-password): Autoload.
Michael Albinus <michael.albinus@gmx.de>
parents: 106815
diff changeset
179 auth-source-debug
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
180 'message)))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
181 (apply logger msg))))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
182
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
183 ;; (auth-source-pick nil :host "any" :protocol 'imap :user "joe")
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
184 ;; (auth-source-pick t :host "any" :protocol 'imap :user "joe")
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
185 ;; (setq auth-sources '((:source (:secrets default) :host t :protocol t :user "joe")
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
186 ;; (:source (:secrets "session") :host t :protocol t :user "joe")
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
187 ;; (:source (:secrets "login") :host t :protocol t)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
188 ;; (:source "~/.authinfo.gpg" :host t :protocol t)))
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
189
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
190 ;; (setq auth-sources '((:source (:secrets default) :host t :protocol t :user "joe")
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
191 ;; (:source (:secrets "session") :host t :protocol t :user "joe")
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
192 ;; (:source (:secrets "login") :host t :protocol t)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
193 ;; ))
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
194
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
195 ;; (setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t)))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
196
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
197 (defun auth-get-source (entry)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
198 "Return the source string of ENTRY, which is one entry in `auth-sources'.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
199 If it is a Secret Service API, return the collection name, otherwise
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
200 the file name."
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
201 (let ((source (plist-get entry :source)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
202 (if (stringp source)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
203 source
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
204 ;; Secret Service API.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
205 (setq source (plist-get source :secrets))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
206 (when (eq source 'default)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
207 (setq source (or (secrets-get-alias "default") "login")))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
208 (or source "session"))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
209
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
210 (defun auth-source-pick (&rest spec)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
211 "Parse `auth-sources' for matches of the SPEC plist.
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
212
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
213 Common keys are :host, :protocol, and :user. A value of t in
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
214 SPEC means to always succeed in the match. A string value is
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
215 matched as a regex."
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
216 (let ((keys (loop for i below (length spec) by 2 collect (nth i spec)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
217 choices)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
218 (dolist (choice (copy-tree auth-sources) choices)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
219 (let ((source (plist-get choice :source))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
220 (match t))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
221 (when
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
222 (and
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
223 ;; Check existence of source.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
224 (if (consp source)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
225 ;; Secret Service API.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
226 (member (auth-get-source choice) (secrets-list-collections))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
227 ;; authinfo file.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
228 (file-exists-p source))
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
229
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
230 ;; Check keywords.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
231 (dolist (k keys match)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
232 (let* ((v (plist-get spec k))
108993
cf7a433d2eb6 * auth-source.el (auth-source-pick): If choice does not contain a
Michael Albinus <albinus@detlef>
parents: 108911
diff changeset
233 (choicev (if (plist-member choice k)
cf7a433d2eb6 * auth-source.el (auth-source-pick): If choice does not contain a
Michael Albinus <albinus@detlef>
parents: 108911
diff changeset
234 (plist-get choice k) t)))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
235 (setq match
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
236 (and match
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
237 (or
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
238 ;; source always matches spec key
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
239 (eq t choicev)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
240 ;; source key gives regex to match against spec
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
241 (and (stringp choicev) (string-match choicev v))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
242 ;; source key gives symbol to match against spec
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
243 (and (symbolp choicev) (eq choicev v))))))))
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
244
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
245 (add-to-list 'choices choice 'append))))))
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
246
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
247 (defun auth-source-retrieve (mode entry &rest spec)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
248 "Retrieve MODE credentials according to SPEC from ENTRY."
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
249 (catch 'no-password
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
250 (let ((host (plist-get spec :host))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
251 (user (plist-get spec :user))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
252 (prot (plist-get spec :protocol))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
253 (source (plist-get entry :source))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
254 result)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
255 (cond
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
256 ;; Secret Service API.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
257 ((consp source)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
258 (let ((coll (auth-get-source entry))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
259 item)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
260 ;; Loop over candidates with a matching host attribute.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
261 (dolist (elt (secrets-search-items coll :host host) item)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
262 (when (and (or (not user)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
263 (string-equal
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
264 user (secrets-get-attribute coll elt :user)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
265 (or (not prot)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
266 (string-equal
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
267 prot (secrets-get-attribute coll elt :protocol))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
268 (setq item elt)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
269 (return elt)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
270 ;; Compose result.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
271 (when item
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
272 (setq result
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
273 (mapcar (lambda (m)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
274 (if (string-equal "password" m)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
275 (or (secrets-get-secret coll item)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
276 ;; When we do not find a password,
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
277 ;; we return nil anyway.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
278 (throw 'no-password nil))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
279 (or (secrets-get-attribute coll item :user)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
280 user)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
281 (if (consp mode) mode (list mode)))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
282 (if (consp mode) result (car result))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
283 ;; Anything else is netrc.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
284 (t
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
285 (let ((search (list source (list host) (list (format "%s" prot))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
286 (auth-source-protocol-defaults prot))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
287 (setq result
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
288 (mapcar (lambda (m)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
289 (if (string-equal "password" m)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
290 (or (apply
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
291 'netrc-machine-user-or-password m search)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
292 ;; When we do not find a password, we
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
293 ;; return nil anyway.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
294 (throw 'no-password nil))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
295 (or (apply
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
296 'netrc-machine-user-or-password m search)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
297 user)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
298 (if (consp mode) mode (list mode)))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
299 (if (consp mode) result (car result)))))))
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
300
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
301 (defun auth-source-create (mode entry &rest spec)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
302 "Create interactively credentials according to SPEC in ENTRY.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
303 Return structure as specified by MODE."
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
304 (let* ((host (plist-get spec :host))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
305 (user (plist-get spec :user))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
306 (prot (plist-get spec :protocol))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
307 (source (plist-get entry :source))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
308 (name (concat (if user (format "%s@" user))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
309 host
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
310 (if prot (format ":%s" prot))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
311 result)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
312 (setq result
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
313 (mapcar
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
314 (lambda (m)
110586
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
315 (cons
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
316 m
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
317 (cond
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
318 ((equal "password" m)
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
319 (let ((passwd (read-passwd
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
320 (format "Password for %s on %s: " prot host))))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
321 (cond
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
322 ;; Secret Service API.
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
323 ((consp source)
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
324 (apply
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
325 'secrets-create-item
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
326 (auth-get-source entry) name passwd spec))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
327 (t)) ;; netrc not implemented yes.
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
328 passwd))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
329 ((equal "login" m)
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
330 (or user
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
331 (read-string (format "User name for %s on %s: " prot host))))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
332 (t
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
333 "unknownuser"))))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
334 (if (consp mode) mode (list mode))))
110586
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
335 ;; Allow the source to save the data.
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
336 (cond
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
337 ((consp source)
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
338 ;; Secret Service API -- not implemented.
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
339 )
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
340 (t
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
341 ;; netrc interface.
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
342 (when (y-or-n-p (format "Do you want to save this password in %s? "
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
343 source))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
344 (netrc-store-data source host prot
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
345 (or user (cdr (assoc "login" result)))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
346 (cdr (assoc "password" result))))))
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
347 (if (consp mode)
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
348 (mapcar #'cdr result)
867180d035b0 auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110585
diff changeset
349 (cdar result))))
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
350
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
351 (defun auth-source-delete (entry &rest spec)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
352 "Delete credentials according to SPEC in ENTRY."
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
353 (let ((host (plist-get spec :host))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
354 (user (plist-get spec :user))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
355 (prot (plist-get spec :protocol))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
356 (source (plist-get entry :source)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
357 (cond
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
358 ;; Secret Service API.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
359 ((consp source)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
360 (let ((coll (auth-get-source entry)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
361 ;; Loop over candidates with a matching host attribute.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
362 (dolist (elt (secrets-search-items coll :host host))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
363 (when (and (or (not user)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
364 (string-equal
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
365 user (secrets-get-attribute coll elt :user)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
366 (or (not prot)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
367 (string-equal
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
368 prot (secrets-get-attribute coll elt :protocol))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
369 (secrets-delete-item coll elt)))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
370 (t)))) ;; netrc not implemented yes.
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
371
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
372 (defun auth-source-forget-user-or-password
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
373 (mode host protocol &optional username)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
374 "Remove cached authentication token."
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
375 (interactive "slogin/password: \nsHost: \nsProtocol: \n") ;for testing
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
376 (remhash
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
377 (if username
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
378 (format "%s %s:%s %s" mode host protocol username)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
379 (format "%s %s:%s" mode host protocol))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
380 auth-source-cache))
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
381
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
382 (defun auth-source-forget-all-cached ()
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
383 "Forget all cached auth-source authentication tokens."
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
384 (interactive)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
385 (setq auth-source-cache (make-hash-table :test 'equal)))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
386
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
387 ;; (progn
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
388 ;; (auth-source-forget-all-cached)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
389 ;; (list
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
390 ;; (auth-source-user-or-password '("login" "password") "imap.myhost.com" "other")
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
391 ;; (auth-source-user-or-password '("login" "password") "imap.myhost.com" "other" "tzz")
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
392 ;; (auth-source-user-or-password '("login" "password") "imap.myhost.com" "other" "joe")))
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
393
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
394 (defun auth-source-user-or-password
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
395 (mode host protocol &optional username create-missing delete-existing)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
396 "Find MODE (string or list of strings) matching HOST and PROTOCOL.
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
397
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
398 USERNAME is optional and will be used as \"login\" in a search
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
399 across the Secret Service API (see secrets.el) if the resulting
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
400 items don't have a username. This means that if you search for
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
401 username \"joe\" and it matches an item but the item doesn't have
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
402 a :user attribute, the username \"joe\" will be returned.
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
403
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
404 A non nil DELETE-EXISTING means deleting any matching password
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
405 entry in the respective sources. This is useful only when
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
406 CREATE-MISSING is non nil as well; the intended use case is to
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
407 remove wrong password entries.
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
408
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
409 If no matching entry is found, and CREATE-MISSING is non nil,
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
410 the password will be retrieved interactively, and it will be
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
411 stored in the password database which matches best (see
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
412 `auth-sources').
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
413
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
414 MODE can be \"login\" or \"password\"."
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
415 (auth-source-do-debug
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
416 "auth-source-user-or-password: get %s for %s (%s) + user=%s"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
417 mode host protocol username)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
418 (let* ((listy (listp mode))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
419 (mode (if listy mode (list mode)))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
420 (cname (if username
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
421 (format "%s %s:%s %s" mode host protocol username)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
422 (format "%s %s:%s" mode host protocol)))
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
423 (search (list :host host :protocol protocol))
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
424 (search (if username (append search (list :user username)) search))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
425 (found (if (not delete-existing)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
426 (gethash cname auth-source-cache)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
427 (remhash cname auth-source-cache)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
428 nil)))
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
429 (if found
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
430 (progn
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
431 (auth-source-do-debug
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
432 "auth-source-user-or-password: cached %s=%s for %s (%s) + %s"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
433 mode
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
434 ;; don't show the password
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
435 (if (and (member "password" mode) auth-source-hide-passwords)
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
436 "SECRET"
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
437 found)
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
438 host protocol username)
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
439 found) ; return the found data
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
440 ;; else, if not found
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
441 (let ((choices (apply 'auth-source-pick search)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
442 (dolist (choice choices)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
443 (if delete-existing
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
444 (apply 'auth-source-delete choice search)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
445 (setq found (apply 'auth-source-retrieve mode choice search)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
446 (and found (return found)))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
447
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
448 ;; We haven't found something, so we will create it interactively.
110585
677b6dea1d61 gnus-sum.el (gnus-auto-center-group): Transform into a defcustom.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
449 (when (and (not found) create-missing)
677b6dea1d61 gnus-sum.el (gnus-auto-center-group): Transform into a defcustom.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
450 (setq found (apply 'auth-source-create
677b6dea1d61 gnus-sum.el (gnus-auto-center-group): Transform into a defcustom.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
451 mode (if choices
677b6dea1d61 gnus-sum.el (gnus-auto-center-group): Transform into a defcustom.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
452 (car choices)
677b6dea1d61 gnus-sum.el (gnus-auto-center-group): Transform into a defcustom.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
453 (car auth-sources))
677b6dea1d61 gnus-sum.el (gnus-auto-center-group): Transform into a defcustom.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
454 search)))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
455
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
456 ;; Cache the result.
107563
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
457 (when found
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
458 (auth-source-do-debug
95c2fdf14356 2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 107473
diff changeset
459 "auth-source-user-or-password: found %s=%s for %s (%s) + %s"
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
460 mode
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
461 ;; don't show the password
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
462 (if (and (member "password" mode) auth-source-hide-passwords)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
463 "SECRET" found)
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
464 host protocol username)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
465 (setq found (if listy found (car-safe found)))
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
466 (when auth-source-do-cache
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
467 (puthash cname found auth-source-cache)))
108911
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
468
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
469 found))))
a7f706d2c627 * auth-source.el (top): Autoload `secrets-list-collections',
Michael Albinus <michael.albinus@gmx.de>
parents: 107568
diff changeset
470
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
471 (defun auth-source-protocol-defaults (protocol)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
472 "Return a list of default ports and names for PROTOCOL."
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
473 (cdr-safe (assoc protocol auth-source-protocols)))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
474
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
475 (defun auth-source-user-or-password-imap (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
476 (auth-source-user-or-password mode host 'imap))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
477
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
478 (defun auth-source-user-or-password-pop3 (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
479 (auth-source-user-or-password mode host 'pop3))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
480
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
481 (defun auth-source-user-or-password-ssh (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
482 (auth-source-user-or-password mode host 'ssh))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
483
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
484 (defun auth-source-user-or-password-sftp (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
485 (auth-source-user-or-password mode host 'sftp))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
486
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
487 (defun auth-source-user-or-password-smtp (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
488 (auth-source-user-or-password mode host 'smtp))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
489
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
490 (provide 'auth-source)
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
491
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
492 ;;; auth-source.el ends here