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