use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Netapi32Test method testDsEnumerateDomainTrusts.
public void testDsEnumerateDomainTrusts() {
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
return;
IntByReference domainTrustCount = new IntByReference();
PointerByReference domainsPointerRef = new PointerByReference();
assertEquals(W32Errors.NO_ERROR, Netapi32.INSTANCE.DsEnumerateDomainTrusts(null, DsGetDC.DS_DOMAIN_VALID_FLAGS, domainsPointerRef, domainTrustCount));
assertTrue(domainTrustCount.getValue() >= 0);
DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue());
DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]);
for (DS_DOMAIN_TRUSTS trust : domainTrusts) {
assertTrue(trust.DnsDomainName.length() > 0);
assertTrue(Advapi32.INSTANCE.IsValidSid(trust.DomainSid));
assertTrue(Advapi32Util.convertSidToStringSid(trust.DomainSid).startsWith("S-"));
assertTrue(Ole32Util.getStringFromGUID(trust.DomainGuid).startsWith("{"));
}
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(domainTrustRefs.getPointer()));
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testGetTokenUserInformation.
public void testGetTokenUserInformation() {
HANDLEByReference phToken = new HANDLEByReference();
try {
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle, WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
IntByReference tokenInformationLength = new IntByReference();
assertFalse(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(), WinNT.TOKEN_INFORMATION_CLASS.TokenUser, null, 0, tokenInformationLength));
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
WinNT.TOKEN_USER user = new WinNT.TOKEN_USER(tokenInformationLength.getValue());
assertTrue(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(), WinNT.TOKEN_INFORMATION_CLASS.TokenUser, user, tokenInformationLength.getValue(), tokenInformationLength));
assertTrue(tokenInformationLength.getValue() > 0);
assertTrue(Advapi32.INSTANCE.IsValidSid(user.User.Sid));
int sidLength = Advapi32.INSTANCE.GetLengthSid(user.User.Sid);
assertTrue(sidLength > 0);
assertTrue(sidLength < tokenInformationLength.getValue());
// System.out.println(Advapi32Util.convertSidToStringSid(user.User.Sid));
} finally {
Kernel32Util.closeHandleRef(phToken);
}
}
use of com.sun.jna.platform.win32.Advapi32 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());
}
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testRegQueryInfoKey.
public void testRegQueryInfoKey() {
IntByReference lpcClass = new IntByReference();
IntByReference lpcSubKeys = new IntByReference();
IntByReference lpcMaxSubKeyLen = new IntByReference();
IntByReference lpcValues = new IntByReference();
IntByReference lpcMaxClassLen = new IntByReference();
IntByReference lpcMaxValueNameLen = new IntByReference();
IntByReference lpcMaxValueLen = new IntByReference();
IntByReference lpcbSecurityDescriptor = new IntByReference();
FILETIME lpftLastWriteTime = new FILETIME();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(WinReg.HKEY_LOCAL_MACHINE, null, lpcClass, null, lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor, lpftLastWriteTime));
assertTrue(lpcSubKeys.getValue() > 0);
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testRegEnumValue.
public void testRegEnumValue() {
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, WinNT.KEY_READ, phKey));
IntByReference lpcValues = new IntByReference();
IntByReference lpcMaxValueNameLen = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(phKey.getValue(), null, null, null, null, null, null, lpcValues, lpcMaxValueNameLen, null, null, null));
char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
for (int i = 0; i < lpcValues.getValue(); i++) {
IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
IntByReference lpType = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumValue(phKey.getValue(), i, name, lpcchValueName, null, lpType, null, null));
assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
}
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
Aggregations