aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-11-06 15:48:05 +0100
committerMichael Albinus2018-11-06 15:48:05 +0100
commit3abe7bfe306706a95ca8dc404c7645073c949507 (patch)
treeb4221e4bd7527ce22f3040e0ea6603ec1954c0a7
parentff1ee4e0bef4f62b758b70266d2f21be166924c3 (diff)
downloademacs-3abe7bfe306706a95ca8dc404c7645073c949507.tar.gz
emacs-3abe7bfe306706a95ca8dc404c7645073c949507.zip
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.
-rw-r--r--doc/misc/tramp.texi3
-rw-r--r--lisp/net/tramp-cmds.el13
-rw-r--r--lisp/net/tramp-sh.el20
-rw-r--r--lisp/net/tramp.el16
-rw-r--r--test/lisp/net/tramp-tests.el40
5 files changed, 60 insertions, 32 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index f68205519f3..a0b65d58b55 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -1374,7 +1374,8 @@ connect to @samp{bastion.your.domain}, then:
1374@end lisp 1374@end lisp
1375 1375
1376@var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or 1376@var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
1377@var{user} respectively. 1377@var{user} respectively. Ports or domains, if they are part of
1378a hop file name, are not expanded by those patterns.
1378 1379
1379To login as @samp{root} on remote hosts in the domain 1380To login as @samp{root} on remote hosts in the domain
1380@samp{your.domain}, but login as @samp{root} is disabled for non-local 1381@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 b05f475f2fd..456300e7662 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."
147 (when (bound-and-true-p tramp-archive-enabled) 147 (when (bound-and-true-p tramp-archive-enabled)
148 (tramp-archive-cleanup-hash)) 148 (tramp-archive-cleanup-hash))
149 149
150 ;; Remove ad-hoc proxies.
151 (let ((proxies tramp-default-proxies-alist))
152 (while proxies
153 (if (ignore-errors
154 (get-text-property 0 'tramp-ad-hoc (nth 2 (car proxies))))
155 (setq tramp-default-proxies-alist
156 (delete (car proxies) tramp-default-proxies-alist)
157 proxies tramp-default-proxies-alist)
158 (setq proxies (cdr proxies)))))
159 (when (and tramp-default-proxies-alist tramp-save-ad-hoc-proxies)
160 (customize-save-variable
161 'tramp-default-proxies-alist tramp-default-proxies-alist))
162
150 ;; Remove buffers. 163 ;; Remove buffers.
151 (dolist (name (tramp-list-tramp-buffers)) 164 (dolist (name (tramp-list-tramp-buffers))
152 (when (bufferp (get-buffer name)) (kill-buffer name)))) 165 (when (bufferp (get-buffer name)) (kill-buffer name))))
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 11ee0639988..4fb011b3423 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'."
4571 4571
4572 ;; Ad-hoc proxy definitions. 4572 ;; Ad-hoc proxy definitions.
4573 (dolist (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit))) 4573 (dolist (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit)))
4574 (let ((user (tramp-file-name-user item)) 4574 (let ((user-domain (tramp-file-name-user-domain item))
4575 (host (tramp-file-name-host item)) 4575 (host-port (tramp-file-name-host-port item))
4576 (proxy (concat 4576 (proxy (concat
4577 tramp-prefix-format proxy tramp-postfix-host-format))) 4577 tramp-prefix-format proxy tramp-postfix-host-format)))
4578 (tramp-message 4578 (tramp-message
4579 vec 5 "Add proxy (\"%s\" \"%s\" \"%s\")" 4579 vec 5 "Add proxy (\"%s\" \"%s\" \"%s\")"
4580 (and (stringp host) (regexp-quote host)) 4580 (and (stringp host-port) (regexp-quote host-port))
4581 (and (stringp user) (regexp-quote user)) 4581 (and (stringp user-domain) (regexp-quote user-domain))
4582 proxy) 4582 proxy)
4583 ;; Add the hop. 4583 ;; Add the hop.
4584 (add-to-list 4584 (add-to-list
4585 'tramp-default-proxies-alist 4585 'tramp-default-proxies-alist
4586 (list (and (stringp host) (regexp-quote host)) 4586 (list (and (stringp host-port) (regexp-quote host-port))
4587 (and (stringp user) (regexp-quote user)) 4587 (and (stringp user-domain) (regexp-quote user-domain))
4588 proxy)) 4588 (propertize proxy 'tramp-ad-hoc t)))
4589 (setq item (tramp-dissect-file-name proxy)))) 4589 (setq item (tramp-dissect-file-name proxy))))
4590 ;; Save the new value. 4590 ;; Save the new value.
4591 (when (and hops tramp-save-ad-hoc-proxies) 4591 (when (and hops tramp-save-ad-hoc-proxies)
@@ -4600,10 +4600,12 @@ Goes through the list `tramp-inline-compress-commands'."
4600 (when (and 4600 (when (and
4601 ;; Host. 4601 ;; Host.
4602 (string-match (or (eval (nth 0 item)) "") 4602 (string-match (or (eval (nth 0 item)) "")
4603 (or (tramp-file-name-host (car target-alist)) "")) 4603 (or (tramp-file-name-host-port (car target-alist))
4604 ""))
4604 ;; User. 4605 ;; User.
4605 (string-match (or (eval (nth 1 item)) "") 4606 (string-match (or (eval (nth 1 item)) "")
4606 (or (tramp-file-name-user (car target-alist)) ""))) 4607 (or (tramp-file-name-user-domain (car target-alist))
4608 "")))
4607 (if (null proxy) 4609 (if (null proxy)
4608 ;; No more hops needed. 4610 ;; No more hops needed.
4609 (setq choices nil) 4611 (setq choices nil)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 13c3b5f939c..6d8e720563f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -379,11 +379,17 @@ empty string for the method name."
379This is an alist of items (HOST USER PROXY). The first matching 379This is an alist of items (HOST USER PROXY). The first matching
380item specifies the proxy to be passed for a file name located on 380item specifies the proxy to be passed for a file name located on
381a remote target matching USER@HOST. HOST and USER are regular 381a remote target matching USER@HOST. HOST and USER are regular
382expressions. PROXY must be a Tramp filename without a localname 382expressions, which could also cover a domain (USER%DOMAIN) or
383part. Method and user name on PROXY are optional, which is 383port (HOST#PORT). PROXY must be a Tramp filename without a
384interpreted with the default values. PROXY can contain the 384localname part. Method and user name on PROXY are optional,
385patterns %h and %u, which are replaced by the strings matching 385which is interpreted with the default values.
386HOST or USER, respectively. 386
387PROXY can contain the patterns %h and %u, which are replaced by
388the strings matching HOST or USER (without DOMAIN and PORT parts),
389respectively.
390
391If an entry is added while parsing ad-hoc hop definitions, PROXY
392carries the non-nil text property `tramp-ad-hoc'.
387 393
388HOST, USER or PROXY could also be Lisp forms, which will be 394HOST, USER or PROXY could also be Lisp forms, which will be
389evaluated. The result must be a string or nil, which is 395evaluated. 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 ceda70947c8..4016ece94d3 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."
819 (file-remote-p 819 (file-remote-p
820 (concat 820 (concat
821 "/method1:%u@%h" 821 "/method1:%u@%h"
822 "|method2:%u@%h" 822 "|method2:user2@host2"
823 "|method3:user3@host3:/path/to/file")) 823 "|method3:%u@%h"
824 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:" 824 "|method4:user4%domain4@host4#1234:/path/to/file"))
825 "method1" "user3" "host3" 825 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s|%s:%s@%s:"
826 "method2" "user3" "host3" 826 "method1" "user2" "host2"
827 "method3" "user3" "host3"))))) 827 "method2" "user2" "host2"
828 "method3" "user4" "host4"
829 "method4" "user4%domain4" "host4#1234")))))
828 830
829(ert-deftest tramp-test02-file-name-dissect-simplified () 831(ert-deftest tramp-test02-file-name-dissect-simplified ()
830 "Check simplified file name components." 832 "Check simplified file name components."
@@ -1134,12 +1136,14 @@ handled properly. BODY shall not contain a timeout."
1134 (file-remote-p 1136 (file-remote-p
1135 (concat 1137 (concat
1136 "/%u@%h" 1138 "/%u@%h"
1139 "|user2@host2"
1137 "|%u@%h" 1140 "|%u@%h"
1138 "|user3@host3:/path/to/file")) 1141 "|user4%domain4@host4#1234:/path/to/file"))
1139 (format "/%s@%s|%s@%s|%s@%s:" 1142 (format "/%s@%s|%s@%s|%s@%s|%s@%s:"
1140 "user3" "host3" 1143 "user2" "host2"
1141 "user3" "host3" 1144 "user2" "host2"
1142 "user3" "host3")))) 1145 "user4" "host4"
1146 "user4%domain4" "host4#1234"))))
1143 1147
1144 ;; Exit. 1148 ;; Exit.
1145 (tramp-change-syntax syntax)))) 1149 (tramp-change-syntax syntax))))
@@ -1780,12 +1784,14 @@ handled properly. BODY shall not contain a timeout."
1780 (file-remote-p 1784 (file-remote-p
1781 (concat 1785 (concat
1782 "/[method1/%u@%h" 1786 "/[method1/%u@%h"
1783 "|method2/%u@%h" 1787 "|method2/user2@host2"
1784 "|method3/user3@host3]/path/to/file")) 1788 "|method3/%u@%h"
1785 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]" 1789 "|method4/user4%domain4@host4#1234]/path/to/file"))
1786 "method1" "user3" "host3" 1790 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1787 "method2" "user3" "host3" 1791 "method1" "user2" "host2"
1788 "method3" "user3" "host3")))) 1792 "method2" "user2" "host2"
1793 "method3" "user4" "host4"
1794 "method4" "user4%domain4" "host4#1234"))))
1789 1795
1790 ;; Exit. 1796 ;; Exit.
1791 (tramp-change-syntax syntax)))) 1797 (tramp-change-syntax syntax))))