annotate lisp/gnus/auth-source.el @ 105964:bedac8edf64d

(define-compiler-macro): Purecopy the file name.
author Dan Nicolaescu <dann@ics.uci.edu>
date Thu, 12 Nov 2009 06:48:03 +0000
parents aa77db41a051
children 1d1d5d9bd884
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
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 99402
diff changeset
3 ;; Copyright (C) 2008, 2009 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)
55eb2a3c59b4 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
35
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
36 (eval-when-compile (require 'cl))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
37 (eval-when-compile (require 'netrc))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
38
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
39 (defgroup auth-source nil
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
40 "Authentication sources."
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
41 :version "23.1" ;; No Gnus
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
42 :group 'gnus)
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
43
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
44 (defcustom auth-source-protocols '((imap "imap" "imaps" "143" "993")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
45 (pop3 "pop3" "pop" "pop3s" "110" "995")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
46 (ssh "ssh" "22")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
47 (sftp "sftp" "115")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
48 (smtp "smtp" "25"))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
49 "List of authentication protocols and their names"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
50
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
51 :group 'auth-source
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
52 :version "23.1" ;; No Gnus
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
53 :type '(repeat :tag "Authentication Protocols"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
54 (cons :tag "Protocol Entry"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
55 (symbol :tag "Protocol")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
56 (repeat :tag "Names"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
57 (string :tag "Name")))))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
58
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
59 ;;; generate all the protocols in a format Customize can use
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
60 (defconst auth-source-protocols-customize
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
61 (mapcar (lambda (a)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
62 (let ((p (car-safe a)))
95665
20496e1c594a * auth-source.el: Precise Tramp doc.
Michael Albinus <michael.albinus@gmx.de>
parents: 95193
diff changeset
63 (list 'const
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
64 :tag (upcase (symbol-name p))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
65 p)))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
66 auth-source-protocols))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
67
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
68 (defvar auth-source-cache (make-hash-table :test 'equal)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
69 "Cache for auth-source data")
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
70
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
71 (defcustom auth-source-do-cache t
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
72 "Whether auth-source should cache information."
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
73 :group 'auth-source
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
74 :version "23.1" ;; No Gnus
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
75 :type `boolean)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
76
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
77 (defcustom auth-source-debug nil
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
78 "Whether auth-source should log debug messages.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
79 Also see `auth-source-hide-passwords'.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
80
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
81 If the value is nil, debug messages are not logged.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
82 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
83 In that case, your authentication data will be in the
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
84 clear (except for passwords, which are always stripped out).
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
85 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
86 that function using the same arguments as `message'."
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
87 :group 'auth-source
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
88 :version "23.1" ;; No Gnus
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
89 :type `(choice
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
90 :tag "auth-source debugging mode"
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
91 (const :tag "Log using `message' to the *Messages* buffer" t)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
92 (function :tag "Function that takes arguments like `message'")
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
93 (const :tag "Don't log anything" nil)))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
94
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
95 (defcustom auth-source-hide-passwords t
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
96 "Whether auth-source should hide passwords in log messages.
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
97 Only relevant if `auth-source-debug' is not nil."
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
98 :group 'auth-source
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
99 :version "23.1" ;; No Gnus
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
100 :type `boolean)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
101
94980
51e9d65c90fc Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94837
diff changeset
102 (defcustom auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
103 "List of authentication sources.
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
104
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 Each entry is the authentication type with optional properties."
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
106 :group 'auth-source
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
107 :version "23.1" ;; No Gnus
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
108 :type `(repeat :tag "Authentication Sources"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
109 (list :tag "Source definition"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
110 (const :format "" :value :source)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
111 (string :tag "Authentication Source")
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
112 (const :format "" :value :host)
94209
0ffd6dd0f75d Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93386
diff changeset
113 (choice :tag "Host (machine) choice"
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
114 (const :tag "Any" t)
94209
0ffd6dd0f75d Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93386
diff changeset
115 (regexp :tag "Host (machine) regular expression (TODO)")
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
116 (const :tag "Fallback" nil))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
117 (const :format "" :value :protocol)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
118 (choice :tag "Protocol"
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
119 (const :tag "Any" t)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
120 (const :tag "Fallback" nil)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
121 ,@auth-source-protocols-customize))))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
122
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
123 ;; temp for debugging
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
124 ;; (unintern 'auth-source-protocols)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
125 ;; (unintern 'auth-sources)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
126 ;; (customize-variable 'auth-sources)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
127 ;; (setq auth-sources nil)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
128 ;; (format "%S" auth-sources)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
129 ;; (customize-variable 'auth-source-protocols)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
130 ;; (setq auth-source-protocols nil)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
131 ;; (format "%S" auth-source-protocols)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
132 ;; (auth-source-pick "a" 'imap)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
133 ;; (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
134 ;; (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
135 ;; (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
136 ;; (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
137 ;; (auth-source-protocol-defaults 'imap)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
138
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
139 ;; (let ((auth-source-debug 'debug)) (auth-source-debug "hello"))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
140 ;; (let ((auth-source-debug t)) (auth-source-debug "hello"))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
141 ;; (let ((auth-source-debug nil)) (auth-source-debug "hello"))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
142 (defun auth-source-do-debug (&rest msg)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
143 ;; 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
144 ;; 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
145 ;; we also check the value
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
146 (when auth-source-debug
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
147 (let ((logger (if (functionp auth-source-debug)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
148 auth-source-debug
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
149 'message)))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
150 (apply logger msg))))
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
151
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
152 (defun auth-source-pick (host protocol &optional fallback)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
153 "Parse `auth-sources' for HOST, and PROTOCOL matches.
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
154
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
155 Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
156 (interactive "sHost: \nsProtocol: \n") ;for testing
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
157 (let (choices)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
158 (dolist (choice auth-sources)
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
159 (let ((h (plist-get choice :host))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
160 (p (plist-get choice :protocol)))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
161 (when (and
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
162 (or (equal t h)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
163 (and (stringp h) (string-match h host))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
164 (and fallback (equal h nil)))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
165 (or (equal t p)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
166 (and (symbolp p) (equal p protocol))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
167 (and fallback (equal p nil))))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
168 (push choice choices))))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
169 (if choices
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
170 choices
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
171 (unless fallback
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
172 (auth-source-pick host protocol t)))))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
173
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
174 (defun auth-source-forget-user-or-password (mode host protocol)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
175 (interactive "slogin/password: \nsHost: \nsProtocol: \n") ;for testing
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
176 (remhash (format "%s %s:%s" mode host protocol) auth-source-cache))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
177
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
178 (defun auth-source-forget-all-cached ()
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
179 "Forget all cached auth-source authentication tokens."
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
180 (interactive)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
181 (setq auth-source-cache (make-hash-table :test 'equal)))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
182
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
183 (defun auth-source-user-or-password (mode host protocol)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
184 "Find MODE (string or list of strings) matching HOST and PROTOCOL.
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
185 MODE can be \"login\" or \"password\" for example."
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
186 (auth-source-do-debug
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
187 "auth-source-user-or-password: get %s for %s (%s)"
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
188 mode host protocol)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
189 (let* ((listy (listp mode))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
190 (mode (if listy mode (list mode)))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
191 (cname (format "%s %s:%s" mode host protocol))
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
192 (found (gethash cname auth-source-cache)))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
193 (if found
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
194 (progn
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
195 (auth-source-do-debug
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
196 "auth-source-user-or-password: cached %s=%s for %s (%s)"
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
197 mode
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
198 ;; don't show the password
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
199 (if (and (member "password" mode) auth-source-hide-passwords) "SECRET" found)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
200 host protocol)
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
201 found)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
202 (dolist (choice (auth-source-pick host protocol))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
203 (setq found (netrc-machine-user-or-password
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
204 mode
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
205 (plist-get choice :source)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
206 (list host)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
207 (list (format "%s" protocol))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
208 (auth-source-protocol-defaults protocol)))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
209 (when found
103944
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
210 (auth-source-do-debug
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
211 "auth-source-user-or-password: found %s=%s for %s (%s)"
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
212 mode
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
213 ;; don't show the password
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
214 (if (and (member "password" mode) auth-source-hide-passwords) "SECRET" found)
aa77db41a051 Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 101804
diff changeset
215 host protocol)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 101281
diff changeset
216 (setq found (if listy found (car-safe found)))
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
217 (when auth-source-do-cache
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95665
diff changeset
218 (puthash cname found auth-source-cache)))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
219 (return found)))))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
220
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
221 (defun auth-source-protocol-defaults (protocol)
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
222 "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
223 (cdr-safe (assoc protocol auth-source-protocols)))
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
224
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
225 (defun auth-source-user-or-password-imap (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
226 (auth-source-user-or-password mode host 'imap))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
227
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
228 (defun auth-source-user-or-password-pop3 (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
229 (auth-source-user-or-password mode host 'pop3))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
230
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
231 (defun auth-source-user-or-password-ssh (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
232 (auth-source-user-or-password mode host 'ssh))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
233
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
234 (defun auth-source-user-or-password-sftp (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
235 (auth-source-user-or-password mode host 'sftp))
93386
a789a1138b08 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 92694
diff changeset
236
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
237 (defun auth-source-user-or-password-smtp (mode host)
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94209
diff changeset
238 (auth-source-user-or-password mode host 'smtp))
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
239
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
240 (provide 'auth-source)
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
241
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
242 ;; arch-tag: ff1afe78-06e9-42c2-b693-e9f922cbe4ab
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents:
diff changeset
243 ;;; auth-source.el ends here