124 lines
4.6 KiB
C++
124 lines
4.6 KiB
C++
/*
|
|
Copyright 2015-2016 Amebis
|
|
Copyright 2016 GÉANT
|
|
|
|
This file is part of GÉANTLink.
|
|
|
|
GÉANTLink is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
GÉANTLink is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GÉANTLink. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "StdAfx.h"
|
|
|
|
using namespace std;
|
|
using namespace winstd;
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// eap::module
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
eap::module::module(type_t eap_method) :
|
|
m_eap_method(eap_method),
|
|
m_instance(NULL)
|
|
{
|
|
m_ep.create(&EAPMETHOD_TRACE_EVENT_PROVIDER);
|
|
m_ep.write(&EAPMETHOD_TRACE_EVT_MODULE_LOAD, event_data((BYTE)m_eap_method), event_data::blank);
|
|
|
|
m_heap.create(0, 0, 0);
|
|
}
|
|
|
|
|
|
eap::module::~module()
|
|
{
|
|
m_ep.write(&EAPMETHOD_TRACE_EVT_MODULE_UNLOAD, event_data((BYTE)m_eap_method), event_data::blank);
|
|
}
|
|
|
|
|
|
EAP_ERROR* eap::module::make_error(_In_ DWORD dwErrorCode, _In_ DWORD dwReasonCode, _In_ LPCGUID pRootCauseGuid, _In_ LPCGUID pRepairGuid, _In_ LPCGUID pHelpLinkGuid, _In_z_ LPCWSTR pszRootCauseString, _In_z_ LPCWSTR pszRepairString) const
|
|
{
|
|
// Calculate memory size requirement.
|
|
SIZE_T
|
|
nRootCauseSize = pszRootCauseString != NULL && pszRootCauseString[0] ? (wcslen(pszRootCauseString) + 1)*sizeof(WCHAR) : 0,
|
|
nRepairStringSize = pszRepairString != NULL && pszRepairString [0] ? (wcslen(pszRepairString ) + 1)*sizeof(WCHAR) : 0,
|
|
nEapErrorSize = sizeof(EAP_ERROR) + nRootCauseSize + nRepairStringSize;
|
|
|
|
EAP_ERROR *pError = (EAP_ERROR*)HeapAlloc(m_heap, 0, nEapErrorSize);
|
|
if (!pError)
|
|
return NULL;
|
|
BYTE *p = (BYTE*)(pError + 1);
|
|
|
|
// Fill the error descriptor.
|
|
pError->dwWinError = dwErrorCode;
|
|
pError->type.eapType.type = (BYTE)m_eap_method;
|
|
pError->type.eapType.dwVendorId = 0;
|
|
pError->type.eapType.dwVendorType = 0;
|
|
pError->type.dwAuthorId = 67532;
|
|
pError->dwReasonCode = dwReasonCode;
|
|
pError->rootCauseGuid = pRootCauseGuid != NULL ? *pRootCauseGuid : GUID_NULL;
|
|
pError->repairGuid = pRepairGuid != NULL ? *pRepairGuid : GUID_NULL;
|
|
pError->helpLinkGuid = pHelpLinkGuid != NULL ? *pHelpLinkGuid : GUID_NULL;
|
|
if (nRootCauseSize) {
|
|
pError->pRootCauseString = (LPWSTR)p;
|
|
memcpy(pError->pRootCauseString, pszRootCauseString, nRootCauseSize);
|
|
p += nRootCauseSize;
|
|
} else
|
|
pError->pRootCauseString = NULL;
|
|
if (nRepairStringSize) {
|
|
pError->pRepairString = (LPWSTR)p;
|
|
memcpy(pError->pRepairString, pszRepairString, nRepairStringSize);
|
|
p += nRepairStringSize;
|
|
} else
|
|
pError->pRepairString = NULL;
|
|
|
|
// Write trace event.
|
|
vector<EVENT_DATA_DESCRIPTOR> evt_desc;
|
|
evt_desc.reserve(8);
|
|
evt_desc.push_back(event_data(pError->dwWinError));
|
|
evt_desc.push_back(event_data(pError->type.eapType.type));
|
|
evt_desc.push_back(event_data(pError->dwReasonCode));
|
|
evt_desc.push_back(event_data(&(pError->rootCauseGuid), sizeof(GUID)));
|
|
evt_desc.push_back(event_data(&(pError->repairGuid), sizeof(GUID)));
|
|
evt_desc.push_back(event_data(&(pError->helpLinkGuid), sizeof(GUID)));
|
|
evt_desc.push_back(event_data(pError->pRootCauseString));
|
|
evt_desc.push_back(event_data(pError->pRepairString));
|
|
m_ep.write(&EAPMETHOD_TRACE_EAP_ERROR, (ULONG)evt_desc.size(), evt_desc.data());
|
|
|
|
return pError;
|
|
}
|
|
|
|
|
|
BYTE* eap::module::alloc_memory(_In_ size_t size)
|
|
{
|
|
return (BYTE*)HeapAlloc(m_heap, 0, size);
|
|
}
|
|
|
|
|
|
void eap::module::free_memory(_In_ BYTE *ptr)
|
|
{
|
|
ETW_FN_VOID;
|
|
|
|
// Since we do security here and some of the BLOBs contain credentials, sanitize every memory block before freeing.
|
|
SecureZeroMemory(ptr, HeapSize(m_heap, 0, ptr));
|
|
HeapFree(m_heap, 0, ptr);
|
|
}
|
|
|
|
|
|
void eap::module::free_error_memory(_In_ EAP_ERROR *err)
|
|
{
|
|
ETW_FN_VOID;
|
|
|
|
// pRootCauseString and pRepairString always trail the ppEapError to reduce number of (de)allocations.
|
|
HeapFree(m_heap, 0, err);
|
|
}
|