From ced27394cf1181bdb40c7cf54d65bc441789dd3a Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sat, 15 Feb 2025 17:12:52 +0100 Subject: [PATCH] Tramp: Don't require PuTTY 0.82 anymore * doc/misc/tramp.texi: Revert last change. * lisp/net/tramp-cache.el (with-tramp-saved-connection-properties): Adapt `tramp-verbose' when completing host names. * lisp/net/tramp-sh.el (tramp-methods) : Adapt `tramp-login-args' and `tramp-copy-args' arguments. (tramp-plink-option-exists-p): New defun. (tramp-ssh-or-plink-options): Rename from `tramp-ssh-controlmaster-options'. Adapt further plink options. (tramp-do-copy-or-rename-file-out-of-band) (tramp-maybe-open-connection): Adapt calls. * lisp/net/tramp.el (tramp-file-name-handler): Don't touch `tramp-verbose'. * test/lisp/net/tramp-tests.el (top): Set `vc-handled-backends' to nil. (tramp--test-enabled): Rearrange code. (cherry picked from commit 5fcf07ac096a588a561fae07d8177acd8e45498b) --- doc/misc/tramp.texi | 10 ++--- lisp/net/tramp-cache.el | 4 +- lisp/net/tramp-sh.el | 87 +++++++++++++++++++----------------- lisp/net/tramp.el | 12 ++--- test/lisp/net/tramp-tests.el | 31 ++++++------- 5 files changed, 73 insertions(+), 71 deletions(-) diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 467bc7d35a2..941029a8ffc 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -955,10 +955,9 @@ This is another method from the Kerberos suite. It behaves like @cindex @option{plink} method @item @option{plink} -@option{plink} method is for MS Windows users with the -PuTTY@footnote{It requires at least PuTTY 0.82.} implementation of -SSH@. It uses @samp{plink -ssh} to log in to the remote host. It -supports changing the remote login shell @command{/bin/sh}. +@option{plink} method is for MS Windows users with the PuTTY +implementation of SSH@. It uses @samp{plink -ssh} to log in to the +remote host. It supports changing the remote login shell @command{/bin/sh}. Check the @samp{Share SSH connections if possible} control for that session. @@ -1181,8 +1180,7 @@ This method supports the @samp{-p} argument. These methods are similar to @option{scp} or @option{sftp}, but they use the @command{plink} command to connect to the remote host, and they use @command{pscp} or @command{psftp} for transferring the files. -These programs are part of PuTTY@footnote{It requires at least PuTTY -0.82.}, an SSH implementation for MS Windows. +These programs are part of PuTTY, an SSH implementation for MS Windows. They support changing the remote login shell @command{/bin/sh}. diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 64f14c46db6..ba4c786451a 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -502,7 +502,9 @@ PROPERTIES is a list of file properties (strings)." (mapcar (lambda (property) (cons property (gethash property hash tramp-cache-undefined))) - ,properties))) + ,properties)) + ;; Avoid superfluous debug buffers during host name completion. + (tramp-verbose (if minibuffer-completing-file-name 0 tramp-verbose))) (tramp-message key 7 "Saved %s" values) (unwind-protect (progn ,@body) ;; Reset PROPERTIES. Recompute hash, it could have been flushed. diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 24e27a102de..e4df1499467 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -322,8 +322,6 @@ The string is used in `tramp-methods'.") `("plink" (tramp-login-program "plink") (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%c") - ;; Since PuTTY 0.82. - ("-legacy-stdio-prompts") ("-t") ("%h") ("\"") (,(format "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" @@ -337,8 +335,6 @@ The string is used in `tramp-methods'.") `("plinkx" (tramp-login-program "plink") (tramp-login-args (("-load") ("%h") ("%c") ("-t") ("\"") - ;; Since PuTTY 0.82. - ("-legacy-stdio-prompts") (,(format "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" tramp-terminal-type @@ -351,8 +347,6 @@ The string is used in `tramp-methods'.") `("pscp" (tramp-login-program "plink") (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%c") - ;; Since PuTTY 0.82. - ("-legacy-stdio-prompts") ("-t") ("%h") ("\"") (,(format "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" @@ -363,9 +357,7 @@ The string is used in `tramp-methods'.") (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-c")) (tramp-copy-program "pscp") - (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") - ;; Since PuTTY 0.82. - ("-legacy-stdio-prompts") + (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("%c") ("-p" "%k") ("-q") ("-r"))) (tramp-copy-keep-date t) (tramp-copy-recursive t))) @@ -373,8 +365,6 @@ The string is used in `tramp-methods'.") `("psftp" (tramp-login-program "plink") (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%c") - ;; Since PuTTY 0.82. - ("-legacy-stdio-prompts") ("-t") ("%h") ("\"") (,(format "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" @@ -385,9 +375,7 @@ The string is used in `tramp-methods'.") (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-c")) (tramp-copy-program "pscp") - (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") - ;; Since PuTTY 0.82. - ("-legacy-stdio-prompts") + (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") ("%c") ("-p" "%k"))) (tramp-copy-keep-date t))) @@ -2506,7 +2494,7 @@ The method used must be an out-of-band method." ;; Compose copy command. (setq options (format-spec - (tramp-ssh-controlmaster-options v) + (tramp-ssh-or-plink-options v) (format-spec-make ?t (tramp-get-connection-property (tramp-get-connection-process v) "temp-file" ""))) @@ -4916,41 +4904,60 @@ Goes through the list `tramp-inline-compress-commands'." (zerop (tramp-call-process vec "ssh" nil nil nil "-G" "-o" option "0.0.0.1")))) -(defun tramp-ssh-controlmaster-options (vec) - "Return the Control* arguments of the local ssh." +(defun tramp-plink-option-exists-p (vec option) + "Check, whether local plink OPTION is applicable." + ;; We don't want to cache it persistently. + (with-tramp-connection-property nil option + ;; "plink" with valid options returns "plink: no valid host name + ;; provided". We xcheck for this error message." + (with-temp-buffer + (tramp-call-process vec "plink" nil t nil option) + (not + (string-match-p + (rx (| (: "plink: unknown option \"" (literal option) "\"" ) + (: "plink: option \"" (literal option) + "\" not available in this tool" ))) + (buffer-string)))))) + +(defun tramp-ssh-or-plink-options (vec) + "Return additional arguments of the local ssh or plink." (cond ;; No options to be computed. - ((or (null tramp-use-connection-share) - (null (assoc "%c" (tramp-get-method-parameter vec 'tramp-login-args)))) - "") + ((null (assoc "%c" (tramp-get-method-parameter vec 'tramp-login-args))) "") - ;; Use plink option. + ;; Use plink options. ((string-match-p (rx "plink" (? ".exe") eol) (tramp-get-method-parameter vec 'tramp-login-program)) - (if (eq tramp-use-connection-share 'suppress) - "-noshare" "-share")) + (concat + (if (eq tramp-use-connection-share 'suppress) + "-noshare" "-share") + ;; Since PuTTY 0.82. + (when (tramp-plink-option-exists-p vec "-legacy-stdio-prompts") + " -legacy-stdio-prompts"))) ;; There is already a value to be used. ((and (eq tramp-use-connection-share t) (stringp tramp-ssh-controlmaster-options)) tramp-ssh-controlmaster-options) - ;; We can't auto-compute the options. - ((ignore-errors - (not (tramp-ssh-option-exists-p vec "ControlMaster=auto"))) - "") - - ;; Determine the options. - (t (ignore-errors - ;; ControlMaster and ControlPath options are introduced in OpenSSH 3.9. - (concat - "-o ControlMaster=" - (if (eq tramp-use-connection-share 'suppress) + ;; Use ssh options. + (tramp-use-connection-share + ;; We can't auto-compute the options. + (if (ignore-errors + (not (tramp-ssh-option-exists-p vec "ControlMaster=auto"))) + "" + + ;; Determine the options. + (ignore-errors + ;; ControlMaster and ControlPath options are introduced in OpenSSH 3.9. + (concat + "-o ControlMaster=" + (if (eq tramp-use-connection-share 'suppress) "no" "auto") - " -o ControlPath=" - (if (eq tramp-use-connection-share 'suppress) + " -o ControlPath=" + (if (eq tramp-use-connection-share 'suppress) "none" ;; Hashed tokens are introduced in OpenSSH 6.7. On macOS ;; we cannot use an absolute file name, it is too long. @@ -4964,10 +4971,10 @@ Goes through the list `tramp-inline-compress-commands'." (or small-temporary-file-directory tramp-compat-temporary-file-directory)))) - ;; ControlPersist option is introduced in OpenSSH 5.6. + ;; ControlPersist option is introduced in OpenSSH 5.6. (when (and (not (eq tramp-use-connection-share 'suppress)) (tramp-ssh-option-exists-p vec "ControlPersist=no")) - " -o ControlPersist=no")))))) + " -o ControlPersist=no"))))))) (defun tramp-scp-strict-file-name-checking (vec) "Return the strict file name checking argument of the local scp." @@ -5183,9 +5190,9 @@ connection if a previous connection has died for some reason." (let* ((current-host tramp-system-name) (target-alist (tramp-compute-multi-hops vec)) (previous-hop tramp-null-hop) - ;; We will apply `tramp-ssh-controlmaster-options' + ;; We will apply `tramp-ssh-or-plink-options' ;; only for the first hop. - (options (tramp-ssh-controlmaster-options vec)) + (options (tramp-ssh-or-plink-options vec)) (process-connection-type tramp-process-connection-type) (process-adaptive-read-buffering nil) ;; There are unfortunate settings for "cmdproxy" diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index dd525fbd01b..9cefeafea6e 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -2538,10 +2538,7 @@ Fall back to normal file name handler if no Tramp file name handler exists." ;; We flush connection properties ;; " process-name" and " process-buffer", ;; because the operations shall be applied - ;; in the main connection process. In order - ;; to avoid superfluous debug buffers during - ;; host name completion, we adapt - ;; `tramp-verbose'. + ;; in the main connection process. ;; If `non-essential' is non-nil, Tramp shall ;; not open a new connection. ;; If Tramp detects that it shouldn't continue @@ -2552,11 +2549,8 @@ Fall back to normal file name handler if no Tramp file name handler exists." ;; In both cases, we try the default handler then. (with-tramp-saved-connection-properties v '(" process-name" " process-buffer") - (let ((tramp-verbose - (if minibuffer-completing-file-name - 0 tramp-verbose))) - (tramp-flush-connection-property v " process-name") - (tramp-flush-connection-property v " process-buffer")) + (tramp-flush-connection-property v " process-name") + (tramp-flush-connection-property v " process-buffer") (setq result (catch 'non-essential (catch 'suppress diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 0bb81c188e7..44ccd552850 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -152,7 +152,8 @@ tramp-copy-size-limit nil tramp-error-show-message-timeout nil tramp-persistency-file-name nil - tramp-verbose 0) + tramp-verbose 0 + vc-handled-backends nil) (defconst tramp-test-name-prefix "tramp-test" "Prefix to use for temporary test files.") @@ -251,20 +252,20 @@ being the result.") (file-writable-p ert-remote-temporary-file-directory)))))) (when (cdr tramp--test-enabled-checked) - ;; Remove old test files. - (dolist (dir `(,temporary-file-directory - ,tramp-compat-temporary-file-directory - ,ert-remote-temporary-file-directory)) - (dolist (file (directory-files - dir 'full - (rx-to-string - `(: bos (? ".#") - (| ,tramp-test-name-prefix - ,(if (getenv "TRAMP_TEST_CLEANUP_TEMP_FILES") - tramp-temp-name-prefix 'unmatchable)))))) - - ;; Exclude sockets and FUSE mount points. - (ignore-errors + (ignore-errors + ;; Remove old test files. + (dolist (dir `(,temporary-file-directory + ,tramp-compat-temporary-file-directory + ,ert-remote-temporary-file-directory)) + (dolist (file (directory-files + dir 'full + (rx-to-string + `(: bos (? ".#") + (| ,tramp-test-name-prefix + ,(if (getenv "TRAMP_TEST_CLEANUP_TEMP_FILES") + tramp-temp-name-prefix 'unmatchable)))))) + + ;; Exclude sockets and FUSE mount points. (unless (or (string-prefix-p "srw" (file-attribute-modes (file-attributes file))) -- 2.39.5