chef 0.10.10 → 10.12.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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 Memory
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Constants
@@ -56,21 +56,21 @@ HLOCAL WINAPI LocalAlloc(
56
56
  __in SIZE_T uBytes
57
57
  );
58
58
  =end
59
- attach_function :LocalAlloc, [ :UINT, :SIZE_T ], :pointer
59
+ safe_attach_function :LocalAlloc, [ :UINT, :SIZE_T ], :pointer
60
60
 
61
61
  =begin
62
62
  UINT WINAPI LocalFlags(
63
63
  __in HLOCAL hMem
64
64
  );
65
65
  =end
66
- attach_function :LocalFlags, [ :pointer ], :UINT
66
+ safe_attach_function :LocalFlags, [ :pointer ], :UINT
67
67
 
68
68
  =begin
69
69
  HLOCAL WINAPI LocalFree(
70
70
  __in HLOCAL hMem
71
71
  );
72
72
  =end
73
- attach_function :LocalFree, [ :pointer ], :pointer
73
+ safe_attach_function :LocalFree, [ :pointer ], :pointer
74
74
 
75
75
  =begin
76
76
  HLOCAL WINAPI LocalReAlloc(
@@ -79,25 +79,25 @@ HLOCAL WINAPI LocalReAlloc(
79
79
  __in UINT uFlags
80
80
  );
81
81
  =end
82
- attach_function :LocalReAlloc, [ :pointer, :SIZE_T, :UINT ], :pointer
82
+ safe_attach_function :LocalReAlloc, [ :pointer, :SIZE_T, :UINT ], :pointer
83
83
 
84
84
  =begin
85
85
  UINT WINAPI LocalSize(
86
86
  __in HLOCAL hMem
87
87
  );
88
88
  =end
89
- attach_function :LocalSize, [ :pointer ], :SIZE_T
89
+ safe_attach_function :LocalSize, [ :pointer ], :SIZE_T
90
90
 
91
91
  ###############################################
92
92
  # FFI API Bindings
93
93
  ###############################################
94
94
 
95
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
96
+ safe_attach_function :malloc, [:size_t], :pointer
97
+ safe_attach_function :calloc, [:size_t], :pointer
98
+ safe_attach_function :realloc, [:pointer, :size_t], :pointer
99
+ safe_attach_function :free, [:pointer], :void
100
+ safe_attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
101
101
 
102
102
  end
103
103
  end
@@ -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 Process
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Bindings
@@ -30,9 +30,9 @@ class Chef
30
30
 
31
31
  ffi_lib 'kernel32'
32
32
 
33
- attach_function :GetCurrentProcess, [], :HANDLE
34
- attach_function :GetProcessHandleCount, [ :HANDLE, :LPDWORD ], :BOOL
35
- attach_function :GetProcessId, [ :HANDLE ], :DWORD
33
+ safe_attach_function :GetCurrentProcess, [], :HANDLE
34
+ safe_attach_function :GetProcessHandleCount, [ :HANDLE, :LPDWORD ], :BOOL
35
+ safe_attach_function :GetProcessId, [ :HANDLE ], :DWORD
36
36
 
37
37
  end
38
38
  end
@@ -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 PSAPI
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Bindings
@@ -43,7 +43,7 @@ class Chef
43
43
 
44
44
  ffi_lib 'psapi'
45
45
 
46
- attach_function :GetProcessMemoryInfo, [ :HANDLE, :pointer, :DWORD ], :BOOL
46
+ safe_attach_function :GetProcessMemoryInfo, [ :HANDLE, :pointer, :DWORD ], :BOOL
47
47
 
48
48
  end
49
49
  end
@@ -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 Security
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Constants
@@ -295,45 +295,45 @@ class Chef
295
295
 
296
296
  ffi_lib "advapi32"
297
297
 
298
- attach_function :AddAce, [ :pointer, :DWORD, :DWORD, :LPVOID, :DWORD ], :BOOL
299
- attach_function :AddAccessAllowedAce, [ :pointer, :DWORD, :DWORD, :pointer ], :BOOL
300
- attach_function :AddAccessAllowedAceEx, [ :pointer, :DWORD, :DWORD, :DWORD, :pointer ], :BOOL
301
- attach_function :AddAccessDeniedAce, [ :pointer, :DWORD, :DWORD, :pointer ], :BOOL
302
- attach_function :AddAccessDeniedAceEx, [ :pointer, :DWORD, :DWORD, :DWORD, :pointer ], :BOOL
303
- attach_function :AdjustTokenPrivileges, [ :HANDLE, :BOOL, :pointer, :DWORD, :pointer, :PDWORD ], :BOOL
304
- attach_function :ConvertSidToStringSidA, [ :pointer, :pointer ], :BOOL
305
- attach_function :ConvertStringSidToSidW, [ :pointer, :pointer ], :BOOL
306
- attach_function :DeleteAce, [ :pointer, :DWORD ], :BOOL
307
- attach_function :EqualSid, [ :pointer, :pointer ], :BOOL
308
- attach_function :FreeSid, [ :pointer ], :pointer
309
- attach_function :GetAce, [ :pointer, :DWORD, :pointer ], :BOOL
310
- attach_function :GetLengthSid, [ :pointer ], :DWORD
311
- attach_function :GetNamedSecurityInfoW, [ :LPWSTR, :SE_OBJECT_TYPE, :DWORD, :pointer, :pointer, :pointer, :pointer, :pointer ], :DWORD
312
- attach_function :GetSecurityDescriptorControl, [ :pointer, :PWORD, :LPDWORD], :BOOL
313
- attach_function :GetSecurityDescriptorDacl, [ :pointer, :LPBOOL, :pointer, :LPBOOL ], :BOOL
314
- attach_function :GetSecurityDescriptorGroup, [ :pointer, :pointer, :LPBOOL], :BOOL
315
- attach_function :GetSecurityDescriptorOwner, [ :pointer, :pointer, :LPBOOL], :BOOL
316
- attach_function :GetSecurityDescriptorSacl, [ :pointer, :LPBOOL, :pointer, :LPBOOL ], :BOOL
317
- attach_function :InitializeAcl, [ :pointer, :DWORD, :DWORD ], :BOOL
318
- attach_function :InitializeSecurityDescriptor, [ :pointer, :DWORD ], :BOOL
319
- attach_function :IsValidAcl, [ :pointer ], :BOOL
320
- attach_function :IsValidSecurityDescriptor, [ :pointer ], :BOOL
321
- attach_function :IsValidSid, [ :pointer ], :BOOL
322
- attach_function :LookupAccountNameW, [ :LPCWSTR, :LPCWSTR, :pointer, :LPDWORD, :LPWSTR, :LPDWORD, :pointer ], :BOOL
323
- attach_function :LookupAccountSidW, [ :LPCWSTR, :pointer, :LPWSTR, :LPDWORD, :LPWSTR, :LPDWORD, :pointer ], :BOOL
324
- attach_function :LookupPrivilegeNameW, [ :LPCWSTR, :PLUID, :LPWSTR, :LPDWORD ], :BOOL
325
- attach_function :LookupPrivilegeDisplayNameW, [ :LPCWSTR, :LPCWSTR, :LPWSTR, :LPDWORD, :LPDWORD ], :BOOL
326
- attach_function :LookupPrivilegeValueW, [ :LPCWSTR, :LPCWSTR, :PLUID ], :BOOL
327
- attach_function :MakeAbsoluteSD, [ :pointer, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD], :BOOL
328
- attach_function :OpenProcessToken, [ :HANDLE, :DWORD, :PHANDLE ], :BOOL
329
- attach_function :QuerySecurityAccessMask, [ :DWORD, :LPDWORD ], :void
330
- attach_function :SetFileSecurityW, [ :LPWSTR, :DWORD, :pointer ], :BOOL
331
- attach_function :SetNamedSecurityInfoW, [ :LPWSTR, :SE_OBJECT_TYPE, :DWORD, :pointer, :pointer, :pointer, :pointer ], :DWORD
332
- attach_function :SetSecurityAccessMask, [ :DWORD, :LPDWORD ], :void
333
- attach_function :SetSecurityDescriptorDacl, [ :pointer, :BOOL, :pointer, :BOOL ], :BOOL
334
- attach_function :SetSecurityDescriptorGroup, [ :pointer, :pointer, :BOOL ], :BOOL
335
- attach_function :SetSecurityDescriptorOwner, [ :pointer, :pointer, :BOOL ], :BOOL
336
- attach_function :SetSecurityDescriptorSacl, [ :pointer, :BOOL, :pointer, :BOOL ], :BOOL
298
+ safe_attach_function :AddAce, [ :pointer, :DWORD, :DWORD, :LPVOID, :DWORD ], :BOOL
299
+ safe_attach_function :AddAccessAllowedAce, [ :pointer, :DWORD, :DWORD, :pointer ], :BOOL
300
+ safe_attach_function :AddAccessAllowedAceEx, [ :pointer, :DWORD, :DWORD, :DWORD, :pointer ], :BOOL
301
+ safe_attach_function :AddAccessDeniedAce, [ :pointer, :DWORD, :DWORD, :pointer ], :BOOL
302
+ safe_attach_function :AddAccessDeniedAceEx, [ :pointer, :DWORD, :DWORD, :DWORD, :pointer ], :BOOL
303
+ safe_attach_function :AdjustTokenPrivileges, [ :HANDLE, :BOOL, :pointer, :DWORD, :pointer, :PDWORD ], :BOOL
304
+ safe_attach_function :ConvertSidToStringSidA, [ :pointer, :pointer ], :BOOL
305
+ safe_attach_function :ConvertStringSidToSidW, [ :pointer, :pointer ], :BOOL
306
+ safe_attach_function :DeleteAce, [ :pointer, :DWORD ], :BOOL
307
+ safe_attach_function :EqualSid, [ :pointer, :pointer ], :BOOL
308
+ safe_attach_function :FreeSid, [ :pointer ], :pointer
309
+ safe_attach_function :GetAce, [ :pointer, :DWORD, :pointer ], :BOOL
310
+ safe_attach_function :GetLengthSid, [ :pointer ], :DWORD
311
+ safe_attach_function :GetNamedSecurityInfoW, [ :LPWSTR, :SE_OBJECT_TYPE, :DWORD, :pointer, :pointer, :pointer, :pointer, :pointer ], :DWORD
312
+ safe_attach_function :GetSecurityDescriptorControl, [ :pointer, :PWORD, :LPDWORD], :BOOL
313
+ safe_attach_function :GetSecurityDescriptorDacl, [ :pointer, :LPBOOL, :pointer, :LPBOOL ], :BOOL
314
+ safe_attach_function :GetSecurityDescriptorGroup, [ :pointer, :pointer, :LPBOOL], :BOOL
315
+ safe_attach_function :GetSecurityDescriptorOwner, [ :pointer, :pointer, :LPBOOL], :BOOL
316
+ safe_attach_function :GetSecurityDescriptorSacl, [ :pointer, :LPBOOL, :pointer, :LPBOOL ], :BOOL
317
+ safe_attach_function :InitializeAcl, [ :pointer, :DWORD, :DWORD ], :BOOL
318
+ safe_attach_function :InitializeSecurityDescriptor, [ :pointer, :DWORD ], :BOOL
319
+ safe_attach_function :IsValidAcl, [ :pointer ], :BOOL
320
+ safe_attach_function :IsValidSecurityDescriptor, [ :pointer ], :BOOL
321
+ safe_attach_function :IsValidSid, [ :pointer ], :BOOL
322
+ safe_attach_function :LookupAccountNameW, [ :LPCWSTR, :LPCWSTR, :pointer, :LPDWORD, :LPWSTR, :LPDWORD, :pointer ], :BOOL
323
+ safe_attach_function :LookupAccountSidW, [ :LPCWSTR, :pointer, :LPWSTR, :LPDWORD, :LPWSTR, :LPDWORD, :pointer ], :BOOL
324
+ safe_attach_function :LookupPrivilegeNameW, [ :LPCWSTR, :PLUID, :LPWSTR, :LPDWORD ], :BOOL
325
+ safe_attach_function :LookupPrivilegeDisplayNameW, [ :LPCWSTR, :LPCWSTR, :LPWSTR, :LPDWORD, :LPDWORD ], :BOOL
326
+ safe_attach_function :LookupPrivilegeValueW, [ :LPCWSTR, :LPCWSTR, :PLUID ], :BOOL
327
+ safe_attach_function :MakeAbsoluteSD, [ :pointer, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD], :BOOL
328
+ safe_attach_function :OpenProcessToken, [ :HANDLE, :DWORD, :PHANDLE ], :BOOL
329
+ safe_attach_function :QuerySecurityAccessMask, [ :DWORD, :LPDWORD ], :void
330
+ safe_attach_function :SetFileSecurityW, [ :LPWSTR, :DWORD, :pointer ], :BOOL
331
+ safe_attach_function :SetNamedSecurityInfoW, [ :LPWSTR, :SE_OBJECT_TYPE, :DWORD, :pointer, :pointer, :pointer, :pointer ], :DWORD
332
+ safe_attach_function :SetSecurityAccessMask, [ :DWORD, :LPDWORD ], :void
333
+ safe_attach_function :SetSecurityDescriptorDacl, [ :pointer, :BOOL, :pointer, :BOOL ], :BOOL
334
+ safe_attach_function :SetSecurityDescriptorGroup, [ :pointer, :pointer, :BOOL ], :BOOL
335
+ safe_attach_function :SetSecurityDescriptorOwner, [ :pointer, :pointer, :BOOL ], :BOOL
336
+ safe_attach_function :SetSecurityDescriptorSacl, [ :pointer, :BOOL, :pointer, :BOOL ], :BOOL
337
337
 
338
338
  end
339
339
  end
@@ -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 System
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Constants
@@ -153,20 +153,20 @@ BOOL WINAPI CloseHandle(
153
153
  __in HANDLE hObject
154
154
  );
155
155
  =end
156
- attach_function :CloseHandle, [ :HANDLE ], :BOOL
156
+ safe_attach_function :CloseHandle, [ :HANDLE ], :BOOL
157
157
 
158
158
  =begin
159
159
  DWORD WINAPI GetVersion(void);
160
160
  =end
161
- attach_function :GetVersion, [], :DWORD
161
+ safe_attach_function :GetVersion, [], :DWORD
162
162
 
163
163
  =begin
164
164
  BOOL WINAPI GetVersionEx(
165
165
  __inout LPOSVERSIONINFO lpVersionInfo
166
166
  );
167
167
  =end
168
- attach_function :GetVersionExW, [:pointer], :BOOL
169
- attach_function :GetVersionExA, [:pointer], :BOOL
168
+ safe_attach_function :GetVersionExW, [:pointer], :BOOL
169
+ safe_attach_function :GetVersionExA, [:pointer], :BOOL
170
170
 
171
171
  =begin
172
172
  BOOL WINAPI GetProductInfo(
@@ -177,14 +177,14 @@ BOOL WINAPI GetProductInfo(
177
177
  __out PDWORD pdwReturnedProductType
178
178
  );
179
179
  =end
180
- attach_function :GetProductInfo, [:DWORD, :DWORD, :DWORD, :DWORD, :PDWORD], :BOOL
180
+ safe_attach_function :GetProductInfo, [:DWORD, :DWORD, :DWORD, :DWORD, :PDWORD], :BOOL
181
181
 
182
182
  =begin
183
183
  int WINAPI GetSystemMetrics(
184
184
  __in int nIndex
185
185
  );
186
186
  =end
187
- attach_function :GetSystemMetrics, [:int], :int
187
+ safe_attach_function :GetSystemMetrics, [:int], :int
188
188
 
189
189
  end
190
190
  end
@@ -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 Unicode
25
- extend Chef::Win32::API
25
+ extend Chef::ReservedNames::Win32::API
26
26
 
27
27
  ###############################################
28
28
  # Win32 API Constants
@@ -101,7 +101,7 @@ BOOL IsTextUnicode(
101
101
  __inout LPINT lpiResult
102
102
  );
103
103
  =end
104
- attach_function :IsTextUnicode, [:pointer, :int, :LPINT], :BOOL
104
+ safe_attach_function :IsTextUnicode, [:pointer, :int, :LPINT], :BOOL
105
105
 
106
106
  =begin
107
107
  int MultiByteToWideChar(
@@ -113,7 +113,7 @@ int MultiByteToWideChar(
113
113
  __in int cchWideChar
114
114
  );
115
115
  =end
116
- attach_function :MultiByteToWideChar, [:UINT, :DWORD, :LPCSTR, :int, :LPWSTR, :int], :int
116
+ safe_attach_function :MultiByteToWideChar, [:UINT, :DWORD, :LPCSTR, :int, :LPWSTR, :int], :int
117
117
 
118
118
  =begin
119
119
  int WideCharToMultiByte(
@@ -127,7 +127,7 @@ int WideCharToMultiByte(
127
127
  __out LPBOOL lpUsedDefaultChar
128
128
  );
129
129
  =end
130
- attach_function :WideCharToMultiByte, [:UINT, :DWORD, :LPCWSTR, :int, :LPSTR, :int, :LPCSTR, :LPBOOL], :int
130
+ safe_attach_function :WideCharToMultiByte, [:UINT, :DWORD, :LPCWSTR, :int, :LPSTR, :int, :LPCSTR, :LPBOOL], :int
131
131
 
132
132
  ###############################################
133
133
  # Helpers
@@ -139,7 +139,7 @@ int WideCharToMultiByte(
139
139
  ustring = (ustring + "").force_encoding('UTF-8') if ustring.respond_to?(:force_encoding) && ustring.encoding.name != "UTF-8"
140
140
 
141
141
  # ensure we have the double-null termination Windows Wide likes
142
- ustring = ustring << "\000\000" if ustring[-1].chr != "\000"
142
+ ustring = ustring + "\000\000" if ustring[-1].chr != "\000"
143
143
 
144
144
  # encode it all as UTF-16LE AKA Windows Wide Character AKA Windows Unicode
145
145
  ustring = begin
@@ -22,10 +22,10 @@ require 'chef/win32/unicode'
22
22
  require 'chef/exceptions'
23
23
 
24
24
  class Chef
25
- module Win32
25
+ module ReservedNames::Win32
26
26
  class Error
27
- include Chef::Win32::API::Error
28
- extend Chef::Win32::API::Error
27
+ include Chef::ReservedNames::Win32::API::Error
28
+ extend Chef::ReservedNames::Win32::API::Error
29
29
 
30
30
  def self.format_message(message_id = 0, args = {})
31
31
  flags = args[:flags] || FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
@@ -42,7 +42,7 @@ class Chef
42
42
  begin
43
43
  return buffer.read_pointer.read_wstring(num_chars)
44
44
  ensure
45
- Chef::Win32::Memory.local_free(buffer.read_pointer)
45
+ Chef::ReservedNames::Win32::Memory.local_free(buffer.read_pointer)
46
46
  end
47
47
  end
48
48
 
@@ -22,10 +22,10 @@ require 'chef/win32/api/security'
22
22
  require 'chef/win32/error'
23
23
 
24
24
  class Chef
25
- module Win32
25
+ module ReservedNames::Win32
26
26
  class File
27
- include Chef::Win32::API::File
28
- extend Chef::Win32::API::File
27
+ include Chef::ReservedNames::Win32::API::File
28
+ extend Chef::ReservedNames::Win32::API::File
29
29
 
30
30
  # Creates a symbolic link called +new_name+ for the file or directory
31
31
  # +old_name+.
@@ -40,7 +40,7 @@ class Chef
40
40
  old_name = encode_path(old_name)
41
41
  new_name = encode_path(new_name)
42
42
  unless CreateHardLinkW(new_name, old_name, nil)
43
- Chef::Win32::Error.raise!
43
+ Chef::ReservedNames::Win32::Error.raise!
44
44
  end
45
45
  end
46
46
 
@@ -51,14 +51,14 @@ class Chef
51
51
  # returns nil as per MRI.
52
52
  #
53
53
  def self.symlink(old_name, new_name)
54
- raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name)
54
+ # raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name)
55
55
  # TODO do a check for CreateSymbolicLinkW and
56
56
  # raise NotImplemented exception on older Windows
57
57
  flags = ::File.directory?(old_name) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0
58
58
  old_name = encode_path(old_name)
59
59
  new_name = encode_path(new_name)
60
60
  unless CreateSymbolicLinkW(new_name, old_name, flags)
61
- Chef::Win32::Error.raise!
61
+ Chef::ReservedNames::Win32::Error.raise!
62
62
  end
63
63
  end
64
64
 
@@ -88,23 +88,73 @@ class Chef
88
88
  # will raise a NotImplementedError, as per MRI.
89
89
  #
90
90
  def self.readlink(link_name)
91
- raise Errno::ENOENT, link_name unless ::File.exist?(link_name)
92
- # TODO do a check for GetFinalPathNameByHandleW and
93
- # raise NotImplemented exception on older Windows
94
- file_handle(link_name) do |handle|
95
- buffer = FFI::MemoryPointer.new(0.chr * MAX_PATH)
96
- num_chars = GetFinalPathNameByHandleW(handle, buffer, buffer.size, FILE_NAME_NORMALIZED)
97
- if num_chars == 0
98
- Chef::Win32::Error.raise! #could be misleading if problem is too small buffer size as GetLastError won't report failure
91
+ raise Errno::ENOENT, link_name unless ::File.exists?(link_name)
92
+ symlink_file_handle(link_name) do |handle|
93
+ # Go to DeviceIoControl to get the symlink information
94
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa364571(v=vs.85).aspx
95
+ reparse_buffer = FFI::MemoryPointer.new(MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
96
+ parsed_size = FFI::Buffer.new(:long).write_long(0)
97
+ if DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, nil, 0, reparse_buffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, parsed_size, nil) == 0
98
+ Chef::ReservedNames::Win32::Error.raise!
99
99
  end
100
- buffer.read_wstring(num_chars).sub(path_prepender, "")
100
+
101
+ # Ensure it's a symbolic link
102
+ reparse_buffer = REPARSE_DATA_BUFFER.new(reparse_buffer)
103
+ if reparse_buffer[:ReparseTag] != IO_REPARSE_TAG_SYMLINK
104
+ raise Errno::EACCES, "#{link_name} is not a symlink"
105
+ end
106
+
107
+ # Return the link destination (strip off \??\ at the beginning, which is a local filesystem thing)
108
+ link_dest = reparse_buffer.reparse_buffer.substitute_name
109
+ if link_dest =~ /^\\\?\?\\/
110
+ link_dest = link_dest[4..-1]
111
+ end
112
+ link_dest
101
113
  end
102
114
  end
103
115
 
116
+ # Gets the short form of a path (Administrator -> ADMINI~1)
117
+ def self.get_short_path_name(path)
118
+ path = path.to_wstring
119
+ size = GetShortPathNameW(path, nil, 0)
120
+ if size == 0
121
+ Chef::ReservedNames::Win32::Error.raise!
122
+ end
123
+ result = FFI::MemoryPointer.new :char, (size+1)*2
124
+ if GetShortPathNameW(path, result, size+1) == 0
125
+ Chef::ReservedNames::Win32::Error.raise!
126
+ end
127
+ result.read_wstring(size)
128
+ end
129
+
130
+ # Gets the long form of a path (ADMINI~1 -> Administrator)
131
+ def self.get_long_path_name(path)
132
+ path = path.to_wstring
133
+ size = GetLongPathNameW(path, nil, 0)
134
+ if size == 0
135
+ Chef::ReservedNames::Win32::Error.raise!
136
+ end
137
+ result = FFI::MemoryPointer.new :char, (size+1)*2
138
+ if GetLongPathNameW(path, result, size+1) == 0
139
+ Chef::ReservedNames::Win32::Error.raise!
140
+ end
141
+ result.read_wstring(size)
142
+ end
143
+
104
144
  def self.info(file_name)
105
145
  Info.new(file_name)
106
146
  end
107
147
 
148
+ def self.verify_links_supported!
149
+ begin
150
+ CreateSymbolicLinkW(nil)
151
+ rescue Chef::Exceptions::Win32APIFunctionNotImplemented => e
152
+ raise e
153
+ rescue Exception
154
+ # things are ok.
155
+ end
156
+ end
157
+
108
158
  # ::File compat
109
159
  class << self
110
160
  alias :stat :info