- (tramp-clear-passwd user host)
- (error "Login failed"))))
-
-;; Functions to execute when we have seen the remote shell prompt but
-;; before we exec the Bourne-ish shell. Note that these commands
-;; might be sent to any shell, not just a Bourne-ish shell. This
-;; means that the commands need to work in all shells. (It is also
-;; okay for some commands to just fail with an error message, but
-;; please make sure that they at least don't crash the odd shell people
-;; might be running...)
-(defun tramp-process-initial-commands (p
- multi-method method user host
- commands)
- "Send list of commands to remote host, in order."
- (let (cmd)
- (while commands
- (setq cmd (pop commands))
- (erase-buffer)
- (tramp-message 10 "Sending command to remote shell: %s"
- cmd)
- (tramp-send-command multi-method method user host cmd nil t)
- (tramp-barf-if-no-shell-prompt
- p 60 "Remote shell command failed: %s" cmd))
- (erase-buffer)))
-
-;; The actual functions for opening connections.
-
-(defun tramp-open-connection-telnet (multi-method method user host)
- "Open a connection using a telnet METHOD.
-This starts the command `telnet HOST ARGS'[*], then waits for a remote
-login prompt, then sends the user name USER, then waits for a remote
-password prompt. It queries the user for the password, then sends the
-password to the remote host.
-
-If USER is nil, uses value returned by `(user-login-name)' instead.
-
-Recognition of the remote shell prompt is based on the variables
-`shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
-set up correctly.
-
-Please note that it is NOT possible to use this connection method
-together with an out-of-band transfer method! You must use an inline
-transfer method.
-
-Maybe the different regular expressions need to be tuned.
-
-* Actually, the telnet program as well as the args to be used can be
- specified in the method parameters, see the variable `tramp-methods'."
- (save-match-data
- (when (tramp-method-out-of-band-p multi-method method user host)
- (error "Cannot use out-of-band method `%s' with telnet connection method"
- method))
- (when multi-method
- (error "Cannot multi-connect using telnet connection method"))
- (tramp-pre-connection multi-method method user host tramp-chunksize)
- (tramp-message 7 "Opening connection for %s@%s using %s..."
- (or user (user-login-name)) host method)
- (let ((process-environment (copy-sequence process-environment)))
- (setenv "TERM" tramp-terminal-type)
- (setenv "LC_ALL" "C")
- (setenv "PROMPT_COMMAND")
- (setenv "PS1" "$ ")
- (let* ((default-directory (tramp-temporary-file-directory))
- ;; If we omit the conditional here, then we would use
- ;; `undecided-dos' in some cases. With the conditional,
- ;; we use nil in these cases. Which one is right?
- (coding-system-for-read (unless (and (not (featurep 'xemacs))
- (> emacs-major-version 20))
- tramp-dos-coding-system))
- (p (apply 'start-process
- (tramp-buffer-name multi-method method user host)
- (tramp-get-buffer multi-method method user host)
- (tramp-get-method-parameter
- multi-method
- (tramp-find-method multi-method method user host)
- user host 'tramp-login-program)
- host
- (tramp-get-method-parameter
- multi-method
- (tramp-find-method multi-method method user host)
- user host 'tramp-login-args)))
- (found nil)
- (pw nil))
- (tramp-set-process-query-on-exit-flag p nil)
- (set-buffer (tramp-get-buffer multi-method method user host))
- (erase-buffer)
- (tramp-process-actions p multi-method method user host
- tramp-actions-before-shell 60)
- (tramp-open-connection-setup-interactive-shell
- p multi-method method user host)
- (tramp-post-connection multi-method method user host)))))
-
-
-(defun tramp-open-connection-rsh (multi-method method user host)
- "Open a connection using an rsh METHOD.
-This starts the command `rsh HOST -l USER'[*], then waits for a remote
-password or shell prompt. If a password prompt is seen, the user is
-queried for a password, this function sends the password to the remote
-host and waits for a shell prompt.
-
-If USER is nil, start the command `rsh HOST'[*] instead
-
-Recognition of the remote shell prompt is based on the variables
-`shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
-set up correctly.
-
-Kludgy feature: if HOST has the form \"xx#yy\", then yy is assumed to
-be a port number for ssh, and \"-p yy\" will be added to the list of
-arguments, and xx will be used as the host name to connect to.
-
-* Actually, the rsh program to be used can be specified in the
- method parameters, see the variable `tramp-methods'."
- (save-match-data
- (when multi-method
- (error "Cannot multi-connect using rsh connection method"))
- (tramp-pre-connection multi-method method user host tramp-chunksize)
- (if (and user (not (string= user "")))
- (tramp-message 7 "Opening connection for %s@%s using %s..."
- user host method)
- (tramp-message 7 "Opening connection at %s using %s..." host method))
- (let ((process-environment (copy-sequence process-environment))
- (bufnam (tramp-buffer-name multi-method method user host))
- (buf (tramp-get-buffer multi-method method user host))
- (login-program (tramp-get-method-parameter
- multi-method
- (tramp-find-method multi-method method user host)
- user host 'tramp-login-program))
- (login-args (mapcar
- (lambda (x)
- (format-spec
- x `((?t . ,(format "/tmp/%s" tramp-temp-name-prefix)))))
- (tramp-get-method-parameter
- multi-method
- (tramp-find-method multi-method method user host)
- user host 'tramp-login-args)))
- (real-host host))
- ;; The following should be changed. We need a more general
- ;; mechanism to parse extra host args.
- (when (string-match "\\([^#]*\\)#\\(.*\\)" host)
- (setq login-args (cons "-p" (cons (match-string 2 host) login-args)))
- (setq real-host (match-string 1 host)))
- (setenv "TERM" tramp-terminal-type)
- (setenv "LC_ALL" "C")
- (setenv "PROMPT_COMMAND")
- (setenv "PS1" "$ ")
- (let* ((default-directory (tramp-temporary-file-directory))
- ;; If we omit the conditional, we would use
- ;; `undecided-dos' in some cases. With the conditional,
- ;; we use nil in these cases. Which one is right?
- (coding-system-for-read (unless (and (not (featurep 'xemacs))
- (> emacs-major-version 20))
- tramp-dos-coding-system))
- (p (if (and user (not (string= user "")))
- (apply #'start-process bufnam buf login-program
- real-host "-l" user login-args)
- (apply #'start-process bufnam buf login-program
- real-host login-args)))
- (found nil))
- (tramp-set-process-query-on-exit-flag p nil)
-
- (set-buffer buf)
- (tramp-process-actions p multi-method method user host
- tramp-actions-before-shell 60)
- (tramp-message 7 "Initializing remote shell")
- (tramp-open-connection-setup-interactive-shell
- p multi-method method user host)
- (tramp-post-connection multi-method method user host)))))
-
-(defun tramp-open-connection-su (multi-method method user host)
- "Open a connection using the `su' program with METHOD.
-This starts `su - USER', then waits for a password prompt. The HOST
-name must be equal to the local host name or to `localhost'.
-
-If USER is nil, uses value returned by user-login-name instead.
-
-Recognition of the remote shell prompt is based on the variables
-`shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
-set up correctly. Note that the other user may have a different shell
-prompt than you do, so it is not at all unlikely that the variable
-`shell-prompt-pattern' is set up wrongly!"
- (save-match-data
- (when (tramp-method-out-of-band-p multi-method method user host)
- (error "Cannot use out-of-band method `%s' with `su' connection method"
- method))
- (unless (or (string-match (concat "^" (regexp-quote host))
- (system-name))
- (string= "localhost" host)
- (string= "" host))
- (error
- "Cannot connect to different host `%s' with `su' connection method"
- host))
- (tramp-pre-connection multi-method method user host tramp-chunksize)
- (tramp-message 7 "Opening connection for `%s' using `%s'..."
- (or user "<root>") method)
- (let ((process-environment (copy-sequence process-environment)))
- (setenv "TERM" tramp-terminal-type)
- (setenv "LC_ALL" "C")
- (setenv "PROMPT_COMMAND")
- (setenv "PS1" "$ ")
- (let* ((default-directory (tramp-temporary-file-directory))
- ;; If we omit the conditional, we use `undecided-dos' in
- ;; some cases. With the conditional, we use nil in these
- ;; cases. What's the difference? Which one is right?
- (coding-system-for-read (unless (and (not (featurep 'xemacs))
- (> emacs-major-version 20))
- tramp-dos-coding-system))
- (p (apply 'start-process
- (tramp-buffer-name multi-method method user host)
- (tramp-get-buffer multi-method method user host)
- (tramp-get-method-parameter
- multi-method
- (tramp-find-method multi-method method user host)
- user host 'tramp-login-program)
- (mapcar
- (lambda (x)
- (format-spec x `((?u . ,(or user "root")))))
- (tramp-get-method-parameter
- multi-method
- (tramp-find-method multi-method method user host)
- user host 'tramp-login-args))))
- (found nil)
- (pw nil))
- (tramp-set-process-query-on-exit-flag p nil)
- (set-buffer (tramp-get-buffer multi-method method user host))
- (tramp-process-actions p multi-method method user host
- tramp-actions-before-shell 60)
- (tramp-open-connection-setup-interactive-shell
- p multi-method method user host)
- (tramp-post-connection multi-method method
- user host)))))
-
-;; HHH: Not Changed. Multi method. It is not clear to me how this can
-;; handle not giving a user name in the "file name".
-;;
-;; This is more difficult than for the single-hop method. In the
-;; multi-hop-method, the desired behaviour should be that the
-;; user must specify names for the telnet hops of which the user
-;; name is different than the "original" name (or different from
-;; the previous hop.
-(defun tramp-open-connection-multi (multi-method method user host)
- "Open a multi-hop connection using METHOD.
-This uses a slightly changed file name syntax. The idea is to say
- [multi/telnet:u1@h1/rsh:u2@h2]/path/to/file
-This will use telnet to log in as u1 to h1, then use rsh from there to
-log in as u2 to h2."
- (save-match-data
- (unless multi-method
- (error "Multi-hop open connection function called on non-multi method"))
- (when (tramp-method-out-of-band-p multi-method method user host)
- (error "No out of band multi-hop connections"))
- (unless (and (arrayp method) (not (stringp method)))
- (error "METHOD must be an array of strings for multi methods"))
- (unless (and (arrayp user) (not (stringp user)))
- (error "USER must be an array of strings for multi methods"))
- (unless (and (arrayp host) (not (stringp host)))
- (error "HOST must be an array of strings for multi methods"))
- (unless (and (= (length method) (length user))
- (= (length method) (length host)))
- (error "Arrays METHOD, USER, HOST must have equal length"))
- (tramp-pre-connection multi-method method user host tramp-chunksize)
- (tramp-message 7 "Opening `%s' connection..." multi-method)
- (let ((process-environment (copy-sequence process-environment)))
- (setenv "TERM" tramp-terminal-type)
- (setenv "LC_ALL" "C")
- (setenv "PROMPT_COMMAND")
- (setenv "PS1" "$ ")
- (let* ((default-directory (tramp-temporary-file-directory))
- ;; If we omit the conditional, we use `undecided-dos' in
- ;; some cases. With the conditional, we use nil in these
- ;; cases. What's the difference? Which one is right?
- (coding-system-for-read (unless (and (not (featurep 'xemacs))
- (> emacs-major-version 20))
- tramp-dos-coding-system))
- (p (start-process (tramp-buffer-name multi-method method user host)
- (tramp-get-buffer multi-method method user host)
- tramp-multi-sh-program))
- (num-hops (length method))
- (i 0))
- (tramp-set-process-query-on-exit-flag p nil)
- (tramp-message 9 "Waiting 60s for local shell to come up...")
- (unless (tramp-wait-for-regexp
- p 60 (format "\\(%s\\)\\'\\|\\(%s\\)\\'"
- shell-prompt-pattern tramp-shell-prompt-pattern))
- (pop-to-buffer (buffer-name))
- (kill-process p)
- (error "Couldn't find local shell prompt"))
- ;; Now do all the connections as specified.
- (while (< i num-hops)
- (let* ((m (aref method i))
- (u (aref user i))
- (h (aref host i))
- (entry (assoc m tramp-multi-connection-function-alist))
- (multi-func (nth 1 entry))
- (command (nth 2 entry)))
- ;; The multi-funcs don't need to do save-match-data, as that
- ;; is done here.
- (funcall multi-func p m u h command)
- (erase-buffer)
- (setq i (1+ i))))
- (tramp-open-connection-setup-interactive-shell
- p multi-method method user host)
- (tramp-post-connection multi-method method user host)))))
-
-;; HHH: Changed. Multi method. Don't know how to handle this in the case
-;; of no user name provided. Hack to make it work as it did before:
-;; changed `user' to `(or user (user-login-name))' in the places where
-;; the value is actually used.
-(defun tramp-multi-connect-telnet (p method user host command)
- "Issue `telnet' command.
-Uses shell COMMAND to issue a `telnet' command to log in as USER to
-HOST. You can use percent escapes in COMMAND: `%h' is replaced with
-the host name, and `%n' is replaced with an end of line character, as
-set in `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
-character.
-
-If USER is nil, uses the return value of (user-login-name) instead."
- (let ((cmd (format-spec command
- `((?h . ,host) (?n . ,tramp-rsh-end-of-line))))
- (cmd1 (format-spec command `((?h . ,host) (?n . ""))))
- found pw)
- (erase-buffer)
- (tramp-message 9 "Sending telnet command `%s'" cmd1)
- (process-send-string p cmd)
- (tramp-process-multi-actions p method user host
- tramp-multi-actions)))
-
-;; HHH: Changed. Multi method. Don't know how to handle this in the case
-;; of no user name provided. Hack to make it work as it did before:
-;; changed `user' to `(or user (user-login-name))' in the places where
-;; the value is actually used.
-(defun tramp-multi-connect-rlogin (p method user host command)
- "Issue `rlogin' command.
-Uses shell COMMAND to issue an `rlogin' command to log in as USER to
-HOST. You can use percent escapes in COMMAND. `%u' will be replaced
-with the user name, `%h' will be replaced with the host name, and `%n'
-will be replaced with the value of `tramp-rsh-end-of-line'. You can use
-`%%' if you want to use a literal percent character.
-
-If USER is nil, uses the return value of (user-login-name) instead."
- (let ((cmd (format-spec command `((?h . ,host)
- (?u . ,(or user (user-login-name)))
- (?n . ,tramp-rsh-end-of-line))))
- (cmd1 (format-spec command `((?h . ,host)
- (?u . ,(or user (user-login-name)))
- (?n . ""))))
- found)
- (erase-buffer)
- (tramp-message 9 "Sending rlogin command `%s'" cmd1)
- (process-send-string p cmd)
- (tramp-process-multi-actions p method user host
- tramp-multi-actions)))
-
-;; HHH: Changed. Multi method. Don't know how to handle this in the case
-;; of no user name provided. Hack to make it work as it did before:
-;; changed `user' to `(or user (user-login-name))' in the places where
-;; the value is actually used.
-(defun tramp-multi-connect-su (p method user host command)
- "Issue `su' command.
-Uses shell COMMAND to issue a `su' command to log in as USER on
-HOST. The HOST name is ignored, this just changes the user id on the
-host currently logged in to.
-
-If USER is nil, uses the return value of (user-login-name) instead.
-
-You can use percent escapes in the COMMAND. `%u' is replaced with the
-user name, and `%n' is replaced with the value of
-`tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
-character."
- (let ((cmd (format-spec command `((?u . ,(or user (user-login-name)))
- (?n . ,tramp-rsh-end-of-line))))
- (cmd1 (format-spec command `((?u . ,(or user (user-login-name)))
- (?n . ""))))
- found)
- (erase-buffer)
- (tramp-message 9 "Sending su command `%s'" cmd1)
- (process-send-string p cmd)
- (tramp-process-multi-actions p method user host
- tramp-multi-actions)))