Mercurial > emacs
annotate lisp/=netunam.el @ 839:c32d6beb8aec
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 22 Jul 1992 02:25:17 +0000 |
parents | 4f28bd14272c |
children | 20674ae6bf52 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
1 ;;; netunam.el --- HP-UX RFA Commands |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
2 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
791
diff
changeset
|
3 ;; Author: Chris Hanson <cph@zurich.ai.mit.edu> |
791
203c23c9f22c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
4 ;; Last-Modified: 31 Oct 1989 |
203c23c9f22c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
5 |
203c23c9f22c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
6 ;;; $Header: netunam.el,v 1.3 88/12/21 16:32:23 GMT cph Exp $ |
203c23c9f22c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
7 |
35 | 8 ;; Copyright (C) 1988 Free Software Foundation, Inc. |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
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 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
791
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
35 | 15 ;; any later version. |
16 | |
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. | |
21 | |
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. | |
25 | |
791
203c23c9f22c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
26 ;;; Code: |
35 | 27 |
28 (defconst rfa-node-directory "/net/" | |
29 "Directory in which RFA network special files are stored. | |
30 By HP convention, this is \"/net/\".") | |
31 | |
32 (defvar rfa-default-node nil | |
33 "If not nil, this is the name of the default RFA network special file.") | |
34 | |
35 (defvar rfa-password-memoize-p t | |
36 "If non-nil, remember login user's passwords after they have been entered.") | |
37 | |
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.") | |
41 | |
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.") | |
45 | |
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)))))))) | |
64 | |
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)) | |
101 | |
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))))) | |
111 | |
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)) | |
125 | |
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))) | |
142 | |
143 (defvar rfa-password-accumulator nil) | |
144 | |
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 ?.)) | |
151 | |
152 (defun rfa-password-rubout () | |
153 (interactive) | |
154 (delete-char -1) | |
155 (setq rfa-password-accumulator | |
156 (substring rfa-password-accumulator 0 -1))) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
157 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
158 ;;; netunam.el ends here |