1 ;;; rlogin.el --- remote login interface
3 ;; Maintainer: Noah Friedman <friedman@prep.ai.mit.edu>
4 ;; Keywords: unix, comm
6 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to: The Free Software Foundation,
20 ;; Inc.; 675 Massachusetts Avenue.; Cambridge, MA 02139, USA.
24 ;; Support for remote logins using `rlogin'.
26 ;; Todo: add directory tracking using ange-ftp style patchnames for the cwd.
32 (defvar rlogin-program
"rlogin"
33 "*Name of program to invoke rlogin")
35 (defvar rlogin-explicit-args nil
36 "*List of arguments to pass to rlogin on the command line.")
38 (defvar rlogin-mode-hook nil
39 "*Hooks to run after setting current buffer to rlogin-mode.")
41 ;; I think this is so obnoxious I refuse to enable it by default.
42 ;; In any case, there is a bug with regards to generating a quit while
43 ;; reading keyboard input in a process filter, so until that's fixed it's
44 ;; not safe to enable this anyway.
45 (defvar rlogin-password-paranoia nil
46 "*If non-`nil', query user for a password in the minibuffer when a
47 Password: prompt appears. Stars will echo as characters are type.
49 It's also possible to selectively enter passwords without echoing them in
50 the minibuffer using the function `rlogin-password'.")
52 (defvar rlogin-last-input-line nil nil
)
54 ;; Initialize rlogin mode map.
55 (defvar rlogin-mode-map
'())
56 (cond ((not rlogin-mode-map
)
57 (setq rlogin-mode-map
(full-copy-sparse-keymap comint-mode-map
))
58 ;(define-key rlogin-mode-map "\M-\t" 'comint-dynamic-complete)
59 ;(define-key rlogin-mode-map "\M-?" 'comint-dynamic-list-completions)
60 (define-key rlogin-mode-map
"\C-c\C-c" 'rlogin-send-Ctrl-C
)
61 (define-key rlogin-mode-map
"\C-c\C-z" 'rlogin-send-Ctrl-Z
)
62 (define-key rlogin-mode-map
"\C-c\C-\\" 'rlogin-send-Ctrl-backslash
)
63 (define-key rlogin-mode-map
"\C-d" 'rlogin-delchar-or-send-Ctrl-D
)))
66 (defun rlogin (&optional prefix host
)
67 "Open a network login connection to HOST via the `rlogin' program.
68 Input is sent line-at-a-time to the remote connection.
70 Communication with HOST is recorded in a buffer *rlogin-HOST*.
71 If a prefix argument is given and the buffer *rlogin-HOST* already exists,
72 a new buffer with a different connection will be made.
74 The variable `rlogin-program' contains the name of the actual program to
75 run. It can be a relative or absolute path.
77 The variable `rlogin-explicit-args' is a list of arguments to give to
78 the rlogin when starting."
79 (interactive (list current-prefix-arg
80 (read-from-minibuffer "Open rlogin connection to host: ")))
81 (let* ((buffer-name (format "*rlogin-%s*" host
))
82 (args (if (and rlogin-explicit-args
(listp rlogin-explicit-args
))
83 (cons host rlogin-explicit-args
)
86 (and prefix
(setq buffer-name
87 (buffer-name (generate-new-buffer buffer-name
))))
88 (switch-to-buffer buffer-name
)
89 (or (comint-check-proc buffer-name
)
92 (comint-exec (current-buffer) buffer-name rlogin-program nil args
)
93 (setq proc
(get-process buffer-name
))
94 (set-marker (process-mark proc
) (point-min))
95 (set-process-filter proc
'rlogin-filter
)
99 (defun rlogin-with-args (host args
)
100 "Open a new rlogin connection to HOST, even if one already exists.
101 String ARGS is given as arguments to the `rlogin' program, overriding the
102 value of `rlogin-explicit-args'."
103 (interactive (list (read-from-minibuffer "Open rlogin connection to host: ")
104 (read-from-minibuffer "with arguments: ")))
105 (let ((old-match-data (match-data))
106 (rlogin-explicit-args nil
))
109 (while (string-match "[ \t]*\\([^ \t]\\)+$" args
)
110 (setq rlogin-explicit-args
111 (cons (substring args
114 rlogin-explicit-args
)
115 args
(substring args
0 (match-beginning 0)))))
116 (store-match-data old-match-data
))
120 (defun rlogin-password ()
121 "Play the paranoia game by not echoing entered password in buffer
122 (stars will echo in the minibuffer instead."
124 (let ((input (comint-read-noecho "Enter password: " 'stars
)))
125 (insert-before-markers "\n")
126 (comint-send-string (get-buffer-process (current-buffer))
127 (format "%s\n" input
))))
130 (defun rlogin-mode ()
132 (kill-all-local-variables)
134 (setq comint-prompt-regexp shell-prompt-pattern
)
135 (setq major-mode
'rlogin-mode
)
136 (setq mode-name
"rlogin")
137 (use-local-map rlogin-mode-map
)
138 (run-hooks 'rlogin-mode-hook
))
140 (defun rlogin-filter (proc string
)
141 (let ((old-buffer (current-buffer))
142 (old-match-data (match-data))
147 (set-buffer (process-buffer proc
))
148 (setq moving
(= (point) (process-mark proc
)))
150 (goto-char (process-mark proc
))
153 (insert-before-markers string
)
154 (narrow-to-region beg
(point))
155 (goto-char (point-min))
156 (while (search-forward "\C-m" nil t
)
158 (and rlogin-password-paranoia
159 (setq string
(buffer-substring (point-min) (point-max))))
160 (goto-char (point-max))))
161 (set-marker (process-mark proc
) (point)))
163 (goto-char (process-mark proc
))))
164 (set-buffer old-buffer
)
165 (store-match-data old-match-data
)))
166 (and rlogin-password-paranoia
167 (string= "Password:" string
)
168 (let ((input (comint-read-noecho "Enter password: " 'stars
)))
171 (insert-before-markers "\n")
172 (comint-send-string proc
(format "%s\n" input
)))))))
174 (defun rlogin-send-Ctrl-C ()
176 (send-string nil
"\C-c"))
178 (defun rlogin-send-Ctrl-Z ()
180 (send-string nil
"\C-z"))
182 (defun rlogin-send-Ctrl-backslash ()
184 (send-string nil
"\C-\\"))
186 (defun rlogin-delchar-or-send-Ctrl-D (arg)
187 "Delete ARG characters forward, or send a C-d to process if at end of
191 (send-string nil
"\C-d")
194 ;;; rlogin.el ends here