hrr_rb_ssh 0.4.0.pre1 → 0.4.0.pre2
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.
- checksums.yaml +4 -4
- data/README.md +16 -8
- data/demo/client.rb +1 -3
- data/demo/echo_server.rb +1 -3
- data/demo/more_flexible_auth.rb +1 -3
- data/demo/multi_step_auth.rb +1 -3
- data/demo/server.rb +1 -3
- data/demo/subsystem_echo_server.rb +1 -3
- data/hrr_rb_ssh.gemspec +1 -1
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2.rb +12 -9
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss.rb +10 -7
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa.rb +9 -6
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/context.rb +9 -8
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb +6 -5
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_response.rb +5 -2
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive.rb +12 -10
- data/lib/hrr_rb_ssh/authentication/method/none/context.rb +7 -6
- data/lib/hrr_rb_ssh/authentication/method/none.rb +10 -8
- data/lib/hrr_rb_ssh/authentication/method/password/context.rb +7 -6
- data/lib/hrr_rb_ssh/authentication/method/password.rb +10 -8
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/functionable.rb +13 -11
- data/lib/hrr_rb_ssh/authentication/method/publickey/context.rb +5 -2
- data/lib/hrr_rb_ssh/authentication/method/publickey.rb +16 -14
- data/lib/hrr_rb_ssh/authentication.rb +28 -27
- data/lib/hrr_rb_ssh/client.rb +58 -56
- data/lib/hrr_rb_ssh/codable.rb +20 -10
- data/lib/hrr_rb_ssh/connection/channel/channel_type/direct_tcpip.rb +20 -18
- data/lib/hrr_rb_ssh/connection/channel/channel_type/forwarded_tcpip.rb +20 -18
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain/chain_context.rb +0 -3
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain.rb +0 -2
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb +2 -5
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +2 -5
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +2 -5
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +2 -5
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +2 -5
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change.rb +2 -5
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +14 -12
- data/lib/hrr_rb_ssh/connection/channel.rb +73 -71
- data/lib/hrr_rb_ssh/connection/global_request_handler.rb +14 -12
- data/lib/hrr_rb_ssh/connection/request_handler/reference_env_request_handler.rb +0 -2
- data/lib/hrr_rb_ssh/connection/request_handler/reference_exec_request_handler.rb +4 -6
- data/lib/hrr_rb_ssh/connection/request_handler/reference_pty_req_request_handler.rb +10 -12
- data/lib/hrr_rb_ssh/connection/request_handler/reference_shell_request_handler.rb +4 -6
- data/lib/hrr_rb_ssh/connection/request_handler/reference_window_change_request_handler.rb +0 -2
- data/lib/hrr_rb_ssh/connection/request_handler.rb +1 -3
- data/lib/hrr_rb_ssh/connection.rb +53 -53
- data/lib/hrr_rb_ssh/loggable.rb +42 -0
- data/lib/hrr_rb_ssh/server.rb +11 -9
- data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +9 -8
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange.rb +13 -12
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman.rb +9 -8
- data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport/receiver.rb +8 -7
- data/lib/hrr_rb_ssh/transport/sender.rb +5 -3
- data/lib/hrr_rb_ssh/transport/sequence_number.rb +0 -4
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/functionable.rb +5 -3
- data/lib/hrr_rb_ssh/transport.rb +41 -40
- data/lib/hrr_rb_ssh/version.rb +1 -1
- data/lib/hrr_rb_ssh.rb +0 -1
- metadata +6 -6
- data/lib/hrr_rb_ssh/logger.rb +0 -56
@@ -1,17 +1,19 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_ssh/
|
4
|
+
require 'hrr_rb_ssh/loggable'
|
5
5
|
|
6
6
|
module HrrRbSsh
|
7
7
|
class Connection
|
8
8
|
class Channel
|
9
9
|
class ChannelType
|
10
10
|
class Session < ChannelType
|
11
|
+
include Loggable
|
12
|
+
|
11
13
|
NAME = 'session'
|
12
14
|
|
13
|
-
def initialize connection, channel, message, socket=nil
|
14
|
-
|
15
|
+
def initialize connection, channel, message, socket=nil, logger: nil
|
16
|
+
self.logger = logger
|
15
17
|
@connection = connection
|
16
18
|
@channel = channel
|
17
19
|
@proc_chain = ProcChain.new
|
@@ -32,27 +34,27 @@ module HrrRbSsh
|
|
32
34
|
|
33
35
|
def request message
|
34
36
|
request_type = message[:'request type']
|
35
|
-
RequestType[request_type].run @proc_chain, @connection.username, @channel.io, @connection.variables, message, @connection.options, self
|
37
|
+
RequestType[request_type].run @proc_chain, @connection.username, @channel.io, @connection.variables, message, @connection.options, self, logger: logger
|
36
38
|
end
|
37
39
|
|
38
40
|
def proc_chain_thread
|
39
41
|
Thread.start {
|
40
|
-
|
42
|
+
log_info { "start proc chain thread" }
|
41
43
|
begin
|
42
44
|
exitstatus = @proc_chain.call_next
|
43
45
|
rescue => e
|
44
|
-
|
46
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
45
47
|
exitstatus = 1
|
46
48
|
ensure
|
47
|
-
|
48
|
-
|
49
|
+
log_info { "closing proc chain thread" }
|
50
|
+
log_info { "closing channel IOs" }
|
49
51
|
@channel.io.each{ |io| io.close rescue nil }
|
50
|
-
|
51
|
-
|
52
|
+
log_info { "channel IOs closed" }
|
53
|
+
log_info { "wait for sending output" }
|
52
54
|
@channel.wait_until_senders_closed
|
53
|
-
|
55
|
+
log_info { "sending output finished" }
|
54
56
|
@channel.close from=:channel_type_instance, exitstatus=exitstatus
|
55
|
-
|
57
|
+
log_info { "proc chain thread closed" }
|
56
58
|
end
|
57
59
|
}
|
58
60
|
end
|
@@ -4,12 +4,14 @@
|
|
4
4
|
require 'socket'
|
5
5
|
require 'thread'
|
6
6
|
require 'monitor'
|
7
|
-
require 'hrr_rb_ssh/
|
7
|
+
require 'hrr_rb_ssh/loggable'
|
8
8
|
require 'hrr_rb_ssh/connection/channel/channel_type'
|
9
9
|
|
10
10
|
module HrrRbSsh
|
11
11
|
class Connection
|
12
12
|
class Channel
|
13
|
+
include Loggable
|
14
|
+
|
13
15
|
INITIAL_WINDOW_SIZE = 100000
|
14
16
|
MAXIMUM_PACKET_SIZE = 100000
|
15
17
|
|
@@ -24,8 +26,8 @@ module HrrRbSsh
|
|
24
26
|
:receive_message_queue,
|
25
27
|
:exit_status
|
26
28
|
|
27
|
-
def initialize connection, message, socket=nil
|
28
|
-
|
29
|
+
def initialize connection, message, socket=nil, logger: nil
|
30
|
+
self.logger = logger
|
29
31
|
|
30
32
|
@connection = connection
|
31
33
|
|
@@ -37,7 +39,7 @@ module HrrRbSsh
|
|
37
39
|
@remote_window_size = message[:'initial window size']
|
38
40
|
@remote_maximum_packet_size = message[:'maximum packet size']
|
39
41
|
|
40
|
-
@channel_type_instance = ChannelType[@channel_type].new connection, self, message, socket
|
42
|
+
@channel_type_instance = ChannelType[@channel_type].new connection, self, message, socket, logger: logger
|
41
43
|
|
42
44
|
@receive_message_queue = Queue.new
|
43
45
|
@receive_data_queue = Queue.new
|
@@ -83,13 +85,13 @@ module HrrRbSsh
|
|
83
85
|
@channel_type_instance.start
|
84
86
|
end
|
85
87
|
@closed = false
|
86
|
-
|
88
|
+
log_debug { "in start: #{@waiting_thread}" }
|
87
89
|
@waiting_thread.wakeup if @waiting_thread
|
88
90
|
end
|
89
91
|
|
90
92
|
def wait_until_started
|
91
93
|
@waiting_thread = Thread.current
|
92
|
-
|
94
|
+
log_debug { "in wait_until_started: #{@waiting_thread}" }
|
93
95
|
Thread.stop
|
94
96
|
end
|
95
97
|
|
@@ -101,7 +103,7 @@ module HrrRbSsh
|
|
101
103
|
begin
|
102
104
|
t.join if t.instance_of? Thread
|
103
105
|
rescue => e
|
104
|
-
|
106
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
105
107
|
end
|
106
108
|
}
|
107
109
|
end
|
@@ -109,7 +111,7 @@ module HrrRbSsh
|
|
109
111
|
def close from=:outside, exitstatus=0
|
110
112
|
@channel_closing_monitor.synchronize {
|
111
113
|
return if @closed
|
112
|
-
|
114
|
+
log_info { "close channel" }
|
113
115
|
@closed = true
|
114
116
|
}
|
115
117
|
unless from == :channel_type_instance
|
@@ -123,7 +125,7 @@ module HrrRbSsh
|
|
123
125
|
when Integer
|
124
126
|
send_channel_request_exit_status exitstatus
|
125
127
|
else
|
126
|
-
|
128
|
+
log_warn { "skip sending exit-status because exitstatus is not an instance of Integer" }
|
127
129
|
end
|
128
130
|
elsif from == :sender_thread
|
129
131
|
send_channel_eof
|
@@ -132,9 +134,9 @@ module HrrRbSsh
|
|
132
134
|
rescue Error::ClosedConnection => e
|
133
135
|
Thread.pass
|
134
136
|
rescue => e
|
135
|
-
|
137
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
136
138
|
end
|
137
|
-
|
139
|
+
log_info { "channel closed" }
|
138
140
|
end
|
139
141
|
|
140
142
|
def wait_until_closed
|
@@ -150,7 +152,7 @@ module HrrRbSsh
|
|
150
152
|
begin
|
151
153
|
t.join if t.instance_of? Thread
|
152
154
|
rescue => e
|
153
|
-
|
155
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
154
156
|
end
|
155
157
|
}
|
156
158
|
end
|
@@ -161,7 +163,7 @@ module HrrRbSsh
|
|
161
163
|
|
162
164
|
def channel_loop_thread
|
163
165
|
Thread.start do
|
164
|
-
|
166
|
+
log_info { "start channel loop thread" }
|
165
167
|
begin
|
166
168
|
loop do
|
167
169
|
begin
|
@@ -174,13 +176,13 @@ module HrrRbSsh
|
|
174
176
|
@receive_data_queue.close
|
175
177
|
@receive_extended_data_queue.close
|
176
178
|
when Message::SSH_MSG_CHANNEL_REQUEST::VALUE
|
177
|
-
|
179
|
+
log_info { "received channel request: #{message[:'request type']}" }
|
178
180
|
case @connection.mode
|
179
181
|
when Mode::SERVER
|
180
182
|
begin
|
181
183
|
@channel_type_instance.request message
|
182
184
|
rescue => e
|
183
|
-
|
185
|
+
log_warn { "request failed: #{e.message}" }
|
184
186
|
send_channel_failure if message[:'want reply']
|
185
187
|
else
|
186
188
|
send_channel_success if message[:'want reply']
|
@@ -188,45 +190,45 @@ module HrrRbSsh
|
|
188
190
|
when Mode::CLIENT
|
189
191
|
case message[:'request type']
|
190
192
|
when "exit-status"
|
191
|
-
|
193
|
+
log_info { "exit status: #{message[:'exit status']}" }
|
192
194
|
@exit_status = message[:'exit status'].to_i
|
193
195
|
end
|
194
196
|
end
|
195
197
|
when Message::SSH_MSG_CHANNEL_DATA::VALUE
|
196
|
-
|
198
|
+
log_info { "received channel data" }
|
197
199
|
local_channel = message[:'recipient channel']
|
198
200
|
@receive_data_queue.enq message[:'data']
|
199
201
|
when Message::SSH_MSG_CHANNEL_EXTENDED_DATA::VALUE
|
200
|
-
|
202
|
+
log_info { "received channel extended data" }
|
201
203
|
local_channel = message[:'recipient channel']
|
202
204
|
@receive_extended_data_queue.enq message[:'data']
|
203
205
|
when Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE
|
204
|
-
|
206
|
+
log_debug { "received channel window adjust" }
|
205
207
|
@remote_window_size = [@remote_window_size + message[:'bytes to add'], 0xffff_ffff].min
|
206
208
|
else
|
207
|
-
|
209
|
+
log_warn { "received unsupported message: #{message.inspect}" }
|
208
210
|
end
|
209
211
|
rescue => e
|
210
|
-
|
212
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
211
213
|
close from=:channel_loop_thread
|
212
214
|
break
|
213
215
|
end
|
214
216
|
end
|
215
217
|
ensure
|
216
|
-
|
218
|
+
log_info { "closing channel loop thread" }
|
217
219
|
@receive_data_queue.close
|
218
220
|
@receive_extended_data_queue.close
|
219
221
|
end
|
220
|
-
|
222
|
+
log_info { "channel loop thread closed" }
|
221
223
|
end
|
222
224
|
end
|
223
225
|
|
224
226
|
def out_sender_thread
|
225
227
|
Thread.start {
|
226
|
-
|
228
|
+
log_info { "start out sender thread" }
|
227
229
|
loop do
|
228
230
|
if @r_io_out.closed?
|
229
|
-
|
231
|
+
log_info { "closing out sender thread" }
|
230
232
|
break
|
231
233
|
end
|
232
234
|
begin
|
@@ -238,21 +240,21 @@ module HrrRbSsh
|
|
238
240
|
rescue EOFError, IOError => e
|
239
241
|
@r_io_out.close rescue nil
|
240
242
|
rescue => e
|
241
|
-
|
243
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
242
244
|
@r_io_out.close rescue nil
|
243
245
|
close
|
244
246
|
end
|
245
247
|
end
|
246
|
-
|
248
|
+
log_info { "out sender thread closed" }
|
247
249
|
}
|
248
250
|
end
|
249
251
|
|
250
252
|
def err_sender_thread
|
251
253
|
Thread.start {
|
252
|
-
|
254
|
+
log_info { "start err sender thread" }
|
253
255
|
loop do
|
254
256
|
if @r_io_err.closed?
|
255
|
-
|
257
|
+
log_info { "closing err sender thread" }
|
256
258
|
break
|
257
259
|
end
|
258
260
|
begin
|
@@ -264,32 +266,32 @@ module HrrRbSsh
|
|
264
266
|
rescue EOFError, IOError => e
|
265
267
|
@r_io_err.close rescue nil
|
266
268
|
rescue => e
|
267
|
-
|
269
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
268
270
|
@r_io_err.close rescue nil
|
269
271
|
close
|
270
272
|
end
|
271
273
|
end
|
272
|
-
|
274
|
+
log_info { "err sender thread closed" }
|
273
275
|
}
|
274
276
|
end
|
275
277
|
|
276
278
|
def receiver_thread
|
277
279
|
Thread.start {
|
278
|
-
|
280
|
+
log_info { "start receiver thread" }
|
279
281
|
loop do
|
280
282
|
begin
|
281
283
|
data = @receive_data_queue.deq
|
282
284
|
if data.nil? && @receive_data_queue.closed?
|
283
|
-
|
284
|
-
|
285
|
+
log_info { "closing receiver thread" }
|
286
|
+
log_info { "closing w_io_in" }
|
285
287
|
@w_io_in.close
|
286
|
-
|
288
|
+
log_info { "w_io_in closed" }
|
287
289
|
break
|
288
290
|
end
|
289
291
|
@w_io_in.write data
|
290
292
|
@local_window_size -= data.size
|
291
293
|
if @local_window_size < INITIAL_WINDOW_SIZE/2
|
292
|
-
|
294
|
+
log_info { "send channel window adjust" }
|
293
295
|
send_channel_window_adjust
|
294
296
|
@local_window_size += INITIAL_WINDOW_SIZE
|
295
297
|
end
|
@@ -297,32 +299,32 @@ module HrrRbSsh
|
|
297
299
|
close
|
298
300
|
break
|
299
301
|
rescue => e
|
300
|
-
|
302
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
301
303
|
close
|
302
304
|
break
|
303
305
|
end
|
304
306
|
end
|
305
|
-
|
307
|
+
log_info { "receiver thread closed" }
|
306
308
|
}
|
307
309
|
end
|
308
310
|
|
309
311
|
def out_receiver_thread
|
310
312
|
Thread.start {
|
311
|
-
|
313
|
+
log_info { "start out receiver thread" }
|
312
314
|
loop do
|
313
315
|
begin
|
314
316
|
data = @receive_data_queue.deq
|
315
317
|
if data.nil? && @receive_data_queue.closed?
|
316
|
-
|
317
|
-
|
318
|
+
log_info { "closing out receiver thread" }
|
319
|
+
log_info { "closing w_io_out" }
|
318
320
|
@w_io_out.close
|
319
|
-
|
321
|
+
log_info { "w_io_out closed" }
|
320
322
|
break
|
321
323
|
end
|
322
324
|
@w_io_out.write data
|
323
325
|
@local_window_size -= data.size
|
324
326
|
if @local_window_size < INITIAL_WINDOW_SIZE/2
|
325
|
-
|
327
|
+
log_info { "send channel window adjust" }
|
326
328
|
send_channel_window_adjust
|
327
329
|
@local_window_size += INITIAL_WINDOW_SIZE
|
328
330
|
end
|
@@ -330,32 +332,32 @@ module HrrRbSsh
|
|
330
332
|
close
|
331
333
|
break
|
332
334
|
rescue => e
|
333
|
-
|
335
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
334
336
|
close
|
335
337
|
break
|
336
338
|
end
|
337
339
|
end
|
338
|
-
|
340
|
+
log_info { "out receiver thread closed" }
|
339
341
|
}
|
340
342
|
end
|
341
343
|
|
342
344
|
def err_receiver_thread
|
343
345
|
Thread.start {
|
344
|
-
|
346
|
+
log_info { "start err receiver thread" }
|
345
347
|
loop do
|
346
348
|
begin
|
347
349
|
data = @receive_extended_data_queue.deq
|
348
350
|
if data.nil? && @receive_extended_data_queue.closed?
|
349
|
-
|
350
|
-
|
351
|
+
log_info { "closing err receiver thread" }
|
352
|
+
log_info { "closing w_io_err" }
|
351
353
|
@w_io_err.close
|
352
|
-
|
354
|
+
log_info { "w_io_err closed" }
|
353
355
|
break
|
354
356
|
end
|
355
357
|
@w_io_err.write data
|
356
358
|
@local_window_size -= data.size
|
357
359
|
if @local_window_size < INITIAL_WINDOW_SIZE/2
|
358
|
-
|
360
|
+
log_info { "send channel window adjust" }
|
359
361
|
send_channel_window_adjust
|
360
362
|
@local_window_size += INITIAL_WINDOW_SIZE
|
361
363
|
end
|
@@ -363,21 +365,21 @@ module HrrRbSsh
|
|
363
365
|
close
|
364
366
|
break
|
365
367
|
rescue => e
|
366
|
-
|
368
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
367
369
|
close
|
368
370
|
break
|
369
371
|
end
|
370
372
|
end
|
371
|
-
|
373
|
+
log_info { "err receiver thread closed" }
|
372
374
|
}
|
373
375
|
end
|
374
376
|
|
375
377
|
def sender_thread
|
376
378
|
Thread.start {
|
377
|
-
|
379
|
+
log_info { "start sender thread" }
|
378
380
|
loop do
|
379
381
|
if @r_io_in.closed?
|
380
|
-
|
382
|
+
log_info { "closing sender thread" }
|
381
383
|
break
|
382
384
|
end
|
383
385
|
begin
|
@@ -389,12 +391,12 @@ module HrrRbSsh
|
|
389
391
|
rescue EOFError, IOError => e
|
390
392
|
@r_io_in.close rescue nil
|
391
393
|
rescue => e
|
392
|
-
|
394
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
393
395
|
@r_io_in.close rescue nil
|
394
396
|
end
|
395
397
|
end
|
396
398
|
close from=:sender_thread
|
397
|
-
|
399
|
+
log_info { "sender thread closed" }
|
398
400
|
}
|
399
401
|
end
|
400
402
|
|
@@ -403,7 +405,7 @@ module HrrRbSsh
|
|
403
405
|
:'message number' => Message::SSH_MSG_CHANNEL_SUCCESS::VALUE,
|
404
406
|
:'recipient channel' => @remote_channel,
|
405
407
|
}
|
406
|
-
payload = Message::SSH_MSG_CHANNEL_SUCCESS.encode message
|
408
|
+
payload = Message::SSH_MSG_CHANNEL_SUCCESS.encode message, logger: logger
|
407
409
|
@connection.send payload
|
408
410
|
end
|
409
411
|
|
@@ -412,7 +414,7 @@ module HrrRbSsh
|
|
412
414
|
:'message number' => Message::SSH_MSG_CHANNEL_FAILURE::VALUE,
|
413
415
|
:'recipient channel' => @remote_channel,
|
414
416
|
}
|
415
|
-
payload = Message::SSH_MSG_CHANNEL_FAILURE.encode message
|
417
|
+
payload = Message::SSH_MSG_CHANNEL_FAILURE.encode message, logger: logger
|
416
418
|
@connection.send payload
|
417
419
|
end
|
418
420
|
|
@@ -422,7 +424,7 @@ module HrrRbSsh
|
|
422
424
|
:'recipient channel' => @remote_channel,
|
423
425
|
:'bytes to add' => INITIAL_WINDOW_SIZE,
|
424
426
|
}
|
425
|
-
payload = Message::SSH_MSG_CHANNEL_WINDOW_ADJUST.encode message
|
427
|
+
payload = Message::SSH_MSG_CHANNEL_WINDOW_ADJUST.encode message, logger: logger
|
426
428
|
@connection.send payload
|
427
429
|
end
|
428
430
|
|
@@ -432,7 +434,7 @@ module HrrRbSsh
|
|
432
434
|
:'recipient channel' => @remote_channel,
|
433
435
|
:'data' => data,
|
434
436
|
}
|
435
|
-
payload = Message::SSH_MSG_CHANNEL_DATA.encode message
|
437
|
+
payload = Message::SSH_MSG_CHANNEL_DATA.encode message, logger: logger
|
436
438
|
@connection.send payload
|
437
439
|
end
|
438
440
|
|
@@ -443,7 +445,7 @@ module HrrRbSsh
|
|
443
445
|
:'data type code' => code,
|
444
446
|
:'data' => data,
|
445
447
|
}
|
446
|
-
payload = Message::SSH_MSG_CHANNEL_EXTENDED_DATA.encode message
|
448
|
+
payload = Message::SSH_MSG_CHANNEL_EXTENDED_DATA.encode message, logger: logger
|
447
449
|
@connection.send payload
|
448
450
|
end
|
449
451
|
|
@@ -460,7 +462,7 @@ module HrrRbSsh
|
|
460
462
|
:'terminal height, pixels' => term_height_pixel,
|
461
463
|
:'encoded terminal modes' => encoded_term_modes,
|
462
464
|
}
|
463
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
465
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
464
466
|
@connection.send payload
|
465
467
|
end
|
466
468
|
|
@@ -473,7 +475,7 @@ module HrrRbSsh
|
|
473
475
|
:'variable name' => variable_name,
|
474
476
|
:'variable value' => variable_value,
|
475
477
|
}
|
476
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
478
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
477
479
|
@connection.send payload
|
478
480
|
end
|
479
481
|
|
@@ -484,7 +486,7 @@ module HrrRbSsh
|
|
484
486
|
:'request type' => "shell",
|
485
487
|
:'want reply' => false,
|
486
488
|
}
|
487
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
489
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
488
490
|
@connection.send payload
|
489
491
|
end
|
490
492
|
|
@@ -496,7 +498,7 @@ module HrrRbSsh
|
|
496
498
|
:'want reply' => false,
|
497
499
|
:'command' => command,
|
498
500
|
}
|
499
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
501
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
500
502
|
@connection.send payload
|
501
503
|
end
|
502
504
|
|
@@ -508,7 +510,7 @@ module HrrRbSsh
|
|
508
510
|
:'want reply' => false,
|
509
511
|
:'subsystem name' => subsystem_name,
|
510
512
|
}
|
511
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
513
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
512
514
|
@connection.send payload
|
513
515
|
end
|
514
516
|
|
@@ -523,7 +525,7 @@ module HrrRbSsh
|
|
523
525
|
:'terminal width, pixels' => term_width_pixel,
|
524
526
|
:'terminal height, pixels' => term_height_pixel,
|
525
527
|
}
|
526
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
528
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
527
529
|
@connection.send payload
|
528
530
|
end
|
529
531
|
|
@@ -535,7 +537,7 @@ module HrrRbSsh
|
|
535
537
|
:'want reply' => false,
|
536
538
|
:'signal name' => signal_name,
|
537
539
|
}
|
538
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
540
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
539
541
|
@connection.send payload
|
540
542
|
end
|
541
543
|
|
@@ -547,7 +549,7 @@ module HrrRbSsh
|
|
547
549
|
:'want reply' => false,
|
548
550
|
:'exit status' => exitstatus,
|
549
551
|
}
|
550
|
-
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
552
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message, logger: logger
|
551
553
|
@connection.send payload
|
552
554
|
end
|
553
555
|
|
@@ -556,7 +558,7 @@ module HrrRbSsh
|
|
556
558
|
:'message number' => Message::SSH_MSG_CHANNEL_EOF::VALUE,
|
557
559
|
:'recipient channel' => @remote_channel,
|
558
560
|
}
|
559
|
-
payload = Message::SSH_MSG_CHANNEL_EOF.encode message
|
561
|
+
payload = Message::SSH_MSG_CHANNEL_EOF.encode message, logger: logger
|
560
562
|
@connection.send payload
|
561
563
|
end
|
562
564
|
|
@@ -565,7 +567,7 @@ module HrrRbSsh
|
|
565
567
|
:'message number' => Message::SSH_MSG_CHANNEL_CLOSE::VALUE,
|
566
568
|
:'recipient channel' => @remote_channel,
|
567
569
|
}
|
568
|
-
payload = Message::SSH_MSG_CHANNEL_CLOSE.encode message
|
570
|
+
payload = Message::SSH_MSG_CHANNEL_CLOSE.encode message, logger: logger
|
569
571
|
@connection.send payload
|
570
572
|
end
|
571
573
|
end
|
@@ -2,23 +2,25 @@
|
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
4
|
require 'socket'
|
5
|
-
require 'hrr_rb_ssh/
|
5
|
+
require 'hrr_rb_ssh/loggable'
|
6
6
|
|
7
7
|
module HrrRbSsh
|
8
8
|
class Connection
|
9
9
|
class GlobalRequestHandler
|
10
|
+
include Loggable
|
11
|
+
|
10
12
|
attr_reader \
|
11
13
|
:accepted
|
12
14
|
|
13
|
-
def initialize connection
|
14
|
-
|
15
|
+
def initialize connection, logger: nil
|
16
|
+
self.logger = logger
|
15
17
|
@connection = connection
|
16
18
|
@tcpip_forward_servers = Hash.new
|
17
19
|
@tcpip_forward_threads = Hash.new
|
18
20
|
end
|
19
21
|
|
20
22
|
def close
|
21
|
-
|
23
|
+
log_info { "closing tcpip-forward" }
|
22
24
|
@tcpip_forward_threads.values.each(&:exit)
|
23
25
|
@tcpip_forward_servers.values.each{ |s|
|
24
26
|
begin
|
@@ -29,7 +31,7 @@ module HrrRbSsh
|
|
29
31
|
}
|
30
32
|
@tcpip_forward_threads.clear
|
31
33
|
@tcpip_forward_servers.clear
|
32
|
-
|
34
|
+
log_info { "tcpip-forward closed" }
|
33
35
|
end
|
34
36
|
|
35
37
|
def request message
|
@@ -39,13 +41,13 @@ module HrrRbSsh
|
|
39
41
|
when "cancel-tcpip-forward"
|
40
42
|
cancel_tcpip_forward message
|
41
43
|
else
|
42
|
-
|
44
|
+
log_warn { "unsupported request name: #{message[:'request name']}" }
|
43
45
|
raise
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
49
|
def tcpip_forward message
|
48
|
-
|
50
|
+
log_info { "starting tcpip-forward" }
|
49
51
|
begin
|
50
52
|
address_to_bind = message[:'address to bind']
|
51
53
|
port_number_to_bind = message[:'port number to bind']
|
@@ -60,18 +62,18 @@ module HrrRbSsh
|
|
60
62
|
}
|
61
63
|
end
|
62
64
|
rescue => e
|
63
|
-
|
65
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
64
66
|
end
|
65
67
|
}
|
66
|
-
|
68
|
+
log_info { "tcpip-forward started" }
|
67
69
|
rescue => e
|
68
|
-
|
70
|
+
log_warn { "starting tcpip-forward failed: #{e.message}" }
|
69
71
|
raise e
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
75
|
def cancel_tcpip_forward message
|
74
|
-
|
76
|
+
log_info { "canceling tcpip-forward" }
|
75
77
|
address_to_bind = message[:'address to bind']
|
76
78
|
port_number_to_bind = message[:'port number to bind']
|
77
79
|
id = "#{address_to_bind}:#{port_number_to_bind}"
|
@@ -83,7 +85,7 @@ module HrrRbSsh
|
|
83
85
|
end
|
84
86
|
@tcpip_forward_threads.delete id
|
85
87
|
@tcpip_forward_servers.delete id
|
86
|
-
|
88
|
+
log_info { "tcpip-forward canceled" }
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_ssh/logger'
|
5
4
|
require 'hrr_rb_ssh/connection/request_handler'
|
6
5
|
|
7
6
|
module HrrRbSsh
|
@@ -9,7 +8,6 @@ module HrrRbSsh
|
|
9
8
|
class RequestHandler
|
10
9
|
class ReferenceEnvRequestHandler < RequestHandler
|
11
10
|
def initialize
|
12
|
-
@logger = Logger.new self.class.name
|
13
11
|
@proc = Proc.new { |context|
|
14
12
|
context.vars[:env] ||= Hash.new
|
15
13
|
context.vars[:env][context.variable_name] = context.variable_value
|