diff options
Diffstat (limited to 'chef/lib/chef/win32/security/ace.rb')
-rw-r--r-- | chef/lib/chef/win32/security/ace.rb | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/chef/lib/chef/win32/security/ace.rb b/chef/lib/chef/win32/security/ace.rb index 6800c06ead..326b77fc45 100644 --- a/chef/lib/chef/win32/security/ace.rb +++ b/chef/lib/chef/win32/security/ace.rb @@ -24,37 +24,38 @@ require 'ffi' class Chef module Win32 - module Security + class Security class ACE - include Chef::Win32::Memory - include Chef::Win32::Security - def initialize(pointer, owner = nil) - if ACE_WITH_MASK_AND_SID.supports?(pointer.read_uchar) - @struct = ACE_WITH_MASK_AND_SID.new pointer + if Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.supports?(pointer.read_uchar) + @struct = Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.new pointer else # TODO Support ALL the things - @struct = ACE_HEADER.new pointer + @struct = Chef::Win32::API::Security::ACE_HEADER.new pointer end # Keep a reference to the actual owner of this memory so we don't get freed @owner = owner end def self.size_with_sid(sid) - ACE_WITH_MASK_AND_SID.offset_of(:SidStart) + sid.size + Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.offset_of(:SidStart) + sid.size end def self.access_allowed(sid, access_mask, flags = 0) - create_ace_with_mask_and_sid(ACCESS_ALLOWED_ACE_TYPE, flags, access_mask, sid) + create_ace_with_mask_and_sid(Chef::Win32::API::Security::ACCESS_ALLOWED_ACE_TYPE, flags, access_mask, sid) end def self.access_denied(sid, access_mask, flags = 0) - create_ace_with_mask_and_sid(ACCESS_DENIED_ACE_TYPE, flags, access_mask, sid) + create_ace_with_mask_and_sid(Chef::Win32::API::Security::ACCESS_DENIED_ACE_TYPE, flags, access_mask, sid) end attr_reader :struct + def ==(other) + type == other.type && flags == other.flags && access_mask == other.access_mask && sid == other.sid + end + def flags struct[:AceFlags] end @@ -68,7 +69,7 @@ class Chef end def inherited? - (struct[:AceFlags] & INHERITED_ACE) != 0 + (struct[:AceFlags] & Chef::Win32::API::Security::INHERITED_ACE) != 0 end def mask @@ -90,7 +91,7 @@ class Chef def sid # The SID runs off the end of the structure, starting at :SidStart. # Use pointer arithmetic to get a pointer to that location. - SID.new(struct.pointer + struct.offset_of(:SidStart)) + Chef::Win32::Security::SID.new(struct.pointer + struct.offset_of(:SidStart)) end def type @@ -102,12 +103,12 @@ class Chef def self.create_ace_with_mask_and_sid(type, flags, mask, sid) size_needed = size_with_sid(sid) pointer = FFI::MemoryPointer.new size_needed - struct = ACE_WITH_MASK_AND_SID.new pointer + struct = Chef::Win32::API::Security::ACE_WITH_MASK_AND_SID.new pointer struct[:AceType] = type struct[:AceFlags] = flags struct[:AceSize] = size_needed struct[:Mask] = mask - memcpy(struct.pointer + struct.offset_of(:SidStart), sid.pointer, sid.size) + Chef::Win32::Memory.memcpy(struct.pointer + struct.offset_of(:SidStart), sid.pointer, sid.size) ACE.new(struct.pointer) end end |