diff options
author | delano <delano@delanotes.com> | 2014-02-01 11:15:46 -0500 |
---|---|---|
committer | delano <delano@delanotes.com> | 2014-02-01 11:15:46 -0500 |
commit | cd7b650349bd8ed8abb69880b286d910f6563cc4 (patch) | |
tree | 547c206bc3ac89a588c28fd7d79a6a51acb481aa | |
parent | 60d3da31d2f6ce1167f1bd4564000789da8d7859 (diff) | |
parent | b84becc741e233fb4182e02b2ef3f194bc29174c (diff) | |
download | net-ssh-yugui-feature/follow-proxy-command-spec-r.tar.gz |
Merge branch 'feature/follow-proxy-command-spec-r' of github.com:yugui/net-ssh into yugui-feature/follow-proxy-command-spec-ryugui-feature/follow-proxy-command-spec-r
-rw-r--r-- | lib/net/ssh/proxy/command.rb | 9 | ||||
-rw-r--r-- | lib/net/ssh/proxy/http.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/proxy/socks4.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/proxy/socks5.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/transport/session.rb | 8 |
5 files changed, 18 insertions, 5 deletions
diff --git a/lib/net/ssh/proxy/command.rb b/lib/net/ssh/proxy/command.rb index 2e6098e..e7b2739 100644 --- a/lib/net/ssh/proxy/command.rb +++ b/lib/net/ssh/proxy/command.rb @@ -33,13 +33,20 @@ module Net; module SSH; module Proxy # Return a new socket connected to the given host and port via the # proxy that was requested when the socket factory was instantiated. - def open(host, port) + def open(host, port, connection_options = nil) command_line = @command_line_template.gsub(/%(.)/) { case $1 when 'h' host when 'p' port.to_s + when 'r' + remote_user = connection_options && connection_options[:remote_user] + if remote_user + remote_user + else + raise ArgumentError, "remote user name not available" + end when '%' '%' else diff --git a/lib/net/ssh/proxy/http.rb b/lib/net/ssh/proxy/http.rb index 0d183be..e08d5d2 100644 --- a/lib/net/ssh/proxy/http.rb +++ b/lib/net/ssh/proxy/http.rb @@ -48,7 +48,7 @@ module Net; module SSH; module Proxy # Return a new socket connected to the given host and port via the # proxy that was requested when the socket factory was instantiated. - def open(host, port) + def open(host, port, connection_options = nil) socket = TCPSocket.new(proxy_host, proxy_port) socket.write "CONNECT #{host}:#{port} HTTP/1.0\r\n" diff --git a/lib/net/ssh/proxy/socks4.rb b/lib/net/ssh/proxy/socks4.rb index fdb1e32..8330d96 100644 --- a/lib/net/ssh/proxy/socks4.rb +++ b/lib/net/ssh/proxy/socks4.rb @@ -47,7 +47,7 @@ module Net # Return a new socket connected to the given host and port via the # proxy that was requested when the socket factory was instantiated. - def open(host, port) + def open(host, port, connection_options) socket = TCPSocket.new(proxy_host, proxy_port) ip_addr = IPAddr.new(Resolv.getaddress(host)) diff --git a/lib/net/ssh/proxy/socks5.rb b/lib/net/ssh/proxy/socks5.rb index 06b2d49..96f8637 100644 --- a/lib/net/ssh/proxy/socks5.rb +++ b/lib/net/ssh/proxy/socks5.rb @@ -62,7 +62,7 @@ module Net # Return a new socket connected to the given host and port via the # proxy that was requested when the socket factory was instantiated. - def open(host, port) + def open(host, port, connection_options = nil) socket = TCPSocket.new(proxy_host, proxy_port) methods = [METHOD_NO_AUTH] diff --git a/lib/net/ssh/transport/session.rb b/lib/net/ssh/transport/session.rb index 2ec13dc..05253c9 100644 --- a/lib/net/ssh/transport/session.rb +++ b/lib/net/ssh/transport/session.rb @@ -64,7 +64,13 @@ module Net; module SSH; module Transport debug { "establishing connection to #{@host}:#{@port}" } factory = options[:proxy] || TCPSocket - @socket = timeout(options[:timeout] || 0) { @bind_address.nil? || options[:proxy] ? factory.open(@host, @port) : factory.open(@host,@port,@bind_address) } + @socket = timeout(options[:timeout] || 0) { + case + when options[:proxy] then factory.open(@host, @port, options) + when @bind_address.nil? then factory.open(@host, @port) + else factory.open(@host, @port, @bind_address) + end + } @socket.extend(PacketStream) @socket.logger = @logger |