diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-02-11 14:27:12 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2015-02-17 09:24:44 -0500 |
commit | 9fbb05e449ba74fd35df40ddbea32efbdeb3f50e (patch) | |
tree | 4b61480795e60d9ecea58e9924f2adc046e1d195 /lib/chef/win32/security.rb | |
parent | a0e367d816e869bb13513a8cb95e90ae85899a4f (diff) | |
download | chef-9fbb05e449ba74fd35df40ddbea32efbdeb3f50e.tar.gz |
Added GetFileSecurity
Diffstat (limited to 'lib/chef/win32/security.rb')
-rw-r--r-- | lib/chef/win32/security.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 48ca78647f..61f71256e8 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -148,6 +148,24 @@ class Chef GetLengthSid(sid) end + def self.get_file_security(path, info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION) + size_ptr = FFI::MemoryPointer.new(:ulong) + + success = GetFileSecurityW(path.to_wstring, info, nil, 0, size_ptr) + + if !success && FFI::LastError.error != ERROR_INSUFFICIENT_BUFFER + Chef::ReservedNames::Win32::Error.raise! + end + + security_descriptor_ptr = FFI::MemoryPointer.new(size_ptr.read_ulong) + unless GetFileSecurityW(path.to_wstring, info, security_descriptor_ptr, size_ptr.read_ulong, size_ptr) + Chef::ReservedNames::Win32::Error.raise! + end + + SecurityDescriptor.new(security_descriptor_ptr) + end + + def self.get_named_security_info(path, type = :SE_FILE_OBJECT, info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION) security_descriptor = FFI::MemoryPointer.new :pointer hr = GetNamedSecurityInfoW(path.to_wstring, type, info, nil, nil, nil, nil, security_descriptor) |