winrm 2.2.3 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/bin/rwinrm +90 -97
  4. data/lib/winrm/connection.rb +84 -86
  5. data/lib/winrm/connection_opts.rb +90 -91
  6. data/lib/winrm/exceptions.rb +14 -2
  7. data/lib/winrm/http/response_handler.rb +127 -96
  8. data/lib/winrm/http/transport.rb +462 -427
  9. data/lib/winrm/http/transport_factory.rb +1 -5
  10. data/lib/winrm/output.rb +1 -2
  11. data/lib/winrm/psrp/fragment.rb +0 -2
  12. data/lib/winrm/psrp/message.rb +128 -130
  13. data/lib/winrm/psrp/message_data/base.rb +0 -2
  14. data/lib/winrm/psrp/message_data/error_record.rb +2 -2
  15. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
  16. data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
  17. data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
  18. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
  19. data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
  20. data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
  21. data/lib/winrm/psrp/message_data.rb +0 -2
  22. data/lib/winrm/psrp/message_defragmenter.rb +2 -2
  23. data/lib/winrm/psrp/message_factory.rb +16 -5
  24. data/lib/winrm/psrp/message_fragmenter.rb +1 -3
  25. data/lib/winrm/psrp/powershell_output_decoder.rb +142 -144
  26. data/lib/winrm/psrp/receive_response_reader.rb +3 -5
  27. data/lib/winrm/psrp/uuid.rb +1 -2
  28. data/lib/winrm/shells/base.rb +7 -4
  29. data/lib/winrm/shells/cmd.rb +63 -65
  30. data/lib/winrm/shells/power_shell.rb +207 -202
  31. data/lib/winrm/shells/retryable.rb +44 -45
  32. data/lib/winrm/shells/shell_factory.rb +0 -2
  33. data/lib/winrm/version.rb +1 -3
  34. data/lib/winrm/wsmv/base.rb +0 -2
  35. data/lib/winrm/wsmv/cleanup_command.rb +1 -2
  36. data/lib/winrm/wsmv/close_shell.rb +1 -2
  37. data/lib/winrm/wsmv/command.rb +2 -3
  38. data/lib/winrm/wsmv/command_output.rb +2 -3
  39. data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
  40. data/lib/winrm/wsmv/configuration.rb +0 -2
  41. data/lib/winrm/wsmv/create_pipeline.rb +0 -2
  42. data/lib/winrm/wsmv/create_shell.rb +2 -6
  43. data/lib/winrm/wsmv/header.rb +213 -215
  44. data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
  45. data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
  46. data/lib/winrm/wsmv/keep_alive.rb +0 -2
  47. data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
  48. data/lib/winrm/wsmv/send_data.rb +0 -2
  49. data/lib/winrm/wsmv/soap.rb +0 -2
  50. data/lib/winrm/wsmv/wql_pull.rb +54 -56
  51. data/lib/winrm/wsmv/wql_query.rb +98 -99
  52. data/lib/winrm/wsmv/write_stdin.rb +0 -2
  53. data/lib/winrm.rb +3 -5
  54. metadata +81 -135
  55. data/.gitignore +0 -10
  56. data/.rubocop.yml +0 -26
  57. data/.travis.yml +0 -11
  58. data/Gemfile +0 -3
  59. data/Rakefile +0 -34
  60. data/Vagrantfile +0 -6
  61. data/WinrmAppveyor.psm1 +0 -32
  62. data/appveyor.yml +0 -51
  63. data/changelog.md +0 -128
  64. data/preamble +0 -17
  65. data/tests/integration/auth_timeout_spec.rb +0 -18
  66. data/tests/integration/cmd_spec.rb +0 -131
  67. data/tests/integration/config-example.yml +0 -16
  68. data/tests/integration/issue_59_spec.rb +0 -26
  69. data/tests/integration/powershell_spec.rb +0 -165
  70. data/tests/integration/spec_helper.rb +0 -65
  71. data/tests/integration/transport_spec.rb +0 -99
  72. data/tests/integration/wql_spec.rb +0 -34
  73. data/tests/matchers.rb +0 -60
  74. data/tests/spec/configuration_spec.rb +0 -184
  75. data/tests/spec/connection_spec.rb +0 -39
  76. data/tests/spec/exception_spec.rb +0 -50
  77. data/tests/spec/http/transport_factory_spec.rb +0 -68
  78. data/tests/spec/http/transport_spec.rb +0 -44
  79. data/tests/spec/output_spec.rb +0 -127
  80. data/tests/spec/psrp/fragment_spec.rb +0 -62
  81. data/tests/spec/psrp/message_data/base_spec.rb +0 -13
  82. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -41
  83. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -25
  84. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -32
  85. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -40
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -25
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -16
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -30
  89. data/tests/spec/psrp/message_data_spec.rb +0 -35
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -47
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -105
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -100
  93. data/tests/spec/psrp/psrp_message_spec.rb +0 -70
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -172
  95. data/tests/spec/psrp/uuid_spec.rb +0 -28
  96. data/tests/spec/response_handler_spec.rb +0 -61
  97. data/tests/spec/shells/base_spec.rb +0 -225
  98. data/tests/spec/shells/cmd_spec.rb +0 -75
  99. data/tests/spec/shells/powershell_spec.rb +0 -175
  100. data/tests/spec/spec_helper.rb +0 -47
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
  102. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
  103. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
  104. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
  105. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
  106. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
  107. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
  108. data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
  109. data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
  110. data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
  111. data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
  112. data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
  113. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -22
  114. data/tests/spec/wsmv/close_shell_spec.rb +0 -17
  115. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -37
  116. data/tests/spec/wsmv/command_output_spec.rb +0 -45
  117. data/tests/spec/wsmv/command_spec.rb +0 -19
  118. data/tests/spec/wsmv/configuration_spec.rb +0 -17
  119. data/tests/spec/wsmv/create_pipeline_spec.rb +0 -31
  120. data/tests/spec/wsmv/create_shell_spec.rb +0 -38
  121. data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -36
  122. data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
  123. data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -123
  124. data/tests/spec/wsmv/send_data_spec.rb +0 -30
  125. data/tests/spec/wsmv/wql_query_spec.rb +0 -13
  126. data/tests/spec/wsmv/write_stdin_spec.rb +0 -22
  127. data/winrm.gemspec +0 -47
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
1
  # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
