mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-23 07:19:15 +00:00
More Tramp optional methods
* doc/misc/tramp.texi (Inline methods) <krlogin, ksu>: (External methods) <fcp, nc>: These are optional methods. * etc/NEWS: Mention more optional Tramp methods. * lisp/net/tramp-androidsu.el (tramp-enable-androidsu-method): Use proper regexp for `tramp-default-user-alist'. * lisp/net/tramp-sh.el (tramp-enable-nc-method) (tramp-enable-ksu-method, tramp-enable-krlogin-method) (tramp-enable-fcp-method): New defuns. Move respective configurations there. * lisp/net/tramp.el (tramp-enable-method): Implement completion for interactive use. * test/lisp/net/tramp-tests.el (tramp-test03-file-name-defaults) (tramp-test03-file-name-host-rules): Extend tests.
This commit is contained in:
parent
e020f4e9ce
commit
339b8349f4
@ -923,12 +923,15 @@ missing shell prompts that confuses @value{tramp}.
|
||||
This method is also similar to @option{ssh}. It uses the
|
||||
@command{krlogin -x} command only for remote host login.
|
||||
|
||||
This method is an optional method, @ref{Optional methods}.
|
||||
|
||||
@item @option{ksu}
|
||||
@cindex method @option{ksu}
|
||||
@cindex @option{ksu} method
|
||||
@cindex kerberos (with @option{ksu} method)
|
||||
|
||||
This is another method from the Kerberos suite. It behaves like @option{su}.
|
||||
This is another method from the Kerberos suite. It behaves like
|
||||
@option{su}. It is an optional method, @ref{Optional methods}.
|
||||
|
||||
@item @option{plink}
|
||||
@cindex method @option{plink}
|
||||
@ -1151,6 +1154,8 @@ The command used for this connection is: @samp{fsh @var{host} -l
|
||||
not useful for @value{tramp}. @command{fsh} connects to remote host
|
||||
and @value{tramp} keeps that one connection open.
|
||||
|
||||
This is an optional method, @ref{Optional methods}.
|
||||
|
||||
@item @option{nc}
|
||||
@cindex method @option{nc}
|
||||
@cindex @option{nc} method
|
||||
@ -1162,6 +1167,8 @@ NAS hosts. These dumb devices have severely restricted local shells,
|
||||
such as the @command{busybox} and do not host any other encode or
|
||||
decode programs.
|
||||
|
||||
This is an optional method, @ref{Optional methods}.
|
||||
|
||||
@item @option{sudoedit}
|
||||
@cindex method @option{sudoedit}
|
||||
@cindex @option{sudoedit} method
|
||||
|
3
etc/NEWS
3
etc/NEWS
@ -1053,7 +1053,8 @@ mode line. 'header' will display in the header line;
|
||||
+++
|
||||
*** Tramp methods can be optional.
|
||||
An optional connection method is not enabled by default. The user must
|
||||
enable it explicitly by the 'tramp-enable-method' command.
|
||||
enable it explicitly by the 'tramp-enable-method' command. The existing
|
||||
methods "fcp", "krlogin", " ksu" and "nc" are optional now.
|
||||
|
||||
+++
|
||||
*** New optional connection method "androidsu".
|
||||
|
@ -91,7 +91,8 @@ may edit files belonging to any and all applications."
|
||||
(tramp-shell-name ,tramp-androidsu-local-shell-name)))
|
||||
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,tramp-androidsu-method nil ,tramp-root-id-string)))
|
||||
`(,(rx bos (literal tramp-androidsu-method) eos)
|
||||
nil ,tramp-root-id-string)))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(tramp--with-startup
|
||||
|
@ -272,22 +272,6 @@ The string is used in `tramp-methods'.")
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))))
|
||||
(add-to-list 'tramp-methods
|
||||
`("nc"
|
||||
(tramp-login-program "telnet")
|
||||
(tramp-login-args (("%h") ("%p") ("%n")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))
|
||||
(tramp-copy-program "nc")
|
||||
;; We use "-v" for better error tracking.
|
||||
(tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r")))
|
||||
(tramp-copy-file-name (("%f")))
|
||||
(tramp-remote-copy-program "nc")
|
||||
;; We use "-p" as required for newer busyboxes. For older
|
||||
;; busybox/nc versions, the value must be (("-l") ("%r")). This
|
||||
;; can be achieved by tweaking `tramp-connection-properties'.
|
||||
(tramp-remote-copy-args (("-l") ("-p" "%r") ("%n")))))
|
||||
(add-to-list 'tramp-methods
|
||||
`("su"
|
||||
(tramp-login-program "su")
|
||||
@ -328,21 +312,6 @@ The string is used in `tramp-methods'.")
|
||||
(tramp-connection-timeout 10)
|
||||
(tramp-session-timeout 300)
|
||||
(tramp-password-previous-hop t)))
|
||||
(add-to-list 'tramp-methods
|
||||
`("ksu"
|
||||
(tramp-login-program "ksu")
|
||||
(tramp-login-args (("%u") ("-q")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))
|
||||
(tramp-connection-timeout 10)))
|
||||
(add-to-list 'tramp-methods
|
||||
`("krlogin"
|
||||
(tramp-login-program "krlogin")
|
||||
(tramp-login-args (("%h") ("-l" "%u") ("-x")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))))
|
||||
(add-to-list 'tramp-methods
|
||||
`("plink"
|
||||
(tramp-login-program "plink")
|
||||
@ -403,30 +372,18 @@ The string is used in `tramp-methods'.")
|
||||
(tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp")
|
||||
("-p" "%k")))
|
||||
(tramp-copy-keep-date t)))
|
||||
(add-to-list 'tramp-methods
|
||||
`("fcp"
|
||||
(tramp-login-program "fsh")
|
||||
(tramp-login-args (("%h") ("-l" "%u") ("sh" "-i")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-i") ("-c"))
|
||||
(tramp-copy-program "fcp")
|
||||
(tramp-copy-args (("-p" "%k")))
|
||||
(tramp-copy-keep-date t)))
|
||||
|
||||
(add-to-list 'tramp-default-method-alist
|
||||
`(,tramp-local-host-regexp
|
||||
,(rx bos (literal tramp-root-id-string) eos) "su"))
|
||||
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,(rx bos (| "su" "sudo" "doas" "ksu") eos)
|
||||
`(,(rx bos (| "su" "sudo" "doas") eos)
|
||||
nil ,tramp-root-id-string))
|
||||
;; Do not add "ssh" based methods, otherwise ~/.ssh/config would be ignored.
|
||||
;; Do not add "plink" based methods, they ask interactively for the user.
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,(rx bos
|
||||
(| "rcp" "remcp" "rsh" "telnet" "nc" "krlogin" "fcp")
|
||||
eos)
|
||||
`(,(rx bos (| "rcp" "remcp" "rsh" "telnet") eos)
|
||||
nil ,(user-login-name))))
|
||||
|
||||
(defconst tramp-default-copy-file-name '(("%u" "@") ("%h" ":") ("%f"))
|
||||
@ -508,20 +465,94 @@ The string is used in `tramp-methods'.")
|
||||
(tramp-set-completion-function "sshx" tramp-completion-function-alist-ssh)
|
||||
(tramp-set-completion-function
|
||||
"telnet" tramp-completion-function-alist-telnet)
|
||||
(tramp-set-completion-function "nc" tramp-completion-function-alist-telnet)
|
||||
(tramp-set-completion-function "su" tramp-completion-function-alist-su)
|
||||
(tramp-set-completion-function "sudo" tramp-completion-function-alist-su)
|
||||
(tramp-set-completion-function "doas" tramp-completion-function-alist-su)
|
||||
(tramp-set-completion-function "ksu" tramp-completion-function-alist-su)
|
||||
(tramp-set-completion-function "sg" tramp-completion-function-alist-sg)
|
||||
(tramp-set-completion-function
|
||||
"krlogin" tramp-completion-function-alist-rsh)
|
||||
(tramp-set-completion-function "plink" tramp-completion-function-alist-ssh)
|
||||
(tramp-set-completion-function
|
||||
"plinkx" tramp-completion-function-alist-putty)
|
||||
(tramp-set-completion-function "pscp" tramp-completion-function-alist-ssh)
|
||||
(tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh)
|
||||
(tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh))
|
||||
(tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defun tramp-enable-nc-method ()
|
||||
"Enable \"ksu\" method."
|
||||
(add-to-list 'tramp-methods
|
||||
`("nc"
|
||||
(tramp-login-program "telnet")
|
||||
(tramp-login-args (("%h") ("%p") ("%n")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))
|
||||
(tramp-copy-program "nc")
|
||||
;; We use "-v" for better error tracking.
|
||||
(tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r")))
|
||||
(tramp-copy-file-name (("%f")))
|
||||
(tramp-remote-copy-program "nc")
|
||||
;; We use "-p" as required for newer busyboxes. For
|
||||
;; older busybox/nc versions, the value must be
|
||||
;; (("-l") ("%r")). This can be achieved by tweaking
|
||||
;; `tramp-connection-properties'.
|
||||
(tramp-remote-copy-args (("-l") ("-p" "%r") ("%n")))))
|
||||
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,(rx bos "nc" eos) nil ,(user-login-name)))
|
||||
|
||||
(tramp-set-completion-function "nc" tramp-completion-function-alist-telnet))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defun tramp-enable-ksu-method ()
|
||||
"Enable \"ksu\" method."
|
||||
(add-to-list 'tramp-methods
|
||||
`("ksu"
|
||||
(tramp-login-program "ksu")
|
||||
(tramp-login-args (("%u") ("-q")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))
|
||||
(tramp-connection-timeout 10)))
|
||||
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,(rx bos "ksu" eos) nil ,tramp-root-id-string))
|
||||
|
||||
(tramp-set-completion-function "ksu" tramp-completion-function-alist-su))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defun tramp-enable-krlogin-method ()
|
||||
"Enable \"krlogin\" method."
|
||||
(add-to-list 'tramp-methods
|
||||
`("krlogin"
|
||||
(tramp-login-program "krlogin")
|
||||
(tramp-login-args (("%h") ("-l" "%u") ("-x")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-c"))))
|
||||
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,(rx bos "krlogin" eos) nil ,(user-login-name)))
|
||||
|
||||
(tramp-set-completion-function
|
||||
"krlogin" tramp-completion-function-alist-rsh))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defun tramp-enable-fcp-method ()
|
||||
"Enable \"fcp\" method."
|
||||
(add-to-list 'tramp-methods
|
||||
`("fcp"
|
||||
(tramp-login-program "fsh")
|
||||
(tramp-login-args (("%h") ("-l" "%u") ("sh" "-i")))
|
||||
(tramp-remote-shell ,tramp-default-remote-shell)
|
||||
(tramp-remote-shell-login ("-l"))
|
||||
(tramp-remote-shell-args ("-i") ("-c"))
|
||||
(tramp-copy-program "fcp")
|
||||
(tramp-copy-args (("-p" "%k")))
|
||||
(tramp-copy-keep-date t)))
|
||||
|
||||
(add-to-list 'tramp-default-user-alist
|
||||
`(,(rx bos "fcp" eos) nil ,(user-login-name)))
|
||||
|
||||
(tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh))
|
||||
|
||||
(defcustom tramp-sh-extra-args
|
||||
`((,(rx (| bos "/") "bash" eos) . "-noediting -norc -noprofile")
|
||||
|
@ -1462,7 +1462,27 @@ calling HANDLER.")
|
||||
|
||||
(defun tramp-enable-method (method)
|
||||
"Enable optional METHOD if possible."
|
||||
(interactive "Mmethod: ")
|
||||
(interactive
|
||||
(list
|
||||
(completing-read
|
||||
"method: "
|
||||
(seq-keep
|
||||
(lambda (x)
|
||||
(when-let ((name (symbol-name x))
|
||||
;; It must match `tramp-enable-METHOD-method'.
|
||||
((string-match
|
||||
(rx "tramp-enable-"
|
||||
(group (regexp tramp-method-regexp))
|
||||
"-method")
|
||||
name))
|
||||
(method (match-string 1 name))
|
||||
;; It must not be enabled yet.
|
||||
((not (assoc method tramp-methods))))
|
||||
method))
|
||||
;; All method enabling functions.
|
||||
(mapcar
|
||||
#'intern (all-completions "tramp-enable-" obarray #'functionp))))))
|
||||
|
||||
(when-let (((not (assoc method tramp-methods)))
|
||||
(fn (intern (format "tramp-enable-%s-method" method)))
|
||||
((functionp fn)))
|
||||
|
@ -2103,14 +2103,18 @@ is greater than 10.
|
||||
(string-equal (file-remote-p (format "/-:%s@:" u) 'method) "ftp"))))
|
||||
;; Default values in tramp-sh.el and tramp-sudoedit.el.
|
||||
(when (assoc "su" tramp-methods)
|
||||
(dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
|
||||
(dolist
|
||||
(h `("127.0.0.1" "[::1]" "localhost" "localhost4" "localhost6"
|
||||
"ip6-localhost" "ip6-loopback" ,(system-name)))
|
||||
(should
|
||||
(string-equal (file-remote-p (format "/-:root@%s:" h) 'method) "su")))
|
||||
(dolist (m '("su" "sudo" "ksu" "doas" "sudoedit"))
|
||||
(string-equal (file-remote-p (format "/-:root@%s:" h) 'method) "su"))))
|
||||
(dolist (m '("su" "sudo" "ksu" "doas" "sudoedit"))
|
||||
(when (assoc m tramp-methods)
|
||||
(should (string-equal (file-remote-p (format "/%s::" m) 'user) "root"))
|
||||
(should
|
||||
(string-equal (file-remote-p (format "/%s::" m) 'host) (system-name))))
|
||||
(dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp" "nc"))
|
||||
(string-equal (file-remote-p (format "/%s::" m) 'host) (system-name)))))
|
||||
(dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp" "nc"))
|
||||
(when (assoc m tramp-methods)
|
||||
(should
|
||||
(string-equal
|
||||
(file-remote-p (format "/%s::" m) 'user) (user-login-name)))))
|
||||
@ -2128,21 +2132,22 @@ is greater than 10.
|
||||
;; Host names must match rules in case the command template of a
|
||||
;; method doesn't use them.
|
||||
(dolist (m '("su" "sg" "sudo" "doas" "ksu"))
|
||||
(let (tramp-connection-properties tramp-default-proxies-alist)
|
||||
(ignore-errors
|
||||
(tramp-cleanup-connection tramp-test-vec nil 'keep-password))
|
||||
;; Single hop. The host name must match `tramp-local-host-regexp'.
|
||||
(should-error
|
||||
(find-file (format "/%s:foo:" m))
|
||||
:type 'user-error)
|
||||
;; Multi hop. The host name must match the previous hop.
|
||||
(should-error
|
||||
(find-file
|
||||
(format
|
||||
"%s|%s:foo:"
|
||||
(substring (file-remote-p ert-remote-temporary-file-directory) 0 -1)
|
||||
m))
|
||||
:type 'user-error))))
|
||||
(when (assoc m tramp-methods)
|
||||
(let (tramp-connection-properties tramp-default-proxies-alist)
|
||||
(ignore-errors
|
||||
(tramp-cleanup-connection tramp-test-vec nil 'keep-password))
|
||||
;; Single hop. The host name must match `tramp-local-host-regexp'.
|
||||
(should-error
|
||||
(find-file (format "/%s:foo:" m))
|
||||
:type 'user-error)
|
||||
;; Multi hop. The host name must match the previous hop.
|
||||
(should-error
|
||||
(find-file
|
||||
(format
|
||||
"%s|%s:foo:"
|
||||
(substring (file-remote-p ert-remote-temporary-file-directory) 0 -1)
|
||||
m))
|
||||
:type 'user-error)))))
|
||||
|
||||
(ert-deftest tramp-test03-file-name-method-rules ()
|
||||
"Check file name rules for some methods."
|
||||
|
Loading…
Reference in New Issue
Block a user