use of com.sun.jna.platform.win32.WinNT.PSIDByReference in project jna by java-native-access.
the class Advapi32Test method testEqualSid.
public void testEqualSid() {
String sidString = EVERYONE;
PSIDByReference sid1 = new PSIDByReference();
PSIDByReference sid2 = new PSIDByReference();
assertTrue("SID1 conversion failed", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid1));
assertTrue("SID2 conversion failed", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid2));
try {
assertTrue("Converted SID1 not valid", Advapi32.INSTANCE.IsValidSid(sid1.getValue()));
assertTrue("Converted SID2 not valid", Advapi32.INSTANCE.IsValidSid(sid2.getValue()));
assertTrue("Invalid sid", Advapi32.INSTANCE.EqualSid(sid1.getValue(), sid2.getValue()));
} finally {
Kernel32Util.freeLocalMemory(sid1.getValue().getPointer());
Kernel32Util.freeLocalMemory(sid2.getValue().getPointer());
}
}
use of com.sun.jna.platform.win32.WinNT.PSIDByReference in project jna by java-native-access.
the class Advapi32Test method testConvertSid.
public void testConvertSid() {
String sidString = EVERYONE;
PSIDByReference sid = new PSIDByReference();
assertTrue("Failed to convert SID string", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
PSID value = sid.getValue();
try {
PointerByReference convertedSidStringPtr = new PointerByReference();
assertTrue("Failed to convert SID string", Advapi32.INSTANCE.ConvertSidToStringSid(value, convertedSidStringPtr));
Pointer conv = convertedSidStringPtr.getValue();
try {
String convertedSidString = conv.getWideString(0);
assertEquals("Mismatched SID string", convertedSidString, sidString);
} finally {
Kernel32Util.freeLocalMemory(conv);
}
} finally {
Kernel32Util.freeLocalMemory(value.getPointer());
}
}
use of com.sun.jna.platform.win32.WinNT.PSIDByReference in project jna by java-native-access.
the class Advapi32Test method testGetSidLength.
public void testGetSidLength() {
String sidString = EVERYONE;
PSIDByReference sid = new PSIDByReference();
assertTrue("SID conversion failed", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
PSID value = sid.getValue();
try {
assertEquals("Wrong SID length", 12, Advapi32.INSTANCE.GetLengthSid(value));
} finally {
Kernel32Util.freeLocalMemory(value.getPointer());
}
}
use of com.sun.jna.platform.win32.WinNT.PSIDByReference in project jna by java-native-access.
the class Advapi32Test method testLookupAccountSid.
public void testLookupAccountSid() {
// get SID bytes
String sidString = EVERYONE;
PSIDByReference sid = new PSIDByReference();
assertTrue("Failed to create sid", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
PSID value = sid.getValue();
try {
int sidLength = Advapi32.INSTANCE.GetLengthSid(value);
assertTrue("Non-positive sid length", sidLength > 0);
// lookup account
IntByReference cchName = new IntByReference();
IntByReference cchReferencedDomainName = new IntByReference();
PointerByReference peUse = new PointerByReference();
assertFalse(Advapi32.INSTANCE.LookupAccountSid(null, value, null, cchName, null, cchReferencedDomainName, peUse));
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
assertTrue(cchName.getValue() > 0);
assertTrue(cchReferencedDomainName.getValue() > 0);
char[] referencedDomainName = new char[cchReferencedDomainName.getValue()];
char[] name = new char[cchName.getValue()];
assertTrue(Advapi32.INSTANCE.LookupAccountSid(null, value, name, cchName, referencedDomainName, cchReferencedDomainName, peUse));
// SidTypeWellKnownGroup
assertEquals(5, peUse.getPointer().getInt(0));
String nameString = Native.toString(name);
String referencedDomainNameString = Native.toString(referencedDomainName);
assertTrue(nameString.length() > 0);
if (AbstractWin32TestSupport.isEnglishLocale) {
assertEquals("Everyone", nameString);
}
assertTrue(referencedDomainNameString.length() == 0);
} finally {
Kernel32Util.freeLocalMemory(value.getPointer());
}
}
use of com.sun.jna.platform.win32.WinNT.PSIDByReference in project jna by java-native-access.
the class Advapi32Test method testIsValidSid.
public void testIsValidSid() {
String sidString = EVERYONE;
PSIDByReference sid = new PSIDByReference();
assertTrue("SID conversion failed", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
PSID value = sid.getValue();
try {
assertTrue("Converted SID not valid: " + value, Advapi32.INSTANCE.IsValidSid(value));
int sidLength = Advapi32.INSTANCE.GetLengthSid(value);
assertTrue("Non positive sid length", sidLength > 0);
assertTrue("Invalid sid", Advapi32.INSTANCE.IsValidSid(value));
} finally {
Kernel32Util.freeLocalMemory(value.getPointer());
}
}
Aggregations