2 ;; Copyright (C) 1988 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 ;;; Author: cph@zurich.ai.mit.edu
22 ;;; $Header: netunam.el,v 1.3 88/12/21 16:32:23 GMT cph Exp $
24 (defconst rfa-node-directory
"/net/"
25 "Directory in which RFA network special files are stored.
26 By HP convention, this is \"/net/\".")
28 (defvar rfa-default-node nil
29 "If not nil, this is the name of the default RFA network special file.")
31 (defvar rfa-password-memoize-p t
32 "If non-nil, remember login user's passwords after they have been entered.")
34 (defvar rfa-password-alist
'()
35 "An association from node-name strings to password strings.
36 Used if `rfa-password-memoize-p' is non-nil.")
38 (defvar rfa-password-per-node-p t
39 "If nil, login user uses same password on all machines.
40 Has no effect if `rfa-password-memoize-p' is nil.")
42 (defun rfa-set-password (password &optional node user
)
43 "Add PASSWORD to the RFA password database.
44 Optional second arg NODE is a string specifying a particular nodename;
45 if supplied and not nil, PASSWORD applies to only that node.
46 Optional third arg USER is a string specifying the (remote) user whose
47 password this is; if not supplied this defaults to (user-login-name)."
48 (if (not user
) (setq user
(user-login-name)))
49 (let ((node-entry (assoc node rfa-password-alist
)))
51 (let ((user-entry (assoc user
(cdr node-entry
))))
53 (rplacd user-entry password
)
55 (nconc (cdr node-entry
)
56 (list (cons user password
))))))
57 (setq rfa-password-alist
58 (nconc rfa-password-alist
59 (list (list node
(cons user password
))))))))
61 (defun rfa-open (node &optional user password
)
62 "Open a network connection to a server using remote file access.
63 First argument NODE is the network node for the remote machine.
64 Second optional argument USER is the user name to use on that machine.
65 If called interactively, the user name is prompted for.
66 Third optional argument PASSWORD is the password string for that user.
67 If not given, this is filled in from the value of
68 `rfa-password-alist', or prompted for. A prefix argument of - will
69 cause the password to be prompted for even if previously memoized."
71 (list (read-file-name "rfa-open: " rfa-node-directory rfa-default-node t
)
72 (read-string "user-name: " (user-login-name))))
74 (and (or rfa-password-per-node-p
75 (not (equal user
(user-login-name))))
80 (cdr (assoc user
(cdr (assoc node rfa-password-alist
))))))
81 (or (and (not current-prefix-arg
) password
)
83 (format "password for user %s%s: "
85 (if node
(format " on node \"%s\"" node
) ""))
88 (sysnetunam (expand-file-name node rfa-node-directory
)
89 (concat user
":" password
))))
92 (message "Opened network connection to %s as %s" node user
)
93 (error "Unable to open network connection")))
94 (if (and rfa-password-memoize-p result
)
95 (rfa-set-password password node user
))
98 (defun rfa-close (node)
99 "Close a network connection to a server using remote file access.
100 NODE is the network node for the remote machine."
102 (list (read-file-name "rfa-close: " rfa-node-directory rfa-default-node t
)))
103 (let ((result (sysnetunam (expand-file-name node rfa-node-directory
) "")))
104 (cond ((not (interactive-p)) result
)
105 ((not result
) (error "Unable to close network connection"))
106 (t (message "Closed network connection to %s" node
)))))
108 (defun rfa-password-read (prompt default
)
109 (let ((rfa-password-accumulator (or default
"")))
110 (read-from-minibuffer prompt
112 (let ((copy (concat default
))
114 (length (length default
)))
115 (while (< index length
)
117 (setq index
(1+ index
)))
120 rfa-password-accumulator
))
122 (defvar rfa-password-map nil
)
123 (if (not rfa-password-map
)
125 (setq rfa-password-map
(make-keymap))
127 (define-key rfa-password-map
(char-to-string char
)
128 'rfa-password-self-insert
)
129 (setq char
(1+ char
)))
130 (define-key rfa-password-map
"\C-g"
131 'abort-recursive-edit
)
132 (define-key rfa-password-map
"\177"
133 'rfa-password-rubout
)
134 (define-key rfa-password-map
"\n"
136 (define-key rfa-password-map
"\r"
139 (defvar rfa-password-accumulator nil
)
141 (defun rfa-password-self-insert ()
143 (setq rfa-password-accumulator
144 (concat rfa-password-accumulator
145 (char-to-string last-command-char
)))
148 (defun rfa-password-rubout ()
151 (setq rfa-password-accumulator
152 (substring rfa-password-accumulator
0 -
1)))