chef 14.8.12 → 14.9.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/chef.gemspec +1 -1
  4. data/lib/chef/api_client.rb +1 -1
  5. data/lib/chef/api_client/registration.rb +1 -1
  6. data/lib/chef/api_client_v1.rb +4 -4
  7. data/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +2 -2
  9. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +1 -1
  10. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +1 -1
  11. data/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +2 -2
  13. data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +3 -3
  17. data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +2 -2
  18. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +3 -3
  19. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +4 -4
  20. data/lib/chef/client.rb +2 -2
  21. data/lib/chef/config_fetcher.rb +1 -1
  22. data/lib/chef/cookbook_uploader.rb +3 -3
  23. data/lib/chef/cookbook_version.rb +1 -1
  24. data/lib/chef/data_bag.rb +1 -1
  25. data/lib/chef/data_bag_item.rb +1 -1
  26. data/lib/chef/environment.rb +1 -1
  27. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  28. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
  29. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +1 -1
  30. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +1 -1
  31. data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +1 -1
  32. data/lib/chef/http.rb +3 -3
  33. data/lib/chef/key.rb +1 -1
  34. data/lib/chef/knife.rb +1 -1
  35. data/lib/chef/knife/bootstrap/client_builder.rb +1 -1
  36. data/lib/chef/knife/cookbook_delete.rb +1 -1
  37. data/lib/chef/knife/cookbook_upload.rb +1 -1
  38. data/lib/chef/knife/data_bag_create.rb +1 -1
  39. data/lib/chef/knife/raw.rb +1 -1
  40. data/lib/chef/knife/search.rb +1 -1
  41. data/lib/chef/knife/supermarket_share.rb +1 -1
  42. data/lib/chef/knife/supermarket_unshare.rb +1 -1
  43. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  44. data/lib/chef/monkey_patches/net_http.rb +5 -1
  45. data/lib/chef/node.rb +4 -4
  46. data/lib/chef/node/mixin/immutablize_array.rb +5 -0
  47. data/lib/chef/node/mixin/immutablize_hash.rb +3 -0
  48. data/lib/chef/org.rb +1 -1
  49. data/lib/chef/policy_builder/policyfile.rb +1 -1
  50. data/lib/chef/provider/apt_repository.rb +1 -1
  51. data/lib/chef/provider/group/windows.rb +1 -0
  52. data/lib/chef/provider/remote_file/content.rb +1 -1
  53. data/lib/chef/provider/windows_task.rb +2 -2
  54. data/lib/chef/resource/group.rb +4 -0
  55. data/lib/chef/resource/homebrew_cask.rb +8 -8
  56. data/lib/chef/resource/homebrew_tap.rb +6 -6
  57. data/lib/chef/resource/openssl_ec_private_key.rb +1 -1
  58. data/lib/chef/resource/openssl_x509_request.rb +1 -1
  59. data/lib/chef/resource/powershell_package_source.rb +11 -7
  60. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  61. data/lib/chef/resource/sysctl.rb +6 -6
  62. data/lib/chef/resource/timezone.rb +17 -1
  63. data/lib/chef/resource/windows_ad_join.rb +11 -1
  64. data/lib/chef/resource/windows_certificate.rb +7 -4
  65. data/lib/chef/resource/windows_printer.rb +3 -3
  66. data/lib/chef/resource/windows_task.rb +17 -8
  67. data/lib/chef/role.rb +1 -1
  68. data/lib/chef/run_list/run_list_expansion.rb +1 -1
  69. data/lib/chef/user.rb +1 -1
  70. data/lib/chef/user_v1.rb +4 -4
  71. data/lib/chef/util/windows/net_group.rb +6 -0
  72. data/lib/chef/version.rb +1 -1
  73. data/lib/chef/win32/api/net.rb +16 -0
  74. data/lib/chef/win32/net.rb +15 -0
  75. data/lib/chef/win32/version.rb +15 -15
  76. data/spec/functional/http/simple_spec.rb +10 -10
  77. data/spec/functional/resource/timezone_spec.rb +39 -0
  78. data/spec/functional/resource/windows_task_spec.rb +51 -7
  79. data/spec/integration/knife/client_create_spec.rb +1 -1
  80. data/spec/integration/knife/client_key_create_spec.rb +1 -1
  81. data/spec/integration/knife/cookbook_download_spec.rb +1 -1
  82. data/spec/integration/knife/cookbook_show_spec.rb +2 -2
  83. data/spec/integration/knife/data_bag_create_spec.rb +1 -1
  84. data/spec/integration/knife/environment_create_spec.rb +1 -1
  85. data/spec/integration/knife/node_create_spec.rb +1 -1
  86. data/spec/integration/knife/role_create_spec.rb +1 -1
  87. data/spec/support/shared/context/client.rb +1 -1
  88. data/spec/support/shared/unit/api_error_inspector.rb +5 -5
  89. data/spec/support/shared/unit/api_versioning.rb +2 -2
  90. data/spec/unit/api_client/registration_spec.rb +1 -1
  91. data/spec/unit/api_client_spec.rb +2 -2
  92. data/spec/unit/api_client_v1_spec.rb +3 -3
  93. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +1 -1
  94. data/spec/unit/client_spec.rb +2 -2
  95. data/spec/unit/data_bag_item_spec.rb +1 -1
  96. data/spec/unit/data_bag_spec.rb +1 -1
  97. data/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +4 -4
  98. data/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +2 -2
  99. data/spec/unit/knife/bootstrap/client_builder_spec.rb +1 -1
  100. data/spec/unit/knife/cookbook_delete_spec.rb +3 -3
  101. data/spec/unit/knife/data_bag_create_spec.rb +2 -2
  102. data/spec/unit/knife/supermarket_share_spec.rb +1 -1
  103. data/spec/unit/knife/supermarket_unshare_spec.rb +3 -3
  104. data/spec/unit/knife_spec.rb +7 -7
  105. data/spec/unit/mixin/api_version_request_handling_spec.rb +2 -2
  106. data/spec/unit/node_spec.rb +2 -2
  107. data/spec/unit/policy_builder/policyfile_spec.rb +2 -2
  108. data/spec/unit/provider/group/windows_spec.rb +15 -0
  109. data/spec/unit/provider/remote_file/content_spec.rb +2 -2
  110. data/spec/unit/resource/group_spec.rb +17 -0
  111. data/spec/unit/resource/powershell_package_source_spec.rb +2 -2
  112. data/spec/unit/resource/windows_certificate.rb +7 -0
  113. data/spec/unit/resource/windows_task_spec.rb +61 -20
  114. data/spec/unit/resource_reporter_spec.rb +7 -7
  115. data/spec/unit/user_v1_spec.rb +2 -2
  116. metadata +13 -6
