chef 12.5.0.alpha.1 → 12.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) 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 +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -21,61 +21,18 @@
21
21
  #see also cmd.exe: net use /?
22
22
 
23
23
  require 'chef/util/windows'
24
+ require 'chef/win32/net'
24
25
 
25
26
  class Chef::Util::Windows::NetUse < Chef::Util::Windows
26
-
27
- private
28
-
29
- USE_NOFORCE = 0
30
- USE_FORCE = 1
31
- USE_LOTS_OF_FORCE = 2 #every windows API should support this flag
32
-
33
- USE_INFO_2 = [
34
- [:local, nil],
35
- [:remote, nil],
36
- [:password, nil],
37
- [:status, 0],
38
- [:asg_type, 0],
39
- [:refcount, 0],
40
- [:usecount, 0],
41
- [:username, nil],
42
- [:domainname, nil]
43
- ]
44
-
45
- USE_INFO_2_TEMPLATE =
46
- USE_INFO_2.collect { |field| field[1].class == Fixnum ? 'i' : 'L' }.join
47
-
48
- SIZEOF_USE_INFO_2 = #sizeof(USE_INFO_2)
49
- USE_INFO_2.inject(0) do |sum, item|
50
- sum + (item[1].class == Fixnum ? 4 : PTR_SIZE)
51
- end
52
-
53
- def use_info_2(args)
54
- USE_INFO_2.collect { |field|
55
- args.include?(field[0]) ? args[field[0]] : field[1]
56
- }
57
- end
58
-
59
- def use_info_2_pack(use)
60
- use.collect { |v|
61
- v.class == Fixnum ? v : str_to_ptr(multi_to_wide(v))
62
- }.pack(USE_INFO_2_TEMPLATE)
27
+ def initialize(localname)
28
+ @use_name = localname
63
29
  end
64
30
 
65
- def use_info_2_unpack(buffer)
66
- use = Hash.new
67
- USE_INFO_2.each_with_index do |field,offset|
68
- use[field[0]] = field[1].class == Fixnum ?
69
- dword_to_i(buffer, offset) : lpwstr_to_s(buffer, offset)
31
+ def to_ui2_struct(use_info)
32
+ use_info.inject({}) do |memo, (k,v)|
33
+ memo["ui2_#{k}".to_sym] = v
34
+ memo
70
35
  end
71
- use
72
- end
73
-
74
- public
75
-
76
- def initialize(localname)
77
- @localname = localname
78
- @name = multi_to_wide(localname)
79
36
  end
80
37
 
81
38
  def add(args)
@@ -84,38 +41,45 @@ class Chef::Util::Windows::NetUse < Chef::Util::Windows
84
41
  args = Hash.new
85
42
  args[:remote] = remote
86
43
  end
87
- args[:local] ||= @localname
88
- use = use_info_2(args)
89
- buffer = use_info_2_pack(use)
90
- rc = NetUseAdd.call(nil, 2, buffer, nil)
91
- if rc != NERR_Success
92
- raise ArgumentError, get_last_error(rc)
44
+ args[:local] ||= use_name
45
+ ui2_hash = to_ui2_struct(args)
46
+
47
+ begin
48
+ Chef::ReservedNames::Win32::Net.net_use_add_l2(nil, ui2_hash)
49
+ rescue Chef::Exceptions::Win32APIError => e
50
+ raise ArgumentError, e
93
51
  end
94
52
  end
95
53
 
96
- def get_info
97
- ptr = 0.chr * PTR_SIZE
98
- rc = NetUseGetInfo.call(nil, @name, 2, ptr)
99
-
100
- if rc != NERR_Success
101
- raise ArgumentError, get_last_error(rc)
54
+ def from_use_info_struct(ui2_hash)
55
+ ui2_hash.inject({}) do |memo, (k,v)|
56
+ memo[k.to_s.sub('ui2_', '').to_sym] = v
57
+ memo
102
58
  end
59
+ end
103
60
 
