annotate lisp/utils/passwd.el @ 131:869e1851236b xemacs-20-1p4

Import from CVS: tag xemacs-20-1p4
author cvs
date Mon, 13 Aug 2007 09:29:07 +0200
parents cca96a509cfe
children 43dd3413c7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; passwd.el --- Prompting for passwords semi-securely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Keywords: comm, extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Jamie Zawinski <jwz@netscape.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Change Log:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Sun Jun 12 04:19:30 1994 by sandy on ibm550.sissa.it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Added support for password histories and (provide 'passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; (jwz says: this "history" thing is completely undocumented, you loser!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; 2-Jan-95 (mon); 4:13 AM by jwz@netscape.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Fixed Sandy's extreme keymap bogosity. Made it invert the screen when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; reading securely (this could be better; maybe use red text or something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; instead...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; 9-Jul-95 (fri); 4:55 AM by jwz@netscape.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; Made it work with XEmacs 19.12.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; 7-Jul-95 by cthomp@cs.uiuc.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Added variable to control inverting frame when keyboard grabbed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
40 (defgroup passwd nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
41 "Prompting for passwords semi-securely"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
42 :group 'processes)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
43
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
44
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
45 (defcustom passwd-invert-frame-when-keyboard-grabbed t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "*If non-nil swap the foreground and background colors of all faces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 This is done while the keyboard is grabbed in order to give a visual
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
48 clue that a grab is in effect."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
49 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
50 :group 'passwd)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
52 (defcustom passwd-echo ?.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "*The character which should be echoed when typing a password,
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
54 or nil, meaning echo nothing."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
55 :type 'sexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
56 :group 'passwd)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defvar read-passwd-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (s (make-string 1 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (cond ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (setq map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (set-keymap-parent map minibuffer-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (t ; v18/FSFmacs compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq map (copy-keymap minibuffer-local-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (fboundp 'set-keymap-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (set-keymap-name map 'read-passwd-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (while (< i 127)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (aset s 0 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (or (and (boundp 'meta-prefix-char) (eq i meta-prefix-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (define-key map s 'self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key map "\C-g" 'keyboard-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (define-key map "\C-h" 'delete-backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (define-key map "\r" 'exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (define-key map "\n" 'exit-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (define-key map "\C-u" 'passwd-erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (define-key map "\C-q" 'quoted-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (define-key map "\177" 'delete-backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (define-key map "\M-n" 'passwd-next-history-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (define-key map "\M-p" 'passwd-previous-history-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "Keymap used for reading passwords in the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 The \"bindings\" in this map are not real commands; only a limited
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 number of commands are understood. The important bindings are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 \\<read-passwd-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 \\[passwd-erase-buffer] Erase all input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 \\[quoted-insert] Insert the next character literally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 \\[delete-backward-char] Delete the previous character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 \\[exit-minibuffer] Accept what you have typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 \\[keyboard-quit] Abort the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 All other characters insert themselves (but do not echo.)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;; internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar passwd-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defvar passwd-history-posn 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defun read-passwd (prompt &optional confirm default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "Prompts for a password in the minibuffer, and returns it as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 If PROMPT may be a prompt string or an alist of elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 '\(prompt . default\).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 If optional arg CONFIRM is true, then ask the user to type the password
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 again to confirm that they typed it correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 If optional arg DEFAULT is provided, then it is a string to insert as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 the default choice (it is not, of course, displayed.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 If running under X, the keyboard will be grabbed (with XGrabKeyboard())
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
114 to reduce the possibility that eavesdropping is occuring.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 When reading a password, all keys self-insert, except for:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 \\<read-passwd-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 \\[read-passwd-erase-line] Erase the entire line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 \\[quoted-insert] Insert the next character literally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 \\[delete-backward-char] Delete the previous character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 \\[exit-minibuffer] Accept what you have typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 \\[keyboard-quit] Abort the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 The returned value is always a newly-created string. No additional copies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 of the password remain after this function has returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 NOTE: unless great care is taken, the typed password will exist in plaintext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 form in the running image for an arbitrarily long time. Priveleged users may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 be able to extract it from memory. If emacs crashes, it may appear in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 resultant core file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Some steps you can take to prevent the password from being copied around:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 - as soon as you are done with the returned string, destroy it with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (fillarray string 0). The same goes for any default passwords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 or password histories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 - do not copy the string, as with concat or substring - if you do, be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 sure to keep track of and destroy all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 - do not insert the password into a buffer - if you do, be sure to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 overwrite the buffer text before killing it, as with the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 `passwd-erase-buffer' or `passwd-kill-buffer'. Note that deleting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 the text from the buffer does NOT necessarily remove the text from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 - be careful of the undo history - if you insert the password into a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 buffer which has undo recording turned on, the password will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 copied onto the undo list, and thus recoverable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 - do not pass it as an argument to a shell command - anyone will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 able to see it if they run `ps' at the right time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 Note that the password will be temporarily recoverable with the `view-lossage'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 command. This data will not be overwritten until another hundred or so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 characters are typed. There's not currently a way around this."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let ((input (get-buffer-create " *password*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (passwd-history-posn 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 passwd-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (if (listp prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq passwd-history prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 default (cdr (car passwd-history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (set-buffer input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (buffer-disable-undo input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (use-local-map read-passwd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if (passwd-grab-keyboard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (passwd-secure-display))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (read-passwd-1 input prompt nil default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (set-buffer input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (not confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (buffer-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let ((ok nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (while (not ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (set-buffer input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq passwd (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (read-passwd-1 input prompt "[Retype to confirm]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (if (passwd-compare-string-to-buffer passwd input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq ok t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (fillarray passwd 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq passwd nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (read-passwd-1 input prompt "[Mismatch. Start over]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 passwd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; protected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (passwd-ungrab-keyboard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (passwd-insecure-display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (passwd-kill-buffer input)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
195 (message "")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (defun read-passwd-1 (buffer prompt &optional prompt2 default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (passwd-erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (if default (insert default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (catch 'exit ; exit-minibuffer throws here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let* ((minibuffer-completion-table nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (key (passwd-read-key-sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (concat (if (listp prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (car (nth passwd-history-posn passwd-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 prompt2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if passwd-echo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (make-string (buffer-size) passwd-echo)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (binding (key-binding key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (setq prompt2 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (set-buffer buffer) ; just in case...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (fboundp 'event-to-character) ;; lemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setq last-command-event (aref key (1- (length key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 last-command-char (event-to-character last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; v18/FSFmacs compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setq last-command-char (aref key (1- (length key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (setq this-command binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (condition-case c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (command-execute binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (fboundp 'display-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (display-error c t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; v18/FSFmacs compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (message (concat (or (get (car-safe c) 'error-message) "???")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (if (cdr-safe c) ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (function (lambda (x) (format "%s" x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (cdr-safe c) ", "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (sit-for 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun passwd-previous-history-element (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (or passwd-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (error "Password history is empty."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (let ((l (length passwd-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq passwd-history-posn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (% (+ n passwd-history-posn) l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (< passwd-history-posn 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq passwd-history-posn (+ passwd-history-posn l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (let ((obuff (current-buffer))) ; want to move point in passwd buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (set-buffer " *password*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (passwd-erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (insert (cdr (nth passwd-history-posn passwd-history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (set-buffer obuff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun passwd-next-history-element (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (passwd-previous-history-element (- n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defun passwd-erase-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; First erase the buffer, which will simply enlarge the gap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Then insert null characters until the gap is filled with them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; to prevent the old text from being visible in core files or kmem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; (Actually use 3x the size of the buffer just to be safe - a longer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; passwd might have been typed and backspaced over.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (let ((s (* (buffer-size) 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (while (> s 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (insert ?\000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq s (1- s)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (erase-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defun passwd-kill-buffer (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (buffer-disable-undo buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (passwd-erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (set-buffer-modified-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (kill-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defun passwd-compare-string-to-buffer (string buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; same as (equal string (buffer-string)) but with no dangerous consing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (let ((L (length string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (if (/= L (- (point-max) (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (/= (following-char) (aref string i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (setq i (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (forward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (= (point) (+ i (point-min)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defvar passwd-face-data nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (defun passwd-secure-display ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;; Inverts the screen - used to indicate secure input, like xterm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ((and passwd-invert-frame-when-keyboard-grabbed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (fboundp 'set-face-foreground))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq passwd-face-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (delq nil (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (lambda (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (let ((fg (face-foreground face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (bg (face-background face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (if (or fg bg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (if (fboundp 'color-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (list face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (color-name fg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (color-name bg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (list face fg bg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (if (fboundp 'list-faces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (list-faces) ; lemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (face-list) ; FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (let ((rest passwd-face-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (set-face-foreground (nth 0 (car rest)) (nth 2 (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (set-face-background (nth 0 (car rest)) (nth 1 (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq rest (cdr rest))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (defun passwd-insecure-display ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; Undoes the effect of `passwd-secure-display'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (passwd-invert-frame-when-keyboard-grabbed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (while passwd-face-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (set-face-foreground (nth 0 (car passwd-face-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (nth 1 (car passwd-face-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (set-face-background (nth 0 (car passwd-face-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (nth 2 (car passwd-face-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (setq passwd-face-data (cdr passwd-face-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (defun passwd-grab-keyboard ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (cond ((not (and (fboundp 'x-grab-keyboard) ; lemacs 19.10+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (eq 'x (if (fboundp 'frame-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (frame-type (selected-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (live-screen-p (selected-screen))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ((x-grab-keyboard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (message "Unable to grab keyboard - waiting a second...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (sleep-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (cond ((x-grab-keyboard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (message "Keyboard grabbed on second try.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (message "WARNING: keyboard is insecure (unable to grab!)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (sleep-for 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defun passwd-ungrab-keyboard ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (if (and (fboundp 'x-ungrab-keyboard) ; lemacs 19.10+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (eq 'x (if (fboundp 'frame-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (frame-type (selected-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (live-screen-p (selected-screen)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (x-ungrab-keyboard)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; v18 compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (or (fboundp 'buffer-disable-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (fset 'buffer-disable-undo 'buffer-flush-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 ;; read-key-sequence echoes the key sequence in Emacs 18.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (defun passwd-read-key-sequence (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (while (or (null str) (keymapp (key-binding str)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
379 (message prompt)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (setq str (concat str (char-to-string (read-char)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (or (string-match "^18" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (fset 'passwd-read-key-sequence 'read-key-sequence))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (provide 'passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;;; passwd.el ends here