2
  #
5
3
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,9 +60,7 @@ module WinRM
62
60
  "#{NS_WIN_SHELL}:OutputStreams" => @o_stream
63
61
  }
64
62
  body["#{NS_WIN_SHELL}:WorkingDirectory"] = @working_directory if @working_directory
65
- if @idle_timeout
66
- body["#{NS_WIN_SHELL}:IdleTimeOut"] = format_idle_timeout(@idle_timeout)
67
- end
63
+ body["#{NS_WIN_SHELL}:IdleTimeOut"] = format_idle_timeout(@idle_timeout) if @idle_timeout
68
64
  body["#{NS_WIN_SHELL}:Environment"] = environment_vars_body if @env_vars
69
65
  body
70
66
  end
@@ -108,7 +104,7 @@ module WinRM
108
104
  "#{NS_WSMAN_DMTF}:OptionSet" => {
109
105
  "#{NS_WSMAN_DMTF}:Option" => [@noprofile, @codepage], :attributes! => {
110
106
  "#{NS_WSMAN_DMTF}:Option" => {
111
- 'Name' => %w(WINRS_NOPROFILE WINRS_CODEPAGE)
107
+ 'Name' => %w[WINRS_NOPROFILE WINRS_CODEPAGE]
112
108
  }
113
109
  }
114
110
  }
