chef 12.3.0 → 12.4.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +86 -7
  3. data/distro/common/markdown/man1/chef-shell.mkd +4 -4
  4. data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
  5. data/distro/common/markdown/man1/knife-client.mkd +1 -1
  6. data/distro/common/markdown/man1/knife-configure.mkd +1 -1
  7. data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
  8. data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
  9. data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
  10. data/distro/common/markdown/man1/knife-environment.mkd +3 -3
  11. data/distro/common/markdown/man1/knife-exec.mkd +1 -1
  12. data/distro/common/markdown/man1/knife-index.mkd +1 -1
  13. data/distro/common/markdown/man1/knife-node.mkd +1 -1
  14. data/distro/common/markdown/man1/knife-role.mkd +3 -3
  15. data/distro/common/markdown/man1/knife-search.mkd +2 -2
  16. data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
  17. data/distro/common/markdown/man1/knife-status.mkd +1 -1
  18. data/distro/common/markdown/man1/knife-tag.mkd +1 -1
  19. data/distro/common/markdown/man1/knife.mkd +2 -2
  20. data/distro/common/markdown/man8/chef-client.mkd +1 -2
  21. data/distro/common/markdown/man8/chef-expander.mkd +1 -2
  22. data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
  23. data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
  24. data/distro/common/markdown/man8/chef-server.mkd +1 -2
  25. data/distro/common/markdown/man8/chef-solo.mkd +2 -2
  26. data/distro/common/markdown/man8/chef-solr.mkd +1 -1
  27. data/lib/chef/client.rb +2 -2
  28. data/lib/chef/config.rb +17 -709
  29. data/lib/chef/cookbook/metadata.rb +9 -5
  30. data/lib/chef/cookbook_loader.rb +1 -1
  31. data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
  32. data/lib/chef/dsl/definitions.rb +44 -0
  33. data/lib/chef/dsl/recipe.rb +50 -35
  34. data/lib/chef/dsl/resources.rb +28 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +2 -0
  36. data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
  37. data/lib/chef/exceptions.rb +4 -0
  38. data/lib/chef/file_access_control/unix.rb +5 -0
  39. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
  40. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
  41. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
  42. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
  43. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
  44. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
  45. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
  46. data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
  47. data/lib/chef/http/authenticator.rb +3 -0
  48. data/lib/chef/http/basic_client.rb +10 -6
  49. data/lib/chef/http/json_input.rb +6 -1
  50. data/lib/chef/key.rb +271 -0
  51. data/lib/chef/knife.rb +11 -1
  52. data/lib/chef/knife/bootstrap.rb +6 -0
  53. data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
  54. data/lib/chef/knife/client_key_create.rb +67 -0
  55. data/lib/chef/knife/client_key_delete.rb +76 -0
  56. data/lib/chef/knife/client_key_edit.rb +80 -0
  57. data/lib/chef/knife/client_key_list.rb +69 -0
  58. data/lib/chef/knife/client_key_show.rb +76 -0
  59. data/lib/chef/knife/key_create.rb +108 -0
  60. data/lib/chef/knife/key_create_base.rb +50 -0
  61. data/lib/chef/knife/key_delete.rb +55 -0
  62. data/lib/chef/knife/key_edit.rb +114 -0
  63. data/lib/chef/knife/key_edit_base.rb +55 -0
  64. data/lib/chef/knife/key_list.rb +88 -0
  65. data/lib/chef/knife/key_list_base.rb +45 -0
  66. data/lib/chef/knife/key_show.rb +53 -0
  67. data/lib/chef/knife/ssh.rb +26 -28
  68. data/lib/chef/knife/user_key_create.rb +69 -0
  69. data/lib/chef/knife/user_key_delete.rb +76 -0
  70. data/lib/chef/knife/user_key_edit.rb +80 -0
  71. data/lib/chef/knife/user_key_list.rb +69 -0
  72. data/lib/chef/knife/user_key_show.rb +76 -0
  73. data/lib/chef/log.rb +2 -0
  74. data/lib/chef/log/syslog.rb +46 -0
  75. data/lib/chef/log/winevt.rb +99 -0
  76. data/lib/chef/mixin/provides.rb +8 -1
  77. data/lib/chef/mixin/unformatter.rb +32 -0
  78. data/lib/chef/mixin/uris.rb +33 -0
  79. data/lib/chef/mixin/wstring.rb +31 -0
  80. data/lib/chef/node.rb +21 -2
  81. data/lib/chef/platform/provider_mapping.rb +8 -4
  82. data/lib/chef/platform/query_helpers.rb +1 -5
  83. data/lib/chef/platform/service_helpers.rb +21 -21
  84. data/lib/chef/provider.rb +33 -0
  85. data/lib/chef/provider/cron/unix.rb +1 -0
  86. data/lib/chef/provider/file.rb +5 -3
  87. data/lib/chef/provider/lwrp_base.rb +76 -58
  88. data/lib/chef/provider/ohai.rb +1 -0
  89. data/lib/chef/provider/package.rb +7 -4
  90. data/lib/chef/provider/package/aix.rb +1 -0
  91. data/lib/chef/provider/package/smartos.rb +5 -5
  92. data/lib/chef/provider/package/windows.rb +90 -6
  93. data/lib/chef/provider/package/yum.rb +102 -32
  94. data/lib/chef/provider/reboot.rb +1 -0
  95. data/lib/chef/provider/registry_key.rb +2 -0
  96. data/lib/chef/provider/remote_file.rb +1 -0
  97. data/lib/chef/provider/remote_file/content.rb +5 -1
  98. data/lib/chef/provider/remote_file/fetcher.rb +22 -8
  99. data/lib/chef/provider/remote_file/network_file.rb +48 -0
  100. data/lib/chef/provider/service/aix.rb +13 -12
  101. data/lib/chef/provider_resolver.rb +87 -0
  102. data/lib/chef/providers.rb +1 -0
  103. data/lib/chef/resource.rb +67 -8
  104. data/lib/chef/resource/bash.rb +1 -0
  105. data/lib/chef/resource/bff_package.rb +1 -2
  106. data/lib/chef/resource/breakpoint.rb +1 -0
  107. data/lib/chef/resource/csh.rb +1 -0
  108. data/lib/chef/resource/deploy.rb +1 -0
  109. data/lib/chef/resource/erl_call.rb +1 -0
  110. data/lib/chef/resource/execute.rb +1 -0
  111. data/lib/chef/resource/file.rb +18 -0
  112. data/lib/chef/resource/http_request.rb +1 -0
  113. data/lib/chef/resource/ifconfig.rb +1 -2
  114. data/lib/chef/resource/log.rb +1 -2
  115. data/lib/chef/resource/lwrp_base.rb +106 -87
  116. data/lib/chef/resource/ohai.rb +1 -0
  117. data/lib/chef/resource/package.rb +1 -0
  118. data/lib/chef/resource/perl.rb +1 -0
  119. data/lib/chef/resource/portage_package.rb +1 -0
  120. data/lib/chef/resource/python.rb +1 -0
  121. data/lib/chef/resource/reboot.rb +2 -0
  122. data/lib/chef/resource/registry_key.rb +1 -0
  123. data/lib/chef/resource/remote_file.rb +1 -1
  124. data/lib/chef/resource/route.rb +1 -2
  125. data/lib/chef/resource/ruby.rb +1 -0
  126. data/lib/chef/resource/ruby_block.rb +1 -0
  127. data/lib/chef/resource/scm.rb +1 -0
  128. data/lib/chef/resource/script.rb +1 -0
  129. data/lib/chef/resource/service.rb +1 -0
  130. data/lib/chef/resource/subversion.rb +1 -0
  131. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +24 -2
  133. data/lib/chef/resource/windows_script.rb +1 -0
  134. data/lib/chef/resource/yum_package.rb +1 -1
  135. data/lib/chef/resource_definition.rb +1 -0
  136. data/lib/chef/resource_reporter.rb +3 -10
  137. data/lib/chef/resource_resolver.rb +20 -10
  138. data/lib/chef/run_context.rb +1 -0
  139. data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
  140. data/lib/chef/run_status.rb +2 -4
  141. data/lib/chef/shell.rb +1 -1
  142. data/lib/chef/util/path_helper.rb +3 -204
  143. data/lib/chef/util/windows/net_user.rb +73 -118
  144. data/lib/chef/version.rb +8 -4
  145. data/lib/chef/win32/api.rb +2 -1
  146. data/lib/chef/win32/api/installer.rb +1 -1
  147. data/lib/chef/win32/api/net.rb +115 -2
  148. data/lib/chef/win32/api/security.rb +24 -0
  149. data/lib/chef/win32/api/unicode.rb +1 -1
  150. data/lib/chef/win32/eventlog.rb +31 -0
  151. data/lib/chef/win32/net.rb +190 -0
  152. data/lib/chef/win32/security.rb +51 -2
  153. data/lib/chef/win32/security/sid.rb +17 -0
  154. data/spec/data/lwrp/providers/buck_passer.rb +18 -2
  155. data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
  156. data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
  157. data/spec/data/lwrp_override/resources/foo.rb +5 -0
  158. data/spec/functional/knife/ssh_spec.rb +2 -2
  159. data/spec/functional/rebooter_spec.rb +1 -1
  160. data/spec/functional/resource/aixinit_service_spec.rb +1 -1
  161. data/spec/functional/resource/user/windows_spec.rb +125 -0
  162. data/spec/functional/shell_spec.rb +25 -10
  163. data/spec/functional/win32/sid_spec.rb +55 -0
  164. data/spec/integration/client/client_spec.rb +53 -29
  165. data/spec/integration/knife/deps_spec.rb +8 -14
  166. data/spec/integration/knife/upload_spec.rb +18 -0
  167. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  168. data/spec/integration/recipes/provider_choice.rb +41 -0
  169. data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
  170. data/spec/spec_helper.rb +6 -1
  171. data/spec/support/key_helpers.rb +104 -0
  172. data/spec/support/lib/chef/resource/cat.rb +1 -0
  173. data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
  174. data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
  175. data/spec/support/lib/chef/resource/zen_master.rb +2 -0
  176. data/spec/support/mock/platform.rb +1 -1
  177. data/spec/support/pedant/Gemfile.lock +67 -0
  178. data/spec/support/shared/functional/securable_resource.rb +34 -12
  179. data/spec/support/shared/integration/integration_helper.rb +6 -5
  180. data/spec/support/shared/unit/provider/file.rb +31 -8
  181. data/spec/unit/application/client_spec.rb +2 -2
  182. data/spec/unit/client_spec.rb +21 -4
  183. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
  184. data/spec/unit/cookbook/metadata_spec.rb +15 -0
  185. data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
  186. data/spec/unit/cookbook_loader_spec.rb +1 -1
  187. data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
  188. data/spec/unit/data_bag_spec.rb +1 -1
  189. data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
  190. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
  191. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
  192. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
  193. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  194. data/spec/unit/http/authenticator_spec.rb +69 -0
  195. data/spec/unit/http/basic_client_spec.rb +16 -0
  196. data/spec/unit/key_spec.rb +634 -0
  197. data/spec/unit/knife/bootstrap_spec.rb +14 -1
  198. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  199. data/spec/unit/knife/core/ui_spec.rb +1 -1
  200. data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
  201. data/spec/unit/knife/environment_from_file_spec.rb +1 -1
  202. data/spec/unit/knife/key_create_spec.rb +224 -0
  203. data/spec/unit/knife/key_delete_spec.rb +135 -0
  204. data/spec/unit/knife/key_edit_spec.rb +267 -0
  205. data/spec/unit/knife/key_helper.rb +74 -0
  206. data/spec/unit/knife/key_list_spec.rb +216 -0
  207. data/spec/unit/knife/key_show_spec.rb +126 -0
  208. data/spec/unit/knife/ssh_spec.rb +23 -26
  209. data/spec/unit/knife_spec.rb +33 -1
  210. data/spec/unit/log/syslog_spec.rb +53 -0
  211. data/spec/unit/log/winevt_spec.rb +55 -0
  212. data/spec/unit/lwrp_spec.rb +105 -51
  213. data/spec/unit/mixin/path_sanity_spec.rb +2 -2
  214. data/spec/unit/mixin/template_spec.rb +2 -2
  215. data/spec/unit/mixin/unformatter_spec.rb +61 -0
  216. data/spec/unit/mixin/uris_spec.rb +45 -0
  217. data/spec/unit/platform/query_helpers_spec.rb +1 -1
  218. data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
  219. data/spec/unit/provider/deploy/revision_spec.rb +1 -1
  220. data/spec/unit/provider/deploy_spec.rb +1 -1
  221. data/spec/unit/provider/directory_spec.rb +1 -1
  222. data/spec/unit/provider/execute_spec.rb +1 -1
  223. data/spec/unit/provider/package/aix_spec.rb +20 -8
  224. data/spec/unit/provider/package/smartos_spec.rb +50 -40
  225. data/spec/unit/provider/package/windows_spec.rb +104 -25
  226. data/spec/unit/provider/package/yum_spec.rb +111 -1
  227. data/spec/unit/provider/package_spec.rb +6 -0
  228. data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
  229. data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
  230. data/spec/unit/provider/service/aix_service_spec.rb +26 -11
  231. data/spec/unit/provider/user/dscl_spec.rb +1 -1
  232. data/spec/unit/provider_spec.rb +20 -0
  233. data/spec/unit/recipe_spec.rb +1 -1
  234. data/spec/unit/resource/batch_spec.rb +1 -0
  235. data/spec/unit/resource/powershell_spec.rb +1 -0
  236. data/spec/unit/resource/remote_file_spec.rb +10 -0
  237. data/spec/unit/resource/windows_package_spec.rb +16 -2
  238. data/spec/unit/resource_spec.rb +40 -24
  239. data/spec/unit/rest_spec.rb +10 -20
  240. data/spec/unit/role_spec.rb +1 -1
  241. data/spec/unit/run_context_spec.rb +31 -0
  242. data/spec/unit/shell_spec.rb +4 -4
  243. data/tasks/external_tests.rb +29 -0
  244. data/tasks/rspec.rb +14 -1
  245. metadata +105 -28
  246. data/spec/unit/config_spec.rb +0 -544
  247. data/spec/unit/util/path_helper_spec.rb +0 -255
