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