@@ -1,215 +1,213 @@
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
1
+ # Copyright 2016 Shawn Neal <sneal@sneal.net>
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
+ # rubocop:disable Metrics/MethodLength
16
+
17
+ require_relative 'soap'
18
+ require_relative 'iso8601_duration'
19
+
20
+ module WinRM
21
+ module WSMV
22
+ # SOAP header utility mixin
23
+ module Header
24
+ # WSMan URI of the regular Windows cmd shell
25
+ RESOURCE_URI_CMD = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd'.freeze
26
+
27
+ # WSMan URI for PowerShell
28
+ RESOURCE_URI_POWERSHELL = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'.freeze
29
+
30
+ # Merge the various header hashes and make sure we carry all of the attributes
31
+ # through instead of overwriting them.
32
+ def merge_headers(*headers)
33
+ hdr = {}
34
+ headers.each do |h|
35
+ hdr.merge!(h) do |k, v1, v2|
36
+ v1.merge!(v2) if k == :attributes!
37
+ end
38
+ end
39
+ hdr
40
+ end
41
+
42
+ def shared_headers(session_opts)
43
+ {
44
+ "#{SOAP::NS_ADDRESSING}:To" => session_opts[:endpoint],
45
+ "#{SOAP::NS_ADDRESSING}:ReplyTo" => {
46
+ "#{SOAP::NS_ADDRESSING}:Address" =>
47
+ 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous',
48
+ :attributes! => {
49
+ "#{SOAP::NS_ADDRESSING}:Address" => {
50
+ 'mustUnderstand' => true
51
+ }
52
+ }
53
+ },
54
+ "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => session_opts[:max_envelope_size],
55
+ "#{SOAP::NS_ADDRESSING}:MessageID" => "uuid:#{SecureRandom.uuid.to_s.upcase}",
56
+ "#{SOAP::NS_WSMAN_MSFT}:SessionId" => "uuid:#{session_opts[:session_id]}",
57
+ "#{SOAP::NS_WSMAN_DMTF}:Locale/" => '',
58
+ "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => '',
59
+ "#{SOAP::NS_WSMAN_DMTF}:OperationTimeout" =>
60
+ Iso8601Duration.sec_to_dur(session_opts[:operation_timeout]),
61
+ :attributes! => {
62
+ "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => { 'mustUnderstand' => true },
63
+ "#{SOAP::NS_WSMAN_DMTF}:Locale/" => {
64
+ 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
65
+ },
66
+ "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => {
67
+ 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
68
+ },
69
+ "#{SOAP::NS_WSMAN_MSFT}:SessionId" => { 'mustUnderstand' => false }
70
+ }
71
+ }
72
+ end
73
+
74
+ # Helper methods for SOAP Headers
75
+
76
+ def resource_uri_shell(shell_uri)
77
+ {
78
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => shell_uri, :attributes! => {
79
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
80
+ 'mustUnderstand' => true
81
+ }
82
+ }
83
+ }
84
+ end
85
+
86
+ def resource_uri_cmd
87
+ resource_uri_shell(RESOURCE_URI_CMD)
88
+ end
89
+
90
+ def resource_uri_wmi(namespace = 'root/cimv2/*')
91
+ {
92
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" =>
93
+ "http://schemas.microsoft.com/wbem/wsman/1/wmi/#{namespace}",
94
+ :attributes! => {
95
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
96
+ 'mustUnderstand' => true
97
+ }
98
+ }
99
+ }
100
+ end
101
+
102
+ def action_get
103
+ {
104
+ "#{SOAP::NS_ADDRESSING}:Action" =>
105
+ 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get',
106
+ :attributes! => {
107
+ "#{SOAP::NS_ADDRESSING}:Action" => {
108
+ 'mustUnderstand' => true
109
+ }
110
+ }
111
+ }
112
+ end
113
+
114
+ def action_delete
115
+ {
116
+ "#{SOAP::NS_ADDRESSING}:Action" =>
117
+ 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete',
118
+ :attributes! => {
119
+ "#{SOAP::NS_ADDRESSING}:Action" => {
120
+ 'mustUnderstand' => true
121
+ }
122
+ }
123
+ }
124
+ end
125
+
126
+ def action_command
127
+ {
128
+ "#{SOAP::NS_ADDRESSING}:Action" =>
129
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command',
130
+ :attributes! => {
131
+ "#{SOAP::NS_ADDRESSING}:Action" => {
132
+ 'mustUnderstand' => true
133
+ }
134
+ }
135
+ }
136
+ end
137
+
138
+ def action_receive
139
+ {
140
+ "#{SOAP::NS_ADDRESSING}:Action" =>
141
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive',
142
+ :attributes! => {
143
+ "#{SOAP::NS_ADDRESSING}:Action" => {
144
+ 'mustUnderstand' => true
145
+ }
146
+ }
147
+ }
148
+ end
149
+
150
+ def action_send
151
+ {
152
+ "#{SOAP::NS_ADDRESSING}:Action" =>
153
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
154
+ :attributes! => {
155
+ "#{SOAP::NS_ADDRESSING}:Action" => {
156
+ 'mustUnderstand' => true
157
+ }
158
+ }
159
+ }
160
+ end
161
+
162
+ def action_signal
163
+ {
164
+ "#{SOAP::NS_ADDRESSING}:Action" =>
165
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal',
166
+ :attributes! => {
167
+ "#{SOAP::NS_ADDRESSING}:Action" => {
168
+ 'mustUnderstand' => true
169
+ }
170
+ }
171
+ }
172
+ end
173
+
174
+ def action_enumerate
175
+ {
176
+ "#{SOAP::NS_ADDRESSING}:Action" =>
177
+ 'http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate',
178
+ :attributes! => {
179
+ "#{SOAP::NS_ADDRESSING}:Action" => {
180
+ 'mustUnderstand' => true
181
+ }
182
+ }
183
+ }
184
+ end
185
+
186
+ def action_enumerate_pull
187
+ {
188
+ "#{SOAP::NS_ADDRESSING}:Action" =>
189
+ 'http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull',
190
+ :attributes! => {
191
+ "#{SOAP::NS_ADDRESSING}:Action" => {
192
+ 'mustUnderstand' => true
193
+ }
194
+ }
195
+ }
196
+ end
197
+
198
+ def selector_shell_id(shell_id)
199
+ {
200
+ "#{SOAP::NS_WSMAN_DMTF}:SelectorSet" => {
201
+ "#{SOAP::NS_WSMAN_DMTF}:Selector" => shell_id, :attributes! => {
202
+ "#{SOAP::NS_WSMAN_DMTF}:Selector" => {
203
+ 'Name' => 'ShellId'
204
+ }
205
+ }
206
+ }
207
+ }
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ # rubocop:enable Metrics/MethodLength
@@ -1,95 +1,96 @@
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
+ # 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_relative 'base'
16
+
17
+ module WinRM
18
+ module WSMV
19
+ # WSMV message to create a remote shell
20
+ class InitRunspacePool < Base
21
+ attr_accessor :shell_id
22
+
23
+ def initialize(session_opts, shell_id, payload)
24
+ @session_opts = session_opts
25
+ @shell_id = shell_id
26
+ @payload = payload
27
+ end
28
+
29
+ protected
30
+
31
+ def create_header(header)
32
+ header << Gyoku.xml(shell_headers)
33
+ end
34
+
35
+ def create_body(body)
36
+ # OMI server requires a Name for the Shell
37
+ body.tag!("#{NS_WIN_SHELL}:Shell", 'ShellId' => shell_id, 'Name' => 'Runspace') do |s|
38
+ s << Gyoku.xml(shell_body)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def shell_body
45
+ body = {
46
+ "#{NS_WIN_SHELL}:InputStreams" => 'stdin pr',
47
+ "#{NS_WIN_SHELL}:OutputStreams" => 'stdout'
48
+ }
49
+ body['creationXml'] = encode_bytes(@payload)
50
+ body[:attributes!] = {
51
+ 'creationXml' => {
52
+ 'xmlns' => 'http://schemas.microsoft.com/powershell'
53
+ }
54
+ }
55
+ body
56
+ end
57
+
58
+ def shell_headers
59
+ merge_headers(shared_headers(@session_opts),
60
+ resource_uri_shell(RESOURCE_URI_POWERSHELL),
61
+ action_create,
62
+ header_opts)
63
+ end
64
+
65
+ def action_create
66
+ {
67
+ "#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create',
68
+ :attributes! => {
69
+ "#{NS_ADDRESSING}:Action" => {
70
+ 'mustUnderstand' => true
71
+ }
72
+ }
73
+ }
74
+ end
75
+
76
+ def header_opts
77
+ {
78
+ "#{NS_WSMAN_DMTF}:OptionSet" => {
79
+ "#{NS_WSMAN_DMTF}:Option" => 2.3,
80
+ :attributes! => {
81
+ "#{NS_WSMAN_DMTF}:Option" => {
82
+ 'Name' => 'protocolversion',
83
+ 'MustComply' => 'true'
84
+ }
85
+ }
86
+ },
87
+ :attributes! => {
88
+ "#{NS_WSMAN_DMTF}:OptionSet" => {
89
+ 'env:mustUnderstand' => 'true'
90
+ }
91
+ }
92
+ }
93
+ end
94
+ end
95
+ end
96
+ end