0
|
1 ;;; netunam.el --- HP-UX RFA Commands
|
|
2
|
|
3 ;; Copyright (C) 1988 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Chris Hanson <cph@zurich.ai.mit.edu>
|
|
6 ;; Keywords: comm
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
16
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
0
|
24
|
|
25 ;;; Synched up with: Not in FSF.
|
|
26 ;;; #### Chuck -- maybe we should nuke this file. I somehow or
|
|
27 ;;; other get the sense that it's extremely obsolete.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; Use the Remote File Access (RFA) facility of HP-UX from Emacs.
|
|
32
|
|
33 ;;; Code:
|
|
34
|
|
35 (defconst rfa-node-directory "/net/"
|
|
36 "Directory in which RFA network special files are stored.
|
|
37 By HP convention, this is \"/net/\".")
|
|
38
|
|
39 (defvar rfa-default-node nil
|
|
40 "If not nil, this is the name of the default RFA network special file.")
|
|
41
|
|
42 (defvar rfa-password-memoize-p t
|
|
43 "If non-nil, remember login user's passwords after they have been entered.")
|
|
44
|
|
45 (defvar rfa-password-alist '()
|
|
46 "An association from node-name strings to password strings.
|
|
47 Used if `rfa-password-memoize-p' is non-nil.")
|
|
48
|
|
49 (defvar rfa-password-per-node-p t
|
|
50 "If nil, login user uses same password on all machines.
|
|
51 Has no effect if `rfa-password-memoize-p' is nil.")
|
|
52
|
|
53 (defun rfa-set-password (password &optional node user)
|
|
54 "Add PASSWORD to the RFA password database.
|
|
55 Optional second arg NODE is a string specifying a particular nodename;
|
|
56 if supplied and not nil, PASSWORD applies to only that node.
|
|
57 Optional third arg USER is a string specifying the (remote) user whose
|
|
58 password this is; if not supplied this defaults to (user-login-name)."
|
|
59 (if (not user) (setq user (user-login-name)))
|
|
60 (let ((node-entry (assoc node rfa-password-alist)))
|
|
61 (if node-entry
|
|
62 (let ((user-entry (assoc user (cdr node-entry))))
|
|
63 (if user-entry
|
|
64 (rplacd user-entry password)
|
|
65 (rplacd node-entry
|
|
66 (nconc (cdr node-entry)
|
|
67 (list (cons user password))))))
|
|
68 (setq rfa-password-alist
|
|
69 (nconc rfa-password-alist
|
|
70 (list (list node (cons user password))))))))
|
|
71
|
|
72 (defun rfa-open (node &optional user password)
|
|
73 "Open a network connection to a server using remote file access.
|
|
74 First argument NODE is the network node for the remote machine.
|
|
75 Second optional argument USER is the user name to use on that machine.
|
|
76 If called interactively, the user name is prompted for.
|
|
77 Third optional argument PASSWORD is the password string for that user.
|
|
78 If not given, this is filled in from the value of
|
|
79 `rfa-password-alist', or prompted for. A prefix argument of - will
|
|
80 cause the password to be prompted for even if previously memoized."
|
|
81 (interactive
|
|
82 (list (read-file-name "rfa-open: " rfa-node-directory rfa-default-node t)
|
|
83 (read-string "user-name: " (user-login-name))))
|
|
84 (let ((node
|
|
85 (and (or rfa-password-per-node-p
|
|
86 (not (equal user (user-login-name))))
|
|
87 node)))
|
|
88 (if (not password)
|
|
89 (setq password
|
|
90 (let ((password
|
|
91 (cdr (assoc user (cdr (assoc node rfa-password-alist))))))
|
|
92 (or (and (not current-prefix-arg) password)
|
|
93 (rfa-password-read
|
|
94 (format "password for user %s%s: "
|
|
95 user
|
|
96 (if node (format " on node \"%s\"" node) ""))
|
|
97 password))))))
|
|
98 (let ((result
|
|
99 (sysnetunam (expand-file-name node rfa-node-directory)
|
|
100 (concat user ":" password))))
|
|
101 (if (interactive-p)
|
|
102 (if result
|
|
103 (message "Opened network connection to %s as %s" node user)
|
|
104 (error "Unable to open network connection")))
|
|
105 (if (and rfa-password-memoize-p result)
|
|
106 (rfa-set-password password node user))
|
|
107 result))
|
|
108
|
|
109 (defun rfa-close (node)
|
|
110 "Close a network connection to a server using remote file access.
|
|
111 NODE is the network node for the remote machine."
|
|
112 (interactive
|
|
113 (list (read-file-name "rfa-close: " rfa-node-directory rfa-default-node t)))
|
|
114 (let ((result (sysnetunam (expand-file-name node rfa-node-directory) "")))
|
|
115 (cond ((not (interactive-p)) result)
|
|
116 ((not result) (error "Unable to close network connection"))
|
|
117 (t (message "Closed network connection to %s" node)))))
|
|
118
|
|
119 (defun rfa-password-read (prompt default)
|
|
120 (let ((rfa-password-accumulator (or default "")))
|
|
121 (read-from-minibuffer prompt
|
|
122 (and default
|
|
123 (let ((copy (concat default))
|
|
124 (index 0)
|
|
125 (length (length default)))
|
|
126 (while (< index length)
|
|
127 (aset copy index ?.)
|
|
128 (setq index (1+ index)))
|
|
129 copy))
|
|
130 rfa-password-map)
|
|
131 rfa-password-accumulator))
|
|
132
|
|
133 (defvar rfa-password-map nil)
|
|
134 (if (not rfa-password-map)
|
|
135 (let ((char ? ))
|
|
136 (setq rfa-password-map (make-keymap))
|
|
137 (while (< char 127)
|
|
138 (define-key rfa-password-map (char-to-string char)
|
|
139 'rfa-password-self-insert)
|
|
140 (setq char (1+ char)))
|
|
141 (define-key rfa-password-map "\C-g"
|
|
142 'abort-recursive-edit)
|
|
143 (define-key rfa-password-map "\177"
|
|
144 'rfa-password-rubout)
|
|
145 (define-key rfa-password-map "\n"
|
|
146 'exit-minibuffer)
|
|
147 (define-key rfa-password-map "\r"
|
|
148 'exit-minibuffer)))
|
|
149
|
|
150 (defvar rfa-password-accumulator nil)
|
|
151
|
|
152 (defun rfa-password-self-insert ()
|
|
153 (interactive)
|
|
154 (setq rfa-password-accumulator
|
|
155 (concat rfa-password-accumulator
|
|
156 (char-to-string last-command-char)))
|
|
157 (insert ?.))
|
|
158
|
|
159 (defun rfa-password-rubout ()
|
|
160 (interactive)
|
|
161 (delete-char -1)
|
|
162 (setq rfa-password-accumulator
|
|
163 (substring rfa-password-accumulator 0 -1)))
|
|
164
|
|
165 ;;; netunam.el ends here
|