chef 0.10.8 → 0.10.10.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/arch/etc/rc.d/chef-client +15 -1
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +6 -10
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +4 -4
- data/distro/common/html/knife-cookbook-site.1.html +6 -6
- data/distro/common/html/knife-cookbook.1.html +4 -4
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +4 -4
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +4 -4
- data/distro/common/html/knife-ssh.1.html +5 -6
- data/distro/common/html/knife-status.1.html +4 -4
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +7 -8
- data/distro/common/html/shef.1.html +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +4 -4
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +2 -2
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +3 -7
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +5 -9
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
- data/distro/common/markdown/man1/knife-node.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
- data/distro/common/markdown/man1/knife.mkd +7 -9
- data/distro/debian/etc/init.d/chef-client +22 -1
- data/distro/redhat/etc/init.d/chef-client +12 -1
- data/distro/windows/service_manager.rb +164 -0
- data/lib/chef/application.rb +12 -6
- data/lib/chef/application/client.rb +4 -3
- data/lib/chef/application/knife.rb +7 -12
- data/lib/chef/application/solo.rb +2 -1
- data/lib/chef/application/windows_service.rb +224 -0
- data/lib/chef/checksum_cache.rb +1 -0
- data/lib/chef/client.rb +3 -16
- data/lib/chef/config.rb +42 -13
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_version.rb +5 -0
- data/lib/chef/daemon.rb +1 -1
- data/lib/chef/exceptions.rb +7 -1
- data/lib/chef/file_access_control.rb +13 -87
- data/lib/chef/file_access_control/unix.rb +119 -0
- data/lib/chef/file_access_control/windows.rb +257 -0
- data/lib/chef/handler/json_file.rb +7 -1
- data/lib/chef/knife.rb +10 -16
- data/lib/chef/knife/bootstrap.rb +15 -8
- data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
- data/lib/chef/knife/configure.rb +2 -2
- data/lib/chef/knife/cookbook_site_download.rb +60 -21
- data/lib/chef/knife/cookbook_site_install.rb +16 -21
- data/lib/chef/knife/cookbook_upload.rb +77 -48
- data/lib/chef/knife/core/bootstrap_context.rb +3 -1
- data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
- data/lib/chef/knife/core/node_editor.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/core/ui.rb +3 -2
- data/lib/chef/knife/help_topics.rb +1 -1
- data/lib/chef/knife/node_run_list_add.rb +14 -6
- data/lib/chef/knife/node_run_list_remove.rb +3 -3
- data/lib/chef/knife/ssh.rb +32 -13
- data/lib/chef/mash.rb +14 -0
- data/lib/chef/mixin/command.rb +1 -0
- data/lib/chef/mixin/command/unix.rb +5 -0
- data/lib/chef/mixin/convert_to_class_name.rb +2 -0
- data/lib/chef/mixin/deep_merge.rb +40 -18
- data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
- data/lib/chef/mixin/language.rb +89 -3
- data/lib/chef/mixin/language_include_recipe.rb +8 -4
- data/lib/chef/mixin/path_sanity.rb +67 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
- data/lib/chef/mixin/securable.rb +152 -0
- data/lib/chef/mixin/shell_out.rb +1 -1
- data/lib/chef/mixin/template.rb +8 -3
- data/lib/chef/mixins.rb +3 -0
- data/lib/chef/monkey_patches/moneta.rb +50 -0
- data/lib/chef/monkey_patches/string.rb +1 -1
- data/lib/chef/node.rb +2 -1
- data/lib/chef/platform.rb +34 -0
- data/lib/chef/provider.rb +23 -21
- data/lib/chef/provider/cron.rb +17 -12
- data/lib/chef/provider/cron/solaris.rb +6 -18
- data/lib/chef/provider/deploy.rb +14 -15
- data/lib/chef/provider/deploy/timestamped.rb +0 -1
- data/lib/chef/provider/directory.rb +1 -3
- data/lib/chef/provider/execute.rb +2 -2
- data/lib/chef/provider/file.rb +1 -75
- data/lib/chef/provider/git.rb +11 -9
- data/lib/chef/provider/group/gpasswd.rb +14 -9
- data/lib/chef/provider/link.rb +28 -59
- data/lib/chef/provider/mdadm.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package.rb +10 -6
- data/lib/chef/provider/package/apt.rb +3 -1
- data/lib/chef/provider/package/dpkg.rb +1 -1
- data/lib/chef/provider/package/portage.rb +6 -3
- data/lib/chef/provider/package/rubygems.rb +75 -6
- data/lib/chef/provider/package/smartos.rb +84 -0
- data/lib/chef/provider/package/yum-dump.py +3 -2
- data/lib/chef/provider/package/yum.rb +51 -10
- data/lib/chef/provider/remote_directory.rb +24 -3
- data/lib/chef/provider/remote_file.rb +0 -6
- data/lib/chef/provider/route.rb +3 -3
- data/lib/chef/provider/service/debian.rb +2 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/macosx.rb +125 -0
- data/lib/chef/provider/service/windows.rb +5 -1
- data/lib/chef/provider/subversion.rb +10 -7
- data/lib/chef/providers.rb +3 -0
- data/lib/chef/resource.rb +181 -87
- data/lib/chef/resource/apt_package.rb +10 -1
- data/lib/chef/resource/chef_gem.rb +53 -0
- data/lib/chef/resource/conditional.rb +3 -0
- data/lib/chef/resource/cookbook_file.rb +12 -6
- data/lib/chef/resource/cron.rb +9 -0
- data/lib/chef/resource/directory.rb +14 -31
- data/lib/chef/resource/execute.rb +11 -9
- data/lib/chef/resource/file.rb +9 -33
- data/lib/chef/resource/link.rb +13 -8
- data/lib/chef/resource/mdadm.rb +10 -1
- data/lib/chef/resource/remote_directory.rb +13 -2
- data/lib/chef/resource/remote_file.rb +14 -7
- data/lib/chef/resource/smartos_package.rb +36 -0
- data/lib/chef/resource/template.rb +12 -5
- data/lib/chef/resource_platform_map.rb +153 -0
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +55 -10
- data/lib/chef/rest/auth_credentials.rb +1 -0
- data/lib/chef/rest/rest_request.rb +24 -8
- data/lib/chef/role.rb +8 -2
- data/lib/chef/run_list.rb +1 -1
- data/lib/chef/run_list/run_list_expansion.rb +2 -2
- data/lib/chef/run_list/run_list_item.rb +7 -0
- data/lib/chef/runner.rb +4 -0
- data/lib/chef/shef.rb +2 -2
- data/lib/chef/shef/shef_session.rb +4 -5
- data/lib/chef/shell_out.rb +2 -245
- data/lib/chef/util/file_edit.rb +99 -89
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +349 -0
- data/lib/chef/win32/api/error.rb +921 -0
- data/lib/chef/win32/api/file.rb +289 -0
- data/lib/chef/win32/api/memory.rb +105 -0
- data/lib/chef/win32/api/process.rb +40 -0
- data/lib/chef/win32/api/psapi.rb +51 -0
- data/lib/chef/win32/api/security.rb +341 -0
- data/lib/chef/win32/api/system.rb +192 -0
- data/lib/chef/win32/api/unicode.rb +178 -0
- data/lib/chef/win32/error.rb +73 -0
- data/lib/chef/win32/file.rb +117 -0
- data/lib/chef/win32/file/info.rb +100 -0
- data/lib/chef/win32/handle.rb +48 -0
- data/lib/chef/win32/memory.rb +101 -0
- data/lib/chef/win32/process.rb +84 -0
- data/lib/chef/win32/security.rb +489 -0
- data/lib/chef/win32/security/ace.rb +125 -0
- data/lib/chef/win32/security/acl.rb +101 -0
- data/lib/chef/win32/security/securable_object.rb +109 -0
- data/lib/chef/win32/security/security_descriptor.rb +93 -0
- data/lib/chef/win32/security/sid.rb +199 -0
- data/lib/chef/win32/security/token.rb +64 -0
- data/lib/chef/win32/unicode.rb +43 -0
- data/lib/chef/win32/version.rb +119 -0
- metadata +104 -158
- data/lib/chef/shell_out/unix.rb +0 -223
- data/lib/chef/shell_out/windows.rb +0 -588
@@ -0,0 +1,289 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Author:: Mark Mzyk (<mmzyk@ospcode.com>)
|
4
|
+
# Copyright:: Copyright 2011 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/win32/api'
|
21
|
+
require 'chef/win32/api/security'
|
22
|
+
require 'chef/win32/api/system'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
module Win32
|
26
|
+
module API
|
27
|
+
module File
|
28
|
+
extend Chef::Win32::API
|
29
|
+
include Chef::Win32::API::Security
|
30
|
+
include Chef::Win32::API::System
|
31
|
+
|
32
|
+
###############################################
|
33
|
+
# Win32 API Constants
|
34
|
+
###############################################
|
35
|
+
|
36
|
+
FILE_ATTRIBUTE_READONLY = 0x00000001
|
37
|
+
FILE_ATTRIBUTE_HIDDEN = 0x00000002
|
38
|
+
FILE_ATTRIBUTE_SYSTEM = 0x00000004
|
39
|
+
FILE_ATTRIBUTE_DIRECTORY = 0x00000010
|
40
|
+
FILE_ATTRIBUTE_ARCHIVE = 0x00000020
|
41
|
+
FILE_ATTRIBUTE_DEVICE = 0x00000040
|
42
|
+
FILE_ATTRIBUTE_NORMAL = 0x00000080
|
43
|
+
FILE_ATTRIBUTE_TEMPORARY = 0x00000100
|
44
|
+
FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200
|
45
|
+
FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
|
46
|
+
FILE_ATTRIBUTE_COMPRESSED = 0x00000800
|
47
|
+
FILE_ATTRIBUTE_OFFLINE = 0x00001000
|
48
|
+
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000
|
49
|
+
FILE_ATTRIBUTE_ENCRYPTED = 0x00004000
|
50
|
+
FILE_ATTRIBUTE_VIRTUAL = 0x00010000
|
51
|
+
INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF
|
52
|
+
|
53
|
+
IO_REPARSE_TAG_SYMLINK = 0xA000000C
|
54
|
+
INVALID_HANDLE_VALUE = 0xFFFFFFFF
|
55
|
+
MAX_PATH = 260
|
56
|
+
|
57
|
+
SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
|
58
|
+
|
59
|
+
FILE_NAME_NORMALIZED = 0x0
|
60
|
+
FILE_NAME_OPENED = 0x8
|
61
|
+
|
62
|
+
# TODO add the rest of these CONSTS
|
63
|
+
FILE_SHARE_READ = 0x00000001
|
64
|
+
OPEN_EXISTING = 3
|
65
|
+
|
66
|
+
###############################################
|
67
|
+
# Win32 API Bindings
|
68
|
+
###############################################
|
69
|
+
|
70
|
+
ffi_lib 'kernel32'
|
71
|
+
|
72
|
+
=begin
|
73
|
+
typedef struct _FILETIME {
|
74
|
+
DWORD dwLowDateTime;
|
75
|
+
DWORD dwHighDateTime;
|
76
|
+
} FILETIME, *PFILETIME;
|
77
|
+
=end
|
78
|
+
class FILETIME < FFI::Struct
|
79
|
+
layout :dw_low_date_time, :DWORD,
|
80
|
+
:dw_high_date_time, :DWORD
|
81
|
+
end
|
82
|
+
|
83
|
+
=begin
|
84
|
+
typedef struct _SECURITY_ATTRIBUTES {
|
85
|
+
DWORD nLength;
|
86
|
+
LPVOID lpSecurityDescriptor;
|
87
|
+
BOOL bInheritHandle;
|
88
|
+
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
|
89
|
+
=end
|
90
|
+
class SECURITY_ATTRIBUTES < FFI::Struct
|
91
|
+
layout :n_length, :DWORD,
|
92
|
+
:lp_security_descriptor, :LPVOID,
|
93
|
+
:b_inherit_handle, :DWORD
|
94
|
+
end
|
95
|
+
|
96
|
+
=begin
|
97
|
+
typedef struct _WIN32_FIND_DATA {
|
98
|
+
DWORD dwFileAttributes;
|
99
|
+
FILETIME ftCreationTime;
|
100
|
+
FILETIME ftLastAccessTime;
|
101
|
+
FILETIME ftLastWriteTime;
|
102
|
+
DWORD nFileSizeHigh;
|
103
|
+
DWORD nFileSizeLow;
|
104
|
+
DWORD dwReserved0;
|
105
|
+
DWORD dwReserved1;
|
106
|
+
TCHAR cFileName[MAX_PATH];
|
107
|
+
TCHAR cAlternateFileName[14];
|
108
|
+
} WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA;
|
109
|
+
=end
|
110
|
+
class WIN32_FIND_DATA < FFI::Struct
|
111
|
+
layout :dw_file_attributes, :DWORD,
|
112
|
+
:ft_creation_time, FILETIME,
|
113
|
+
:ft_last_access_time, FILETIME,
|
114
|
+
:ft_last_write_time, FILETIME,
|
115
|
+
:n_file_size_high, :DWORD,
|
116
|
+
:n_file_size_low, :DWORD,
|
117
|
+
:dw_reserved_0, :DWORD,
|
118
|
+
:dw_reserved_1, :DWORD,
|
119
|
+
:c_file_name, [:BYTE, MAX_PATH*2],
|
120
|
+
:c_alternate_file_name, [:BYTE, 14]
|
121
|
+
end
|
122
|
+
|
123
|
+
=begin
|
124
|
+
typedef struct _BY_HANDLE_FILE_INFORMATION {
|
125
|
+
DWORD dwFileAttributes;
|
126
|
+
FILETIME ftCreationTime;
|
127
|
+
FILETIME ftLastAccessTime;
|
128
|
+
FILETIME ftLastWriteTime;
|
129
|
+
DWORD dwVolumeSerialNumber;
|
130
|
+
DWORD nFileSizeHigh;
|
131
|
+
DWORD nFileSizeLow;
|
132
|
+
DWORD nNumberOfLinks;
|
133
|
+
DWORD nFileIndexHigh;
|
134
|
+
DWORD nFileIndexLow;
|
135
|
+
} BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION;
|
136
|
+
=end
|
137
|
+
class BY_HANDLE_FILE_INFORMATION < FFI::Struct
|
138
|
+
layout :dw_file_attributes, :DWORD,
|
139
|
+
:ft_creation_time, FILETIME,
|
140
|
+
:ft_last_access_time, FILETIME,
|
141
|
+
:ft_last_write_time, FILETIME,
|
142
|
+
:dw_volume_serial_number, :DWORD,
|
143
|
+
:n_file_size_high, :DWORD,
|
144
|
+
:n_file_size_low, :DWORD,
|
145
|
+
:n_number_of_links, :DWORD,
|
146
|
+
:n_file_index_high, :DWORD,
|
147
|
+
:n_file_index_low, :DWORD
|
148
|
+
end
|
149
|
+
|
150
|
+
=begin
|
151
|
+
HANDLE WINAPI CreateFile(
|
152
|
+
__in LPCTSTR lpFileName,
|
153
|
+
__in DWORD dwDesiredAccess,
|
154
|
+
__in DWORD dwShareMode,
|
155
|
+
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
156
|
+
__in DWORD dwCreationDisposition,
|
157
|
+
__in DWORD dwFlagsAndAttributes,
|
158
|
+
__in_opt HANDLE hTemplateFile
|
159
|
+
);
|
160
|
+
=end
|
161
|
+
attach_function :CreateFileW, [:LPCTSTR, :DWORD, :DWORD, :LPSECURITY_ATTRIBUTES, :DWORD, :DWORD, :pointer], :HANDLE
|
162
|
+
|
163
|
+
=begin
|
164
|
+
BOOL WINAPI FindClose(
|
165
|
+
__inout HANDLE hFindFile
|
166
|
+
);
|
167
|
+
=end
|
168
|
+
attach_function :FindClose, [:HANDLE], :BOOL
|
169
|
+
|
170
|
+
=begin
|
171
|
+
DWORD WINAPI GetFileAttributes(
|
172
|
+
__in LPCTSTR lpFileName
|
173
|
+
);
|
174
|
+
=end
|
175
|
+
attach_function :GetFileAttributesW, [:LPCWSTR], :DWORD
|
176
|
+
|
177
|
+
=begin
|
178
|
+
DWORD WINAPI GetFinalPathNameByHandle(
|
179
|
+
__in HANDLE hFile,
|
180
|
+
__out LPTSTR lpszFilePath,
|
181
|
+
__in DWORD cchFilePath,
|
182
|
+
__in DWORD dwFlags
|
183
|
+
);
|
184
|
+
=end
|
185
|
+
attach_function :GetFinalPathNameByHandleW, [:HANDLE, :LPTSTR, :DWORD, :DWORD], :DWORD
|
186
|
+
|
187
|
+
=begin
|
188
|
+
BOOL WINAPI GetFileInformationByHandle(
|
189
|
+
__in HANDLE hFile,
|
190
|
+
__out LPBY_HANDLE_FILE_INFORMATION lpFileInformation
|
191
|
+
);
|
192
|
+
=end
|
193
|
+
attach_function :GetFileInformationByHandle, [:HANDLE, :LPBY_HANDLE_FILE_INFORMATION], :BOOL
|
194
|
+
|
195
|
+
=begin
|
196
|
+
HANDLE WINAPI FindFirstFile(
|
197
|
+
__in LPCTSTR lpFileName,
|
198
|
+
__out LPWIN32_FIND_DATA lpFindFileData
|
199
|
+
);
|
200
|
+
=end
|
201
|
+
attach_function :FindFirstFileW, [:LPCTSTR, :LPWIN32_FIND_DATA], :HANDLE
|
202
|
+
|
203
|
+
=begin
|
204
|
+
BOOL WINAPI CreateHardLink(
|
205
|
+
__in LPCTSTR lpFileName,
|
206
|
+
__in LPCTSTR lpExistingFileName,
|
207
|
+
__reserved LPSECURITY_ATTRIBUTES lpSecurityAttributes
|
208
|
+
);
|
209
|
+
=end
|
210
|
+
attach_function :CreateHardLinkW, [:LPCTSTR, :LPCTSTR, :LPSECURITY_ATTRIBUTES], :BOOLEAN
|
211
|
+
|
212
|
+
=begin
|
213
|
+
BOOLEAN WINAPI CreateSymbolicLink(
|
214
|
+
__in LPTSTR lpSymlinkFileName,
|
215
|
+
__in LPTSTR lpTargetFileName,
|
216
|
+
__in DWORD dwFlags
|
217
|
+
);
|
218
|
+
=end
|
219
|
+
attach_function :CreateSymbolicLinkW, [:LPTSTR, :LPTSTR, :DWORD], :BOOLEAN
|
220
|
+
|
221
|
+
|
222
|
+
###############################################
|
223
|
+
# Helpers
|
224
|
+
###############################################
|
225
|
+
|
226
|
+
# takes the given path pre-pends "\\?\" and
|
227
|
+
# UTF-16LE encodes it. Used to prepare paths
|
228
|
+
# to be passed to the *W vesion of WinAPI File
|
229
|
+
# functions
|
230
|
+
def encode_path(path)
|
231
|
+
path.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR)
|
232
|
+
(path_prepender << path).to_wstring
|
233
|
+
end
|
234
|
+
|
235
|
+
def path_prepender
|
236
|
+
"\\\\?\\"
|
237
|
+
end
|
238
|
+
|
239
|
+
# retrieves a file search handle and passes it
|
240
|
+
# to +&block+ along with the find_data. also
|
241
|
+
# ensures the handle is closed on exit of the block
|
242
|
+
def file_search_handle(path, &block)
|
243
|
+
begin
|
244
|
+
path = encode_path(path)
|
245
|
+
find_data = WIN32_FIND_DATA.new
|
246
|
+
handle = FindFirstFileW(path, find_data)
|
247
|
+
if handle == INVALID_HANDLE_VALUE
|
248
|
+
Chef::Win32::Error.raise!
|
249
|
+
end
|
250
|
+
block.call(handle, find_data)
|
251
|
+
ensure
|
252
|
+
FindClose(handle) if handle && handle != INVALID_HANDLE_VALUE
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# retrieves a file handle and passes it
|
257
|
+
# to +&block+ along with the find_data. also
|
258
|
+
# ensures the handle is closed on exit of the block
|
259
|
+
def file_handle(path, &block)
|
260
|
+
begin
|
261
|
+
path = encode_path(path)
|
262
|
+
handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
|
263
|
+
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nil)
|
264
|
+
|
265
|
+
if handle == INVALID_HANDLE_VALUE
|
266
|
+
Chef::Win32::Error.raise!
|
267
|
+
end
|
268
|
+
block.call(handle)
|
269
|
+
ensure
|
270
|
+
CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def retrieve_file_info(file_name)
|
275
|
+
file_information = nil
|
276
|
+
file_handle(file_name) do |handle|
|
277
|
+
file_information = BY_HANDLE_FILE_INFORMATION.new
|
278
|
+
success = GetFileInformationByHandle(handle, file_information)
|
279
|
+
if success == 0
|
280
|
+
Chef::Win32::Error.raise!
|
281
|
+
end
|
282
|
+
end
|
283
|
+
file_information
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#
|
2
|
+
# Author:: John Keiser (<jkeiser@opscode.com>)
|
3
|
+
# Copyright:: Copyright 2011 Opscode, 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 Win32
|
23
|
+
module API
|
24
|
+
module Memory
|
25
|
+
extend Chef::Win32::API
|
26
|
+
|
27
|
+
###############################################
|
28
|
+
# Win32 API Constants
|
29
|
+
###############################################
|
30
|
+
|
31
|
+
LMEM_FIXED = 0x0000
|
32
|
+
LMEM_MOVEABLE = 0x0002
|
33
|
+
LMEM_NOCOMPACT = 0x0010
|
34
|
+
LMEM_NODISCARD = 0x0020
|
35
|
+
LMEM_ZEROINIT = 0x0040
|
36
|
+
LMEM_MODIFY = 0x0080
|
37
|
+
LMEM_DISCARDABLE = 0x0F00
|
38
|
+
LMEM_VALID_FLAGS = 0x0F72
|
39
|
+
LMEM_INVALID_HANDLE = 0x8000
|
40
|
+
LHND = LMEM_MOVEABLE | LMEM_ZEROINIT
|
41
|
+
LPTR = LMEM_FIXED | LMEM_ZEROINIT
|
42
|
+
NONZEROLHND = LMEM_MOVEABLE
|
43
|
+
NONZEROLPTR = LMEM_FIXED
|
44
|
+
LMEM_DISCARDED = 0x4000
|
45
|
+
LMEM_LOCKCOUNT = 0x00FF
|
46
|
+
|
47
|
+
###############################################
|
48
|
+
# Win32 API Bindings
|
49
|
+
###############################################
|
50
|
+
|
51
|
+
ffi_lib 'kernel32'
|
52
|
+
|
53
|
+
=begin
|
54
|
+
HLOCAL WINAPI LocalAlloc(
|
55
|
+
__in UINT uFlags,
|
56
|
+
__in SIZE_T uBytes
|
57
|
+
);
|
58
|
+
=end
|
59
|
+
attach_function :LocalAlloc, [ :UINT, :SIZE_T ], :pointer
|
60
|
+
|
61
|
+
=begin
|
62
|
+
UINT WINAPI LocalFlags(
|
63
|
+
__in HLOCAL hMem
|
64
|
+
);
|
65
|
+
=end
|
66
|
+
attach_function :LocalFlags, [ :pointer ], :UINT
|
67
|
+
|
68
|
+
=begin
|
69
|
+
HLOCAL WINAPI LocalFree(
|
70
|
+
__in HLOCAL hMem
|
71
|
+
);
|
72
|
+
=end
|
73
|
+
attach_function :LocalFree, [ :pointer ], :pointer
|
74
|
+
|
75
|
+
=begin
|
76
|
+
HLOCAL WINAPI LocalReAlloc(
|
77
|
+
__in HLOCAL hMem,
|
78
|
+
__in SIZE_T uBytes,
|
79
|
+
__in UINT uFlags
|
80
|
+
);
|
81
|
+
=end
|
82
|
+
attach_function :LocalReAlloc, [ :pointer, :SIZE_T, :UINT ], :pointer
|
83
|
+
|
84
|
+
=begin
|
85
|
+
UINT WINAPI LocalSize(
|
86
|
+
__in HLOCAL hMem
|
87
|
+
);
|
88
|
+
=end
|
89
|
+
attach_function :LocalSize, [ :pointer ], :SIZE_T
|
90
|
+
|
91
|
+
###############################################
|
92
|
+
# FFI API Bindings
|
93
|
+
###############################################
|
94
|
+
|
95
|
+
ffi_lib FFI::Library::LIBC
|
96
|
+
attach_function :malloc, [:size_t], :pointer
|
97
|
+
attach_function :calloc, [:size_t], :pointer
|
98
|
+
attach_function :realloc, [:pointer, :size_t], :pointer
|
99
|
+
attach_function :free, [:pointer], :void
|
100
|
+
attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Author:: John Keiser (<jkeiser@opscode.com>)
|
3
|
+
# Copyright:: Copyright 2011 Opscode, 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 Win32
|
23
|
+
module API
|
24
|
+
module Process
|
25
|
+
extend Chef::Win32::API
|
26
|
+
|
27
|
+
###############################################
|
28
|
+
# Win32 API Bindings
|
29
|
+
###############################################
|
30
|
+
|
31
|
+
ffi_lib 'kernel32'
|
32
|
+
|
33
|
+
attach_function :GetCurrentProcess, [], :HANDLE
|
34
|
+
attach_function :GetProcessHandleCount, [ :HANDLE, :LPDWORD ], :BOOL
|
35
|
+
attach_function :GetProcessId, [ :HANDLE ], :DWORD
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright 2011 Opscode, 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 Win32
|
23
|
+
module API
|
24
|
+
module PSAPI
|
25
|
+
extend Chef::Win32::API
|
26
|
+
|
27
|
+
###############################################
|
28
|
+
# Win32 API Bindings
|
29
|
+
###############################################
|
30
|
+
|
31
|
+
class PROCESS_MEMORY_COUNTERS < FFI::Struct
|
32
|
+
layout :cb, :DWORD,
|
33
|
+
:PageFaultCount, :DWORD,
|
34
|
+
:PeakWorkingSetSize, :SIZE_T,
|
35
|
+
:WorkingSetSize, :SIZE_T,
|
36
|
+
:QuotaPeakPagedPoolUsage, :SIZE_T,
|
37
|
+
:QuotaPagedPoolUsage, :SIZE_T,
|
38
|
+
:QuotaPeakNonPagedPoolUsage, :SIZE_T,
|
39
|
+
:QuotaNonPagedPoolUsage, :SIZE_T,
|
40
|
+
:PagefileUsage, :SIZE_T,
|
41
|
+
:PeakPagefileUsage, :SIZE_T
|
42
|
+
end
|
43
|
+
|
44
|
+
ffi_lib 'psapi'
|
45
|
+
|
46
|
+
attach_function :GetProcessMemoryInfo, [ :HANDLE, :pointer, :DWORD ], :BOOL
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|