puppet 5.5.16-x64-mingw32 → 5.5.17-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +9 -9
  3. data/Gemfile.lock +18 -18
  4. data/ext/project_data.yaml +2 -2
  5. data/install.rb +3 -21
  6. data/lib/puppet/application/agent.rb +12 -0
  7. data/lib/puppet/application/device.rb +4 -4
  8. data/lib/puppet/application/resource.rb +4 -4
  9. data/lib/puppet/defaults.rb +4 -0
  10. data/lib/puppet/face/config.rb +10 -48
  11. data/lib/puppet/face/facts.rb +1 -1
  12. data/lib/puppet/face/plugin.rb +9 -2
  13. data/lib/puppet/module_tool/tar/mini.rb +11 -1
  14. data/lib/puppet/network/http/factory.rb +1 -11
  15. data/lib/puppet/parameter.rb +8 -0
  16. data/lib/puppet/provider/file/posix.rb +5 -0
  17. data/lib/puppet/provider/nameservice.rb +10 -3
  18. data/lib/puppet/provider/package/dnf.rb +1 -1
  19. data/lib/puppet/provider/package/rpm.rb +51 -13
  20. data/lib/puppet/provider/package/yum.rb +8 -4
  21. data/lib/puppet/provider/service/launchd.rb +20 -5
  22. data/lib/puppet/provider/service/systemd.rb +4 -9
  23. data/lib/puppet/provider/service/windows.rb +8 -0
  24. data/lib/puppet/provider/user/pw.rb +12 -3
  25. data/lib/puppet/provider/user/user_role_add.rb +4 -0
  26. data/lib/puppet/provider/user/useradd.rb +23 -7
  27. data/lib/puppet/resource.rb +17 -0
  28. data/lib/puppet/settings.rb +40 -0
  29. data/lib/puppet/type.rb +7 -0
  30. data/lib/puppet/type/exec.rb +14 -6
  31. data/lib/puppet/type/package.rb +10 -0
  32. data/lib/puppet/type/service.rb +7 -2
  33. data/lib/puppet/type/user.rb +1 -15
  34. data/lib/puppet/type/yumrepo.rb +3 -7
  35. data/lib/puppet/util/execution.rb +4 -3
  36. data/lib/puppet/util/http_proxy.rb +16 -2
  37. data/lib/puppet/util/selinux.rb +5 -1
  38. data/lib/puppet/util/windows/security.rb +2 -0
  39. data/lib/puppet/util/windows/service.rb +149 -4
  40. data/lib/puppet/util/windows/sid.rb +1 -0
  41. data/lib/puppet/version.rb +1 -1
  42. data/locales/puppet.pot +189 -193
  43. data/man/man5/puppet.conf.5 +10 -2
  44. data/man/man8/puppet-agent.8 +1 -1
  45. data/man/man8/puppet-apply.8 +1 -1
  46. data/man/man8/puppet-ca.8 +1 -1
  47. data/man/man8/puppet-catalog.8 +1 -1
  48. data/man/man8/puppet-cert.8 +1 -1
  49. data/man/man8/puppet-certificate.8 +1 -1
  50. data/man/man8/puppet-certificate_request.8 +1 -1
  51. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  52. data/man/man8/puppet-config.8 +1 -1
  53. data/man/man8/puppet-describe.8 +1 -1
  54. data/man/man8/puppet-device.8 +1 -1
  55. data/man/man8/puppet-doc.8 +1 -1
  56. data/man/man8/puppet-epp.8 +1 -1
  57. data/man/man8/puppet-facts.8 +1 -1
  58. data/man/man8/puppet-filebucket.8 +1 -1
  59. data/man/man8/puppet-generate.8 +1 -1
  60. data/man/man8/puppet-help.8 +1 -1
  61. data/man/man8/puppet-key.8 +1 -1
  62. data/man/man8/puppet-lookup.8 +1 -1
  63. data/man/man8/puppet-man.8 +1 -1
  64. data/man/man8/puppet-master.8 +1 -1
  65. data/man/man8/puppet-module.8 +1 -1
  66. data/man/man8/puppet-node.8 +1 -1
  67. data/man/man8/puppet-parser.8 +1 -1
  68. data/man/man8/puppet-plugin.8 +1 -1
  69. data/man/man8/puppet-report.8 +1 -1
  70. data/man/man8/puppet-resource.8 +1 -1
  71. data/man/man8/puppet-script.8 +1 -1
  72. data/man/man8/puppet-status.8 +1 -1
  73. data/man/man8/puppet.8 +2 -2
  74. data/spec/integration/provider/service/systemd_spec.rb +8 -5
  75. data/spec/integration/type/file_spec.rb +28 -0
  76. data/spec/integration/util/execution_spec.rb +27 -0
  77. data/spec/unit/application/agent_spec.rb +18 -0
  78. data/spec/unit/application/device_spec.rb +1 -1
  79. data/spec/unit/face/facts_spec.rb +9 -0
  80. data/spec/unit/face/plugin_spec.rb +8 -0
  81. data/spec/unit/module_tool/tar/mini_spec.rb +1 -1
  82. data/spec/unit/network/http/api/indirected_routes_spec.rb +26 -10
  83. data/spec/unit/network/http/factory_spec.rb +27 -5
  84. data/spec/unit/pops/validator/validator_spec.rb +7 -0
  85. data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
  86. data/spec/unit/provider/package/dnf_spec.rb +7 -0
  87. data/spec/unit/provider/package/rpm_spec.rb +150 -16
  88. data/spec/unit/provider/package/yum_spec.rb +7 -0
  89. data/spec/unit/provider/service/launchd_spec.rb +28 -0
  90. data/spec/unit/provider/service/windows_spec.rb +20 -0
  91. data/spec/unit/provider/user/pw_spec.rb +37 -0
  92. data/spec/unit/provider/user/useradd_spec.rb +42 -0
  93. data/spec/unit/resource_spec.rb +26 -1
  94. data/spec/unit/transaction_spec.rb +18 -0
  95. data/spec/unit/type/exec_spec.rb +9 -0
  96. data/spec/unit/type/file/source_spec.rb +4 -4
  97. data/spec/unit/type/schedule_spec.rb +3 -1
  98. data/spec/unit/type/service_spec.rb +16 -0
  99. data/spec/unit/type/user_spec.rb +13 -13
  100. data/spec/unit/type/yumrepo_spec.rb +30 -0
  101. data/spec/unit/type_spec.rb +40 -0
  102. data/spec/unit/util/http_proxy_spec.rb +24 -1
  103. data/spec/unit/util/log_spec.rb +27 -1
  104. data/spec/unit/util/windows/service_spec.rb +9 -0
  105. metadata +5 -9
  106. data/ext/windows/eventlog/Rakefile +0 -32
  107. data/ext/windows/eventlog/puppetres.dll +0 -0
  108. data/ext/windows/eventlog/puppetres.mc +0 -18
