winrm 2.1.3 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +276 -263
- data/changelog.md +118 -114
- data/lib/winrm/connection.rb +86 -83
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/header.rb +215 -203
- data/lib/winrm/wsmv/wql_pull.rb +56 -0
- data/lib/winrm/wsmv/wql_query.rb +99 -79
- data/tests/integration/wql_spec.rb +34 -16
- data/tests/spec/wsmv/wql_query_spec.rb +13 -13
- metadata +4 -3
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'nori'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module WinRM
|
7
|
+
module WSMV
|
8
|
+
# WSMV message to 'pull' rest of enumeration results from Windows via WQL
|
9
|
+
class WqlPull < Base
|
10
|
+
def initialize(session_opts, namespace, enumeration_context)
|
11
|
+
@session_opts = session_opts
|
12
|
+
@namespace = namespace
|
13
|
+
@enumeration_context = enumeration_context
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_response(response)
|
17
|
+
parser = Nori.new(
|
18
|
+
parser: :rexml,
|
19
|
+
advanced_typecasting: false,
|
20
|
+
convert_tags_to: ->(tag) { tag.snakecase.to_sym },
|
21
|
+
strip_namespaces: true
|
22
|
+
)
|
23
|
+
parser.parse(response.to_s)[:envelope][:body]
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def create_header(header)
|
29
|
+
header << Gyoku.xml(wql_header)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_body(body)
|
33
|
+
body.tag!("#{NS_ENUM}:Pull") { |en| en << Gyoku.xml(wql_body) }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def wql_header
|
39
|
+
merge_headers(
|
40
|
+
shared_headers(@session_opts),
|
41
|
+
resource_uri_wmi(@namespace),
|
42
|
+
action_enumerate_pull
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def wql_body
|
47
|
+
{
|
48
|
+
"#{NS_ENUM}:EnumerationContext" => @enumeration_context,
|
49
|
+
"#{NS_WSMAN_DMTF}:OptimizeEnumeration" => nil,
|
50
|
+
"#{NS_ENUM}:MaxElements" => '32000',
|
51
|
+
"#{NS_WSMAN_MSFT}:SessionId" => "uuid:#{@session_opts[:session_id]}"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/winrm/wsmv/wql_query.rb
CHANGED
@@ -1,79 +1,99 @@
|
|
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 'nori'
|
18
|
-
require_relative 'base'
|
19
|
-
|
20
|
-
module WinRM
|
21
|
-
module WSMV
|
22
|
-
# WSMV message to query Windows via WQL
|
23
|
-
class WqlQuery < Base
|
24
|
-
def initialize(session_opts, wql)
|
25
|
-
@session_opts = session_opts
|
26
|
-
@wql = wql
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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 'nori'
|
18
|
+
require_relative 'base'
|
19
|
+
|
20
|
+
module WinRM
|
21
|
+
module WSMV
|
22
|
+
# WSMV message to query Windows via WQL
|
23
|
+
class WqlQuery < Base
|
24
|
+
def initialize(transport, session_opts, wql, namespace = nil)
|
25
|
+
@session_opts = session_opts
|
26
|
+
@wql = wql
|
27
|
+
@namespace = namespace
|
28
|
+
@transport = transport
|
29
|
+
end
|
30
|
+
|
31
|
+
def process_response(response, &block)
|
32
|
+
parser = Nori.new(
|
33
|
+
parser: :rexml,
|
34
|
+
advanced_typecasting: false,
|
35
|
+
convert_tags_to: ->(tag) { tag.snakecase.to_sym },
|
36
|
+
strip_namespaces: true
|
37
|
+
)
|
38
|
+
@items = Hash.new { |h, k| h[k] = [] }
|
39
|
+
|
40
|
+
hresp = parser.parse(response.to_s)[:envelope][:body][:enumerate_response]
|
41
|
+
process_items hresp[:items], &block
|
42
|
+
|
43
|
+
# Perform WS-Enum PULL's until we have all the elements
|
44
|
+
enumeration_context = hresp[:enumeration_context]
|
45
|
+
until enumeration_context.nil?
|
46
|
+
query = WqlPull.new(@session_opts, @namespace, enumeration_context)
|
47
|
+
hresp = query.process_response(@transport.send_request(query.build))[:pull_response]
|
48
|
+
process_items hresp[:items], &block
|
49
|
+
enumeration_context = hresp[:enumeration_context]
|
50
|
+
end
|
51
|
+
|
52
|
+
@items
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
def create_header(header)
|
58
|
+
header << Gyoku.xml(wql_header)
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_body(body)
|
62
|
+
body.tag!("#{NS_ENUM}:Enumerate") { |en| en << Gyoku.xml(wql_body) }
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def process_items(items, &block)
|
68
|
+
return if items.nil?
|
69
|
+
items.each_pair do |k, v|
|
70
|
+
# Normalize items so the type always has an array even if it's just a single item.
|
71
|
+
v_ary = v.is_a?(Array) ? v : [v]
|
72
|
+
if block
|
73
|
+
v_ary.each { |val| yield k, val }
|
74
|
+
else
|
75
|
+
@items[k] += v_ary
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def wql_header
|
81
|
+
merge_headers(shared_headers(@session_opts), resource_uri_wmi(@namespace), action_enumerate)
|
82
|
+
end
|
83
|
+
|
84
|
+
def wql_body
|
85
|
+
{
|
86
|
+
"#{NS_WSMAN_DMTF}:OptimizeEnumeration" => nil,
|
87
|
+
"#{NS_WSMAN_DMTF}:MaxElements" => '32000',
|
88
|
+
"#{NS_WSMAN_DMTF}:Filter" => @wql,
|
89
|
+
"#{NS_WSMAN_MSFT}:SessionId" => "uuid:#{@session_opts[:session_id]}",
|
90
|
+
:attributes! => {
|
91
|
+
"#{NS_WSMAN_DMTF}:Filter" => {
|
92
|
+
'Dialect' => 'http://schemas.microsoft.com/wbem/wsman/1/WQL'
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,16 +1,34 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
|
4
|
-
describe 'winrm client wql' do
|
5
|
-
before(:all) do
|
6
|
-
@winrm = winrm_connection
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should query Win32_OperatingSystem' do
|
10
|
-
output = @winrm.run_wql('select * from Win32_OperatingSystem')
|
11
|
-
expect(output).to_not be_empty
|
12
|
-
output_caption = output[:win32_operating_system][0][:caption]
|
13
|
-
expect(output_caption).to include('Microsoft')
|
14
|
-
expect(output_caption).to include('Windows')
|
15
|
-
end
|
16
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'winrm client wql' do
|
5
|
+
before(:all) do
|
6
|
+
@winrm = winrm_connection
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should query Win32_OperatingSystem' do
|
10
|
+
output = @winrm.run_wql('select * from Win32_OperatingSystem')
|
11
|
+
expect(output).to_not be_empty
|
12
|
+
output_caption = output[:win32_operating_system][0][:caption]
|
13
|
+
expect(output_caption).to include('Microsoft')
|
14
|
+
expect(output_caption).to include('Windows')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should query Win32_Process' do
|
18
|
+
output = @winrm.run_wql('select * from Win32_Process')
|
19
|
+
expect(output).to_not be_empty
|
20
|
+
process_count = output[:win32_process].count
|
21
|
+
expect(process_count).to be > 1
|
22
|
+
expect(output[:win32_process]).to all(include(:command_line))
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should query Win32_Process with block' do
|
26
|
+
count = 0
|
27
|
+
@winrm.run_wql('select * from Win32_Process') do |type, item|
|
28
|
+
expect(type).to eq(:win32_process)
|
29
|
+
expect(item).to include(:command_line)
|
30
|
+
count += 1
|
31
|
+
end
|
32
|
+
expect(count).to be > 1
|
33
|
+
end
|
34
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm/wsmv/wql_query'
|
4
|
-
|
5
|
-
describe WinRM::WSMV::WqlQuery do
|
6
|
-
context 'default session options' do
|
7
|
-
subject { described_class.new(default_connection_opts, 'SELECT * FROM Win32') }
|
8
|
-
let(:xml) { subject.build }
|
9
|
-
it 'creates a well formed message' do
|
10
|
-
expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'winrm/wsmv/wql_query'
|
4
|
+
|
5
|
+
describe WinRM::WSMV::WqlQuery do
|
6
|
+
context 'default session options' do
|
7
|
+
subject { described_class.new(nil, default_connection_opts, 'SELECT * FROM Win32') }
|
8
|
+
let(:xml) { subject.build }
|
9
|
+
it 'creates a well formed message' do
|
10
|
+
expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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.
|
4
|
+
version: 2.2.0
|
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: 2017-
|
14
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: gssapi
|
@@ -288,6 +288,7 @@ files:
|
|
288
288
|
- lib/winrm/wsmv/receive_response_reader.rb
|
289
289
|
- lib/winrm/wsmv/send_data.rb
|
290
290
|
- lib/winrm/wsmv/soap.rb
|
291
|
+
- lib/winrm/wsmv/wql_pull.rb
|
291
292
|
- lib/winrm/wsmv/wql_query.rb
|
292
293
|
- lib/winrm/wsmv/write_stdin.rb
|
293
294
|
- preamble
|
@@ -378,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
378
379
|
version: '0'
|
379
380
|
requirements: []
|
380
381
|
rubyforge_project:
|
381
|
-
rubygems_version: 2.6.
|
382
|
+
rubygems_version: 2.6.10
|
382
383
|
signing_key:
|
383
384
|
specification_version: 4
|
384
385
|
summary: Ruby library for Windows Remote Management
|