@@ -18,98 +18,69 @@
18
18
 
19
19
  require 'chef/util/windows'
20
20
  require 'chef/exceptions'
21
+ require 'chef/win32/net'
22
+ require 'chef/win32/security'
21
23
 
22
24
  #wrapper around a subset of the NetUser* APIs.
23
25
  #nothing Chef specific, but not complete enough to be its own gem, so util for now.
24
26
  class Chef::Util::Windows::NetUser < Chef::Util::Windows
25
27
 
26
28
  private
27
-
28
- LogonUser = Windows::API.new('LogonUser', 'SSSLLP', 'I', 'advapi32')
29
-
30
- DOMAIN_GROUP_RID_USERS = 0x00000201
31
-
32
- UF_SCRIPT = 0x000001
33
- UF_ACCOUNTDISABLE = 0x000002
34
- UF_PASSWD_CANT_CHANGE = 0x000040
35
- UF_NORMAL_ACCOUNT = 0x000200
36
- UF_DONT_EXPIRE_PASSWD = 0x010000
37
-
38
- #[:symbol_name, default_val]
39
- #default_val duals as field type
40
- #array index duals as structure offset
41
-
42
- #OC-8391
43
- #Changing [:password, nil], to [:password, ""],
44
- #if :password is set to nil, windows user creation api ignores the password policy applied
45
- #thus initializing it with empty string value.
46
- USER_INFO_3 = [
47
- [:name, nil],
48
- [:password, ""],
49
- [:password_age, 0],
50
- [:priv, 0], #"The NetUserAdd and NetUserSetInfo functions ignore this member"
51
- [:home_dir, nil],
52
- [:comment, nil],
53
- [:flags, UF_SCRIPT|UF_DONT_EXPIRE_PASSWD|UF_NORMAL_ACCOUNT],
54
- [:script_path, nil],
55
- [:auth_flags, 0],
56
- [:full_name, nil],
57
- [:user_comment, nil],
58
- [:parms, nil],
59
- [:workstations, nil],
60
- [:last_logon, 0],
61
- [:last_logoff, 0],
62
- [:acct_expires, -1],
63
- [:max_storage, -1],
64
- [:units_per_week, 0],
65
- [:logon_hours, nil],
66
- [:bad_pw_count, 0],
67
- [:num_logons, 0],
68
- [:logon_server, nil],
69
- [:country_code, 0],
70
- [:code_page, 0],
71
- [:user_id, 0],
72
- [:primary_group_id, DOMAIN_GROUP_RID_USERS],
73
- [:profile, nil],
74
- [:home_dir_drive, nil],
75
- [:password_expired, 0]
76
- ]
77
-
78
- USER_INFO_3_TEMPLATE =
79
- USER_INFO_3.collect { |field| field[1].class == Fixnum ? 'i' : 'L' }.join
80
-
81
- SIZEOF_USER_INFO_3 = #sizeof(USER_INFO_3)
82
- USER_INFO_3.inject(0){|sum,item|
83
- sum + (item[1].class == Fixnum ? 4 : PTR_SIZE)
84
- }
85
-
86
- def user_info_3(args)
87
- USER_INFO_3.collect { |field|
88
- args.include?(field[0]) ? args[field[0]] : field[1]
89
- }
90
- end
91
-
92
- def user_info_3_pack(user)
93
- user.collect { |v|
94
- v.class == Fixnum ? v : str_to_ptr(multi_to_wide(v))
95
- }.pack(USER_INFO_3_TEMPLATE)
29
+ NetUser = Chef::ReservedNames::Win32::NetUser
30
+ Security = Chef::ReservedNames::Win32::Security
31
+
32
+ USER_INFO_3_TRANSFORM = {
33
+ name: :usri3_name,
34
+ password: :usri3_password,
35
+ password_age: :usri3_password_age,
36
+ priv: :usri3_priv,
37
+ home_dir: :usri3_home_dir,
38
+ comment: :usri3_comment,
39
+ flags: :usri3_flags,
40
+ script_path: :usri3_script_path,
41
+ auth_flags: :usri3_auth_flags,
42
+ full_name: :usri3_full_name,
43
+ user_comment: :usri3_usr_comment,
44
+ parms: :usri3_parms,
45
+ workstations: :usri3_workstations,
46
+ last_logon: :usri3_last_logon,
47
+ last_logoff: :usri3_last_logoff,
48
+ acct_expires: :usri3_acct_expires,
49
+ max_storage: :usri3_max_storage,
50
+ units_per_week: :usri3_units_per_week,
51
+ logon_hours: :usri3_logon_hours,
52
+ bad_pw_count: :usri3_bad_pw_count,
53
+ num_logons: :usri3_num_logons,
54
+ logon_server: :usri3_logon_server,
55
+ country_code: :usri3_country_code,
56
+ code_page: :usri3_code_page,
57
+ user_id: :usri3_user_id,
58
+ primary_group_id: :usri3_primary_group_id,
59
+ profile: :usri3_profile,
60
+ home_dir_drive: :usri3_home_dir_drive,
61
+ password_expired: :usri3_password_expired,
62
+ }
63
+
64
+ def transform_usri3(args)
65
+ args.inject({}) do |memo, (k,v)|
66
+ memo[USER_INFO_3_TRANSFORM[k]] = v
67
+ memo
68
+ end
96
69
  end
