chef 0.10.10 → 10.12.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/README.rdoc +6 -0
  2. data/distro/common/html/chef-client.8.html +4 -3
  3. data/distro/common/html/chef-expander.8.html +3 -3
  4. data/distro/common/html/chef-expanderctl.8.html +3 -3
  5. data/distro/common/html/chef-server-webui.8.html +3 -3
  6. data/distro/common/html/chef-server.8.html +3 -3
  7. data/distro/common/html/chef-solo.8.html +3 -3
  8. data/distro/common/html/chef-solr.8.html +3 -3
  9. data/distro/common/html/knife-bootstrap.1.html +3 -3
  10. data/distro/common/html/knife-client.1.html +3 -3
  11. data/distro/common/html/knife-configure.1.html +3 -3
  12. data/distro/common/html/knife-cookbook-site.1.html +3 -3
  13. data/distro/common/html/knife-cookbook.1.html +3 -3
  14. data/distro/common/html/knife-data-bag.1.html +3 -3
  15. data/distro/common/html/knife-environment.1.html +3 -3
  16. data/distro/common/html/knife-exec.1.html +3 -3
  17. data/distro/common/html/knife-index.1.html +3 -3
  18. data/distro/common/html/knife-node.1.html +3 -3
  19. data/distro/common/html/knife-role.1.html +3 -3
  20. data/distro/common/html/knife-search.1.html +3 -3
  21. data/distro/common/html/knife-ssh.1.html +3 -3
  22. data/distro/common/html/knife-status.1.html +3 -3
  23. data/distro/common/html/knife-tag.1.html +3 -3
  24. data/distro/common/html/knife.1.html +3 -3
  25. data/distro/common/html/shef.1.html +3 -3
  26. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +5 -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/man8/chef-client.mkd +2 -0
  51. data/lib/chef/application/client.rb +1 -1
  52. data/lib/chef/application/solo.rb +1 -1
  53. data/lib/chef/application/windows_service.rb +1 -1
  54. data/lib/chef/config.rb +1 -1
  55. data/lib/chef/exceptions.rb +3 -0
  56. data/lib/chef/file_access_control/unix.rb +21 -6
  57. data/lib/chef/file_access_control/windows.rb +7 -7
  58. data/lib/chef/knife/ssh.rb +4 -2
  59. data/lib/chef/mixin/enforce_ownership_and_permissions.rb +1 -1
  60. data/lib/chef/provider/link.rb +49 -45
  61. data/lib/chef/provider/mdadm.rb +4 -1
  62. data/lib/chef/provider/package/rubygems.rb +2 -1
  63. data/lib/chef/provider/remote_file.rb +17 -1
  64. data/lib/chef/reserved_names.rb +9 -0
  65. data/lib/chef/resource/link.rb +1 -17
  66. data/lib/chef/resource/mdadm.rb +1 -1
  67. data/lib/chef/resource_platform_map.rb +1 -3
  68. data/lib/chef/rest.rb +48 -17
  69. data/lib/chef/version.rb +1 -1
  70. data/lib/chef/win32/api.rb +16 -1
  71. data/lib/chef/win32/api/error.rb +9 -9
  72. data/lib/chef/win32/api/file.rb +263 -17
  73. data/lib/chef/win32/api/memory.rb +12 -12
  74. data/lib/chef/win32/api/process.rb +5 -5
  75. data/lib/chef/win32/api/psapi.rb +3 -3
  76. data/lib/chef/win32/api/security.rb +41 -41
  77. data/lib/chef/win32/api/system.rb +8 -8
  78. data/lib/chef/win32/api/unicode.rb +6 -6
  79. data/lib/chef/win32/error.rb +4 -4
  80. data/lib/chef/win32/file.rb +65 -15
  81. data/lib/chef/win32/file/info.rb +7 -7
  82. data/lib/chef/win32/handle.rb +3 -3
  83. data/lib/chef/win32/memory.rb +8 -8
  84. data/lib/chef/win32/process.rb +8 -8
  85. data/lib/chef/win32/security.rb +49 -49
  86. data/lib/chef/win32/security/ace.rb +11 -11
  87. data/lib/chef/win32/security/acl.rb +10 -10
  88. data/lib/chef/win32/security/securable_object.rb +13 -13
  89. data/lib/chef/win32/security/security_descriptor.rb +12 -12
  90. data/lib/chef/win32/security/sid.rb +8 -8
  91. data/lib/chef/win32/security/token.rb +8 -8
  92. data/lib/chef/win32/unicode.rb +5 -5
  93. data/lib/chef/win32/version.rb +4 -4
  94. metadata +374 -370
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '0.10.10'
20
+ VERSION = '10.12.0.rc.1'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -18,11 +18,26 @@
18
18
  #
