aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-12-21 12:42:22 +0100
committerMichael Albinus2016-12-21 12:42:22 +0100
commit8661313efd5fd5b0a27fe82f276a1ff862646424 (patch)
treeacdb27c91f2380b3aa13e25c36dc26a8e1cea5a5
parent221d3a9767422ba783aedcd354fd1fe2d60e9bb3 (diff)
downloademacs-8661313efd5fd5b0a27fe82f276a1ff862646424.tar.gz
emacs-8661313efd5fd5b0a27fe82f276a1ff862646424.zip
Remove gateway methods in Tramp
* doc/misc/tramp.texi (Top, Configuration): Remove section `Gateway methods', insert section `Firewalls' in menu. (History): Gateways are removed now. (Gateway methods): Remove section. (Multi-hops, Traces and Profiles): Don't reference to gateways anymore. (Firewalls): New section. * etc/NEWS: Gateway methods in Tramp have been removed. * lisp/net/tramp.el (tramp-methods): Adapt docstring. (tramp-file-name-port, tramp-accept-process-output): Simplify. * lisp/net/tramp-gw.el: Remove. * lisp/net/tramp-sh.el (tramp-gw-tunnel-method) (tramp-gw-socks-method): Remove declarations. (tramp-methods) <scp, scpx, ssh, sshx, telnet, nc, plink, pscp>: Remove `tramp-gw-args' and `tramp-default-port'. (Bug#18967) (tramp-do-copy-or-rename-file-out-of-band) (tramp-compute-multi-hops, tramp-maybe-open-connection): Remove gateway support. * test/lisp/net/tramp-tests.el (tramp-test03-file-name-defaults): Remove gateway tests.
-rw-r--r--doc/misc/tramp.texi139
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/net/tramp-gw.el339
-rw-r--r--lisp/net/tramp-sh.el105
-rw-r--r--lisp/net/tramp.el31
-rw-r--r--test/lisp/net/tramp-tests.el4
6 files changed, 82 insertions, 540 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 955a13e477a..1ba22e0b594 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -143,11 +143,11 @@ Configuring @value{tramp} for use
143* Inline methods:: Inline methods. 143* Inline methods:: Inline methods.
144* External methods:: External methods. 144* External methods:: External methods.
145* GVFS based methods:: GVFS based external methods. 145* GVFS based methods:: GVFS based external methods.
146* Gateway methods:: Gateway methods.
147* Default Method:: Selecting a default method. 146* Default Method:: Selecting a default method.
148* Default User:: Selecting a default user. 147* Default User:: Selecting a default user.
149* Default Host:: Selecting a default host. 148* Default Host:: Selecting a default host.
150* Multi-hops:: Connecting to a remote host using multiple hops. 149* Multi-hops:: Connecting to a remote host using multiple hops.
150* Firewalls:: Passing firewalls.
151* Customizing Methods:: Using Non-Standard Methods. 151* Customizing Methods:: Using Non-Standard Methods.
152* Customizing Completion:: Selecting config files for user/host name completion. 152* Customizing Completion:: Selecting config files for user/host name completion.
153* Password handling:: Reusing passwords for several connections. 153* Password handling:: Reusing passwords for several connections.
@@ -406,10 +406,11 @@ April 2000 was the first time when multi-hop methods were added. In
406July 2002, @value{tramp} unified file names with Ange-FTP@. In July 406July 2002, @value{tramp} unified file names with Ange-FTP@. In July
4072004, proxy hosts replaced multi-hop methods. Running commands on 4072004, proxy hosts replaced multi-hop methods. Running commands on
408remote hosts was introduced in December 2005. Support for gateways 408remote hosts was introduced in December 2005. Support for gateways
409since April 2007. GVFS integration started in February 2009. Remote 409since April 2007 (and removed in December 2016). GVFS integration
410commands on Windows hosts since September 2011. Ad-hoc multi-hop 410started in February 2009. Remote commands on Windows hosts since
411methods (with a changed syntax) re-enabled in November 2011. In 411September 2011. Ad-hoc multi-hop methods (with a changed syntax)
412November 2012, added Juergen Hoetzel's @file{tramp-adb.el}. 412re-enabled in November 2011. In November 2012, added Juergen
413Hoetzel's @file{tramp-adb.el}.
413 414
414XEmacs support has been stopped in January 2016. 415XEmacs support has been stopped in January 2016.
415 416
@@ -453,7 +454,6 @@ installed and loaded:
453* Inline methods:: Inline methods. 454* Inline methods:: Inline methods.
454* External methods:: External methods. 455* External methods:: External methods.
455* GVFS based methods:: GVFS based external methods. 456* GVFS based methods:: GVFS based external methods.
456* Gateway methods:: Gateway methods.
457* Default Method:: Selecting a default method. 457* Default Method:: Selecting a default method.
458 Here we also try to help those who 458 Here we also try to help those who
459 don't have the foggiest which method 459 don't have the foggiest which method
@@ -461,6 +461,7 @@ installed and loaded:
461* Default User:: Selecting a default user. 461* Default User:: Selecting a default user.
462* Default Host:: Selecting a default host. 462* Default Host:: Selecting a default host.
463* Multi-hops:: Connecting to a remote host using multiple hops. 463* Multi-hops:: Connecting to a remote host using multiple hops.
464* Firewalls:: Passing firewalls.
464* Customizing Methods:: Using Non-Standard Methods. 465* Customizing Methods:: Using Non-Standard Methods.
465* Customizing Completion:: Selecting config files for user/host name completion. 466* Customizing Completion:: Selecting config files for user/host name completion.
466* Password handling:: Reusing passwords for several connections. 467* Password handling:: Reusing passwords for several connections.
@@ -997,51 +998,6 @@ Other methods to include are: @option{ftp} and @option{smb}.
997@end defopt 998@end defopt
998 999
999 1000
1000@node Gateway methods
1001@section Gateway methods
1002@cindex methods, gateway
1003@cindex gateway methods
1004
1005Gateway methods are for proxy host declarations (@pxref{Multi-hops})
1006so as to pass through firewalls and proxy servers. They are not like
1007the other methods that declare direct connections to a remote host.
1008
1009A gateway method always comes with a port setting. @value{tramp}
1010targets the port number with the gateway method
1011@file{localhost#random_port} from where the firewall or proxy server
1012is accessed.
1013
1014Gateway methods support user name and password declarations for
1015authenticating the corresponding firewall or proxy server. Such
1016authentication can be passed through only if granted access by system
1017administrators.
1018
1019@table @asis
1020@item @option{tunnel}
1021@cindex method tunnel
1022@cindex tunnel method
1023
1024This method implements an HTTP tunnel via the @command{CONNECT}
1025command (conforming to RFC 2616, 2817 specifications). Proxy servers
1026using HTTP version 1.1 or later protocol support this command.
1027
1028For authentication, this protocol uses only @option{Basic
1029Authentication} (see RFC 2617). When no port number is specified, this
1030protocol defaults to @option{8080}.
1031
1032@item @option{socks}
1033@cindex method socks
1034@cindex socks method
1035
1036The @option{socks} method connects to SOCKSv5 servers (see RFC 1928)
1037and supports @option{Username/Password Authentication}.
1038
1039The default port number for the socks server is @option{1080}, if not
1040specified otherwise.
1041
1042@end table
1043
1044
1045@node Default Method 1001@node Default Method
1046@section Selecting a default method 1002@section Selecting a default method
1047@cindex default method 1003@cindex default method
@@ -1244,9 +1200,8 @@ regular expression which always matches.
1244@var{proxy} is a literal @value{tramp} file name whose local name part 1200@var{proxy} is a literal @value{tramp} file name whose local name part
1245is ignored, and the method and user name parts are optional. 1201is ignored, and the method and user name parts are optional.
1246 1202
1247The method must be an inline or gateway method (@pxref{Inline 1203The method must be an inline method (@pxref{Inline methods}). If
1248methods}, @pxref{Gateway methods}). 1204@var{proxy} is @code{nil}, no additional hop is required reaching
1249If @var{proxy} is @code{nil}, no additional hop is required reaching
1250@var{user}@@@var{host}. 1205@var{user}@@@var{host}.
1251 1206
1252For example, to pass through the host @samp{bastion.your.domain} as 1207For example, to pass through the host @samp{bastion.your.domain} as
@@ -1313,32 +1268,6 @@ local one, first connect via @command{ssh}, and then apply
1313 '((regexp-quote (system-name)) nil nil)) 1268 '((regexp-quote (system-name)) nil nil))
1314@end group 1269@end group
1315@end lisp 1270@end lisp
1316
1317The above configuration allows @value{tramp} connection as @samp{root}
1318to remote Ubuntu hosts.
1319
1320@option{tramp-default-proxies-alist} is also used for passing through
1321firewalls or proxy servers.
1322
1323For example, the local host @samp{proxy.your.domain} on port 3128
1324serves as HTTP proxy to the outer world. User has access rights to
1325another proxy server on @samp{host.other.domain}.@footnote{HTTP tunnels
1326are intended for secure SSL/TLS communication. Therefore, many proxy
1327servers restrict the tunnels to related target ports. You might need
1328to run your ssh server on your target host @samp{host.other.domain} on
1329such a port, like 443 (https). See
1330@uref{http://savannah.gnu.org/maintenance/CvsFromBehindFirewall} for
1331discussion of ethical issues.} Then the configuration is:
1332
1333@lisp
1334@group
1335(add-to-list 'tramp-default-proxies-alist
1336 '("\\`host\\.other\\.domain\\'" nil
1337 "@trampfn{tunnel,proxy.your.domain#3128,}"))
1338@end group
1339@end lisp
1340
1341Gateway methods in a multiple hop chain can be declared only as the first hop.
1342@end defopt 1271@end defopt
1343 1272
1344Passing through hops involves dealing with restricted shells, such as 1273Passing through hops involves dealing with restricted shells, such as
@@ -1362,6 +1291,50 @@ restricted shell:
1362@end defopt 1291@end defopt
1363 1292
1364 1293
1294@node Firewalls
1295@section Passing firewalls
1296@cindex HTTP tunnel
1297@cindex proxy hosts, HTTP tunnel
1298
1299Sometimes, it is not possible to reach a remote host directly. A
1300firewall might be in the way, which could be passed via a proxy
1301server.
1302
1303Both ssh and PuTTY support such proxy settings, using an HTTP tunnel
1304via the @command{CONNECT} command (conforming to RFC 2616, 2817
1305specifications). Proxy servers using HTTP version 1.1 or later
1306protocol support this command.
1307
1308@subsection Tunneling with ssh
1309
1310With ssh, you could use the @code{ProxyCommand} entry in the
1311@file{~/.ssh/config}:
1312
1313@example
1314@group
1315Host host.other.domain
1316 ProxyCommand nc -X connect -x proxy.your.domain:3128 %h %p
1317@end group
1318@end example
1319
1320@code{nc} is BSD's netcat program, which establishes HTTP tunnels. Any
1321other program with such a feature could be used as well.
1322
1323In the example, opening @file{@trampfn{ssh,host.your.domain,}} passes
1324the HTTP proxy server @samp{proxy.your.domain} on port 3128.
1325
1326@subsection Tunneling with PuTTY
1327
1328PuTTY does not need an external program, HTTP tunnel support is
1329built-in. In the PuTTY config program, create a session for
1330@samp{host.your.domain}. In the @option{Connection/Data} entry,
1331select the @option{HTTP} option, and add @samp{proxy.your.domain} as
1332@option{Proxy hostname}, and 3128 as @option{Port}.
1333
1334Opening @file{@trampfn{plinkx,host.your.domain,}} passes the HTTP
1335proxy server @samp{proxy.your.domain} on port 3128.
1336
1337
1365@node Customizing Methods 1338@node Customizing Methods
1366@section Using Non-Standard Methods 1339@section Using Non-Standard Methods
1367@cindex customizing methods 1340@cindex customizing methods
@@ -3618,14 +3591,12 @@ have to be specifically enabled as shown in this code:
3618(dolist (elt (all-completions "tramp-" obarray 'functionp)) 3591(dolist (elt (all-completions "tramp-" obarray 'functionp))
3619 (trace-function-background (intern elt))) 3592 (trace-function-background (intern elt)))
3620(untrace-function 'tramp-read-passwd) 3593(untrace-function 'tramp-read-passwd)
3621(untrace-function 'tramp-gw-basic-authentication)
3622@end group 3594@end group
3623@end lisp 3595@end lisp
3624 3596
3625The buffer @file{*trace-output*} contains the output from the function 3597The buffer @file{*trace-output*} contains the output from the function
3626call traces. Disable @code{tramp-read-passwd} and 3598call traces. Disable @code{tramp-read-passwd} to stop password
3627@code{tramp-gw-basic-authentication} to stop password strings from 3599strings from being written to @file{*trace-output*}.
3628being written to @file{*trace-output*}.
3629 3600
3630 3601
3631@node GNU Free Documentation License 3602@node GNU Free Documentation License
diff --git a/etc/NEWS b/etc/NEWS
index ee74236a528..7338c0c6a70 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -567,6 +567,10 @@ different group ID.
567Drive onsite repositories. 567Drive onsite repositories.
568 568
569+++ 569+++
570*** Gateway methods in Tramp have been removed. Instead, the Tramp
571manual documents how to configure ssh and PuTTY accordingly.
572
573+++
570Setting the "ENV" environment variable in 'tramp-remote-process-environment' 574Setting the "ENV" environment variable in 'tramp-remote-process-environment'
571enables reading of shell initialization files. 575enables reading of shell initialization files.
572 576
diff --git a/lisp/net/tramp-gw.el b/lisp/net/tramp-gw.el
deleted file mode 100644
index 8f8f107ec10..00000000000
--- a/lisp/net/tramp-gw.el
+++ /dev/null
@@ -1,339 +0,0 @@
1;;; tramp-gw.el --- Tramp utility functions for HTTP tunnels and SOCKS gateways
2
3;; Copyright (C) 2007-2016 Free Software Foundation, Inc.
4
5;; Author: Michael Albinus <michael.albinus@gmx.de>
6;; Keywords: comm, processes
7;; Package: tramp
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;; Access functions for HTTP tunnels and SOCKS gateways from Tramp.
27;; SOCKS functionality is implemented by socks.el from the w3 package.
28;; HTTP tunnels are partly implemented in socks.el and url-http.el;
29;; both implementations are not complete. Therefore, it is
30;; implemented in this package.
31
32;;; Code:
33
34(require 'tramp)
35
36;; Pacify byte-compiler.
37(eval-when-compile
38 (require 'cl)
39 (require 'custom))
40(defvar socks-noproxy)
41
42;; We don't add the following methods to `tramp-methods', in order to
43;; exclude them from file name completion.
44
45;; Define HTTP tunnel method ...
46;;;###tramp-autoload
47(defconst tramp-gw-tunnel-method "tunnel"
48 "Method to connect HTTP gateways.")
49
50;; ... and port.
51(defconst tramp-gw-default-tunnel-port 8080
52 "Default port for HTTP gateways.")
53
54;; Define SOCKS method ...
55;;;###tramp-autoload
56(defconst tramp-gw-socks-method "socks"
57 "Method to connect SOCKS servers.")
58
59;; ... and port.
60(defconst tramp-gw-default-socks-port 1080
61 "Default port for SOCKS servers.")
62
63;; Autoload the socks library. It is used only when we access a SOCKS server.
64(autoload 'socks-open-network-stream "socks")
65(defvar socks-username (user-login-name))
66(defvar socks-server
67 (list "Default server" "socks" tramp-gw-default-socks-port 5))
68
69;; Add a default for `tramp-default-user-alist'. Default is the local user.
70;;;###tramp-autoload
71(add-to-list
72 'tramp-default-user-alist
73 (list (concat "\\`"
74 (regexp-opt (list tramp-gw-tunnel-method tramp-gw-socks-method))
75 "\\'")
76 nil (user-login-name)))
77
78;; Internal file name functions and variables.
79
80(defvar tramp-gw-vector nil
81 "Keeps the remote host identification. Needed for Tramp messages.")
82
83(defvar tramp-gw-gw-vector nil
84 "Current gateway identification vector.")
85
86(defvar tramp-gw-gw-proc nil
87 "Current gateway process.")
88
89;; This variable keeps the listening process, in order to reuse it for
90;; new processes.
91(defvar tramp-gw-aux-proc nil
92 "Process listening on local port, as mediation between SSH and the gateway.")
93
94(defun tramp-gw-gw-proc-sentinel (proc _event)
95 "Delete auxiliary process when we are deleted."
96 (unless (tramp-compat-process-live-p proc)
97 (tramp-message
98 tramp-gw-vector 4 "Deleting auxiliary process `%s'" tramp-gw-gw-proc)
99 (let* ((tramp-verbose 0)
100 (p (tramp-get-connection-property proc "process" nil)))
101 (when (processp p) (delete-process p)))))
102
103(defun tramp-gw-aux-proc-sentinel (proc _event)
104 "Activate the different filters for involved gateway and auxiliary processes."
105 (when (tramp-compat-process-live-p proc)
106 ;; A new process has been spawned from `tramp-gw-aux-proc'.
107 (tramp-message
108 tramp-gw-vector 4
109 "Opening auxiliary process `%s', speaking with process `%s'"
110 proc tramp-gw-gw-proc)
111 (set-process-query-on-exit-flag proc nil)
112 ;; We don't want debug messages, because the corresponding debug
113 ;; buffer might be undecided.
114 (let ((tramp-verbose 0))
115 (tramp-set-connection-property tramp-gw-gw-proc "process" proc)
116 (tramp-set-connection-property proc "process" tramp-gw-gw-proc))
117 ;; Set the process-filter functions for both processes.
118 (set-process-filter proc 'tramp-gw-process-filter)
119 (set-process-filter tramp-gw-gw-proc 'tramp-gw-process-filter)
120 ;; There might be already some output from the gateway process.
121 (with-current-buffer (process-buffer tramp-gw-gw-proc)
122 (unless (= (point-min) (point-max))
123 (let ((s (buffer-string)))
124 (delete-region (point) (point-max))
125 (tramp-gw-process-filter tramp-gw-gw-proc s))))))
126
127(defun tramp-gw-process-filter (proc string)
128 "Resend the string to the other process."
129 (let ((tramp-verbose 0))
130 ;; The other process might have been stopped already. We don't
131 ;; want to be interrupted then.
132 (ignore-errors
133 (process-send-string
134 (tramp-get-connection-property proc "process" nil) string))))
135
136;;;###tramp-autoload
137(defun tramp-gw-open-connection (vec gw-vec target-vec)
138 "Open a remote connection to VEC (see `tramp-file-name' structure).
139Take GW-VEC as SOCKS or HTTP gateway, i.e. its method must be a
140gateway method. TARGET-VEC identifies where to connect to via
141the gateway, it can be different from VEC when there are more
142hops to be applied.
143
144It returns a string like \"localhost#port\", which must be used
145instead of the host name declared in TARGET-VEC."
146
147 ;; Remember vectors for property retrieval.
148 (setq tramp-gw-vector vec
149 tramp-gw-gw-vector gw-vec)
150
151 ;; Start listening auxiliary process.
152 (unless (tramp-compat-process-live-p tramp-gw-aux-proc)
153 (let ((aux-vec
154 (vector "aux" (tramp-file-name-user gw-vec)
155 (tramp-file-name-host gw-vec) nil nil)))
156 (setq tramp-gw-aux-proc
157 (make-network-process
158 :name (tramp-buffer-name aux-vec) :buffer nil :host 'local
159 :server t :noquery t :service t :coding 'binary))
160 (set-process-sentinel tramp-gw-aux-proc 'tramp-gw-aux-proc-sentinel)
161 (set-process-query-on-exit-flag tramp-gw-aux-proc nil)
162 (tramp-message
163 vec 4 "Opening auxiliary process `%s', listening on port %d"
164 tramp-gw-aux-proc (process-contact tramp-gw-aux-proc :service))))
165
166 (let* ((gw-method
167 (intern
168 (tramp-find-method
169 (tramp-file-name-method gw-vec)
170 (tramp-file-name-user gw-vec)
171 (tramp-file-name-host gw-vec))))
172 (socks-username
173 (tramp-find-user
174 (tramp-file-name-method gw-vec)
175 (tramp-file-name-user gw-vec)
176 (tramp-file-name-host gw-vec)))
177 ;; Declare the SOCKS server to be used.
178 (socks-server
179 (list "Tramp temporary socks server list"
180 ;; Host name.
181 (tramp-file-name-real-host gw-vec)
182 ;; Port number.
183 (or (tramp-file-name-port gw-vec)
184 (case gw-method
185 (tunnel tramp-gw-default-tunnel-port)
186 (socks tramp-gw-default-socks-port)))
187 ;; Type. We support only http and socks5, NO socks4.
188 ;; 'http could be used when HTTP tunnel works in socks.el.
189 5))
190 ;; The function to be called.
191 (socks-function
192 (case gw-method
193 (tunnel 'tramp-gw-open-network-stream)
194 (socks 'socks-open-network-stream)))
195 socks-noproxy)
196
197 ;; Open SOCKS process.
198 (setq tramp-gw-gw-proc
199 (funcall
200 socks-function
201 (let ((tramp-verbose 0)) (tramp-get-connection-name gw-vec))
202 (let ((tramp-verbose 0)) (tramp-get-connection-buffer gw-vec))
203 (tramp-file-name-real-host target-vec)
204 (tramp-file-name-port target-vec)))
205 (set-process-sentinel tramp-gw-gw-proc 'tramp-gw-gw-proc-sentinel)
206 (set-process-coding-system tramp-gw-gw-proc 'binary 'binary)
207 (set-process-query-on-exit-flag tramp-gw-gw-proc nil)
208 (tramp-message
209 vec 4 "Opened %s process `%s'"
210 (case gw-method ('tunnel "HTTP tunnel") ('socks "SOCKS"))
211 tramp-gw-gw-proc)
212
213 ;; Return the new host for gateway access.
214 (format "localhost#%d" (process-contact tramp-gw-aux-proc :service))))
215
216(defun tramp-gw-open-network-stream (name buffer host service)
217 "Open stream to proxy server HOST:SERVICE.
218Resulting process has name NAME and buffer BUFFER. If
219authentication is requested from proxy server, provide it."
220 (let ((command (format (concat
221 "CONNECT %s:%d HTTP/1.1\r\n"
222 "Host: %s:%d\r\n"
223 "Connection: keep-alive\r\n"
224 "User-Agent: Tramp/%s\r\n")
225 host service host service tramp-version))
226 (authentication "")
227 (first t)
228 found proc)
229
230 (while (not found)
231 ;; Clean up.
232 (when (processp proc) (delete-process proc))
233 (with-current-buffer buffer (erase-buffer))
234 ;; Open network stream.
235 (setq proc (open-network-stream
236 name buffer (nth 1 socks-server) (nth 2 socks-server)))
237 (set-process-coding-system proc 'binary 'binary)
238 (set-process-query-on-exit-flag proc nil)
239 ;; Send CONNECT command.
240 (process-send-string proc (format "%s%s\r\n" command authentication))
241 (tramp-message
242 tramp-gw-vector 6 "\n%s"
243 (format
244 "%s%s\r\n" command
245 (replace-regexp-in-string ;; no password in trace!
246 "Basic [^\r\n]+" "Basic xxxxx" authentication t)))
247 (with-current-buffer buffer
248 ;; Trap errors to be traced in the right trace buffer. Often,
249 ;; proxies have a timeout of 60". We wait 65" in order to
250 ;; receive an answer this case.
251 (ignore-errors
252 (let ((tramp-verbose 0))
253 (tramp-wait-for-regexp proc 65 "\r?\n\r?\n")))
254 ;; Check return code.
255 (goto-char (point-min))
256 (narrow-to-region
257 (point-min)
258 (or (search-forward-regexp "\r?\n\r?\n" nil t) (point-max)))
259 (tramp-message tramp-gw-vector 6 "\n%s" (buffer-string))
260 (goto-char (point-min))
261 (search-forward-regexp "^HTTP/[1-9]\\.[0-9]" nil t)
262 (case (condition-case nil (read (current-buffer)) (error))
263 ;; Connected.
264 (200 (setq found t))
265 ;; We need basic authentication.
266 (401 (setq authentication (tramp-gw-basic-authentication nil first)))
267 ;; Access forbidden.
268 (403 (tramp-error-with-buffer
269 (current-buffer) tramp-gw-vector 'file-error
270 "Connection to %s:%d forbidden." host service))
271 ;; Target host not found.
272 (404 (tramp-error-with-buffer
273 (current-buffer) tramp-gw-vector 'file-error
274 "Host %s not found." host))
275 ;; We need basic proxy authentication.
276 (407 (setq authentication (tramp-gw-basic-authentication t first)))
277 ;; Connection failed.
278 (503 (tramp-error-with-buffer
279 (current-buffer) tramp-gw-vector 'file-error
280 "Connection to %s:%d failed." host service))
281 ;; That doesn't work at all.
282 (t (tramp-error-with-buffer
283 (current-buffer) tramp-gw-vector 'file-error
284 "Access to HTTP server %s:%d failed."
285 (nth 1 socks-server) (nth 2 socks-server))))
286 ;; Remove HTTP headers.
287 (delete-region (point-min) (point-max))
288 (widen)
289 (setq first nil)))
290 ;; Return the process.
291 proc))
292
293(defun tramp-gw-basic-authentication (proxy pw-cache)
294 "Return authentication header for CONNECT, based on server request.
295PROXY is an indication whether we need a Proxy-Authorization header
296or an Authorization header. If PW-CACHE is non-nil, check for
297password in password cache. This is done for the first try only."
298
299 ;; `tramp-current-*' must be set for `tramp-read-passwd'.
300 (let ((tramp-current-method (tramp-file-name-method tramp-gw-gw-vector))
301 (tramp-current-user (tramp-file-name-user tramp-gw-gw-vector))
302 (tramp-current-host (tramp-file-name-host tramp-gw-gw-vector)))
303 (unless pw-cache (tramp-clear-passwd tramp-gw-gw-vector))
304 ;; We are already in the right buffer.
305 (tramp-message
306 tramp-gw-vector 5 "%s required"
307 (if proxy "Proxy authentication" "Authentication"))
308 ;; Search for request header. We accept only basic authentication.
309 (goto-char (point-min))
310 (search-forward-regexp
311 "^\\(Proxy\\|WWW\\)-Authenticate:\\s-*Basic\\s-+realm=")
312 ;; Return authentication string.
313 (format
314 "%s: Basic %s\r\n"
315 (if proxy "Proxy-Authorization" "Authorization")
316 (base64-encode-string
317 (format
318 "%s:%s"
319 socks-username
320 (tramp-read-passwd
321 nil
322 (format
323 "Password for %s@[%s]: " socks-username (read (current-buffer)))))))))
324
325(add-hook 'tramp-unload-hook
326 (lambda ()
327 (unload-feature 'tramp-gw 'force)))
328
329(provide 'tramp-gw)
330
331;;; TODO:
332
333;; * Provide descriptive Commentary.
334;;
335;; * Enable it for several gateway processes in parallel.
336;;
337;; * Use `url-https-proxy-connect' as of Emacs 26.
338
339;;; tramp-gw.el ends here
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index fbf44b77a12..57cb6e11d21 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -32,8 +32,6 @@
32(eval-when-compile 32(eval-when-compile
33 (require 'cl) 33 (require 'cl)
34 (require 'dired)) 34 (require 'dired))
35(defvar tramp-gw-tunnel-method)
36(defvar tramp-gw-socks-method)
37(defvar vc-handled-backends) 35(defvar vc-handled-backends)
38(defvar vc-bzr-program) 36(defvar vc-bzr-program)
39(defvar vc-git-program) 37(defvar vc-git-program)
@@ -172,11 +170,7 @@ The string is used in `tramp-methods'.")
172 (tramp-copy-program "scp") 170 (tramp-copy-program "scp")
173 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") ("%c"))) 171 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") ("%c")))
174 (tramp-copy-keep-date t) 172 (tramp-copy-keep-date t)
175 (tramp-copy-recursive t) 173 (tramp-copy-recursive t)))
176 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
177 ("-o" "UserKnownHostsFile=/dev/null")
178 ("-o" "StrictHostKeyChecking=no")))
179 (tramp-default-port 22)))
180;;;###tramp-autoload 174;;;###tramp-autoload
181(add-to-list 'tramp-methods 175(add-to-list 'tramp-methods
182 '("scpx" 176 '("scpx"
@@ -191,11 +185,7 @@ The string is used in `tramp-methods'.")
191 (tramp-copy-args (("-P" "%p") ("-p" "%k") 185 (tramp-copy-args (("-P" "%p") ("-p" "%k")
192 ("-q") ("-r") ("%c"))) 186 ("-q") ("-r") ("%c")))
193 (tramp-copy-keep-date t) 187 (tramp-copy-keep-date t)
194 (tramp-copy-recursive t) 188 (tramp-copy-recursive t)))
195 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
196 ("-o" "UserKnownHostsFile=/dev/null")
197 ("-o" "StrictHostKeyChecking=no")))
198 (tramp-default-port 22)))
199;;;###tramp-autoload 189;;;###tramp-autoload
200(add-to-list 'tramp-methods 190(add-to-list 'tramp-methods
201 '("rsync" 191 '("rsync"
@@ -237,11 +227,7 @@ The string is used in `tramp-methods'.")
237 (tramp-async-args (("-q"))) 227 (tramp-async-args (("-q")))
238 (tramp-remote-shell "/bin/sh") 228 (tramp-remote-shell "/bin/sh")
239 (tramp-remote-shell-login ("-l")) 229 (tramp-remote-shell-login ("-l"))
240 (tramp-remote-shell-args ("-c")) 230 (tramp-remote-shell-args ("-c"))))
241 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
242 ("-o" "UserKnownHostsFile=/dev/null")
243 ("-o" "StrictHostKeyChecking=no")))
244 (tramp-default-port 22)))
245;;;###tramp-autoload 231;;;###tramp-autoload
246(add-to-list 'tramp-methods 232(add-to-list 'tramp-methods
247 '("sshx" 233 '("sshx"
@@ -251,11 +237,7 @@ The string is used in `tramp-methods'.")
251 (tramp-async-args (("-q"))) 237 (tramp-async-args (("-q")))
252 (tramp-remote-shell "/bin/sh") 238 (tramp-remote-shell "/bin/sh")
253 (tramp-remote-shell-login ("-l")) 239 (tramp-remote-shell-login ("-l"))
254 (tramp-remote-shell-args ("-c")) 240 (tramp-remote-shell-args ("-c"))))
255 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
256 ("-o" "UserKnownHostsFile=/dev/null")
257 ("-o" "StrictHostKeyChecking=no")))
258 (tramp-default-port 22)))
259;;;###tramp-autoload 241;;;###tramp-autoload
260(add-to-list 'tramp-methods 242(add-to-list 'tramp-methods
261 '("telnet" 243 '("telnet"
@@ -263,8 +245,7 @@ The string is used in `tramp-methods'.")
263 (tramp-login-args (("%h") ("%p") ("2>/dev/null"))) 245 (tramp-login-args (("%h") ("%p") ("2>/dev/null")))
264 (tramp-remote-shell "/bin/sh") 246 (tramp-remote-shell "/bin/sh")
265 (tramp-remote-shell-login ("-l")) 247 (tramp-remote-shell-login ("-l"))
266 (tramp-remote-shell-args ("-c")) 248 (tramp-remote-shell-args ("-c"))))
267 (tramp-default-port 23)))
268;;;###tramp-autoload 249;;;###tramp-autoload
269(add-to-list 'tramp-methods 250(add-to-list 'tramp-methods
270 '("nc" 251 '("nc"
@@ -280,8 +261,7 @@ The string is used in `tramp-methods'.")
280 ;; We use "-p" as required for newer busyboxes. For older 261 ;; We use "-p" as required for newer busyboxes. For older
281 ;; busybox/nc versions, the value must be (("-l") ("%r")). This 262 ;; busybox/nc versions, the value must be (("-l") ("%r")). This
282 ;; can be achieved by tweaking `tramp-connection-properties'. 263 ;; can be achieved by tweaking `tramp-connection-properties'.
283 (tramp-remote-copy-args (("-l") ("-p" "%r") ("2>/dev/null"))) 264 (tramp-remote-copy-args (("-l") ("-p" "%r") ("2>/dev/null")))))
284 (tramp-default-port 23)))
285;;;###tramp-autoload 265;;;###tramp-autoload
286(add-to-list 'tramp-methods 266(add-to-list 'tramp-methods
287 '("su" 267 '("su"
@@ -353,8 +333,7 @@ The string is used in `tramp-methods'.")
353 ("/bin/sh") ("\""))) 333 ("/bin/sh") ("\"")))
354 (tramp-remote-shell "/bin/sh") 334 (tramp-remote-shell "/bin/sh")
355 (tramp-remote-shell-login ("-l")) 335 (tramp-remote-shell-login ("-l"))
356 (tramp-remote-shell-args ("-c")) 336 (tramp-remote-shell-args ("-c"))))
357 (tramp-default-port 22)))
358;;;###tramp-autoload 337;;;###tramp-autoload
359(add-to-list 'tramp-methods 338(add-to-list 'tramp-methods
360 `("plinkx" 339 `("plinkx"
@@ -386,8 +365,7 @@ The string is used in `tramp-methods'.")
386 (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k") 365 (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k")
387 ("-q") ("-r"))) 366 ("-q") ("-r")))
388 (tramp-copy-keep-date t) 367 (tramp-copy-keep-date t)
389 (tramp-copy-recursive t) 368 (tramp-copy-recursive t)))
390 (tramp-default-port 22)))
391;;;###tramp-autoload 369;;;###tramp-autoload
392(add-to-list 'tramp-methods 370(add-to-list 'tramp-methods
393 `("psftp" 371 `("psftp"
@@ -2395,10 +2373,6 @@ The method used must be an out-of-band method."
2395 v "login-as" nil)) 2373 v "login-as" nil))
2396 tramp-current-host (tramp-file-name-real-host v)) 2374 tramp-current-host (tramp-file-name-real-host v))
2397 2375
2398 ;; Expand hops. Might be necessary for gateway methods.
2399 (setq v (car (tramp-compute-multi-hops v)))
2400 (aset v 3 localname)
2401
2402 ;; Check which ones of source and target are Tramp files. 2376 ;; Check which ones of source and target are Tramp files.
2403 (setq source (funcall 2377 (setq source (funcall
2404 (if (and (file-directory-p filename) 2378 (if (and (file-directory-p filename)
@@ -2412,15 +2386,9 @@ The method used must be an out-of-band method."
2412 (tramp-make-copy-program-file-name v) 2386 (tramp-make-copy-program-file-name v)
2413 (tramp-unquote-shell-quote-argument newname))) 2387 (tramp-unquote-shell-quote-argument newname)))
2414 2388
2415 ;; Check for host and port number. We cannot use 2389 ;; Check for host and port number.
2416 ;; `tramp-file-name-port', because this returns also 2390 (setq host (tramp-file-name-real-host v)
2417 ;; `tramp-default-port', which might clash with settings in 2391 port (tramp-file-name-port v))
2418 ;; "~/.ssh/config".
2419 (setq host (tramp-file-name-host v)
2420 port "")
2421 (when (string-match tramp-host-with-port-regexp host)
2422 (setq port (string-to-number (match-string 2 host))
2423 host (string-to-number (match-string 1 host))))
2424 2392
2425 ;; Check for user. There might be an interactive setting. 2393 ;; Check for user. There might be an interactive setting.
2426 (setq user (or (tramp-file-name-user v) 2394 (setq user (or (tramp-file-name-user v)
@@ -4504,8 +4472,7 @@ Goes through the list `tramp-inline-compress-commands'."
4504 vec 2 "Couldn't find an inline transfer compress command"))))) 4472 vec 2 "Couldn't find an inline transfer compress command")))))
4505 4473
4506(defun tramp-compute-multi-hops (vec) 4474(defun tramp-compute-multi-hops (vec)
4507 "Expands VEC according to `tramp-default-proxies-alist'. 4475 "Expands VEC according to `tramp-default-proxies-alist'."
4508Gateway hops are already opened."
4509 (let ((target-alist `(,vec)) 4476 (let ((target-alist `(,vec))
4510 (hops (or (tramp-file-name-hop vec) "")) 4477 (hops (or (tramp-file-name-hop vec) ""))
4511 (item vec) 4478 (item vec)
@@ -4562,32 +4529,6 @@ Gateway hops are already opened."
4562 ;; Start next search. 4529 ;; Start next search.
4563 (setq choices tramp-default-proxies-alist))))) 4530 (setq choices tramp-default-proxies-alist)))))
4564 4531
4565 ;; Handle gateways.
4566 (when (and (boundp 'tramp-gw-tunnel-method) (boundp 'tramp-gw-socks-method)
4567 (string-match
4568 (format
4569 "^\\(%s\\|%s\\)$" tramp-gw-tunnel-method tramp-gw-socks-method)
4570 (tramp-file-name-method (car target-alist))))
4571 (let ((gw (pop target-alist))
4572 (hop (pop target-alist)))
4573 ;; Is the method prepared for gateways?
4574 (unless (tramp-file-name-port hop)
4575 (tramp-error
4576 vec 'file-error
4577 "Connection `%s' is not supported for gateway access." hop))
4578 ;; Open the gateway connection.
4579 (push
4580 (vector
4581 (tramp-file-name-method hop) (tramp-file-name-user hop)
4582 (tramp-gw-open-connection vec gw hop) nil nil)
4583 target-alist)
4584 ;; For the password prompt, we need the correct values.
4585 ;; Therefore, we must remember the gateway vector. But we
4586 ;; cannot do it as connection property, because it shouldn't
4587 ;; be persistent. And we have no started process yet either.
4588 (let ((tramp-verbose 0))
4589 (tramp-set-file-property (car target-alist) "" "gateway" hop))))
4590
4591 ;; Foreign and out-of-band methods are not supported for multi-hops. 4532 ;; Foreign and out-of-band methods are not supported for multi-hops.
4592 (when (cdr target-alist) 4533 (when (cdr target-alist)
4593 (setq choices target-alist) 4534 (setq choices target-alist)
@@ -4802,13 +4743,6 @@ connection if a previous connection has died for some reason."
4802 (connection-timeout 4743 (connection-timeout
4803 (tramp-get-method-parameter 4744 (tramp-get-method-parameter
4804 hop 'tramp-connection-timeout)) 4745 hop 'tramp-connection-timeout))
4805 (gw-args
4806 (tramp-get-method-parameter hop 'tramp-gw-args))
4807 (gw (let ((tramp-verbose 0))
4808 (tramp-get-file-property hop "" "gateway" nil)))
4809 (g-method (and gw (tramp-file-name-method gw)))
4810 (g-user (and gw (tramp-file-name-user gw)))
4811 (g-host (and gw (tramp-file-name-real-host gw)))
4812 (command login-program) 4746 (command login-program)
4813 ;; We don't create the temporary file. In 4747 ;; We don't create the temporary file. In
4814 ;; fact, it is just a prefix for the 4748 ;; fact, it is just a prefix for the
@@ -4832,12 +4766,6 @@ connection if a previous connection has died for some reason."
4832 (when (and process-name async-args) 4766 (when (and process-name async-args)
4833 (setq login-args (append async-args login-args))) 4767 (setq login-args (append async-args login-args)))
4834 4768
4835 ;; Add gateway arguments if necessary.
4836 (when gw
4837 (tramp-set-connection-property p "gateway" t)
4838 (when gw-args
4839 (setq login-args (append gw-args login-args))))
4840
4841 ;; Check for port number. Until now, there's no 4769 ;; Check for port number. Until now, there's no
4842 ;; need for handling like method, user, host. 4770 ;; need for handling like method, user, host.
4843 (when (string-match tramp-host-with-port-regexp l-host) 4771 (when (string-match tramp-host-with-port-regexp l-host)
@@ -4850,11 +4778,10 @@ connection if a previous connection has died for some reason."
4850 (setq r-shell t))) 4778 (setq r-shell t)))
4851 4779
4852 ;; Set variables for computing the prompt for 4780 ;; Set variables for computing the prompt for
4853 ;; reading password. They can also be derived 4781 ;; reading password.
4854 ;; from a gateway. 4782 (setq tramp-current-method l-method
4855 (setq tramp-current-method (or g-method l-method) 4783 tramp-current-user l-user
4856 tramp-current-user (or g-user l-user) 4784 tramp-current-host l-host)
4857 tramp-current-host (or g-host l-host))
4858 4785
4859 ;; Add login environment. 4786 ;; Add login environment.
4860 (when login-env 4787 (when login-env
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index da745524a14..4103a6e76a8 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -241,12 +241,7 @@ pair of the form (KEY VALUE). The following KEYs are defined:
241 * `tramp-copy-recursive' 241 * `tramp-copy-recursive'
242 Whether the operation copies directories recursively. 242 Whether the operation copies directories recursively.
243 * `tramp-default-port' 243 * `tramp-default-port'
244 The default port of a method is needed in case of gateway connections. 244 The default port of a method.
245 Additionally, it is used as indication which method is prepared for
246 passing gateways.
247 * `tramp-gw-args'
248 As the attribute name says, additional arguments are specified here
249 when a method is applied via a gateway.
250 * `tramp-tmpdir' 245 * `tramp-tmpdir'
251 A directory on the remote host for temporary files. If not 246 A directory on the remote host for temporary files. If not
252 specified, \"/tmp\" is taken as default. 247 specified, \"/tmp\" is taken as default.
@@ -277,8 +272,7 @@ See the variables `tramp-local-coding-commands' and
277 272
278So, to summarize: if the method is an out-of-band method, then you 273So, to summarize: if the method is an out-of-band method, then you
279must specify `tramp-copy-program' and `tramp-copy-args'. If it is an 274must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
280inline method, then these two parameters should be nil. Methods which 275inline method, then these two parameters should be nil.
281are fit for gateways must have `tramp-default-port' at least.
282 276
283Notes: 277Notes:
284 278
@@ -1139,8 +1133,7 @@ entry does not exist, return nil."
1139(defun tramp-file-name-port (vec) 1133(defun tramp-file-name-port (vec)
1140 "Return the port number of VEC." 1134 "Return the port number of VEC."
1141 (save-match-data 1135 (save-match-data
1142 (let ((method (tramp-file-name-method vec)) 1136 (let ((host (tramp-file-name-host vec)))
1143 (host (tramp-file-name-host vec)))
1144 (or (and (stringp host) 1137 (or (and (stringp host)
1145 (string-match tramp-host-with-port-regexp host) 1138 (string-match tramp-host-with-port-regexp host)
1146 (string-to-number (match-string 2 host))) 1139 (string-to-number (match-string 2 host)))
@@ -1267,9 +1260,6 @@ values."
1267 1260
1268(defun tramp-buffer-name (vec) 1261(defun tramp-buffer-name (vec)
1269 "A name for the connection buffer VEC." 1262 "A name for the connection buffer VEC."
1270 ;; We must use `tramp-file-name-real-host', because for gateway
1271 ;; methods the default port will be expanded later on, which would
1272 ;; tamper the name.
1273 (let ((method (tramp-file-name-method vec)) 1263 (let ((method (tramp-file-name-method vec))
1274 (user (tramp-file-name-user vec)) 1264 (user (tramp-file-name-user vec))
1275 (host (tramp-file-name-real-host vec))) 1265 (host (tramp-file-name-real-host vec)))
@@ -1359,9 +1349,6 @@ version, the function does nothing."
1359 1349
1360(defun tramp-debug-buffer-name (vec) 1350(defun tramp-debug-buffer-name (vec)
1361 "A name for the debug buffer for VEC." 1351 "A name for the debug buffer for VEC."
1362 ;; We must use `tramp-file-name-real-host', because for gateway
1363 ;; methods the default port will be expanded later on, which would
1364 ;; tamper the name.
1365 (let ((method (tramp-file-name-method vec)) 1352 (let ((method (tramp-file-name-method vec))
1366 (user (tramp-file-name-user vec)) 1353 (user (tramp-file-name-user vec))
1367 (host (tramp-file-name-real-host vec))) 1354 (host (tramp-file-name-real-host vec)))
@@ -3632,17 +3619,13 @@ connection buffer."
3632This is needed in order to hide `last-coding-system-used', which is set 3619This is needed in order to hide `last-coding-system-used', which is set
3633for process communication also." 3620for process communication also."
3634 (with-current-buffer (process-buffer proc) 3621 (with-current-buffer (process-buffer proc)
3635 ;; FIXME: If there is a gateway process, we need communication 3622 (let (buffer-read-only last-coding-system-used)
3636 ;; between several processes. Too complicate to implement, so we
3637 ;; read output from all processes.
3638 (let ((p (if (tramp-get-connection-property proc "gateway" nil) nil proc))
3639 buffer-read-only last-coding-system-used)
3640 ;; Under Windows XP, accept-process-output doesn't return 3623 ;; Under Windows XP, accept-process-output doesn't return
3641 ;; sometimes. So we add an additional timeout. 3624 ;; sometimes. So we add an additional timeout.
3642 (with-timeout ((or timeout 1)) 3625 (with-timeout ((or timeout 1))
3643 (accept-process-output p timeout timeout-msecs (and proc t))) 3626 (accept-process-output proc timeout timeout-msecs (and proc t)))
3644 (tramp-message proc 10 "%s %s %s\n%s" 3627 (tramp-message proc 10 "%s %s\n%s"
3645 proc (process-status proc) p (buffer-string))))) 3628 proc (process-status proc) (buffer-string)))))
3646 3629
3647(defun tramp-check-for-regexp (proc regexp) 3630(defun tramp-check-for-regexp (proc regexp)
3648 "Check, whether REGEXP is contained in process buffer of PROC. 3631 "Check, whether REGEXP is contained in process buffer of PROC.
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index ee8a95e7bd5..2884187fa0a 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -583,10 +583,6 @@ handled properly. BODY shall not contain a timeout."
583 (when (and (load "tramp-gvfs" 'noerror 'nomessage) 583 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
584 (symbol-value 'tramp-gvfs-enabled)) 584 (symbol-value 'tramp-gvfs-enabled))
585 (should (string-equal (file-remote-p "/synce::" 'user) nil))) 585 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
586 ;; Default values in tramp-gw.el.
587 (dolist (m '("tunnel" "socks"))
588 (should
589 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
590 ;; Default values in tramp-sh.el. 586 ;; Default values in tramp-sh.el.
591 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name))) 587 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
592 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su"))) 588 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))