mixlib-shellout 3.0.4 → 3.0.7

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: a1d11760771e83f70693a84e1073b52deb6577247c15c171812b9a3b872654f0
4
- data.tar.gz: 6c18e96112d21e666513555dc776259f7400142787ff21bef27b2063ea282c43
3
+ metadata.gz: 0ca06c3a60fc5bea01f33c33f69c43d7e8031d220a49625ded5753c47ecde9b9
4
+ data.tar.gz: 815fa8031fa4b50a8d2477ace37aa20090fe78eb246715588b0bd3b19480444e
5
5
  SHA512:
6
- metadata.gz: c746c6741617f66101f8c8a8817b84efa403dbe0f2bb2c9276ebb82377c6b89f7223e6ccac89d7a717a8e4534bb4005212b43d63754975503baf513b7d547536
7
- data.tar.gz: e351af12c38924c2f4000146d3a309cd319045c658f864839418c9a3ab6d71b5f3bf0991c6b51bad8b7ed3afe7d40bf0d96e7e0b7e7da5df33b0d7390dd748de
6
+ metadata.gz: 470b0b0c9b923f44580a3d73c33c4413b6df170b56e3a1c3e392e1f71882cb4cee3f9bb91750c3335f460f79c2684978cf3ceb95bc2324958e8cd191a8f772b4
7
+ data.tar.gz: 7fb95480a956559fd665eae9031f54c832fd83a26ecd0dabc7c525ce5a2ca94c9f80427f6704ac64c18aceb8abf26db014131a90ed856e2994eccc10163cc9e3
@@ -210,15 +210,17 @@ module Mixlib
210
210
  # TODO migrate to shellout/unix.rb
211
211
  def uid
212
212
  return nil unless user
213
- user.kind_of?(Integer) ? user : Etc.getpwnam(user.to_s).uid
213
+
214
+ user.is_a?(Integer) ? user : Etc.getpwnam(user.to_s).uid
214
215
  end
215
216
 
216
217
  # The gid that the subprocess will switch to. If the group attribute is
217
218
  # given as a group name, it is converted to a gid by Etc.getgrnam
218
219
  # TODO migrate to shellout/unix.rb
219
220
  def gid
220
- return group.kind_of?(Integer) ? group : Etc.getgrnam(group.to_s).gid if group
221
+ return group.is_a?(Integer) ? group : Etc.getgrnam(group.to_s).gid if group
221
222
  return Etc.getpwuid(uid).gid if using_login?
223
+
222
224
  nil
223
225
  end
224
226
 
@@ -231,6 +233,7 @@ module Mixlib
231
233
  # results when the command exited with an unexpected status.
232
234
  def format_for_exception
233
235
  return "Command execution failed. STDOUT/STDERR suppressed for sensitive resource" if sensitive
236
+
234
237
  msg = ""
235
238
  msg << "#{@terminate_reason}\n" if @terminate_reason
236
239
  msg << "---- Begin output of #{command} ----\n"
@@ -363,6 +366,7 @@ module Mixlib
363
366
  if login && !user
364
367
  raise InvalidCommandOption, "cannot set login without specifying a user"
365
368
  end
369
+
366
370
  super
367
371
  end
368
372
  end
@@ -53,14 +53,16 @@ module Mixlib
53
53
  # to the user's secondary groups
54
54
  def sgids
55
55
  return nil unless using_login?
56
+
56
57
  user_name = Etc.getpwuid(uid).name
57
- all_seconderies.select { |g| g.mem.include?(user_name) }.map { |g| g.gid }
58
+ all_seconderies.select { |g| g.mem.include?(user_name) }.map(&:gid)
58
59
  end
59
60
 
60
61
  # The environment variables that are deduced from simulating logon
61
62
  # Only valid if login is used
62
63
  def logon_environment
63
64
  return {} unless using_login?
65
+
64
66
  entry = Etc.getpwuid(uid)
65
67
  # According to `man su`, the set fields are:
66
68
  # $HOME, $SHELL, $USER, $LOGNAME, $PATH, and $IFS
@@ -269,6 +271,7 @@ module Mixlib
269
271
  # Keep this unbuffered for now
270
272
  def write_to_child_stdin
271
273
  return unless input
274
+
272
275
  child_stdin << input
273
276
  child_stdin.close # Kick things off
274
277
  end
@@ -337,7 +340,7 @@ module Mixlib
337
340
  set_cwd
338
341
 
339
342
  begin
340
- command.kind_of?(Array) ? exec(*command, close_others: true) : exec(command, close_others: true)
343
+ command.is_a?(Array) ? exec(*command, close_others: true) : exec(command, close_others: true)
341
344
 
342
345
  raise "forty-two" # Should never get here
343
346
  rescue Exception => e
@@ -365,6 +368,7 @@ module Mixlib
365
368
 
366
369
  def reap_errant_child
367
370
  return if attempt_reap
371
+
368
372
  @terminate_reason = "Command exceeded allowed execution time, process terminated"
369
373
  logger.error("Command exceeded allowed execution time, sending TERM") if logger
370
374
  Process.kill(:TERM, child_pgid)
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "3.0.4".freeze
3
+ VERSION = "3.0.7".freeze
4
4
  end
5
5
  end
@@ -88,7 +88,7 @@ module Mixlib
88
88
  #
89
89
  # Start the process
90
90
  #
91
- process, profile, token = Process.create(create_process_args)
91
+ process, profile, token = Process.create3(create_process_args)
92
92
  logger.debug(format_process(process, app_name, command_line, timeout)) if logger
93
93
  begin
94
94
  # Start pushing data into input