@@ -2443,6 +2443,13 @@ end
2443
2443
  err(_("Unable to mark '%{name}' as sensitive: the property itself is not defined on %{type}.") % { name: name, type: type })
2444
2444
  end
2445
2445
  end
2446
+
2447
+ parameters.each do |name, param|
2448
+ next if param.sensitive
2449
+ if param.is_a?(Puppet::Parameter)
2450
+ param.sensitive = param.is_sensitive if param.respond_to?(:is_sensitive)
2451
+ end
2452
+ end
2446
2453
  end
2447
2454
 
2448
2455
  private
@@ -455,9 +455,13 @@ module Puppet
455
455
  return false
456
456
  end
457
457
 
458
- output.split(/\n/).each { |line|
459
- self.debug(line)
460
- }
458
+ if sensitive
459
+ self.debug("[output redacted]")
460
+ else
461
+ output.split(/\n/).each { |line|
462
+ self.debug(line)
463
+ }
464
+ end
461
465
 
462
466
  status.exitstatus != 0
463
467
  end
@@ -507,9 +511,13 @@ module Puppet
507
511
  return false
508
512
  end
509
513
 
510
- output.split(/\n/).each { |line|
511
- self.debug(line)
512
- }
514
+ if sensitive
515
+ self.debug("[output redacted]")
516
+ else
517
+ output.split(/\n/).each { |line|
518
+ self.debug(line)
519
+ }
520
+ end
513
521
 