19
19
 
20
20
  require 'ffi'
21
+ require 'chef/reserved_names'
22
+ require 'chef/exceptions'
21
23
 
22
24
  class Chef
23
- module Win32
25
+ module ReservedNames::Win32
24
26
  module API
25
27
 
28
+ # Attempts to use FFI's attach_function method to link a native Win32
29
+ # function into the calling module. If this fails a dummy method is
30
+ # defined which when called, raises a helpful exception to the end-user.
31
+ def safe_attach_function(win32_func, *args)
32
+ begin
33
+ attach_function(win32_func.to_sym, *args)
34
+ rescue FFI::NotFoundError
35
+ define_method(win32_func.to_sym) do |*margs|
36
+ raise Chef::Exceptions::Win32APIFunctionNotImplemented, "This version of Windows does not implement the Win32 function [#{win32_func}]."
37
+ end
38
+ end
39
+ end
40
+
26
41
  # put shared stuff (like constants) for all raw Win32 API calls
27
42
  def self.extended(host)
28
43
  host.extend FFI::Library
@@ -19,10 +19,10 @@
19
19
  require 'chef/win32/api'
20
20
 
21
21
  class Chef
22
- module Win32
22
+ module ReservedNames::Win32
23
23
  module API
24
24
  module Error
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Constants
@@ -890,30 +890,30 @@ DWORD WINAPI FormatMessage(
890
890
  __in_opt va_list *Arguments
891
891
  );
892
892
  =end
893
- attach_function :FormatMessageA, [:DWORD, :LPCVOID, :DWORD, :DWORD, :LPTSTR, :DWORD, :varargs], :DWORD
894
- attach_function :FormatMessageW, [:DWORD, :LPCVOID, :DWORD, :DWORD, :LPWSTR, :DWORD, :varargs], :DWORD
893
+ safe_attach_function :FormatMessageA, [:DWORD, :LPCVOID, :DWORD, :DWORD, :LPTSTR, :DWORD, :varargs], :DWORD
894
+ safe_attach_function :FormatMessageW, [:DWORD, :LPCVOID, :DWORD, :DWORD, :LPWSTR, :DWORD, :varargs], :DWORD
895
895
 
896
896
  =begin
897
897
  DWORD WINAPI GetLastError(void);
898
898
  =end
899
- attach_function :GetLastError, [], :DWORD
899
+ safe_attach_function :GetLastError, [], :DWORD
900
900
  =begin
901
901
  void WINAPI SetLastError(
902
902
  __in DWORD dwErrCode
903
903
  );
904
904
  =end
905
- attach_function :SetLastError, [:DWORD], :void
906
- attach_function :SetLastErrorEx, [:DWORD, :DWORD], :void
905
+ safe_attach_function :SetLastError, [:DWORD], :void
906
+ safe_attach_function :SetLastErrorEx, [:DWORD, :DWORD], :void
907
907
  =begin
908
908
  UINT WINAPI GetErrorMode(void);s
909
909
  =end
910
- attach_function :GetErrorMode, [], :uint
910
+ safe_attach_function :GetErrorMode, [], :uint
911
911
  =begin
912
912
  UINT WINAPI SetErrorMode(
913
913
  __in UINT uMode
914
914
  );
915
915
  =end
916
- attach_function :SetErrorMode, [:UINT], :UINT
916
+ safe_attach_function :SetErrorMode, [:UINT], :UINT
917
917
 
918
918
  end
919
919
  end
