Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Win32API struct member help

Reply
Thread Tools

Win32API struct member help

 
 
Daniel Berger
Guest
Posts: n/a
 
      03-18-2006
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:

http://msdn.microsoft.com/library/de...curity/acl.asp

Thanks,

Dan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Help: How to pass a struct as a pointer to Win32API? Jing Li Ruby 3 07-27-2010 08:40 AM
Using an instance of a struct as a member of that struct dutchgoldtony C Programming 15 11-16-2005 11:24 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments