emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 3abe7bf: Handle also port and domain in Tramp proxy


From: Michael Albinus
Subject: [Emacs-diffs] master 3abe7bf: Handle also port and domain in Tramp proxy definitions
Date: Tue, 6 Nov 2018 09:48:13 -0500 (EST)

branch: master
commit 3abe7bfe306706a95ca8dc404c7645073c949507
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    Handle also port and domain in Tramp proxy definitions
    
    * doc/misc/tramp.texi (Multi-hops): Exclude ports and domains from
    pattern expansion.
    
    * lisp/net/tramp-cmds.el (tramp-cleanup-all-connections):
    Remove ad-hoc proxies.
    
    * lisp/net/tramp-sh.el (tramp-compute-multi-hops): Handle also
    port and domain in the proxy.  Propertize ad-hoc proxies.
    
    * lisp/net/tramp.el (tramp-default-proxies-alist): Adapt docstring.
    
    * test/lisp/net/tramp-tests.el (tramp-test02-file-name-dissect)
    (tramp-test02-file-name-dissect-simplified)
    (tramp-test02-file-name-dissect-separate): Extend tests.
---
 doc/misc/tramp.texi          |  3 ++-
 lisp/net/tramp-cmds.el       | 13 +++++++++++++
 lisp/net/tramp-sh.el         | 20 +++++++++++---------
 lisp/net/tramp.el            | 16 +++++++++++-----
 test/lisp/net/tramp-tests.el | 40 +++++++++++++++++++++++-----------------
 5 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index f682055..a0b65d5 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -1374,7 +1374,8 @@ connect to @samp{bastion.your.domain}, then:
 @end lisp
 
 @var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
address@hidden respectively.
address@hidden respectively.  Ports or domains, if they are part of
+a hop file name, are not expanded by those patterns.
 
 To login as @samp{root} on remote hosts in the domain
 @samp{your.domain}, but login as @samp{root} is disabled for non-local
diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el
index b05f475..456300e 100644
--- a/lisp/net/tramp-cmds.el
+++ b/lisp/net/tramp-cmds.el
@@ -147,6 +147,19 @@ This includes password cache, file cache, connection 
cache, buffers."
   (when (bound-and-true-p tramp-archive-enabled)
     (tramp-archive-cleanup-hash))
 
