all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60499: 28.2; tramp: Remote host name not always accounted when computing multi-hops
@ 2023-01-02 11:57 Jani Juhani Sinervo
  2023-01-04 17:26 ` Michael Albinus
  0 siblings, 1 reply; 3+ messages in thread
From: Jani Juhani Sinervo @ 2023-01-02 11:57 UTC (permalink / raw)
  To: 60499

When using a custom TRAMP method with a program that expects the host
name to be passed in as an argument to a command-line switch, the
natural way of writing the `tramp-login-args' like (("--switch" "%h"))
does not work, since `tramp-compute-multi-hops' only considers the host
name to have been used within the command template, if it is in its own
list, as in (("--switch") ("%h")).

This is a problem, because there are tools, like Toolbox[0], which
allow running the command within a specific container. For example with
Toolbox, it would look something like the following:

`toolbox run -c container-name-here command'

This can be turned into a TRAMP method relatively easily, and the most
natural way to write the `tramp-login-args' would be the following:

(tramp-login-args (("run") ("-c" "%h") ("sh")))

This however will not work for the aforementioned bug in
`tramp-compute-multi-hops'. While splitting the "-c" and "%h" into
their own lists works, and would work for the usecase of
`C-x C-f /toolbox:container-name-here:', there is a reasonable
interpretation for `C-x C-f /toolbox::', entering the default
container, in which case splitting the optional "-c"-flag from the
"host name" would not be the valid thing to do.

[0]: https://containertoolbx.org/

Steps to reproduce from `emacs -Q':

1. Evaluate the following Lisp in the scratch buffer:

(require 'tramp)
(add-to-list 'tramp-methods
             (cons "ssh4"
                   '((tramp-login-program "ssh")
                     (tramp-login-args (("-l" "%u")
                                        ("-p" "%p")
                                        ("%c")
                                        ("-e" "none")
                                        ("-t" "-t")
                                        ("-o" "RemoteCommand=\"%l\"")
                                        ("-4" "%h")))
                     (tramp-remote-shell "/bin/sh")
                     (tramp-remote-shell-login
                      ("-l"))
                     (tramp-remote-shell-args
                      ("-c")))))

2. Try to connect somewhere with this method, for example by doing:

`C-x C-f /ssh4:example.org: TAB'

Expected behavior:

TRAMP should try to connect to the host according to the method
definition.

Actual behavior:

TRAMP gives the error message:

Host name ‘example.org’ does not match
‘\`\(127\.0\.0\.1\|::1\|hostname\|localhost6?\)\'’

The code responsible can be found in `lisp/net/tramp.el' and within the
function `tramp-compute-multi-hops'. Excerpt:

;; Some methods ("su", "sg", "sudo", "doas", "ksu") do not use the
;; host name in their command template.  In this case, the remote
;; file name must use either a local host name (first hop), or a
;; host name matching the previous hop.
(let ((previous-host (or tramp-local-host-regexp "")))
  (setq choices target-alist)
  (while (setq item (pop choices))
    (let ((host (tramp-file-name-host item)))
      (unless
          (or
           ;; The host name is used for the remote shell command.
           (member
            '("%h") (tramp-get-method-parameter item 'tramp-login-
args))
           ;; The host name must match previous hop.
           (string-match-p previous-host host))
        (setq tramp-default-proxies-alist saved-tdpa)
        (tramp-user-error
         vec "Host name `%s' does not match `%s'" host previous-host))
      (setq previous-host (concat "^" (regexp-quote host) "$")))))

We notice that the culprit here is the call to `member', where it
erroneously checks for the host name being used by the command template
by only checking whether the literal list '("%h") is within the
`tramp-login-args'.

