winrm 1.7.1 → 1.7.2
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/.rspec +3 -3
- data/.rubocop.yml +12 -12
- data/.travis.yml +12 -12
- data/Gemfile +9 -9
- data/LICENSE +202 -202
- data/README.md +194 -194
- data/Rakefile +36 -36
- data/Vagrantfile +9 -9
- data/appveyor.yml +42 -42
- data/bin/rwinrm +97 -97
- data/changelog.md +77 -74
- data/lib/winrm.rb +42 -42
- data/lib/winrm/command_executor.rb +224 -224
- data/lib/winrm/command_output_decoder.rb +53 -0
- data/lib/winrm/exceptions/exceptions.rb +57 -57
- data/lib/winrm/helpers/iso8601_duration.rb +58 -58
- data/lib/winrm/helpers/powershell_script.rb +42 -42
- data/lib/winrm/http/response_handler.rb +82 -82
- data/lib/winrm/http/transport.rb +421 -421
- data/lib/winrm/output.rb +43 -43
- data/lib/winrm/soap_provider.rb +39 -39
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/winrm_service.rb +547 -556
- data/preamble +17 -17
- data/spec/auth_timeout_spec.rb +16 -16
- data/spec/cmd_spec.rb +102 -102
- data/spec/command_executor_spec.rb +429 -429
- data/spec/command_output_decoder_spec.rb +37 -0
- data/spec/config-example.yml +19 -19
- data/spec/exception_spec.rb +50 -50
- data/spec/issue_184_spec.rb +67 -67
- data/spec/issue_59_spec.rb +23 -23
- data/spec/matchers.rb +74 -74
- data/spec/output_spec.rb +110 -110
- data/spec/powershell_spec.rb +97 -97
- data/spec/response_handler_spec.rb +59 -59
- data/spec/spec_helper.rb +73 -73
- data/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/spec/stubs/responses/open_shell_v1.xml +19 -19
- data/spec/stubs/responses/open_shell_v2.xml +20 -20
- data/spec/stubs/responses/soap_fault_v1.xml +36 -36
- data/spec/stubs/responses/soap_fault_v2.xml +42 -42
- data/spec/stubs/responses/wmi_error_v2.xml +41 -41
- data/spec/transport_spec.rb +124 -124
- data/spec/winrm_options_spec.rb +76 -76
- data/spec/winrm_primitives_spec.rb +51 -51
- data/spec/wql_spec.rb +14 -14
- data/winrm.gemspec +40 -40
- metadata +5 -3
data/Vagrantfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# -*- mode: ruby -*-
|
3
|
-
# vi: set ft=ruby :
|
4
|
-
|
5
|
-
VAGRANTFILE_API_VERSION = '2'
|
6
|
-
|
7
|
-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
-
config.vm.box = 'mwrock/Windows2012R2'
|
9
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# vi: set ft=ruby :
|
4
|
+
|
5
|
+
VAGRANTFILE_API_VERSION = '2'
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
config.vm.box = 'mwrock/Windows2012R2'
|
9
|
+
end
|
data/appveyor.yml
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
version: "master-{build}"
|
2
|
-
|
3
|
-
os: Windows Server 2012 R2
|
4
|
-
platform:
|
5
|
-
- x64
|
6
|
-
|
7
|
-
environment:
|
8
|
-
winrm_user: test_user
|
9
|
-
winrm_pass: Pass@word1
|
10
|
-
|
11
|
-
matrix:
|
12
|
-
- ruby_version: "21"
|
13
|
-
winrm_endpoint: http://localhost:5985/wsman
|
14
|
-
|
15
|
-
clone_folder: c:\projects\winrm
|
16
|
-
clone_depth: 1
|
17
|
-
branches:
|
18
|
-
only:
|
19
|
-
- master
|
20
|
-
|
21
|
-
install:
|
22
|
-
- ps: net user /add $env:winrm_user $env:winrm_pass
|
23
|
-
- ps: net localgroup administrators $env:winrm_user /add
|
24
|
-
- ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint
|
25
|
-
- ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
|
26
|
-
- ps: winrm set winrm/config/client/auth '@{Basic="true"}'
|
27
|
-
- ps: winrm set winrm/config/service/auth '@{Basic="true"}'
|
28
|
-
- ps: winrm set winrm/config/service/auth '@{CbtHardeningLevel="Strict"}'
|
29
|
-
- ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
30
|
-
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
|
31
|
-
- ps: Write-Host $env:PATH
|
32
|
-
- ps: ruby --version
|
33
|
-
- ps: gem --version
|
34
|
-
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
35
|
-
- ps: bundler --version
|
36
|
-
|
37
|
-
build_script:
|
38
|
-
- bundle install || bundle install || bundle install
|
39
|
-
|
40
|
-
test_script:
|
41
|
-
- SET SPEC_OPTS=--format progress
|
42
|
-
- bundle exec rake integration
|
1
|
+
version: "master-{build}"
|
2
|
+
|
3
|
+
os: Windows Server 2012 R2
|
4
|
+
platform:
|
5
|
+
- x64
|
6
|
+
|
7
|
+
environment:
|
8
|
+
winrm_user: test_user
|
9
|
+
winrm_pass: Pass@word1
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
- ruby_version: "21"
|
13
|
+
winrm_endpoint: http://localhost:5985/wsman
|
14
|
+
|
15
|
+
clone_folder: c:\projects\winrm
|
16
|
+
clone_depth: 1
|
17
|
+
branches:
|
18
|
+
only:
|
19
|
+
- master
|
20
|
+
|
21
|
+
install:
|
22
|
+
- ps: net user /add $env:winrm_user $env:winrm_pass
|
23
|
+
- ps: net localgroup administrators $env:winrm_user /add
|
24
|
+
- ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint
|
25
|
+
- ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
|
26
|
+
- ps: winrm set winrm/config/client/auth '@{Basic="true"}'
|
27
|
+
- ps: winrm set winrm/config/service/auth '@{Basic="true"}'
|
28
|
+
- ps: winrm set winrm/config/service/auth '@{CbtHardeningLevel="Strict"}'
|
29
|
+
- ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
30
|
+
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
|
31
|
+
- ps: Write-Host $env:PATH
|
32
|
+
- ps: ruby --version
|
33
|
+
- ps: gem --version
|
34
|
+
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
35
|
+
- ps: bundler --version
|
36
|
+
|
37
|
+
build_script:
|
38
|
+
- bundle install || bundle install || bundle install
|
39
|
+
|
40
|
+
test_script:
|
41
|
+
- SET SPEC_OPTS=--format progress
|
42
|
+
- bundle exec rake integration
|
data/bin/rwinrm
CHANGED
@@ -1,97 +1,97 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
# rubocop:disable all
|
19
|
-
|
20
|
-
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
21
|
-
|
22
|
-
require 'readline'
|
23
|
-
require 'io/console'
|
24
|
-
require 'winrm'
|
25
|
-
|
26
|
-
def help_msg
|
27
|
-
puts 'Usage: rwinrm user@host'
|
28
|
-
puts ''
|
29
|
-
end
|
30
|
-
|
31
|
-
def parse_options
|
32
|
-
options = {}
|
33
|
-
fail 'Missing required options' unless ARGV.length == 1
|
34
|
-
|
35
|
-
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
|
36
|
-
fail "#{ARGV[0]} is an invalid host" unless m
|
37
|
-
options[:user] = m[:user]
|
38
|
-
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
39
|
-
|
40
|
-
# Get the password
|
41
|
-
print 'Password: '
|
42
|
-
options[:pass] = STDIN.noecho(&:gets).chomp
|
43
|
-
puts
|
44
|
-
|
45
|
-
# Set some defaults required by WinRM WS
|
46
|
-
options[:auth_type] = :plaintext
|
47
|
-
options[:basic_auth_only] = true
|
48
|
-
|
49
|
-
options
|
50
|
-
rescue StandardError => e
|
51
|
-
puts e.message
|
52
|
-
help_msg
|
53
|
-
exit 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def repl(options)
|
57
|
-
client = WinRM::WinRMWebService.new(
|
58
|
-
options[:endpoint],
|
59
|
-
options[:auth_type].to_sym,
|
60
|
-
options)
|
61
|
-
|
62
|
-
client.set_timeout(3600)
|
63
|
-
shell_id = client.open_shell
|
64
|
-
command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
|
65
|
-
|
66
|
-
read_thread = Thread.new do
|
67
|
-
client.get_command_output(shell_id, command_id) do |stdout, stderr|
|
68
|
-
STDOUT.write stdout
|
69
|
-
STDERR.write stderr
|
70
|
-
end
|
71
|
-
end
|
72
|
-
read_thread.abort_on_exception = true
|
73
|
-
|
74
|
-
while (buf = Readline.readline('', true))
|
75
|
-
if buf =~ /^exit/
|
76
|
-
read_thread.exit
|
77
|
-
client.cleanup_command(shell_id, command_id)
|
78
|
-
client.close_shell(shell_id)
|
79
|
-
exit 0
|
80
|
-
else
|
81
|
-
client.write_stdin(shell_id, command_id, "#{buf}\r\n")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
rescue Interrupt
|
85
|
-
puts 'exiting'
|
86
|
-
# ctrl-c
|
87
|
-
rescue WinRM::WinRMAuthorizationError
|
88
|
-
puts 'Authentication failed, bad user name or password'
|
89
|
-
exit 1
|
90
|
-
rescue StandardError => e
|
91
|
-
puts e.message
|
92
|
-
exit 1
|
93
|
-
end
|
94
|
-
|
95
|
-
repl(parse_options)
|
96
|
-
|
97
|
-
# rubocop:enable all
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# rubocop:disable all
|
19
|
+
|
20
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
21
|
+
|
22
|
+
require 'readline'
|
23
|
+
require 'io/console'
|
24
|
+
require 'winrm'
|
25
|
+
|
26
|
+
def help_msg
|
27
|
+
puts 'Usage: rwinrm user@host'
|
28
|
+
puts ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_options
|
32
|
+
options = {}
|
33
|
+
fail 'Missing required options' unless ARGV.length == 1
|
34
|
+
|
35
|
+
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
|
36
|
+
fail "#{ARGV[0]} is an invalid host" unless m
|
37
|
+
options[:user] = m[:user]
|
38
|
+
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
39
|
+
|
40
|
+
# Get the password
|
41
|
+
print 'Password: '
|
42
|
+
options[:pass] = STDIN.noecho(&:gets).chomp
|
43
|
+
puts
|
44
|
+
|
45
|
+
# Set some defaults required by WinRM WS
|
46
|
+
options[:auth_type] = :plaintext
|
47
|
+
options[:basic_auth_only] = true
|
48
|
+
|
49
|
+
options
|
50
|
+
rescue StandardError => e
|
51
|
+
puts e.message
|
52
|
+
help_msg
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def repl(options)
|
57
|
+
client = WinRM::WinRMWebService.new(
|
58
|
+
options[:endpoint],
|
59
|
+
options[:auth_type].to_sym,
|
60
|
+
options)
|
61
|
+
|
62
|
+
client.set_timeout(3600)
|
63
|
+
shell_id = client.open_shell
|
64
|
+
command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
|
65
|
+
|
66
|
+
read_thread = Thread.new do
|
67
|
+
client.get_command_output(shell_id, command_id) do |stdout, stderr|
|
68
|
+
STDOUT.write stdout
|
69
|
+
STDERR.write stderr
|
70
|
+
end
|
71
|
+
end
|
72
|
+
read_thread.abort_on_exception = true
|
73
|
+
|
74
|
+
while (buf = Readline.readline('', true))
|
75
|
+
if buf =~ /^exit/
|
76
|
+
read_thread.exit
|
77
|
+
client.cleanup_command(shell_id, command_id)
|
78
|
+
client.close_shell(shell_id)
|
79
|
+
exit 0
|
80
|
+
else
|
81
|
+
client.write_stdin(shell_id, command_id, "#{buf}\r\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
rescue Interrupt
|
85
|
+
puts 'exiting'
|
86
|
+
# ctrl-c
|
87
|
+
rescue WinRM::WinRMAuthorizationError
|
88
|
+
puts 'Authentication failed, bad user name or password'
|
89
|
+
exit 1
|
90
|
+
rescue StandardError => e
|
91
|
+
puts e.message
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
repl(parse_options)
|
96
|
+
|
97
|
+
# rubocop:enable all
|
data/changelog.md
CHANGED
@@ -1,74 +1,77 @@
|
|
1
|
-
# WinRM Gem Changelog
|
2
|
-
|
3
|
-
# 1.7.
|
4
|
-
- Fix
|
5
|
-
|
6
|
-
# 1.7.
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
|
13
|
-
# 1.6.
|
14
|
-
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
|
19
|
-
|
20
|
-
-
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
|
25
|
-
|
26
|
-
-
|
27
|
-
|
28
|
-
# 1.
|
29
|
-
-
|
30
|
-
|
31
|
-
# 1.3.
|
32
|
-
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
-
|
37
|
-
|
38
|
-
# 1.3.
|
39
|
-
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
- Fixed
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
|
70
|
-
|
71
|
-
-
|
72
|
-
|
73
|
-
|
74
|
-
-
|
1
|
+
# WinRM Gem Changelog
|
2
|
+
|
3
|
+
# 1.7.2
|
4
|
+
- Fix regression where BOM appears in 2008R2 output and is not stripped
|
5
|
+
|
6
|
+
# 1.7.1
|
7
|
+
- Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
|
8
|
+
|
9
|
+
# 1.7.0
|
10
|
+
- Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
|
11
|
+
- Fix for parsing binary data in command output
|
12
|
+
|
13
|
+
# 1.6.1
|
14
|
+
- Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
|
15
|
+
|
16
|
+
# 1.6.0
|
17
|
+
- Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
|
18
|
+
- Removed dependency on UUIDTools gem
|
19
|
+
- Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
|
20
|
+
- Correct deprecation warning for WinRMWebService.run_powershell_script
|
21
|
+
|
22
|
+
# 1.5.0
|
23
|
+
- 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.
|
24
|
+
- Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
|
25
|
+
- Opening a winrm shell is retriable with configurable delay and retry limit.
|
26
|
+
- Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
|
27
|
+
|
28
|
+
# 1.4.0
|
29
|
+
- Added WinRM::Version so the gem version is available at runtime for consumers.
|
30
|
+
|
31
|
+
# 1.3.6
|
32
|
+
- Remove BOM from response (Issue #159) added by Windows 2008R2
|
33
|
+
|
34
|
+
# 1.3.5
|
35
|
+
- Widen logging version constraints to include 2.0
|
36
|
+
- Use codepage 65001 (UTF-8)
|
37
|
+
|
38
|
+
# 1.3.4
|
39
|
+
- Relaxed version pins on dev dependencies
|
40
|
+
|
41
|
+
# 1.3.3
|
42
|
+
- Fixed issue 133, rwinrm allow hostnames with dashes
|
43
|
+
- Use duck typing for powershell script read
|
44
|
+
|
45
|
+
# 1.3.2
|
46
|
+
- Add spec.license attribute to gemspec
|
47
|
+
- Bump RSpec dependency 3.0 to 3.2
|
48
|
+
|
49
|
+
# 1.3.1
|
50
|
+
- Fixed issue 129, long running commands could cause a stackoverflow exception
|
51
|
+
- Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
|
52
|
+
- Fixed issue 124 rwinrm won't take '.' characters in username
|
53
|
+
|
54
|
+
# 1.3.0
|
55
|
+
- Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
|
56
|
+
- Refactored and added more unit and integration tests
|
57
|
+
- Added ability to write to stdin
|
58
|
+
- Added rwinrm binary to launch remote shell
|
59
|
+
- Added WINRM_LOG env var to set log level
|
60
|
+
- Retry Kerberos auth once if 401 response is received
|
61
|
+
- Remove Savon dependency and use newer versions of underlying dependencies
|
62
|
+
- Remove Nokogiri dependency and replace with native Ruby XML
|
63
|
+
- Fixed issue 85, ensure WQL response is not nil
|
64
|
+
- All WinRM library errors inherit from base class WinRMError
|
65
|
+
- Integrations tests should now pass on Windows Server 2008+
|
66
|
+
- Bump Ruby NTLM gem version dependency
|
67
|
+
- HTTP client receive timeout is now configurable via set_timeout
|
68
|
+
- Added backwards compatible Output class to make it easier to collect output
|
69
|
+
- Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
|
70
|
+
- Added Rubocop to build
|
71
|
+
- Fixed error when commands contain a newline character
|
72
|
+
|
73
|
+
# 1.2.0
|
74
|
+
- Allow user to disable SSL peer ceritifcate validation #44
|
75
|
+
- Allow commands with "'" chars on Ruby 2.x, fixes #69
|
76
|
+
- Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
|
77
|
+
- Commands with non-ASCII chars should work, #70
|