@@ -104,7 +104,7 @@ class Chef
104
104
  keys = r.variables[:entries].reject(&:empty?)
105
105
 
106
106
  if key_exists?(keys, key, comment)
107
- Chef::Log.debug "Known hosts key for #{new_resource.name} already exists - skipping"
107
+ Chef::Log.debug "Known hosts key for #{new_resource.host} already exists - skipping"
108
108
  else
109
109
  r.variables[:entries].push(key)
110
110
  end
@@ -80,7 +80,7 @@ class Chef
80
80
 
81
81
  directory new_resource.conf_dir
82
82
 
83
- file "#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
83
+ file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do
84
84
  content "#{new_resource.key} = #{new_resource.value}"
85
85
  end
86
86
 
@@ -96,9 +96,9 @@ class Chef
96
96
  description "Remove a sysctl value."
97
97
 
98
98
  # only converge the resource if the file actually exists to delete
99
- if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf")
100
- converge_by "removing sysctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
101
- file "#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
99
+ if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf")
100
+ converge_by "removing sysctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do
101
+ file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do
102
102
  action :delete
103
103
  end
104
104
 
@@ -140,8 +140,8 @@ class Chef
140
140
  # return the value. Raise in case this conf file needs to be created
141
141
  # or updated
142
142
  def get_sysctld_value(key)
143
- raise unless ::File.exist?("/etc/sysctl.d/99-chef-#{key}.conf")
144
- k, v = ::File.read("/etc/sysctl.d/99-chef-#{key}.conf").match(/(.*) = (.*)/).captures
143
+ raise unless ::File.exist?("/etc/sysctl.d/99-chef-#{key.tr('/', '.')}.conf")
144
+ k, v = ::File.read("/etc/sysctl.d/99-chef-#{key.tr('/', '.')}.conf").match(/(.*) = (.*)/).captures
145
145
  raise "Unknown sysctl key!" if k.nil?
