HRESULT CIhvSecurityProfile::GetFullSecurityFlag ( BOOL* pbUseFullSecurity ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_FSFLAG_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2Bool ( bstrData, pbUseFullSecurity ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::SetParamDWORD ( DWORD dwNewValue ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = Dword2Bstr ( dwNewValue, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_PARAM2_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
HRESULT CIhvSecurityProfile::SetCipherType ( IHV_CIPHER_TYPE CipherType ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = CipherType2Bstr ( CipherType, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_ETYPE_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
HRESULT CIhvSecurityProfile::GetParamDWORD ( DWORD* pdwParam1 ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_PARAM2_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2Dword ( bstrData, pdwParam1 ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::SetSecurityType ( IHV_SECURITY_TYPE SecurityType ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = SecurityType2Bstr ( SecurityType, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_ATYPE_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
HRESULT CIhvSecurityProfile::GetCipherType ( PIHV_CIPHER_TYPE pCipherType ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_ETYPE_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2CipherType ( bstrData, pCipherType ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
// Accessor. HRESULT CIhvSecurityProfile::GetAuthType ( PIHV_AUTH_TYPE pAuthType ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_ATYPE_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrData ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2AuthType ( bstrData, pAuthType ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::GetSecurityType ( PIHV_SECURITY_TYPE pSecurityType ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_ATYPE_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2SecurityType ( bstrData, pSecurityType ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::SetFullSecurityFlag ( BOOL bUseFullSecurity ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = Bool2Bstr ( bUseFullSecurity, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_FSFLAG_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
// Accessor. HRESULT CIhvConnectivityProfile::GetParam1 ( DWORD* pdwParam1 ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( CON_PARAM1_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrData ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2Dword ( bstrData, pdwParam1 ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
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) malloc( sizeof( IHV_CONNECTIVITY_PROFILE ) ); if ( !pIhvProfile ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } ZeroMemory( pIhvProfile, sizeof( IHV_CONNECTIVITY_PROFILE ) ); hr = GetParamBSTR ( &bstrParam2 ); BAIL_ON_FAILURE( hr ); hr = Wstr2Wstr ( bstrParam2, &(pIhvProfile->pszParam2) ); BAIL_ON_FAILURE( hr ); hr = GetParamDWORD ( &(pIhvProfile->dwParam1) ); BAIL_ON_FAILURE( hr ); // Transfering local cache to OUT parameter. (*ppvData) = pIhvProfile; pIhvProfile = NULL; error: if ( pIhvProfile ) { free( pIhvProfile->pszParam2 ); // NULL Safe. free( pIhvProfile ); } SYS_FREE_STRING( bstrParam2 ); return hr; }
// base function to obtain text from // node described by XPATH. HRESULT CIhvProfileBase::GetTextFromNode ( IN LPCWSTR pszQuery, OUT BSTR* pbstrText ) { HRESULT hr = S_OK; BSTR bstrQuery = NULL; IXMLDOMNode* pQueryNode = NULL; ASSERT( pszQuery ); ASSERT( pbstrText ); // if node is NULL, return empty string. if ( !m_pRootNode ) { hr = Wstr2Bstr ( L"", pbstrText ); BAIL( ); } hr = Wstr2Bstr ( pszQuery, &bstrQuery ); BAIL_ON_FAILURE( hr ); hr = m_pRootNode->selectSingleNode( bstrQuery, &pQueryNode ); BAIL_ON_FAILURE( hr ); if (!pQueryNode) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pQueryNode->get_text( pbstrText ); BAIL_ON_FAILURE( hr ); if ( !(*pbstrText) ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } error: RELEASE_INTERFACE( pQueryNode ); SYS_FREE_STRING( bstrQuery ); return hr; }
// // 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; }
HRESULT CIhvProfileBase::PutTextInNode ( IN LPCWSTR pszQuery, IN BSTR bstrText ) { HRESULT hr = S_OK; BSTR bstrQuery = NULL; BSTR bstrOrig = NULL; BOOL bPut = TRUE; IXMLDOMNode* pQueryNode = NULL; if ( !m_pRootNode ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } if ( (!pszQuery) || (!bstrText) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } hr = Wstr2Bstr ( pszQuery, &bstrQuery ); BAIL_ON_FAILURE( hr ); hr = m_pRootNode->selectSingleNode( bstrQuery, &pQueryNode ); BAIL_ON_FAILURE( hr ); if (!pQueryNode) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pQueryNode->get_text( &bstrOrig ); BAIL_ON_FAILURE( hr ); if ( bstrOrig && ( 0 == wcscmp( bstrOrig, bstrText ) ) ) { bPut = FALSE; } if ( bPut ) { hr = pQueryNode->put_text( bstrText ); BAIL_ON_FAILURE( hr ); SetModified( ); } error: RELEASE_INTERFACE( pQueryNode ); SYS_FREE_STRING( bstrQuery ); SYS_FREE_STRING( bstrOrig ); return hr; }
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) malloc( sizeof( IHV_SECURITY_PROFILE ) ); if ( !pIhvProfile ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } ZeroMemory( pIhvProfile, sizeof( IHV_SECURITY_PROFILE ) ); hr = GetFullSecurityFlag ( &(pIhvProfile->bUseFullSecurity) ); BAIL_ON_FAILURE( hr ); hr = GetAuthType ( &(pIhvProfile->AuthType) ); BAIL_ON_FAILURE( hr ); hr = GetCipherType ( &(pIhvProfile->CipherType) ); BAIL_ON_FAILURE( hr ); hr = GetParamDWORD ( &(pIhvProfile->dwParam1) ); BAIL_ON_FAILURE( hr ); hr = GetParamBSTR ( &bstrParam2 ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrParam2 ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2Wstr ( bstrParam2, &(pIhvProfile->pszParam2) ); BAIL_ON_FAILURE( hr ); // Transfering local cache to OUT parameter. (*ppvData) = pIhvProfile; pIhvProfile = NULL; error: if ( pIhvProfile ) { free( pIhvProfile->pszParam2 ); // NULL Safe. free( pIhvProfile ); } SYS_FREE_STRING( bstrParam2 ); return hr; }
HRESULT CIhvProfileBase::LoadXml ( IN BSTR bstrProfileData ) { HRESULT hr = S_OK; IXMLDOMDocument* pDOMDoc = NULL; IXMLDOMElement* pDocElem = NULL; BSTR bstrIhvProfile = NULL; VARIANT_BOOL vfSuccess; if ( !bstrProfileData ) { hr = GetDefaultXml( &bstrIhvProfile ); BAIL_ON_FAILURE( hr ); } else { bstrIhvProfile = bstrProfileData; } if ( m_pRootNode ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = CoCreateInstance ( CLSID_DOMDocument, NULL, CLSCTX_ALL, IID_IXMLDOMDocument, (LPVOID *) &pDOMDoc ); BAIL_ON_FAILURE( hr ); hr = pDOMDoc->loadXML ( bstrIhvProfile, &vfSuccess ); BAIL_ON_FAILURE( hr ); if ( VARIANT_TRUE != vfSuccess ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pDOMDoc->get_documentElement ( &pDocElem ); BAIL_ON_FAILURE( hr ); // Caching the pointer to the document element // in a member variable. m_pRootNode = pDocElem; pDocElem = NULL; error: if ( !bstrProfileData ) { SYS_FREE_STRING( bstrIhvProfile ); } RELEASE_INTERFACE( pDOMDoc ); RELEASE_INTERFACE( pDocElem ); return hr; }
// // 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; }
// Converts string to security profile. DWORD GetIhvSecurityProfile ( PDOT11EXT_IHV_SECURITY_PROFILE pDot11ExtIhvSecProfile, PIHV_SECURITY_PROFILE* ppSecurityProfile ) { HRESULT hr = S_OK; BOOL bComInitialized = FALSE; BSTR bstrIhvProfile = NULL; PIHV_SECURITY_PROFILE pSecurityProfile = NULL; CIhvSecurityProfile* pIhvProfile = NULL; ASSERT( pDot11ExtIhvSecProfile ); ASSERT( ppSecurityProfile ); // Data structure is multi-thread safe because // it is both allocated and freed by current // function. hr = CoInitializeEx ( NULL, COINIT_MULTITHREADED ); BAIL_ON_FAILURE( hr ); bComInitialized = TRUE; pIhvProfile = new(std::nothrow) CIhvSecurityProfile; if (!pIhvProfile) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } hr = Wstr2Bstr ( pDot11ExtIhvSecProfile->pszXmlFragmentIhvSecurity, &bstrIhvProfile ); BAIL_ON_FAILURE( hr ); hr = pIhvProfile->LoadXml ( bstrIhvProfile ); BAIL_ON_FAILURE( hr ); hr = pIhvProfile->GetNativeData ( (LPVOID*) &pSecurityProfile ); BAIL_ON_FAILURE( hr ); if ( pDot11ExtIhvSecProfile->bUseMSOnex && pSecurityProfile->bUseFullSecurity ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } (*ppSecurityProfile) = pSecurityProfile; pSecurityProfile = NULL; error: SYS_FREE_STRING( bstrIhvProfile ); FreeIhvSecurityProfile ( &pSecurityProfile ); delete pIhvProfile; if ( bComInitialized ) { CoUninitialize( ); } return WIN32_FROM_HRESULT( hr ); }