Ejemplo n.º 1
0
// Convert unicode string to unicode string. NULL safe.
// string allocated by malloc and freed by free.
HRESULT
Wstr2Wstr
(
    _In_     LPCWSTR     pszSrc,
    _Outptr_ LPWSTR*     ppszDest
)
{
    HRESULT hr  =   S_OK;
    size_t  len =   0;

    if ( !ppszDest )
    {
        hr = E_INVALIDARG;
        BAIL_ON_FAILURE( hr );
    }

    (*ppszDest) = NULL;
    if ( !pszSrc )
    {
        BAIL( );
    }

    len =   1 + wcslen( pszSrc );
    len *=  sizeof( WCHAR );

    (*ppszDest) = (LPWSTR) PrivateMemoryAlloc( len );
    if ( !(*ppszDest) )
    {
        hr = E_OUTOFMEMORY;
        BAIL_ON_FAILURE( hr );
    }

    CopyMemory( (*ppszDest), pszSrc, len );

error:
    return hr;
}
Ejemplo n.º 2
0
//
// Calls the accessors to build native data.
//
HRESULT
CIhvSecurityProfile::GetNativeData
(
    LPVOID* ppvData
)
{
    HRESULT                 hr          =   S_OK;
    PIHV_SECURITY_PROFILE   pIhvProfile =   NULL;
    BSTR                    bstrParam2  =   NULL;

    if ( !ppvData )
    {
        hr = E_INVALIDARG;
        BAIL_ON_FAILURE( hr );
    }

    pIhvProfile = (PIHV_SECURITY_PROFILE) PrivateMemoryAlloc( sizeof( IHV_SECURITY_PROFILE ) );
    if ( !pIhvProfile )
    {
        hr = E_OUTOFMEMORY;
        BAIL_ON_FAILURE( hr );
    }

    pIhvProfile->bUseIhvConnectivityOnly = ( m_pRootNode == NULL );

    // Ignoring errors since structure is already
    // populated with defaults.
    hr =
    GetFullSecurityFlag
    (
        &(pIhvProfile->bUseFullSecurity)
    );

    hr =
    GetAuthType
    (
        &(pIhvProfile->AuthType)
    );

    hr =
    GetCipherType
    (
        &(pIhvProfile->CipherType)
    );

    hr =
    GetParam1
    (
        &(pIhvProfile->dwParam1)
    );

    hr =
    GetParam2
    (
        &bstrParam2
    );
    BAIL_ON_FAILURE( hr );

    if ( NULL == bstrParam2 )
    {
        hr = E_POINTER;
        BAIL_ON_FAILURE( hr );
    }

    hr =
    Wstr2Wstr
    (
        bstrParam2,
        &(pIhvProfile->pszParam2)
    );

    // Consuming earlier failures.
    hr = S_OK;

    // Transfering local cache to OUT parameter.
    (*ppvData) = pIhvProfile;
    pIhvProfile = NULL;

error:
    if ( pIhvProfile )
    {
        PrivateMemoryFree( pIhvProfile->pszParam2 ); // NULL Safe.
        PrivateMemoryFree( pIhvProfile );
    }
    SYS_FREE_STRING( bstrParam2 );
    return hr;
}
Ejemplo n.º 3
0
// Send the UI request and wait for the UI response.
DWORD
SendUIRequestToReceiveKey
(
    PADAPTER_DETAILS    pAdapterDetails,
    DWORD*              pdwKeyLen,
    BYTE**              ppbKeyData
)
{
    DWORD                           dwResult        =   ERROR_SUCCESS;
    DOT11EXT_IHV_UI_REQUEST         uiRequest       =   {0};
    PIHV_UI_REQUEST                 pIHVRequest     =   NULL;
    CHAR                            szTitle[]       =   UI_TITLE_STRING;
    CHAR                            szHelp[]        =   UI_HELP_STRING;
    BOOL                            bLocked         =   FALSE;
    HANDLE                          hUIResponse     =   NULL;



    // CLSID of COM class that implements the UI page. In a real
    // implementation this GUID could be dynamically obtained.
    CLSID                            uiPageClsid    =
    {
        /* 4A01F9F9-6012-4343-A8C4-10B5DF32672A */
        0x4A01F9F9,
        0x6012,
        0x4343,
        {0xA8, 0xC4, 0x10, 0xB5, 0xDF, 0x32, 0x67, 0x2A}
    };

    ASSERT( pAdapterDetails );

    // prepare the IHV request.
    uiRequest.dwByteCount = sizeof(IHV_UI_REQUEST);
    uiRequest.pvUIRequest = (BYTE*) PrivateMemoryAlloc( sizeof(IHV_UI_REQUEST) );
    if ( !(uiRequest.pvUIRequest) )
    {
        dwResult = ERROR_OUTOFMEMORY;
        BAIL( );
    }

    pIHVRequest = (IHV_UI_REQUEST*)uiRequest.pvUIRequest;


    memcpy(  pIHVRequest->szTitle ,  szTitle  , sizeof(szTitle) );
    memcpy(  pIHVRequest->szHelp  ,  szHelp   , sizeof(szHelp)  );

    uiRequest.dwSessionId = WTSGetActiveConsoleSessionId( );
    uiRequest.UIPageClsid = uiPageClsid;

    // acquire the lock to register the request.
    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    // create new request guid.
    dwResult = UuidCreate( &(uiRequest.guidUIRequest) );
    BAIL_ON_WIN32_ERROR(dwResult);

    // free the existing response.
    PrivateMemoryFree( pAdapterDetails->pbResponse );
    pAdapterDetails->pbResponse = NULL;

    // register the guid.
    pAdapterDetails->currentGuidUIRequest = uiRequest.guidUIRequest;

    // Initializing the event this thread
    // would be waiting on later.
    ResetEvent( pAdapterDetails->hUIResponse );

    hUIResponse = pAdapterDetails->hUIResponse;

    // leave the lock since this thread needs
    // to wait for the response.
    LeaveCriticalSection( &g_csSynch );
    bLocked = FALSE;


    // send the request.
    dwResult =
        (g_pDot11ExtApi->Dot11ExtSendUIRequest)
        (
            pAdapterDetails->hDot11SvcHandle,
            &uiRequest
        );
    BAIL_ON_WIN32_ERROR(dwResult);

    TRACE_MESSAGE( "Sent UI request to receive key." );

    // Waiting for UI response.
    // This would be triggered
    // off if no UI response
    // is received.
    dwResult =
        WaitForSingleObject
        (
            hUIResponse,
            1000 * 60 * 5                    // 5 minutes
        );

    // acquire the lock - required for both success and failure.
    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    ZeroMemory( &(pAdapterDetails->currentGuidUIRequest), sizeof( GUID ) );

    if ( WAIT_OBJECT_0 == dwResult )
    {
        dwResult = ERROR_SUCCESS;
    }
    BAIL_ON_WIN32_ERROR(dwResult);

    if ( NULL == pAdapterDetails->pbResponse )
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR(dwResult);
    }


    // At this point in the code a response
    // has been received, and the thread
    // has not been aborted.

    (*ppbKeyData) = pAdapterDetails->pbResponse;
    pAdapterDetails->pbResponse = NULL;

    (*pdwKeyLen) = pAdapterDetails->dwResponseLen;


    // Convert the Unicode string to ASCII.
    dwResult =
        ConvertStringToKey
        (
            *ppbKeyData,
            pdwKeyLen
        );
    BAIL_ON_WIN32_ERROR(dwResult);

    pAdapterDetails->bModifyCurrentProfile  =   TRUE;