514
522
  status.exitstatus == 0
515
523
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # Define the different packaging systems. Each package system is implemented
2
3
  # in a module, which then gets used to individually extend each package object.
3
4
  # This allows packages to exist on the same machine using different packaging
@@ -56,6 +57,7 @@ module Puppet
56
57
  a user or another package. Held is considered a superset of
57
58
  installed.",
58
59
  :methods => [:hold]
60
+ feature :install_only, "The provider accepts options to only install packages never update (kernels, etc.)"
59
61
  feature :install_options, "The provider accepts options to be
60
62
  passed to the installer command."
61
63
  feature :uninstall_options, "The provider accepts options to be
@@ -483,6 +485,14 @@ module Puppet
483
485
  which type of package you want."
484
486
  end
485
487
 
488
+ newparam(:install_only, :boolean => false, :parent => Puppet::Parameter::Boolean, :required_features => :install_only) do
489
+ desc <<-EOT
490
+ It should be set for packages that should only ever be installed,
491
+ never updated. Kernels in particular fall into this category.
492
+ EOT
493
+ defaultto false
494
+ end
495
+
486
496
  newparam(:install_options, :parent => Puppet::Parameter::PackageOptions, :required_features => :install_options) do
487
497
  desc <<-EOT
488
498
  An array of additional options to pass when installing a package. These
@@ -73,6 +73,11 @@ module Puppet
73
73
  provider.enabled?
74
74
  end
75
75
 
76
+ # This only works on Windows systems.
77
+ newvalue(:delayed, :event => :service_delayed_start) do
78
+ provider.delayed_start
79
+ end
80
+
76
81
  # This only makes sense on systemd systems. Static services cannot be enabled
77
82
  # or disabled manually.
78
83
  def insync?(current)
@@ -85,8 +90,8 @@ module Puppet
85
90
  end
86
91
 
87
92
  validate do |value|
88
- if value == :manual and !Puppet.features.microsoft_windows?
89
- raise Puppet::Error.new(_("Setting enable to manual is only supported on Microsoft Windows."))
93
+ if (value == :manual || value == :delayed) && !Puppet.features.microsoft_windows?
94
+ raise Puppet::Error.new(_("Setting enable to %{value} is only supported on Microsoft Windows.") % { value: value.to_s} )
90
95
  end
91
96
  end
92
97
  end
@@ -255,21 +255,7 @@ module Puppet
255
255
  raise ArgumentError, _("Passwords cannot include ':'") if value.is_a?(String) and value.include?(":")
256
256
  end
257
257
 
258
- def change_to_s(currentvalue, newvalue)
259
- if currentvalue == :absent
260
- return _("created password")
261
- else
262
- return _("changed password")
263
- end
264
- end
265
-
266
- def is_to_s( currentvalue )
267
- return _('[old password hash redacted]')
268
- end
269
- def should_to_s( newvalue )
270
- return _('[new password hash redacted]')
271
- end
272
-
258
+ sensitive true
273
259
  end
274
260
 
275
261
  newproperty(:password_min_age, :required_features => :manages_password_age) do
@@ -321,6 +321,8 @@ Puppet::Type.newtype(:yumrepo) do
321
321
  desc "Password for this proxy. #{ABSENT_DOC}"
322
322
 
323
323
  newvalues(/.*/, :absent)
324
+
325
+ sensitive true
324
326
  end
325
327
 
326
328
  newproperty(:s3_enabled) do
@@ -423,12 +425,6 @@ Puppet::Type.newtype(:yumrepo) do
423
425
  desc "Password to use with the username for basic authentication.
424
426
  #{ABSENT_DOC}"
425
427
  newvalues(/.*/, :absent)
