hrr_rb_ssh 0.3.0.pre1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -3
  3. data/.travis.yml +1 -0
  4. data/README.md +208 -46
  5. data/demo/client.rb +71 -0
  6. data/demo/echo_server.rb +8 -3
  7. data/demo/more_flexible_auth.rb +105 -0
  8. data/demo/multi_step_auth.rb +99 -0
  9. data/demo/server.rb +10 -4
  10. data/demo/subsystem_echo_server.rb +8 -3
  11. data/hrr_rb_ssh.gemspec +6 -6
  12. data/lib/hrr_rb_ssh.rb +1 -1
  13. data/lib/hrr_rb_ssh/algorithm/publickey.rb +0 -1
  14. data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2.rb +12 -9
  15. data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2/ecdsa_signature_blob.rb +2 -4
  16. data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2/public_key_blob.rb +2 -4
  17. data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2/signature.rb +2 -4
  18. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss.rb +10 -7
  19. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss/public_key_blob.rb +2 -4
  20. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss/signature.rb +2 -4
  21. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa.rb +9 -6
  22. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa/public_key_blob.rb +2 -4
  23. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa/signature.rb +2 -4
  24. data/lib/hrr_rb_ssh/authentication.rb +103 -22
  25. data/lib/hrr_rb_ssh/authentication/constant.rb +14 -0
  26. data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive.rb +44 -7
  27. data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/context.rb +16 -9
  28. data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb +7 -6
  29. data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_response.rb +5 -2
  30. data/lib/hrr_rb_ssh/authentication/method/none.rb +23 -7
  31. data/lib/hrr_rb_ssh/authentication/method/none/context.rb +15 -7
  32. data/lib/hrr_rb_ssh/authentication/method/password.rb +28 -7
  33. data/lib/hrr_rb_ssh/authentication/method/password/context.rb +16 -7
  34. data/lib/hrr_rb_ssh/authentication/method/publickey.rb +63 -10
  35. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +0 -1
  36. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/functionable.rb +32 -8
  37. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/signature_blob.rb +2 -4
  38. data/lib/hrr_rb_ssh/authentication/method/publickey/context.rb +11 -2
  39. data/lib/hrr_rb_ssh/client.rb +234 -0
  40. data/lib/hrr_rb_ssh/codable.rb +15 -13
  41. data/lib/hrr_rb_ssh/compat/ruby.rb +0 -1
  42. data/lib/hrr_rb_ssh/connection.rb +145 -75
  43. data/lib/hrr_rb_ssh/connection/channel.rb +342 -109
  44. data/lib/hrr_rb_ssh/connection/channel/channel_type/direct_tcpip.rb +24 -19
  45. data/lib/hrr_rb_ssh/connection/channel/channel_type/forwarded_tcpip.rb +24 -19
  46. data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +19 -12
  47. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain.rb +0 -2
  48. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain/chain_context.rb +0 -3
  49. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb +2 -5
  50. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +5 -4
  51. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +2 -5
  52. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +5 -4
  53. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +2 -5
  54. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +5 -4
  55. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +2 -5
  56. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +5 -4
  57. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +2 -5
  58. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +5 -4
  59. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change.rb +2 -5
  60. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change/context.rb +5 -4
  61. data/lib/hrr_rb_ssh/connection/global_request_handler.rb +14 -12
  62. data/lib/hrr_rb_ssh/connection/request_handler.rb +1 -3
  63. data/lib/hrr_rb_ssh/connection/request_handler/reference_env_request_handler.rb +0 -2
  64. data/lib/hrr_rb_ssh/connection/request_handler/reference_exec_request_handler.rb +4 -6
  65. data/lib/hrr_rb_ssh/connection/request_handler/reference_pty_req_request_handler.rb +10 -12
  66. data/lib/hrr_rb_ssh/connection/request_handler/reference_shell_request_handler.rb +4 -6
  67. data/lib/hrr_rb_ssh/connection/request_handler/reference_window_change_request_handler.rb +0 -2
  68. data/lib/hrr_rb_ssh/error/closed_authentication.rb +1 -1
  69. data/lib/hrr_rb_ssh/error/closed_connection.rb +1 -1
  70. data/lib/hrr_rb_ssh/error/closed_transport.rb +1 -1
  71. data/lib/hrr_rb_ssh/loggable.rb +42 -0
  72. data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +2 -4
  73. data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +2 -4
  74. data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +2 -4
  75. data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +2 -4
  76. data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +2 -4
  77. data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +2 -4
  78. data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +2 -4
  79. data/lib/hrr_rb_ssh/message/021_ssh_msg_newkeys.rb +2 -4
  80. data/lib/hrr_rb_ssh/message/030_ssh_msg_kex_dh_gex_request_old.rb +2 -4
  81. data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +2 -4
  82. data/lib/hrr_rb_ssh/message/030_ssh_msg_kexecdh_init.rb +2 -4
  83. data/lib/hrr_rb_ssh/message/031_ssh_msg_kex_dh_gex_group.rb +2 -4
  84. data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +2 -4
  85. data/lib/hrr_rb_ssh/message/031_ssh_msg_kexecdh_reply.rb +2 -4
  86. data/lib/hrr_rb_ssh/message/032_ssh_msg_kex_dh_gex_init.rb +2 -4
  87. data/lib/hrr_rb_ssh/message/033_ssh_msg_kex_dh_gex_reply.rb +2 -4
  88. data/lib/hrr_rb_ssh/message/034_ssh_msg_kex_dh_gex_request.rb +2 -4
  89. data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +2 -4
  90. data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +2 -4
  91. data/lib/hrr_rb_ssh/message/052_ssh_msg_userauth_success.rb +2 -4
  92. data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_info_request.rb +2 -4
  93. data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_pk_ok.rb +2 -4
  94. data/lib/hrr_rb_ssh/message/061_ssh_msg_userauth_info_response.rb +2 -4
  95. data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +2 -4
  96. data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +2 -4
  97. data/lib/hrr_rb_ssh/message/082_ssh_msg_request_failure.rb +2 -4
  98. data/lib/hrr_rb_ssh/message/090_ssh_msg_channel_open.rb +2 -4
  99. data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +2 -4
  100. data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +2 -4
  101. data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +2 -4
  102. data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +2 -4
  103. data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +2 -4
  104. data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +2 -4
  105. data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +2 -4
  106. data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +3 -5
  107. data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +2 -4
  108. data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +2 -4
  109. data/lib/hrr_rb_ssh/server.rb +16 -10
  110. data/lib/hrr_rb_ssh/transport.rb +113 -77
  111. data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +5 -3
  112. data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +5 -3
  113. data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +5 -3
  114. data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +5 -3
  115. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +43 -37
  116. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman/h0.rb +2 -4
  117. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange.rb +87 -52
  118. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange/h0.rb +2 -4
  119. data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman.rb +43 -37
  120. data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman/h0.rb +2 -4
  121. data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +5 -3
  122. data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +5 -3
  123. data/lib/hrr_rb_ssh/transport/receiver.rb +8 -7
  124. data/lib/hrr_rb_ssh/transport/sender.rb +5 -3
  125. data/lib/hrr_rb_ssh/transport/sequence_number.rb +0 -4
  126. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +0 -1
  127. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/functionable.rb +5 -3
  128. data/lib/hrr_rb_ssh/version.rb +1 -1
  129. metadata +18 -51
  130. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519.rb +0 -61
  131. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/openssh_private_key.rb +0 -29
  132. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/openssh_private_key_content.rb +0 -26
  133. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/pkey.rb +0 -158
  134. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/public_key_blob.rb +0 -23
  135. data/lib/hrr_rb_ssh/algorithm/publickey/ssh_ed25519/signature.rb +0 -23
  136. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_ed25519.rb +0 -21
  137. data/lib/hrr_rb_ssh/compat/ruby/array.rb +0 -14
  138. data/lib/hrr_rb_ssh/logger.rb +0 -56
  139. 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
