mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-17 10:06:13 +00:00
59f7af816e
* lisp/allout.el (allout-passphrase-hint-string): Likewise. (allout-init): Use a declare form to mark obsolete. * lisp/calendar/calendar.el (calendar-version): * lisp/calendar/icalendar.el (icalendar-extract-ical-from-buffer) (icalendar-convert-diary-to-ical): * lisp/cus-edit.el (custom-mode): * lisp/ansi-color.el (ansi-color-unfontify-region): * lisp/international/latin1-disp.el (latin1-char-displayable-p): * lisp/progmodes/cwarn.el (turn-on-cwarn-mode): * lisp/progmodes/which-func.el (which-func-update-1): Use define-obsolete-function-alias. * lisp/bookmark.el (bookmark-jump-noselect): Use a declare form to mark this function obsolete. * lisp/calendar/cal-x.el (calendar-two-frame-setup) (calendar-only-one-frame-setup, calendar-one-frame-setup): * lisp/calendar/calendar.el (american-calendar, european-calendar) (calendar-for-loop): * lisp/comint.el (comint-dynamic-simple-complete) (comint-dynamic-complete-as-filename, comint-unquote-filename): * lisp/desktop.el (desktop-load-default): * lisp/dired-x.el (dired-omit-here-always) (dired-hack-local-variables, dired-default-directory): * lisp/emacs-lisp/derived.el (derived-mode-class): * lisp/emacs-lisp/timer.el (timer-set-time-with-usecs): * lisp/emacs-lock.el (toggle-emacs-lock): * lisp/epa.el (epa-display-verify-result): * lisp/epg.el (epg-sign-keys, epg-start-sign-keys) (epg-passphrase-callback-function): * lisp/eshell/esh-util.el (eshell-for): * lisp/eshell/eshell.el (eshell-remove-from-window-buffer-names) (eshell-add-to-window-buffer-names): * lisp/files.el (locate-file-completion): * lisp/imenu.el (imenu-example--create-c-index) (imenu-example--create-lisp-index) (imenu-example--lisp-extract-index-name) (imenu-example--name-and-position): * lisp/international/mule-cmds.el (princ-list): * lisp/international/mule-diag.el (decode-codepage-char): * lisp/international/mule-util.el (detect-coding-with-priority): * lisp/iswitchb.el (iswitchb-read-buffer): * lisp/mail/mailalias.el (mail-complete): * lisp/mail/sendmail.el (mail-sent-via): * lisp/mouse.el (mouse-popup-menubar-stuff, mouse-popup-menubar) (mouse-major-mode-menu): * lisp/password-cache.el (password-read-and-add): * lisp/pcomplete.el (pcomplete-parse-comint-arguments): * lisp/progmodes/sh-script.el (sh-maybe-here-document): * lisp/replace.el (query-replace-regexp-eval): * lisp/savehist.el (savehist-load): * lisp/simple.el (choose-completion-delete-max-match): * lisp/term.el (term-dynamic-simple-complete): * lisp/vc/ediff-init.el (ediff-check-version): * lisp/vc/ediff-wind.el (ediff-choose-window-setup-function-automatically): * lisp/vc/vc.el (vc-diff-switches-list): * lisp/view.el (view-return-to-alist-update): Likewise. * lisp/iswitchb.el (iswitchb-read-buffer): Move code of iswitchb-define-mode-map here, and delete that obsolete function. * lisp/subr.el (eval-next-after-load, makehash, insert-string) (assoc-ignore-representation, assoc-ignore-case): Use declare to mark obsolete. (mode-line-inverse-video): Variable deleted. * lisp/emacs-lisp/byte-run.el (make-obsolete): Doc fix; emphasize that this applies to functions. * lisp/erc/erc.el (erc-send-command): Use define-obsolete-function-alias. * lisp/international/mule-util.el (string-to-sequence): Remove. * lisp/net/newst-backend.el (newsticker-cache-filename): * lisp/net/newst-treeview.el (newsticker-groups-filename): Fix incorrect obsolescence declaration. * lisp/net/snmp-mode.el (snmp-font-lock-keywords-3): Don't use obsolete font-lock-reference-face. * lisp/url/url-parse.el (url-recreate-url-attributes): * lisp/url/url-util.el (url-generate-unique-filename): Use declare to mark obsolete. * src/xdisp.c (mode_line_inverse_video): Delete obsolete variable.
145 lines
4.6 KiB
EmacsLisp
145 lines
4.6 KiB
EmacsLisp
;;; password-cache.el --- Read passwords, possibly using a password cache.
|
|
|
|
;; Copyright (C) 1999-2000, 2003-2012 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))))
|
|
|
|
;;;###autoload
|
|
(defun password-in-cache-p (key)
|
|
"Check if KEY is in the cache."
|
|
(and password-cache
|
|
key
|
|
(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."
|
|
(declare (obsolete password-read "23.1"))
|
|
(let ((password (password-read prompt key)))
|
|
(when (and password key)
|
|
(password-cache-add key password))
|
|
password))
|
|
|
|
(defun password-cache-remove (key)
|
|
"Remove password indexed by KEY from password cache.
|
|
This is typically run by 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 ((sym (intern-soft key password-data)))
|
|
(when sym
|
|
(let ((password (symbol-value sym)))
|
|
(when (stringp 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)
|
|
|
|
;;; password-cache.el ends here
|