winrm 2.3.1 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc2dfd4574c525ca194a12eb9cbc41b8bc0213b5927c5a7bf570d3010e58d9c8
4
- data.tar.gz: f3a9877260b7fd617653d7665136534c5e3761da289ab51d89bbd674cefd80d6
3
+ metadata.gz: d70e24f7a32d8dac9c3d3a7c1675c40af3431df4e5c9a1b202cd87de21bb0a1f
4
+ data.tar.gz: 839b983ad19d3172c56cac95955efd20191a5f80880a53197366d2ef44b7dd4a
5
5
  SHA512:
6
- metadata.gz: ac8268cd7fad1e4d9a04deddbe4fdb097e4869fb52304d27fb23f55b79a0b44a00028f6c1e7fa3833d45f5d59f350c16c2f23d3cd105ccfe7e76b6f4d27c2936
7
- data.tar.gz: 271f9696f1d960a19ad73315b363f626cd8d51eda1ce742d499b5419b57c58665612b196add8e43fd8dfd5a7461822676bf3bb03b374b09cf8aa2db6cc667d77
6
+ metadata.gz: 20d3f20e5ddf0dc50519145c6bb13b40c1e5da21770510a50fd529bb2afb4b87ea3f55cde0a6653ccffdd1368a041c98992957800a9b45a016e8f6fd113eac61
7
+ data.tar.gz: 01ad60c5c78598ebf17434a02b0b4848eaeb605d2f5871edd11dc16be8c627d1bb8bf4390a282f80ebaaced51564858b5d2a82c552c608115054b78e4ad0e4dc
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'rexml/document'
15
+ require 'rexml/document' unless defined?(REXML::Document)
16
16
  require_relative '../wsmv/soap'
17
17
 
18
18
  module WinRM
@@ -435,7 +435,7 @@ module WinRM
435
435
  str.sub!(%r{^.*Content-Type: application\/octet-stream\r\n(.*)--Encrypted.*$}m, '\1')
436
436
 
437
437
  len = str.unpack('L').first
438
- iov_data = str.unpack("LA#{len}A*")
438
+ iov_data = str.unpack("La#{len}a*")
439
439
  iov0[:buffer].value = iov_data[1]
440
440
  iov1[:buffer].value = iov_data[2]
441
441
 
@@ -48,6 +48,8 @@ module WinRM
48
48
 
49
49
  def property_hash(prop_name)
50
50
  prop_nodes = REXML::XPath.first(doc, "//*[@N='#{prop_name}']/Props")
51
+ return {} if prop_nodes.nil?
52
+
51
53
  prop_nodes.elements.each_with_object({}) do |node, props|
52
54
  name = node.attributes['N']
53
55
  props[underscore(name).to_sym] = node.text if node.text
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'rexml/document'
15
+ require 'rexml/document' unless defined?(REXML::Document)
16
16
 
17
17
  module WinRM
18
18
  module PSRP
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'erubis'
15
+ require 'erubi'
16
16
  require_relative 'message'
17
17
 
18
18
  module WinRM
@@ -66,7 +66,19 @@ module WinRM
66
66
  "#{File.dirname(__FILE__)}/#{template}.xml.erb"
67
67
  )
68
68
  template = File.read(template_path)
69
- Erubis::Eruby.new(template).result(context)
69
+ case context
70
+ when Hash
71
+ b = binding
72
+ locals = context.collect { |k, _| "#{k} = context[#{k.inspect}]; " }
73
+ b.eval(locals.join)
74
+ when Binding
75
+ b = context
76
+ when NilClass
77
+ b = binding
78
+ else
79
+ raise ArgumentError
80
+ end
81
+ b.eval(Erubi::Engine.new(template).src)
70
82
  end
71
83
  end
72
84
  end