@@ -22,12 +22,12 @@ require 'chef/win32/api/security'
22
22
  require 'chef/win32/api/system'
23
23
 
24
24
  class Chef
25
- module Win32
25
+ module ReservedNames::Win32
26
26
  module API
27
27
  module File
28
- extend Chef::Win32::API
29
- include Chef::Win32::API::Security
30
- include Chef::Win32::API::System
28
+ extend Chef::ReservedNames::Win32::API
29
+ include Chef::ReservedNames::Win32::API::Security
30
+ include Chef::ReservedNames::Win32::API::System
31
31
 
32
32
  ###############################################
33
33
  # Win32 API Constants
@@ -50,7 +50,18 @@ class Chef
50
50
  FILE_ATTRIBUTE_VIRTUAL = 0x00010000
51
51
  INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF
52
52
 
53
- IO_REPARSE_TAG_SYMLINK = 0xA000000C
53
+ FILE_FLAG_WRITE_THROUGH = 0x80000000
54
+ FILE_FLAG_OVERLAPPED = 0x40000000
55
+ FILE_FLAG_NO_BUFFERING = 0x20000000
56
+ FILE_FLAG_RANDOM_ACCESS = 0x10000000
57
+ FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000
58
+ FILE_FLAG_DELETE_ON_CLOSE = 0x04000000
59
+ FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
60
+ FILE_FLAG_POSIX_SEMANTICS = 0x01000000
61
+ FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
62
+ FILE_FLAG_OPEN_NO_RECALL = 0x00100000
63
+ FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000
64
+
54
65
  INVALID_HANDLE_VALUE = 0xFFFFFFFF
55
66
  MAX_PATH = 260
56
67
 
@@ -63,6 +74,109 @@ class Chef
63
74
  FILE_SHARE_READ = 0x00000001
64
75
  OPEN_EXISTING = 3
65
76
 