@@ -110,6 +110,7 @@ module Mixlib
110
110
  unless GetExitCodeProcess(process.process_handle, exit_code)
111
111
  raise get_last_error
112
112
  end
113
+
113
114
  @status = ThingThatLooksSortOfLikeAProcessStatus.new
114
115
  @status.exitstatus = exit_code.unpack("l").first
115
116
 
@@ -170,8 +171,9 @@ module Mixlib
170
171
 
171
172
  def consume_output(open_streams, stdout_read, stderr_read)
172
173
  return false if open_streams.length == 0
174
+
173
175
  ready = IO.select(open_streams, nil, nil, READ_WAIT_TIME)
174
- return true if ! ready
176
+ return true unless ready
175
177
 
176
178
  if ready.first.include?(stdout_read)
177
179
  begin
@@ -227,6 +229,7 @@ module Mixlib
227
229
  # @return String
228
230
  def combine_args(*args)
229
231
  return args[0] if args.length == 1
232
+
230
233
  args.map do |arg|
231
234
  if arg =~ /[ \t\n\v"]/
232
235
  arg = arg.gsub(/(\\*)"/, '\1\1\"') # interior quotes with N preceeding backslashes need 2N+1 backslashes
@@ -321,10 +324,12 @@ module Mixlib
321
324
  return true unless quote
322
325
  when "%"
323
326
  return true if env
327
+
324
328
  env = env_first_char = true
325
329
  next
326
330
  else
327
331
  next unless env
332
+
328
333
  if env_first_char
329
334
  env_first_char = false
330
335
  (env = false) && next if c !~ /[A-Za-z_]/
@@ -370,6 +375,7 @@ module Mixlib
370
375
 
371
376
  def unsafe_process?(name, logger)
372
377
  return false unless system_required_processes.include? name
378
+
373
379
  logger.debug(
374
380
  "A request to kill a critical system process - #{name} - was received and skipped."
375
381
  )
@@ -383,6 +389,7 @@ module Mixlib
383
389
  def kill_process_tree(pid, wmi, logger)
384
390
  wmi.query("select * from Win32_Process where ParentProcessID=#{pid}").each do |instance|
385
391
  next if unsafe_process?(instance.wmi_ole_object.name, logger)
392
+
386
393
  child_pid = instance.wmi_ole_object.processid
387
394
  kill_process_tree(child_pid, wmi, logger)
388
395
  kill_process(instance, logger)
@@ -73,19 +73,19 @@ module Process::Functions
73
73
  [:pointer], :bool
74
74
 
75
75
  attach_pfunc :LoadUserProfileW,
76
- [:handle, :pointer], :bool
76
+ %i{handle pointer}, :bool
77
77
 
78
78
  attach_pfunc :UnloadUserProfile,
79
- [:handle, :handle], :bool
79
+ %i{handle handle}, :bool
80
80
 
81
81
  ffi_lib :advapi32
82
82
 
83
83
  attach_pfunc :LogonUserW,
84
- [:buffer_in, :buffer_in, :buffer_in, :ulong, :ulong, :pointer], :bool
84
+ %i{buffer_in buffer_in buffer_in ulong ulong pointer}, :bool
85
85
 
86
86
  attach_pfunc :CreateProcessAsUserW,
87
- [:ulong, :buffer_in, :buffer_inout, :pointer, :pointer, :int,
88
- :ulong, :buffer_in, :buffer_in, :pointer, :pointer], :bool
87
+ %i{ulong buffer_in buffer_inout pointer pointer int
88
+ ulong buffer_in buffer_in pointer pointer}, :bool
89
89
 
90
90
  ffi_lib :user32
91
91
 
@@ -93,7 +93,7 @@ module Process::Functions
93
93
  [], :ulong
94
94
 
95
95
  attach_pfunc :GetUserObjectInformationA,
96
- [:ulong, :uint, :buffer_out, :ulong, :pointer], :bool
96
+ %i{ulong uint buffer_out ulong pointer}, :bool
97
97
  end
98
98
 
99
99
  # Override Process.create to check for running in the Service window station and doing
@@ -109,7 +109,11 @@ module Process
109
109
  class << self
110
110
 
111
111
  def create(args)
112
- unless args.kind_of?(Hash)
112
+ create3(args).first
113
+ end
114
+
115
+ def create3(args)
116
+ unless args.is_a?(Hash)
113
117
  raise TypeError, "hash keyword arguments expected"
114
118
  end
115
119
 
@@ -137,6 +141,7 @@ module Process
137
141
  unless valid_keys.include?(key)
138
142
  raise ArgumentError, "invalid key '#{key}'"
139
143
  end
144
+
140
145
  hash[key] = val
141
146
  end
142
147
 
@@ -149,6 +154,7 @@ module Process
149
154
  unless valid_si_keys.include?(key)
150
155
  raise ArgumentError, "invalid startup_info key '#{key}'"
151
156
  end
157
+
152
158
  si_hash[key] = val
153
159
  end
154
160
  end
@@ -367,6 +373,7 @@ module Process
367
373
  unless GetProfileType(ptr)
368
374
  raise SystemCallError.new("GetProfileType", FFI.errno)
369
375
  end
376
+
370
377
  ptr.read_uint
371
378
  end
372
379
 
@@ -374,6 +381,7 @@ module Process
374
381
  unless LoadUserProfileW(token, profile_ptr)
375
382
  raise SystemCallError.new("LoadUserProfileW", FFI.errno)
376
383
  end
384
+
377
385
  true
378
386
  end
379
387
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-shellout
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-06 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Run external commands on Unix or Windows
14
14
  email: info@chef.io