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);
}
Aggregations