Search in sources :

Example 1 with PACLByReference

use of com.sun.jna.platform.win32.WinNT.PACLByReference in project jna by java-native-access.

the class Advapi32Test method testSetGetSecurityDescriptorDacl.

public void testSetGetSecurityDescriptorDacl() throws IOException {
    SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
    assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
    ACL pAcl;
    int cbAcl = 0;
    PSID pSid = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
    IntByReference cbSid = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
    assertTrue("Failed to create well-known SID", Advapi32.INSTANCE.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinBuiltinAdministratorsSid, null, pSid, cbSid));
    int sidLength = Advapi32.INSTANCE.GetLengthSid(pSid);
    cbAcl = Native.getNativeSize(ACL.class, null);
    cbAcl += Native.getNativeSize(ACCESS_ALLOWED_ACE.class, null);
    cbAcl += (sidLength - DWORD.SIZE);
    cbAcl = Advapi32Util.alignOnDWORD(cbAcl);
    pAcl = new ACL(cbAcl);
    assertTrue(Advapi32.INSTANCE.InitializeAcl(pAcl, cbAcl, WinNT.ACL_REVISION));
    assertTrue(Advapi32.INSTANCE.AddAccessAllowedAce(pAcl, WinNT.ACL_REVISION, WinNT.STANDARD_RIGHTS_ALL, pSid));
    assertTrue(Advapi32.INSTANCE.SetSecurityDescriptorDacl(sd, true, pAcl, false));
    BOOLByReference lpbDaclPresent = new BOOLByReference();
    BOOLByReference lpbDaclDefaulted = new BOOLByReference();
    PACLByReference pDacl = new PACLByReference();
    assertTrue(Advapi32.INSTANCE.GetSecurityDescriptorDacl(sd, lpbDaclPresent, pDacl, lpbDaclDefaulted));
    ACL pAclGet = pDacl.getValue();
    assertEquals(new BOOL(true), lpbDaclPresent.getValue());
    assertEquals(new BOOL(false), lpbDaclDefaulted.getValue());
    assertEquals(1, pAclGet.AceCount);
    assertEquals(WinNT.ACL_REVISION, pAclGet.AclRevision);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) ACCESS_ALLOWED_ACE(com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) BOOL(com.sun.jna.platform.win32.WinDef.BOOL) SECURITY_DESCRIPTOR(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR) PACLByReference(com.sun.jna.platform.win32.WinNT.PACLByReference) ACL(com.sun.jna.platform.win32.WinNT.ACL) PSID(com.sun.jna.platform.win32.WinNT.PSID)

Aggregations

BOOL (com.sun.jna.platform.win32.WinDef.BOOL)1 BOOLByReference (com.sun.jna.platform.win32.WinDef.BOOLByReference)1 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)1 ACL (com.sun.jna.platform.win32.WinNT.ACL)1 PACLByReference (com.sun.jna.platform.win32.WinNT.PACLByReference)1 PSID (com.sun.jna.platform.win32.WinNT.PSID)1 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)1 IntByReference (com.sun.jna.ptr.IntByReference)1