My proposed fix would be the go through the `tramp-login-args' method
parameter, and go through each of the list-of-lists to check whether
there is a string "%h" there.


In GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.35,
cairo version 1.16.0)
 of 2022-12-09 built on cncf-x86-3
Windowing system distributor 'The X.Org Foundation', version
11.0.12201007
System Description: Freedesktop.org SDK 22.08 (Flatpak runtime)

Configured using:
 'configure --prefix=/app --with-gnutls 'CFLAGS=-O2 -g -pipe
 -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions
 -fstack-protector-strong -grecord-gcc-switches
 -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
 -fno-omit-frame-pointer ' 'LDFLAGS=-L/app/lib -Wl,-z,relro,-z,now
 -Wl,--as-needed ''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG
JSON
LCMS2 LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM
GTK3 ZLIB

Important settings:
  value of $LANG: en_GB.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  electric-pair-mode: t
  icomplete-mode: t
  yas-global-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  global-corfu-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/var/home/jani/.emacs.d/elpa/transient-20221202.1727/transient hides
/app/share/emacs/28.2/lisp/transient

Features:
(shadow sort mail-extr emacsbug sendmail checkdoc lisp-mnt
rainbow-delimiters elec-pair cus-edit cus-load wid-edit icomplete
geiser
slime-tramp docker-tramp tramp-cache tramp tramp-loaddefs trampver
tramp-integration files-x tramp-compat parse-time iso8601 ls-lisp
slime-asdf grep slime-fancy slime-indentation slime-cl-indent cl-indent
slime-trace-dialog slime-fontifying-fu slime-package-fu slime-
references
slime-compiler-notes-tree advice slime-scratch slime-presentations
bridge slime-macrostep macrostep slime-mdot-fu slime-enclosing-context
slime-fuzzy slime-fancy-trace slime-fancy-inspector slime-c-p-c
slime-editing-commands slime-autodoc slime-repl slime-parse slime
arc-mode archive-mode pp hyperspec ibuffer ibuffer-loaddefs elixir-mode
elixir-format elixir-smie pass f f-shortdoc shortdoc s password-store
auth-source-pass adoc-mode tempo markup-faces markdown-mode
edit-indirect color haskell-mode haskell-cabal haskell-utils
haskell-font-lock haskell-indentation haskell-string
haskell-sort-imports haskell-lexeme haskell-align-imports
haskell-complete-module haskell-ghc-support noutline outline etags
fileloop generator xref dabbrev haskell-customize typescript-mode
cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs irony irony-iotask meson-mode smie tango-theme
yasnippet
magit-submodule magit-obsolete magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-
status
magit magit-repos magit-apply magit-wip magit-log which-func imenu
magit-diff smerge-mode diff diff-mode git-commit rx log-edit message
rmc
puny dired dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068
epg-config gnus-util rmail rmail-loaddefs time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums
mail-prsvr mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log
magit-core magit-autorevert autorevert filenotify magit-margin
magit-transient magit-process with-editor shell pcomplete server
magit-mode transient edmacro kmacro magit-git magit-base magit-section
format-spec crm dash compat-27 compat-26 compat compat-macs flymake-
proc
flymake project compile text-property-search comint ansi-color ring
warnings thingatpt corfu cl-extra help-mode use-package-bind-key
bind-key easy-mmode use-package-ensure use-package-core tex-site
slime-autoloads info package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
mailcap url-handlers url-parse auth-source cl-seq eieio eieio-core
cl-macs eieio-loaddefs password-cache json subr-x map url-vars seq
byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib iso-transl
tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-
dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj
charscript
charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
emacs)

Memory information:
((conses 16 262115 24837)
 (symbols 48 27853 4)
 (strings 32 93904 4769)
 (string-bytes 1 3030693)
 (vectors 16 50616)
 (vector-slots 8 589420 28184)
 (floats 8 264 120)
 (intervals 56 490 79)
 (buffers 992 13))






^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#60499: 28.2; tramp: Remote host name not always accounted when computing multi-hops
  2023-01-02 11:57 bug#60499: 28.2; tramp: Remote host name not always accounted when computing multi-hops Jani Juhani Sinervo
@ 2023-01-04 17:26 ` Michael Albinus
  2023-01-08 18:27   ` Michael Albinus
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Albinus @ 2023-01-04 17:26 UTC (permalink / raw)
  To: Jani Juhani Sinervo; +Cc: 60499

[-- Attachment #1: Type: text/plain, Size: 1987 bytes --]

Jani Juhani Sinervo <jani@sinervo.fi> writes:

Hi Jani,

> When using a custom TRAMP method with a program that expects the host
> name to be passed in as an argument to a command-line switch, the
> natural way of writing the `tramp-login-args' like (("--switch" "%h"))
> does not work, since `tramp-compute-multi-hops' only considers the host
> name to have been used within the command template, if it is in its own
> list, as in (("--switch") ("%h")).
>
> This is a problem, because there are tools, like Toolbox[0], which
> allow running the command within a specific container. For example with
> Toolbox, it would look something like the following:
>
> `toolbox run -c container-name-here command'
>
> This can be turned into a TRAMP method relatively easily, and the most
> natural way to write the `tramp-login-args' would be the following:
>
> (tramp-login-args (("run") ("-c" "%h") ("sh")))

Thanks for the bug report.

> The code responsible can be found in `lisp/net/tramp.el' and within the
> function `tramp-compute-multi-hops'. Excerpt:
>
> We notice that the culprit here is the call to `member', where it
> erroneously checks for the host name being used by the command template
> by only checking whether the literal list '("%h") is within the
> `tramp-login-args'.
>
> My proposed fix would be the go through the `tramp-login-args' method
> parameter, and go through each of the list-of-lists to check whether
> there is a string "%h" there.