77
+ # DeviceIoControl control codes
78
+ # -----------------------------
79
+ FILE_DEVICE_BEEP = 0x00000001
80
+ FILE_DEVICE_CD_ROM = 0x00000002
81
+ FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003
82
+ FILE_DEVICE_CONTROLLER = 0x00000004
83
+ FILE_DEVICE_DATALINK = 0x00000005
84
+ FILE_DEVICE_DFS = 0x00000006
85
+ FILE_DEVICE_DISK = 0x00000007
86
+ FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008
87
+ FILE_DEVICE_FILE_SYSTEM = 0x00000009
88
+ FILE_DEVICE_INPORT_PORT = 0x0000000a
89
+ FILE_DEVICE_KEYBOARD = 0x0000000b
90
+ FILE_DEVICE_MAILSLOT = 0x0000000c
91
+ FILE_DEVICE_MIDI_IN = 0x0000000d
92
+ FILE_DEVICE_MIDI_OUT = 0x0000000e
93
+ FILE_DEVICE_MOUSE = 0x0000000f
94
+ FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010
95
+ FILE_DEVICE_NAMED_PIPE = 0x00000011
96
+ FILE_DEVICE_NETWORK = 0x00000012
97
+ FILE_DEVICE_NETWORK_BROWSER = 0x00000013
98
+ FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014
99
+ FILE_DEVICE_NULL = 0x00000015
100
+ FILE_DEVICE_PARALLEL_PORT = 0x00000016
101
+ FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017
102
+ FILE_DEVICE_PRINTER = 0x00000018
103
+ FILE_DEVICE_SCANNER = 0x00000019
104
+ FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001a
105
+ FILE_DEVICE_SERIAL_PORT = 0x0000001b
106
+ FILE_DEVICE_SCREEN = 0x0000001c
107
+ FILE_DEVICE_SOUND = 0x0000001d
108
+ FILE_DEVICE_STREAMS = 0x0000001e
109
+ FILE_DEVICE_TAPE = 0x0000001f
110
+ FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020
111
+ FILE_DEVICE_TRANSPORT = 0x00000021
112
+ FILE_DEVICE_UNKNOWN = 0x00000022
113
+ FILE_DEVICE_VIDEO = 0x00000023
114
+ FILE_DEVICE_VIRTUAL_DISK = 0x00000024
115
+ FILE_DEVICE_WAVE_IN = 0x00000025
116
+ FILE_DEVICE_WAVE_OUT = 0x00000026
117
+ FILE_DEVICE_8042_PORT = 0x00000027
118
+ FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028
119
+ FILE_DEVICE_BATTERY = 0x00000029
120
+ FILE_DEVICE_BUS_EXTENDER = 0x0000002a
121
+ FILE_DEVICE_MODEM = 0x0000002b
122
+ FILE_DEVICE_VDM = 0x0000002c
123
+ FILE_DEVICE_MASS_STORAGE = 0x0000002d
124
+ FILE_DEVICE_SMB = 0x0000002e
125
+ FILE_DEVICE_KS = 0x0000002f
126
+ FILE_DEVICE_CHANGER = 0x00000030
127
+ FILE_DEVICE_SMARTCARD = 0x00000031
128
+ FILE_DEVICE_ACPI = 0x00000032
129
+ FILE_DEVICE_DVD = 0x00000033
130
+ FILE_DEVICE_FULLSCREEN_VIDEO = 0x00000034
131
+ FILE_DEVICE_DFS_FILE_SYSTEM = 0x00000035
132
+ FILE_DEVICE_DFS_VOLUME = 0x00000036
133
+ FILE_DEVICE_SERENUM = 0x00000037
134
+ FILE_DEVICE_TERMSRV = 0x00000038
135
+ FILE_DEVICE_KSEC = 0x00000039
136
+ FILE_DEVICE_FIPS = 0x0000003A
137
+ FILE_DEVICE_INFINIBAND = 0x0000003B
138
+ FILE_DEVICE_VMBUS = 0x0000003E
139
+ FILE_DEVICE_CRYPT_PROVIDER = 0x0000003F
140
+ FILE_DEVICE_WPD = 0x00000040
141
+ FILE_DEVICE_BLUETOOTH = 0x00000041
142
+ FILE_DEVICE_MT_COMPOSITE = 0x00000042
143
+ FILE_DEVICE_MT_TRANSPORT = 0x00000043
144
+ FILE_DEVICE_BIOMETRIC = 0x00000044
145
+ FILE_DEVICE_PMI = 0x00000045
146
+
147
+ # Methods
148
+ METHOD_BUFFERED = 0
149
+ METHOD_IN_DIRECT = 1
150
+ METHOD_OUT_DIRECT = 2
151
+ METHOD_NEITHER = 3
152
+ METHOD_DIRECT_TO_HARDWARE = METHOD_IN_DIRECT
153
+ METHOD_DIRECT_FROM_HARDWARE = METHOD_OUT_DIRECT
154
+
155
+ # Access
156
+ FILE_ANY_ACCESS = 0
157
+ FILE_SPECIAL_ACCESS = FILE_ANY_ACCESS
158
+ FILE_READ_ACCESS = 0x0001
159
+ FILE_WRITE_ACCESS = 0x0002
160
+
161
+ def self.CTL_CODE( device_type, function, method, access )
162
+ (device_type << 16) | (access << 14) | (function << 2) | method
163
+ end
164
+
165
+ FSCTL_GET_REPARSE_POINT = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS)
166
+
167
+ # Reparse point tags
168
+ IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003
169
+ IO_REPARSE_TAG_HSM = 0xC0000004
170
+ IO_REPARSE_TAG_HSM2 = 0x80000006
171
+ IO_REPARSE_TAG_SIS = 0x80000007
172
+ IO_REPARSE_TAG_WIM = 0x80000008
173
+ IO_REPARSE_TAG_CSV = 0x80000009
174
+ IO_REPARSE_TAG_DFS = 0x8000000A
175
+ IO_REPARSE_TAG_SYMLINK = 0xA000000C
176
+ IO_REPARSE_TAG_DFSR = 0x80000012
177
+
178
+ MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16*1024
179
+
66
180
  ###############################################
67
181
  # Win32 API Bindings
68
182
  ###############################################
