net-ssh 2.1.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,8 @@
1
1
 
2
+ === 2.2.0 / 16 Aug 2011
3
+
4
+ * Add support for forward a local UNIX domain socket to a remote TCP socket. [Mark Imbriaco]
5
+
2
6
  === 2.1.4 / 3 Apr 2011
3
7
 
4
8
  * Add ConnectionTimeout exception class. [Joel Watson]
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ include FileUtils
7
7
  begin
8
8
  require 'hanna/rdoctask'
9
9
  rescue LoadError
10
- require 'rake/rdoctask'
10
+ require 'rdoc/task'
11
11
  end
12
12
 
13
13
 
@@ -61,10 +61,10 @@ module Net
61
61
  # This is the set of options that Net::SSH.start recognizes. See
62
62
  # Net::SSH.start for a description of each option.
63
63
  VALID_OPTIONS = [
64
- :auth_methods, :compression, :compression_level, :config, :encryption,
65
- :forward_agent, :hmac, :host_key, :kex, :keys, :key_data, :languages,
66
- :logger, :paranoid, :password, :port, :proxy, :rekey_blocks_limit,
67
- :rekey_limit, :rekey_packet_limit, :timeout, :verbose,
64
+ :auth_methods, :bind_address, :compression, :compression_level, :config,
65
+ :encryption, :forward_agent, :hmac, :host_key, :kex, :keys, :key_data,
66
+ :languages, :logger, :paranoid, :password, :port, :proxy,
67
+ :rekey_blocks_limit,:rekey_limit, :rekey_packet_limit, :timeout, :verbose,
68
68
  :global_known_hosts_file, :user_known_hosts_file, :host_key_alias,
69
69
  :host_name, :user, :properties, :passphrase, :keys_only
70
70
  ]
@@ -98,6 +98,9 @@ module Net
98
98
  # This method accepts the following options (all are optional):
99
99
  #
100
100
  # * :auth_methods => an array of authentication methods to try
101
+ # * :bind_address => the IP address on the connecting machine to use in
102
+ # establishing connection. (:bind_address is discarded if :proxy
103
+ # is set.)
101
104
  # * :compression => the compression algorithm to use, or +true+ to use
102
105
  # whatever is supported.
103
106
  # * :compression_level => the compression level to use when sending data
@@ -119,6 +119,8 @@ module Net; module SSH
119
119
  def translate(settings)
120
120
  settings.inject({}) do |hash, (key, value)|
121
121
  case key
122
+ when 'bindaddress' then
123
+ hash[:bind_address] = value
122
124
  when 'ciphers' then
123
125
  hash[:encryption] = value.split(/,/)
124
126
  when 'compression' then
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'net/ssh/loggable'
2
3
 
3
4
  module Net; module SSH; module Service
@@ -53,22 +54,31 @@ module Net; module SSH; module Service
53
54
  raise ArgumentError, "expected 3 or 4 parameters, got #{args.length}"
54
55
  end
55
56
 
56
- bind_address = "127.0.0.1"
57
- bind_address = args.shift if args.first.is_a?(String) && args.first =~ /\D/
57
+ local_port_type = :long
58
+
59
+ socket = begin
60
+ if args.first.class == UNIXServer
61
+ local_port_type = :string
62
+ args.shift
63
+ else
64
+ bind_address = "127.0.0.1"
65
+ bind_address = args.shift if args.first.is_a?(String) && args.first =~ /\D/
66
+ local_port = args.shift.to_i
67
+ local_port_type = :long
68
+ TCPServer.new(bind_address, local_port)
69
+ end
70
+ end
58
71
 
59
- local_port = args.shift.to_i
60
72
  remote_host = args.shift
61
73
  remote_port = args.shift.to_i
62
74
 
63
- socket = TCPServer.new(bind_address, local_port)
64
-
65
75
  @local_forwarded_ports[[local_port, bind_address]] = socket
66
76
 
67
77
  session.listen_to(socket) do |server|
68
78
  client = server.accept
69
- debug { "received connection on #{bind_address}:#{local_port}" }
79
+ debug { "received connection on #{socket}" }
70
80
 
71
- channel = session.open_channel("direct-tcpip", :string, remote_host, :long, remote_port, :string, bind_address, :long, local_port) do |achannel|
81
+ channel = session.open_channel("direct-tcpip", :string, remote_host, :long, remote_port, :string, bind_address, local_port_type, local_port) do |achannel|
72
82
  achannel.info { "direct channel established" }
73
83
  end
74
84
 
@@ -285,4 +295,4 @@ module Net; module SSH; module Service
285
295
  end
286
296
  end
287
297
 
288
- end; end; end
298
+ end; end; end
@@ -58,11 +58,12 @@ module Net; module SSH; module Transport
58
58
 
59
59
  @host = host
60
60
  @port = options[:port] || DEFAULT_PORT
