use of com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR in project jna by java-native-access.
the class Advapi32Test method testMakeAbsoluteSD.
public void testMakeAbsoluteSD() throws Exception {
SECURITY_DESCRIPTOR absolute = new SECURITY_DESCRIPTOR(64 * 1024);
// Get a SD in self relative form
int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
PointerByReference relativeByReference = new PointerByReference();
File file = createTempFile();
try {
try {
assertEquals("GetNamedSecurityInfo(" + file + ")", Advapi32.INSTANCE.GetNamedSecurityInfo(file.getAbsolutePath(), AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, null, null, null, null, relativeByReference), 0);
SECURITY_DESCRIPTOR_RELATIVE relative = new SECURITY_DESCRIPTOR_RELATIVE(relativeByReference.getValue());
PSID pOwner = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
PSID pGroup = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
ACL pDacl = new ACL(ACL.MAX_ACL_SIZE);
ACL pSacl = new ACL(ACL.MAX_ACL_SIZE);
IntByReference lpdwBufferLength = new IntByReference(absolute.size());
IntByReference lpdwDaclSize = new IntByReference(ACL.MAX_ACL_SIZE);
IntByReference lpdwSaclSize = new IntByReference(ACL.MAX_ACL_SIZE);
IntByReference lpdwOwnerSize = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
IntByReference lpdwPrimaryGroupSize = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
assertTrue(Advapi32.INSTANCE.MakeAbsoluteSD(relative, absolute, lpdwBufferLength, pDacl, lpdwDaclSize, pSacl, lpdwSaclSize, pOwner, lpdwOwnerSize, pGroup, lpdwPrimaryGroupSize));
} finally {
file.delete();
}
} finally {
Kernel32Util.freeLocalMemory(relativeByReference.getValue());
}
}
use of com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR 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);
}
use of com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR in project jna by java-native-access.
the class Advapi32Test method testSetGetSecurityDescriptorOwner.
public void testSetGetSecurityDescriptorOwner() {
SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
PSID pSidPut = 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, pSidPut, cbSid));
assertTrue(Advapi32.INSTANCE.SetSecurityDescriptorOwner(sd, pSidPut, true));
BOOLByReference lpbOwnerDefaulted = new BOOLByReference();
PSIDByReference prSd = new PSIDByReference();
assertTrue(Advapi32.INSTANCE.GetSecurityDescriptorOwner(sd, prSd, lpbOwnerDefaulted));
PSID pSidGet = prSd.getValue();
assertTrue(Advapi32.INSTANCE.EqualSid(pSidPut, pSidGet));
}
use of com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR in project jna by java-native-access.
the class Advapi32Test method testSetGetSecurityDescriptorGroup.
public void testSetGetSecurityDescriptorGroup() {
SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
PSID pSidPut = 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, pSidPut, cbSid));
assertTrue(Advapi32.INSTANCE.SetSecurityDescriptorGroup(sd, pSidPut, true));
BOOLByReference lpbOwnerDefaulted = new BOOLByReference();
PSIDByReference prSd = new PSIDByReference();
assertTrue(Advapi32.INSTANCE.GetSecurityDescriptorGroup(sd, prSd, lpbOwnerDefaulted));
PSID pSidGet = prSd.getValue();
assertTrue(Advapi32.INSTANCE.EqualSid(pSidPut, pSidGet));
}
use of com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR in project jna by java-native-access.
the class Advapi32Test method testInitializeSecurityDescriptor.
public void testInitializeSecurityDescriptor() {
SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
}
Aggregations