Win32API struct member help

Discussion in 'Ruby' started by Daniel Berger, Mar 18, 2006.

  1. 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/default.asp?url=/library/en-us/secauthz/security/acl.asp

    Thanks,

    Dan
    Daniel Berger, Mar 18, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Angus Comber
    Replies:
    7
    Views:
    1,152
    Richard Heathfield
    Feb 5, 2004
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,371
    Chris Fogelklou
    Apr 20, 2004
  3. dutchgoldtony
    Replies:
    15
    Views:
    468
    Mike Wahler
    Nov 16, 2005
  4. pete142
    Replies:
    5
    Views:
    443
    Ben Bacarisse
    Jan 23, 2008
  5. Jing Li
    Replies:
    3
    Views:
    233
    Heesob Park
    Jul 27, 2010
Loading...

Share This Page