- logger = Logger.new self.class.name
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/logger'
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
- @logger = Logger.new self.class.name
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
- logger = Logger.new self.class.name
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
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/logger'
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
- @logger = Logger.new self.class.name
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
- logger = Logger.new self.class.name
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
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/logger'
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
- @logger = Logger.new self.class.name
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/logger'
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
- @logger = Logger.new self.class.name
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
- @logger.info { "closing tcpip-forward" }
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
- @logger.info { "tcpip-forward closed" }
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
- @logger.warn { "unsupported request name: #{message[:'request name']}" }
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
- @logger.info { "starting tcpip-forward" }
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
- @logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
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
- @logger.info { "tcpip-forward started" }
68
+ log_info { "tcpip-forward started" }
67
69
  rescue => e
68
- @logger.warn { "starting tcpip-forward failed: #{e.message}" }
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
- @logger.info { "canceling tcpip-forward" }
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
- @logger.info { "tcpip-forward canceled" }
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.logger.info { "program exited with status #{status.inspect}" }
59
+ context.log_info { "program exited with status #{status.inspect}" }
62
60
  status.exitstatus
63
61
  ensure
64
62
  unless status
65
- context.logger.info { "exiting program" }
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.logger.warn { "force exiting program" }
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.logger.info { "program exited with status #{status.inspect}" }
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.logger.info { "ptm is EOF in ptm_read_thread" }
33
+ context.log_info { "ptm is EOF in ptm_read_thread" }
36
34
  break
37
35
  rescue IOError => e
38
- context.logger.warn { "IO Error in ptm_read_thread" }
36
+ context.log_warn { "IO Error in ptm_read_thread" }
39
37
  break
40
38
  rescue Errno::EIO => e
41
- context.logger.info { "EIO Error in ptm_read_thread" }
39
+ context.log_info { "EIO Error in ptm_read_thread" }
42
40
  break
43
41
  rescue => e
44
- context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
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.logger.info { "IO is EOF in ptm_write_thread" }
52
+ context.log_info { "IO is EOF in ptm_write_thread" }
55
53
  break
56
54
  rescue IOError => e
57
- context.logger.warn { "IO Error in ptm_write_thread" }
55
+ context.log_warn { "IO Error in ptm_write_thread" }
58
56
  break
59
57
  rescue Errno::EIO => e
60
- context.logger.info { "EIO Error in ptm_read_thread" }
58
+ context.log_info { "EIO Error in ptm_read_thread" }
61
59
  break
62
60
  rescue => e
63
- context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
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.logger.info { "closing pty-req request handler chain_proc" }
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.logger.info { "pty-req request handler chain_proc closed" }
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.logger.info { "shell exited with status #{status.inspect}" }
50
+ context.log_info { "shell exited with status #{status.inspect}" }
53
51
  status.exitstatus
54
52
  ensure
55
53
  unless status
56
- context.logger.info { "exiting shell" }
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.logger.warn { "force exiting shell" }
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.logger.info { "shell exited with status #{status.inspect}" }
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
  }