97
70
 
98
- def user_info_3_unpack(buffer)
99
- user = Hash.new
100
- USER_INFO_3.each_with_index do |field,offset|
101
- user[field[0]] = field[1].class == Fixnum ?
102
- dword_to_i(buffer, offset) : lpwstr_to_s(buffer, offset)
71
+ def usri3_to_hash(usri3)
72
+ t = USER_INFO_3_TRANSFORM.invert
73
+ usri3.inject({}) do |memo, (k,v)|
74
+ memo[t[k]] = v
75
+ memo
103
76
  end
104
- user
105
77
  end
106
78
 
107
79
  def set_info(args)
108
- user = user_info_3(args)
109
- buffer = user_info_3_pack(user)
110
- rc = NetUserSetInfo.call(nil, @name, 3, buffer, nil)
111
- if rc != NERR_Success
112
- raise ArgumentError, get_last_error(rc)
80
+ begin
81
+ rc = NetUser::net_user_set_info_l3(nil, @username, transform_usri3(args))
82
+ rescue Chef::Exceptions::Win32APIError => e
83
+ raise ArgumentError, e
113
84
  end
114
85
  end
115
86
 
@@ -120,49 +91,32 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
120
91
  @name = multi_to_wide(username)
121
92
  end
122
93
 
123
- LOGON32_PROVIDER_DEFAULT = 0
124
- LOGON32_LOGON_NETWORK = 3
94
+ LOGON32_PROVIDER_DEFAULT = Security::LOGON32_PROVIDER_DEFAULT
95
+ LOGON32_LOGON_NETWORK = Security::LOGON32_LOGON_NETWORK
125
96
  #XXX for an extra painful alternative, see: http://support.microsoft.com/kb/180548
