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