use of com.sun.jna.platform.win32.WinNT.HANDLEByReference in project jna by java-native-access.
the class Rasapi32Util method dialEntry.
/**
* Dial a phone book entry by name (Asynchronously - callback type 2)
* @param entryName The phone book entry name
* @param func2
* @return the HRASCONN for this connection
* @throws Ras32Exception errors
*/
public static HANDLE dialEntry(String entryName, RasDialFunc2 func2) throws Ras32Exception {
// get the RAS Credentials
RASCREDENTIALS.ByReference credentials = new RASCREDENTIALS.ByReference();
synchronized (phoneBookMutex) {
credentials.dwMask = WinRas.RASCM_UserName | WinRas.RASCM_Password | WinRas.RASCM_Domain;
int err = Rasapi32.INSTANCE.RasGetCredentials(null, entryName, credentials);
if (err != WinError.ERROR_SUCCESS)
throw new Ras32Exception(err);
}
// set the dialing parameters
RASDIALPARAMS.ByReference rasDialParams = new RASDIALPARAMS.ByReference();
System.arraycopy(entryName.toCharArray(), 0, rasDialParams.szEntryName, 0, entryName.length());
System.arraycopy(credentials.szUserName, 0, rasDialParams.szUserName, 0, credentials.szUserName.length);
System.arraycopy(credentials.szPassword, 0, rasDialParams.szPassword, 0, credentials.szPassword.length);
System.arraycopy(credentials.szDomain, 0, rasDialParams.szDomain, 0, credentials.szDomain.length);
// dial
HANDLEByReference hrasConn = new HANDLEByReference();
int err = Rasapi32.INSTANCE.RasDial(null, null, rasDialParams, 2, func2, hrasConn);
if (err != WinError.ERROR_SUCCESS) {
if (hrasConn.getValue() != null)
Rasapi32.INSTANCE.RasHangUp(hrasConn.getValue());
throw new Ras32Exception(err);
}
return hrasConn.getValue();
}
use of com.sun.jna.platform.win32.WinNT.HANDLEByReference in project jna by java-native-access.
the class Rasapi32Util method dialEntry.
/**
* Dial a phone book entry by name (Synchronously)
* @param entryName The phone book entry name
* @return result reference
* @throws Ras32Exception errors
*/
public static HANDLE dialEntry(String entryName) throws Ras32Exception {
// get the RAS Credentials
RASCREDENTIALS.ByReference credentials = new RASCREDENTIALS.ByReference();
synchronized (phoneBookMutex) {
credentials.dwMask = WinRas.RASCM_UserName | WinRas.RASCM_Password | WinRas.RASCM_Domain;
int err = Rasapi32.INSTANCE.RasGetCredentials(null, entryName, credentials);
if (err != WinError.ERROR_SUCCESS)
throw new Ras32Exception(err);
}
// set the dialing parameters
RASDIALPARAMS.ByReference rasDialParams = new RASDIALPARAMS.ByReference();
System.arraycopy(entryName.toCharArray(), 0, rasDialParams.szEntryName, 0, entryName.length());
System.arraycopy(credentials.szUserName, 0, rasDialParams.szUserName, 0, credentials.szUserName.length);
System.arraycopy(credentials.szPassword, 0, rasDialParams.szPassword, 0, credentials.szPassword.length);
System.arraycopy(credentials.szDomain, 0, rasDialParams.szDomain, 0, credentials.szDomain.length);
// dial
HANDLEByReference hrasConn = new HANDLEByReference();
int err = Rasapi32.INSTANCE.RasDial(null, null, rasDialParams, 0, null, hrasConn);
if (err != WinError.ERROR_SUCCESS) {
if (hrasConn.getValue() != null)
Rasapi32.INSTANCE.RasHangUp(hrasConn.getValue());
throw new Ras32Exception(err);
}
return hrasConn.getValue();
}
use of com.sun.jna.platform.win32.WinNT.HANDLEByReference in project jna by java-native-access.
the class Advapi32Test method testOpenThreadOrProcessToken.
public void testOpenThreadOrProcessToken() {
HANDLEByReference phToken = new HANDLEByReference();
try {
HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
if (!Advapi32.INSTANCE.OpenThreadToken(threadHandle, WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, true, phToken)) {
assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle, WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
}
} finally {
Kernel32Util.closeHandleRef(phToken);
}
}
use of com.sun.jna.platform.win32.WinNT.HANDLEByReference in project jna by java-native-access.
the class Advapi32Test method testDuplicateToken.
public void testDuplicateToken() {
HANDLEByReference phToken = new HANDLEByReference();
HANDLEByReference phTokenDup = new HANDLEByReference();
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
try {
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle, WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
assertTrue(Advapi32.INSTANCE.DuplicateToken(phToken.getValue(), WinNT.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, phTokenDup));
} finally {
Kernel32Util.closeHandleRefs(phTokenDup, phToken);
}
}
use of com.sun.jna.platform.win32.WinNT.HANDLEByReference in project jna by java-native-access.
the class Advapi32Test method testLogonUser.
public void testLogonUser() {
HANDLEByReference phToken = new HANDLEByReference();
assertFalse(Advapi32.INSTANCE.LogonUser("AccountDoesntExist", ".", "passwordIsInvalid", WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phToken));
assertTrue(W32Errors.ERROR_SUCCESS != Kernel32.INSTANCE.GetLastError());
}
Aggregations