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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +21 -25
- data/Gemfile +46 -0
- data/README.md +4 -4
- data/Rakefile +5 -110
- data/distro/common/html/knife_cookbook_site.html +18 -18
- data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/apply.rb +19 -1
- data/lib/chef/application/client.rb +11 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/windows_service_manager.rb +9 -7
- data/lib/chef/chef_class.rb +39 -0
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
- data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
- data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
- data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
- data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
- data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
- data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
- data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
- data/lib/chef/client.rb +2 -3
- data/lib/chef/config.rb +34 -2
- data/lib/chef/cookbook/metadata.rb +25 -3
- data/lib/chef/cookbook/synchronizer.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/deprecation/mixin/template.rb +1 -2
- data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
- data/lib/chef/deprecation/provider/file.rb +1 -1
- data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
- data/lib/chef/deprecation/provider/remote_file.rb +1 -2
- data/lib/chef/deprecation/provider/template.rb +1 -1
- data/lib/chef/deprecation/warnings.rb +3 -4
- data/lib/chef/dsl/reboot_pending.rb +3 -2
- data/lib/chef/dsl/recipe.rb +6 -5
- data/lib/chef/dsl/resources.rb +2 -2
- data/lib/chef/event_dispatch/base.rb +12 -7
- data/lib/chef/event_dispatch/dispatcher.rb +21 -6
- data/lib/chef/exceptions.rb +22 -0
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/base.rb +3 -0
- data/lib/chef/formatters/doc.rb +53 -5
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
- data/lib/chef/formatters/minimal.rb +2 -2
- data/lib/chef/knife.rb +35 -55
- data/lib/chef/knife/bootstrap.rb +41 -0
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
- data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
- data/lib/chef/knife/bootstrap/templates/README.md +3 -4
- data/lib/chef/knife/cookbook_create.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +6 -6
- data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
- data/lib/chef/knife/core/bootstrap_context.rb +12 -4
- data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
- data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
- data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
- data/lib/chef/knife/core/node_presenter.rb +24 -1
- data/lib/chef/knife/core/object_loader.rb +1 -0
- data/lib/chef/knife/core/subcommand_loader.rb +131 -146
- data/lib/chef/knife/node_run_list_remove.rb +12 -1
- data/lib/chef/knife/null.rb +10 -0
- data/lib/chef/knife/rehash.rb +62 -0
- data/lib/chef/knife/search.rb +3 -3
- data/lib/chef/knife/ssh.rb +52 -30
- data/lib/chef/local_mode.rb +5 -0
- data/lib/chef/log.rb +5 -1
- data/lib/chef/mixin/deprecation.rb +8 -8
- data/lib/chef/mixin/params_validate.rb +2 -2
- data/lib/chef/mixin/template.rb +48 -0
- data/lib/chef/mixin/which.rb +1 -1
- data/lib/chef/mixin/wide_string.rb +72 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
- data/lib/chef/mixin/windows_env_helper.rb +4 -1
- data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
- data/lib/chef/monkey_patches/win32/registry.rb +72 -0
- data/lib/chef/node.rb +97 -3
- data/lib/chef/node_map.rb +2 -2
- data/lib/chef/platform/provider_mapping.rb +5 -6
- data/lib/chef/platform/query_helpers.rb +46 -4
- data/lib/chef/platform/service_helpers.rb +30 -32
- data/lib/chef/policy_builder.rb +1 -8
- data/lib/chef/policy_builder/dynamic.rb +186 -0
- data/lib/chef/policy_builder/expand_node_object.rb +30 -15
- data/lib/chef/policy_builder/policyfile.rb +155 -18
- data/lib/chef/property.rb +38 -9
- data/lib/chef/provider.rb +104 -12
- data/lib/chef/provider/batch.rb +8 -0
- data/lib/chef/provider/deploy.rb +2 -2
- data/lib/chef/provider/directory.rb +14 -2
- data/lib/chef/provider/dsc_resource.rb +5 -9
- data/lib/chef/provider/group/pw.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -2
- data/lib/chef/provider/mount.rb +7 -3
- data/lib/chef/provider/package/dpkg.rb +5 -11
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/yum.rb +17 -5
- data/lib/chef/provider/powershell_script.rb +27 -4
- data/lib/chef/provider/remote_directory.rb +190 -102
- data/lib/chef/provider/service.rb +12 -2
- data/lib/chef/provider/service/aix.rb +1 -1
- data/lib/chef/provider/service/debian.rb +3 -5
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +3 -3
- data/lib/chef/provider/service/init.rb +3 -3
- data/lib/chef/provider/service/insserv.rb +2 -4
- data/lib/chef/provider/service/invokercd.rb +2 -4
- data/lib/chef/provider/service/openbsd.rb +2 -1
- data/lib/chef/provider/service/redhat.rb +52 -16
- data/lib/chef/provider/service/simple.rb +2 -2
- data/lib/chef/provider/service/systemd.rb +3 -5
- data/lib/chef/provider/service/upstart.rb +4 -6
- data/lib/chef/provider/subversion.rb +13 -7
- data/lib/chef/provider/template/content.rb +16 -6
- data/lib/chef/provider/user/solaris.rb +32 -4
- data/lib/chef/provider/windows_script.rb +3 -5
- data/lib/chef/provider_resolver.rb +2 -2
- data/lib/chef/resource.rb +85 -27
- data/lib/chef/resource/action_class.rb +83 -0
- data/lib/chef/resource/chef_gem.rb +3 -3
- data/lib/chef/resource/deploy.rb +8 -2
- data/lib/chef/resource/dsc_script.rb +2 -0
- data/lib/chef/resource/file/verification.rb +1 -1
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/service.rb +10 -2
- data/lib/chef/resource/subversion.rb +5 -0
- data/lib/chef/resource/windows_script.rb +6 -2
- data/lib/chef/resource/yum_package.rb +10 -1
- data/lib/chef/resource_resolver.rb +3 -3
- data/lib/chef/run_context.rb +6 -8
- data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
- data/lib/chef/run_lock.rb +30 -21
- data/lib/chef/util/powershell/ps_credential.rb +4 -0
- data/lib/chef/util/windows.rb +0 -32
- data/lib/chef/util/windows/net_group.rb +85 -106
- data/lib/chef/util/windows/net_use.rb +35 -71
- data/lib/chef/util/windows/net_user.rb +0 -1
- data/lib/chef/util/windows/volume.rb +19 -19
- data/lib/chef/version.rb +3 -3
- data/lib/chef/win32/api.rb +1 -0
- data/lib/chef/win32/api/file.rb +20 -0
- data/lib/chef/win32/api/net.rb +163 -43
- data/lib/chef/win32/api/registry.rb +51 -0
- data/lib/chef/win32/api/system.rb +23 -0
- data/lib/chef/win32/api/unicode.rb +0 -43
- data/lib/chef/win32/crypto.rb +2 -1
- data/lib/chef/win32/file.rb +28 -3
- data/lib/chef/win32/mutex.rb +1 -2
- data/lib/chef/win32/net.rb +162 -8
- data/lib/chef/win32/process.rb +13 -0
- data/lib/chef/win32/registry.rb +25 -28
- data/lib/chef/win32/security.rb +1 -1
- data/lib/chef/win32/security/token.rb +1 -1
- data/lib/chef/win32/system.rb +62 -0
- data/lib/chef/win32/unicode.rb +7 -2
- data/lib/chef/win32/version.rb +0 -4
- data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
- data/spec/data/dsc_lcm.pfx +0 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
- data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
- data/spec/functional/knife/ssh_spec.rb +16 -0
- data/spec/functional/resource/deploy_revision_spec.rb +1 -1
- data/spec/functional/resource/dsc_resource_spec.rb +2 -0
- data/spec/functional/resource/dsc_script_spec.rb +91 -2
- data/spec/functional/resource/group_spec.rb +67 -44
- data/spec/functional/resource/powershell_script_spec.rb +104 -15
- data/spec/functional/resource/windows_service_spec.rb +1 -1
- data/spec/functional/run_lock_spec.rb +368 -189
- data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
- data/spec/integration/client/client_spec.rb +51 -0
- data/spec/integration/knife/download_spec.rb +4 -0
- data/spec/integration/knife/list_spec.rb +8 -0
- data/spec/integration/knife/upload_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/remote_directory.rb +74 -0
- data/spec/integration/recipes/resource_action_spec.rb +42 -22
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
- data/spec/integration/recipes/resource_load_spec.rb +206 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/platform_helpers.rb +13 -0
- data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
- data/spec/support/shared/functional/windows_script.rb +63 -26
- data/spec/support/shared/unit/mock_shellout.rb +46 -0
- data/spec/support/shared/unit/provider/file.rb +10 -4
- data/spec/unit/application/client_spec.rb +16 -3
- data/spec/unit/application/knife_spec.rb +2 -2
- data/spec/unit/chef_class_spec.rb +0 -4
- data/spec/unit/client_spec.rb +6 -1
- data/spec/unit/config_spec.rb +31 -0
- data/spec/unit/cookbook/metadata_spec.rb +23 -3
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/deprecation_spec.rb +3 -6
- data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
- data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
- data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
- data/spec/unit/formatters/doc_spec.rb +32 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
- data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -3
- data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
- data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
- data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
- data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
- data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
- data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
- data/spec/unit/mixin/template_spec.rb +5 -1
- data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
- data/spec/unit/node_spec.rb +213 -0
- data/spec/unit/platform/query_helpers_spec.rb +146 -3
- data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
- data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
- data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
- data/spec/unit/property/validation_spec.rb +5 -0
- data/spec/unit/property_spec.rb +152 -26
- data/spec/unit/provider/deploy_spec.rb +5 -5
- data/spec/unit/provider/directory_spec.rb +35 -0
- data/spec/unit/provider/dsc_resource_spec.rb +3 -10
- data/spec/unit/provider/ifconfig_spec.rb +22 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -1
- data/spec/unit/provider/mount/mount_spec.rb +6 -0
- data/spec/unit/provider/mount/windows_spec.rb +14 -0
- data/spec/unit/provider/mount_spec.rb +12 -1
- data/spec/unit/provider/package/dpkg_spec.rb +8 -1
- data/spec/unit/provider/package/rpm_spec.rb +18 -1
- data/spec/unit/provider/package/rubygems_spec.rb +18 -0
- data/spec/unit/provider/package/yum_spec.rb +97 -24
- data/spec/unit/provider/powershell_script_spec.rb +52 -26
- data/spec/unit/provider/remote_directory_spec.rb +1 -2
- data/spec/unit/provider/service/aix_service_spec.rb +3 -3
- data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
- data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
- data/spec/unit/provider/service/redhat_spec.rb +88 -8
- data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
- data/spec/unit/provider/service/windows_spec.rb +211 -200
- data/spec/unit/provider/subversion_spec.rb +50 -31
- data/spec/unit/provider/template/content_spec.rb +93 -2
- data/spec/unit/provider/user/solaris_spec.rb +66 -9
- data/spec/unit/provider_resolver_spec.rb +707 -650
- data/spec/unit/resource/deploy_spec.rb +7 -1
- data/spec/unit/resource/dsc_script_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +1 -1
- data/spec/unit/resource/powershell_script_spec.rb +17 -13
- data/spec/unit/resource/service_spec.rb +4 -4
- data/spec/unit/resource/subversion_spec.rb +4 -0
- data/spec/unit/resource/yum_package_spec.rb +10 -1
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
- data/spec/unit/win32/registry_spec.rb +394 -0
- data/tasks/external_tests.rb +47 -23
- data/tasks/maintainers.rb +155 -14
- metadata +51 -26
- data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
- data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
- data/spec/unit/registry_helper_spec.rb +0 -390
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Salim Alam (<salam@chef.io>)
|
3
|
+
# Copyright:: Copyright 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/win32/api'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
module ReservedNames::Win32
|
23
|
+
module API
|
24
|
+
module Registry
|
25
|
+
extend Chef::ReservedNames::Win32::API
|
26
|
+
|
27
|
+
###############################################
|
28
|
+
# Win32 API Bindings
|
29
|
+
###############################################
|
30
|
+
|
31
|
+
ffi_lib 'advapi32'
|
32
|
+
|
33
|
+
# LONG WINAPI RegDeleteKeyEx(
|
34
|
+
# _In_ HKEY hKey,
|
35
|
+
# _In_ LPCTSTR lpSubKey,
|
36
|
+
# _In_ REGSAM samDesired,
|
37
|
+
# _Reserved_ DWORD Reserved
|
38
|
+
# );
|
39
|
+
safe_attach_function :RegDeleteKeyExW, [ :HKEY, :LPCTSTR, :LONG, :DWORD ], :LONG
|
40
|
+
safe_attach_function :RegDeleteKeyExA, [ :HKEY, :LPCTSTR, :LONG, :DWORD ], :LONG
|
41
|
+
|
42
|
+
# LONG WINAPI RegDeleteValue(
|
43
|
+
# _In_ HKEY hKey,
|
44
|
+
# _In_opt_ LPCTSTR lpValueName
|
45
|
+
# );
|
46
|
+
safe_attach_function :RegDeleteValueW, [ :HKEY, :LPCTSTR ], :LONG
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -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
|
data/lib/chef/win32/crypto.rb
CHANGED
@@ -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,
|
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])
|
data/lib/chef/win32/file.rb
CHANGED
@@ -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
|
data/lib/chef/win32/mutex.rb
CHANGED
data/lib/chef/win32/net.rb
CHANGED
@@ -18,11 +18,11 @@
|
|
18
18
|
|
19
19
|
require 'chef/win32/api/net'
|
20
20
|
require 'chef/win32/error'
|
21
|
-
require 'chef/mixin/
|
21
|
+
require 'chef/mixin/wide_string'
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
module ReservedNames::Win32
|
25
|
-
class
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
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
|
data/lib/chef/win32/process.rb
CHANGED
@@ -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)
|