WinRb / winrm-elevated

Runs PowerShell commands as elevated over Windows Remote Management (WinRM) via a scheduled task
Apache License 2.0
27 stars 17 forks source link

Conflict With md5 names for output files #19

Closed ITD27M01 closed 7 years ago

ITD27M01 commented 7 years ago

Hi guys. I found another race condition for scripts that have the same output. May be this problem is resolved in new version ?

My script:

require 'winrm'
require 'winrm-elevated'

code = "Get-Host"

endpoint = 'https://winrm.example.com:5986/wsman'
winrm = WinRM::WinRMWebService.new(endpoint, :ssl, :user => 'VP_DNS_Account', :pass => 'password', :no_ssl_peer_verification => true)

winrm.create_executor do |executor|
  elevated_runner = WinRM::Elevated::Runner.new(executor)
  result = elevated_runner.powershell_elevated(code, 'VP_DNS_Account', 'password')
  puts "Std out: #{result.output}"
end

My ERROR:

[root@miq02 scripts]# ruby winrm.rb & ruby winrm.rb &
[1] 24596
[2] 24597
[root@miq02 scripts]# /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:394:in `parse_response': [WinRM::FS::Core::FileTransporter] Upload failed (exitcode: 1) (WinRM::FS::Core::FileTransporterFailed)
gi : Cannot find path 'C:\Users\VP_DNS~1\AppData\Local\Temp\b64-0c80d94b729a42134397ceafdd26856e.txt' because it does n
ot exist.
At line:18 char:16
+       $sMd5 = (gi $tmp).BaseName.Replace("b64-", "")
+                ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\VP_DNS...eafdd26856e.txt:String) [Get-Item], ItemNotFoundExcep 
   tion
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

You cannot call a method on a null-valued expression.
At line:18 char:7
+       $sMd5 = (gi $tmp).BaseName.Replace("b64-", "")
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvokeMethodOnNull

        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:273:in `decode_files'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:94:in `block in upload'
        from /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:93:in `upload'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-elevated-0.4.0/lib/winrm-elevated/runner.rb:56:in `block in upload_elevated_shell_wrapper_script'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-elevated-0.4.0/lib/winrm-elevated/runner.rb:66:in `with_temp_file'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-elevated-0.4.0/lib/winrm-elevated/runner.rb:55:in `upload_elevated_shell_wrapper_script'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-elevated-0.4.0/lib/winrm-elevated/runner.rb:46:in `powershell_elevated'
        from winrm.rb:11:in `block in <main>'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/winrm-1.7.3/lib/winrm/winrm_service.rb:360:in `create_executor'
        from winrm.rb:9:in `<main>'
Std out: 

Name             : ConsoleHost
Version          : 5.1.14393.0
InstanceId       : a651ce96-60d0-42d9-8f9b-b5666134ece9
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : ru-RU
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

[1]-  Done                    ruby winrm.rb
[2]+  Exit 1                  ruby winrm.rb

Versions are listed here: https://access.redhat.com/articles/2936901

https://github.com/WinRb/winrm-elevated/issues/5

mwrock commented 7 years ago

This should be fixed in the latest version.