126
97
  def validate_credentials(passwd)
127
- token = 0.chr * PTR_SIZE
128
- res = LogonUser.call(@username, nil, passwd,
129
- LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, token)
130
- if res == 0
98
+ begin
99
+ token = Security::logon_user(@username, nil, passwd,
100
+ LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT)
101
+ return true
102
+ rescue Chef::Exceptions::Win32APIError
131
103
  return false
132
104
  end
133
- ::Windows::Handle::CloseHandle.call(token.unpack('L')[0])
134
- return true
135
105
  end
136
106
 
137
107
  def get_info
138
- ptr = 0.chr * PTR_SIZE
139
- rc = NetUserGetInfo.call(nil, @name, 3, ptr)
140
-
141
- if rc == NERR_UserNotFound
142
- raise Chef::Exceptions::UserIDNotFound, get_last_error(rc)
143
- elsif rc != NERR_Success
144
- raise ArgumentError, get_last_error(rc)
108
+ begin
109
+ ui3 = NetUser::net_user_get_info_l3(nil, @username)
110
+ rescue Chef::Exceptions::Win32APIError => e
111
+ raise ArgumentError, e
145
112
  end
146
-
147
- ptr = ptr.unpack('L')[0]
148
- buffer = 0.chr * SIZEOF_USER_INFO_3
149
- memcpy(buffer, ptr, buffer.size)
150
- NetApiBufferFree(ptr)
151
- user_info_3_unpack(buffer)
113
+ usri3_to_hash(ui3)
152
114
  end