104
- ptr = ptr.unpack('L')[0]
105
- buffer = 0.chr * SIZEOF_USE_INFO_2
106
- memcpy(buffer, ptr, buffer.size)
107
- NetApiBufferFree(ptr)
108
- use_info_2_unpack(buffer)
61
+ def get_info
62
+ begin
63
+ ui2 = Chef::ReservedNames::Win32::Net.net_use_get_info_l2(nil, use_name)
64
+ from_use_info_struct(ui2)
65
+ rescue Chef::Exceptions::Win32APIError => e
66
+ raise ArgumentError, e
67
+ end
109
68
  end
110
69
 
111
70
  def device
112
71
  get_info()[:remote]
113
72
  end
114
- #XXX should we use some FORCE here?
73
+
115
74
  def delete
116
- rc = NetUseDel.call(nil, @name, USE_NOFORCE)
117
- if rc != NERR_Success
118
- raise ArgumentError, get_last_error(rc)
75
+ begin
76
+ Chef::ReservedNames::Win32::Net.net_use_del(nil, use_name, :use_noforce)
77
+ rescue Chef::Exceptions::Win32APIError => e
78
+ raise ArgumentError, e
119
79
  end
120
80
  end
81
+
82
+ def use_name
83
+ @use_name
84
+ end
121
85
  end
@@ -88,7 +88,6 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
88
88
 
89
89
  def initialize(username)
90
90
  @username = username
91
- @name = multi_to_wide(username)
92
91
  end
93
92
 
94
93
  LOGON32_PROVIDER_DEFAULT = Security::LOGON32_PROVIDER_DEFAULT
@@ -18,42 +18,42 @@
18
18
 
19
19
  #simple wrapper around Volume APIs. might be possible with WMI, but possibly more complex.
20
20
 
21
+ require 'chef/win32/api/file'
21
22
  require 'chef/util/windows'
22
- require 'windows/volume'
23
23
 
24
24
  class Chef::Util::Windows::Volume < Chef::Util::Windows
25
-
26
- private
27
- include Windows::Volume
28
- #XXX not defined in the current windows-pr release
29
- DeleteVolumeMountPoint =
30
- Windows::API.new('DeleteVolumeMountPoint', 'S', 'B') unless defined? DeleteVolumeMountPoint
31
-
32
- public
25
+ attr_reader :mount_point
33
26
 
34
27
  def initialize(name)
35
28
  name += "\\" unless name =~ /\\$/ #trailing slash required
36
- @name = name
29
+ @mount_point = name
37
30
  end
38
31
 
39
32
  def device
40
- buffer = 0.chr * 256
41
- if GetVolumeNameForVolumeMountPoint(@name, buffer, buffer.size)
42
- return buffer[0,buffer.size].unpack("Z*")[0]
43
- else
44
- raise ArgumentError, get_last_error
33
+ begin
34
+ Chef::ReservedNames::Win32::File.get_volume_name_for_volume_mount_point(mount_point)
35
+ rescue Chef::Exceptions::Win32APIError => e
36
+ raise ArgumentError, e
45
37
  end
46
38
  end
47
39
 
48
40
  def delete
49
- unless DeleteVolumeMountPoint.call(@name)
50
- raise ArgumentError, get_last_error
41
+ begin
42
+ Chef::ReservedNames::Win32::File.delete_volume_mount_point(mount_point)
43
+ rescue Chef::Exceptions::Win32APIError => e
44
+ raise ArgumentError, e
51
45
  end
52
46
  end
53
47
 
54
48
  def add(args)
55
- unless SetVolumeMountPoint(@name, args[:remote])
56
- raise ArgumentError, get_last_error
49
+ begin
50
+ Chef::ReservedNames::Win32::File.set_volume_mount_point(mount_point, args[:remote])
51
+ rescue Chef::Exceptions::Win32APIError => e
52
+ raise ArgumentError, e
57
53
  end
58
54
  end
55
+
56
+ def mount_point
57
+ @mount_point
58
+ end
59
59
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
24
- VERSION = '12.5.0.alpha.1'
24
+ VERSION = '12.5.1'
25
25
  end
26
26
 
27
27
  #
@@ -29,6 +29,6 @@ end
29
29
  #
30
30
  # NOTE: DO NOT Use the Chef::Version class on Chef::VERSIONs. The