146
146
  raise "Unknown sysctl value!" if v.nil?
147
147
  v
@@ -25,7 +25,7 @@ class Chef
25
25
  preview_resource true
26
26
  resource_name :timezone
27
27
 
28
- description "Use the timezone resource to change the system timezone on Linux and macOS hosts. Timezones are specified in tz database format, with a complete list of available TZ values here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones."
28
+ description "Use the timezone resource to change the system timezone on Windows, Linux, and macOS hosts. Timezones are specified in tz database format, with a complete list of available TZ values for Linux and macOS here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones and for Windows here: https://ss64.com/nt/timezones.html."
29
29
  introduced "14.6"
30
30
 
31
31
  property :timezone, String,
@@ -96,6 +96,12 @@ class Chef
96
96
  shell_out!("sudo systemsetup -settimezone #{new_resource.timezone}")
97
97
  end
98
98
  end
99
+ when "windows"
100
+ unless current_windows_tz.casecmp?(new_resource.timezone)
101
+ converge_by("setting timezone to \"#{new_resource.timezone}\"") do
102
+ shell_out!("tzutil /s \"#{new_resource.timezone}\"")
103
+ end
104
+ end
99
105
  end
100
106
  end
101
107
  end
@@ -113,6 +119,16 @@ class Chef
113
119
  /Time Zone: (.*)/.match(tz_shellout.stdout)[1]
114
120
  end
115
121
  end
122
+
123
+ # detect the current timezone on windows hosts
124
+ #
125
+ # @since 14.9
126
+ # @return [String] timezone id
127
+ def current_windows_tz
128
+ tz_shellout = shell_out("tzutil /g")
129
+ raise "There was an error running the tzutil command" if tz_shellout.exitstatus == 1
130
+ tz_shellout.stdout.strip
131
+ end
116
132
  end
117
133
  end
118
134
  end
@@ -73,7 +73,13 @@ class Chef
73
73
 
74
74
  converge_by("join Active Directory domain #{new_resource.domain_name}") do
75
75
  ps_run = powershell_out(cmd)
76
- raise "Failed to join the domain #{new_resource.domain_name}: #{ps_run.stderr}}" if ps_run.error?
76
+ if ps_run.error?
77
+ if sensitive?
78
+ raise "Failed to join the domain #{new_resource.domain_name}: *suppressed sensitive resource output*"
79
+ else
80
+ raise "Failed to join the domain #{new_resource.domain_name}: #{ps_run.stderr}"
81
+ end
82
+ end
77
83
 
78
84
  unless new_resource.reboot == :never
79
85
  reboot "Reboot to join domain #{new_resource.domain_name}" do
@@ -104,6 +110,10 @@ class Chef
104
110
  reboot_action
105
111
  end
106
112
  end
113
+
114
+ def sensitive?
115
+ !!new_resource.sensitive
116
+ end
107
117
  end
108
118
  end
109
119
  end
@@ -59,7 +59,6 @@ class Chef
59
59
 
60
60
  action :create do
61
61
  description "Creates or updates a certificate."
62
-
63
62
  add_cert(OpenSSL::X509::Certificate.new(raw_source))
64
63
  end
65
64
 
@@ -91,8 +90,12 @@ class Chef
91
90
 
92
91
  action :delete do
93
92
  description "Deletes a certificate."
94
-
95
- delete_cert
93
+ cert_obj = fetch_cert
94
+ if cert_obj
95
+ converge_by("Deleting certificate #{new_resource.source} from Store #{new_resource.store_name}") do
96
+ delete_cert
97
+ end
98
+ end
96
99
  end
97
100
 
98
101
  action :fetch do
@@ -250,7 +253,7 @@ class Chef
250
253
  when ".cer"
251
254
  powershell_out("openssl x509 -text -inform DER -in #{source} -outform PEM").stdout
252
255
  when ".pfx"
253
- powershell_out("openssl pkcs12 -in #{source} -nodes -passin pass:#{new_resource.pfx_password}").stdout
256
+ powershell_out("openssl pkcs12 -in #{source} -nodes -passin pass:'#{new_resource.pfx_password}'").stdout
254
257
  when ".p7b"
255
258
  powershell_out("openssl pkcs7 -print_certs -in #{source} -outform PEM").stdout
