winrm 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rubocop.yml +26 -26
- data/.travis.yml +11 -11
- data/Gemfile +3 -3
- data/README.md +260 -233
- data/Rakefile +34 -34
- data/Vagrantfile +6 -6
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/changelog.md +104 -101
- data/lib/winrm.rb +39 -39
- data/lib/winrm/connection.rb +83 -82
- data/lib/winrm/connection_opts.rb +91 -91
- data/lib/winrm/exceptions.rb +76 -76
- data/lib/winrm/http/response_handler.rb +96 -96
- data/lib/winrm/http/transport.rb +424 -424
- data/lib/winrm/http/transport_factory.rb +68 -68
- data/lib/winrm/output.rb +59 -59
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -167
- data/lib/winrm/psrp/fragment.rb +70 -70
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -224
- data/lib/winrm/psrp/message.rb +130 -130
- data/lib/winrm/psrp/message_data.rb +42 -42
- data/lib/winrm/psrp/message_data/base.rb +49 -49
- data/lib/winrm/psrp/message_data/error_record.rb +68 -68
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -32
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -49
- data/lib/winrm/psrp/message_data/pipeline_state.rb +40 -40
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -32
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -39
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -36
- data/lib/winrm/psrp/message_defragmenter.rb +62 -62
- data/lib/winrm/psrp/message_factory.rb +75 -75
- data/lib/winrm/psrp/message_fragmenter.rb +60 -60
- data/lib/winrm/psrp/powershell_output_decoder.rb +139 -139
- data/lib/winrm/psrp/receive_response_reader.rb +97 -97
- data/lib/winrm/psrp/session_capability.xml.erb +7 -7
- data/lib/winrm/psrp/uuid.rb +40 -40
- data/lib/winrm/shells/base.rb +180 -175
- data/lib/winrm/shells/cmd.rb +65 -65
- data/lib/winrm/shells/power_shell.rb +202 -202
- data/lib/winrm/shells/retryable.rb +45 -45
- data/lib/winrm/shells/shell_factory.rb +58 -50
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -59
- data/lib/winrm/wsmv/cleanup_command.rb +61 -61
- data/lib/winrm/wsmv/close_shell.rb +50 -50
- data/lib/winrm/wsmv/command.rb +101 -101
- data/lib/winrm/wsmv/command_output.rb +76 -76
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -55
- data/lib/winrm/wsmv/configuration.rb +46 -46
- data/lib/winrm/wsmv/create_pipeline.rb +66 -66
- data/lib/winrm/wsmv/create_shell.rb +119 -119
- data/lib/winrm/wsmv/header.rb +203 -203
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -60
- data/lib/winrm/wsmv/keep_alive.rb +68 -68
- data/lib/winrm/wsmv/receive_response_reader.rb +126 -126
- data/lib/winrm/wsmv/send_data.rb +68 -68
- data/lib/winrm/wsmv/soap.rb +51 -51
- data/lib/winrm/wsmv/wql_query.rb +79 -79
- data/lib/winrm/wsmv/write_stdin.rb +88 -88
- data/tests/integration/auth_timeout_spec.rb +18 -18
- data/tests/integration/cmd_spec.rb +131 -110
- data/tests/integration/config-example.yml +16 -16
- data/tests/integration/issue_59_spec.rb +26 -26
- data/tests/integration/powershell_spec.rb +165 -165
- data/tests/integration/spec_helper.rb +65 -65
- data/tests/integration/transport_spec.rb +99 -99
- data/tests/integration/wql_spec.rb +16 -16
- data/tests/matchers.rb +60 -60
- data/tests/spec/configuration_spec.rb +184 -184
- data/tests/spec/connection_spec.rb +39 -39
- data/tests/spec/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -68
- data/tests/spec/http/transport_spec.rb +44 -44
- data/tests/spec/output_spec.rb +127 -127
- data/tests/spec/psrp/fragment_spec.rb +62 -62
- data/tests/spec/psrp/message_data/base_spec.rb +13 -13
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -41
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -25
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -32
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +40 -40
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -25
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -16
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -30
- data/tests/spec/psrp/message_data_spec.rb +35 -35
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -47
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -105
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +100 -100
- data/tests/spec/psrp/psrp_message_spec.rb +70 -70
- data/tests/spec/psrp/recieve_response_reader_spec.rb +172 -172
- data/tests/spec/psrp/uuid_spec.rb +28 -28
- data/tests/spec/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -202
- data/tests/spec/shells/cmd_spec.rb +75 -75
- data/tests/spec/shells/powershell_spec.rb +175 -175
- data/tests/spec/spec_helper.rb +47 -47
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -84
- data/tests/spec/stubs/clixml/pipeline_state.xml.erb +88 -88
- data/tests/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -10
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -10
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -12
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -9
- data/tests/spec/stubs/responses/open_shell_v1.xml +19 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +20 -20
- data/tests/spec/stubs/responses/soap_fault_v1.xml +36 -36
- data/tests/spec/stubs/responses/soap_fault_v2.xml +42 -42
- data/tests/spec/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -22
- data/tests/spec/wsmv/close_shell_spec.rb +17 -17
- data/tests/spec/wsmv/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -45
- data/tests/spec/wsmv/command_spec.rb +19 -19
- data/tests/spec/wsmv/configuration_spec.rb +17 -17
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -31
- data/tests/spec/wsmv/create_shell_spec.rb +38 -38
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -123
- data/tests/spec/wsmv/send_data_spec.rb +30 -30
- data/tests/spec/wsmv/wql_query_spec.rb +13 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -22
- data/winrm.gemspec +42 -42
- metadata +2 -2
data/lib/winrm/wsmv/header.rb
CHANGED
@@ -1,203 +1,203 @@
|
|
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 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,95 +1,95 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
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 'base'
|
18
|
-
|
19
|
-
module WinRM
|
20
|
-
module WSMV
|
21
|
-
# WSMV message to create a remote shell
|
22
|
-
class InitRunspacePool < Base
|
23
|
-
attr_accessor :shell_id
|
24
|
-
|
25
|
-
def initialize(session_opts, shell_id, payload)
|
26
|
-
@session_opts = session_opts
|
27
|
-
@shell_id = shell_id
|
28
|
-
@payload = payload
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def create_header(header)
|
34
|
-
header << Gyoku.xml(shell_headers)
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_body(body)
|
38
|
-
body.tag!("#{NS_WIN_SHELL}:Shell", 'ShellId' => shell_id) { |s| s << Gyoku.xml(shell_body) }
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def shell_body
|
44
|
-
body = {
|
45
|
-
"#{NS_WIN_SHELL}:InputStreams" => 'stdin pr',
|
46
|
-
"#{NS_WIN_SHELL}:OutputStreams" => 'stdout'
|
47
|
-
}
|
48
|
-
body['creationXml'] = encode_bytes(@payload)
|
49
|
-
body[:attributes!] = {
|
50
|
-
'creationXml' => {
|
51
|
-
'xmlns' => 'http://schemas.microsoft.com/powershell'
|
52
|
-
}
|
53
|
-
}
|
54
|
-
body
|
55
|
-
end
|
56
|
-
|
57
|
-
def shell_headers
|
58
|
-
merge_headers(shared_headers(@session_opts),
|
59
|
-
resource_uri_shell(RESOURCE_URI_POWERSHELL),
|
60
|
-
action_create,
|
61
|
-
header_opts)
|
62
|
-
end
|
63
|
-
|
64
|
-
def action_create
|
65
|
-
{
|
66
|
-
"#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create',
|
67
|
-
:attributes! => {
|
68
|
-
"#{NS_ADDRESSING}:Action" => {
|
69
|
-
'mustUnderstand' => true
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
def header_opts
|
76
|
-
{
|
77
|
-
"#{NS_WSMAN_DMTF}:OptionSet" => {
|
78
|
-
"#{NS_WSMAN_DMTF}:Option" => 2.3,
|
79
|
-
:attributes! => {
|
80
|
-
"#{NS_WSMAN_DMTF}:Option" => {
|
81
|
-
'Name' => 'protocolversion',
|
82
|
-
'MustComply' => 'true'
|
83
|
-
}
|
84
|
-
}
|
85
|
-
},
|
86
|
-
:attributes! => {
|
87
|
-
"#{NS_WSMAN_DMTF}:OptionSet" => {
|
88
|
-
'env:mustUnderstand' => 'true'
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
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 'base'
|
18
|
+
|
19
|
+
module WinRM
|
20
|
+
module WSMV
|
21
|
+
# WSMV message to create a remote shell
|
22
|
+
class InitRunspacePool < Base
|
23
|
+
attr_accessor :shell_id
|
24
|
+
|
25
|
+
def initialize(session_opts, shell_id, payload)
|
26
|
+
@session_opts = session_opts
|
27
|
+
@shell_id = shell_id
|
28
|
+
@payload = payload
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def create_header(header)
|
34
|
+
header << Gyoku.xml(shell_headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_body(body)
|
38
|
+
body.tag!("#{NS_WIN_SHELL}:Shell", 'ShellId' => shell_id) { |s| s << Gyoku.xml(shell_body) }
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def shell_body
|
44
|
+
body = {
|
45
|
+
"#{NS_WIN_SHELL}:InputStreams" => 'stdin pr',
|
46
|
+
"#{NS_WIN_SHELL}:OutputStreams" => 'stdout'
|
47
|
+
}
|
48
|
+
body['creationXml'] = encode_bytes(@payload)
|
49
|
+
body[:attributes!] = {
|
50
|
+
'creationXml' => {
|
51
|
+
'xmlns' => 'http://schemas.microsoft.com/powershell'
|
52
|
+
}
|
53
|
+
}
|
54
|
+
body
|
55
|
+
end
|
56
|
+
|
57
|
+
def shell_headers
|
58
|
+
merge_headers(shared_headers(@session_opts),
|
59
|
+
resource_uri_shell(RESOURCE_URI_POWERSHELL),
|
60
|
+
action_create,
|
61
|
+
header_opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
def action_create
|
65
|
+
{
|
66
|
+
"#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create',
|
67
|
+
:attributes! => {
|
68
|
+
"#{NS_ADDRESSING}:Action" => {
|
69
|
+
'mustUnderstand' => true
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def header_opts
|
76
|
+
{
|
77
|
+
"#{NS_WSMAN_DMTF}:OptionSet" => {
|
78
|
+
"#{NS_WSMAN_DMTF}:Option" => 2.3,
|
79
|
+
:attributes! => {
|
80
|
+
"#{NS_WSMAN_DMTF}:Option" => {
|
81
|
+
'Name' => 'protocolversion',
|
82
|
+
'MustComply' => 'true'
|
83
|
+
}
|
84
|
+
}
|
85
|
+
},
|
86
|
+
:attributes! => {
|
87
|
+
"#{NS_WSMAN_DMTF}:OptionSet" => {
|
88
|
+
'env:mustUnderstand' => 'true'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|