@@ -1,142 +1,142 @@
1
- # Copyright 2016 Matt Wrock <matt@mattwrock.com>
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'base64'
16
- require_relative 'message'
17
- require_relative 'message_data/pipeline_state'
18
-
19
- module WinRM
20
- module PSRP
21
- # Handles decoding a raw powershell output response
22
- class PowershellOutputDecoder
23
- # rubocop:disable Metrics/CyclomaticComplexity
24
- # Decode the raw SOAP output into decoded PSRP message,
25
- # Removes BOM and replaces encoded line endings
26
- # @param raw_output [String] The raw encoded output
27
- # @return [String] The decoded output
28
- def decode(message)
29
- case message.type
30
- when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output]
31
- decode_pipeline_output(message)
32
- when WinRM::PSRP::Message::MESSAGE_TYPES[:runspacepool_host_call]
33
- decode_host_call(message)
34
- when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call]
35
- decode_host_call(message)
36
- when WinRM::PSRP::Message::MESSAGE_TYPES[:error_record]
37
- decode_error_record(message)
38
- when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
39
- if message.parsed_data.pipeline_state == WinRM::PSRP::MessageData::PipelineState::FAILED
40
- decode_error_record(message)
41
- end
42
- end
43
- end
44
- # rubocop:enable Metrics/CyclomaticComplexity
45
-
46
- protected
47
-
48
- def decode_pipeline_output(message)
49
- message.parsed_data.output
50
- end
51
-
52
- def decode_host_call(message)
53
- text = begin
54
- case message.parsed_data.method_identifier
55
- when /WriteLine/, 'WriteErrorLine'
56
- "#{message.parsed_data.method_parameters[:s]}\r\n"
57
- when 'WriteDebugLine'
58
- "Debug: #{message.parsed_data.method_parameters[:s]}\r\n"
59
- when 'WriteWarningLine'
60
- "Warning: #{message.parsed_data.method_parameters[:s]}\r\n"
61
- when 'WriteVerboseLine'
62
- "Verbose: #{message.parsed_data.method_parameters[:s]}\r\n"
63
- when /Write[1-2]/
64
- message.parsed_data.method_parameters[:s]
65
- end
66
- end
67
-
68
- hex_decode(text)
69
- end
70
-
71
- def decode_error_record(message)
72
- parsed = message.parsed_data
73
- text = begin
74
- if message.type == WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
75
- render_exception_as_error_record(parsed.exception_as_error_record)
76
- else
77
- case parsed.fully_qualified_error_id
78
- when 'Microsoft.PowerShell.Commands.WriteErrorException'
79
- render_write_error_exception(parsed)
80
- when 'NativeCommandError'
81
- render_native_command_error(parsed)
82
- when 'NativeCommandErrorMessage'
83
- parsed.exception[:message]
84
- else
85
- render_exception(parsed)
86
- end
87
- end
88
- end
89
-
90
- hex_decode(text)
91
- end
92
-
93
- def render_write_error_exception(parsed)
94
- <<EOH
95
- #{parsed.invocation_info[:line]} : #{parsed.exception[:message]}
96
- + CategoryInfo : #{parsed.error_category_message}
97
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
98
- EOH
99
- end
100
-
101
- def render_exception(parsed)
102
- <<EOH
103
- #{parsed.exception[:message]}
104
- #{parsed.invocation_info[:position_message]}
105
- + CategoryInfo : #{parsed.error_category_message}
106
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
107
- EOH
108
- end
109
-
110
- def render_native_command_error(parsed)
111
- <<EOH
112
- #{parsed.invocation_info[:my_command]} : #{parsed.exception[:message]}
113
- + CategoryInfo : #{parsed.error_category_message}
114
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
115
- EOH
116
- end
117
-
118
- def render_exception_as_error_record(parsed)
119
- <<EOH
120
- #{parsed.exception[:message]}
121
- + CategoryInfo : #{parsed.error_category_message}
122
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
123
- EOH
124
- end
125
-
126
- private
127
-
128
- def hex_decode(text)
129
- return unless text
130
-
131
- text.gsub(/_x(\h\h\h\h)_/) do
132
- decoded_text = Regexp.last_match[1].hex.chr.force_encoding('utf-8')
133
- if decoded_text.respond_to?(:scrub)
134
- decoded_text.scrub
135
- else
136
- decoded_text.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8')
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end
1
+ # Copyright 2016 Matt Wrock <matt@mattwrock.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'base64' unless defined?(Base64)
16
+ require_relative 'message'
17
+ require_relative 'message_data/pipeline_state'
18
+
19
+ module WinRM
20
+ module PSRP
21
+ # Handles decoding a raw powershell output response
22
+ class PowershellOutputDecoder
23
+ # rubocop:disable Metrics/CyclomaticComplexity
24
+ # Decode the raw SOAP output into decoded PSRP message,
25
+ # Removes BOM and replaces encoded line endings
26
+ # @param raw_output [String] The raw encoded output
27
+ # @return [String] The decoded output
28
+ def decode(message)
29
+ case message.type
30
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output]
31
+ decode_pipeline_output(message)
32
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:runspacepool_host_call]
33
+ decode_host_call(message)
34
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call]
35
+ decode_host_call(message)
36
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:error_record]
37
+ decode_error_record(message)
38
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
39
+ if message.parsed_data.pipeline_state == WinRM::PSRP::MessageData::PipelineState::FAILED
40
+ decode_error_record(message)
41
+ end
42
+ end
43
+ end
44
+ # rubocop:enable Metrics/CyclomaticComplexity
45
+
46
+ protected
47
+
48
+ def decode_pipeline_output(message)
49
+ message.parsed_data.output
50
+ end
51
+
52
+ def decode_host_call(message)
53
+ text = begin
54
+ case message.parsed_data.method_identifier
55
+ when /WriteLine/, 'WriteErrorLine'
56
+ "#{message.parsed_data.method_parameters[:s]}\r\n"
57
+ when 'WriteDebugLine'
58
+ "Debug: #{message.parsed_data.method_parameters[:s]}\r\n"
59
+ when 'WriteWarningLine'
60
+ "Warning: #{message.parsed_data.method_parameters[:s]}\r\n"
61
+ when 'WriteVerboseLine'
62
+ "Verbose: #{message.parsed_data.method_parameters[:s]}\r\n"
63
+ when /Write[1-2]/
64
+ message.parsed_data.method_parameters[:s]
65
+ end
66
+ end
67
+
68
+ hex_decode(text)
69
+ end
70
+
71
+ def decode_error_record(message)
72
+ parsed = message.parsed_data
73
+ text = begin
74
+ if message.type == WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
75
+ render_exception_as_error_record(parsed.exception_as_error_record)
76
+ else
77
+ case parsed.fully_qualified_error_id
78
+ when 'Microsoft.PowerShell.Commands.WriteErrorException'
79
+ render_write_error_exception(parsed)
80
+ when 'NativeCommandError'
81
+ render_native_command_error(parsed)
82
+ when 'NativeCommandErrorMessage'
83
+ parsed.exception[:message]
84
+ else
85
+ render_exception(parsed)
86
+ end
87
+ end
88
+ end
89
+
90
+ hex_decode(text)
91
+ end
92
+
93
+ def render_write_error_exception(parsed)
94
+ <<EOH
95
+ #{parsed.invocation_info[:line]} : #{parsed.exception[:message]}
96
+ + CategoryInfo : #{parsed.error_category_message}
97
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
98
+ EOH
99
+ end
100
+
101
+ def render_exception(parsed)
102
+ <<EOH
103
+ #{parsed.exception[:message]}
104
+ #{parsed.invocation_info[:position_message]}
105
+ + CategoryInfo : #{parsed.error_category_message}
106
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
107
+ EOH
108
+ end
109
+
110
+ def render_native_command_error(parsed)
111
+ <<EOH
112
+ #{parsed.invocation_info[:my_command]} : #{parsed.exception[:message]}
113
+ + CategoryInfo : #{parsed.error_category_message}
114
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
115
+ EOH
116
+ end
117
+
118
+ def render_exception_as_error_record(parsed)
119
+ <<EOH
120
+ #{parsed.exception[:message]}
121
+ + CategoryInfo : #{parsed.error_category_message}
122
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
123
+ EOH
124
+ end
125
+
126
+ private
127
+
128
+ def hex_decode(text)
129
+ return unless text
130
+
131
+ text.gsub(/_x(\h\h\h\h)_/) do
132
+ decoded_text = Regexp.last_match[1].hex.chr.force_encoding('utf-8')
133
+ if decoded_text.respond_to?(:scrub)
134
+ decoded_text.scrub
135
+ else
136
+ decoded_text.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8')
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -147,6 +147,7 @@ module WinRM
147
147
  end
