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.
Files changed (197) hide show
  1. data/distro/arch/etc/rc.d/chef-client +15 -1
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-solo.8.html +4 -4
  8. data/distro/common/html/chef-solr.8.html +4 -4
  9. data/distro/common/html/knife-bootstrap.1.html +6 -10
  10. data/distro/common/html/knife-client.1.html +4 -4
  11. data/distro/common/html/knife-configure.1.html +4 -4
  12. data/distro/common/html/knife-cookbook-site.1.html +6 -6
  13. data/distro/common/html/knife-cookbook.1.html +4 -4
  14. data/distro/common/html/knife-data-bag.1.html +4 -4
  15. data/distro/common/html/knife-environment.1.html +4 -4
  16. data/distro/common/html/knife-exec.1.html +4 -4
  17. data/distro/common/html/knife-index.1.html +4 -4
  18. data/distro/common/html/knife-node.1.html +5 -5
  19. data/distro/common/html/knife-role.1.html +4 -4
  20. data/distro/common/html/knife-search.1.html +4 -4
  21. data/distro/common/html/knife-ssh.1.html +5 -6
  22. data/distro/common/html/knife-status.1.html +4 -4
  23. data/distro/common/html/knife-tag.1.html +4 -4
  24. data/distro/common/html/knife.1.html +7 -8
  25. data/distro/common/html/shef.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +4 -4
  27. data/distro/common/man/man1/knife-client.1 +1 -1
  28. data/distro/common/man/man1/knife-configure.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +2 -2
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +3 -7
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +5 -9
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
  51. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  52. data/distro/common/markdown/man1/knife-node.mkd +2 -2
  53. data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
  54. data/distro/common/markdown/man1/knife.mkd +7 -9
  55. data/distro/debian/etc/init.d/chef-client +22 -1
  56. data/distro/redhat/etc/init.d/chef-client +12 -1
  57. data/distro/windows/service_manager.rb +164 -0
  58. data/lib/chef/application.rb +12 -6
  59. data/lib/chef/application/client.rb +4 -3
  60. data/lib/chef/application/knife.rb +7 -12
  61. data/lib/chef/application/solo.rb +2 -1
  62. data/lib/chef/application/windows_service.rb +224 -0
  63. data/lib/chef/checksum_cache.rb +1 -0
  64. data/lib/chef/client.rb +3 -16
  65. data/lib/chef/config.rb +42 -13
  66. data/lib/chef/cookbook/metadata.rb +1 -1
  67. data/lib/chef/cookbook/syntax_check.rb +2 -2
  68. data/lib/chef/cookbook_version.rb +5 -0
  69. data/lib/chef/daemon.rb +1 -1
  70. data/lib/chef/exceptions.rb +7 -1
  71. data/lib/chef/file_access_control.rb +13 -87
  72. data/lib/chef/file_access_control/unix.rb +119 -0
  73. data/lib/chef/file_access_control/windows.rb +257 -0
  74. data/lib/chef/handler/json_file.rb +7 -1
  75. data/lib/chef/knife.rb +10 -16
  76. data/lib/chef/knife/bootstrap.rb +15 -8
  77. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  78. data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
  79. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
  80. data/lib/chef/knife/configure.rb +2 -2
  81. data/lib/chef/knife/cookbook_site_download.rb +60 -21
  82. data/lib/chef/knife/cookbook_site_install.rb +16 -21
  83. data/lib/chef/knife/cookbook_upload.rb +77 -48
  84. data/lib/chef/knife/core/bootstrap_context.rb +3 -1
  85. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  86. data/lib/chef/knife/core/node_editor.rb +1 -1
  87. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  88. data/lib/chef/knife/core/ui.rb +3 -2
  89. data/lib/chef/knife/help_topics.rb +1 -1
  90. data/lib/chef/knife/node_run_list_add.rb +14 -6
  91. data/lib/chef/knife/node_run_list_remove.rb +3 -3
  92. data/lib/chef/knife/ssh.rb +32 -13
  93. data/lib/chef/mash.rb +14 -0
  94. data/lib/chef/mixin/command.rb +1 -0
  95. data/lib/chef/mixin/command/unix.rb +5 -0
  96. data/lib/chef/mixin/convert_to_class_name.rb +2 -0
  97. data/lib/chef/mixin/deep_merge.rb +40 -18
  98. data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
  99. data/lib/chef/mixin/language.rb +89 -3
  100. data/lib/chef/mixin/language_include_recipe.rb +8 -4
  101. data/lib/chef/mixin/path_sanity.rb +67 -0
  102. data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
  103. data/lib/chef/mixin/securable.rb +152 -0
  104. data/lib/chef/mixin/shell_out.rb +1 -1
  105. data/lib/chef/mixin/template.rb +8 -3
  106. data/lib/chef/mixins.rb +3 -0
  107. data/lib/chef/monkey_patches/moneta.rb +50 -0
  108. data/lib/chef/monkey_patches/string.rb +1 -1
  109. data/lib/chef/node.rb +2 -1
  110. data/lib/chef/platform.rb +34 -0
  111. data/lib/chef/provider.rb +23 -21
  112. data/lib/chef/provider/cron.rb +17 -12
  113. data/lib/chef/provider/cron/solaris.rb +6 -18
  114. data/lib/chef/provider/deploy.rb +14 -15
  115. data/lib/chef/provider/deploy/timestamped.rb +0 -1
  116. data/lib/chef/provider/directory.rb +1 -3
  117. data/lib/chef/provider/execute.rb +2 -2
  118. data/lib/chef/provider/file.rb +1 -75
  119. data/lib/chef/provider/git.rb +11 -9
  120. data/lib/chef/provider/group/gpasswd.rb +14 -9
  121. data/lib/chef/provider/link.rb +28 -59
  122. data/lib/chef/provider/mdadm.rb +2 -2
  123. data/lib/chef/provider/mount/mount.rb +1 -1
  124. data/lib/chef/provider/package.rb +10 -6
  125. data/lib/chef/provider/package/apt.rb +3 -1
  126. data/lib/chef/provider/package/dpkg.rb +1 -1
  127. data/lib/chef/provider/package/portage.rb +6 -3
  128. data/lib/chef/provider/package/rubygems.rb +75 -6
  129. data/lib/chef/provider/package/smartos.rb +84 -0
  130. data/lib/chef/provider/package/yum-dump.py +3 -2
  131. data/lib/chef/provider/package/yum.rb +51 -10
  132. data/lib/chef/provider/remote_directory.rb +24 -3
  133. data/lib/chef/provider/remote_file.rb +0 -6
  134. data/lib/chef/provider/route.rb +3 -3
  135. data/lib/chef/provider/service/debian.rb +2 -2
  136. data/lib/chef/provider/service/freebsd.rb +1 -1
  137. data/lib/chef/provider/service/macosx.rb +125 -0
  138. data/lib/chef/provider/service/windows.rb +5 -1
  139. data/lib/chef/provider/subversion.rb +10 -7
  140. data/lib/chef/providers.rb +3 -0
  141. data/lib/chef/resource.rb +181 -87
  142. data/lib/chef/resource/apt_package.rb +10 -1
  143. data/lib/chef/resource/chef_gem.rb +53 -0
  144. data/lib/chef/resource/conditional.rb +3 -0
  145. data/lib/chef/resource/cookbook_file.rb +12 -6
  146. data/lib/chef/resource/cron.rb +9 -0
  147. data/lib/chef/resource/directory.rb +14 -31
  148. data/lib/chef/resource/execute.rb +11 -9
  149. data/lib/chef/resource/file.rb +9 -33
  150. data/lib/chef/resource/link.rb +13 -8
  151. data/lib/chef/resource/mdadm.rb +10 -1
  152. data/lib/chef/resource/remote_directory.rb +13 -2
  153. data/lib/chef/resource/remote_file.rb +14 -7
  154. data/lib/chef/resource/smartos_package.rb +36 -0
  155. data/lib/chef/resource/template.rb +12 -5
  156. data/lib/chef/resource_platform_map.rb +153 -0
  157. data/lib/chef/resources.rb +2 -0
  158. data/lib/chef/rest.rb +55 -10
  159. data/lib/chef/rest/auth_credentials.rb +1 -0
  160. data/lib/chef/rest/rest_request.rb +24 -8
  161. data/lib/chef/role.rb +8 -2
  162. data/lib/chef/run_list.rb +1 -1
  163. data/lib/chef/run_list/run_list_expansion.rb +2 -2
  164. data/lib/chef/run_list/run_list_item.rb +7 -0
  165. data/lib/chef/runner.rb +4 -0
  166. data/lib/chef/shef.rb +2 -2
  167. data/lib/chef/shef/shef_session.rb +4 -5
  168. data/lib/chef/shell_out.rb +2 -245
  169. data/lib/chef/util/file_edit.rb +99 -89
  170. data/lib/chef/version.rb +1 -1
  171. data/lib/chef/win32/api.rb +349 -0
  172. data/lib/chef/win32/api/error.rb +921 -0
  173. data/lib/chef/win32/api/file.rb +289 -0
  174. data/lib/chef/win32/api/memory.rb +105 -0
  175. data/lib/chef/win32/api/process.rb +40 -0
  176. data/lib/chef/win32/api/psapi.rb +51 -0
  177. data/lib/chef/win32/api/security.rb +341 -0
  178. data/lib/chef/win32/api/system.rb +192 -0
  179. data/lib/chef/win32/api/unicode.rb +178 -0
  180. data/lib/chef/win32/error.rb +73 -0
  181. data/lib/chef/win32/file.rb +117 -0
  182. data/lib/chef/win32/file/info.rb +100 -0
  183. data/lib/chef/win32/handle.rb +48 -0
  184. data/lib/chef/win32/memory.rb +101 -0
  185. data/lib/chef/win32/process.rb +84 -0
  186. data/lib/chef/win32/security.rb +489 -0
  187. data/lib/chef/win32/security/ace.rb +125 -0
  188. data/lib/chef/win32/security/acl.rb +101 -0
  189. data/lib/chef/win32/security/securable_object.rb +109 -0
  190. data/lib/chef/win32/security/security_descriptor.rb +93 -0
  191. data/lib/chef/win32/security/sid.rb +199 -0
  192. data/lib/chef/win32/security/token.rb +64 -0
  193. data/lib/chef/win32/unicode.rb +43 -0
  194. data/lib/chef/win32/version.rb +119 -0
  195. metadata +104 -158
  196. data/lib/chef/shell_out/unix.rb +0 -223
  197. 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