426
- end
427
-
428
- private
429
-
430
- def set_sensitive_parameters(sensitive_parameters)
431
- parameter(:password).sensitive = true if parameter(:password)
432
- super(sensitive_parameters)
428
+ sensitive true
433
429
  end
434
430
  end
@@ -162,15 +162,16 @@ module Puppet::Util::Execution
162
162
 
163
163
  options = default_options.merge(options)
164
164
 
165
- if options[:sensitive]
166
- command_str = '[redacted]'
167
- elsif command.is_a?(Array)
165
+ if command.is_a?(Array)
168
166
  command = command.flatten.map(&:to_s)
169
167
  command_str = command.join(" ")
170
168
  elsif command.is_a?(String)
171
169
  command_str = command
172
170
  end
173
171
 
172
+ # do this after processing 'command' array or string
173
+ command_str = '[redacted]' if options[:sensitive]
174
+
174
175
  user_log_s = ''
175
176
  if options[:uid]
176
177
  user_log_s << " uid=#{options[:uid]}"
@@ -33,7 +33,7 @@ module Puppet::Util::HttpProxy
33
33
  # .example.com
34
34
  # We'll accommodate both here.
35
35
  def self.no_proxy?(dest)
36
- unless no_proxy_env = ENV["no_proxy"] || ENV["NO_PROXY"]
36
+ unless no_proxy = self.no_proxy
37
37
  return false
38
38
  end
39
39
 
@@ -45,7 +45,7 @@ module Puppet::Util::HttpProxy
45
45
  end
46
46
  end
47
47
 
48
- no_proxy_env.split(/\s*,\s*/).each do |d|
48
+ no_proxy.split(/\s*,\s*/).each do |d|
49
49
  host, port = d.split(':')
50
50
  host = Regexp.escape(host).gsub('\*', '.*')
51
51
 
@@ -127,6 +127,20 @@ module Puppet::Util::HttpProxy
127
127
  return Puppet.settings[:http_proxy_password]
128
128
  end
129
129
 
130
+ def self.no_proxy
131
+ no_proxy_env = ENV["no_proxy"] || ENV["NO_PROXY"]
132
+
133
+ if no_proxy_env
134
+ return no_proxy_env
135
+ end
136
+
137
+ if Puppet.settings[:no_proxy] == 'none'
138
+ return nil
139
+ end
140
+
141
+ return Puppet.settings[:no_proxy]
142
+ end
143
+
130
144
  # Return a Net::HTTP::Proxy object.
131
145
  #
132
146
  # This method optionally configures SSL correctly if the URI scheme is
@@ -13,7 +13,7 @@ require 'pathname'
13
13
 
14
14
  module Puppet::Util::SELinux
15
15
 
16
- def selinux_support?
16
+ def self.selinux_support?
17
17
  return false unless defined?(Selinux)
18
18
  if Selinux.is_selinux_enabled == 1
19
19
  return true
@@ -21,6 +21,10 @@ module Puppet::Util::SELinux
21
21
  false
22
22
  end
23
23
 
24
+ def selinux_support?
25
+ Puppet::Util::SELinux.selinux_support?
26
+ end
27
+
24
28
  # Retrieve and return the full context of the file. If we don't have
25
29
  # SELinux support or if the SELinux call fails then return nil.
26
30
  def get_selinux_current_context(file)
@@ -200,6 +200,7 @@ module Puppet::Util::Windows::Security
200
200
  well_known_world_sid = Puppet::Util::Windows::SID::Everyone
201
201
  well_known_nobody_sid = Puppet::Util::Windows::SID::Nobody
202
202
  well_known_system_sid = Puppet::Util::Windows::SID::LocalSystem
203
+ well_known_app_packages_sid = Puppet::Util::Windows::SID::AllAppPackages
203
204
 
204
205
  mode = S_ISYSTEM_MISSING
205
206
 
@@ -234,6 +235,7 @@ module Puppet::Util::Windows::Security
234
235
  if (ace.mask & FILE::FILE_APPEND_DATA).nonzero?
235
236
  mode |= S_ISVTX