error:
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    PrivateMemoryFree( uiRequest.pvUIRequest );
    return dwResult;
}
Ejemplo n.º 4
0
//
// Perform Wep based pre-association once the key is known.
//
DWORD
WINAPI
DoWepPreAssociateCommon
(
    PADAPTER_DETAILS                    pAdapterDetails,
    DWORD                               dwKeyLen,
    BYTE*                               pbKeyData,
    DWORD*                              pdwReasonCode
)
{
    DWORD                               dwResult        =   ERROR_SUCCESS;
    BOOL                                bLocked         =   FALSE;
    LONG                                lIndex          =   0;
    PDOT11_CIPHER_DEFAULT_KEY_VALUE     pKey            =   0;
    ULONG                               uLen            =   0;

    ASSERT( pAdapterDetails );
    ASSERT( dwKeyLen );
    ASSERT( pbKeyData );
    ASSERT( pdwReasonCode );

    // Reason code is set before making calls that could fail.
    (*pdwReasonCode) = L2_REASON_CODE_IHV_OUTOFMEMORY;

    uLen = FIELD_OFFSET(DOT11_CIPHER_DEFAULT_KEY_VALUE, ucKey) + dwKeyLen * sizeof(UCHAR);
    pKey = (PDOT11_CIPHER_DEFAULT_KEY_VALUE) PrivateMemoryAlloc(uLen);
    if (!pKey)
    {
        dwResult = ERROR_OUTOFMEMORY;
        BAIL_ON_WIN32_ERROR(dwResult);
    }
    CopyMemory( &(pKey->ucKey), pbKeyData, dwKeyLen );

    // Prepare the key.
    pKey->AlgorithmId = DOT11_CIPHER_ALGO_WEP;
    pKey->usKeyLength = (USHORT) dwKeyLen;
    pKey->bStatic = TRUE;
    pKey->Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
    pKey->Header.Revision = DOT11_CIPHER_DEFAULT_KEY_VALUE_REVISION_1;
    pKey->Header.Size = sizeof(DOT11_CIPHER_DEFAULT_KEY_VALUE);

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    // Reason code is set before making calls that could fail.
    (*pdwReasonCode) = L2_REASON_CODE_IHV_INVALID_STATE;

    if ( nic_state_pre_assoc_started != pAdapterDetails->NicState )
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    // Reason code is set before making calls that could fail.
    (*pdwReasonCode) = L2_REASON_CODE_IHV_HARDWARE_FAILURE;

    // plumb the settings and keys down.

    TRACE_MESSAGE( "Setting Auth Algorithm." );
    dwResult =
        (g_pDot11ExtApi->Dot11ExtSetAuthAlgorithm)
        (
            pAdapterDetails->hDot11SvcHandle,
            DOT11_AUTH_ALGO_80211_OPEN
        );
    BAIL_ON_WIN32_ERROR(dwResult);

    TRACE_MESSAGE( "Setting Unicast cipher algorithm." );
    dwResult =
        (g_pDot11ExtApi->Dot11ExtSetUnicastCipherAlgorithm)
        (
            pAdapterDetails->hDot11SvcHandle,
            DOT11_CIPHER_ALGO_WEP
        );
    BAIL_ON_WIN32_ERROR(dwResult);

    TRACE_MESSAGE( "Setting exclude unencrypted flag." );
    dwResult =
        (g_pDot11ExtApi->Dot11ExtSetExcludeUnencrypted)
        (
            pAdapterDetails->hDot11SvcHandle,
            TRUE
        );
    BAIL_ON_WIN32_ERROR(dwResult);

    for ( lIndex = MAX_KEY_INDEX; lIndex >= MIN_KEY_INDEX; lIndex-- )
    {
        pKey->uKeyIndex = lIndex;

        TRACE_MESSAGE( "Setting default key." );

        dwResult =
            (g_pDot11ExtApi->Dot11ExtSetDefaultKey)
            (
                pAdapterDetails->hDot11SvcHandle,
                pKey,
                DOT11_DIR_BOTH
            );
        BAIL_ON_WIN32_ERROR(dwResult);
    }

    TRACE_MESSAGE( "Setting default key ID." );
    dwResult =
        (g_pDot11ExtApi->Dot11ExtSetDefaultKeyId)
        (
            pAdapterDetails->hDot11SvcHandle,
            0
        );
    BAIL_ON_WIN32_ERROR(dwResult);


    // Verified before, just after acquiring lock.
    ASSERT( nic_state_pre_assoc_started == pAdapterDetails->NicState  );

    pAdapterDetails->NicState = nic_state_pre_assoc_ended;

    // Reason code is set to SUCCESS.
    (*pdwReasonCode) = L2_REASON_CODE_SUCCESS;

    // register the post-association handlers with the adapter.

    pAdapterDetails->pPerformPostAssociateCompletionRoutine =   DoWepPostAssociate;
    pAdapterDetails->pPerformPostAssociateRoutine           =   NULL;
    pAdapterDetails->pStopPostAssociateRoutine              =   NULL;

error:
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    PrivateMemoryFree( pKey );
    return dwResult;
}
Ejemplo n.º 5
0
//
// Calls the accessors to build native data.
//
HRESULT
CIhvConnectivityProfile::GetNativeData
(
    LPVOID* ppvData
)
{
    HRESULT                     hr          =   S_OK;
    PIHV_CONNECTIVITY_PROFILE   pIhvProfile =   NULL;
    BSTR                        bstrParam2  =   NULL;

    if ( !ppvData )
    {
        hr = E_INVALIDARG;
        BAIL_ON_FAILURE( hr );
    }

    pIhvProfile = (PIHV_CONNECTIVITY_PROFILE) PrivateMemoryAlloc( sizeof( IHV_CONNECTIVITY_PROFILE ) );
    if ( !pIhvProfile )
    {
        hr = E_OUTOFMEMORY;
        BAIL_ON_FAILURE( hr );
    }

    // Ignoring errors since structure is already
    // populated with defaults.

    hr =
    GetParam2
    (
        &bstrParam2
    );

    hr =
    Wstr2Wstr
    (
        bstrParam2,
        &(pIhvProfile->pszParam2)
    );

    hr =
    GetParam1
    (
        &(pIhvProfile->dwParam1)
    );

    // Consuming earlier failures.
    hr = S_OK;

    // Transfering local cache to OUT parameter.
    (*ppvData) = pIhvProfile;
    pIhvProfile = NULL;

error:
    if ( pIhvProfile )
    {
        PrivateMemoryFree( pIhvProfile->pszParam2 ); // NULL Safe.
        PrivateMemoryFree( pIhvProfile );
    }
    SYS_FREE_STRING( bstrParam2 );
    return hr;
}