31
31
  # Chef::Version class is for _cookbooks_ only, and cannot handle
32
- # pre-release chef-client versions like "10.14.0.rc.2". Please
33
- # use Rubygem's Gem::Version class instead.
32
+ # pre-release versions like "10.14.0.rc.2". Please use Rubygem's
33
+ # Gem::Version class instead.
34
34
  #
@@ -188,6 +188,7 @@ class Chef
188
188
  host.typedef :pointer, :PCRYPTPROTECT_PROMPTSTRUCT # Pointer to a CRYPTOPROTECT_PROMPTSTRUCT.
189
189
  host.typedef :pointer, :PDATA_BLOB # Pointer to a DATA_BLOB.
190
190
  host.typedef :pointer, :PTSTR # A PWSTR if UNICODE is defined, a PSTR otherwise.
191
+ host.typedef :pointer, :PSID
191
192
  host.typedef :pointer, :PUCHAR # Pointer to a UCHAR.
192
193
  host.typedef :pointer, :PUHALF_PTR # Pointer to a UHALF_PTR.
193
194
  host.typedef :pointer, :PUINT # Pointer to a UINT.
@@ -20,6 +20,7 @@
20
20
  require 'chef/win32/api'
21
21
  require 'chef/win32/api/security'
22
22
  require 'chef/win32/api/system'
23
+ require 'chef/win32/unicode'
23
24
 
24
25
  class Chef
25
26
  module ReservedNames::Win32