153
115
 
154
116
  def add(args)
155
- user = user_info_3(args)
156
- buffer = user_info_3_pack(user)
157
-
158
- rc = NetUserAdd.call(nil, 3, buffer, rc)
159
- if rc != NERR_Success
160
- raise ArgumentError, get_last_error(rc)
161
- end
162
-
163
- #usri3_primary_group_id:
164
- #"When you call the NetUserAdd function, this member must be DOMAIN_GROUP_RID_USERS"
165
- NetLocalGroupAddMembers(nil, multi_to_wide("Users"), 3, buffer[0,PTR_SIZE], 1)
117
+ transformed_args = transform_usri3(args)
118
+ NetUser::net_user_add_l3(nil, transformed_args)
119
+ NetUser::net_local_group_add_member(nil, "Users", args[:name])
166
120
  end
167
121
 
168
122
  def user_modify(&proc)
@@ -182,15 +136,16 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
182
136
  end
183
137
 
184
138
  def delete
185
- rc = NetUserDel.call(nil, @name)
186
- if rc != NERR_Success
187
- raise ArgumentError, get_last_error(rc)
139
+ begin
140
+ NetUser::net_user_del(nil, @username)
141
+ rescue Chef::Exceptions::Win32APIError => e
142
+ raise ArgumentError, e
188
143
  end
