winrm 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,114 +1,118 @@
1
- # WinRM Gem Changelog
2
-
3
- # 2.1.3
4
- - Ignore WSManFault 2150858843 during command cleanup
5
- - Uns `Integer` in place of `Fixnum` to remove deprecation warnings in ruby 2.4
6
-
7
- # 2.1.2
8
- - Fix kerberos transport
9
-
10
- # 2.1.1
11
- - Fix rendering of powershell output with non ascii UTF-8 characters emitted from executables
12
-
13
- # 2.1.0
14
- - Expose shell options when creating a winrm shell
15
-
16
- # 2.0.3
17
- - Do not swallow exit codes from executables
18
-
19
- # 2.0.2
20
- - Constrain to rubyntlm `>= 0.6.1` to avoid mutating frozen strings
21
- - When using certificate authentication, do not validate presense of user and password
22
- - Handle failed `PIPELINE_STATE` messages so that `throw` errors are not swallowed
23
-
24
- # 2.0.1
25
- - Fixed Powershell shell leakage when not explicitly closed
26
- - Fixed cmd commands with responses that extend beyond one stream
27
-
28
- # 2.0.0
29
- - Cleaned up API and implemented Powershell Remoting Protocol (PSRP) for all powershell calls.
30
-
31
- # 1.8.1
32
- - Http receive timeout should always be equal to 10 seconds greater than the winrm operation timeout and not default to one hour
33
-
34
- # 1.8.0
35
- - Add certificate authentication
36
-
37
- # 1.7.3
38
- - Open a new shell if the current shell has been deleted
39
-
40
- # 1.7.2
41
- - Fix regression where BOM appears in 2008R2 output and is not stripped
42
-
43
- # 1.7.1
44
- - Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
45
-
46
- # 1.7.0
47
- - Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
48
- - Fix for parsing binary data in command output
49
-
50
- # 1.6.1
51
- - Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
52
-
53
- # 1.6.0
54
- - Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
55
- - Removed dependency on UUIDTools gem
56
- - Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
57
- - Correct deprecation warning for WinRMWebService.run_powershell_script
58
-
59
- # 1.5.0
60
- - Deprecating `WinRM::WinRMWebService` methods `cmd`, `run_cmd`, `powershell`, and `run_powershell_script` in favor of the `run_cmd` and `run_powershell_script` methods of the `WinRM::CommandExecutor` class. The `CommandExecutor` allows multiple commands to be run from the same WinRM shell providing a significant performance improvement when issuing multiple calls.
61
- - Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
62
- - Opening a winrm shell is retriable with configurable delay and retry limit.
63
- - Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
64
-
65
- # 1.4.0
66
- - Added WinRM::Version so the gem version is available at runtime for consumers.
67
-
68
- # 1.3.6
69
- - Remove BOM from response (Issue #159) added by Windows 2008R2
70
-
71
- # 1.3.5
72
- - Widen logging version constraints to include 2.0
73
- - Use codepage 65001 (UTF-8)
74
-
75
- # 1.3.4
76
- - Relaxed version pins on dev dependencies
77
-
78
- # 1.3.3
79
- - Fixed issue 133, rwinrm allow hostnames with dashes
80
- - Use duck typing for powershell script read
81
-
82
- # 1.3.2
83
- - Add spec.license attribute to gemspec
84
- - Bump RSpec dependency 3.0 to 3.2
85
-
86
- # 1.3.1
87
- - Fixed issue 129, long running commands could cause a stackoverflow exception
88
- - Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
89
- - Fixed issue 124 rwinrm won't take '.' characters in username
90
-
91
- # 1.3.0
92
- - Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
93
- - Refactored and added more unit and integration tests
94
- - Added ability to write to stdin
95
- - Added rwinrm binary to launch remote shell
96
- - Added WINRM_LOG env var to set log level
97
- - Retry Kerberos auth once if 401 response is received
98
- - Remove Savon dependency and use newer versions of underlying dependencies
99
- - Remove Nokogiri dependency and replace with native Ruby XML
100
- - Fixed issue 85, ensure WQL response is not nil
101
- - All WinRM library errors inherit from base class WinRMError
102
- - Integrations tests should now pass on Windows Server 2008+
103
- - Bump Ruby NTLM gem version dependency
104
- - HTTP client receive timeout is now configurable via set_timeout
105
- - Added backwards compatible Output class to make it easier to collect output
106
- - Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
107
- - Added Rubocop to build
108
- - Fixed error when commands contain a newline character
109
-
110
- # 1.2.0
111
- - Allow user to disable SSL peer ceritifcate validation #44
112
- - Allow commands with "'" chars on Ruby 2.x, fixes #69
113
- - Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
114
- - Commands with non-ASCII chars should work, #70
1
+ # WinRM Gem Changelog
2
+
3
+ # 2.2.0
4
+ - Allow run_wql to accept custom namespace
5
+ - Allow enumeration of WQL result sets
6
+
7
+ # 2.1.3
8
+ - Ignore WSManFault 2150858843 during command cleanup
9
+ - Uns `Integer` in place of `Fixnum` to remove deprecation warnings in ruby 2.4
10
+
11
+ # 2.1.2
12
+ - Fix kerberos transport
13
+
14
+ # 2.1.1
15
+ - Fix rendering of powershell output with non ascii UTF-8 characters emitted from executables
16
+
17
+ # 2.1.0
18
+ - Expose shell options when creating a winrm shell
19
+
20
+ # 2.0.3
21
+ - Do not swallow exit codes from executables
22
+
23
+ # 2.0.2
24
+ - Constrain to rubyntlm `>= 0.6.1` to avoid mutating frozen strings
25
+ - When using certificate authentication, do not validate presense of user and password
26
+ - Handle failed `PIPELINE_STATE` messages so that `throw` errors are not swallowed
27
+
28
+ # 2.0.1
29
+ - Fixed Powershell shell leakage when not explicitly closed
30
+ - Fixed cmd commands with responses that extend beyond one stream
31
+
32
+ # 2.0.0
33
+ - Cleaned up API and implemented Powershell Remoting Protocol (PSRP) for all powershell calls.
34
+
35
+ # 1.8.1
36
+ - Http receive timeout should always be equal to 10 seconds greater than the winrm operation timeout and not default to one hour
37
+
38
+ # 1.8.0
39
+ - Add certificate authentication
40
+
41
+ # 1.7.3
42
+ - Open a new shell if the current shell has been deleted
43
+
44
+ # 1.7.2
45
+ - Fix regression where BOM appears in 2008R2 output and is not stripped
46
+
47
+ # 1.7.1
48
+ - Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
49
+
50
+ # 1.7.0
51
+ - Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
52
+ - Fix for parsing binary data in command output
53
+
54
+ # 1.6.1
55
+ - Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
56
+
57
+ # 1.6.0
58
+ - Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
59
+ - Removed dependency on UUIDTools gem
60
+ - Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
61
+ - Correct deprecation warning for WinRMWebService.run_powershell_script
62
+
63
+ # 1.5.0
64
+ - Deprecating `WinRM::WinRMWebService` methods `cmd`, `run_cmd`, `powershell`, and `run_powershell_script` in favor of the `run_cmd` and `run_powershell_script` methods of the `WinRM::CommandExecutor` class. The `CommandExecutor` allows multiple commands to be run from the same WinRM shell providing a significant performance improvement when issuing multiple calls.
65
+ - Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
66
+ - Opening a winrm shell is retriable with configurable delay and retry limit.
67
+ - Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
68
+
69
+ # 1.4.0
70
+ - Added WinRM::Version so the gem version is available at runtime for consumers.
71
+
72
+ # 1.3.6
73
+ - Remove BOM from response (Issue #159) added by Windows 2008R2
74
+
75
+ # 1.3.5
76
+ - Widen logging version constraints to include 2.0
77
+ - Use codepage 65001 (UTF-8)
78
+
79
+ # 1.3.4
80
+ - Relaxed version pins on dev dependencies
81
+
82
+ # 1.3.3
83
+ - Fixed issue 133, rwinrm allow hostnames with dashes
84
+ - Use duck typing for powershell script read
85
+
86
+ # 1.3.2
87
+ - Add spec.license attribute to gemspec
88
+ - Bump RSpec dependency 3.0 to 3.2
89
+
90
+ # 1.3.1
91
+ - Fixed issue 129, long running commands could cause a stackoverflow exception
92
+ - Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
93
+ - Fixed issue 124 rwinrm won't take '.' characters in username
94
+
95
+ # 1.3.0
96
+ - Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
97
+ - Refactored and added more unit and integration tests
98
+ - Added ability to write to stdin
99
+ - Added rwinrm binary to launch remote shell
100
+ - Added WINRM_LOG env var to set log level
101
+ - Retry Kerberos auth once if 401 response is received
102
+ - Remove Savon dependency and use newer versions of underlying dependencies
103
+ - Remove Nokogiri dependency and replace with native Ruby XML
104
+ - Fixed issue 85, ensure WQL response is not nil
105
+ - All WinRM library errors inherit from base class WinRMError
106
+ - Integrations tests should now pass on Windows Server 2008+
107
+ - Bump Ruby NTLM gem version dependency
108
+ - HTTP client receive timeout is now configurable via set_timeout
109
+ - Added backwards compatible Output class to make it easier to collect output
110
+ - Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
111
+ - Added Rubocop to build
112
+ - Fixed error when commands contain a newline character
113
+
114
+ # 1.2.0
115
+ - Allow user to disable SSL peer ceritifcate validation #44
116
+ - Allow commands with "'" chars on Ruby 2.x, fixes #69
117
+ - Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
118
+ - Commands with non-ASCII chars should work, #70
@@ -1,83 +1,86 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require_relative 'connection_opts'
18
- require_relative 'http/transport_factory'
19
- require_relative 'shells/shell_factory'
20
- require_relative 'wsmv/wql_query'
21
-
22
- module WinRM
23
- # WinRM connection used to establish a session with the remote WinRM service.
24
- class Connection
25
- # Creates a new WinRM connection
26
- # See the ConnectionOpts class for connection options.
27
- def initialize(connection_opts)
28
- configure_connection_opts(connection_opts)
29
- configure_logger
30
- end
31
-
32
- attr_accessor :logger
33
-
34
- # Creates a new shell on the remote Windows server associated with
35
- # this connection.
36
- # @param shell_type [Symbol] The shell type :cmd or :powershell
37
- # @param shell_opts [Hash] Options targeted for the created shell
38
- # @return [Shell] PowerShell or Cmd shell instance.
39
- def shell(shell_type, shell_opts = {})
40
- shell = shell_factory.create_shell(shell_type, shell_opts)
41
- if block_given?
42
- begin
43
- yield shell
44
- ensure
45
- shell.close
46
- end
47
- else
48
- shell
49
- end
50
- end
51
-
52
- # Executes a WQL query against the WinRM connection
53
- # @param wql [String] The wql query
54
- # @return [Hash] Hash representation of wql query response
55
- def run_wql(wql)
56
- query = WinRM::WSMV::WqlQuery.new(@connection_opts, wql)
57
- query.process_response(transport.send_request(query.build))
58
- end
59
-
60
- private
61
-
62
- def configure_connection_opts(connection_opts)
63
- @connection_opts = ConnectionOpts.create_with_defaults(connection_opts)
64
- end
65
-
66
- def configure_logger
67
- @logger = Logging.logger[self]
68
- logger.level = :warn
69
- logger.add_appenders(Logging.appenders.stdout)
70
- end
71
-
72
- def shell_factory
73
- @shell_factory ||= WinRM::Shells::ShellFactory.new(@connection_opts, transport, logger)
74
- end
75
-
76
- def transport
77
- @transport ||= begin
78
- transport_factory = WinRM::HTTP::TransportFactory.new
79
- transport_factory.create_transport(@connection_opts)
80
- end
81
- end
82
- end
83
- end
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'connection_opts'
18
+ require_relative 'http/transport_factory'
19
+ require_relative 'shells/shell_factory'
20
+ require_relative 'wsmv/wql_query'
21
+ require_relative 'wsmv/wql_pull'
22
+
23
+ module WinRM
24
+ # WinRM connection used to establish a session with the remote WinRM service.
25
+ class Connection
26
+ # Creates a new WinRM connection
27
+ # See the ConnectionOpts class for connection options.
28
+ def initialize(connection_opts)
29
+ configure_connection_opts(connection_opts)
30
+ configure_logger
31
+ end
32
+
33
+ attr_accessor :logger
34
+
35
+ # Creates a new shell on the remote Windows server associated with
36
+ # this connection.
37
+ # @param shell_type [Symbol] The shell type :cmd or :powershell
38
+ # @param shell_opts [Hash] Options targeted for the created shell
39
+ # @return [Shell] PowerShell or Cmd shell instance.
40
+ def shell(shell_type, shell_opts = {})
41
+ shell = shell_factory.create_shell(shell_type, shell_opts)
42
+ if block_given?
43
+ begin
44
+ yield shell
45
+ ensure
46
+ shell.close
47
+ end
48
+ else
49
+ shell
50
+ end
51
+ end
52
+
53
+ # Executes a WQL query against the WinRM connection
54
+ # @param wql [String] The wql query
55
+ # @param namespace [String] namespace for query - default is root/cimv2/*
56
+ # @return [Hash] Hash representation of wql query response (Hash is empty if a block is given)
57
+ # @yeild [type, item] Yields the time name and item for every item
58
+ def run_wql(wql, namespace = 'root/cimv2/*', &block)
59
+ query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace)
60
+ query.process_response(transport.send_request(query.build), &block)
61
+ end
62
+
63
+ private
64
+
65
+ def configure_connection_opts(connection_opts)
66
+ @connection_opts = ConnectionOpts.create_with_defaults(connection_opts)
67
+ end
68
+
69
+ def configure_logger
70
+ @logger = Logging.logger[self]
71
+ logger.level = :warn
72
+ logger.add_appenders(Logging.appenders.stdout)
73
+ end
74
+
75
+ def shell_factory
76
+ @shell_factory ||= WinRM::Shells::ShellFactory.new(@connection_opts, transport, logger)
77
+ end
78
+
79
+ def transport
80
+ @transport ||= begin
81
+ transport_factory = WinRM::HTTP::TransportFactory.new
82
+ transport_factory.create_transport(@connection_opts)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,7 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- # WinRM module
4
- module WinRM
5
- # The version of the WinRM library
6
- VERSION = '2.1.3'.freeze
7
- end
1
+ # encoding: UTF-8
2
+
3
+ # WinRM module
4
+ module WinRM
5
+ # The version of the WinRM library
6
+ VERSION = '2.2.0'.freeze
7
+ end
@@ -1,203 +1,215 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- # rubocop:disable Metrics/MethodLength
18
-
19
- require_relative 'soap'
20
- require_relative 'iso8601_duration'
21
-
22
- module WinRM
23
- module WSMV
24
- # SOAP header utility mixin
25
- module Header
26
- # WSMan URI of the regular Windows cmd shell
27
- RESOURCE_URI_CMD = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd'.freeze
28
-
29
- # WSMan URI for PowerShell
30
- RESOURCE_URI_POWERSHELL = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'.freeze
31
-
32
- # Merge the various header hashes and make sure we carry all of the attributes
33
- # through instead of overwriting them.
34
- def merge_headers(*headers)
35
- hdr = {}
36
- headers.each do |h|
37
- hdr.merge!(h) do |k, v1, v2|
38
- v1.merge!(v2) if k == :attributes!
39
- end
40
- end
41
- hdr
42
- end
43
-
44
- def shared_headers(session_opts)
45
- {
46
- "#{SOAP::NS_ADDRESSING}:To" => session_opts[:endpoint],
47
- "#{SOAP::NS_ADDRESSING}:ReplyTo" => {
48
- "#{SOAP::NS_ADDRESSING}:Address" =>
49
- 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous',
50
- :attributes! => {
51
- "#{SOAP::NS_ADDRESSING}:Address" => {
52
- 'mustUnderstand' => true
53
- }
54
- }
55
- },
56
- "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => session_opts[:max_envelope_size],
57
- "#{SOAP::NS_ADDRESSING}:MessageID" => "uuid:#{SecureRandom.uuid.to_s.upcase}",
58
- "#{SOAP::NS_WSMAN_MSFT}:SessionId" => "uuid:#{session_opts[:session_id]}",
59
- "#{SOAP::NS_WSMAN_DMTF}:Locale/" => '',
60
- "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => '',
61
- "#{SOAP::NS_WSMAN_DMTF}:OperationTimeout" =>
62
- Iso8601Duration.sec_to_dur(session_opts[:operation_timeout]),
63
- :attributes! => {
64
- "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => { 'mustUnderstand' => true },
65
- "#{SOAP::NS_WSMAN_DMTF}:Locale/" => {
66
- 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
67
- },
68
- "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => {
69
- 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
70
- },
71
- "#{SOAP::NS_WSMAN_MSFT}:SessionId" => { 'mustUnderstand' => false }
72
- }
73
- }
74
- end
75
-
76
- # Helper methods for SOAP Headers
77
-
78
- def resource_uri_shell(shell_uri)
79
- {
80
- "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => shell_uri, :attributes! => {
81
- "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
82
- 'mustUnderstand' => true
83
- }
84
- }
85
- }
86
- end
87
-
88
- def resource_uri_cmd
89
- resource_uri_shell(RESOURCE_URI_CMD)
90
- end
91
-
92
- def resource_uri_wmi(namespace = 'root/cimv2/*')
93
- {
94
- "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" =>
95
- "http://schemas.microsoft.com/wbem/wsman/1/wmi/#{namespace}",
96
- :attributes! => {
97
- "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
98
- 'mustUnderstand' => true
99
- }
100
- }
101
- }
102
- end
103
-
104
- def action_get
105
- {
106
- "#{SOAP::NS_ADDRESSING}:Action" =>
107
- 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get',
108
- :attributes! => {
109
- "#{SOAP::NS_ADDRESSING}:Action" => {
110
- 'mustUnderstand' => true
111
- }
112
- }
113
- }
114
- end
115
-
116
- def action_delete
117
- {
118
- "#{SOAP::NS_ADDRESSING}:Action" =>
119
- 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete',
120
- :attributes! => {
121
- "#{SOAP::NS_ADDRESSING}:Action" => {
122
- 'mustUnderstand' => true
123
- }
124
- }
125
- }
126
- end
127
-
128
- def action_command
129
- {
130
- "#{SOAP::NS_ADDRESSING}:Action" =>
131
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command',
132
- :attributes! => {
133
- "#{SOAP::NS_ADDRESSING}:Action" => {
134
- 'mustUnderstand' => true
135
- }
136
- }
137
- }
138
- end
139
-
140
- def action_receive
141
- {
142
- "#{SOAP::NS_ADDRESSING}:Action" =>
143
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive',
144
- :attributes! => {
145
- "#{SOAP::NS_ADDRESSING}:Action" => {
146
- 'mustUnderstand' => true
147
- }
148
- }
149
- }
150
- end
151
-
152
- def action_send
153
- {
154
- "#{SOAP::NS_ADDRESSING}:Action" =>
155
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
156
- :attributes! => {
157
- "#{SOAP::NS_ADDRESSING}:Action" => {
158
- 'mustUnderstand' => true
159
- }
160
- }
161
- }
162
- end
163
-
164
- def action_signal
165
- {
166
- "#{SOAP::NS_ADDRESSING}:Action" =>
167
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal',
168
- :attributes! => {
169
- "#{SOAP::NS_ADDRESSING}:Action" => {
170
- 'mustUnderstand' => true
171
- }
172
- }
173
- }
174
- end
175
-
176
- def action_enumerate
177
- {
178
- "#{SOAP::NS_ADDRESSING}:Action" =>
179
- 'http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate',
180
- :attributes! => {
181
- "#{SOAP::NS_ADDRESSING}:Action" => {
182
- 'mustUnderstand' => true
183
- }
184
- }
185
- }
186
- end
187
-
188
- def selector_shell_id(shell_id)
189
- {
190
- "#{SOAP::NS_WSMAN_DMTF}:SelectorSet" => {
191
- "#{SOAP::NS_WSMAN_DMTF}:Selector" => shell_id, :attributes! => {
192
- "#{SOAP::NS_WSMAN_DMTF}:Selector" => {
193
- 'Name' => 'ShellId'
194
- }
195
- }
196
- }
197
- }
198
- end
199
- end
200
- end
201
- end
202
-
203
- # rubocop:enable Metrics/MethodLength
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # rubocop:disable Metrics/MethodLength
18
+
19
+ require_relative 'soap'
20
+ require_relative 'iso8601_duration'
21
+
22
+ module WinRM
23
+ module WSMV
24
+ # SOAP header utility mixin
25
+ module Header
26
+ # WSMan URI of the regular Windows cmd shell
27
+ RESOURCE_URI_CMD = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd'.freeze
28
+
29
+ # WSMan URI for PowerShell
30
+ RESOURCE_URI_POWERSHELL = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'.freeze
31
+
32
+ # Merge the various header hashes and make sure we carry all of the attributes
33
+ # through instead of overwriting them.
34
+ def merge_headers(*headers)
35
+ hdr = {}
36
+ headers.each do |h|
37
+ hdr.merge!(h) do |k, v1, v2|
38
+ v1.merge!(v2) if k == :attributes!
39
+ end
40
+ end
41
+ hdr
42
+ end
43
+
44
+ def shared_headers(session_opts)
45
+ {
46
+ "#{SOAP::NS_ADDRESSING}:To" => session_opts[:endpoint],
47
+ "#{SOAP::NS_ADDRESSING}:ReplyTo" => {
48
+ "#{SOAP::NS_ADDRESSING}:Address" =>
49
+ 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous',
50
+ :attributes! => {
51
+ "#{SOAP::NS_ADDRESSING}:Address" => {
52
+ 'mustUnderstand' => true
53
+ }
54
+ }
55
+ },
56
+ "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => session_opts[:max_envelope_size],
57
+ "#{SOAP::NS_ADDRESSING}:MessageID" => "uuid:#{SecureRandom.uuid.to_s.upcase}",
58
+ "#{SOAP::NS_WSMAN_MSFT}:SessionId" => "uuid:#{session_opts[:session_id]}",
59
+ "#{SOAP::NS_WSMAN_DMTF}:Locale/" => '',
60
+ "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => '',
61
+ "#{SOAP::NS_WSMAN_DMTF}:OperationTimeout" =>
62
+ Iso8601Duration.sec_to_dur(session_opts[:operation_timeout]),
63
+ :attributes! => {
64
+ "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => { 'mustUnderstand' => true },
65
+ "#{SOAP::NS_WSMAN_DMTF}:Locale/" => {
66
+ 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
67
+ },
68
+ "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => {
69
+ 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
70
+ },
71
+ "#{SOAP::NS_WSMAN_MSFT}:SessionId" => { 'mustUnderstand' => false }
72
+ }
73
+ }
74
+ end
75
+
76
+ # Helper methods for SOAP Headers
77
+
78
+ def resource_uri_shell(shell_uri)
79
+ {
80
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => shell_uri, :attributes! => {
81
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
82
+ 'mustUnderstand' => true
83
+ }
84
+ }
85
+ }
86
+ end
87
+
88
+ def resource_uri_cmd
89
+ resource_uri_shell(RESOURCE_URI_CMD)
90
+ end
91
+
92
+ def resource_uri_wmi(namespace = 'root/cimv2/*')
93
+ {
94
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" =>
95
+ "http://schemas.microsoft.com/wbem/wsman/1/wmi/#{namespace}",
96
+ :attributes! => {
97
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
98
+ 'mustUnderstand' => true
99
+ }
100
+ }
101
+ }
102
+ end
103
+
104
+ def action_get
105
+ {
106
+ "#{SOAP::NS_ADDRESSING}:Action" =>
107
+ 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get',
108
+ :attributes! => {
109
+ "#{SOAP::NS_ADDRESSING}:Action" => {
110
+ 'mustUnderstand' => true
111
+ }
112
+ }
113
+ }
114
+ end
115
+
116
+ def action_delete
117
+ {
118
+ "#{SOAP::NS_ADDRESSING}:Action" =>
119
+ 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete',
120
+ :attributes! => {
121
+ "#{SOAP::NS_ADDRESSING}:Action" => {
122
+ 'mustUnderstand' => true
123
+ }
124
+ }
125
+ }
126
+ end
127
+
128
+ def action_command
129
+ {
130
+ "#{SOAP::NS_ADDRESSING}:Action" =>
131
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command',
132
+ :attributes! => {
133
+ "#{SOAP::NS_ADDRESSING}:Action" => {
134
+ 'mustUnderstand' => true
135
+ }
136
+ }
137
+ }
138
+ end
139
+
140
+ def action_receive
141
+ {
142
+ "#{SOAP::NS_ADDRESSING}:Action" =>
143
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive',
144
+ :attributes! => {
145
+ "#{SOAP::NS_ADDRESSING}:Action" => {
146
+ 'mustUnderstand' => true
147
+ }
148
+ }
149
+ }
150
+ end
151
+
152
+ def action_send
153
+ {
154
+ "#{SOAP::NS_ADDRESSING}:Action" =>
155
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
156
+ :attributes! => {
157
+ "#{SOAP::NS_ADDRESSING}:Action" => {
158
+ 'mustUnderstand' => true
159
+ }
160
+ }
161
+ }
162
+ end
163
+
164
+ def action_signal
165
+ {
166
+ "#{SOAP::NS_ADDRESSING}:Action" =>
167
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal',
168
+ :attributes! => {
169
+ "#{SOAP::NS_ADDRESSING}:Action" => {
170
+ 'mustUnderstand' => true
171
+ }
172
+ }
173
+ }
174
+ end
175
+
176
+ def action_enumerate
177
+ {
178
+ "#{SOAP::NS_ADDRESSING}:Action" =>
179
+ 'http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate',
180
+ :attributes! => {
181
+ "#{SOAP::NS_ADDRESSING}:Action" => {
182
+ 'mustUnderstand' => true
183
+ }
184
+ }
185
+ }
186
+ end
187
+
188
+ def action_enumerate_pull
189
+ {
190
+ "#{SOAP::NS_ADDRESSING}:Action" =>
191
+ 'http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull',
192
+ :attributes! => {
193
+ "#{SOAP::NS_ADDRESSING}:Action" => {
194
+ 'mustUnderstand' => true
195
+ }
196
+ }
197
+ }
198
+ end
199
+
200
+ def selector_shell_id(shell_id)
201
+ {
202
+ "#{SOAP::NS_WSMAN_DMTF}:SelectorSet" => {
203
+ "#{SOAP::NS_WSMAN_DMTF}:Selector" => shell_id, :attributes! => {
204
+ "#{SOAP::NS_WSMAN_DMTF}:Selector" => {
205
+ 'Name' => 'ShellId'
206
+ }
207
+ }
208
+ }
209
+ }
210
+ end
211
+ end
212
+ end
213
+ end
214
+
215
+ # rubocop:enable Metrics/MethodLength