Mercurial > emacs
annotate lisp/gnus/auth-source.el @ 108702:a0b236a315d5
* net/tramp.el (tramp-methods): Add `tramp-async-args' attribute
where appropriate.
(tramp-maybe-open-connection): Use it.
author | Michael Albinus <albinus@detlef> |
---|---|
date | Wed, 19 May 2010 20:56:18 +0200 |
parents | 3350692f1a89 |
children | a7f706d2c627 |
rev | line source |
---|---|
92694 | 1 ;;; auth-source.el --- authentication sources for Gnus and Emacs |
2 | |
106815 | 3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
92694 | 4 |
5 ;; Author: Ted Zlatanov <tzz@lifelogs.com> | |
6 ;; Keywords: news | |
7 | |
8 ;; This file is part of GNU Emacs. | |
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 | 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 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
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 | 18 ;; GNU General Public License for more details. |
19 | |
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 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; This is the auth-source.el package. It lets users tell Gnus how to | |
26 ;; authenticate in a single place. Simplicity is the goal. Instead | |
27 ;; of providing 5000 options, we'll stick to simple, easy to | |
28 ;; understand options. | |
94209 | 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 | 31 |
92694 | 32 ;;; Code: |
33 | |
94837 | 34 (require 'gnus-util) |
35 | |
92694 | 36 (eval-when-compile (require 'cl)) |
107433
02eb32da1fbb
* auth-source.el (netrc-machine-user-or-password): Autoload.
Michael Albinus <michael.albinus@gmx.de>
parents:
106815
diff
changeset
|
37 (autoload 'netrc-machine-user-or-password "netrc") |
107473 | 38 (autoload 'secrets-search-items "secrets") |
39 (autoload 'secrets-get-alias "secrets") | |
40 (autoload 'secrets-get-attribute "secrets") | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
41 (autoload 'secrets-get-secret "secrets") |
92694 | 42 |
43 (defgroup auth-source nil | |
44 "Authentication sources." | |
93386 | 45 :version "23.1" ;; No Gnus |
92694 | 46 :group 'gnus) |
47 | |
93386 | 48 (defcustom auth-source-protocols '((imap "imap" "imaps" "143" "993") |
49 (pop3 "pop3" "pop" "pop3s" "110" "995") | |
50 (ssh "ssh" "22") | |
51 (sftp "sftp" "115") | |
52 (smtp "smtp" "25")) | |
53 "List of authentication protocols and their names" | |
54 | |
55 :group 'auth-source | |
107473 | 56 :version "23.2" ;; No Gnus |
93386 | 57 :type '(repeat :tag "Authentication Protocols" |
58 (cons :tag "Protocol Entry" | |
59 (symbol :tag "Protocol") | |
60 (repeat :tag "Names" | |
61 (string :tag "Name"))))) | |
62 | |
63 ;;; 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
|
64 ;;; TODO: generate on the fly from auth-source-protocols |
93386 | 65 (defconst auth-source-protocols-customize |
66 (mapcar (lambda (a) | |
67 (let ((p (car-safe a))) | |
95665
20496e1c594a
* auth-source.el: Precise Tramp doc.
Michael Albinus <michael.albinus@gmx.de>
parents:
95193
diff
changeset
|
68 (list 'const |
93386 | 69 :tag (upcase (symbol-name p)) |
70 p))) | |
71 auth-source-protocols)) | |
72 | |
99402 | 73 (defvar auth-source-cache (make-hash-table :test 'equal) |
74 "Cache for auth-source data") | |
75 | |
76 (defcustom auth-source-do-cache t | |
77 "Whether auth-source should cache information." | |
78 :group 'auth-source | |
107473 | 79 :version "23.2" ;; No Gnus |
99402 | 80 :type `boolean) |
81 | |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
82 (defcustom auth-source-debug nil |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
83 "Whether auth-source should log debug messages. |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
84 Also see `auth-source-hide-passwords'. |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
85 |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
86 If the value is nil, debug messages are not logged. |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
87 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
|
88 In that case, your authentication data will be in the |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
89 clear (except for passwords, which are always stripped out). |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
90 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
|
91 that function using the same arguments as `message'." |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
92 :group 'auth-source |
107473 | 93 :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
|
94 :type `(choice |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
95 :tag "auth-source debugging mode" |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
96 (const :tag "Log using `message' to the *Messages* buffer" t) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
97 (function :tag "Function that takes arguments like `message'") |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
98 (const :tag "Don't log anything" nil))) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
99 |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
100 (defcustom auth-source-hide-passwords t |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
101 "Whether auth-source should hide passwords in log messages. |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
102 Only relevant if `auth-source-debug' is not nil." |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
103 :group 'auth-source |
107473 | 104 :version "23.2" ;; No Gnus |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
105 :type `boolean) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
106 |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
107 (defcustom auth-sources '((:source "~/.authinfo.gpg")) |
92694 | 108 "List of authentication sources. |
109 | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 |
107473 | 114 Each entry is the authentication type with optional properties. |
115 | |
116 It's best to customize this with `M-x customize-variable' because the choices | |
117 can get pretty complex." | |
92694 | 118 :group 'auth-source |
107473 | 119 :version "23.2" ;; No Gnus |
93386 | 120 :type `(repeat :tag "Authentication Sources" |
121 (list :tag "Source definition" | |
122 (const :format "" :value :source) | |
107473 | 123 (choice :tag "Authentication backend choice" |
124 (string :tag "Authentication Source (file)") | |
125 (list :tag "secrets.el (Secret Service API/KWallet/GNOME KeyRing)" | |
126 (const :format "" :value :secrets) | |
127 (choice :tag "Collection to use" | |
128 (string :tag "Collection name") | |
129 (const :tag "Default" 'default) | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
130 (const :tag "Login" "login") |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
131 (const :tag "Temporary" "session")))) |
107473 | 132 (repeat :tag "Extra Parameters" :inline t |
133 (choice :tag "Extra parameter" | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
134 (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
|
135 (const :format "" :value :host) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
136 (choice :tag "Host (machine) choice" |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
137 (const :tag "Any" t) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
138 (regexp :tag "Host (machine) regular expression"))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
139 (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
|
140 (const :format "" :value :protocol) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
141 (choice :tag "Protocol" |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
142 (const :tag "Any" t) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
143 ,@auth-source-protocols-customize)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
144 (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
|
145 (const :format "" :value :user) |
107473 | 146 (choice :tag "Personality or username" |
147 (const :tag "Any" t) | |
148 (string :tag "Specific user name")))))))) | |
92694 | 149 |
150 ;; temp for debugging | |
93386 | 151 ;; (unintern 'auth-source-protocols) |
152 ;; (unintern 'auth-sources) | |
153 ;; (customize-variable 'auth-sources) | |
154 ;; (setq auth-sources nil) | |
155 ;; (format "%S" auth-sources) | |
156 ;; (customize-variable 'auth-source-protocols) | |
157 ;; (setq auth-source-protocols nil) | |
158 ;; (format "%S" auth-source-protocols) | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
159 ;; (auth-source-pick nil :host "a" :port 'imap) |
93386 | 160 ;; (auth-source-user-or-password "login" "imap.myhost.com" 'imap) |
161 ;; (auth-source-user-or-password "password" "imap.myhost.com" 'imap) | |
162 ;; (auth-source-user-or-password-imap "login" "imap.myhost.com") | |
163 ;; (auth-source-user-or-password-imap "password" "imap.myhost.com") | |
164 ;; (auth-source-protocol-defaults 'imap) | |
165 | |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
166 ;; (let ((auth-source-debug 'debug)) (auth-source-debug "hello")) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
167 ;; (let ((auth-source-debug t)) (auth-source-debug "hello")) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
168 ;; (let ((auth-source-debug nil)) (auth-source-debug "hello")) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
169 (defun auth-source-do-debug (&rest msg) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
170 ;; 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
|
171 ;; 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
|
172 ;; we also check the value |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
173 (when auth-source-debug |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
174 (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
|
175 auth-source-debug |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
176 'message))) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
177 (apply logger msg)))) |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
178 |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
179 ;; (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
|
180 ;; (auth-source-pick t :host "any" :protocol 'imap :user "joe") |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
181 ;; (setq auth-sources '((:source (:secrets default) :host t :protocol t :user "joe") |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
182 ;; (:source (:secrets "session") :host t :protocol t :user "joe") |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
183 ;; (: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
|
184 ;; (: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
|
185 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
186 ;; (setq auth-sources '((:source (:secrets default) :host t :protocol t :user "joe") |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
187 ;; (:source (:secrets "session") :host t :protocol t :user "joe") |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
188 ;; (: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
|
189 ;; )) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
190 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
191 ;; (setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t))) |
93386 | 192 |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
193 (defun auth-source-pick (&rest spec) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
194 "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
|
195 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
196 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
|
197 SPEC means to always succeed in the match. A string value is |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
198 matched as a regex. |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
199 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
200 The first pass skips fallback choices. If no choices are found |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
201 on the first pass, a second pass is made including the fallback |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
202 choices. |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
203 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
204 For string (filename) sources, fallback choices are those where |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
205 PROTOCOL or HOST are nil. |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
206 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
207 For secrets.el collections, the :host and :protocol keys are not |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
208 checked for fallback choices." |
93386 | 209 (let (choices) |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
210 (dolist (fallback '(nil t)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
211 (let ((keys (loop for i below (length spec) by 2 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
212 collect (nth i spec))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
213 (default-session-fallback "login")) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
214 (dolist (choice auth-sources) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
215 (let* ((s (plist-get choice :source)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
216 ;; this is only set for Secret Service API specs (see secrets.el) |
107568
3350692f1a89
2010-03-29 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107563
diff
changeset
|
217 (coll (and (consp s) (plist-get s :secrets))) |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
218 (score 0)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
219 (cond |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
220 (coll ; use secrets.el here |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
221 (when (eq coll 'default) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
222 (setq coll (secrets-get-alias "default")) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
223 (unless coll |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
224 (auth-source-do-debug |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
225 "No 'default' alias. Trying collection '%s'." |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
226 default-session-fallback) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
227 (setq coll default-session-fallback))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
228 (let* ((coll-search (cond |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
229 ((stringp coll) coll) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
230 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
231 ;; when the collection is nil: |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
232 ;; in fallback mode, accept it as any |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
233 ;; otherwise, hope to fail |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
234 ((null coll) (if fallback |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
235 nil |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
236 " *fallback-fail*")))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
237 ;; assemble a search query for secrets-search-items |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
238 ;; in fallback mode, host and protocol are not checked |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
239 (other-search (loop for k |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
240 in (if fallback |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
241 (remove :host |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
242 (remove :protocol keys)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
243 keys) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
244 append (list |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
245 k |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
246 ;; convert symbols to a string |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
247 (let ((v (plist-get spec k))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
248 (if (stringp v) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
249 v |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
250 (prin1-to-string v)))))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
251 ;; the score is based on how exact the search was, |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
252 ;; plus base score = 1 for any match |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
253 (score (1+ (length other-search))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
254 (results (apply 'secrets-search-items |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
255 coll-search |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
256 other-search))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
257 (auth-source-do-debug |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
258 "auth-source-pick: got items %s in collection '%s' + %s" |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
259 results coll-search other-search) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
260 ;; put the results in the choices variable |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
261 (dolist (result results) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
262 (setq choices (cons (list score |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
263 `(:source secrets |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
264 :item ,result |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
265 :collection ,coll |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
266 :search ,coll-search |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
267 ,@other-search)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
268 choices))))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
269 ;; this is any non-secrets spec (currently means a string filename) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
270 (t |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
271 (let ((match t)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
272 (dolist (k keys) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
273 (let* ((v (plist-get spec k)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
274 (choicev (plist-get choice k))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
275 (setq match |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
276 (and match |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
277 (or (eq t choicev) ; source always matches spec key |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
278 ;; source key gives regex to match against spec |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
279 (and (stringp choicev) (string-match choicev v)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
280 ;; source key gives symbol to match against spec |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
281 (and (symbolp choicev) (eq choicev v)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
282 ;; in fallback mode, missing source key is OK |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
283 fallback))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
284 (when match (incf score)))) ; increment the score for each match |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
285 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
286 ;; now if the whole iteration resulted in a match: |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
287 (when match |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
288 (setq choices (cons (list score choice) choices)))))))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
289 ;; when there were matches, skip the second pass |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
290 (when choices (return choices)))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
291 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
292 ;; return the results sorted by score |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
293 (mapcar 'cadr (sort choices (lambda (x y) (> (car x) (car y))))))) |
93386 | 294 |
99402 | 295 (defun auth-source-forget-user-or-password (mode host protocol) |
296 (interactive "slogin/password: \nsHost: \nsProtocol: \n") ;for testing | |
297 (remhash (format "%s %s:%s" mode host protocol) auth-source-cache)) | |
298 | |
101804 | 299 (defun auth-source-forget-all-cached () |
300 "Forget all cached auth-source authentication tokens." | |
301 (interactive) | |
302 (setq auth-source-cache (make-hash-table :test 'equal))) | |
303 | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
304 ;; (progn |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
305 ;; (auth-source-forget-all-cached) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
306 ;; (list |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
307 ;; (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
|
308 ;; (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
|
309 ;; (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
|
310 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
311 (defun auth-source-user-or-password (mode host protocol &optional username) |
101804 | 312 "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
|
313 |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 |
101804 | 320 MODE can be \"login\" or \"password\" for example." |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
321 (auth-source-do-debug |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
322 "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
|
323 mode host protocol username) |
101804 | 324 (let* ((listy (listp mode)) |
325 (mode (if listy mode (list mode))) | |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
326 (extras (when username `(:user ,username))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
327 (cname (format "%s %s:%s %s" mode host protocol extras)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
328 (search (list :host host :protocol protocol)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
329 (search (if username (append search (list :user username)) search)) |
99402 | 330 (found (gethash cname auth-source-cache))) |
331 (if found | |
332 (progn | |
103944
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
333 (auth-source-do-debug |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
334 "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
|
335 mode |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
336 ;; don't show the password |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
337 (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
|
338 "SECRET" |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
339 found) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
340 host protocol extras) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
341 found) ; return the found data |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
342 ;; else, if not found |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
343 (dolist (choice (apply 'auth-source-pick search)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
344 (setq found (cond |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
345 ;; the secrets.el spec |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
346 ((eq (plist-get choice :source) 'secrets) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
347 (let ((coll (plist-get choice :search)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
348 (item (plist-get choice :item))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
349 (mapcar (lambda (m) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
350 (if (equal "password" m) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
351 (secrets-get-secret coll item) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
352 ;; the user name is either |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
353 (or |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
354 ;; the secret's attribute :user, or |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
355 (secrets-get-attribute coll item :user) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
356 ;; the originally requested :user |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
357 username |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
358 "unknown-user"))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
359 mode))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
360 (t ; anything else is netrc |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
361 (netrc-machine-user-or-password |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
362 mode |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
363 (plist-get choice :source) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
364 (list host) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
365 (list (format "%s" protocol)) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
366 (auth-source-protocol-defaults protocol))))) |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
367 (when found |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
368 (auth-source-do-debug |
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
369 "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
|
370 mode |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
371 ;; don't show the password |
aa77db41a051
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
101804
diff
changeset
|
372 (if (and (member "password" mode) auth-source-hide-passwords) "SECRET" found) |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
373 host protocol extras) |
101804 | 374 (setq found (if listy found (car-safe found))) |
99402 | 375 (when auth-source-do-cache |
376 (puthash cname found auth-source-cache))) | |
93386 | 377 (return found))))) |
107563
95c2fdf14356
2010-03-27 Teodor Zlatanov <tzz@lifelogs.com>
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107473
diff
changeset
|
378 |
93386 | 379 (defun auth-source-protocol-defaults (protocol) |
380 "Return a list of default ports and names for PROTOCOL." | |
381 (cdr-safe (assoc protocol auth-source-protocols))) | |
382 | |
94369 | 383 (defun auth-source-user-or-password-imap (mode host) |
384 (auth-source-user-or-password mode host 'imap)) | |
93386 | 385 |
94369 | 386 (defun auth-source-user-or-password-pop3 (mode host) |
387 (auth-source-user-or-password mode host 'pop3)) | |
93386 | 388 |
94369 | 389 (defun auth-source-user-or-password-ssh (mode host) |
390 (auth-source-user-or-password mode host 'ssh)) | |
93386 | 391 |
94369 | 392 (defun auth-source-user-or-password-sftp (mode host) |
393 (auth-source-user-or-password mode host 'sftp)) | |
93386 | 394 |
94369 | 395 (defun auth-source-user-or-password-smtp (mode host) |
396 (auth-source-user-or-password mode host 'smtp)) | |
92694 | 397 |
398 (provide 'auth-source) | |
399 | |
400 ;; arch-tag: ff1afe78-06e9-42c2-b693-e9f922cbe4ab | |
401 ;;; auth-source.el ends here |