winrm-elevated 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e4916b2c5b46182c68c2e5e8a360fe34a7f580cc9664a93391e2e827d17eda9
4
- data.tar.gz: 17b6a1f2bd0253e1b9bdd605fea6412f8afed2e0131b14f00b359f98191eb002
3
+ metadata.gz: 0a697d6786acdc942c9144e8c726d3727ee22983bb21351f7a19be530873ec6a
4
+ data.tar.gz: cfa396d8c5a62a3a3174d996dc7f30347a4c8f9913468f3d27323067ac1f12e4
5
5
  SHA512:
6
- metadata.gz: 80fff66d02742310cccc2cedfb04f73610583f05240279a4b83508566aa732bd81838ab18b374f714323315f6758fabaf8913767fba6b5559874e3105f656331
7
- data.tar.gz: cd94f9e5cdb2ca9ae6b8d66f0a8b05db4e94b036b6ffe309d1418d52a0fb0eb8e6ac5c512d7d4754e15f3bd67beffb7d7caa312b99cbdaf810d5a81f6f2808b1
6
+ metadata.gz: c76b27bacedf07dd2f525cb98e04ddbb4a045b821eff0d97575e865ade5b980e28c062d5007c39201cd8cf1ed590f9cb6db5b8d4061b721617236afbfabe2f6c
7
+ data.tar.gz: 79a05661830ddb4b7bcf5423c67891368dc78cdd479278b30d56bd30493f9518e0fc92b3219f8d18ef5e45ece98d05af2595047b4b7f9006ab2f4256adebf1c7
@@ -13,5 +13,5 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- require 'winrm'
16
+ require 'winrm' unless defined?(WinRM::Connection)
17
17
  require_relative 'winrm/shells/elevated'
@@ -119,7 +119,17 @@ try { Remove-Item $script_file -ErrorAction Stop } catch {}
119
119
 
120
120
  $exit_code = $registered_task.LastTaskResult
121
121
 
122
- try { Unregister-ScheduledTask -TaskName $task_name -Confirm:$false } catch {}
122
+ try {
123
+ # Clean current task
124
+ $folder.DeleteTask($task_name, 0)
125
+ # Clean old tasks if required
126
+ $old_tasks_filter_date = [datetime]::Now.AddSeconds(<%= -1 * execution_timeout %>)
127
+ $old_tasks_to_kill = $folder.GetTasks(0) | Select Name,LastRunTime | Where-Object {
128
+ ($_.Name -like "WinRM_Elevated_Shell*") -and ($_.LastRunTime -le $old_tasks_filter_date) -and ($_.Name -ne $task_name)
129
+ }
130
+ $old_tasks_to_kill | ForEach-Object { try { $folder.DeleteTask($_.Name, 0) } catch {} }
131
+ }
132
+ catch {}
123
133
 
124
134
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null
125
135
 
@@ -14,9 +14,10 @@
14
14
  # limitations under the License.
15
15
 
16
16
  require 'erubi'
17
- require 'winrm'
17
+ require 'winrm' unless defined?(WinRM::Connection)
18
18
  require 'winrm-fs'
19
- require 'securerandom'
19
+ require 'securerandom' unless defined?(SecureRandom)
20
+ require 'stringio'
20
21
 
21
22
  module WinRM
22
23
  module Shells
@@ -72,24 +73,11 @@ module WinRM
72
73
 
73
74
  def upload_elevated_shell_script(script_text)
74
75
  elevated_shell_path = 'c:/windows/temp/winrm-elevated-shell-' + SecureRandom.uuid + '.ps1'
75
- with_temp_file(script_text) do |temp_file|
76
- @winrm_file_transporter.upload(temp_file, elevated_shell_path)
77
- end
76
+ script_text_with_exit = "#{script_text}\r\n$Host.SetShouldExit($LASTEXITCODE)"
77
+ @winrm_file_transporter.upload(StringIO.new(script_text_with_exit), elevated_shell_path)
78
78
  elevated_shell_path
79
79
  end
80
80
 
81
- def with_temp_file(script_text)
82
- file = Tempfile.new(%w[winrm-elevated-shell ps1])
83
- file.write(script_text)
84
- file.write("\r\n$Host.SetShouldExit($LASTEXITCODE)")
85
- file.fsync
86
- file.close
87
- yield file.path
88
- ensure
89
- file.close
90
- file.unlink
91
- end
92
-
93
81
  def elevated_shell_script_content
94
82
  IO.read(File.expand_path('../../winrm-elevated/scripts/elevated_shell.ps1', __dir__))
95
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm-elevated
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Neal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-12 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -134,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.7.8
137
+ rubygems_version: 3.1.2
139
138
  signing_key:
140
139
  specification_version: 4
141
140
  summary: Ruby library for running commands as elevated