@@ -450,6 +451,25 @@ BOOL WINAPI DeviceIoControl(
450
451
  =end
451
452
  safe_attach_function :DeviceIoControl, [:HANDLE, :DWORD, :LPVOID, :DWORD, :LPVOID, :DWORD, :LPDWORD, :pointer], :BOOL
452
453
 
454
+
455
+ #BOOL WINAPI DeleteVolumeMountPoint(
456
+ #_In_ LPCTSTR lpszVolumeMountPoint
457
+ #);
458
+ safe_attach_function :DeleteVolumeMountPointW, [:LPCTSTR], :BOOL
459
+
460
+ #BOOL WINAPI SetVolumeMountPoint(
461
+ #_In_ LPCTSTR lpszVolumeMountPoint,
462
+ #_In_ LPCTSTR lpszVolumeName
463
+ #);
464
+ safe_attach_function :SetVolumeMountPointW, [:LPCTSTR, :LPCTSTR], :BOOL
465
+
466
+ #BOOL WINAPI GetVolumeNameForVolumeMountPoint(
467
+ #_In_ LPCTSTR lpszVolumeMountPoint,
468
+ #_Out_ LPTSTR lpszVolumeName,
469
+ #_In_ DWORD cchBufferLength
470
+ #);
471
+ safe_attach_function :GetVolumeNameForVolumeMountPointW, [:LPCTSTR, :LPTSTR, :DWORD], :BOOL
472
+
453
473
  ###############################################
454
474
  # Helpers
455
475
  ###############################################
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/win32/api'
20
+ require 'chef/win32/unicode'
20
21
 
21
22
  class Chef
22
23
  module ReservedNames::Win32
@@ -40,6 +41,10 @@ class Chef
40
41
  UF_NORMAL_ACCOUNT = 0x000200
41
42
  UF_DONT_EXPIRE_PASSWD = 0x010000
42
43
 
44
+ USE_NOFORCE = 0
45
+ USE_FORCE = 1
46
+ USE_LOTS_OF_FORCE = 2 #every windows API should support this flag
47
+
43
48
  NERR_Success = 0
44
49
  NERR_InvalidComputer = 2351
45
50
  NERR_NotPrimary = 2226
@@ -49,41 +54,13 @@ class Chef
49
54
  NERR_BadPassword = 2203
50
55
  NERR_PasswordTooShort = 2245
51
56
  NERR_UserNotFound = 2221
57
+ NERR_GroupNotFound = 2220
52
58
  ERROR_ACCESS_DENIED = 5
59
+ ERROR_MORE_DATA = 234
53
60
 
54
61
  ffi_lib "netapi32"
55
62
 
56
- class USER_INFO_3 < FFI::Struct
57
- layout :usri3_name, :LPWSTR,
58
- :usri3_password, :LPWSTR,
59
- :usri3_password_age, :DWORD,
60
- :usri3_priv, :DWORD,
61
- :usri3_home_dir, :LPWSTR,
62
- :usri3_comment, :LPWSTR,
63
- :usri3_flags, :DWORD,
64
- :usri3_script_path, :LPWSTR,
65
- :usri3_auth_flags, :DWORD,
66
- :usri3_full_name, :LPWSTR,
67
- :usri3_usr_comment, :LPWSTR,
68
- :usri3_parms, :LPWSTR,
69
- :usri3_workstations, :LPWSTR,
70
- :usri3_last_logon, :DWORD,
71
- :usri3_last_logoff, :DWORD,
72
- :usri3_acct_expires, :DWORD,
73
- :usri3_max_storage, :DWORD,
74
- :usri3_units_per_week, :DWORD,
75
- :usri3_logon_hours, :PBYTE,
76
- :usri3_bad_pw_count, :DWORD,
77
- :usri3_num_logons, :DWORD,
78
- :usri3_logon_server, :LPWSTR,
79
- :usri3_country_code, :DWORD,
80
- :usri3_code_page, :DWORD,
81
- :usri3_user_id, :DWORD,
82
- :usri3_primary_group_id, :DWORD,
83
- :usri3_profile, :LPWSTR,
84
- :usri3_home_dir_drive, :LPWSTR,
85
- :usri3_password_expired, :DWORD
86
-
63
+ module StructHelpers
87
64
  def set(key, val)
88
65
  val = if val.is_a? String
89
66
  encoded = if val.encoding == Encoding::UTF_16LE
@@ -115,6 +92,47 @@ class Chef
115
92
  end
116
93
  end
117
94
 
95
+ def as_ruby
96
+ members.inject({}) do |memo, key|
97
+ memo[key] = get(key)
98
+ memo
99
+ end
100
+ end
101
+ end
102
+
103
+
104
+ class USER_INFO_3 < FFI::Struct
105
+ include StructHelpers
106
+ layout :usri3_name, :LPWSTR,
107
+ :usri3_password, :LPWSTR,
108
+ :usri3_password_age, :DWORD,
109
+ :usri3_priv, :DWORD,
110
+ :usri3_home_dir, :LPWSTR,
111
+ :usri3_comment, :LPWSTR,
112
+ :usri3_flags, :DWORD,
113
+ :usri3_script_path, :LPWSTR,
114
+ :usri3_auth_flags, :DWORD,
115
+ :usri3_full_name, :LPWSTR,
116
+ :usri3_usr_comment, :LPWSTR,
117
+ :usri3_parms, :LPWSTR,
118
+ :usri3_workstations, :LPWSTR,
119
+ :usri3_last_logon, :DWORD,
120
+ :usri3_last_logoff, :DWORD,
121
+ :usri3_acct_expires, :DWORD,
122
+ :usri3_max_storage, :DWORD,
123
+ :usri3_units_per_week, :DWORD,
124
+ :usri3_logon_hours, :PBYTE,
125
+ :usri3_bad_pw_count, :DWORD,
126
+ :usri3_num_logons, :DWORD,
127
+ :usri3_logon_server, :LPWSTR,
128
+ :usri3_country_code, :DWORD,
129
+ :usri3_code_page, :DWORD,
130
+ :usri3_user_id, :DWORD,
131
+ :usri3_primary_group_id, :DWORD,
132
+ :usri3_profile, :LPWSTR,
133
+ :usri3_home_dir_drive, :LPWSTR,
134
+ :usri3_password_expired, :DWORD
135
+
118
136
  def usri3_logon_hours
119
137
  val = self[:usri3_logon_hours]
120
138
  if !val.nil? && !val.null?
@@ -123,19 +141,66 @@ class Chef
123
141
  nil
124
142
  end
125
143
  end
144
+ end
126
145
 
127
- def as_ruby
128
- members.inject({}) do |memo, key|
129
- memo[key] = get(key)
130
- memo
131
- end
132
- end
146
+ class LOCALGROUP_MEMBERS_INFO_0 < FFI::Struct
147
+ layout :lgrmi0_sid, :PSID
133
148
  end
134
149
 
135
150
  class LOCALGROUP_MEMBERS_INFO_3 < FFI::Struct
136
151
  layout :lgrmi3_domainandname, :LPWSTR
137
152
  end
138
153
 
154
+ class LOCALGROUP_INFO_0 < FFI::Struct
155
+ layout :lgrpi0_name, :LPWSTR
156
+ end
157
+
158
+ class USE_INFO_2 < FFI::Struct
159
+ include StructHelpers
160
+
161
+ layout :ui2_local, :LMSTR,
162
+ :ui2_remote, :LMSTR,
163
+ :ui2_password, :LMSTR,
164
+ :ui2_status, :DWORD,
165
+ :ui2_asg_type, :DWORD,
166
+ :ui2_refcount, :DWORD,
167
+ :ui2_usecount, :DWORD,
168
+ :ui2_username, :LPWSTR,
169
+ :ui2_domainname, :LMSTR
170
+ end
171
+
172
+
173
+ #NET_API_STATUS NetLocalGroupAdd(
174
+ #_In_ LPCWSTR servername,
175
+ #_In_ DWORD level,
176
+ #_In_ LPBYTE buf,
177
+ #_Out_ LPDWORD parm_err
178
+ #);
179
+ safe_attach_function :NetLocalGroupAdd, [
180
+ :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD
181
+ ], :DWORD
182
+
183
+ #NET_API_STATUS NetLocalGroupDel(
184
+ #_In_ LPCWSTR servername,
185
+ #_In_ LPCWSTR groupname
186
+ #);
187
+ safe_attach_function :NetLocalGroupDel, [:LPCWSTR, :LPCWSTR], :DWORD
188
+
189
+ #NET_API_STATUS NetLocalGroupGetMembers(
190
+ #_In_ LPCWSTR servername,
191
+ #_In_ LPCWSTR localgroupname,
192
+ #_In_ DWORD level,
193
+ #_Out_ LPBYTE *bufptr,
194
+ #_In_ DWORD prefmaxlen,
195
+ #_Out_ LPDWORD entriesread,
196
+ #_Out_ LPDWORD totalentries,
197
+ #_Inout_ PDWORD_PTR resumehandle
198
+ #);
199
+ safe_attach_function :NetLocalGroupGetMembers, [
200
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD,
201
+ :LPDWORD, :LPDWORD, :PDWORD_PTR
202
+ ], :DWORD
203
+
139
204
  # NET_API_STATUS NetUserEnum(
140
205
  # _In_ LPCWSTR servername,
141
206
  # _In_ DWORD level,
@@ -146,12 +211,15 @@ class Chef
146
211
  # _Out_ LPDWORD totalentries,
147
212
  # _Inout_ LPDWORD resume_handle
148
213
  # );
149
- safe_attach_function :NetUserEnum, [ :LPCWSTR, :DWORD, :DWORD, :LPBYTE, :DWORD, :LPDWORD, :LPDWORD, :LPDWORD ], :DWORD
214
+ safe_attach_function :NetUserEnum, [
215
+ :LPCWSTR, :DWORD, :DWORD, :LPBYTE,
216
+ :DWORD, :LPDWORD, :LPDWORD, :LPDWORD
217
+ ], :DWORD
150
218
 
151
219
  # NET_API_STATUS NetApiBufferFree(
152
220
  # _In_ LPVOID Buffer
153
221
  # );
154
- safe_attach_function :NetApiBufferFree, [ :LPVOID ], :DWORD
222
+ safe_attach_function :NetApiBufferFree, [:LPVOID], :DWORD
155
223
 
156
224
  #NET_API_STATUS NetUserAdd(
157
225
  #_In_ LMSTR servername,
@@ -159,7 +227,9 @@ class Chef
159
227
  #_In_ LPBYTE buf,
160
228
  #_Out_ LPDWORD parm_err
161
229
  #);
162
- safe_attach_function :NetUserAdd, [:LMSTR, :DWORD, :LPBYTE, :LPDWORD ], :DWORD
230
+ safe_attach_function :NetUserAdd, [
231
+ :LMSTR, :DWORD, :LPBYTE, :LPDWORD
232
+ ], :DWORD
163
233
 
164
234
  #NET_API_STATUS NetLocalGroupAddMembers(
165
235
  # _In_ LPCWSTR servername,
@@ -168,7 +238,31 @@ class Chef
168
238
  # _In_ LPBYTE buf,
169
239
  # _In_ DWORD totalentries
170
240
  #);
171
- safe_attach_function :NetLocalGroupAddMembers, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD ], :DWORD
241
+ safe_attach_function :NetLocalGroupAddMembers, [
242
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD
243
+ ], :DWORD
244
+
245
+ #NET_API_STATUS NetLocalGroupSetMembers(
246
+ # _In_ LPCWSTR servername,
247
+ # _In_ LPCWSTR groupname,
248
+ # _In_ DWORD level,
249
+ # _In_ LPBYTE buf,
250
+ # _In_ DWORD totalentries
251
+ #);
252
+ safe_attach_function :NetLocalGroupSetMembers, [
253
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD
254
+ ], :DWORD
255
+
256
+ #NET_API_STATUS NetLocalGroupDelMembers(
257
+ # _In_ LPCWSTR servername,
258
+ # _In_ LPCWSTR groupname,
259
+ # _In_ DWORD level,
260
+ # _In_ LPBYTE buf,
261
+ # _In_ DWORD totalentries
262
+ #);
263
+ safe_attach_function :NetLocalGroupDelMembers, [
264
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD
265
+ ], :DWORD
172
266
 