236
237
  end
238
+ when well_known_app_packages_sid
237
239
  when well_known_system_sid
238
240
  else
239
241
  #puts "Warning, unable to map SID into POSIX mode: #{ace.sid}"
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'puppet/util/windows'
2
3
  require 'ffi'
3
4
 
@@ -180,7 +181,30 @@ module Puppet::Util::Windows
180
181
  # // Value to indicate no change to an optional parameter
181
182
  # //
182
183
  # #define SERVICE_NO_CHANGE 0xffffffff
183
- SERVICE_NO_CHANGE = 0xffffffff
184
+ # https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-changeserviceconfig2w
185
+ SERVICE_CONFIG_DESCRIPTION = 0x00000001
186
+ SERVICE_CONFIG_FAILURE_ACTIONS = 0x00000002
187
+ SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 0x00000003
188
+ SERVICE_CONFIG_FAILURE_ACTIONS_FLAG = 0x00000004
189
+ SERVICE_CONFIG_SERVICE_SID_INFO = 0x00000005
190
+ SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 0x00000006
191
+ SERVICE_CONFIG_PRESHUTDOWN_INFO = 0x00000007
192
+ SERVICE_CONFIG_TRIGGER_INFO = 0x00000008
193
+ SERVICE_CONFIG_PREFERRED_NODE = 0x00000009
194
+ SERVICE_CONFIG_LAUNCH_PROTECTED = 0x00000012
195
+ SERVICE_NO_CHANGE = 0xffffffff
196
+ SERVICE_CONFIG_TYPES = {
197
+ SERVICE_CONFIG_DESCRIPTION => :SERVICE_CONFIG_DESCRIPTION,
198
+ SERVICE_CONFIG_FAILURE_ACTIONS => :SERVICE_CONFIG_FAILURE_ACTIONS,
199
+ SERVICE_CONFIG_DELAYED_AUTO_START_INFO => :SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
200
+ SERVICE_CONFIG_FAILURE_ACTIONS_FLAG => :SERVICE_CONFIG_FAILURE_ACTIONS_FLAG,
201
+ SERVICE_CONFIG_SERVICE_SID_INFO => :SERVICE_CONFIG_SERVICE_SID_INFO,
202
+ SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO => :SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO,
203
+ SERVICE_CONFIG_PRESHUTDOWN_INFO => :SERVICE_CONFIG_PRESHUTDOWN_INFO,
204
+ SERVICE_CONFIG_TRIGGER_INFO => :SERVICE_CONFIG_TRIGGER_INFO,
205
+ SERVICE_CONFIG_PREFERRED_NODE => :SERVICE_CONFIG_PREFERRED_NODE,
206
+ SERVICE_CONFIG_LAUNCH_PROTECTED => :SERVICE_CONFIG_LAUNCH_PROTECTED,
207
+ }
184
208
 
185
209
  # Service enum codes
186
210
  # https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-enumservicesstatusexa
@@ -219,6 +243,19 @@ module Puppet::Util::Windows
219
243
  )
220
244
  end
221
245
 
246
+ # https://docs.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_delayed_auto_start_info
247
+ # typedef struct _SERVICE_DELAYED_AUTO_START_INFO {
248
+ # BOOL fDelayedAutostart;
249
+ # } SERVICE_DELAYED_AUTO_START_INFO, *LPSERVICE_DELAYED_AUTO_START_INFO;
250
+ class SERVICE_DELAYED_AUTO_START_INFO < FFI::Struct
251
+ layout(:fDelayedAutostart, :int)
252
+ alias aset []=
253
+ # Intercept the accessor so that we can handle either true/false or 1/0.
254
+ # Since there is only one member, there’s no need to check the key name.
255
+ def []=(key, value)
256
+ [0, false].include?(value) ? aset(key, 0) : aset(key, 1)
257
+ end
258
+ end
222
259
 
223
260
  # https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/ns-winsvc-_enum_service_status_processw
224
261
  # typedef struct _ENUM_SERVICE_STATUS_PROCESSW {
