1 ;;; auth-source.el --- authentication sources for Gnus and Emacs
3 ;; Copyright (C) 2008-2011 Free Software Foundation, Inc.
5 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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.
30 ;; See the auth.info Info documentation for details.
34 ;; - never decode the backend file unless it's necessary
35 ;; - a more generic way to match backends and search backend contents
36 ;; - absorb netrc.el and simplify it
37 ;; - protect passwords better
38 ;; - allow creating and changing netrc lines (not files) e.g. change a password
45 (eval-when-compile (require 'cl))
46 (eval-when-compile (require 'eieio))
48 (autoload 'secrets-create-item "secrets")
49 (autoload 'secrets-delete-item "secrets")
50 (autoload 'secrets-get-alias "secrets")
51 (autoload 'secrets-get-attribute "secrets")
52 (autoload 'secrets-get-secret "secrets")
53 (autoload 'secrets-list-collections "secrets")
54 (autoload 'secrets-search-items "secrets")
56 (defvar secrets-enabled)
58 (defgroup auth-source nil
59 "Authentication sources."
60 :version "23.1" ;; No Gnus
63 (defclass auth-source-backend ()
68 :documentation "The backend type.")
69 (source :initarg :source
72 :documentation "The backend source.")
77 :documentation "The backend host.")
82 :documentation "The backend user.")
83 (protocol :initarg :protocol
87 :documentation "The backend protocol.")
88 (create-function :initarg :create-function
92 :documentation "The create function.")
93 (search-function :initarg :search-function
97 :documentation "The search function.")))
99 ;;(auth-source-backend "netrc" :type 'netrc)
101 (defcustom auth-source-protocols '((imap "imap" "imaps" "143" "993")
102 (pop3 "pop3" "pop" "pop3s" "110" "995")
106 "List of authentication protocols and their names"
109 :version "23.2" ;; No Gnus
110 :type '(repeat :tag "Authentication Protocols"
111 (cons :tag "Protocol Entry"
112 (symbol :tag "Protocol")
114 (string :tag "Name")))))
116 ;;; generate all the protocols in a format Customize can use
117 ;;; TODO: generate on the fly from auth-source-protocols
118 (defconst auth-source-protocols-customize
120 (let ((p (car-safe a)))
122 :tag (upcase (symbol-name p))
124 auth-source-protocols))
126 (defvar auth-source-creation-defaults nil
127 "Defaults for creating token values. Usually let-bound.")
129 (defvar auth-source-cache (make-hash-table :test 'equal)
130 "Cache for auth-source data")
132 (defcustom auth-source-do-cache t
133 "Whether auth-source should cache information."
135 :version "23.2" ;; No Gnus
138 (defcustom auth-source-debug nil
139 "Whether auth-source should log debug messages.
140 Also see `auth-source-hide-passwords'.
142 If the value is nil, debug messages are not logged.
143 If the value is t, debug messages are logged with `message'.
144 In that case, your authentication data will be in the
145 clear (except for passwords, which are always stripped out).
146 If the value is a function, debug messages are logged by calling
147 that function using the same arguments as `message'."
149 :version "23.2" ;; No Gnus
151 :tag "auth-source debugging mode"
152 (const :tag "Log using `message' to the *Messages* buffer" t)
153 (function :tag "Function that takes arguments like `message'")
154 (const :tag "Don't log anything" nil)))
156 (defcustom auth-source-hide-passwords t
157 "Whether auth-source should hide passwords in log messages.
158 Only relevant if `auth-source-debug' is not nil."
160 :version "23.2" ;; No Gnus
163 (defcustom auth-sources '("~/.authinfo.gpg" "~/.authinfo")
164 "List of authentication sources.
166 The default will get login and password information from
167 \"~/.authinfo.gpg\", which you should set up with the EPA/EPG
168 packages to be encrypted. If that file doesn't exist, it will
169 try the unencrypted version \"~/.authinfo\".
171 See the auth.info manual for details.
173 Each entry is the authentication type with optional properties.
175 It's best to customize this with `M-x customize-variable' because the choices
176 can get pretty complex."
178 :version "24.1" ;; No Gnus
179 :type `(repeat :tag "Authentication Sources"
181 (string :tag "Just a file")
182 (const :tag "Default Secrets API Collection" 'default)
183 (const :tag "Login Secrets API Collection" "secrets:login")
184 (const :tag "Temp Secrets API Collection" "secrets:session")
185 (list :tag "Source definition"
186 (const :format "" :value :source)
187 (choice :tag "Authentication backend choice"
188 (string :tag "Authentication Source (file)")
190 :tag "Secret Service API/KWallet/GNOME Keyring"
191 (const :format "" :value :secrets)
192 (choice :tag "Collection to use"
193 (string :tag "Collection name")
194 (const :tag "Default" 'default)
195 (const :tag "Login" "login")