# Win32API struct member help

**URL:** <https://www.ruby-forum.com/t/win32api-struct-member-help/55228>\
**Category:** Ruby\
**Created:** [March 18, 2006, 7:14am UTC](https://www.ruby-forum.com/t/win32api-struct-member-help/55228 "2006-03-18T07:14:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 18, 2006, 7:14am UTC](https://www.ruby-forum.com/t/win32api-struct-member-help/55228/1 "2006-03-18T07:14:16Z")

</div>

Hi all,

I’m trying to figure out how to get the acl attributes of a simple text  
file, and I need a little help getting data out of a struct.  
Specifically, I need to get the AceCount from an access control list  
(ACL struct) after a call to GetSecurityDescriptorDacl(). Here’s what  
I’ve got so far:

require ‘Win32API’

GetFileSecurity =  
Win32API.new(‘advapi32’, ‘GetFileSecurity’, ‘PLPLP’, ‘I’)

GetSecurityDescriptorControl =  
Win32API.new(‘advapi32’, ‘GetSecurityDescriptorControl’, ‘PPP’, ‘I’)

GetSecurityDescriptorDacl =  
Win32API.new(‘advapi32’, ‘GetSecurityDescriptorDacl’, ‘PPPP’, ‘I’)

file = ‘test.txt’ # nothing special about this file

current\_length = 0  
length\_needed = [1].pack(‘L’)  
sec\_buf = ‘’ # 0 length string

loop do  
bool = GetFileSecurity.call(  
file,  
DACL\_SECURITY\_INFORMATION,  
sec\_buf,  
sec\_buf.length,  
length\_needed  
)

if bool == 0 && GetLastError.call != 122  
raise ArgumentError, ‘GetFileSecurity failed’  
end

break if sec\_buf.length \>= length\_needed.unpack(‘L’).first  
sec\_buf += ’ ’ \* length\_needed.unpack(“L”).first  
end

control = [0].pack(‘L’)  
revision = [0].pack(‘L’)

if GetSecurityDescriptorControl.call(sec\_buf, control, revision) == 0  
raise ArgumentError, ‘GetSecurityDescriptorControl failed’  
end

# No DACL exists

if (control.unpack(‘L’).first & 4) == 0  
raise ArgumentError, ‘No DACL present: explicit deny all’  
end

dacl\_present = [0].pack(‘L’)  
dacl\_defaulted = [0].pack(‘L’)

acl\_ptr = [0].pack(‘L’) # what should this be?

val = GetSecurityDescriptorDacl.call(  
sec\_buf,  
dacl\_present,  
acl\_ptr,  
dacl\_defaulted  
)

if val == 0  
raise ArgumentError, ‘GetSecurityDescriptorDacl failed’  
end

p acl\_ptr.unpack(‘CCSSS’) # [228, 50, 632, nil, nil]

I was expecting 4 for the 4th attribute (AceCount). I tried changing  
the initial value of acl\_ptr to [0,0,0,0,0].pack(‘CCSSS’) but that  
didn’t help. What did I do wrong?

For more on ACL structures:

> **[Technical documentation](https://learn.microsoft.com/en-us/docs/)**

Thanks,

Dan
