chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +4 -110
  6. data/bin/chef-service-manager +3 -1
  7. data/distro/common/html/knife_cookbook_site.html +18 -18
  8. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  9. data/lib/chef.rb +1 -1
  10. data/lib/chef/application.rb +1 -1
  11. data/lib/chef/application/apply.rb +19 -1
  12. data/lib/chef/application/client.rb +11 -5
  13. data/lib/chef/application/knife.rb +2 -2
  14. data/lib/chef/application/solo.rb +1 -1
  15. data/lib/chef/application/windows_service_manager.rb +19 -12
  16. data/lib/chef/chef_class.rb +46 -0
  17. data/lib/chef/chef_fs/config.rb +22 -24
  18. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  19. data/lib/chef/chef_fs/file_pattern.rb +4 -15
  20. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  21. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  22. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  23. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  27. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  28. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  29. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  30. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
  31. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  32. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  33. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  34. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  35. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  36. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  37. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  38. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  39. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  40. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  41. data/lib/chef/chef_fs/knife.rb +35 -7
  42. data/lib/chef/chef_fs/path_utils.rb +65 -34
  43. data/lib/chef/client.rb +2 -3
  44. data/lib/chef/config.rb +34 -2
  45. data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
  46. data/lib/chef/cookbook/metadata.rb +25 -3
  47. data/lib/chef/cookbook/synchronizer.rb +1 -1
  48. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  49. data/lib/chef/cookbook_version.rb +3 -3
  50. data/lib/chef/delayed_evaluator.rb +21 -0
  51. data/lib/chef/deprecation/mixin/template.rb +1 -2
  52. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  53. data/lib/chef/deprecation/provider/file.rb +1 -1
  54. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  55. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  56. data/lib/chef/deprecation/provider/template.rb +1 -1
  57. data/lib/chef/deprecation/warnings.rb +3 -4
  58. data/lib/chef/dsl/reboot_pending.rb +3 -2
  59. data/lib/chef/dsl/recipe.rb +26 -7
  60. data/lib/chef/dsl/resources.rb +2 -2
  61. data/lib/chef/event_dispatch/base.rb +51 -22
  62. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  63. data/lib/chef/event_dispatch/dsl.rb +64 -0
  64. data/lib/chef/exceptions.rb +28 -1
  65. data/lib/chef/file_content_management/tempfile.rb +1 -1
  66. data/lib/chef/formatters/base.rb +3 -0
  67. data/lib/chef/formatters/doc.rb +56 -6
  68. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  69. data/lib/chef/formatters/minimal.rb +2 -2
  70. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
  71. data/lib/chef/http/http_request.rb +1 -1
  72. data/lib/chef/knife.rb +35 -55
  73. data/lib/chef/knife/bootstrap.rb +41 -0
  74. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  75. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  76. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  77. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  78. data/lib/chef/knife/cookbook_create.rb +1 -1
  79. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  80. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  81. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  82. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  83. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  84. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  85. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  86. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  87. data/lib/chef/knife/core/node_presenter.rb +24 -1
  88. data/lib/chef/knife/core/object_loader.rb +1 -0
  89. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  90. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  91. data/lib/chef/knife/null.rb +10 -0
  92. data/lib/chef/knife/rehash.rb +62 -0
  93. data/lib/chef/knife/search.rb +3 -3
  94. data/lib/chef/knife/ssh.rb +52 -30
  95. data/lib/chef/knife/ssl_check.rb +3 -2
  96. data/lib/chef/knife/user_edit.rb +1 -2
  97. data/lib/chef/local_mode.rb +5 -0
  98. data/lib/chef/log.rb +5 -1
  99. data/lib/chef/mixin/deprecation.rb +8 -8
  100. data/lib/chef/mixin/params_validate.rb +362 -135
  101. data/lib/chef/mixin/template.rb +48 -0
  102. data/lib/chef/mixin/which.rb +1 -1
  103. data/lib/chef/mixin/wide_string.rb +72 -0
  104. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  105. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  106. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  107. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  108. data/lib/chef/node.rb +116 -3
  109. data/lib/chef/node_map.rb +2 -2
  110. data/lib/chef/platform/handler_map.rb +0 -5
  111. data/lib/chef/platform/provider_mapping.rb +5 -6
  112. data/lib/chef/platform/query_helpers.rb +46 -4
  113. data/lib/chef/platform/rebooter.rb +1 -1
  114. data/lib/chef/platform/service_helpers.rb +30 -32
  115. data/lib/chef/policy_builder.rb +1 -8
  116. data/lib/chef/policy_builder/dynamic.rb +186 -0
  117. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  118. data/lib/chef/policy_builder/policyfile.rb +155 -18
  119. data/lib/chef/property.rb +568 -0
  120. data/lib/chef/provider.rb +222 -13
  121. data/lib/chef/provider/batch.rb +8 -0
  122. data/lib/chef/provider/deploy.rb +5 -7
  123. data/lib/chef/provider/directory.rb +14 -2
  124. data/lib/chef/provider/dsc_resource.rb +5 -9
  125. data/lib/chef/provider/group/pw.rb +1 -1
  126. data/lib/chef/provider/ifconfig.rb +2 -2
  127. data/lib/chef/provider/lwrp_base.rb +1 -75
  128. data/lib/chef/provider/mount.rb +7 -3
  129. data/lib/chef/provider/package.rb +1 -1
  130. data/lib/chef/provider/package/dpkg.rb +5 -11
  131. data/lib/chef/provider/package/rpm.rb +2 -2
  132. data/lib/chef/provider/package/rubygems.rb +1 -1
  133. data/lib/chef/provider/package/windows/msi.rb +2 -2
  134. data/lib/chef/provider/package/yum.rb +17 -5
  135. data/lib/chef/provider/powershell_script.rb +59 -23
  136. data/lib/chef/provider/registry_key.rb +5 -5
  137. data/lib/chef/provider/remote_directory.rb +190 -102
  138. data/lib/chef/provider/service.rb +12 -2
  139. data/lib/chef/provider/service/aix.rb +1 -1
  140. data/lib/chef/provider/service/debian.rb +3 -5
  141. data/lib/chef/provider/service/freebsd.rb +1 -1
  142. data/lib/chef/provider/service/gentoo.rb +3 -3
  143. data/lib/chef/provider/service/init.rb +3 -3
  144. data/lib/chef/provider/service/insserv.rb +2 -4
  145. data/lib/chef/provider/service/invokercd.rb +2 -4
  146. data/lib/chef/provider/service/macosx.rb +5 -1
  147. data/lib/chef/provider/service/openbsd.rb +2 -1
  148. data/lib/chef/provider/service/redhat.rb +52 -16
  149. data/lib/chef/provider/service/simple.rb +2 -2
  150. data/lib/chef/provider/service/systemd.rb +3 -5
  151. data/lib/chef/provider/service/upstart.rb +4 -6
  152. data/lib/chef/provider/subversion.rb +13 -7
  153. data/lib/chef/provider/template/content.rb +16 -6
  154. data/lib/chef/provider/user/solaris.rb +32 -4
  155. data/lib/chef/provider/windows_script.rb +3 -5
  156. data/lib/chef/provider_resolver.rb +2 -2
  157. data/lib/chef/recipe.rb +1 -8
  158. data/lib/chef/resource.rb +563 -90
  159. data/lib/chef/resource/action_class.rb +83 -0
  160. data/lib/chef/resource/chef_gem.rb +3 -3
  161. data/lib/chef/resource/deploy.rb +8 -2
  162. data/lib/chef/resource/dsc_script.rb +2 -0
  163. data/lib/chef/resource/file/verification.rb +7 -1
  164. data/lib/chef/resource/lwrp_base.rb +1 -7
  165. data/lib/chef/resource/registry_key.rb +1 -1
  166. data/lib/chef/resource/service.rb +10 -2
  167. data/lib/chef/resource/subversion.rb +5 -0
  168. data/lib/chef/resource/windows_script.rb +6 -2
  169. data/lib/chef/resource/yum_package.rb +10 -1
  170. data/lib/chef/resource_resolver.rb +3 -3
  171. data/lib/chef/run_context.rb +402 -83
  172. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  173. data/lib/chef/run_lock.rb +30 -21
  174. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  175. data/lib/chef/util/windows.rb +0 -32
  176. data/lib/chef/util/windows/net_group.rb +85 -106
  177. data/lib/chef/util/windows/net_use.rb +35 -71
  178. data/lib/chef/util/windows/net_user.rb +0 -1
  179. data/lib/chef/util/windows/volume.rb +19 -19
  180. data/lib/chef/version.rb +3 -3
  181. data/lib/chef/win32/api.rb +1 -0
  182. data/lib/chef/win32/api/file.rb +20 -0
  183. data/lib/chef/win32/api/net.rb +163 -43
  184. data/lib/chef/win32/api/registry.rb +51 -0
  185. data/lib/chef/win32/api/system.rb +23 -0
  186. data/lib/chef/win32/api/unicode.rb +0 -43
  187. data/lib/chef/win32/crypto.rb +2 -1
  188. data/lib/chef/win32/file.rb +28 -3
  189. data/lib/chef/win32/mutex.rb +1 -2
  190. data/lib/chef/win32/net.rb +162 -8
  191. data/lib/chef/win32/process.rb +13 -0
  192. data/lib/chef/win32/registry.rb +35 -30
  193. data/lib/chef/win32/security.rb +1 -1
  194. data/lib/chef/win32/security/token.rb +1 -1
  195. data/lib/chef/win32/system.rb +62 -0
  196. data/lib/chef/win32/unicode.rb +7 -2
  197. data/lib/chef/win32/version.rb +0 -4
  198. data/lib/chef/workstation_config_loader.rb +3 -158
  199. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  200. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  201. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  202. data/spec/data/dsc_lcm.pfx +0 -0
  203. data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
  204. data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
  205. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  206. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  207. data/spec/functional/knife/ssh_spec.rb +16 -0
  208. data/spec/functional/rebooter_spec.rb +1 -1
  209. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  210. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  211. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  212. data/spec/functional/resource/group_spec.rb +67 -44
  213. data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
  214. data/spec/functional/resource/windows_service_spec.rb +1 -1
  215. data/spec/functional/run_lock_spec.rb +368 -189
  216. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
  217. data/spec/functional/win32/service_manager_spec.rb +2 -2
  218. data/spec/integration/client/client_spec.rb +51 -0
  219. data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
  220. data/spec/integration/knife/download_spec.rb +4 -0
  221. data/spec/integration/knife/list_spec.rb +8 -0
  222. data/spec/integration/knife/upload_spec.rb +1 -1
  223. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
  224. data/spec/integration/recipes/remote_directory.rb +74 -0
  225. data/spec/integration/recipes/resource_action_spec.rb +363 -0
  226. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  227. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  228. data/spec/spec_helper.rb +9 -0
  229. data/spec/support/platform_helpers.rb +13 -0
  230. data/spec/support/shared/context/win32.rb +34 -0
  231. data/spec/support/shared/functional/win32_service.rb +2 -1
  232. data/spec/support/shared/functional/windows_script.rb +63 -26
  233. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  234. data/spec/support/shared/unit/provider/file.rb +10 -4
  235. data/spec/unit/application/client_spec.rb +16 -3
  236. data/spec/unit/application/knife_spec.rb +2 -2
  237. data/spec/unit/application/solo_spec.rb +4 -3
  238. data/spec/unit/chef_class_spec.rb +23 -4
  239. data/spec/unit/chef_fs/path_util_spec.rb +108 -0
  240. data/spec/unit/client_spec.rb +6 -1
  241. data/spec/unit/config_spec.rb +31 -0
  242. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  243. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  244. data/spec/unit/deprecation_spec.rb +3 -6
  245. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  246. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  247. data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
  248. data/spec/unit/formatters/doc_spec.rb +32 -0
  249. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  250. data/spec/unit/json_compat_spec.rb +4 -3
  251. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  252. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  253. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  254. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  255. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  256. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  257. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  258. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  259. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  260. data/spec/unit/knife/ssl_check_spec.rb +4 -0
  261. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  262. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  263. data/spec/unit/mixin/template_spec.rb +5 -1
  264. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  265. data/spec/unit/node_spec.rb +220 -0
  266. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  267. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  268. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  269. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  270. data/spec/unit/property/state_spec.rb +506 -0
  271. data/spec/unit/property/validation_spec.rb +663 -0
  272. data/spec/unit/property_spec.rb +1094 -0
  273. data/spec/unit/provider/deploy_spec.rb +5 -5
  274. data/spec/unit/provider/directory_spec.rb +35 -0
  275. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  276. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  277. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  278. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  279. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  280. data/spec/unit/provider/mount_spec.rb +12 -1
  281. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  282. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  283. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  284. data/spec/unit/provider/package/yum_spec.rb +97 -24
  285. data/spec/unit/provider/powershell_script_spec.rb +106 -0
  286. data/spec/unit/provider/registry_key_spec.rb +12 -0
  287. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  288. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  289. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  290. data/spec/unit/provider/service/macosx_spec.rb +4 -4
  291. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  292. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  293. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  294. data/spec/unit/provider/service/windows_spec.rb +211 -200
  295. data/spec/unit/provider/subversion_spec.rb +50 -31
  296. data/spec/unit/provider/template/content_spec.rb +93 -2
  297. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  298. data/spec/unit/provider_resolver_spec.rb +707 -650
  299. data/spec/unit/provider_spec.rb +1 -3
  300. data/spec/unit/recipe_spec.rb +0 -4
  301. data/spec/unit/resource/deploy_spec.rb +7 -1
  302. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  303. data/spec/unit/resource/file/verification_spec.rb +33 -5
  304. data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
  305. data/spec/unit/resource/service_spec.rb +4 -4
  306. data/spec/unit/resource/subversion_spec.rb +4 -0
  307. data/spec/unit/resource/yum_package_spec.rb +10 -1
  308. data/spec/unit/resource_spec.rb +2 -2
  309. data/spec/unit/run_context/child_run_context_spec.rb +133 -0
  310. data/spec/unit/run_context_spec.rb +7 -0
  311. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  312. data/spec/unit/win32/registry_spec.rb +394 -0
  313. data/tasks/external_tests.rb +47 -23
  314. data/tasks/maintainers.rb +155 -14
  315. metadata +64 -53
  316. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  317. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  318. data/spec/unit/provider/powershell_spec.rb +0 -80
  319. data/spec/unit/registry_helper_spec.rb +0 -376
  320. data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -186,6 +186,29 @@ int WINAPI GetSystemMetrics(
186
186
  =end
187
187
  safe_attach_function :GetSystemMetrics, [:int], :int
188
188
 
189
+ =begin
190
+ UINT WINAPI GetSystemWow64Directory(
191
+ _Out_ LPTSTR lpBuffer,
192
+ _In_ UINT uSize
193
+ );
194
+ =end
195
+ safe_attach_function :GetSystemWow64DirectoryW, [:LPTSTR, :UINT], :UINT
196
+ safe_attach_function :GetSystemWow64DirectoryA, [:LPTSTR, :UINT], :UINT
197
+
198
+ =begin
199
+ BOOL WINAPI Wow64DisableWow64FsRedirection(
200
+ _Out_ PVOID *OldValue
201
+ );
202
+ =end
203
+ safe_attach_function :Wow64DisableWow64FsRedirection, [:PVOID], :BOOL
204
+
205
+ =begin
206
+ BOOL WINAPI Wow64RevertWow64FsRedirection(
207
+ _In_ PVOID OldValue
208
+ );
209
+ =end
210
+ safe_attach_function :Wow64RevertWow64FsRedirection, [:PVOID], :BOOL
211
+
189
212
  =begin
190
213
  LRESULT WINAPI SendMessageTimeout(
191
214
  _In_ HWND hWnd,
@@ -129,49 +129,6 @@ int WideCharToMultiByte(
129
129
  =end
130
130
  safe_attach_function :WideCharToMultiByte, [:UINT, :DWORD, :LPCWSTR, :int, :LPSTR, :int, :LPCSTR, :LPBOOL], :int
131
131
 
132
- ###############################################
133
- # Helpers
134
- ###############################################
135
-
136
- def utf8_to_wide(ustring)
137
- # ensure it is actually UTF-8
138
- # Ruby likes to mark binary data as ASCII-8BIT
139
- ustring = (ustring + "").force_encoding('UTF-8') if ustring.respond_to?(:force_encoding) && ustring.encoding.name != "UTF-8"
140
-
141
- # ensure we have the double-null termination Windows Wide likes
142
- ustring = ustring + "\000\000" if ustring.length == 0 or ustring[-1].chr != "\000"
143
-
144
- # encode it all as UTF-16LE AKA Windows Wide Character AKA Windows Unicode
145
- ustring = begin
146
- if ustring.respond_to?(:encode)
147
- ustring.encode('UTF-16LE')
148
- else
149
- require 'iconv'
150
- Iconv.conv("UTF-16LE", "UTF-8", ustring)
151
- end
152
- end
153
- ustring
154
- end
155
-
156
- def wide_to_utf8(wstring)
157
- # ensure it is actually UTF-16LE
158
- # Ruby likes to mark binary data as ASCII-8BIT
159
- wstring = wstring.force_encoding('UTF-16LE') if wstring.respond_to?(:force_encoding)
160
-
161
- # encode it all as UTF-8
162
- wstring = begin
163
- if wstring.respond_to?(:encode)
164
- wstring.encode('UTF-8')
165
- else
166
- require 'iconv'
167
- Iconv.conv("UTF-8", "UTF-16LE", wstring)
168
- end
169
- end
170
- # remove trailing CRLF and NULL characters
171
- wstring.strip!
172
- wstring
173
- end
174
-
175
132
  end
176
133
  end
177
134
  end
@@ -19,6 +19,7 @@
19
19
  require 'chef/win32/error'
20
20
  require 'chef/win32/api/memory'
21
21
  require 'chef/win32/api/crypto'
22
+ require 'chef/win32/unicode'
22
23
  require 'digest'
23
24
 
24
25
  class Chef
@@ -29,7 +30,7 @@ class Chef
29
30
 
30
31
  def self.encrypt(str, &block)
31
32
  data_blob = CRYPT_INTEGER_BLOB.new
32
- unless CryptProtectData(CRYPT_INTEGER_BLOB.new(str.to_wstring), nil, nil, nil, nil, 0, data_blob)
33
+ unless CryptProtectData(CRYPT_INTEGER_BLOB.new(str.to_wstring), nil, nil, nil, nil, CRYPTPROTECT_LOCAL_MACHINE, data_blob)
33
34
  Chef::ReservedNames::Win32::Error.raise!
34
35
  end
35
36
  bytes = data_blob[:pbData].get_bytes(0, data_blob[:cbData])
@@ -17,9 +17,11 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
+ require 'chef/mixin/wide_string'
20
21
  require 'chef/win32/api/file'
21
22
  require 'chef/win32/api/security'
22
23
  require 'chef/win32/error'
24
+ require 'chef/win32/unicode'
23
25
 
24
26
  class Chef
25
27
  module ReservedNames::Win32
@@ -27,6 +29,9 @@ class Chef
27
29
  include Chef::ReservedNames::Win32::API::File
28
30
  extend Chef::ReservedNames::Win32::API::File
29
31
 
32
+ include Chef::Mixin::WideString
33
+ extend Chef::Mixin::WideString
34
+
30
35
  # Creates a symbolic link called +new_name+ for the file or directory
31
36
  # +old_name+.
32
37
  #
@@ -157,9 +162,9 @@ class Chef
157
162
 
158
163
  def self.file_access_check(path, desired_access)
159
164
  security_descriptor = Chef::ReservedNames::Win32::Security.get_file_security(path)
160
- token_rights = Chef::ReservedNames::Win32::Security::TOKEN_IMPERSONATE |
165
+ token_rights = Chef::ReservedNames::Win32::Security::TOKEN_IMPERSONATE |
161
166
  Chef::ReservedNames::Win32::Security::TOKEN_QUERY |
162
- Chef::ReservedNames::Win32::Security::TOKEN_DUPLICATE |
167
+ Chef::ReservedNames::Win32::Security::TOKEN_DUPLICATE |
163
168
  Chef::ReservedNames::Win32::Security::STANDARD_RIGHTS_READ
164
169
  token = Chef::ReservedNames::Win32::Security.open_process_token(
165
170
  Chef::ReservedNames::Win32::Process.get_current_process,
@@ -172,10 +177,30 @@ class Chef
172
177
  mapping[:GenericExecute] = Chef::ReservedNames::Win32::Security::FILE_GENERIC_EXECUTE
173
178
  mapping[:GenericAll] = Chef::ReservedNames::Win32::Security::FILE_ALL_ACCESS
174
179
 
175
- Chef::ReservedNames::Win32::Security.access_check(security_descriptor, duplicate_token,
180
+ Chef::ReservedNames::Win32::Security.access_check(security_descriptor, duplicate_token,
176
181
  desired_access, mapping)
177
182
  end
178
183
 
184
+ def self.delete_volume_mount_point(mount_point)
185
+ unless DeleteVolumeMountPointW(wstring(mount_point))
186
+ Chef::ReservedNames::Win32::Error.raise!
187
+ end
188
+ end
189
+
190
+ def self.set_volume_mount_point(mount_point, name)
191
+ unless SetVolumeMountPointW(wstring(mount_point), wstring(name))
192
+ Chef::ReservedNames::Win32::Error.raise!
193
+ end
194
+ end
195
+
196
+ def self.get_volume_name_for_volume_mount_point(mount_point)
197
+ buffer = FFI::MemoryPointer.new(2, 128)
198
+ unless GetVolumeNameForVolumeMountPointW(wstring(mount_point), buffer, buffer.size/buffer.type_size)
199
+ Chef::ReservedNames::Win32::Error.raise!
200
+ end
201
+ buffer.read_wstring
202
+ end
203
+
179
204
  # ::File compat
180
205
  class << self
181
206
  alias :stat :info
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/win32/api/synchronization'
20
+ require 'chef/win32/unicode'
20
21
 
21
22
  class Chef
22
23
  module ReservedNames::Win32
@@ -113,5 +114,3 @@ if the mutex is attempted to be acquired by other threads.")
113
114
  end
114
115
  end
115
116
  end
116
-
117
-
@@ -18,11 +18,11 @@
18
18
 
19
19
  require 'chef/win32/api/net'
20
20
  require 'chef/win32/error'
21
- require 'chef/mixin/wstring'
21
+ require 'chef/mixin/wide_string'
22
22
 
23
23
  class Chef
24
24
  module ReservedNames::Win32
25
- class NetUser
25
+ class Net
26
26
  include Chef::ReservedNames::Win32::API::Error
27
27
  extend Chef::ReservedNames::Win32::API::Error
28
28
 
@@ -91,19 +91,72 @@ The password is shorter than required. (The password could also be too
91
91
  long, be too recent in its change history, not have enough unique characters,
92
92
  or not meet another password policy requirement.)
93
93
  END
94
+ when NERR_GroupNotFound
95
+ "The group name could not be found."
94
96
  when ERROR_ACCESS_DENIED
95
97
  "The user does not have access to the requested information."
96
98
  else
97
99
  "Received unknown error code (#{code})"
98
100
  end
99
101
 
100
- formatted_message = ""
101
- formatted_message << "---- Begin Win32 API output ----\n"
102
- formatted_message << "Net Api Error Code: #{code}\n"
103
- formatted_message << "Net Api Error Message: #{msg}\n"
104
- formatted_message << "---- End Win32 API output ----\n"
102
+ raise Chef::Exceptions::Win32NetAPIError.new(msg, code)
103
+ end
104
+
105
+ def self.net_local_group_add(server_name, group_name)
106
+ server_name = wstring(server_name)
107
+ group_name = wstring(group_name)
108
+
109
+ buf = LOCALGROUP_INFO_0.new
110
+ buf[:lgrpi0_name] = FFI::MemoryPointer.from_string(group_name)
111
+
112
+ rc = NetLocalGroupAdd(server_name, 0, buf, nil)
113
+ if rc != NERR_Success
114
+ net_api_error!(rc)
115
+ end
116
+ end
117
+
118
+ def self.net_local_group_del(server_name, group_name)
119
+ server_name = wstring(server_name)
120
+ group_name = wstring(group_name)
105
121
 
106
- raise Chef::Exceptions::Win32APIError, msg + "\n" + formatted_message
122
+ rc = NetLocalGroupDel(server_name, group_name)
123
+ if rc != NERR_Success
124
+ net_api_error!(rc)
125
+ end
126
+ end
127
+
128
+ def self.net_local_group_get_members(server_name, group_name)
129
+ server_name = wstring(server_name)
130
+ group_name = wstring(group_name)
131
+
132
+ buf = FFI::MemoryPointer.new(:pointer)
133
+ entries_read_ptr = FFI::MemoryPointer.new(:long)
134
+ total_read_ptr = FFI::MemoryPointer.new(:long)
135
+ resume_handle_ptr = FFI::MemoryPointer.new(:pointer)
136
+
137
+ rc = ERROR_MORE_DATA
138
+ group_members = []
139
+ while rc == ERROR_MORE_DATA
140
+ rc = NetLocalGroupGetMembers(
141
+ server_name, group_name, 0, buf, -1,
142
+ entries_read_ptr, total_read_ptr, resume_handle_ptr
143
+ )
144
+
145
+ nread = entries_read_ptr.read_long
146
+ nread.times do |i|
147
+ member = LOCALGROUP_MEMBERS_INFO_0.new(buf.read_pointer +
148
+ (i * LOCALGROUP_MEMBERS_INFO_0.size))
149
+ member_sid = Chef::ReservedNames::Win32::Security::SID.new(member[:lgrmi0_sid])
150
+ group_members << member_sid.to_s
151
+ end
152
+ NetApiBufferFree(buf.read_pointer)
153
+ end
154
+
155
+ if rc != NERR_Success
156
+ net_api_error!(rc)
157
+ end
158
+
159
+ group_members
107
160
  end
108
161
 
109
162
  def self.net_user_add_l3(server_name, args)
@@ -185,6 +238,107 @@ END
185
238
  end
186
239
  end
187
240
 
241
+ def self.members_to_lgrmi3(members)
242
+ buf = FFI::MemoryPointer.new(LOCALGROUP_MEMBERS_INFO_3, members.size)
243
+ members.size.times.collect do |i|
244
+ member_info = LOCALGROUP_MEMBERS_INFO_3.new(
245
+ buf + i * LOCALGROUP_MEMBERS_INFO_3.size)
246
+ member_info[:lgrmi3_domainandname] = FFI::MemoryPointer.from_string(wstring(members[i]))
247
+ member_info
248
+ end
249
+ end
250
+
251
+ def self.net_local_group_add_members(server_name, group_name, members)
252
+ server_name = wstring(server_name)
253
+ group_name = wstring(group_name)
254
+
255
+ lgrmi3s = members_to_lgrmi3(members)
256
+ rc = NetLocalGroupAddMembers(
257
+ server_name, group_name, 3, lgrmi3s[0], members.size)
258
+
259
+ if rc != NERR_Success
260
+ net_api_error!(rc)
261
+ end
262
+ end
263
+
264
+ def self.net_local_group_set_members(server_name, group_name, members)
265
+ server_name = wstring(server_name)
266
+ group_name = wstring(group_name)
267
+
268
+ lgrmi3s = members_to_lgrmi3(members)
269
+ rc = NetLocalGroupSetMembers(
270
+ server_name, group_name, 3, lgrmi3s[0], members.size)
271
+
272
+ if rc != NERR_Success
273
+ net_api_error!(rc)
274
+ end
275
+ end
276
+
277
+ def self.net_local_group_del_members(server_name, group_name, members)
278
+ server_name = wstring(server_name)
279
+ group_name = wstring(group_name)
280
+
281
+ lgrmi3s = members_to_lgrmi3(members)
282
+ rc = NetLocalGroupDelMembers(
283
+ server_name, group_name, 3, lgrmi3s[0], members.size)
284
+
285
+ if rc != NERR_Success
286
+ net_api_error!(rc)
287
+ end
288
+ end
289
+
290
+ def self.net_use_del(server_name, use_name, force=:use_noforce)
291
+ server_name = wstring(server_name)
292
+ use_name = wstring(use_name)
293
+ force_const = case force
294
+ when :use_noforce
295
+ USE_NOFORCE
296
+ when :use_force
297
+ USE_FORCE
298
+ when :use_lots_of_force
299
+ USE_LOTS_OF_FORCE
300
+ else
301
+ raise ArgumentError, "force must be one of [:use_noforce, :use_force, or :use_lots_of_force]"
302
+ end
303
+
304
+ rc = NetUseDel(server_name, use_name, force_const)
305
+ if rc != NERR_Success
306
+ net_api_error!(rc)
307
+ end
308
+ end
309
+
310
+ def self.net_use_get_info_l2(server_name, use_name)
311
+ server_name = wstring(server_name)
312
+ use_name = wstring(use_name)
313
+ ui2_p = FFI::MemoryPointer.new(:pointer)
314
+
315
+ rc = NetUseGetInfo(server_name, use_name, 2, ui2_p)
316
+ if rc != NERR_Success
317
+ net_api_error!(rc)
318
+ end
319
+
320
+ ui2 = USE_INFO_2.new(ui2_p.read_pointer).as_ruby
321
+ NetApiBufferFree(ui2_p.read_pointer)
322
+
323
+ ui2
324
+ end
325
+
326
+ def self.net_use_add_l2(server_name, ui2_hash)
327
+ server_name = wstring(server_name)
328
+ group_name = wstring(group_name)
329
+
330
+ buf = USE_INFO_2.new
331
+
332
+ ui2_hash.each do |(k,v)|
333
+ buf.set(k,v)
334
+ end
335
+
336
+ rc = NetUseAdd(server_name, 2, buf, nil)
337
+ if rc != NERR_Success
338
+ net_api_error!(rc)
339
+ end
340
+ end
188
341
  end
342
+ NetUser = Net # For backwards compatibility
189
343
  end
190
344
  end
@@ -69,6 +69,19 @@ class Chef
69
69
  result
70
70
  end
71
71
 
72
+ def self.is_wow64_process
73
+ is_64_bit_process_result = FFI::MemoryPointer.new(:int)
74
+
75
+ # The return value of IsWow64Process is nonzero value if the API call succeeds.
76
+ # The result data are returned in the last parameter, not the return value.
77
+ call_succeeded = IsWow64Process(GetCurrentProcess(), is_64_bit_process_result)
78
+
79
+ # The result is nonzero if IsWow64Process's calling process, in the case here
80
+ # this process, is running under WOW64, i.e. the result is nonzero if this
81
+ # process is 32-bit (aka :i386).
82
+ (call_succeeded != 0) && (is_64_bit_process_result.get_int(0) != 0)
83
+ end
84
+
72
85
  # Must have PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION rights,
73
86
  # AND the PROCESS_VM_READ right
74
87
  def self.get_process_memory_info(handle)
@@ -17,8 +17,12 @@
17
17
  # limitations under the License.
18
18
  #
19
19
  require 'chef/reserved_names'
20
+ require 'chef/win32/api'
21
+ require 'chef/mixin/wide_string'
20
22
 
21
23
  if RUBY_PLATFORM =~ /mswin|mingw32|windows/
24
+ require 'chef/monkey_patches/win32/registry'
25
+ require 'chef/win32/api/registry'
22
26
  require 'win32/registry'
23
27
  require 'win32/api'
24
28
  end
@@ -27,6 +31,14 @@ class Chef
27
31
  class Win32
28
32
  class Registry
29
33
 
34
+ if RUBY_PLATFORM =~ /mswin|mingw32|windows/
35
+ include Chef::ReservedNames::Win32::API::Registry
36
+ extend Chef::ReservedNames::Win32::API::Registry
37
+ end
38
+
39
+ include Chef::Mixin::WideString
40
+ extend Chef::Mixin::WideString
41
+
30
42
  attr_accessor :run_context
31
43
  attr_accessor :architecture
32
44
 
@@ -115,38 +127,23 @@ class Chef
115
127
  Chef::Log.debug("Registry key #{key_path}, does not exist, not deleting")
116
128
  return true
117
129
  end
118
- #key_path is in the form "HKLM\Software\Opscode" for example, extracting
119
- #hive = HKLM,
120
- #hive_namespace = ::Win32::Registry::HKEY_LOCAL_MACHINE
121
- hive = key_path.split("\\").shift
122
- hive_namespace, key_including_parent = get_hive_and_key(key_path)
123
- if has_subkeys?(key_path)
124
- if recursive == true
125
- subkeys = get_subkeys(key_path)
126
- subkeys.each do |key|
127
- keypath_to_check = hive+"\\"+key_including_parent+"\\"+key
128
- Chef::Log.debug("Deleting registry key #{key_path} recursively")
129
- delete_key(keypath_to_check, true)
130
- end
131
- delete_key_ex(hive_namespace, key_including_parent)
132
- else
133
- raise Chef::Exceptions::Win32RegNoRecursive, "Registry key #{key_path} has subkeys, and recursive not specified"
134
- end
135
- else
136
- delete_key_ex(hive_namespace, key_including_parent)
137
- return true
130
+ if has_subkeys?(key_path) && !recursive
131
+ raise Chef::Exceptions::Win32RegNoRecursive, "Registry key #{key_path} has subkeys, and recursive not specified"
132
+ end
133
+ hive, key_including_parent = get_hive_and_key(key_path)
134
+ # key_including_parent: Software\\Root\\Branch\\Fruit
135
+ # key => Fruit
136
+ # key_parent => Software\\Root\\Branch
137
+ key_parts = key_including_parent.split("\\")
138
+ key = key_parts.pop
139
+ key_parent = key_parts.join("\\")
140
+ hive.open(key_parent, ::Win32::Registry::KEY_WRITE | registry_system_architecture) do |reg|
141
+ reg.delete_key(key, recursive)
138
142
  end
143
+ Chef::Log.debug("Registry key #{key_path} deleted")
139
144
  true
140
145
  end
141
146
 
142
- #Using the 'RegDeleteKeyEx' Windows API that correctly supports WOW64 systems (Win2003)
143
- #instead of the 'RegDeleteKey'
144
- def delete_key_ex(hive, key)
145
- regDeleteKeyEx = ::Win32::API.new('RegDeleteKeyEx', 'LPLL', 'L', 'advapi32')
146
- hive_num = hive.hkey - (1 << 32)
147
- regDeleteKeyEx.call(hive_num, key, ::Win32::Registry::KEY_WRITE | registry_system_architecture, 0)
148
- end
149
-
150
147
  def key_exists?(key_path)
151
148
  hive, key = get_hive_and_key(key_path)
152
149
  begin
@@ -203,7 +200,7 @@ class Chef
203
200
  key_exists!(key_path)
204
201
  hive, key = get_hive_and_key(key_path)
205
202
  hive.open(key, ::Win32::Registry::KEY_READ | registry_system_architecture) do |reg|
206
- return true if reg.any? {|val| val == value[:name] }
203
+ return true if reg.any? {|val| safely_downcase(val) == safely_downcase(value[:name]) }
207
204
  end
208
205
  return false
209
206
  end
@@ -213,7 +210,7 @@ class Chef
213
210
  hive, key = get_hive_and_key(key_path)
214
211
  hive.open(key, ::Win32::Registry::KEY_READ | registry_system_architecture) do |reg|
215
212
  reg.each do |val_name, val_type, val_data|
216
- if val_name == value[:name] &&
213
+ if safely_downcase(val_name) == safely_downcase(value[:name]) &&
217
214
  val_type == get_type_from_name(value[:type]) &&
218
215
  val_data == value[:data]
219
216
  return true
@@ -289,6 +286,14 @@ class Chef
289
286
 
290
287
  private
291
288
 
289
+
290
+ def safely_downcase(val)
291
+ if val.is_a? String
292
+ return val.downcase
293
+ end
294
+ return val
295
+ end
296
+
292
297
  def node
293
298
  run_context && run_context.node
294
299
  end