hrr_rb_ssh 0.3.0.pre1 → 0.4.2
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/.gitignore +0 -3
- data/.travis.yml +1 -0
- data/README.md +208 -46
- data/demo/client.rb +71 -0
- data/demo/echo_server.rb +8 -3
- data/demo/more_flexible_auth.rb +105 -0
- data/demo/multi_step_auth.rb +99 -0
- data/demo/server.rb +10 -4
- data/demo/subsystem_echo_server.rb +8 -3
- data/hrr_rb_ssh.gemspec +6 -6
- data/lib/hrr_rb_ssh.rb +1 -1
- data/lib/hrr_rb_ssh/algorithm/publickey.rb +0 -1
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2.rb +12 -9
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2/ecdsa_signature_blob.rb +2 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2/public_key_blob.rb +2 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2/signature.rb +2 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss.rb +10 -7
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss/public_key_blob.rb +2 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss/signature.rb +2 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa.rb +9 -6
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa/public_key_blob.rb +2 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa/signature.rb +2 -4
- data/lib/hrr_rb_ssh/authentication.rb +103 -22
- data/lib/hrr_rb_ssh/authentication/constant.rb +14 -0
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive.rb +44 -7
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/context.rb +16 -9
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb +7 -6
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_response.rb +5 -2
- data/lib/hrr_rb_ssh/authentication/method/none.rb +23 -7
- data/lib/hrr_rb_ssh/authentication/method/none/context.rb +15 -7
- data/lib/hrr_rb_ssh/authentication/method/password.rb +28 -7
- data/lib/hrr_rb_ssh/authentication/method/password/context.rb +16 -7
- data/lib/hrr_rb_ssh/authentication/method/publickey.rb +63 -10
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +0 -1
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/functionable.rb +32 -8
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/signature_blob.rb +2 -4
- data/lib/hrr_rb_ssh/authentication/method/publickey/context.rb +11 -2
- data/lib/hrr_rb_ssh/client.rb +234 -0
- data/lib/hrr_rb_ssh/codable.rb +15 -13
- data/lib/hrr_rb_ssh/compat/ruby.rb +0 -1
- data/lib/hrr_rb_ssh/connection.rb +145 -75
- data/lib/hrr_rb_ssh/connection/channel.rb +342 -109
- data/lib/hrr_rb_ssh/connection/channel/channel_type/direct_tcpip.rb +24 -19
- data/lib/hrr_rb_ssh/connection/channel/channel_type/forwarded_tcpip.rb +24 -19
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +19 -12
- 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/proc_chain/chain_context.rb +0 -3
- 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/env/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/exec/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/pty_req/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/shell/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/subsystem/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/request_type/window_change/context.rb +5 -4
- data/lib/hrr_rb_ssh/connection/global_request_handler.rb +14 -12
- data/lib/hrr_rb_ssh/connection/request_handler.rb +1 -3
- 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/error/closed_authentication.rb +1 -1
- data/lib/hrr_rb_ssh/error/closed_connection.rb +1 -1
- data/lib/hrr_rb_ssh/error/closed_transport.rb +1 -1
- data/lib/hrr_rb_ssh/loggable.rb +42 -0
- data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +2 -4
- data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +2 -4
- data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +2 -4
- data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +2 -4
- data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +2 -4
- data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +2 -4
- data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +2 -4
- data/lib/hrr_rb_ssh/message/021_ssh_msg_newkeys.rb +2 -4
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kex_dh_gex_request_old.rb +2 -4
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +2 -4
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexecdh_init.rb +2 -4
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kex_dh_gex_group.rb +2 -4
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +2 -4
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexecdh_reply.rb +2 -4
- data/lib/hrr_rb_ssh/message/032_ssh_msg_kex_dh_gex_init.rb +2 -4
- data/lib/hrr_rb_ssh/message/033_ssh_msg_kex_dh_gex_reply.rb +2 -4
- data/lib/hrr_rb_ssh/message/034_ssh_msg_kex_dh_gex_request.rb +2 -4
- data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +2 -4
- data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +2 -4
- data/lib/hrr_rb_ssh/message/052_ssh_msg_userauth_success.rb +2 -4
- data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_info_request.rb +2 -4
- data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_pk_ok.rb +2 -4
- data/lib/hrr_rb_ssh/message/061_ssh_msg_userauth_info_response.rb +2 -4
- data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +2 -4
- data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +2 -4
- data/lib/hrr_rb_ssh/message/082_ssh_msg_request_failure.rb +2 -4
- data/lib/hrr_rb_ssh/message/090_ssh_msg_channel_open.rb +2 -4
- data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +2 -4
- data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +2 -4
- data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +2 -4
- data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +2 -4
- data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +2 -4
- data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +2 -4
- data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +2 -4
- data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +3 -5
- data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +2 -4
- data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +2 -4
- data/lib/hrr_rb_ssh/server.rb +16 -10
- data/lib/hrr_rb_ssh/transport.rb +113 -77
- 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 +43 -37
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman/h0.rb +2 -4
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange.rb +87 -52
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange/h0.rb +2 -4
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman.rb +43 -37
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman/h0.rb +2 -4
- 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.rb +0 -1
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/functionable.rb +5 -3
- data/lib/hrr_rb_ssh/version.rb +1 -1
- metadata +18 -51
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519.rb +0 -61
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/openssh_private_key.rb +0 -29
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/openssh_private_key_content.rb +0 -26
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/pkey.rb +0 -158
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/public_key_blob.rb +0 -23
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/signature.rb +0 -23
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_ed25519.rb +0 -21
- data/lib/hrr_rb_ssh/compat/ruby/array.rb +0 -14
- data/lib/hrr_rb_ssh/logger.rb +0 -56
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_ed25519.rb +0 -20
@@ -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
|
@@ -13,10 +12,8 @@ module HrrRbSsh
|
|
13
12
|
class Shell < RequestType
|
14
13
|
NAME = 'shell'
|
15
14
|
|
16
|
-
def self.run proc_chain, username, io, variables, message, options, session
|
17
|
-
|
18
|
-
|
19
|
-
context = Context.new proc_chain, username, io, variables, message, session
|
15
|
+
def self.run proc_chain, username, io, variables, message, options, session, logger: nil
|
16
|
+
context = Context.new proc_chain, username, io, variables, message, session, logger: logger
|
20
17
|
handler = options.fetch('connection_channel_request_shell', RequestHandler.new {})
|
21
18
|
handler.run context
|
22
19
|
|
@@ -1,7 +1,7 @@
|
|
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
|
@@ -11,15 +11,16 @@ module HrrRbSsh
|
|
11
11
|
class RequestType
|
12
12
|
class Shell
|
13
13
|
class Context
|
14
|
+
include Loggable
|
15
|
+
|
14
16
|
attr_reader \
|
15
|
-
:logger,
|
16
17
|
:username,
|
17
18
|
:io,
|
18
19
|
:variables,
|
19
20
|
:vars
|
20
21
|
|
21
|
-
def initialize proc_chain, username, io, variables, message, session
|
22
|
-
|
22
|
+
def initialize proc_chain, username, io, variables, message, session, logger: nil
|
23
|
+
self.logger = logger
|
23
24
|
|
24
25
|
@proc_chain = proc_chain
|
25
26
|
@username = username
|
@@ -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
|
@@ -13,10 +12,8 @@ module HrrRbSsh
|
|
13
12
|
class Subsystem < RequestType
|
14
13
|
NAME = 'subsystem'
|
15
14
|
|
16
|
-
def self.run proc_chain, username, io, variables, message, options, session
|
17
|
-
|
18
|
-
|
19
|
-
context = Context.new proc_chain, username, io, variables, message, session
|
15
|
+
def self.run proc_chain, username, io, variables, message, options, session, logger: nil
|
16
|
+
context = Context.new proc_chain, username, io, variables, message, session, logger: logger
|
20
17
|
handler = options.fetch('connection_channel_request_subsystem', RequestHandler.new {})
|
21
18
|
handler.run context
|
22
19
|
|
data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -11,16 +11,17 @@ module HrrRbSsh
|
|
11
11
|
class RequestType
|
12
12
|
class Subsystem
|
13
13
|
class Context
|
14
|
+
include Loggable
|
15
|
+
|
14
16
|
attr_reader \
|
15
|
-
:logger,
|
16
17
|
:username,
|
17
18
|
:io,
|
18
19
|
:variables,
|
19
20
|
:vars,
|
20
21
|
:subsystem_name
|
21
22
|
|
22
|
-
def initialize proc_chain, username, io, variables, message, session
|
23
|
-
|
23
|
+
def initialize proc_chain, username, io, variables, message, session, logger: nil
|
24
|
+
self.logger = logger
|
24
25
|
|
25
26
|
@proc_chain = proc_chain
|
26
27
|
@username = username
|
@@ -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
|
@@ -13,10 +12,8 @@ module HrrRbSsh
|
|
13
12
|
class WindowChange < RequestType
|
14
13
|
NAME = 'window-change'
|
15
14
|
|
16
|
-
def self.run proc_chain, username, io, variables, message, options, session
|
17
|
-
|
18
|
-
|
19
|
-
context = Context.new proc_chain, username, io, variables, message, session
|
15
|
+
def self.run proc_chain, username, io, variables, message, options, session, logger: nil
|
16
|
+
context = Context.new proc_chain, username, io, variables, message, session, logger: logger
|
20
17
|
handler = options.fetch('connection_channel_request_window_change', RequestHandler.new {})
|
21
18
|
handler.run context
|
22
19
|
|
data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change/context.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -11,8 +11,9 @@ module HrrRbSsh
|
|
11
11
|
class RequestType
|
12
12
|
class WindowChange
|
13
13
|
class Context
|
14
|
+
include Loggable
|
15
|
+
|
14
16
|
attr_reader \
|
15
|
-
:logger,
|
16
17
|
:username,
|
17
18
|
:io,
|
18
19
|
:variables,
|
@@ -22,8 +23,8 @@ module HrrRbSsh
|
|
22
23
|
:terminal_width_pixels,
|
23
24
|
:terminal_height_pixels
|
24
25
|
|
25
|
-
def initialize proc_chain, username, io, variables, message, session
|
26
|
-
|
26
|
+
def initialize proc_chain, username, io, variables, message, session, logger: nil
|
27
|
+
self.logger = logger
|
27
28
|
|
28
29
|
@proc_chain = proc_chain
|
29
30
|
@username = username
|
@@ -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,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_ssh/logger'
|
5
|
-
|
6
4
|
module HrrRbSsh
|
7
5
|
class Connection
|
8
6
|
class RequestHandler
|
9
7
|
def initialize &block
|
10
|
-
@logger = Logger.new self.class.name
|
11
8
|
@proc = block
|
12
9
|
end
|
10
|
+
|
13
11
|
def run context
|
14
12
|
@proc.call context
|
15
13
|
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
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
4
|
require 'etc'
|
5
|
-
require 'hrr_rb_ssh/logger'
|
6
5
|
require 'hrr_rb_ssh/connection/request_handler'
|
7
6
|
|
8
7
|
module HrrRbSsh
|
@@ -10,7 +9,6 @@ module HrrRbSsh
|
|
10
9
|
class RequestHandler
|
11
10
|
class ReferenceExecRequestHandler < RequestHandler
|
12
11
|
def initialize
|
13
|
-
@logger = Logger.new self.class.name
|
14
12
|
@proc = Proc.new { |context|
|
15
13
|
ptm = context.vars[:ptm]
|
16
14
|
pts = context.vars[:pts]
|
@@ -58,22 +56,22 @@ module HrrRbSsh
|
|
58
56
|
|
59
57
|
begin
|
60
58
|
pid, status = Process.waitpid2 pid
|
61
|
-
context.
|
59
|
+
context.log_info { "program exited with status #{status.inspect}" }
|
62
60
|
status.exitstatus
|
63
61
|
ensure
|
64
62
|
unless status
|
65
|
-
context.
|
63
|
+
context.log_info { "exiting program" }
|
66
64
|
Process.kill :TERM, pid
|
67
65
|
begin
|
68
66
|
Timeout.timeout(1) do
|
69
67
|
pid, status = Process.waitpid2 pid
|
70
68
|
end
|
71
69
|
rescue Timeout::Error
|
72
|
-
context.
|
70
|
+
context.log_warn { "force exiting program" }
|
73
71
|
Process.kill :KILL, pid
|
74
72
|
pid, status = Process.waitpid2 pid
|
75
73
|
end
|
76
|
-
context.
|
74
|
+
context.log_info { "program exited with status #{status.inspect}" }
|
77
75
|
end
|
78
76
|
end
|
79
77
|
end
|
@@ -5,7 +5,6 @@ require 'etc'
|
|
5
5
|
require 'fileutils'
|
6
6
|
require 'pty'
|
7
7
|
require 'io/console'
|
8
|
-
require 'hrr_rb_ssh/logger'
|
9
8
|
require 'hrr_rb_ssh/connection/request_handler'
|
10
9
|
|
11
10
|
module HrrRbSsh
|
@@ -13,7 +12,6 @@ module HrrRbSsh
|
|
13
12
|
class RequestHandler
|
14
13
|
class ReferencePtyReqRequestHandler < RequestHandler
|
15
14
|
def initialize
|
16
|
-
@logger = Logger.new self.class.name
|
17
15
|
@proc = Proc.new { |context|
|
18
16
|
begin
|
19
17
|
ptm, pts = PTY.open
|
@@ -32,16 +30,16 @@ module HrrRbSsh
|
|
32
30
|
begin
|
33
31
|
context.io[1].write ptm.readpartial(10240)
|
34
32
|
rescue EOFError => e
|
35
|
-
context.
|
33
|
+
context.log_info { "ptm is EOF in ptm_read_thread" }
|
36
34
|
break
|
37
35
|
rescue IOError => e
|
38
|
-
context.
|
36
|
+
context.log_warn { "IO Error in ptm_read_thread" }
|
39
37
|
break
|
40
38
|
rescue Errno::EIO => e
|
41
|
-
context.
|
39
|
+
context.log_info { "EIO Error in ptm_read_thread" }
|
42
40
|
break
|
43
41
|
rescue => e
|
44
|
-
context.
|
42
|
+
context.log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
45
43
|
break
|
46
44
|
end
|
47
45
|
end
|
@@ -51,29 +49,29 @@ module HrrRbSsh
|
|
51
49
|
begin
|
52
50
|
ptm.write context.io[0].readpartial(10240)
|
53
51
|
rescue EOFError => e
|
54
|
-
context.
|
52
|
+
context.log_info { "IO is EOF in ptm_write_thread" }
|
55
53
|
break
|
56
54
|
rescue IOError => e
|
57
|
-
context.
|
55
|
+
context.log_warn { "IO Error in ptm_write_thread" }
|
58
56
|
break
|
59
57
|
rescue Errno::EIO => e
|
60
|
-
context.
|
58
|
+
context.log_info { "EIO Error in ptm_read_thread" }
|
61
59
|
break
|
62
60
|
rescue => e
|
63
|
-
context.
|
61
|
+
context.log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
64
62
|
break
|
65
63
|
end
|
66
64
|
end
|
67
65
|
}
|
68
66
|
chain.call_next
|
69
67
|
ensure
|
70
|
-
context.
|
68
|
+
context.log_info { "closing pty-req request handler chain_proc" }
|
71
69
|
context.vars[:ptm].close rescue nil
|
72
70
|
context.vars[:pts].close rescue nil
|
73
71
|
ptm_read_thread.join
|
74
72
|
ptm_write_thread.exit
|
75
73
|
ptm_write_thread.join
|
76
|
-
context.
|
74
|
+
context.log_info { "pty-req request handler chain_proc closed" }
|
77
75
|
end
|
78
76
|
}
|
79
77
|
rescue => e
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
require 'etc'
|
5
5
|
require 'timeout'
|
6
|
-
require 'hrr_rb_ssh/logger'
|
7
6
|
require 'hrr_rb_ssh/connection/request_handler'
|
8
7
|
|
9
8
|
module HrrRbSsh
|
@@ -11,7 +10,6 @@ module HrrRbSsh
|
|
11
10
|
class RequestHandler
|
12
11
|
class ReferenceShellRequestHandler < RequestHandler
|
13
12
|
def initialize
|
14
|
-
@logger = Logger.new self.class.name
|
15
13
|
@proc = Proc.new { |context|
|
16
14
|
ptm = context.vars[:ptm]
|
17
15
|
pts = context.vars[:pts]
|
@@ -49,22 +47,22 @@ module HrrRbSsh
|
|
49
47
|
|
50
48
|
begin
|
51
49
|
pid, status = Process.waitpid2 pid
|
52
|
-
context.
|
50
|
+
context.log_info { "shell exited with status #{status.inspect}" }
|
53
51
|
status.exitstatus
|
54
52
|
ensure
|
55
53
|
unless status
|
56
|
-
context.
|
54
|
+
context.log_info { "exiting shell" }
|
57
55
|
Process.kill :TERM, pid
|
58
56
|
begin
|
59
57
|
Timeout.timeout(1) do
|
60
58
|
pid, status = Process.waitpid2 pid
|
61
59
|
end
|
62
60
|
rescue Timeout::Error
|
63
|
-
context.
|
61
|
+
context.log_warn { "force exiting shell" }
|
64
62
|
Process.kill :KILL, pid
|
65
63
|
pid, status = Process.waitpid2 pid
|
66
64
|
end
|
67
|
-
context.
|
65
|
+
context.log_info { "shell exited with status #{status.inspect}" }
|
68
66
|
end
|
69
67
|
end
|
70
68
|
}
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
4
|
require 'io/console'
|
5
|
-
require 'hrr_rb_ssh/logger'
|
6
5
|
require 'hrr_rb_ssh/connection/request_handler'
|
7
6
|
|
8
7
|
module HrrRbSsh
|
@@ -10,7 +9,6 @@ module HrrRbSsh
|
|
10
9
|
class RequestHandler
|
11
10
|
class ReferenceWindowChangeRequestHandler < RequestHandler
|
12
11
|
def initialize
|
13
|
-
@logger = Logger.new self.class.name
|
14
12
|
@proc = Proc.new { |context|
|
15
13
|
context.vars[:ptm].winsize = [context.terminal_height_rows, context.terminal_width_columns, context.terminal_width_pixels, context.terminal_height_pixels]
|
16
14
|
}
|