173
267
  #NET_API_STATUS NetUserGetInfo(
174
268
  # _In_ LPCWSTR servername,
@@ -176,7 +270,9 @@ class Chef
176
270
  # _In_ DWORD level,
177
271
  # _Out_ LPBYTE *bufptr
178
272
  #);
179
- safe_attach_function :NetUserGetInfo, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE], :DWORD
273
+ safe_attach_function :NetUserGetInfo, [
274
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE
275
+ ], :DWORD
180
276
 
181
277
  #NET_API_STATUS NetApiBufferFree(
182
278
  # _In_ LPVOID Buffer
@@ -190,7 +286,9 @@ class Chef
190
286
  # _In_ LPBYTE buf,
191
287
  # _Out_ LPDWORD parm_err
192
288
  #);
193
- safe_attach_function :NetUserSetInfo, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD], :DWORD
289
+ safe_attach_function :NetUserSetInfo, [
290
+ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD
291
+ ], :DWORD
194
292
 
195
293
  #NET_API_STATUS NetUserDel(
196
294
  # _In_ LPCWSTR servername,
@@ -198,6 +296,28 @@ class Chef
198
296
  #);
199
297
  safe_attach_function :NetUserDel, [:LPCWSTR, :LPCWSTR], :DWORD
200
298
 
299
+ #NET_API_STATUS NetUseDel(
300
+ #_In_ LMSTR UncServerName,
301
+ #_In_ LMSTR UseName,
302
+ #_In_ DWORD ForceCond
303
+ #);
304
+ safe_attach_function :NetUseDel, [:LMSTR, :LMSTR, :DWORD], :DWORD
305
+
306
+ #NET_API_STATUS NetUseGetInfo(
307
+ #_In_ LMSTR UncServerName,
308
+ #_In_ LMSTR UseName,
309
+ #_In_ DWORD Level,
310
+ #_Out_ LPBYTE *BufPtr
311
+ #);
312
+ safe_attach_function :NetUseGetInfo, [:LMSTR, :LMSTR, :DWORD, :pointer], :DWORD
313
+
314
+ #NET_API_STATUS NetUseAdd(
315
+ #_In_ LMSTR UncServerName,
316
+ #_In_ DWORD Level,
317
+ #_In_ LPBYTE Buf,
318
+ #_Out_ LPDWORD ParmError
319
+ #);
320
+ safe_attach_function :NetUseAdd, [:LMSTR, :DWORD, :LPBYTE, :LPDWORD], :DWORD
201
321
  end
202
322
  end
203
323
  end