+  ;; Remove ad-hoc proxies.
+  (let ((proxies tramp-default-proxies-alist))
+    (while proxies
+      (if (ignore-errors
+           (get-text-property 0 'tramp-ad-hoc (nth 2 (car proxies))))
+         (setq tramp-default-proxies-alist
+               (delete (car proxies) tramp-default-proxies-alist)
+               proxies tramp-default-proxies-alist)
+       (setq proxies (cdr proxies)))))
+    (when (and tramp-default-proxies-alist tramp-save-ad-hoc-proxies)
+      (customize-save-variable
+       'tramp-default-proxies-alist tramp-default-proxies-alist))
+
   ;; Remove buffers.
   (dolist (name (tramp-list-tramp-buffers))
     (when (bufferp (get-buffer name)) (kill-buffer name))))
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 11ee063..4fb011b 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -4571,21 +4571,21 @@ Goes through the list `tramp-inline-compress-commands'."
 
     ;; Ad-hoc proxy definitions.
     (dolist (proxy (reverse (split-string hops tramp-postfix-hop-regexp 
'omit)))
-      (let ((user (tramp-file-name-user item))
-           (host (tramp-file-name-host item))
+      (let ((user-domain (tramp-file-name-user-domain item))
+           (host-port (tramp-file-name-host-port item))
            (proxy (concat
                    tramp-prefix-format proxy tramp-postfix-host-format)))
        (tramp-message
         vec 5 "Add proxy (\"%s\" \"%s\" \"%s\")"
-        (and (stringp host) (regexp-quote host))
-        (and (stringp user) (regexp-quote user))
+        (and (stringp host-port) (regexp-quote host-port))
+        (and (stringp user-domain) (regexp-quote user-domain))
         proxy)
        ;; Add the hop.
        (add-to-list
         'tramp-default-proxies-alist
-        (list (and (stringp host) (regexp-quote host))
-              (and (stringp user) (regexp-quote user))
-              proxy))
+        (list (and (stringp host-port) (regexp-quote host-port))
+              (and (stringp user-domain) (regexp-quote user-domain))
+              (propertize proxy 'tramp-ad-hoc t)))
        (setq item (tramp-dissect-file-name proxy))))
     ;; Save the new value.
     (when (and hops tramp-save-ad-hoc-proxies)
@@ -4600,10 +4600,12 @@ Goes through the list `tramp-inline-compress-commands'."
       (when (and
             ;; Host.
             (string-match (or (eval (nth 0 item)) "")
-                          (or (tramp-file-name-host (car target-alist)) ""))
+                          (or (tramp-file-name-host-port (car target-alist))
+                              ""))
             ;; User.
             (string-match (or (eval (nth 1 item)) "")
-                          (or (tramp-file-name-user (car target-alist)) "")))
+                          (or (tramp-file-name-user-domain (car target-alist))
+                              "")))
        (if (null proxy)
            ;; No more hops needed.
            (setq choices nil)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 13c3b5f..6d8e720 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -379,11 +379,17 @@ empty string for the method name."
 This is an alist of items (HOST USER PROXY).  The first matching
 item specifies the proxy to be passed for a file name located on
 a remote target matching address@hidden  HOST and USER are regular
-expressions.  PROXY must be a Tramp filename without a localname
-part.  Method and user name on PROXY are optional, which is
-interpreted with the default values.  PROXY can contain the
-patterns %h and %u, which are replaced by the strings matching
-HOST or USER, respectively.
+expressions, which could also cover a domain (USER%DOMAIN) or
+port (HOST#PORT).  PROXY must be a Tramp filename without a
+localname part.  Method and user name on PROXY are optional,
+which is interpreted with the default values.
+
+PROXY can contain the patterns %h and %u, which are replaced by
+the strings matching HOST or USER (without DOMAIN and PORT parts),
+respectively.
+
+If an entry is added while parsing ad-hoc hop definitions, PROXY
+carries the non-nil text property `tramp-ad-hoc'.
 
 HOST, USER or PROXY could also be Lisp forms, which will be
 evaluated.  The result must be a string or nil, which is
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index ceda709..4016ece 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -819,12 +819,14 @@ handled properly.  BODY shall not contain a timeout."
       (file-remote-p
        (concat
        "/method1:address@hidden"
-       "|method2:address@hidden"
-       "|method3:address@hidden:/path/to/file"))
-      (format "/%s:address@hidden|%s:address@hidden|%s:address@hidden:"
-             "method1" "user3" "host3"
-             "method2" "user3" "host3"
-             "method3" "user3" "host3")))))
+       "|method2:address@hidden"
+       "|method3:address@hidden"
+       "|method4:address@hidden:/path/to/file"))
+      (format 
"/%s:address@hidden|%s:address@hidden|%s:address@hidden|%s:address@hidden:"
+             "method1" "user2" "host2"
+             "method2" "user2" "host2"
+             "method3" "user4" "host4"
+             "method4" "user4%domain4" "host4#1234")))))
 
 (ert-deftest tramp-test02-file-name-dissect-simplified ()
   "Check simplified file name components."
@@ -1134,12 +1136,14 @@ handled properly.  BODY shall not contain a timeout."
            (file-remote-p
             (concat
              "/address@hidden"
+             "|address@hidden"
              "|address@hidden"
-             "|address@hidden:/path/to/file"))
-           (format "/address@hidden|address@hidden|address@hidden:"
-                   "user3" "host3"
-                   "user3" "host3"
-                   "user3" "host3"))))
+             "|address@hidden:/path/to/file"))
+           (format 
"/address@hidden|address@hidden|address@hidden|address@hidden:"
+                   "user2" "host2"
+                   "user2" "host2"
+                   "user4" "host4"
+                   "user4%domain4" "host4#1234"))))
 
       ;; Exit.
       (tramp-change-syntax syntax))))
@@ -1780,12 +1784,14 @@ handled properly.  BODY shall not contain a timeout."
            (file-remote-p
             (concat
              "/[method1/address@hidden"
-             "|method2/address@hidden"
-             "|method3/address@hidden/path/to/file"))
-           (format "/[%s/address@hidden|%s/address@hidden|%s/address@hidden"
-                   "method1" "user3" "host3"
-                   "method2" "user3" "host3"
-                   "method3" "user3" "host3"))))
+             "|method2/address@hidden"
+             "|method3/address@hidden"
+             "|method4/address@hidden/path/to/file"))
+           (format 
"/[%s/address@hidden|%s/address@hidden|%s/address@hidden|%s/address@hidden"
+                   "method1" "user2" "host2"
+                   "method2" "user2" "host2"
+                   "method3" "user4" "host4"
+                   "method4" "user4%domain4" "host4#1234"))))
 
       ;; Exit.
       (tramp-change-syntax syntax))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]