256
259
  end
@@ -114,7 +114,7 @@ class Chef
114
114
 
115
115
  port_name = "IP_#{new_resource.ipv4_address}"
116
116
 
117
- declare_resource(:powershell_script, "Creating printer: #{new_resource.name}") do
117
+ declare_resource(:powershell_script, "Creating printer: #{new_resource.device_id}") do
118
118
  code <<-EOH
119
119
 
120
120
  Set-WmiInstance -class Win32_Printer `
@@ -133,9 +133,9 @@ class Chef
133
133
  end
134
134
 
135
135
  def delete_printer
136
- declare_resource(:powershell_script, "Deleting printer: #{new_resource.name}") do
136
+ declare_resource(:powershell_script, "Deleting printer: #{new_resource.device_id}") do
137
137
  code <<-EOH
138
- $printer = Get-WMIObject -class Win32_Printer -EnableAllPrivileges -Filter "name = '#{new_resource.name}'"
138
+ $printer = Get-WMIObject -class Win32_Printer -EnableAllPrivileges -Filter "name = '#{new_resource.device_id}'"
139
139
  $printer.Delete()
140
140
  EOH
141
141
  end
@@ -143,7 +143,6 @@ class Chef
143
143
  validate_start_time(start_time, frequency)
144
144
  validate_start_day(start_day, frequency) if start_day
145
145
  validate_user_and_password(user, password)
146
- validate_interactive_setting(interactive_enabled, password)
147
146
  validate_create_frequency_modifier(frequency, frequency_modifier) if frequency_modifier
148
147
  validate_create_day(day, frequency, frequency_modifier) if day
149
148
  validate_create_months(months, frequency) if months
@@ -226,20 +225,30 @@ class Chef
226
225
  end
227
226
  end
228
227
 
228
+ # System users will not require a password
229
+ # Other users will require a password if the task is non-interactive.
230
+ #
231
+ # @param [String] user
232
+ # @param [String] password
233
+ #
229
234
  def validate_user_and_password(user, password)
230
- if password_required?(user) && password.nil?
231
- raise ArgumentError, "Cannot specify a user other than the system users without specifying a password!. Valid passwordless users: '#{Chef::ReservedNames::Win32::Security::SID::SYSTEM_USER.join("', '")}'"
235
+ if non_system_user?(user)
236
+ if password.nil? && !interactive_enabled
237
+ raise ArgumentError, "Please provide a password or check if this task needs to be interactive! Valid passwordless users are: '#{Chef::ReservedNames::Win32::Security::SID::SYSTEM_USER.join("', '")}'"
238
+ end
239
+ else
240
+ unless password.nil?
241
+ raise ArgumentError, "Password is not required for system users."
242
+ end
232
243
  end
233
244
  end
234
245
 
246
+ # Password is not required for system user and required for non-system user.
235
247
  def password_required?(user)
236
- return false if user.nil?
237
- @password_required ||= !Chef::ReservedNames::Win32::Security::SID.system_user?(user)
248
+ @password_required ||= (!user.nil? && !Chef::ReservedNames::Win32::Security::SID.system_user?(user))
238
249
  end
239
250
 
240
- def validate_interactive_setting(interactive_enabled, password)
241
- raise ArgumentError, "Please provide the password when attempting to set interactive/non-interactive." if interactive_enabled && password.nil?
242
- end
251
+ alias non_system_user? password_required?
243
252
 
244
253
  def validate_create_frequency_modifier(frequency, frequency_modifier)
245
254
  if ([:on_logon, :onstart, :on_idle, :none].include?(frequency)) && ( frequency_modifier != 1)
data/lib/chef/role.rb CHANGED
@@ -224,7 +224,7 @@ class Chef
224
224
  def save
225
225
  begin
226
226
  chef_server_rest.put("roles/#{@name}", self)
227
- rescue Net::HTTPServerException => e
227
+ rescue Net::HTTPClientException => e
228
228
  raise e unless e.response.code == "404"
229
229
  chef_server_rest.post("roles", self)
230
230
  end
@@ -219,7 +219,7 @@ class Chef
219
219
 
220
220
  def fetch_role(name, included_by)
221
221
  Chef::Role.from_hash(rest.get("roles/#{name}"))
222
- rescue Net::HTTPServerException => e
222
+ rescue Net::HTTPClientException => e
223
223
  if e.message == '404 "Not Found"'
224
224
  role_not_found(name, included_by)
225
225
  else
data/lib/chef/user.rb CHANGED
@@ -115,7 +115,7 @@ class Chef
115
115
 
116
116
  def save(new_key = false)
117
117
  create
118
- rescue Net::HTTPServerException => e
118
+ rescue Net::HTTPClientException => e
119
119
  if e.response.code == "409"
120
120
  update(new_key)
121
121
  else
data/lib/chef/user_v1.rb CHANGED
@@ -164,7 +164,7 @@ class Chef
164
164
  new_user["public_key"] = new_user["chef_key"]["public_key"]
165
165
  new_user.delete("chef_key")
166
166
  end
167
- rescue Net::HTTPServerException => e
167
+ rescue Net::HTTPClientException => e
168
168
  # rescue API V0 if 406 and the server supports V0
169
169
  supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
170
170
  raise e unless supported_versions && supported_versions.include?(0)
@@ -200,7 +200,7 @@ class Chef
200
200
  payload[:private_key] = new_key if new_key
201
201
 
202
202
  updated_user = chef_root_rest_v1.put("users/#{username}", payload)
203
- rescue Net::HTTPServerException => e
203
+ rescue Net::HTTPClientException => e
204
204
  if e.response.code == "400"
205
205
  # if a 400 is returned but the error message matches the error related to private / public key fields, try V0
206
206
  # else, raise the 400
@@ -220,7 +220,7 @@ class Chef
220
220
 
221
221
  def save(new_key = false)
222
222
  create
223
- rescue Net::HTTPServerException => e
223
+ rescue Net::HTTPClientException => e
224
224
  if e.response.code == "409"
225
225
  update(new_key)
226
226
  else
@@ -235,7 +235,7 @@ class Chef
235
235
  reregistered_self = chef_root_rest_v0.put("users/#{username}", payload)
236
236
  private_key(reregistered_self["private_key"])
237
237
  # only V0 supported for reregister
238
- rescue Net::HTTPServerException => e
238
+ rescue Net::HTTPClientException => e
239
239
  # if there was a 406 related to versioning, give error explaining that
240
240
  # only API version 0 is supported for reregister command
241
241
  if e.response.code == "406" && e.response["x-ops-server-api-version"]
@@ -58,6 +58,12 @@ class Chef::Util::Windows::NetGroup
58
58
  raise ArgumentError, e
59
59
  end
60
60
 
61
+ def local_group_set_info(comment)
62
+ Chef::ReservedNames::Win32::NetUser.net_local_group_set_info(nil, groupname, comment)
63
+ rescue Chef::Exceptions::Win32APIError => e
64
+ raise ArgumentError, e
65
+ end
66
+
61
67
  def local_delete_members(members)
62
68
  Chef::ReservedNames::Win32::NetUser.net_local_group_del_members(nil, groupname, members)
63
69
  rescue Chef::Exceptions::Win32APIError => e
data/lib/chef/version.rb CHANGED
@@ -23,7 +23,7 @@ require "chef/version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("../..", __FILE__)
26
- VERSION = Chef::VersionString.new("14.8.12")
26
+ VERSION = Chef::VersionString.new("14.9.13")
27
27
  end
28
28
 
29
29
  #
@@ -144,6 +144,11 @@ class Chef
144
144
  layout :lgrpi0_name, :LPWSTR
145
145
  end
146
146
 
147
+ class LOCALGROUP_INFO_1 < FFI::Struct
148
+ layout :lgrpi1_name, :LPWSTR,
149
+ :lgrpi1_comment, :LPWSTR
150
+ end
151
+
147
152
  class USE_INFO_2 < FFI::Struct
148
153
  include StructHelpers
149
154
 
@@ -168,6 +173,17 @@ class Chef
168
173
  :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD
169
174
  ], :DWORD
170
175
 
176
+ # NET_API_STATUS NetLocalGroupSetInfo(
177
+ # _In_ LPCWSTR servername,
178
+ # _In_ LPCWSTR groupname,
179
+ # _In_ DWORD level,
180
+ # _In_ LPBYTE buf,
181
+ # _Out_ LPDWORD parm_err
182
+ # );
183
+ safe_attach_function :NetLocalGroupSetInfo, [
184
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD
185
+ ], :DWORD
186
+
171
187
  # NET_API_STATUS NetLocalGroupDel(
172
188
  # _In_ LPCWSTR servername,
173
189
  # _In_ LPCWSTR groupname
@@ -180,6 +180,21 @@ class Chef
180
180
  end
181
181
  end
182
182
 
183
+ def self.net_local_group_set_info(server_name, group_name, comment)
184
+ server_name = wstring(server_name)
185
+ group_name = wstring(group_name)
186
+ comment = wstring(comment)
187
+
188
+ buf = LOCALGROUP_INFO_1.new
189
+ buf[:lgrpi1_name] = FFI::MemoryPointer.from_string(group_name)
190
+ buf[:lgrpi1_comment] = FFI::MemoryPointer.from_string(comment)
191
+
192
+ rc = NetLocalGroupSetInfo(server_name, group_name, 1, buf, nil)
193
+ if rc != NERR_Success
194
+ Chef::ReservedNames::Win32::Error.raise!(nil, rc)
195
+ end
196
+ end
197
+
183
198
  def self.net_user_del(server_name, user_name)
184
199
  server_name = wstring(server_name)
185
200
  user_name = wstring(user_name)
@@ -44,25 +44,25 @@ class Chef
44
44
 
45
45
  def self.method_name_from_marketing_name(marketing_name)
46
46
  "#{marketing_name.gsub(/\s/, '_').tr('.', '_').downcase}?"
47
- # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?"
48
47
  end
49
48
 
50
49
  private_class_method :method_name_from_marketing_name
51
50
 
52
51
  WIN_VERSIONS = {
53
- "Windows 10" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } },
54
- "Windows Server 2016" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } },
55
- "Windows 8.1" => { major: 6, minor: 3, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } },
56
- "Windows Server 2012 R2" => { major: 6, minor: 3, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } },
57
- "Windows 8" => { major: 6, minor: 2, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } },
58
- "Windows Server 2012" => { major: 6, minor: 2, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } },
59
- "Windows 7" => { major: 6, minor: 1, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } },
60
- "Windows Server 2008 R2" => { major: 6, minor: 1, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } },
61
- "Windows Server 2008" => { major: 6, minor: 0, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } },
62
- "Windows Vista" => { major: 6, minor: 0, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } },
63
- "Windows Server 2003 R2" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) != 0 } },
64
- "Windows Home Server" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| (suite_mask & VER_SUITE_WH_SERVER) == VER_SUITE_WH_SERVER } },
65
- "Windows Server 2003" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) == 0 } },
52
+ "Windows Server 2019" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask, build_number| product_type != VER_NT_WORKSTATION && build_number >= 17763 } },
53
+ "Windows 10" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask, build_number| product_type == VER_NT_WORKSTATION } },
54
+ "Windows Server 2016" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask, build_number| product_type != VER_NT_WORKSTATION && build_number <= 14393 } },
55
+ "Windows 8.1" => { major: 6, minor: 3, callable: lambda { |product_type, suite_mask, build_number| product_type == VER_NT_WORKSTATION } },
56
+ "Windows Server 2012 R2" => { major: 6, minor: 3, callable: lambda { |product_type, suite_mask, build_number| product_type != VER_NT_WORKSTATION } },
57
+ "Windows 8" => { major: 6, minor: 2, callable: lambda { |product_type, suite_mask, build_number| product_type == VER_NT_WORKSTATION } },
58
+ "Windows Server 2012" => { major: 6, minor: 2, callable: lambda { |product_type, suite_mask, build_number| product_type != VER_NT_WORKSTATION } },
59
+ "Windows 7" => { major: 6, minor: 1, callable: lambda { |product_type, suite_mask, build_number| product_type == VER_NT_WORKSTATION } },
60
+ "Windows Server 2008 R2" => { major: 6, minor: 1, callable: lambda { |product_type, suite_mask, build_number| product_type != VER_NT_WORKSTATION } },
61
+ "Windows Server 2008" => { major: 6, minor: 0, callable: lambda { |product_type, suite_mask, build_number| product_type != VER_NT_WORKSTATION } },
62
+ "Windows Vista" => { major: 6, minor: 0, callable: lambda { |product_type, suite_mask, build_number| product_type == VER_NT_WORKSTATION } },
63
+ "Windows Server 2003 R2" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask, build_number| get_system_metrics(SM_SERVERR2) != 0 } },
64
+ "Windows Home Server" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask, build_number| (suite_mask & VER_SUITE_WH_SERVER) == VER_SUITE_WH_SERVER } },
65
+ "Windows Server 2003" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask, build_number| get_system_metrics(SM_SERVERR2) == 0 } },
66
66
  "Windows XP" => { major: 5, minor: 1 },
67
67
  "Windows 2000" => { major: 5, minor: 0 },
68
68
  }.freeze
@@ -88,7 +88,7 @@ class Chef
88
88
  define_method(method_name) do
89
89
  (@major_version == v[:major]) &&
90
90
  (@minor_version == v[:minor]) &&
91
- (v[:callable] ? v[:callable].call(@product_type, @suite_mask) : true)
91
+ (v[:callable] ? v[:callable].call(@product_type, @suite_mask, @build_number) : true)
92
92
  end
93
93
  marketing_names << [k, method_name]
94
94
  end
@@ -61,27 +61,27 @@ describe Chef::HTTP::Simple do
61
61
  end
62
62
 
63
63
  shared_examples_for "an endpoint that 403s" do
64
- it "fails with a Net::HTTPServerException for a streaming request" do
65
- expect { http_client.streaming_request(source) }.to raise_error(Net::HTTPServerException)
64
+ it "fails with a Net::HTTPClientException for a streaming request" do
65
+ expect { http_client.streaming_request(source) }.to raise_error(Net::HTTPClientException)
66
66
  end
67
67
 
68
- it "fails with a Net::HTTPServerException for a GET request" do
69
- expect { http_client.get(source) }.to raise_error(Net::HTTPServerException)
68
+ it "fails with a Net::HTTPClientException for a GET request" do
69
+ expect { http_client.get(source) }.to raise_error(Net::HTTPClientException)
70
70
  end
71
71
  end
72
72
 
73
73
  # see CHEF-5100
74
74
  shared_examples_for "a 403 after a successful request when reusing the request object" do
75
- it "fails with a Net::HTTPServerException for a streaming request" do
75
+ it "fails with a Net::HTTPClientException for a streaming request" do
76
76
  tempfile = http_client.streaming_request(source)
77
77
  tempfile.close
78
78
  expect(Digest::MD5.hexdigest(binread(tempfile.path))).to eq(Digest::MD5.hexdigest(expected_content))
79
- expect { http_client.streaming_request(source2) }.to raise_error(Net::HTTPServerException)
79
+ expect { http_client.streaming_request(source2) }.to raise_error(Net::HTTPClientException)
80
80
  end
81
81
 
82
- it "fails with a Net::HTTPServerException for a GET request" do
82
+ it "fails with a Net::HTTPClientException for a GET request" do
83
83
  expect(Digest::MD5.hexdigest(http_client.get(source))).to eq(Digest::MD5.hexdigest(expected_content))
84
- expect { http_client.get(source2) }.to raise_error(Net::HTTPServerException)
84
+ expect { http_client.get(source2) }.to raise_error(Net::HTTPClientException)
85
85
  end
86
86
  end
87
87
 
@@ -120,7 +120,7 @@ describe Chef::HTTP::Simple do
120
120
  it "Logs the request and response and bodies for 400 response" do
121
121
  expect do
122
122
  http_client.get("http://localhost:9000/bad_request")
123
- end.to raise_error(Net::HTTPServerException)
123
+ end.to raise_error(Net::HTTPClientException)
124
124
  expect(@debug_log).to match(/400/)
125
125
  expect(@debug_log).to match(/HTTP Request Header Data/)
126
126
  expect(@debug_log).to match(/HTTP Status and Header Data/)
@@ -133,7 +133,7 @@ describe Chef::HTTP::Simple do
133
133
  it "Logs the request and response and bodies for 400 POST response" do
134
134
  expect do
135
135
  http_client.post("http://localhost:9000/bad_request", "hithere")
136
- end.to raise_error(Net::HTTPServerException)
136
+ end.to raise_error(Net::HTTPClientException)
137
137
  expect(@debug_log).to match(/400/)
138
138
  expect(@debug_log).to match(/HTTP Request Header Data/)
139
139
  expect(@debug_log).to match(/HTTP Status and Header Data/)