]> git.eshelyaron.com Git - emacs.git/commitdiff
More Tramp optional methods
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 8 May 2024 11:44:15 +0000 (13:44 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 8 May 2024 16:53:07 +0000 (18:53 +0200)
* 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.

(cherry picked from commit 339b8349f436b3738cfa02b236e05c3da4c5a8a5)

doc/misc/tramp.texi
etc/NEWS
lisp/net/tramp-androidsu.el
lisp/net/tramp-sh.el
lisp/net/tramp.el
test/lisp/net/tramp-tests.el

index aa628e55f825e22cc430d6893dab64da918cb68c..76d8136d196e5748809a115e6e9bf753e7255c1f 100644 (file)
@@ -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
index 7c58d01444e0ca1fa0b29744980c605f7ed8c78c..ec98255c0111763cf361504ae672f8f885640d82 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1151,7 +1151,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".
index 09dcd4d7bed1b56ae2fea3b6cb823ba6e697e14e..953f75ad9f307e4992e0285fe95e4d60a8ae2114 100644 (file)
@@ -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
index 5af1d723bb9aad4d24d70f46398ca3e930a969a7..bb136d6e6b5ff6f9e2dd39ee8dcf4b6ad60ae9bd 100644 (file)
@@ -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")
index 6b002366c172df3f95ae1523317bdb97ba0fbd22..f2f25e60cc29afefc844de5bf2cd820afad9f631 100644 (file)
@@ -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)))
index 88d6c13331da5dbd5925fb9cf3c06169c1f59815..931bc25ef43220b7b417901c669c2c01b38aba18 100644 (file)
@@ -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."