189
144
  end
190
145
 
191
146
  def disable_account
192
147
  user_modify do |user|
193
- user[:flags] |= UF_ACCOUNTDISABLE
148
+ user[:flags] |= NetUser::UF_ACCOUNTDISABLE
194
149
  #This does not set the password to nil. It (for some reason) means to ignore updating the field.
195
150
  #See similar behavior for the logon_hours field documented at
196
151
  #http://msdn.microsoft.com/en-us/library/windows/desktop/aa371338%28v=vs.85%29.aspx
@@ -200,7 +155,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
200
155
 
201
156
  def enable_account
202
157
  user_modify do |user|
203
- user[:flags] &= ~UF_ACCOUNTDISABLE
158
+ user[:flags] &= ~NetUser::UF_ACCOUNTDISABLE
204
159
  #This does not set the password to nil. It (for some reason) means to ignore updating the field.
205
160
  #See similar behavior for the logon_hours field documented at
206
161
  #http://msdn.microsoft.com/en-us/library/windows/desktop/aa371338%28v=vs.85%29.aspx
@@ -209,6 +164,6 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
209
164
  end
210
165
 
211
166
  def check_enabled
212
- (get_info()[:flags] & UF_ACCOUNTDISABLE) != 0
167
+ (get_info()[:flags] & NetUser::UF_ACCOUNTDISABLE) != 0
213
168
  end
214
169
  end
@@ -1,6 +1,4 @@
1
-
2
- # Author:: Daniel DeLeo (<dan@opscode.com>)
3
- # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
1
+ # Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
4
2
  # License:: Apache License, Version 2.0
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,9 +13,15 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
 
16
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17
+ # NOTE: This file is generated by running `rake version` in the top level of
18
+ # this repo. Do not edit this manually. Edit the VERSION file and run the rake
19
+ # task instead.
20
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21
+
18
22
  class Chef
19
23
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '12.3.0'
24
+ VERSION = '12.4.0.rc.0'
21
25
  end
22
26
 
23
27
  #
@@ -67,7 +67,7 @@ class Chef
67
67
  # BaseTsd.h: #ifdef (_WIN64) host.typedef int HALF_PTR; #else host.typedef short HALF_PTR;
68
68
  host.typedef :ulong, :HACCEL # (L) Handle to an accelerator table. WinDef.h: #host.typedef HANDLE HACCEL;
69
69
  # See http://msdn.microsoft.com/en-us/library/ms645526%28VS.85%29.aspx
70
- host.typedef :ulong, :HANDLE # (L) Handle to an object. WinNT.h: #host.typedef PVOID HANDLE;
70
+ host.typedef :size_t, :HANDLE # (L) Handle to an object. WinNT.h: #host.typedef PVOID HANDLE;
71
71
  # todo: Platform-dependent! Need to change to :uint64 for Win64
