mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-10 15:56:18 +00:00
aa8f82773f
The general approach is to autoload rather than require, and to require in the specific functions rather than the file. (Bug#5642) * url/url.el: Move mailcap require earlier in the file. * gnus/gmm-utils.el: Don't require wid-edit. (widget-create-child-value, widget-convert, widget-default-get): Autoload. * gnus/gnus-util.el: Don't require time-date, netrc. (message-fetch-field, gnus-group-name-decode): Declare rather than autoloading. (gnus-fetch-field): Require message. (gnus-decode-newsgroups): Require gnus-group. * gnus/ietf-drums.el: Don't require time-date. * gnus/message.el: Don't require hashcash, canlock, ecomplete. Do require mail-utils. Require nnheader only when compiling. (smtpmail-default-smtp-server): Remove declaration. (message-send-mail-function): Check smtpmail-default-smtp-server is bound rather than requiring smtpmail. (message-auto-save-directory, message-insert-signature): Use expand-file-name rather than nnheader-concat. (nnheader-insert-file-contents): Autoload. (hashcash-wait-async): Declare. (message-send-mail): Only call gnus-setup-posting-charset if gnus-group-posting-charset-alist is bound. Require hashcash if needed. (message-send-mail-with-sendmail): Require sendmail. (canlock-password, canlock-password-for-verify): Declare. (message-canlock-password): Require canlock. (nnheader-get-report): Autoload. (gnus-setup-posting-charset): Declare. (message-send-news): Require gnus-msg. (message-make-references, message-make-in-reply-to): Use mail-header-id rather than the alias mail-header-message-id. (ecomplete-add-item, ecomplete-save): Declare. (message-put-addresses-in-ecomplete): Require ecomplete. (ecomplete-display-matches): Autoload. * gnus/mm-decode.el: Don't require mailcap, gnus-util. (gnus-map-function, gnus-replace-in-string, gnus-read-shell-command) (message-fetch-field, mailcap-parse-mailcaps, mailcap-mime-info): Autoload. (mailcap-mime-extensions): Declare. * gnus/mm-encode.el: Don't require mailcap. (mailcap-extension-to-mime): Autoload. * gnus/mml-sec.el: Don't require password-cache. * gnus/mml.el (gnus-setup-posting-charset): Declare rather than autoload. (mailcap-parse-mimetypes, mailcap-mime-types): Declare. (mml-minibuffer-read-type): Require mailcap. (mml-preview): Require gnus-msg. * gnus/mml1991.el: Require password-cache. (password-cache-expiry): Remove declaration. * gnus/mml2015.el: Require password-cache. (password-cache-expiry): Remove declaration. * gnus/nneething.el (mailcap): Require mailcap. * gnus/nnheader.el: (declare-function): Add compatibility stub. (message-remove-header): Declare rather than autoload. (nnheader-replace-header): Require message. * gnus/nnimap.el (declare-function): Add compatibility stub. (netrc-parse, netrc-machine-user-or-password): Declare. (nnimap-open-connection): Require netrc. * gnus/nntp.el (declare-function): Add compatibility stub. (netrc-parse, netrc-machine, netrc-get): Declare. (nntp-send-authinfo): Require netrc. * gnus/rfc2047.el: Don't require qp. (quoted-printable-encode-region, quoted-printable-decode-string): Autoload. * gnus/sieve-mode.el: Don't require easymenu. (easy-menu-add-item): Autoload it. * gnus/spam-stat.el (time-to-number-of-days): Autoload it. * password-cache.el (password-cache, password-cache-expiry): Autoload.
139 lines
4.5 KiB
EmacsLisp
139 lines
4.5 KiB
EmacsLisp
;;; password-cache.el --- Read passwords, possibly using a password cache.
|
|
|
|
;; Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
|
;; 2010 Free Software Foundation, Inc.
|
|
|
|
;; Author: Simon Josefsson <simon@josefsson.org>
|
|
;; Created: 2003-12-21
|
|
;; Keywords: password cache passphrase key
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Greatly influenced by pgg.el written by Daiki Ueno, with timer
|
|
;; fixes for XEmacs by Katsumi Yamaoka. In fact, this is mostly just
|
|
;; a rip-off.
|
|
;;
|
|
;; (password-read "Password? " "test")
|
|
;; ;; Minibuffer prompt for password.
|
|
;; => "foo"
|
|
;;
|
|
;; (password-cache-add "test" "foo")
|
|
;; => nil
|
|
|
|
;; (password-read "Password? " "test")
|
|
;; ;; No minibuffer prompt
|
|
;; => "foo"
|
|
;;
|
|
;; (password-read "Password? " "test")
|
|
;; ;; No minibuffer prompt
|
|
;; => "foo"
|
|
;;
|
|
;; ;; Wait `password-cache-expiry' seconds.
|
|
;;
|
|
;; (password-read "Password? " "test")
|
|
;; ;; Minibuffer prompt for password is back.
|
|
;; => "foo"
|
|
|
|
;;; Code:
|
|
|
|
;; Options are autoloaded since they are used by eg mml-sec.el.
|
|
|
|
;;;###autoload
|
|
(defcustom password-cache t
|
|
"Whether to cache passwords."
|
|
:group 'password
|
|
:type 'boolean)
|
|
|
|
;;;###autoload
|
|
(defcustom password-cache-expiry 16
|
|
"How many seconds passwords are cached, or nil to disable expiring.
|
|
Whether passwords are cached at all is controlled by `password-cache'."
|
|
:group 'password
|
|
:type '(choice (const :tag "Never" nil)
|
|
(integer :tag "Seconds")))
|
|
|
|
(defvar password-data (make-vector 7 0))
|
|
|
|
(defun password-read-from-cache (key)
|
|
"Obtain passphrase for KEY from time-limited passphrase cache.
|
|
Custom variables `password-cache' and `password-cache-expiry'
|
|
regulate cache behavior."
|
|
(and password-cache
|
|
key
|
|
(symbol-value (intern-soft key password-data))))
|
|
|
|
(defun password-read (prompt &optional key)
|
|
"Read password, for use with KEY, from user, or from cache if wanted.
|
|
KEY indicate the purpose of the password, so the cache can
|
|
separate passwords. The cache is not used if KEY is nil. It is
|
|
typically a string.
|
|
The variable `password-cache' control whether the cache is used."
|
|
(or (password-read-from-cache key)
|
|
(read-passwd prompt)))
|
|
|
|
(defun password-read-and-add (prompt &optional key)
|
|
"Read password, for use with KEY, from user, or from cache if wanted.
|
|
Then store the password in the cache. Uses `password-read' and
|
|
`password-cache-add'. Custom variables `password-cache' and
|
|
`password-cache-expiry' regulate cache behavior.
|
|
|
|
Warning: the password is cached without checking that it is
|
|
correct. It is better to check the password before caching. If
|
|
you must use this function, take care to check passwords and
|
|
remove incorrect ones from the cache."
|
|
(let ((password (password-read prompt key)))
|
|
(when (and password key)
|
|
(password-cache-add key password))
|
|
password))
|
|
|
|
(make-obsolete 'password-read-and-add 'password-read "23.1")
|
|
|
|
(defun password-cache-remove (key)
|
|
"Remove password indexed by KEY from password cache.
|
|
This is typically run be a timer setup from `password-cache-add',
|
|
but can be invoked at any time to forcefully remove passwords
|
|
from the cache. This may be useful when it has been detected
|
|
that a password is invalid, so that `password-read' query the
|
|
user again."
|
|
(let ((password (symbol-value (intern-soft key password-data))))
|
|
(when password
|
|
(if (fboundp 'clear-string)
|
|
(clear-string password)
|
|
(fillarray password ?_))
|
|
(unintern key password-data))))
|
|
|
|
(defun password-cache-add (key password)
|
|
"Add password to cache.
|
|
The password is removed by a timer after `password-cache-expiry' seconds."
|
|
(when (and password-cache-expiry (null (intern-soft key password-data)))
|
|
(run-at-time password-cache-expiry nil
|
|
#'password-cache-remove
|
|
key))
|
|
(set (intern key password-data) password)
|
|
nil)
|
|
|
|
(defun password-reset ()
|
|
"Clear the password cache."
|
|
(interactive)
|
|
(fillarray password-data 0))
|
|
|
|
(provide 'password-cache)
|
|
|
|
;; arch-tag: ab160494-16c8-4c68-a4a1-73eebf6686e5
|
|
;;; password-cache.el ends here
|