Search in sources :

Example 16 with HANDLEByReference

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();
}
Also used : RASDIALPARAMS(com.sun.jna.platform.win32.WinRas.RASDIALPARAMS) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) RASCREDENTIALS(com.sun.jna.platform.win32.WinRas.RASCREDENTIALS) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) IntByReference(com.sun.jna.ptr.IntByReference)

Example 17 with HANDLEByReference

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();
}
Also used : RASDIALPARAMS(com.sun.jna.platform.win32.WinRas.RASDIALPARAMS) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) RASCREDENTIALS(com.sun.jna.platform.win32.WinRas.RASCREDENTIALS) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) IntByReference(com.sun.jna.ptr.IntByReference)

Example 18 with HANDLEByReference

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);
    }
}
Also used : HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 19 with HANDLEByReference

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);
    }
}
Also used : HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 20 with HANDLEByReference

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());
}
Also used : HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference)

Aggregations

HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)33 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)22 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)15 IntByReference (com.sun.jna.ptr.IntByReference)11 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)7 TOKEN_PRIVILEGES (com.sun.jna.platform.win32.WinNT.TOKEN_PRIVILEGES)5 File (java.io.File)5 USER_INFO_1 (com.sun.jna.platform.win32.LMAccess.USER_INFO_1)3 BOOLByReference (com.sun.jna.platform.win32.WinDef.BOOLByReference)3 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)3 PointerByReference (com.sun.jna.ptr.PointerByReference)3 Memory (com.sun.jna.Memory)2 Account (com.sun.jna.platform.win32.Advapi32Util.Account)2 PDH_COUNTER_PATH_ELEMENTS (com.sun.jna.platform.win32.Pdh.PDH_COUNTER_PATH_ELEMENTS)2 PDH_RAW_COUNTER (com.sun.jna.platform.win32.Pdh.PDH_RAW_COUNTER)2 RASCREDENTIALS (com.sun.jna.platform.win32.WinRas.RASCREDENTIALS)2 RASDIALPARAMS (com.sun.jna.platform.win32.WinRas.RASDIALPARAMS)2 Test (org.junit.Test)2 CredHandle (com.sun.jna.platform.win32.Sspi.CredHandle)1 CtxtHandle (com.sun.jna.platform.win32.Sspi.CtxtHandle)1