Mercurial > emacs
annotate lisp/gnus/auth-source.el @ 94961:ea6c5b7ab8d3
Regenerate.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 14 May 2008 07:40:12 +0000 |
parents | 55eb2a3c59b4 |
children | 51e9d65c90fc |
rev | line source |
---|---|
92694 | 1 ;;; auth-source.el --- authentication sources for Gnus and Emacs |
2 | |
93386 | 3 ;; Copyright (C) 2008 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 |
30 ;; Easy setup: | |
31 ;; (require 'auth-source) | |
32 ;; (customize-variable 'auth-sources) ;; optional | |
33 | |
34 ;; now, whatever sources you've defined for password have to be available | |
35 | |
36 ;; if you want encrypted sources, which is strongly recommended, do | |
37 ;; (require 'epa-file) | |
38 ;; (epa-file-mode) | |
39 | |
40 ;; before you put some data in ~/.authinfo.gpg (the default place) | |
41 | |
94837 | 42 ;;; For url-auth authentication (HTTP/HTTPS), you need to use: |
43 | |
44 ;;; machine yourmachine.com:80 port http login testuser password testpass | |
45 | |
46 ;;; This will match any realm and authentication method (basic or | |
47 ;;; digest). If you want finer controls, explore the url-auth source | |
48 ;;; code and variables. | |
49 | |
92694 | 50 ;;; Code: |
51 | |
94837 | 52 (require 'gnus-util) |
53 | |
92694 | 54 (eval-when-compile (require 'cl)) |
93386 | 55 (eval-when-compile (require 'netrc)) |
92694 | 56 |
57 (defgroup auth-source nil | |
58 "Authentication sources." | |
93386 | 59 :version "23.1" ;; No Gnus |
92694 | 60 :group 'gnus) |
61 | |
93386 | 62 (defcustom auth-source-protocols '((imap "imap" "imaps" "143" "993") |
63 (pop3 "pop3" "pop" "pop3s" "110" "995") | |
64 (ssh "ssh" "22") | |
65 (sftp "sftp" "115") | |
66 (smtp "smtp" "25")) | |
67 "List of authentication protocols and their names" | |
68 | |
69 :group 'auth-source | |
70 :version "23.1" ;; No Gnus | |
71 :type '(repeat :tag "Authentication Protocols" | |
72 (cons :tag "Protocol Entry" | |
73 (symbol :tag "Protocol") | |
74 (repeat :tag "Names" | |
75 (string :tag "Name"))))) | |
76 | |
77 ;;; generate all the protocols in a format Customize can use | |
78 (defconst auth-source-protocols-customize | |
79 (mapcar (lambda (a) | |
80 (let ((p (car-safe a))) | |
81 (list 'const | |
82 :tag (upcase (symbol-name p)) | |
83 p))) | |
84 auth-source-protocols)) | |
85 | |
86 ;;; this default will be changed to ~/.authinfo.gpg | |
87 (defcustom auth-sources '((:source "~/.authinfo.enc" :host t :protocol t)) | |
92694 | 88 "List of authentication sources. |
89 | |
90 Each entry is the authentication type with optional properties." | |
91 :group 'auth-source | |
93386 | 92 :version "23.1" ;; No Gnus |
93 :type `(repeat :tag "Authentication Sources" | |
94 (list :tag "Source definition" | |
95 (const :format "" :value :source) | |
96 (string :tag "Authentication Source") | |
97 (const :format "" :value :host) | |
94209 | 98 (choice :tag "Host (machine) choice" |
93386 | 99 (const :tag "Any" t) |
94209 | 100 (regexp :tag "Host (machine) regular expression (TODO)") |
93386 | 101 (const :tag "Fallback" nil)) |
102 (const :format "" :value :protocol) | |
103 (choice :tag "Protocol" | |
104 (const :tag "Any" t) | |
105 (const :tag "Fallback" nil) | |
106 ,@auth-source-protocols-customize)))) | |
92694 | 107 |
108 ;; temp for debugging | |
93386 | 109 ;; (unintern 'auth-source-protocols) |
110 ;; (unintern 'auth-sources) | |
111 ;; (customize-variable 'auth-sources) | |
112 ;; (setq auth-sources nil) | |
113 ;; (format "%S" auth-sources) | |
114 ;; (customize-variable 'auth-source-protocols) | |
115 ;; (setq auth-source-protocols nil) | |
116 ;; (format "%S" auth-source-protocols) | |
117 ;; (auth-source-pick "a" 'imap) | |
118 ;; (auth-source-user-or-password "login" "imap.myhost.com" 'imap) | |
119 ;; (auth-source-user-or-password "password" "imap.myhost.com" 'imap) | |
120 ;; (auth-source-user-or-password-imap "login" "imap.myhost.com") | |
121 ;; (auth-source-user-or-password-imap "password" "imap.myhost.com") | |
122 ;; (auth-source-protocol-defaults 'imap) | |
123 | |
94369 | 124 (defun auth-source-pick (host protocol &optional fallback) |
125 "Parse `auth-sources' for HOST, and PROTOCOL matches. | |
93386 | 126 |
94369 | 127 Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t." |
93386 | 128 (interactive "sHost: \nsProtocol: \n") ;for testing |
129 (let (choices) | |
130 (dolist (choice auth-sources) | |
94369 | 131 (let ((h (plist-get choice :host)) |
93386 | 132 (p (plist-get choice :protocol))) |
133 (when (and | |
134 (or (equal t h) | |
135 (and (stringp h) (string-match h host)) | |
136 (and fallback (equal h nil))) | |
137 (or (equal t p) | |
138 (and (symbolp p) (equal p protocol)) | |
139 (and fallback (equal p nil)))) | |
140 (push choice choices)))) | |
141 (if choices | |
142 choices | |
143 (unless fallback | |
94369 | 144 (auth-source-pick host protocol t))))) |
93386 | 145 |
94369 | 146 (defun auth-source-user-or-password (mode host protocol) |
147 "Find user or password (from the string MODE) matching HOST and PROTOCOL." | |
94837 | 148 (gnus-message 9 |
149 "auth-source-user-or-password: get %s for %s (%s)" | |
150 mode host protocol) | |
93386 | 151 (let (found) |
94369 | 152 (dolist (choice (auth-source-pick host protocol)) |
93386 | 153 (setq found (netrc-machine-user-or-password |
154 mode | |
155 (plist-get choice :source) | |
156 (list host) | |
157 (list (format "%s" protocol)) | |
158 (auth-source-protocol-defaults protocol))) | |
159 (when found | |
94837 | 160 (gnus-message 9 |
161 "auth-source-user-or-password: found %s=%s for %s (%s)" | |
162 mode | |
163 ;; don't show the password | |
164 (if (equal mode "password") "SECRET" found) | |
165 host protocol) | |
93386 | 166 (return found))))) |
167 | |
168 (defun auth-source-protocol-defaults (protocol) | |
169 "Return a list of default ports and names for PROTOCOL." | |
170 (cdr-safe (assoc protocol auth-source-protocols))) | |
171 | |
94369 | 172 (defun auth-source-user-or-password-imap (mode host) |
173 (auth-source-user-or-password mode host 'imap)) | |
93386 | 174 |
94369 | 175 (defun auth-source-user-or-password-pop3 (mode host) |
176 (auth-source-user-or-password mode host 'pop3)) | |
93386 | 177 |
94369 | 178 (defun auth-source-user-or-password-ssh (mode host) |
179 (auth-source-user-or-password mode host 'ssh)) | |
93386 | 180 |
94369 | 181 (defun auth-source-user-or-password-sftp (mode host) |
182 (auth-source-user-or-password mode host 'sftp)) | |
93386 | 183 |
94369 | 184 (defun auth-source-user-or-password-smtp (mode host) |
185 (auth-source-user-or-password mode host 'smtp)) | |
92694 | 186 |
187 (provide 'auth-source) | |
188 | |
189 ;; arch-tag: ff1afe78-06e9-42c2-b693-e9f922cbe4ab | |
190 ;;; auth-source.el ends here |