@@ -374,6 +411,7 @@ module Puppet::Util::Windows
374
411
  module_function :service_state
375
412
 
376
413
  # Query the configuration of a service using QueryServiceConfigW
414
+ # or QueryServiceConfig2W
377
415
  #
378
416
  # @param [:string] service_name name of the service to query
379
417
  # @return [QUERY_SERVICE_CONFIGW.struct] the configuration of the service
@@ -384,6 +422,14 @@ module Puppet::Util::Windows
384
422
  start_type = SERVICE_START_TYPES[config[:dwStartType]]
385
423
  end
386
424
  end
425
+ # if the service has type AUTO_START, check if it's a delayed service
426
+ if start_type == :SERVICE_AUTO_START
427
+ open_service(service_name, SC_MANAGER_CONNECT, SERVICE_QUERY_CONFIG) do |service|
428
+ query_config2(service, SERVICE_CONFIG_DELAYED_AUTO_START_INFO) do |config|
429
+ return :SERVICE_DELAYED_AUTO_START if config[:fDelayedAutostart] == 1
430
+ end
431
+ end
432
+ end
387
433
  if start_type.nil?
388
434
  raise Puppet::Error.new(_("Unknown start type '%{start_type}' for '%{service_name}'") % { start_type: start_type.to_s, service_name: service_name})
389
435
  end
@@ -393,11 +439,12 @@ module Puppet::Util::Windows
393
439
 
394
440
  # Change the startup mode of a windows service
395
441
  #
396
- # @param [string] service_name the name of the service to modify
397
- # @param [Int] startup_type a code corresponding to a start type for
442
+ # @param [String] service_name the name of the service to modify
443
+ # @param [Integer] startup_type a code corresponding to a start type for
398
444
  # windows service, see the "Service start type codes" section in the
399
445
  # Puppet::Util::Windows::Service file for the list of available codes
400
- def set_startup_mode(service_name, startup_type)
446
+ # @param [Bool] delayed whether the service should be started with a delay
447
+ def set_startup_mode(service_name, startup_type, delayed=false)
401
448
  startup_code = SERVICE_START_TYPES.key(startup_type)
402
449
  if startup_code.nil?
403
450
  raise Puppet::Error.new(_("Unknown start type %{start_type}") % {startup_type: startup_type.to_s})
@@ -424,6 +471,7 @@ module Puppet::Util::Windows
424
471
  raise Puppet::Util::Windows::Error.new(_("Failed to update service configuration"))
425
472
  end
426
473
  end
474
+ set_startup_mode_delayed(service_name, delayed)
427
475
  end
428
476
  module_function :set_startup_mode
429
477
 
@@ -705,6 +753,82 @@ module Puppet::Util::Windows
705
753
  end
706
754
  private :query_config
707
755
 
