use of com.sun.jna.ptr.PointerByReference 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.ptr.PointerByReference in project jna by java-native-access.
the class Advapi32Test method testGetSecurityDescriptorLength.
public void testGetSecurityDescriptorLength() throws Exception {
int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
PointerByReference ppSecurityDescriptor = new PointerByReference();
File file = createTempFile();
try {
try {
assertEquals("GetNamedSecurityInfo(" + file + ")", 0, Advapi32.INSTANCE.GetNamedSecurityInfo(file.getAbsolutePath(), AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, null, null, null, null, ppSecurityDescriptor));
assertTrue("GetSecurityDescriptorLength(" + file + ")", Advapi32.INSTANCE.GetSecurityDescriptorLength(ppSecurityDescriptor.getValue()) > 0);
} finally {
file.delete();
}
} finally {
Kernel32Util.freeLocalMemory(ppSecurityDescriptor.getValue());
}
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class Advapi32Test method testSetNamedSecurityInfoForFileNoSACL.
public void testSetNamedSecurityInfoForFileNoSACL() throws Exception {
int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
PointerByReference ppsidOwner = new PointerByReference();
PointerByReference ppsidGroup = new PointerByReference();
PointerByReference ppDacl = new PointerByReference();
PointerByReference ppSecurityDescriptor = new PointerByReference();
// create a temp file
File file = createTempFile();
String filePath = file.getAbsolutePath();
try {
try {
assertEquals("GetNamedSecurityInfo(" + filePath + ")", 0, Advapi32.INSTANCE.GetNamedSecurityInfo(filePath, AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, ppsidOwner, ppsidGroup, ppDacl, null, ppSecurityDescriptor));
assertEquals("SetNamedSecurityInfo(" + filePath + ")", 0, Advapi32.INSTANCE.SetNamedSecurityInfo(filePath, AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, ppsidOwner.getValue(), ppsidGroup.getValue(), ppDacl.getValue(), null));
} finally {
file.delete();
}
} finally {
Kernel32Util.freeLocalMemory(ppSecurityDescriptor.getValue());
}
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class Advapi32Test method testLookupAccountName.
public void testLookupAccountName() {
IntByReference pSid = new IntByReference(0);
IntByReference pDomain = new IntByReference(0);
PointerByReference peUse = new PointerByReference();
String accountName = "Administrator";
assertFalse(Advapi32.INSTANCE.LookupAccountName(null, accountName, null, pSid, null, pDomain, peUse));
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
assertTrue(pSid.getValue() > 0);
Memory sidMemory = new Memory(pSid.getValue());
PSID pSidMemory = new PSID(sidMemory);
char[] referencedDomainName = new char[pDomain.getValue() + 1];
assertTrue(Advapi32.INSTANCE.LookupAccountName(null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
assertTrue(Native.toString(referencedDomainName).length() > 0);
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class ITypeLibTest method testGetTypeComp.
public void testGetTypeComp() {
ITypeLib shellTypeLib = loadShellTypeLib();
PointerByReference pbr = new PointerByReference();
HRESULT hr = shellTypeLib.GetTypeComp(pbr);
// Only check that call works
assertTrue(COMUtils.SUCCEEDED(hr));
}
Aggregations