35
|
1 ;; HP-UX RFA Commands
|
|
2 ;; Copyright (C) 1988 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; This file is part of GNU Emacs.
|
|
5
|
|
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)
|
|
9 ;; any later version.
|
|
10
|
|
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.
|
|
15
|
|
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.
|
|
19
|
|
20 ;;; Author: cph@zurich.ai.mit.edu
|
|
21
|
|
22 ;;; $Header: netunam.el,v 1.3 88/12/21 16:32:23 GMT cph Exp $
|
|
23
|
|
24 (defconst rfa-node-directory "/net/"
|
|
25 "Directory in which RFA network special files are stored.
|
|
26 By HP convention, this is \"/net/\".")
|
|
27
|
|
28 (defvar rfa-default-node nil
|
|
29 "If not nil, this is the name of the default RFA network special file.")
|
|
30
|
|
31 (defvar rfa-password-memoize-p t
|
|
32 "If non-nil, remember login user's passwords after they have been entered.")
|
|
33
|
|
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.")
|
|
37
|
|
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.")
|
|
41
|
|
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)))
|
|
50 (if node-entry
|
|
51 (let ((user-entry (assoc user (cdr node-entry))))
|
|
52 (if user-entry
|
|
53 (rplacd user-entry password)
|
|
54 (rplacd node-entry
|
|
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))))))))
|
|
60
|
|
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."
|
|
70 (interactive
|
|
71 (list (read-file-name "rfa-open: " rfa-node-directory rfa-default-node t)
|
|
72 (read-string "user-name: " (user-login-name))))
|
|
73 (let ((node
|
|
74 (and (or rfa-password-per-node-p
|
|
75 (not (equal user (user-login-name))))
|
|
76 node)))
|
|
77 (if (not password)
|
|
78 (setq password
|
|
79 (let ((password
|
|
80 (cdr (assoc user (cdr (assoc node rfa-password-alist))))))
|
|
81 (or (and (not current-prefix-arg) password)
|
|
82 (rfa-password-read
|
|
83 (format "password for user %s%s: "
|
|
84 user
|
|
85 (if node (format " on node \"%s\"" node) ""))
|
|
86 password))))))
|
|
87 (let ((result
|
|
88 (sysnetunam (expand-file-name node rfa-node-directory)
|
|
89 (concat user ":" password))))
|
|
90 (if (interactive-p)
|
|
91 (if result
|
|
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))
|
|
96 result))
|
|
97
|
|
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."
|
|
101 (interactive
|
|
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)))))
|
|
107
|
|
108 (defun rfa-password-read (prompt default)
|
|
109 (let ((rfa-password-accumulator (or default "")))
|
|
110 (read-from-minibuffer prompt
|
|
111 (and default
|
|
112 (let ((copy (concat default))
|
|
113 (index 0)
|
|
114 (length (length default)))
|
|
115 (while (< index length)
|
|
116 (aset copy index ?.)
|
|
117 (setq index (1+ index)))
|
|
118 copy))
|
|
119 rfa-password-map)
|
|
120 rfa-password-accumulator))
|
|
121
|
|
122 (defvar rfa-password-map nil)
|
|
123 (if (not rfa-password-map)
|
|
124 (let ((char ? ))
|
|
125 (setq rfa-password-map (make-keymap))
|
|
126 (while (< char 127)
|
|
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"
|
|
135 'exit-minibuffer)
|
|
136 (define-key rfa-password-map "\r"
|
|
137 'exit-minibuffer)))
|
|
138
|
|
139 (defvar rfa-password-accumulator nil)
|
|
140
|
|
141 (defun rfa-password-self-insert ()
|
|
142 (interactive)
|
|
143 (setq rfa-password-accumulator
|
|
144 (concat rfa-password-accumulator
|
|
145 (char-to-string last-command-char)))
|
|
146 (insert ?.))
|
|
147
|
|
148 (defun rfa-password-rubout ()
|
|
149 (interactive)
|
|
150 (delete-char -1)
|
|
151 (setq rfa-password-accumulator
|
|
152 (substring rfa-password-accumulator 0 -1)))
|