I've pushed a slightly simpler fix to the emacs-29 branch, see
appended. It will appear with the upcoming Emacs 29.1.

Until it is released, you could also try to apply it in Emacs 28.2 (I
didn't check myself). Or you wait for the next GNU ELPA release of
Tramp, 2.6.0.1, which will appear later this month.

Btw, the idea with toolbox looks good. I'll see whether I could add it
to Tramp 2.7, living in the Emacs master branch. However, I'd prefer to say

(tramp-login-args (("enter") ("-c" "%h")))

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 588 bytes --]

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 61a606c3383..f0b17ef3934 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4694,7 +4694,8 @@ tramp-compute-multi-hops
 	      (or
 	       ;; The host name is used for the remote shell command.
 	       (member
-		'("%h") (tramp-get-method-parameter item 'tramp-login-args))
+		"%h" (tramp-compat-flatten-tree
+		      (tramp-get-method-parameter item 'tramp-login-args)))
 	       ;; The host name must match previous hop.
 	       (string-match-p previous-host host))
 	    (setq tramp-default-proxies-alist saved-tdpa)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#60499: 28.2; tramp: Remote host name not always accounted when computing multi-hops
  2023-01-04 17:26 ` Michael Albinus
@ 2023-01-08 18:27   ` Michael Albinus
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Albinus @ 2023-01-08 18:27 UTC (permalink / raw)
  To: Jani Juhani Sinervo; +Cc: 60499-done

Version: 29.1

Michael Albinus <michael.albinus@gmx.de> writes:

Hi Jani,

> Btw, the idea with toolbox looks good. I'll see whether I could add it
> to Tramp 2.7, living in the Emacs master branch.

I've added this to Emacs master (Tramp 2.7).

> However, I'd prefer to say
>
> (tramp-login-args (("enter") ("-c" "%h")))

This didn't work, so I'm using "toolbox run ..." as proposed.

Since there's nothing left to do, I'm closing the bug.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-08 18:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-02 11:57 bug#60499: 28.2; tramp: Remote host name not always accounted when computing multi-hops Jani Juhani Sinervo
2023-01-04 17:26 ` Michael Albinus
2023-01-08 18:27   ` Michael Albinus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.