72
72
  host.typedef :ulong, :HBITMAP # (L) Handle to a bitmap: http://msdn.microsoft.com/en-us/library/dd183377%28VS.85%29.aspx
73
73
  host.typedef :ulong, :HBRUSH # (L) Handle to a brush. http://msdn.microsoft.com/en-us/library/dd183394%28VS.85%29.aspx
@@ -117,6 +117,7 @@ class Chef
117
117
  host.typedef :uint32, :LCID # Locale identifier. For more information, see Locales.
118
118
  host.typedef :uint32, :LCTYPE # Locale information type. For a list, see Locale Information Constants.
119
119
  host.typedef :uint32, :LGRPID # Language group identifier. For a list, see EnumLanguageGroupLocales.
120
+ host.typedef :pointer, :LMSTR # Pointer to null termiated string of unicode characters
120
121
  host.typedef :long, :LONG # 32-bit signed integer. The range is -2,147,483,648 through +...647 decimal.
121
122
  host.typedef :int32, :LONG32 # 32-bit signed integer. The range is -2,147,483,648 through +...647 decimal.
122
123
  host.typedef :int64, :LONG64 # 64-bit signed integer. The range is –9,223,372,036,854,775,808 through +...807
@@ -158,7 +158,7 @@ UINT MsiCloseHandle(
158
158
  raise Chef::Exceptions::Package, msg
159
159
  end
160
160
 
161
- version
161
+ version.chomp(0.chr)
162
162
  end
163
163
  end
164
164
  end
@@ -32,8 +32,24 @@ class Chef
32
32
 
33
33
  MAX_PREFERRED_LENGTH = 0xFFFF
34
34
 
35
- NERR_Success = 0
36
- NERR_UserNotFound = 2221
35
+ DOMAIN_GROUP_RID_USERS = 0x00000201
36
+
37
+ UF_SCRIPT = 0x000001
38
+ UF_ACCOUNTDISABLE = 0x000002
39
+ UF_PASSWD_CANT_CHANGE = 0x000040
40
+ UF_NORMAL_ACCOUNT = 0x000200
41
+ UF_DONT_EXPIRE_PASSWD = 0x010000
42
+
43
+ NERR_Success = 0
44
+ NERR_InvalidComputer = 2351
45
+ NERR_NotPrimary = 2226
46
+ NERR_SpeGroupOp = 2234
47
+ NERR_LastAdmin = 2452
48
+ NERR_BadUsername = 2202
49
+ NERR_BadPassword = 2203
50
+ NERR_PasswordTooShort = 2245
51
+ NERR_UserNotFound = 2221
52
+ ERROR_ACCESS_DENIED = 5
37
53
 
38
54
  ffi_lib "netapi32"
39
55
 
@@ -67,6 +83,57 @@ class Chef
67
83
  :usri3_profile, :LPWSTR,
68
84
  :usri3_home_dir_drive, :LPWSTR,
69
85
  :usri3_password_expired, :DWORD
86
+
87
+ def set(key, val)
88
+ val = if val.is_a? String
89
+ encoded = if val.encoding == Encoding::UTF_16LE
90
+ val
91
+ else
92
+ val.to_wstring
93
+ end
94
+ FFI::MemoryPointer.from_string(encoded)
95
+ else
96
+ val
97
+ end
98
+ self[key] = val
99
+ end
100
+
101
+ def get(key)
102
+ if respond_to? key
103
+ send(key)
104
+ else
105
+ val = self[key]
106
+ if val.is_a? FFI::Pointer
107
+ if val.null?
108
+ nil
109
+ else
110
+ val.read_wstring
111
+ end
112
+ else
113
+ val
114
+ end
115
+ end
116
+ end
117
+
118
+ def usri3_logon_hours
119
+ val = self[:usri3_logon_hours]
120
+ if !val.nil? && !val.null?
121
+ val.read_bytes(21)
122
+ else
123
+ nil
124
+ end
125
+ end
126
+
127
+ def as_ruby
128
+ members.inject({}) do |memo, key|
129
+ memo[key] = get(key)
130
+ memo
131
+ end
132
+ end
133
+ end
134
+
135
+ class LOCALGROUP_MEMBERS_INFO_3 < FFI::Struct
136
+ layout :lgrmi3_domainandname, :LPWSTR
70
137
  end
71
138
 
72
139
  # NET_API_STATUS NetUserEnum(
@@ -85,6 +152,52 @@ class Chef
85
152
  # _In_ LPVOID Buffer
86
153
  # );
87
154
  safe_attach_function :NetApiBufferFree, [ :LPVOID ], :DWORD
155
+
156
+ #NET_API_STATUS NetUserAdd(
157
+ #_In_ LMSTR servername,
158
+ #_In_ DWORD level,
159
+ #_In_ LPBYTE buf,
160
+ #_Out_ LPDWORD parm_err
161
+ #);
162
+ safe_attach_function :NetUserAdd, [:LMSTR, :DWORD, :LPBYTE, :LPDWORD ], :DWORD
163
+
164
+ #NET_API_STATUS NetLocalGroupAddMembers(
165
+ # _In_ LPCWSTR servername,
166
+ # _In_ LPCWSTR groupname,
167
+ # _In_ DWORD level,
168
+ # _In_ LPBYTE buf,
169
+ # _In_ DWORD totalentries
170
+ #);
171
+ safe_attach_function :NetLocalGroupAddMembers, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD ], :DWORD
172
+
173
+ #NET_API_STATUS NetUserGetInfo(
174
+ # _In_ LPCWSTR servername,
175
+ # _In_ LPCWSTR username,
176
+ # _In_ DWORD level,
177
+ # _Out_ LPBYTE *bufptr
178
+ #);
179
+ safe_attach_function :NetUserGetInfo, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE], :DWORD
180
+
181
+ #NET_API_STATUS NetApiBufferFree(
182
+ # _In_ LPVOID Buffer
183
+ #);
184
+ safe_attach_function :NetApiBufferFree, [:LPVOID], :DWORD
185
+
186
+ #NET_API_STATUS NetUserSetInfo(
187
+ # _In_ LPCWSTR servername,
188
+ # _In_ LPCWSTR username,
189
+ # _In_ DWORD level,
190
+ # _In_ LPBYTE buf,
191
+ # _Out_ LPDWORD parm_err
192
+ #);
193
+ safe_attach_function :NetUserSetInfo, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD], :DWORD
194
+
195
+ #NET_API_STATUS NetUserDel(
196
+ # _In_ LPCWSTR servername,
197
+ # _In_ LPCWSTR username
198
+ #);
199
+ safe_attach_function :NetUserDel, [:LPCWSTR, :LPCWSTR], :DWORD
200
+
88
201
  end
