Sessions are actually methods now

This commit is contained in:
2016-08-06 10:28:15 +02:00
parent 97d0f75f8d
commit faadb712fc
7 changed files with 134 additions and 422 deletions

View File

@@ -323,22 +323,27 @@ bool eap::peer_ttls::begin_session(
_Out_ EAP_SESSION_HANDLE *phSession,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(dwFlags);
UNREFERENCED_PARAMETER(pAttributeArray);
UNREFERENCED_PARAMETER(hTokenImpersonateUser);
UNREFERENCED_PARAMETER(dwMaxSendPacketSize);
*phSession = NULL;
// Allocate new session.
unique_ptr<session_ttls> session(new session_ttls(*this));
if (!session) {
unique_ptr<session> s(new session(*this));
if (!s) {
*ppEapError = make_error(ERROR_OUTOFMEMORY, _T(__FUNCTION__) _T(" Error allocating memory for EAP-TTLS session."));
return false;
}
// Begin the session.
if (!unpack(session->m_cfg, pConnectionData, dwConnectionDataSize, ppEapError) ||
!unpack(session->m_cred, pUserData, dwUserDataSize, ppEapError) ||
!session->begin(dwFlags, pAttributeArray, hTokenImpersonateUser, dwMaxSendPacketSize, ppEapError))
if (!unpack(s->m_cfg, pConnectionData, dwConnectionDataSize, ppEapError) ||
!unpack(s->m_cred, pUserData, dwUserDataSize, ppEapError)/* ||
!s->begin(dwFlags, pAttributeArray, hTokenImpersonateUser, dwMaxSendPacketSize, ppEapError)*/)
return false;
*phSession = session.release();
*phSession = s.release();
return true;
}
@@ -346,11 +351,12 @@ bool eap::peer_ttls::begin_session(
bool eap::peer_ttls::end_session(_In_ EAP_SESSION_HANDLE hSession, _Out_ EAP_ERROR **ppEapError)
{
assert(hSession);
UNREFERENCED_PARAMETER(ppEapError); // What could possibly go wrong when destroying!? ;)
// End the session.
session_ttls *session = static_cast<session_ttls*>(hSession);
session->end(ppEapError);
delete session;
session *s = static_cast<session*>(hSession);
//s->end(ppEapError);
delete s;
return true;
}
@@ -364,7 +370,7 @@ bool eap::peer_ttls::process_request_packet(
_Out_ EAP_ERROR **ppEapError)
{
assert(dwReceivedPacketSize == ntohs(*(WORD*)pReceivedPacket->Length));
return static_cast<session_ttls*>(hSession)->process_request_packet(dwReceivedPacketSize, pReceivedPacket, pEapOutput, ppEapError);
return static_cast<session*>(hSession)->m_method.process_request_packet(pReceivedPacket, dwReceivedPacketSize, pEapOutput, ppEapError);
}
@@ -374,7 +380,7 @@ bool eap::peer_ttls::get_response_packet(
_Inout_ DWORD *pdwSendPacketSize,
_Out_ EAP_ERROR **ppEapError)
{
return static_cast<session_ttls*>(hSession)->get_response_packet(pdwSendPacketSize, pSendPacket, ppEapError);
return static_cast<session*>(hSession)->m_method.get_response_packet(pSendPacket, pdwSendPacketSize, ppEapError);
}
@@ -384,7 +390,13 @@ bool eap::peer_ttls::get_result(
_Out_ EapPeerMethodResult *ppResult,
_Out_ EAP_ERROR **ppEapError)
{
return static_cast<session_ttls*>(hSession)->get_result(reason, ppResult, ppEapError);
UNREFERENCED_PARAMETER(hSession);
UNREFERENCED_PARAMETER(reason);
UNREFERENCED_PARAMETER(ppResult);
assert(ppEapError);
*ppEapError = make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
}
@@ -394,7 +406,13 @@ bool eap::peer_ttls::get_ui_context(
_Out_ DWORD *pdwUIContextDataSize,
_Out_ EAP_ERROR **ppEapError)
{
return static_cast<session_ttls*>(hSession)->get_ui_context(ppUIContextData, pdwUIContextDataSize, ppEapError);
UNREFERENCED_PARAMETER(hSession);
UNREFERENCED_PARAMETER(ppUIContextData);
UNREFERENCED_PARAMETER(pdwUIContextDataSize);
assert(ppEapError);
*ppEapError = make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
}
@@ -405,7 +423,14 @@ bool eap::peer_ttls::set_ui_context(
_In_ const EapPeerMethodOutput *pEapOutput,
_Out_ EAP_ERROR **ppEapError)
{
return static_cast<session_ttls*>(hSession)->set_ui_context(pUIContextData, dwUIContextDataSize, pEapOutput, ppEapError);
UNREFERENCED_PARAMETER(hSession);
UNREFERENCED_PARAMETER(pUIContextData);
UNREFERENCED_PARAMETER(dwUIContextDataSize);
UNREFERENCED_PARAMETER(pEapOutput);
assert(ppEapError);
*ppEapError = make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
}
@@ -414,7 +439,13 @@ bool eap::peer_ttls::get_response_attributes(
_Out_ EapAttributes *pAttribs,
_Out_ EAP_ERROR **ppEapError)
{
return static_cast<session_ttls*>(hSession)->get_response_attributes(pAttribs, ppEapError);
UNREFERENCED_PARAMETER(hSession);
UNREFERENCED_PARAMETER(pAttribs);
UNREFERENCED_PARAMETER(ppEapError);
assert(ppEapError);
*ppEapError = make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
}
@@ -424,5 +455,12 @@ bool eap::peer_ttls::set_response_attributes(
_Out_ EapPeerMethodOutput *pEapOutput,
_Out_ EAP_ERROR **ppEapError)
{
return static_cast<session_ttls*>(hSession)->set_response_attributes(pAttribs, pEapOutput, ppEapError);
UNREFERENCED_PARAMETER(hSession);
UNREFERENCED_PARAMETER(pAttribs);
UNREFERENCED_PARAMETER(pEapOutput);
UNREFERENCED_PARAMETER(ppEapError);
assert(ppEapError);
*ppEapError = make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
}

View File

@@ -25,91 +25,79 @@ using namespace winstd;
//////////////////////////////////////////////////////////////////////
// eap::session_ttls
// eap::method_ttls
//////////////////////////////////////////////////////////////////////
eap::session_ttls::session_ttls(_In_ module &mod) :
m_version(version_0),
session<credentials_ttls, bool, bool>(mod)
eap::method_ttls::method_ttls(_In_ module &module, _In_ config_method_ttls &cfg, _In_ credentials_ttls &cred) :
m_outer(module, cfg.m_outer, cred.m_outer),
method(module, cfg, cred)
{
}
eap::session_ttls::session_ttls(_In_ const session_ttls &other) :
m_version(other.m_version),
session<credentials_ttls, bool, bool>(other)
eap::method_ttls::method_ttls(_In_ const method_ttls &other) :
m_outer(other.m_outer),
method(other)
{
}
eap::session_ttls::session_ttls(_Inout_ session_ttls &&other) :
m_version(std::move(other.m_version)),
session<credentials_ttls, bool, bool>(std::move(other))
eap::method_ttls::method_ttls(_Inout_ method_ttls &&other) :
m_outer(std::move(other.m_outer)),
method(std::move(other))
{
}
eap::session_ttls& eap::session_ttls::operator=(_In_ const session_ttls &other)
eap::method_ttls& eap::method_ttls::operator=(_In_ const method_ttls &other)
{
if (this != &other) {
(session<credentials_ttls, bool, bool>&)*this = other;
m_version = other.m_version;
if (this != std::addressof(other)) {
(method&)*this = other;
m_outer = other.m_outer;
}
return *this;
}
eap::session_ttls& eap::session_ttls::operator=(_Inout_ session_ttls &&other)
eap::method_ttls& eap::method_ttls::operator=(_Inout_ method_ttls &&other)
{
if (this != &other) {
(session<credentials_ttls, bool, bool>&)*this = std::move(other);
m_version = std::move(other.m_version);
if (this != std::addressof(other)) {
(method&)*this = std::move(other);
m_outer = std::move(other.m_outer);
}
return *this;
}
bool eap::session_ttls::process_request_packet(
_In_ DWORD dwReceivedPacketSize,
bool eap::method_ttls::process_request_packet(
_In_bytecount_(dwReceivedPacketSize) const EapPacket *pReceivedPacket,
_In_ DWORD dwReceivedPacketSize,
_Out_ EapPeerMethodOutput *pEapOutput,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(dwReceivedPacketSize);
UNREFERENCED_PARAMETER(pReceivedPacket);
UNREFERENCED_PARAMETER(pEapOutput);
assert(ppEapError);
// Initialize output.
pEapOutput->fAllowNotifications = TRUE;
pEapOutput->action = EapPeerMethodResponseActionDiscard;
*ppEapError = m_module.make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
// Is this a valid EAP-TTLS packet?
if (dwReceivedPacketSize < 6) {
*ppEapError = m_module.make_error(EAP_E_EAPHOST_METHOD_INVALID_PACKET, _T(__FUNCTION__) _T(" Packet is too small. EAP-%s packets should be at least 6B."));
return false;
} else if (pReceivedPacket->Data[0] != eap_type_ttls) {
*ppEapError = m_module.make_error(EAP_E_EAPHOST_METHOD_INVALID_PACKET, wstring_printf(_T(__FUNCTION__) _T(" Packet is not EAP-TTLS (expected: %u, received: %u)."), eap_type_ttls, pReceivedPacket->Data[0]).c_str());
return false;
}
return m_outer.process_request_packet(pReceivedPacket, dwReceivedPacketSize, pEapOutput, ppEapError);
}
bool eap::session_ttls::get_response_packet(
_Inout_ DWORD *pdwSendPacketSize,
bool eap::method_ttls::get_response_packet(
_Inout_bytecap_(*dwSendPacketSize) EapPacket *pSendPacket,
_Inout_ DWORD *pdwSendPacketSize,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(pdwSendPacketSize);
UNREFERENCED_PARAMETER(pSendPacket);
assert(ppEapError);
*ppEapError = m_module.make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
}
bool eap::session_ttls::get_result(
_In_ EapPeerMethodResultReason reason,
_Out_ EapPeerMethodResult *ppResult,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(reason);
UNREFERENCED_PARAMETER(ppResult);
assert(ppEapError);
*ppEapError = m_module.make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported."));
return false;
return m_outer.get_response_packet(pSendPacket, pdwSendPacketSize, ppEapError);
}