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,125 @@
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/security'
20
+ require 'chef/win32/security/sid'
21
+ require 'chef/win32/memory'
22
+
23
+ require 'ffi'
24
+
25
+ class Chef
26
+ module Win32
27
+ class Security
28
+ class ACE
29
+
30
+ def initialize(pointer, owner = nil)
31
+ if Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.supports?(pointer.read_uchar)
32
+ @struct = Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.new pointer
33
+ else
34
+ # TODO Support ALL the things
35
+ @struct = Chef::Win32::API::Security::ACE_HEADER.new pointer
36
+ end
37
+ # Keep a reference to the actual owner of this memory so we don't get freed
38
+ @owner = owner
39
+ end
40
+
41
+ def self.size_with_sid(sid)
42
+ Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.offset_of(:SidStart) + sid.size
43
+ end
44
+
45
+ def self.access_allowed(sid, mask, flags = 0)
46
+ create_ace_with_mask_and_sid(Chef::Win32::API::Security::ACCESS_ALLOWED_ACE_TYPE, flags, mask, sid)
47
+ end
48
+
49
+ def self.access_denied(sid, mask, flags = 0)
50
+ create_ace_with_mask_and_sid(Chef::Win32::API::Security::ACCESS_DENIED_ACE_TYPE, flags, mask, sid)
51
+ end
52
+
53
+ attr_reader :struct
54
+
55
+ def ==(other)
56
+ type == other.type && flags == other.flags && mask == other.mask && sid == other.sid
57
+ end
58
+
59
+ def dup
60
+ ACE.create_ace_with_mask_and_sid(type, flags, mask, sid)
61
+ end
62
+
63
+ def flags
64
+ struct[:AceFlags]
65
+ end
66
+
67
+ def flags=(val)
68
+ struct[:AceFlags] = val
69
+ end
70
+
71
+ def explicit?
72
+ ! inherited?
73
+ end
74
+
75
+ def inherited?
76
+ (struct[:AceFlags] & Chef::Win32::API::Security::INHERITED_ACE) != 0
77
+ end
78
+
79
+ def mask
80
+ struct[:Mask]
81
+ end
82
+
83
+ def mask=(val)
84
+ struct[:Mask] = val
85
+ end
86
+
87
+ def pointer
88
+ struct.pointer
89
+ end
90
+
91
+ def size
92
+ struct[:AceSize]
93
+ end
94
+
95
+ def sid
96
+ # The SID runs off the end of the structure, starting at :SidStart.
97
+ # Use pointer arithmetic to get a pointer to that location.
98
+ Chef::Win32::Security::SID.new(struct.pointer + struct.offset_of(:SidStart))
99
+ end
100
+
101
+ def to_s
102
+ "#{sid.account_name}/flags:#{flags.to_s(16)}/mask:#{mask.to_s(16)}"
103
+ end
104
+
105
+ def type
106
+ struct[:AceType]
107
+ end
108
+
109
+ private
110
+
111
+ def self.create_ace_with_mask_and_sid(type, flags, mask, sid)
112
+ size_needed = size_with_sid(sid)
113
+ pointer = FFI::MemoryPointer.new size_needed
114
+ struct = Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.new pointer
115
+ struct[:AceType] = type
116
+ struct[:AceFlags] = flags
117
+ struct[:AceSize] = size_needed
118
+ struct[:Mask] = mask
119
+ Chef::Win32::Memory.memcpy(struct.pointer + struct.offset_of(:SidStart), sid.pointer, sid.size)
120
+ ACE.new(struct.pointer)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,101 @@
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/security'
20
+ require 'chef/win32/security/ace'
21
+ require 'ffi'
22
+
23
+ class Chef
24
+ module Win32
25
+ class Security
26
+ class ACL
27
+ include Enumerable
28
+
29
+ def initialize(pointer, owner = nil)
30
+ @struct = Chef::Win32::API::Security::ACLStruct.new pointer
31
+ # Keep a reference to the actual owner of this memory so that it isn't freed out from under us
32
+ # TODO this could be avoided if we could mark a pointer's parent manually
33
+ @owner = owner
34
+ end
35
+
36
+ def self.create(aces)
37
+ aces_size = aces.inject(0) { |sum,ace| sum + ace.size }
38
+ acl_size = align_dword(Chef::Win32::API::Security::ACLStruct.size + aces_size) # What the heck is 94???
39
+ acl = Chef::Win32::Security.initialize_acl(acl_size)
40
+ aces.each { |ace| Chef::Win32::Security.add_ace(acl, ace) }
41
+ acl
42
+ end
43
+
44
+ attr_reader :struct
45
+
46
+ def ==(other)
47
+ return false if length != other.length
48
+ 0.upto(length-1) do |i|
49
+ return false if self[i] != other[i]
50
+ end
51
+ return true
52
+ end
53
+
54
+ def pointer
55
+ struct.pointer
56
+ end
57
+
58
+ def [](index)
59
+ Chef::Win32::Security.get_ace(self, index)
60
+ end
61
+
62
+ def delete_at(index)
63
+ Chef::Win32::Security.delete_ace(self, index)
64
+ end
65
+
66
+ def each
67
+ 0.upto(length-1) { |i| yield self[i] }
68
+ end
69
+
70
+ def insert(index, *aces)
71
+ aces.reverse_each { |ace| add_ace(self, ace, index) }
72
+ end
73
+
74
+ def length
75
+ struct[:AceCount]
76
+ end
77
+
78
+ def push(*aces)
79
+ aces.each { |ace| Chef::Win32::Security.add_ace(self, ace) }
80
+ end
81
+
82
+ def unshift(*aces)
83
+ aces.each { |ace| Chef::Win32::Security.add_ace(self, ace, 0) }
84
+ end
85
+
86
+ def valid?
87
+ Chef::Win32::Security.is_valid_acl(self)
88
+ end
89
+
90
+ def to_s
91
+ "[#{self.collect { |ace| ace.to_s }.join(", ")}]"
92
+ end
93
+ private
94
+
95
+ def self.align_dword(size)
96
+ (size + 4 - 1) & 0xfffffffc
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,109 @@
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/security'
20
+ require 'chef/win32/security/acl'
21
+ require 'chef/win32/security/sid'
22
+
23
+ class Chef
24
+ module Win32
25
+ class Security
26
+ class SecurableObject
27
+
28
+ def initialize(path, type = :SE_FILE_OBJECT)
29
+ @path = path
30
+ @type = type
31
+ end
32
+
33
+ attr_reader :path
34
+ attr_reader :type
35
+
36
+ SecurityConst = Chef::Win32::API::Security
37
+
38
+ # This method predicts what the rights mask would be on an object
39
+ # if you created an ACE with the given mask. Specifically, it looks for
40
+ # generic attributes like GENERIC_READ, and figures out what specific
41
+ # attributes will be set. This is important if you want to try to
42
+ # compare an existing ACE with one you want to create.
43
+ def predict_rights_mask(generic_mask)
44
+ mask = generic_mask
45
+ #mask |= Chef::Win32::API::Security::STANDARD_RIGHTS_READ if (mask | Chef::Win32::API::Security::GENERIC_READ) != 0
46
+ #mask |= Chef::Win32::API::Security::STANDARD_RIGHTS_WRITE if (mask | Chef::Win32::API::Security::GENERIC_WRITE) != 0
47
+ #mask |= Chef::Win32::API::Security::STANDARD_RIGHTS_EXECUTE if (mask | Chef::Win32::API::Security::GENERIC_EXECUTE) != 0
48
+ #mask |= Chef::Win32::API::Security::STANDARD_RIGHTS_ALL if (mask | Chef::Win32::API::Security::GENERIC_ALL) != 0
49
+ if type == :SE_FILE_OBJECT
50
+ mask |= Chef::Win32::API::Security::FILE_GENERIC_READ if (mask & Chef::Win32::API::Security::GENERIC_READ) != 0
51
+ mask |= Chef::Win32::API::Security::FILE_GENERIC_WRITE if (mask & Chef::Win32::API::Security::GENERIC_WRITE) != 0
52
+ mask |= Chef::Win32::API::Security::FILE_GENERIC_EXECUTE if (mask & Chef::Win32::API::Security::GENERIC_EXECUTE) != 0
53
+ mask |= Chef::Win32::API::Security::FILE_ALL_ACCESS if (mask & Chef::Win32::API::Security::GENERIC_ALL) != 0
54
+ else
55
+ raise "Unimplemented object type for predict_security_mask: #{type}"
56
+ end
57
+ mask &= ~(Chef::Win32::API::Security::GENERIC_READ | Chef::Win32::API::Security::GENERIC_WRITE | Chef::Win32::API::Security::GENERIC_EXECUTE | Chef::Win32::API::Security::GENERIC_ALL)
58
+ mask
59
+ end
60
+
61
+ def security_descriptor(include_sacl = false)
62
+ security_information = Chef::Win32::API::Security::OWNER_SECURITY_INFORMATION | Chef::Win32::API::Security::GROUP_SECURITY_INFORMATION | Chef::Win32::API::Security::DACL_SECURITY_INFORMATION
63
+ if include_sacl
64
+ security_information |= Chef::Win32::API::Security::SACL_SECURITY_INFORMATION
65
+ Security.with_privileges("SeSecurityPrivilege") do
66
+ Security.get_named_security_info(path, type, security_information)
67
+ end
68
+ else
69
+ Security.get_named_security_info(path, type, security_information)
70
+ end
71
+ end
72
+
73
+ def dacl=(val)
74
+ Security.set_named_security_info(path, type, :dacl => val)
75
+ end
76
+
77
+ # You don't set dacl_inherits without also setting dacl,
78
+ # because Windows gets angry and denies you access. So
79
+ # if you want to do that, you may as well do both at once.
80
+ def set_dacl(dacl, dacl_inherits)
81
+ Security.set_named_security_info(path, type, :dacl => dacl, :dacl_inherits => dacl_inherits)
82
+ end
83
+
84
+ def group=(val)
85
+ Security.set_named_security_info(path, type, :group => val)
86
+ end
87
+
88
+ def owner=(val)
89
+ # TODO to fix serious permissions problems, we may need to enable SeBackupPrivilege. But we might need it (almost) everywhere else, too.
90
+ Security.with_privileges("SeTakeOwnershipPrivilege", "SeRestorePrivilege") do
91
+ Security.set_named_security_info(path, type, :owner => val)
92
+ end
93
+ end
94
+
95
+ def sacl=(val)
96
+ Security.with_privileges("SeSecurityPrivilege") do
97
+ Security.set_named_security_info(path, type, :sacl => val)
98
+ end
99
+ end
100
+
101
+ def set_sacl(sacl, sacl_inherits)
102
+ Security.with_privileges("SeSecurityPrivilege") do
103
+ Security.set_named_security_info(path, type, :sacl => sacl, :sacl_inherits => sacl_inherits)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,93 @@
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/security'
20
+ require 'chef/win32/security/acl'
21
+ require 'chef/win32/security/sid'
22
+
23
+ class Chef
24
+ module Win32
25
+ class Security
26
+ class SecurityDescriptor
27
+
28
+ def initialize(pointer)
29
+ @pointer = pointer
30
+ end
31
+
32
+ attr_reader :pointer
33
+
34
+ def absolute?
35
+ !self_relative?
36
+ end
37
+
38
+ def control
39
+ control, version = Chef::Win32::Security.get_security_descriptor_control(self)
40
+ control
41
+ end
42
+
43
+ def dacl
44
+ raise "DACL not present" if !dacl_present?
45
+ present, acl, defaulted = Chef::Win32::Security.get_security_descriptor_dacl(self)
46
+ acl
47
+ end
48
+
49
+ def dacl_inherits?
50
+ (control & Chef::Win32::API::Security::SE_DACL_PROTECTED) == 0
51
+ end
52
+
53
+ def dacl_present?
54
+ (control & Chef::Win32::API::Security::SE_DACL_PRESENT) != 0
55
+ end
56
+
57
+ def group
58
+ result, defaulted = Chef::Win32::Security.get_security_descriptor_group(self)
59
+ result
60
+ end
61
+
62
+ def owner
63
+ result, defaulted = Chef::Win32::Security.get_security_descriptor_owner(self)
64
+ result
65
+ end
66
+
67
+ def sacl
68
+ raise "SACL not present" if !sacl_present?
69
+ Security.with_privileges("SeSecurityPrivilege") do
70
+ present, acl, defaulted = Chef::Win32::Security.get_security_descriptor_sacl(self)
71
+ acl
72
+ end
73
+ end
74
+
75
+ def sacl_inherits?
76
+ (control & Chef::Win32::API::Security::SE_SACL_PROTECTED) == 0
77
+ end
78
+
79
+ def sacl_present?
80
+ (control & Chef::Win32::API::Security::SE_SACL_PRESENT) != 0
81
+ end
82
+
83
+ def self_relative?
84
+ (control & Chef::Win32::API::Security::SE_SELF_RELATIVE) != 0
85
+ end
86
+
87
+ def valid?
88
+ Chef::Win32::Security.is_valid_security_descriptor(self)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,199 @@
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/security'
20
+
21
+ class Chef
22
+ module Win32
23
+ class Security
24
+ class SID
25
+
26
+ def initialize(pointer, owner = nil)
27
+ @pointer = pointer
28
+ # Keep a reference to the actual owner of this memory so we don't get freed
29
+ @owner = owner
30
+ end
31
+
32
+ def self.from_account(name)
33
+ domain, sid, use = Chef::Win32::Security.lookup_account_name(name)
34
+ sid
35
+ end
36
+
37
+ def self.from_string_sid(string_sid)
38
+ Chef::Win32::Security::convert_string_sid_to_sid(string_sid)
39
+ end
40
+
41
+ def ==(other)
42
+ other != nil && Chef::Win32::Security.equal_sid(self, other)
43
+ end
44
+
45
+ attr_reader :pointer
46
+
47
+ def account
48
+ Chef::Win32::Security.lookup_account_sid(self)
49
+ end
50
+
51
+ def account_name
52
+ domain, name, use = account
53
+ (domain != nil && domain.length > 0) ? "#{domain}\\#{name}" : name
54
+ end
55
+
56
+ def size
57
+ Chef::Win32::Security.get_length_sid(self)
58
+ end
59
+
60
+ def to_s
61
+ Chef::Win32::Security.convert_sid_to_string_sid(self)
62
+ end
63
+
64
+ def valid?
65
+ Chef::Win32::Security.is_valid_sid(self)
66
+ end
67
+
68
+ # Well-known SIDs
69
+ def self.Null
70
+ SID.from_string_sid('S-1-0')
71
+ end
72
+ def self.Nobody
73
+ SID.from_string_sid('S-1-0-0')
74
+ end
75
+ def self.World
76
+ SID.from_string_sid('S-1-1')
77
+ end
78
+ def self.Everyone
79
+ SID.from_string_sid('S-1-1-0')
80
+ end
81
+ def self.Local
82
+ SID.from_string_sid('S-1-2')
83
+ end
84
+ def self.Creator
85
+ SID.from_string_sid('S-1-3')
86
+ end
87
+ def self.CreatorOwner
88
+ SID.from_string_sid('S-1-3-0')
89
+ end
90
+ def self.CreatorGroup
91
+ SID.from_string_sid('S-1-3-1')
92
+ end
93
+ def self.CreatorOwnerServer
94
+ SID.from_string_sid('S-1-3-2')
95
+ end
96
+ def self.CreatorGroupServer
97
+ SID.from_string_sid('S-1-3-3')
98
+ end
99
+ def self.NonUnique
100
+ SID.from_string_sid('S-1-4')
101
+ end
102
+ def self.Nt
103
+ SID.from_string_sid('S-1-5')
104
+ end
105
+ def self.Dialup
106
+ SID.from_string_sid('S-1-5-1')
107
+ end
108
+ def self.Network
109
+ SID.from_string_sid('S-1-5-2')
110
+ end
111
+ def self.Batch
112
+ SID.from_string_sid('S-1-5-3')
113
+ end
114
+ def self.Interactive
115
+ SID.from_string_sid('S-1-5-4')
116
+ end
117
+ def self.Service
118
+ SID.from_string_sid('S-1-5-6')
119
+ end
120
+ def self.Anonymous
121
+ SID.from_string_sid('S-1-5-7')
122
+ end
123
+ def self.Proxy
124
+ SID.from_string_sid('S-1-5-8')
125
+ end
126
+ def self.EnterpriseDomainControllers
127
+ SID.from_string_sid('S-1-5-9')
128
+ end
129
+ def self.PrincipalSelf
130
+ SID.from_string_sid('S-1-5-10')
131
+ end
132
+ def self.AuthenticatedUsers
133
+ SID.from_string_sid('S-1-5-11')
134
+ end
135
+ def self.RestrictedCode
136
+ SID.from_string_sid('S-1-5-12')
137
+ end
138
+ def self.TerminalServerUsers
139
+ SID.from_string_sid('S-1-5-13')
140
+ end
141
+ def self.LocalSystem
142
+ SID.from_string_sid('S-1-5-18')
143
+ end
144
+ def self.NtLocal
145
+ SID.from_string_sid('S-1-5-19')
146
+ end
147
+ def self.NtNetwork
148
+ SID.from_string_sid('S-1-5-20')
149
+ end
150
+ def self.BuiltinAdministrators
151
+ SID.from_string_sid('S-1-5-32-544')
152
+ end
153
+ def self.BuiltinUsers
154
+ SID.from_string_sid('S-1-5-32-545')
155
+ end
156
+ def self.Guests
157
+ SID.from_string_sid('S-1-5-32-546')
158
+ end
159
+ def self.PowerUsers
160
+ SID.from_string_sid('S-1-5-32-547')
161
+ end
162
+ def self.AccountOperators
163
+ SID.from_string_sid('S-1-5-32-548')
164
+ end
165
+ def self.ServerOperators
166
+ SID.from_string_sid('S-1-5-32-549')
167
+ end
168
+ def self.PrintOperators
169
+ SID.from_string_sid('S-1-5-32-550')
170
+ end
171
+ def self.BackupOperators
172
+ SID.from_string_sid('S-1-5-32-551')
173
+ end
174
+ def self.Replicators
175
+ SID.from_string_sid('S-1-5-32-552')
176
+ end
177
+ def self.Administrators
178
+ SID.from_string_sid('S-1-5-32-544')
179
+ end
180
+
181
+ # Machine-specific, well-known SIDs
182
+ # TODO: don't use strings, dummy
183
+ def self.None
184
+ SID.from_account("#{::ENV['COMPUTERNAME']}\\None")
185
+ end
186
+ def self.Administrator
187
+ SID.from_account("#{::ENV['COMPUTERNAME']}\\Administrator")
188
+ end
189
+ def self.Guest
190
+ SID.from_account("#{::ENV['COMPUTERNAME']}\\Guest")
191
+ end
192
+
193
+ def self.current_user
194
+ SID.from_account("#{::ENV['USERDOMAIN']}\\#{::ENV['USERNAME']}")
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end