148
148
 
149
149
  def cleanup_command(command_id)
150
+ return unless shell_id
150
151
  logger.debug("[WinRM] cleaning up command_id: #{command_id} on shell_id #{shell_id}")
151
152
  cleanup_msg = WinRM::WSMV::CleanupCommand.new(
152
153
  connection_opts,
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'securerandom'
15
+ require 'securerandom' unless defined?(SecureRandom)
16
16
  require_relative 'base'
17
17
  require_relative '../psrp/message_fragmenter'
18
18
  require_relative '../psrp/receive_response_reader'
@@ -152,8 +152,9 @@ module WinRM
152
152
  msg = config_msg.build
153
153
  resp_doc = transport.send_request(msg)
154
154
  REXML::XPath.first(resp_doc, "//*[local-name() = 'MaxEnvelopeSizekb']").text.to_i
155
- ensure
156
- logger.debug("[WinRM] Endpoint doesn't support config request for MaxEnvelopsizekb")
155
+ rescue REXML::ParseException
156
+ logger.debug("[WinRM] Endpoint doesn't support config request for MaxEnvelopeSizekb")
157
+ raise
157
158
  end
158
159
  # rubocop:enable Layout/RescueEnsureAlignment
159
160
  end
@@ -1,5 +1,5 @@
1
1
  # WinRM module
2
2
  module WinRM
3
3
  # The version of the WinRM library
4
- VERSION = '2.3.1'.freeze
4
+ VERSION = '2.3.6'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Wanek
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-12-19 00:00:00.000000000 Z
14
+ date: 2021-01-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: builder
@@ -28,19 +28,19 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.1.2
30
30
  - !ruby/object:Gem::Dependency
31
- name: erubis
31
+ name: erubi
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: '2.7'
36
+ version: '1.8'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '2.7'
43
+ version: '1.8'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: gssapi
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +171,20 @@ dependencies:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: rexml
176
+ requirement: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ type: :development
182
+ prerelease: false
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
174
188
  - !ruby/object:Gem::Dependency
175
189
  name: rspec
176
190
  requirement: !ruby/object:Gem::Requirement
@@ -208,7 +222,7 @@ dependencies:
208
222
  version: 0.6.0
209
223
  - - ">="
210
224
  - !ruby/object:Gem::Version
211
- version: 0.6.1
225
+ version: 0.6.3
212
226
  type: :runtime
213
227
  prerelease: false
214
228
  version_requirements: !ruby/object:Gem::Requirement
@@ -218,7 +232,7 @@ dependencies:
218
232
  version: 0.6.0
219
233
  - - ">="
220
234
  - !ruby/object:Gem::Version
221
- version: 0.6.1
235
+ version: 0.6.3
222
236
  description: " Ruby library for Windows Remote Management\n"
223
237
  email:
224
238
  - dan.wanek@gmail.com
@@ -311,8 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
325
  - !ruby/object:Gem::Version
312
326
  version: '0'
313
327
  requirements: []
314
- rubyforge_project:
315
- rubygems_version: 2.7.6
328
+ rubygems_version: 3.1.4
316
329
  signing_key:
317
330
  specification_version: 4
318
331
  summary: Ruby library for Windows Remote Management