@@ -147,6 +261,92 @@ typedef struct _BY_HANDLE_FILE_INFORMATION {
147
261
  :n_file_index_low, :DWORD
148
262
  end
149
263
 
264
+ =begin
265
+ typedef struct _REPARSE_DATA_BUFFER {
266
+ ULONG ReparseTag;
267
+ USHORT ReparseDataLength;
268
+ USHORT Reserved;
269
+ union {
270
+ struct {
271
+ USHORT SubstituteNameOffset;
272
+ USHORT SubstituteNameLength;
273
+ USHORT PrintNameOffset;
274
+ USHORT PrintNameLength;
275
+ ULONG Flags;
276
+ WCHAR PathBuffer[1];
277
+ } SymbolicLinkReparseBuffer;
278
+ struct {
279
+ USHORT SubstituteNameOffset;
280
+ USHORT SubstituteNameLength;
281
+ USHORT PrintNameOffset;
282
+ USHORT PrintNameLength;
283
+ WCHAR PathBuffer[1];
284
+ } MountPointReparseBuffer;
285
+ struct {
286
+ UCHAR DataBuffer[1];
287
+ } GenericReparseBuffer;
288
+ };
289
+ } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
290
+ =end
291
+
292
+ class REPARSE_DATA_BUFFER_SYMBOLIC_LINK < FFI::Struct
293
+ layout :SubstituteNameOffset, :ushort,
294
+ :SubstituteNameLength, :ushort,
295
+ :PrintNameOffset, :ushort,
296
+ :PrintNameLength, :ushort,
297
+ :Flags, :uint32,
298
+ :PathBuffer, :ushort
299
+
300
+ def substitute_name
301
+ string_pointer = FFI::Pointer.new(pointer.address) + offset_of(:PathBuffer) + self[:SubstituteNameOffset]
302
+ string_pointer.read_wstring(self[:SubstituteNameLength]/2)
303
+ end
304
+ def print_name
305
+ string_pointer = FFI::Pointer.new(pointer.address) + offset_of(:PathBuffer) + self[:PrintNameOffset]
306
+ string_pointer.read_wstring(self[:PrintNameLength]/2)
307
+ end
308
+ end
309
+ class REPARSE_DATA_BUFFER_MOUNT_POINT < FFI::Struct
310
+ layout :SubstituteNameOffset, :ushort,
311
+ :SubstituteNameLength, :ushort,
312
+ :PrintNameOffset, :ushort,
313
+ :PrintNameLength, :ushort,
314
+ :PathBuffer, :ushort
315
+
316
+ def substitute_name
317
+ string_pointer = FFI::Pointer.new(pointer.address) + offset_of(:PathBuffer) + self[:SubstituteNameOffset]
318
+ string_pointer.read_wstring(self[:SubstituteNameLength]/2)
319
+ end
320
+ def print_name
321
+ string_pointer = FFI::Pointer.new(pointer.address) + offset_of(:PathBuffer) + self[:PrintNameOffset]
322
+ string_pointer.read_wstring(self[:PrintNameLength]/2)
323
+ end
324
+ end
325
+ class REPARSE_DATA_BUFFER_GENERIC < FFI::Struct
326
+ layout :DataBuffer, :uchar
327
+ end
328
+ class REPARSE_DATA_BUFFER_UNION < FFI::Union
329
+ layout :SymbolicLinkReparseBuffer, REPARSE_DATA_BUFFER_SYMBOLIC_LINK,
330
+ :MountPointReparseBuffer, REPARSE_DATA_BUFFER_MOUNT_POINT,
331
+ :GenericReparseBuffer, REPARSE_DATA_BUFFER_GENERIC
332
+ end
333
+ class REPARSE_DATA_BUFFER < FFI::Struct
334
+ layout :ReparseTag, :uint32,
335
+ :ReparseDataLength, :ushort,
336
+ :Reserved, :ushort,
337
+ :ReparseBuffer, REPARSE_DATA_BUFFER_UNION
338
+
339
+ def reparse_buffer
340
+ if self[:ReparseTag] == IO_REPARSE_TAG_SYMLINK
341
+ self[:ReparseBuffer][:SymbolicLinkReparseBuffer]
342
+ elsif self[:ReparseTag] == IO_REPARSE_TAG_MOUNT_POINT
343
+ self[:ReparseBuffer][:MountPointReparseBuffer]
344
+ else
345
+ self[:ReparseBuffer][:GenericReparseBuffer]
346
+ end
347
+ end
348
+ end
349
+
150
350
  =begin
151
351
  HANDLE WINAPI CreateFile(
152
352
  __in LPCTSTR lpFileName,
@@ -158,21 +358,21 @@ HANDLE WINAPI CreateFile(
158
358
  __in_opt HANDLE hTemplateFile
159
359
  );
160
360
  =end
161
- attach_function :CreateFileW, [:LPCTSTR, :DWORD, :DWORD, :LPSECURITY_ATTRIBUTES, :DWORD, :DWORD, :pointer], :HANDLE
361
+ safe_attach_function :CreateFileW, [:LPCTSTR, :DWORD, :DWORD, :LPSECURITY_ATTRIBUTES, :DWORD, :DWORD, :pointer], :HANDLE
162
362
 
163
363
  =begin
164
364
  BOOL WINAPI FindClose(
165
365
  __inout HANDLE hFindFile
166
366
  );
167
367
  =end
168
- attach_function :FindClose, [:HANDLE], :BOOL
368
+ safe_attach_function :FindClose, [:HANDLE], :BOOL
169
369
 
170
370
  =begin
171
371
  DWORD WINAPI GetFileAttributes(
172
372
  __in LPCTSTR lpFileName
173
373
  );
174
374
  =end
175
- attach_function :GetFileAttributesW, [:LPCWSTR], :DWORD
375
+ safe_attach_function :GetFileAttributesW, [:LPCWSTR], :DWORD
176
376
 
177
377
  =begin
178
378
  DWORD WINAPI GetFinalPathNameByHandle(
@@ -182,7 +382,7 @@ DWORD WINAPI GetFinalPathNameByHandle(
182
382
  __in DWORD dwFlags
183
383
  );
184
384
  =end
185
- attach_function :GetFinalPathNameByHandleW, [:HANDLE, :LPTSTR, :DWORD, :DWORD], :DWORD
385
+ safe_attach_function :GetFinalPathNameByHandleW, [:HANDLE, :LPTSTR, :DWORD, :DWORD], :DWORD
186
386
 
187
387
  =begin
188
388
  BOOL WINAPI GetFileInformationByHandle(
@@ -190,7 +390,7 @@ BOOL WINAPI GetFileInformationByHandle(
190
390
  __out LPBY_HANDLE_FILE_INFORMATION lpFileInformation
191
391
  );
192
392
  =end
193
- attach_function :GetFileInformationByHandle, [:HANDLE, :LPBY_HANDLE_FILE_INFORMATION], :BOOL
393
+ safe_attach_function :GetFileInformationByHandle, [:HANDLE, :LPBY_HANDLE_FILE_INFORMATION], :BOOL
194
394
 
195
395
  =begin
196
396
  HANDLE WINAPI FindFirstFile(
@@ -198,7 +398,7 @@ HANDLE WINAPI FindFirstFile(
198
398
  __out LPWIN32_FIND_DATA lpFindFileData
199
399
  );
200
400
  =end
201
- attach_function :FindFirstFileW, [:LPCTSTR, :LPWIN32_FIND_DATA], :HANDLE
401
+ safe_attach_function :FindFirstFileW, [:LPCTSTR, :LPWIN32_FIND_DATA], :HANDLE
202
402
 
203
403
  =begin
204
404
  BOOL WINAPI CreateHardLink(
@@ -207,7 +407,7 @@ BOOL WINAPI CreateHardLink(
207
407
  __reserved LPSECURITY_ATTRIBUTES lpSecurityAttributes
208
408
  );
209
409
  =end
210
- attach_function :CreateHardLinkW, [:LPCTSTR, :LPCTSTR, :LPSECURITY_ATTRIBUTES], :BOOLEAN
410
+ safe_attach_function :CreateHardLinkW, [:LPCTSTR, :LPCTSTR, :LPSECURITY_ATTRIBUTES], :BOOLEAN
211
411
 
212
412
  =begin
213
413
  BOOLEAN WINAPI CreateSymbolicLink(
@@ -216,8 +416,39 @@ BOOLEAN WINAPI CreateSymbolicLink(
216
416
  __in DWORD dwFlags
217
417
  );
218
418
  =end
219
- attach_function :CreateSymbolicLinkW, [:LPTSTR, :LPTSTR, :DWORD], :BOOLEAN
419
+ safe_attach_function :CreateSymbolicLinkW, [:LPTSTR, :LPTSTR, :DWORD], :BOOLEAN
420
+
421
+ =begin
422
+ DWORD WINAPI GetLongPathName(
423
+ __in LPCTSTR lpszShortPath,
424
+ __out LPTSTR lpszLongPath,
425
+ __in DWORD cchBuffer
426
+ );
427
+ =end
428
+ safe_attach_function :GetLongPathNameW, [:LPCTSTR, :LPTSTR, :DWORD], :DWORD
220
429
 
430
+ =begin
431
+ DWORD WINAPI GetShortPathName(
432
+ __in LPCTSTR lpszLongPath,
433
+ __out LPTSTR lpszShortPath,
434
+ __in DWORD cchBuffer
435
+ );
436
+ =end
437
+ safe_attach_function :GetShortPathNameW, [:LPCTSTR, :LPTSTR, :DWORD], :DWORD
438
+
439
+ =begin
440
+ BOOL WINAPI DeviceIoControl(
441
+ __in HANDLE hDevice,
442
+ __in DWORD dwIoControlCode,
443
+ __in_opt LPVOID lpInBuffer,
444
+ __in DWORD nInBufferSize,
445
+ __out_opt LPVOID lpOutBuffer,
446
+ __in DWORD nOutBufferSize,
447
+ __out_opt LPDWORD lpBytesReturned,
448
+ __inout_opt LPOVERLAPPED lpOverlapped
449
+ );
450
+ =end
451
+ safe_attach_function :DeviceIoControl, [:HANDLE, :DWORD, :LPVOID, :DWORD, :LPVOID, :DWORD, :LPDWORD, :pointer], :BOOL
221
452
 
222
453
  ###############################################
223
454
  # Helpers
@@ -245,7 +476,7 @@ BOOLEAN WINAPI CreateSymbolicLink(
245
476
  find_data = WIN32_FIND_DATA.new
246
477
  handle = FindFirstFileW(path, find_data)
247
478
  if handle == INVALID_HANDLE_VALUE
248
- Chef::Win32::Error.raise!
479
+ Chef::ReservedNames::Win32::Error.raise!
249
480
  end
250
481
  block.call(handle, find_data)
251
482
  ensure
@@ -260,10 +491,25 @@ BOOLEAN WINAPI CreateSymbolicLink(
260
491
  begin
261
492
  path = encode_path(path)
262
493
  handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
263
- nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nil)
494
+ nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil)
495
+
496
+ if handle == INVALID_HANDLE_VALUE
497
+ Chef::ReservedNames::Win32::Error.raise!
498
+ end
499
+ block.call(handle)
500
+ ensure
501
+ CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE
502
+ end
503
+ end
504
+
505
+ def symlink_file_handle(path, &block)
506
+ begin
507
+ path = encode_path(path)
508
+ handle = CreateFileW(path, FILE_READ_EA, FILE_SHARE_READ,
509
+ nil, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nil)
264
510
 
265
511
  if handle == INVALID_HANDLE_VALUE
266
- Chef::Win32::Error.raise!
512
+ Chef::ReservedNames::Win32::Error.raise!
267
513
  end
268
514
  block.call(handle)
269
515
  ensure
@@ -277,7 +523,7 @@ BOOLEAN WINAPI CreateSymbolicLink(
277
523
  file_information = BY_HANDLE_FILE_INFORMATION.new
278
524
  success = GetFileInformationByHandle(handle, file_information)
279
525
  if success == 0
280
- Chef::Win32::Error.raise!
526
+ Chef::ReservedNames::Win32::Error.raise!
281
527
  end
282
528
  end
283
529
  file_information