EAP modules divided to libraries
This commit is contained in:
149
lib/TTLS/src/Config.cpp
Normal file
149
lib/TTLS/src/Config.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
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::config_ttls
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::config_ttls::config_ttls(_In_ module &mod) :
|
||||
m_inner(NULL),
|
||||
config_tls(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_ttls::config_ttls(const _In_ config_ttls &other) :
|
||||
m_inner(other.m_inner ? (config_method*)other.m_inner->clone() : NULL),
|
||||
config_tls(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_ttls::config_ttls(_Inout_ config_ttls &&other) :
|
||||
m_inner(other.m_inner),
|
||||
config_tls(std::move(other))
|
||||
{
|
||||
other.m_inner = NULL;
|
||||
}
|
||||
|
||||
|
||||
eap::config_ttls::~config_ttls()
|
||||
{
|
||||
if (m_inner)
|
||||
delete m_inner;
|
||||
}
|
||||
|
||||
|
||||
eap::config_ttls& eap::config_ttls::operator=(const _In_ config_ttls &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config_tls&)*this = other;
|
||||
if (m_inner) delete m_inner;
|
||||
m_inner = other.m_inner ? (config_method*)other.m_inner->clone() : NULL;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config_ttls& eap::config_ttls::operator=(_Inout_ config_ttls &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config_tls&&)*this = std::move(other);
|
||||
if (m_inner) delete m_inner;
|
||||
m_inner = other.m_inner;
|
||||
other.m_inner = NULL;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DWORD eap::config_ttls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
|
||||
{
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
|
||||
// <InnerAuthenticationMethod>
|
||||
com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error creating <InnerAuthenticationMethod> element."), NULL);
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
if (dynamic_cast<const config_pap*>(m_inner)) {
|
||||
// <InnerAuthenticationMethod>/<NonEAPAuthMethod>
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElInnerAuthenticationMethod, bstr(L"NonEAPAuthMethod"), bstrNamespace, bstr(L"PAP"))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error creating <NonEAPAuthMethod> element."), NULL);
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
// <InnerAuthenticationMethod>/...
|
||||
if ((dwResult = m_inner->save(pDoc, pXmlElInnerAuthenticationMethod, ppEapError)) != ERROR_SUCCESS)
|
||||
return dwResult;
|
||||
} else
|
||||
return dwResult = ERROR_NOT_SUPPORTED;
|
||||
|
||||
return config_tls::save(pDoc, pConfigRoot, ppEapError);
|
||||
}
|
||||
|
||||
|
||||
DWORD eap::config_ttls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
assert(ppEapError);
|
||||
DWORD dwResult;
|
||||
|
||||
// Load inner authentication configuration (<InnerAuthenticationMethod>).
|
||||
com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
|
||||
if ((dwResult = eapxml::select_element(pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), &pXmlElInnerAuthenticationMethod)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error selecting <InnerAuthenticationMethod> element."), NULL);
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
// Determine inner authentication type (<EAPMethod> and <NonEAPAuthMethod>).
|
||||
//DWORD dwMethodID;
|
||||
bstr bstrMethod;
|
||||
/*if (eapxml::get_element_value(pXmlElInnerAuthenticationMethod, bstr(L"eap-metadata:EAPMethod"), &dwMethodID) == ERROR_SUCCESS &&
|
||||
dwMethodID == EAP_TYPE_MSCHAPV2)
|
||||
{
|
||||
// MSCHAPv2
|
||||
// TODO: Add MSCHAPv2 support.
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
} else*/ if (eapxml::get_element_value(pXmlElInnerAuthenticationMethod, bstr(L"eap-metadata:NonEAPAuthMethod"), &bstrMethod) == ERROR_SUCCESS &&
|
||||
CompareStringEx(LOCALE_NAME_INVARIANT, NORM_IGNORECASE, bstrMethod, bstrMethod.length(), L"PAP", -1, NULL, NULL, 0) == CSTR_EQUAL)
|
||||
{
|
||||
// PAP
|
||||
assert(!m_inner);
|
||||
m_inner = new eap::config_pap(m_module);
|
||||
if ((dwResult = m_inner->load(pXmlElInnerAuthenticationMethod, ppEapError)) != ERROR_SUCCESS)
|
||||
return dwResult;
|
||||
} else {
|
||||
*ppEapError = m_module.make_error(dwResult = ERROR_NOT_SUPPORTED, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Unsupported inner authentication method."), NULL);
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
return config_tls::load(pConfigRoot, ppEapError);
|
||||
}
|
Reference in New Issue
Block a user