61
+ @bind_address = options[:bind_address] || nil
61
62
  @options = options
62
63
 
63
64
  debug { "establishing connection to #{@host}:#{@port}" }
64
65
  factory = options[:proxy] || TCPSocket
65
- @socket = timeout(options[:timeout] || 0) { factory.open(@host, @port) }
66
+ @socket = timeout(options[:timeout] || 0) { @bind_address.nil? || options[:proxy] ? factory.open(@host, @port) : factory.open(@host,@port,@bind_address) }
66
67
  @socket.extend(PacketStream)
67
68
  @socket.logger = @logger
68
69
 
@@ -48,10 +48,10 @@ module Net; module SSH
48
48
  MAJOR = 2
49
49
 
50
50
  # The minor component of this version of the Net::SSH library
51
- MINOR = 1
51
+ MINOR = 2
52
52
 
53
53
  # The tiny component of this version of the Net::SSH library
54
- TINY = 4
54
+ TINY = 0
55
55
 
56
56
  # The current version of the Net::SSH library as a Version instance
57
57
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "net-ssh"
3
3
  s.rubyforge_project = 'net-ssh'
4
- s.version = "2.1.4"
4
+ s.version = "2.2.0"
5
5
  s.summary = "Net::SSH: a pure-Ruby implementation of the SSH2 client protocol."
6
6
  s.description = s.summary
7
7
  s.authors = ["Jamis Buck", "Delano Mandelbaum"]
@@ -18,6 +18,7 @@ require 'common'
18
18
  require 'net/ssh/buffer'
19
19
  require 'net/ssh'
20
20
  require 'timeout'
21
+ require 'tempfile'
21
22
 
22
23
  class TestForward < Test::Unit::TestCase
23
24
 
@@ -120,7 +121,44 @@ class TestForward < Test::Unit::TestCase
120
121
  session.loop(0.1) { client_done.empty? }
121
122
  assert_equal "Broken pipe", "#{server_exc.pop}" unless server_exc.empty?
122
123
  end
124
+
125
+ def create_local_socket(&blk)
126
+ tempfile = Tempfile.new("net_ssh_forward_test")
127
+ path = tempfile.path
128
+ tempfile.delete
129
+ yield UNIXServer.open(path)
130
+ File.delete(path)
131
+ end
123
132
 
133
+ def test_forward_local_unix_socket_to_remote_port
134
+ session = Net::SSH.start(*ssh_start_params)
135
+ server_exc = Queue.new
136
+ server = start_server_sending_lot_of_data(server_exc)
137
+ remote_port = server.addr[1]
138
+ client_data = nil
139
+
140
+ create_local_socket do |local_socket|
141
+ session.forward.local(local_socket, localhost, remote_port)
142
+ client_done = Queue.new
143
+
144
+ Thread.start do
145
+ begin
146
+ client = UNIXSocket.new(local_socket.path)
147
+ client_data = client.recv(1024)
148
+ client.close
149
+ sleep(0.2)
150
+ ensure
151
+ client_done << true
152
+ end
153
+ end
154
+
155
+ session.loop(0.1) { client_done.empty? }
156
+ end
157
+
158
+ assert_not_nil(client_data, "client should have received data")
159
+ assert(client_data.match(/item\d/), 'client should have received the string item')
160
+ end
161
+
124
162
  def test_loop_should_not_abort_when_server_side_of_forward_is_closed
125
163
  session = Net::SSH.start(*ssh_start_params)
126
164
  server = start_server_closing_soon
@@ -182,4 +220,4 @@ class TestForward < Test::Unit::TestCase
182
220
  assert_equal "This is a small message!", client_done.pop
183
221
  end
184
222
  end
185
- end
223
+ end
@@ -67,6 +67,7 @@ class TestConfig < Test::Unit::TestCase
67
67
 
68
68
  def test_translate_should_correctly_translate_from_openssh_to_net_ssh_names
69
69
  open_ssh = {
70
+ 'bindaddress' => "127.0.0.1",
70
71
  'ciphers' => "a,b,c",
71
72
  'compression' => true,
72
73
  'compressionlevel' => 6,
@@ -95,6 +96,7 @@ class TestConfig < Test::Unit::TestCase
95
96
  assert_equal %w(j k l), net_ssh[:hmac]
96
97
  assert_equal 1234, net_ssh[:port]
97
98
  assert_equal 1024, net_ssh[:rekey_limit]
99
+ assert_equal "127.0.0.1", net_ssh[:bind_address]
98
100
  end
99
101
 
100
102
  def test_load_with_plus_sign_hosts
@@ -114,4 +116,4 @@ class TestConfig < Test::Unit::TestCase
114
116
  def config(name)
115
117
  "test/configs/#{name}"
116
118
  end
117
- end
119
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: net-ssh
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.4
5
+ version: 2.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamis Buck
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-03 00:00:00 -04:00
14
+ date: 2011-08-17 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies: []
17
17