89
202
  end
90
203
  end
@@ -193,6 +193,20 @@ class Chef
193
193
 
194
194
  MAXDWORD = 0xffffffff
195
195
 
196
+ # LOGON32 constants for LogonUser
197
+ LOGON32_LOGON_INTERACTIVE = 2;
198
+ LOGON32_LOGON_NETWORK = 3;
199
+ LOGON32_LOGON_BATCH = 4;
200
+ LOGON32_LOGON_SERVICE = 5;
201
+ LOGON32_LOGON_UNLOCK = 7;
202
+ LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
203
+ LOGON32_LOGON_NEW_CREDENTIALS = 9;
204
+
205
+ LOGON32_PROVIDER_DEFAULT = 0;
206
+ LOGON32_PROVIDER_WINNT35 = 1;
207
+ LOGON32_PROVIDER_WINNT40 = 2;
208
+ LOGON32_PROVIDER_WINNT50 = 3;
209
+
196
210
  ###############################################
197
211
  # Win32 API Bindings
198
212
  ###############################################
@@ -270,6 +284,14 @@ class Chef
270
284
  :MaxTokenInfoClass
271
285
  ]
272
286
 
287
+ class TOKEN_OWNER < FFI::Struct
288
+ layout :Owner, :pointer
289
+ end
290
+
291
+ class TOKEN_PRIMARY_GROUP < FFI::Struct
292
+ layout :PrimaryGroup, :pointer
293
+ end
294
+
273
295
  # https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572%28v=vs.85%29.aspx
274
296
  SECURITY_IMPERSONATION_LEVEL = enum :SECURITY_IMPERSONATION_LEVEL, [
275
297
  :SecurityAnonymous,
@@ -405,6 +427,8 @@ class Chef
405
427
  safe_attach_function :SetSecurityDescriptorOwner, [ :pointer, :pointer, :BOOL ], :BOOL
406
428
  safe_attach_function :SetSecurityDescriptorSacl, [ :pointer, :BOOL, :pointer, :BOOL ], :BOOL
407
429
  safe_attach_function :GetTokenInformation, [ :HANDLE, :TOKEN_INFORMATION_CLASS, :pointer, :DWORD, :PDWORD ], :BOOL
430
+ safe_attach_function :LogonUserW, [:LPTSTR, :LPTSTR, :LPTSTR, :DWORD, :DWORD, :PHANDLE], :BOOL
431
+
408
432
  end
409
433
  end
410
434
  end