[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Win32API struct member help

Park Heesob

3/18/2006 7:17:00 AM


Hi,
>
>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'
>
>
...
>
>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?
>
memcpy is required for pointer reference,try this:

memcpy = Win32API.new('msvcrt','memcpy','PLL','P')
acl_buf = "\0" * 8
memcpy.call(acl_buf,acl_ptr.unpack('L')[0],8)
p acl_buf.unpack('CCSSS')

Regards,

Park Heesob




2 Answers

Daniel Berger

3/18/2006 3:32:00 PM

0

Park Heesob wrote:
> Hi,

<snip>

> memcpy is required for pointer reference,try this:
>
> memcpy = Win32API.new('msvcrt','memcpy','PLL','P')
> acl_buf = "\0" * 8
> memcpy.call(acl_buf,acl_ptr.unpack('L')[0],8)
> p acl_buf.unpack('CCSSS')

Excellent, thanks!

Dan

Daniel Berger

3/18/2006 6:08:00 PM

0

Park Heesob wrote:
> Hi,

<snip>

> memcpy is required for pointer reference,try this:
>
> memcpy = Win32API.new('msvcrt','memcpy','PLL','P')
> acl_buf = "\0" * 8
> memcpy.call(acl_buf,acl_ptr.unpack('L')[0],8)
> p acl_buf.unpack('CCSSS')

Ok, along the same lines, I'm having some trouble with GetAce(). Using
'acl_buf' from above:

GetAce = Win32API.new('advapi32', 'GetAce', 'PLP', 'I')

ace_count = acl_buf.unpack('CCSSS')[3] # 4
ace_ptr = [0].pack('L')

0.upto(ace_count - 1){ |i|
if GetAce.call(acl_buf, i, ace_ptr) == 0
next
end

ace_buf = 0.chr * 4 # 2 BYTE, 1 WORD
memcpy.call(ace_buf, ace_ptr.unpack('L').first, 4)

# This doesn't return the values I would have expected
p ace_buf.unpack('CCS')
}

I would have expected somewhere between 20 and 40 for the third element
of the array returned by ace_buf.unpack('CCS'), but instead I'm getting
0. What am I doing wrong this time?

Thanks,

Dan