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,341 @@
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 Security
25
+ extend Chef::Win32::API
26
+
27
+ ###############################################
28
+ # Win32 API Constants
29
+ ###############################################
30
+
31
+ # ACE_HEADER AceType
32
+ ACCESS_MIN_MS_ACE_TYPE = 0x0
33
+ ACCESS_ALLOWED_ACE_TYPE = 0x0
34
+ ACCESS_DENIED_ACE_TYPE = 0x1
35
+ SYSTEM_AUDIT_ACE_TYPE = 0x2
36
+ SYSTEM_ALARM_ACE_TYPE = 0x3
37
+ ACCESS_MAX_MS_V2_ACE_TYPE = 0x3
38
+ ACCESS_ALLOWED_COMPOUND_ACE_TYPE = 0x4
39
+ ACCESS_MAX_MS_V3_ACE_TYPE = 0x4
40
+ ACCESS_MIN_MS_OBJECT_ACE_TYPE = 0x5
41
+ ACCESS_ALLOWED_OBJECT_ACE_TYPE = 0x5
42
+ ACCESS_DENIED_OBJECT_ACE_TYPE = 0x6
43
+ SYSTEM_AUDIT_OBJECT_ACE_TYPE = 0x7
44
+ SYSTEM_ALARM_OBJECT_ACE_TYPE = 0x8
45
+ ACCESS_MAX_MS_OBJECT_ACE_TYPE = 0x8
46
+ ACCESS_MAX_MS_V4_ACE_TYPE = 0x8
47
+ ACCESS_MAX_MS_ACE_TYPE = 0x8
48
+ ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 0x9
49
+ ACCESS_DENIED_CALLBACK_ACE_TYPE = 0xA
50
+ ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 0xB
51
+ ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 0xC
52
+ SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 0xD
53
+ SYSTEM_ALARM_CALLBACK_ACE_TYPE = 0xE
54
+ SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 0xF
55
+ SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 0x10
56
+ SYSTEM_MANDATORY_LABEL_ACE_TYPE = 0x11
57
+ ACCESS_MAX_MS_V5_ACE_TYPE = 0x11
58
+
59
+ # ACE_HEADER AceFlags
60
+ OBJECT_INHERIT_ACE = 0x1
61
+ CONTAINER_INHERIT_ACE = 0x2
62
+ NO_PROPAGATE_INHERIT_ACE = 0x4
63
+ INHERIT_ONLY_ACE = 0x8
64
+ INHERITED_ACE = 0x10
65
+ VALID_INHERIT_FLAGS = 0x1F
66
+ SUCCESSFUL_ACCESS_ACE_FLAG = 0x40
67
+ FAILED_ACCESS_ACE_FLAG = 0x80
68
+
69
+ # SECURITY_INFORMATION flags (DWORD)
70
+ OWNER_SECURITY_INFORMATION = 0x01
71
+ GROUP_SECURITY_INFORMATION = 0x02
72
+ DACL_SECURITY_INFORMATION = 0x04
73
+ SACL_SECURITY_INFORMATION = 0x08
74
+ LABEL_SECURITY_INFORMATION = 0x10
75
+ UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000
76
+ UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000
77
+ PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000
78
+ PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000
79
+
80
+ # SECURITY_DESCRIPTOR_REVISION
81
+ SECURITY_DESCRIPTOR_REVISION = 1
82
+ SECURITY_DESCRIPTOR_REVISION1 = 1
83
+
84
+ # SECURITY_DESCRIPTOR_CONTROL
85
+ SE_OWNER_DEFAULTED = 0x0001
86
+ SE_GROUP_DEFAULTED = 0x0002
87
+ SE_DACL_PRESENT = 0x0004
88
+ SE_DACL_DEFAULTED = 0x0008
89
+ SE_SACL_PRESENT = 0x0010
90
+ SE_SACL_DEFAULTED = 0x0020
91
+ SE_DACL_AUTO_INHERIT_REQ = 0x0100
92
+ SE_SACL_AUTO_INHERIT_REQ = 0x0200
93
+ SE_DACL_AUTO_INHERITED = 0x0400
94
+ SE_SACL_AUTO_INHERITED = 0x0800
95
+ SE_DACL_PROTECTED = 0x1000
96
+ SE_SACL_PROTECTED = 0x2000
97
+ SE_RM_CONTROL_VALID = 0x4000
98
+ SE_SELF_RELATIVE = 0x8000
99
+
100
+ # ACCESS_RIGHTS_MASK
101
+ # Generic Access Rights
102
+ GENERIC_READ = 0x80000000
103
+ GENERIC_WRITE = 0x40000000
104
+ GENERIC_EXECUTE = 0x20000000
105
+ GENERIC_ALL = 0x10000000
106
+ # Standard Access Rights
107
+ DELETE = 0x00010000
108
+ READ_CONTROL = 0x00020000
109
+ WRITE_DAC = 0x00040000
110
+ WRITE_OWNER = 0x00080000
111
+ SYNCHRONIZE = 0x00100000
112
+ STANDARD_RIGHTS_REQUIRED = 0x000F0000
113
+ STANDARD_RIGHTS_READ = READ_CONTROL
114
+ STANDARD_RIGHTS_WRITE = READ_CONTROL
115
+ STANDARD_RIGHTS_EXECUTE = READ_CONTROL
116
+ STANDARD_RIGHTS_ALL = 0x001F0000
117
+ SPECIFIC_RIGHTS_ALL = 0x0000FFFF
118
+ # Access System Security Right
119
+ ACCESS_SYSTEM_SECURITY = 0x01000000
120
+ # File/Directory Specific Rights
121
+ FILE_READ_DATA = 0x0001
122
+ FILE_LIST_DIRECTORY = 0x0001
123
+ FILE_WRITE_DATA = 0x0002
124
+ FILE_ADD_FILE = 0x0002
125
+ FILE_APPEND_DATA = 0x0004
126
+ FILE_ADD_SUBDIRECTORY = 0x0004
127
+ FILE_CREATE_PIPE_INSTANCE = 0x0004
128
+ FILE_READ_EA = 0x0008
129
+ FILE_WRITE_EA = 0x0010
130
+ FILE_EXECUTE = 0x0020
131
+ FILE_TRAVERSE = 0x0020
132
+ FILE_DELETE_CHILD = 0x0040
133
+ FILE_READ_ATTRIBUTES = 0x0080
134
+ FILE_WRITE_ATTRIBUTES = 0x0100
135
+ FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED |
136
+ SYNCHRONIZE |
137
+ 0x1FF
138
+ FILE_GENERIC_READ = STANDARD_RIGHTS_READ |
139
+ FILE_READ_DATA |
140
+ FILE_READ_ATTRIBUTES |
141
+ FILE_READ_EA |
142
+ SYNCHRONIZE
143
+ FILE_GENERIC_WRITE = STANDARD_RIGHTS_WRITE |
144
+ FILE_WRITE_DATA |
145
+ FILE_WRITE_ATTRIBUTES |
146
+ FILE_WRITE_EA |
147
+ FILE_APPEND_DATA |
148
+ SYNCHRONIZE
149
+ FILE_GENERIC_EXECUTE = STANDARD_RIGHTS_EXECUTE |
150
+ FILE_READ_ATTRIBUTES |
151
+ FILE_EXECUTE |
152
+ SYNCHRONIZE
153
+ # Access Token Rights (for OpenProcessToken)
154
+ # Access Rights for Access-Token Objects (used in OpenProcessToken)
155
+ TOKEN_ASSIGN_PRIMARY = 0x0001
156
+ TOKEN_DUPLICATE = 0x0002
157
+ TOKEN_IMPERSONATE = 0x0004
158
+ TOKEN_QUERY = 0x0008
159
+ TOKEN_QUERY_SOURCE = 0x0010
160
+ TOKEN_ADJUST_PRIVILEGES = 0x0020
161
+ TOKEN_ADJUST_GROUPS = 0x0040
162
+ TOKEN_ADJUST_DEFAULT = 0x0080
163
+ TOKEN_ADJUST_SESSIONID = 0x0100
164
+ TOKEN_READ = (STANDARD_RIGHTS_READ | TOKEN_QUERY)
165
+ TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY |
166
+ TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE |
167
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT |
168
+ TOKEN_ADJUST_SESSIONID)
169
+
170
+ # AdjustTokenPrivileges
171
+ SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001
172
+ SE_PRIVILEGE_ENABLED = 0x00000002
173
+ SE_PRIVILEGE_REMOVED = 0X00000004
174
+ SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000
175
+ SE_PRIVILEGE_VALID_ATTRIBUTES = SE_PRIVILEGE_ENABLED_BY_DEFAULT |
176
+ SE_PRIVILEGE_ENABLED |
177
+ SE_PRIVILEGE_REMOVED |
178
+ SE_PRIVILEGE_USED_FOR_ACCESS
179
+
180
+ # Minimum size of a SECURITY_DESCRIPTOR. TODO: this is probably platform dependent.
181
+ # Make it work on 64 bit.
182
+ SECURITY_DESCRIPTOR_MIN_LENGTH = 20
183
+
184
+ # ACL revisions
185
+ ACL_REVISION = 2
186
+ ACL_REVISION_DS = 4
187
+ ACL_REVISION1 = 1
188
+ ACL_REVISION2 = 2
189
+ ACL_REVISION3 = 3
190
+ ACL_REVISION4 = 4
191
+ MIN_ACL_REVISION = ACL_REVISION2
192
+ MAX_ACL_REVISION = ACL_REVISION4
193
+
194
+ MAXDWORD = 0xffffffff
195
+
196
+ ###############################################
197
+ # Win32 API Bindings
198
+ ###############################################
199
+
200
+ SE_OBJECT_TYPE = enum :SE_OBJECT_TYPE, [
201
+ :SE_UNKNOWN_OBJECT_TYPE,
202
+ :SE_FILE_OBJECT,
203
+ :SE_SERVICE,
204
+ :SE_PRINTER,
205
+ :SE_REGISTRY_KEY,
206
+ :SE_LMSHARE,
207
+ :SE_KERNEL_OBJECT,
208
+ :SE_WINDOW_OBJECT,
209
+ :SE_DS_OBJECT,
210
+ :SE_DS_OBJECT_ALL,
211
+ :SE_PROVIDER_DEFINED_OBJECT,
212
+ :SE_WMIGUID_OBJECT,
213
+ :SE_REGISTRY_WOW64_32KEY
214
+ ]
215
+
216
+ SID_NAME_USE = enum :SID_NAME_USE, [
217
+ :SidTypeUser, 1,
218
+ :SidTypeGroup,
219
+ :SidTypeDomain,
220
+ :SidTypeAlias,
221
+ :SidTypeWellKnownGroup,
222
+ :SidTypeDeletedAccount,
223
+ :SidTypeInvalid,
224
+ :SidTypeUnknown,
225
+ :SidTypeComputer,
226
+ :SidTypeLabel
227
+ ]
228
+
229
+ # SECURITY_DESCRIPTOR is an opaque structure whose contents can vary. Pass the
230
+ # pointer around and free it with LocalFree.
231
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa379561(v=vs.85).aspx
232
+
233
+ # SID is an opaque structure. Pass the pointer around.
234
+
235
+ # ACL type is a header with some information, followed by an array of ACEs
236
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa374931(v=VS.85).aspx
237
+ class ACLStruct < FFI::Struct
238
+ layout :AclRevision, :uchar,
239
+ :Sbzl, :uchar,
240
+ :AclSize, :ushort,
241
+ :AceCount, :ushort,
242
+ :Sbz2, :ushort
243
+ end
244
+
245
+ class ACE_HEADER < FFI::Struct
246
+ layout :AceType, :uchar,
247
+ :AceFlags, :uchar,
248
+ :AceSize, :ushort
249
+ end
250
+
251
+ class ACE_WITH_MASK_AND_SID < FFI::Struct
252
+ layout :AceType, :uchar,
253
+ :AceFlags, :uchar,
254
+ :AceSize, :ushort,
255
+ :Mask, :uint32,
256
+ :SidStart, :uint32
257
+
258
+ # The AceTypes this structure supports
259
+ def self.supports?(ace_type)
260
+ [
261
+ ACCESS_ALLOWED_ACE_TYPE,
262
+ ACCESS_DENIED_ACE_TYPE,
263
+ SYSTEM_AUDIT_ACE_TYPE,
264
+ SYSTEM_ALARM_ACE_TYPE
265
+ ].include?(ace_type)
266
+ end
267
+ end
268
+
269
+ class LUID < FFI::Struct
270
+ layout :LowPart, :DWORD,
271
+ :HighPart, :LONG
272
+ end
273
+
274
+ class LUID_AND_ATTRIBUTES < FFI::Struct
275
+ layout :Luid, LUID,
276
+ :Attributes, :DWORD
277
+ end
278
+
279
+ class TOKEN_PRIVILEGES < FFI::Struct
280
+ layout :PrivilegeCount, :DWORD,
281
+ :Privileges, LUID_AND_ATTRIBUTES
282
+
283
+ def self.size_with_privileges(num_privileges)
284
+ offset_of(:Privileges) + LUID_AND_ATTRIBUTES.size*num_privileges
285
+ end
286
+
287
+ def size_with_privileges
288
+ TOKEN_PRIVILEGES.size_with_privileges(self[:PrivilegeCount])
289
+ end
290
+
291
+ def privilege(index)
292
+ LUID_AND_ATTRIBUTES.new(pointer + offset_of(:Privileges) + (index * LUID_AND_ATTRIBUTES.size))
293
+ end
294
+ end
295
+
296
+ ffi_lib "advapi32"
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
337
+
338
+ end
339
+ end
340
+ end
341
+ end
@@ -0,0 +1,192 @@
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 System
25
+ extend Chef::Win32::API
26
+
27
+ ###############################################
28
+ # Win32 API Constants
29
+ ###############################################
30
+
31
+ # http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx
32
+
33
+ # Suite Masks
34
+ # Microsoft BackOffice components are installed.
35
+ VER_SUITE_BACKOFFICE = 0x00000004
36
+ # Windows Server 2003, Web Edition is installed.
37
+ VER_SUITE_BLADE = 0x00000400
38
+ # Windows Server 2003, Compute Cluster Edition is installed.
39
+ VER_SUITE_COMPUTE_SERVER = 0x00004000
40
+ # Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
41
+ VER_SUITE_DATACENTER = 0x00000080
42
+ # Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer to the Remarks section for more information about this bit flag.
43
+ VER_SUITE_ENTERPRISE = 0x00000002
44
+ # Windows XP Embedded is installed.
45
+ VER_SUITE_EMBEDDEDNT = 0x00000040
46
+ # Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
47
+ VER_SUITE_PERSONAL = 0x00000200
48
+ # Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in application server mode.
49
+ VER_SUITE_SINGLEUSERTS = 0x00000100
50
+ # Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. Refer to the Remarks section for more information about this bit flag.
51
+ VER_SUITE_SMALLBUSINESS = 0x00000001
52
+ # Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for more information about this bit flag.
53
+ VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
54
+ # Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed.
55
+ VER_SUITE_STORAGE_SERVER = 0x00002000
56
+ # Terminal Services is installed. This value is always set.
57
+ # If VER_SUITE_TERMINAL is set but VER_SUITE_SINGLEUSERTS is not set, the system is running in application server mode.
58
+ VER_SUITE_TERMINAL = 0x00000010
59
+ # Windows Home Server is installed.
60
+ VER_SUITE_WH_SERVER = 0x00008000
61
+
62
+ # Product Type
63
+ # The system is a domain controller and the operating system is Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
64
+ VER_NT_DOMAIN_CONTROLLER = 0x0000002
65
+ # The operating system is Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
66
+ # Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.
67
+ VER_NT_SERVER = 0x0000003
68
+ # The operating system is Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
69
+ VER_NT_WORKSTATION = 0x0000001
70
+
71
+ # Product Info
72
+ # http://msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx
73
+ PRODUCT_BUSINESS = 0x00000006 # Business
74
+ PRODUCT_BUSINESS_N = 0x00000010 # Business N
75
+ PRODUCT_CLUSTER_SERVER = 0x00000012 # HPC Edition
76
+ PRODUCT_DATACENTER_SERVER = 0x00000008 # Server Datacenter (full installation)
77
+ PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C # Server Datacenter (core installation)
78
+ PRODUCT_DATACENTER_SERVER_CORE_V = 0x00000027 # Server Datacenter without Hyper-V (core installation)
79
+ PRODUCT_DATACENTER_SERVER_V = 0x00000025 # Server Datacenter without Hyper-V (full installation)
80
+ PRODUCT_ENTERPRISE = 0x00000004 # Enterprise
81
+ PRODUCT_ENTERPRISE_E = 0x00000046 # Not supported
82
+ PRODUCT_ENTERPRISE_N = 0x0000001B # Enterprise N
83
+ PRODUCT_ENTERPRISE_SERVER = 0x0000000A # Server Enterprise (full installation)
84
+ PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E # Server Enterprise (core installation)
85
+ PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029 # Server Enterprise without Hyper-V (core installation)
86
+ PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F # Server Enterprise for Itanium-based Systems
87
+ PRODUCT_ENTERPRISE_SERVER_V = 0x00000026 # Server Enterprise without Hyper-V (full installation)
88
+ PRODUCT_HOME_BASIC = 0x00000002 # Home Basic
89
+ PRODUCT_HOME_BASIC_E = 0x00000043 # Not supported
90
+ PRODUCT_HOME_BASIC_N = 0x00000005 # Home Basic N
91
+ PRODUCT_HOME_PREMIUM = 0x00000003 # Home Premium
92
+ PRODUCT_HOME_PREMIUM_E = 0x00000044 # Not supported
93
+ PRODUCT_HOME_PREMIUM_N = 0x0000001A # Home Premium N
94
+ PRODUCT_HYPERV = 0x0000002A # Microsoft Hyper-V Server
95
+ PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E # Windows Essential Business Server Management Server
96
+ PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020 # Windows Essential Business Server Messaging Server
97
+ PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F # Windows Essential Business Server Security Server
98
+ PRODUCT_PROFESSIONAL = 0x00000030 # Professional
99
+ PRODUCT_PROFESSIONAL_E = 0x00000045 # Not supported
100
+ PRODUCT_PROFESSIONAL_N = 0x00000031 # Professional N
101
+ PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018 # Windows Server 2008 for Windows Essential Server Solutions
102
+ PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023 # Windows Server 2008 without Hyper-V for Windows Essential Server Solutions
103
+ PRODUCT_SERVER_FOUNDATION = 0x00000021 # Server Foundation
104
+ PRODUCT_HOME_PREMIUM_SERVER = 0x00000022 # Windows Home Server 2011
105
+ PRODUCT_SB_SOLUTION_SERVER = 0x00000032 # Windows Small Business Server 2011 Essentials
106
+ PRODUCT_HOME_SERVER = 0x00000013 # Windows Storage Server 2008 R2 Essentials
107
+ PRODUCT_SMALLBUSINESS_SERVER = 0x00000009 # Windows Small Business Server
108
+ PRODUCT_SOLUTION_EMBEDDEDSERVER = 0x00000038 # Windows MultiPoint Server
109
+ PRODUCT_STANDARD_SERVER = 0x00000007 # Server Standard (full installation)
110
+ PRODUCT_STANDARD_SERVER_CORE = 0x0000000D # Server Standard (core installation)
111
+ PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028 # Server Standard without Hyper-V (core installation)
112
+ PRODUCT_STANDARD_SERVER_V = 0x00000024 # Server Standard without Hyper-V (full installation)
113
+ PRODUCT_STARTER = 0x0000000B # Starter
114
+ PRODUCT_STARTER_E = 0x00000042 # Not supported
115
+ PRODUCT_STARTER_N = 0x0000002F # Starter N
116
+ PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017 # Storage Server Enterprise
117
+ PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014 # Storage Server Express
118
+ PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015 # Storage Server Standard
119
+ PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016 # Storage Server Workgroup
120
+ PRODUCT_UNDEFINED = 0x00000000 # An unknown product
121
+ PRODUCT_ULTIMATE = 0x00000001 # Ultimate
122
+ PRODUCT_ULTIMATE_E = 0x00000047 # Not supported
123
+ PRODUCT_ULTIMATE_N = 0x0000001C # Ultimate N
124
+ PRODUCT_WEB_SERVER = 0x00000011 # Web Server (full installation)
125
+ PRODUCT_WEB_SERVER_CORE = 0x0000001D # Web Server (core installation)
126
+
127
+ # GetSystemMetrics
128
+ # The build number if the system is Windows Server 2003 R2; otherwise, 0.
129
+ SM_SERVERR2 = 89
130
+
131
+ ###############################################
132
+ # Win32 API Bindings
133
+ ###############################################
134
+
135
+ ffi_lib 'kernel32', 'user32'
136
+
137
+ class OSVERSIONINFOEX < FFI::Struct
138
+ layout :dw_os_version_info_size, :DWORD,
139
+ :dw_major_version, :DWORD,
140
+ :dw_minor_version, :DWORD,
141
+ :dw_build_number, :DWORD,
142
+ :dw_platform_id, :DWORD,
143
+ :sz_csd_version, [:BYTE, 256],
144
+ :w_service_pack_major, :WORD,
145
+ :w_service_pack_minor, :WORD,
146
+ :w_suite_mask, :WORD,
147
+ :w_product_type, :BYTE,
148
+ :w_reserved, :BYTE
149
+ end
150
+
151
+ =begin
152
+ BOOL WINAPI CloseHandle(
153
+ __in HANDLE hObject
154
+ );
155
+ =end
156
+ attach_function :CloseHandle, [ :HANDLE ], :BOOL
157
+
158
+ =begin
159
+ DWORD WINAPI GetVersion(void);
160
+ =end
161
+ attach_function :GetVersion, [], :DWORD
162
+
163
+ =begin
164
+ BOOL WINAPI GetVersionEx(
165
+ __inout LPOSVERSIONINFO lpVersionInfo
166
+ );
167
+ =end
168
+ attach_function :GetVersionExW, [:pointer], :BOOL
169
+ attach_function :GetVersionExA, [:pointer], :BOOL
170
+
171
+ =begin
172
+ BOOL WINAPI GetProductInfo(
173
+ __in DWORD dwOSMajorVersion,
174
+ __in DWORD dwOSMinorVersion,
175
+ __in DWORD dwSpMajorVersion,
176
+ __in DWORD dwSpMinorVersion,
177
+ __out PDWORD pdwReturnedProductType
178
+ );
179
+ =end
180
+ attach_function :GetProductInfo, [:DWORD, :DWORD, :DWORD, :DWORD, :PDWORD], :BOOL
181
+
182
+ =begin
183
+ int WINAPI GetSystemMetrics(
184
+ __in int nIndex
185
+ );
186
+ =end
187
+ attach_function :GetSystemMetrics, [:int], :int
188
+
189
+ end
190
+ end
191
+ end
192
+ end