756
+ # @api private
757
+ # perform QueryServiceConfig2W on a windows service and return the
758
+ # result
759
+ #
760
+ # @param [:handle] service handle of the service to query
761
+ # @param [Integer] info_level the configuration information to be queried
762
+ # @return [QUERY_SERVICE_CONFIG2W struct] the result of the query
763
+ def query_config2(service, info_level, &block)
764
+ config = nil
765
+ size_required = nil
766
+ # Fetch the bytes of memory required to be allocated
767
+ # for QueryServiceConfig2W to return succesfully. This
768
+ # is done by sending NULL and 0 for the pointer and size
769
+ # respectively, letting the command fail, then reading the
770
+ # value of pcbBytesNeeded
771
+ FFI::MemoryPointer.new(:lpword) do |bytes_pointer|
772
+ # return value will be false from this call, since it's designed
773
+ # to fail. Just ignore it
774
+ QueryServiceConfig2W(service, info_level, FFI::Pointer::NULL, 0, bytes_pointer)
775
+ size_required = bytes_pointer.read_dword
776
+ FFI::MemoryPointer.new(size_required) do |ssp_ptr|
777
+ # We need to supply the appropriate struct to be created based on
778
+ # the info_level
779
+ case info_level
780
+ when SERVICE_CONFIG_DELAYED_AUTO_START_INFO
781
+ config = SERVICE_DELAYED_AUTO_START_INFO.new(ssp_ptr)
782
+ end
783
+ success = QueryServiceConfig2W(
784
+ service,
785
+ info_level,
786
+ ssp_ptr,
787
+ size_required,
788
+ bytes_pointer
789
+ )
790
+ if success == FFI::WIN32_FALSE
791
+ raise Puppet::Util::Windows::Error.new(_("Service query for %{parameter_name} failed") % { parameter_name: SERVICE_CONFIG_TYPES[info_level] } )
792
+ end
793
+ yield config
794
+ end
795
+ end
796
+ end
797
+ private :query_config2
798
+
799
+ # @api private
800
+ # Sets an optional parameter on a service by calling
801
+ # ChangeServiceConfig2W
802
+ #
803
+ # @param [String] service_name name of service
804
+ # @param [Integer] change parameter to change
805
+ # @param [struct] value appropriate struct based on the parameter to change
806
+ def set_optional_parameter(service_name, change, value)
807
+ open_service(service_name, SC_MANAGER_CONNECT, SERVICE_CHANGE_CONFIG) do |service|
808
+ success = ChangeServiceConfig2W(
809
+ service,
810
+ change, # dwInfoLevel
811
+ value, # lpInfo
812
+ )
813
+ if success == FFI::WIN32_FALSE
814
+ raise Puppet::Util::windows::Error.new(_("Failed to update service %{change} configuration") % { change: change } )
815
+ end
816
+ end
817
+ end
818
+ private :set_optional_parameter
819
+
820
+ # @api private
821
+ # Controls the delayed auto-start setting of a service
822
+ #
823
+ # @param [String] service_name name of service
824
+ # @param [Bool] delayed whether the service should be started with a delay or not
825
+ def set_startup_mode_delayed(service_name, delayed)
826
+ delayed_start = SERVICE_DELAYED_AUTO_START_INFO.new
827
+ delayed_start[:fDelayedAutostart] = delayed
828
+ set_optional_parameter(service_name, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, delayed_start)
829
+ end
830
+ private :set_startup_mode_delayed
831
+
708
832
  # @api private
709
833
  # Sends a service control signal to a service
710
834
  #
@@ -899,6 +1023,18 @@ module Puppet::Util::Windows
899
1023
  attach_function_private :QueryServiceConfigW,
900
1024
  [:handle, :lpbyte, :dword, :lpdword], :win32_bool
901
1025
 
1026
+ # https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-queryserviceconfig2w
1027
+ # BOOL QueryServiceConfig2W(
1028
+ # SC_HANDLE hService,
1029
+ # DWORD dwInfoLevel,
1030
+ # LPBYTE lpBuffer,
1031
+ # DWORD cbBufSize,
1032
+ # LPDWORD pcbBytesNeeded
1033
+ # );
1034
+ ffi_lib :advapi32
1035
+ attach_function_private :QueryServiceConfig2W,
1036
+ [:handle, :dword, :lpbyte, :dword, :lpdword], :win32_bool
1037
+
902
1038
  # https://docs.microsoft.com/en-us/windows/desktop/api/Winsvc/nf-winsvc-startservicew
903
1039
  # BOOL StartServiceW(
904
1040
  # SC_HANDLE hService,
@@ -949,6 +1085,15 @@ module Puppet::Util::Windows
949
1085
  :lpcwstr
950
1086
  ], :win32_bool
951
1087
 
1088
+ # https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-changeserviceconfig2w
1089
+ # BOOL ChangeServiceConfig2W(
1090
+ # SC_HANDLE hService,
1091
+ # DWORD dwInfoLevel,
1092
+ # LPVOID lpInfo
1093
+ # );
1094
+ ffi_lib :advapi32
1095
+ attach_function_private :ChangeServiceConfig2W,
1096
+ [:handle, :dword, :lpvoid], :win32_bool
952
1097
 
953
1098
  # https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-enumservicesstatusexw
954
1099
  # BOOL EnumServicesStatusExW(