config_method_with_cred is no longer a template

This commit is contained in:
Simon Rozman 2016-08-05 11:51:59 +02:00
parent f4be571499
commit 4fc029138c
9 changed files with 187 additions and 162 deletions

View File

@ -37,7 +37,7 @@ namespace eap
///
/// Base class for method with credentials
///
template <class _Tcred> class config_method_with_cred;
class config_method_with_cred;
///
/// Base class for single provider configuration storage
@ -260,7 +260,6 @@ namespace eap
class credentials;
template <class _Tcred>
class config_method_with_cred : public config_method
{
public:
@ -269,42 +268,21 @@ namespace eap
///
/// \param[in] mod EAP module to use for global services
///
config_method_with_cred(_In_ module *mod) :
m_allow_save(true),
m_use_preshared(false),
m_preshared(new _Tcred(mod)),
config_method(mod)
{
}
config_method_with_cred(_In_ module *mod);
///
/// Copies configuration
///
/// \param[in] other Configuration to copy from
///
config_method_with_cred(_In_ const config_method_with_cred<_Tcred> &other) :
m_allow_save(other.m_allow_save),
m_use_preshared(other.m_use_preshared),
m_preshared((_Tcred*)other.m_preshared->clone()),
config_method(other)
{
}
config_method_with_cred(_In_ const config_method_with_cred &other);
///
/// Moves configuration
///
/// \param[in] other Configuration to move from
///
config_method_with_cred(_Inout_ config_method_with_cred<_Tcred> &&other) :
m_allow_save(std::move(other.m_allow_save)),
m_use_preshared(std::move(other.m_use_preshared)),
m_preshared(std::move(other.m_preshared)),
config_method(std::move(other))
{
}
config_method_with_cred(_Inout_ config_method_with_cred &&other);
///
/// Copies configuration
@ -313,18 +291,7 @@ namespace eap
///
/// \returns Reference to this object
///
config_method_with_cred& operator=(_In_ const config_method_with_cred<_Tcred> &other)
{
if (this != &other) {
(config_method&)*this = other;
m_allow_save = other.m_allow_save;
m_use_preshared = other.m_use_preshared;
m_preshared.reset((_Tcred*)other.m_preshared->clone());
}
return *this;
}
config_method_with_cred& operator=(_In_ const config_method_with_cred &other);
///
/// Moves configuration
@ -333,18 +300,7 @@ namespace eap
///
/// \returns Reference to this object
///
config_method_with_cred& operator=(_Inout_ config_method_with_cred<_Tcred> &&other)
{
if (this != &other) {
(config_method&)*this = std::move(other );
m_allow_save = std::move(other.m_allow_save );
m_use_preshared = std::move(other.m_use_preshared);
m_preshared = std::move(other.m_preshared );
}
return *this;
}
config_method_with_cred& operator=(_Inout_ config_method_with_cred &&other);
/// \name XML configuration management
/// @{
@ -360,33 +316,7 @@ namespace eap
/// - \c true if succeeded
/// - \c false otherwise. See \p ppEapError for details.
///
virtual bool save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
{
assert(pDoc);
assert(pConfigRoot);
assert(ppEapError);
const winstd::bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
DWORD dwResult;
// <ClientSideCredential>
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, winstd::bstr(L"eap-metadata:ClientSideCredential"), winstd::bstr(L"ClientSideCredential"), bstrNamespace, &pXmlElClientSideCredential)) != ERROR_SUCCESS) {
*ppEapError = m_module->make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ClientSideCredential> element."));
return false;
}
// <ClientSideCredential>/<allow-save>
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElClientSideCredential, winstd::bstr(L"allow-save"), bstrNamespace, m_allow_save)) != ERROR_SUCCESS) {
*ppEapError = m_module->make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <allow-save> element."));
return false;
}
if (m_use_preshared && !m_preshared->save(pDoc, pXmlElClientSideCredential, ppEapError))
return false;
return true;
}
virtual bool save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const;
///
/// Load configuration from XML document
@ -398,39 +328,7 @@ namespace eap
/// - \c true if succeeded
/// - \c false otherwise. See \p ppEapError for details.
///
virtual bool load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
{
assert(pConfigRoot);
assert(ppEapError);
m_allow_save = true;
m_use_preshared = false;
m_preshared->clear();
// <ClientSideCredential>
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
if (eapxml::select_element(pConfigRoot, winstd::bstr(L"eap-metadata:ClientSideCredential"), &pXmlElClientSideCredential) == ERROR_SUCCESS) {
std::wstring xpath(eapxml::get_xpath(pXmlElClientSideCredential));
// <allow-save>
eapxml::get_element_value(pXmlElClientSideCredential, winstd::bstr(L"eap-metadata:allow-save"), &m_allow_save);
m_module->log_config((xpath + L"/allow-save").c_str(), m_allow_save);
_Tcred preshared(m_module);
if (preshared.load(pXmlElClientSideCredential, ppEapError)) {
m_use_preshared = true;
*m_preshared = std::move(preshared);
} else {
// This is not really an error - merely an indication pre-shared credentials are unavailable.
if (*ppEapError) {
m_module->free_error_memory(*ppEapError);
*ppEapError = NULL;
}
}
}
return true;
}
virtual bool load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError);
/// @}
@ -442,49 +340,28 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void operator<<(_Inout_ cursor_out &cursor) const
{
config_method::operator<<(cursor);
cursor << m_allow_save;
cursor << m_use_preshared;
cursor << *m_preshared;
}
virtual void operator<<(_Inout_ cursor_out &cursor) const;
///
/// Returns packed size of a configuration
///
/// \returns Size of data when packed (in bytes)
///
virtual size_t get_pk_size() const
{
return
config_method::get_pk_size() +
pksizeof(m_allow_save ) +
pksizeof(m_use_preshared) +
pksizeof(*m_preshared );
}
virtual size_t get_pk_size() const;
///
/// Unpacks a configuration
///
/// \param[inout] cursor Memory cursor
///
virtual void operator>>(_Inout_ cursor_in &cursor)
{
config_method::operator>>(cursor);
cursor >> m_allow_save;
cursor >> m_use_preshared;
cursor >> *m_preshared;
}
virtual void operator>>(_Inout_ cursor_in &cursor);
/// @}
public:
bool m_allow_save; ///< Are credentials allowed to be saved to Windows Credential Manager?
bool m_use_preshared; ///< Use pre-shared credentials
std::unique_ptr<_Tcred> m_preshared; ///< Pre-shared credentials
bool m_allow_save; ///< Are credentials allowed to be saved to Windows Credential Manager?
bool m_use_preshared; ///< Use pre-shared credentials
std::unique_ptr<credentials> m_preshared; ///< Pre-shared credentials
};

View File

@ -138,6 +138,152 @@ eap::config_method& eap::config_method::operator=(_Inout_ config_method &&other)
}
//////////////////////////////////////////////////////////////////////
// eap::config_method_with_cred
//////////////////////////////////////////////////////////////////////
eap::config_method_with_cred::config_method_with_cred(_In_ module *mod) :
m_allow_save(true),
m_use_preshared(false),
config_method(mod)
{
}
eap::config_method_with_cred::config_method_with_cred(_In_ const config_method_with_cred &other) :
m_allow_save(other.m_allow_save),
m_use_preshared(other.m_use_preshared),
m_preshared((credentials*)other.m_preshared->clone()),
config_method(other)
{
}
eap::config_method_with_cred::config_method_with_cred(_Inout_ config_method_with_cred &&other) :
m_allow_save(std::move(other.m_allow_save)),
m_use_preshared(std::move(other.m_use_preshared)),
m_preshared(std::move(other.m_preshared)),
config_method(std::move(other))
{
}
eap::config_method_with_cred& eap::config_method_with_cred::operator=(_In_ const config_method_with_cred &other)
{
if (this != &other) {
(config_method&)*this = other;
m_allow_save = other.m_allow_save;
m_use_preshared = other.m_use_preshared;
m_preshared.reset((credentials*)other.m_preshared->clone());
}
return *this;
}
eap::config_method_with_cred& eap::config_method_with_cred::operator=(_Inout_ config_method_with_cred &&other)
{
if (this != &other) {
(config_method&)*this = std::move(other );
m_allow_save = std::move(other.m_allow_save );
m_use_preshared = std::move(other.m_use_preshared);
m_preshared = std::move(other.m_preshared );
}
return *this;
}
bool eap::config_method_with_cred::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
{
assert(pDoc);
assert(pConfigRoot);
assert(ppEapError);
const winstd::bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
DWORD dwResult;
// <ClientSideCredential>
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, winstd::bstr(L"eap-metadata:ClientSideCredential"), winstd::bstr(L"ClientSideCredential"), bstrNamespace, &pXmlElClientSideCredential)) != ERROR_SUCCESS) {
*ppEapError = m_module->make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ClientSideCredential> element."));
return false;
}
// <ClientSideCredential>/<allow-save>
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElClientSideCredential, winstd::bstr(L"allow-save"), bstrNamespace, m_allow_save)) != ERROR_SUCCESS) {
*ppEapError = m_module->make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <allow-save> element."));
return false;
}
if (m_use_preshared && !m_preshared->save(pDoc, pXmlElClientSideCredential, ppEapError))
return false;
return true;
}
bool eap::config_method_with_cred::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
{
assert(pConfigRoot);
assert(ppEapError);
m_allow_save = true;
m_use_preshared = false;
m_preshared->clear();
// <ClientSideCredential>
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
if (eapxml::select_element(pConfigRoot, winstd::bstr(L"eap-metadata:ClientSideCredential"), &pXmlElClientSideCredential) == ERROR_SUCCESS) {
std::wstring xpath(eapxml::get_xpath(pXmlElClientSideCredential));
// <allow-save>
eapxml::get_element_value(pXmlElClientSideCredential, winstd::bstr(L"eap-metadata:allow-save"), &m_allow_save);
m_module->log_config((xpath + L"/allow-save").c_str(), m_allow_save);
if (m_preshared->load(pXmlElClientSideCredential, ppEapError)) {
m_use_preshared = true;
} else {
// This is not really an error - merely an indication pre-shared credentials are unavailable.
if (*ppEapError) {
m_module->free_error_memory(*ppEapError);
*ppEapError = NULL;
}
}
}
return true;
}
void eap::config_method_with_cred::operator<<(_Inout_ cursor_out &cursor) const
{
config_method::operator<<(cursor);
cursor << m_allow_save;
cursor << m_use_preshared;
cursor << *m_preshared;
}
size_t eap::config_method_with_cred::get_pk_size() const
{
return
config_method::get_pk_size() +
pksizeof(m_allow_save ) +
pksizeof(m_use_preshared) +
pksizeof(*m_preshared );
}
void eap::config_method_with_cred::operator>>(_Inout_ cursor_in &cursor)
{
config_method::operator>>(cursor);
cursor >> m_allow_save;
cursor >> m_use_preshared;
cursor >> *m_preshared;
}
//////////////////////////////////////////////////////////////////////
// eap::config_provider
//////////////////////////////////////////////////////////////////////

View File

@ -231,7 +231,7 @@ public:
/// \param[in] pszCredTarget Target name of credentials in Windows Credential Manager. Can be further decorated to create final target name.
/// \param[in] parent Parent window
///
wxEAPCredentialsConfigPanel(const eap::config_provider &prov, eap::config_method_with_cred<_Tcred> &cfg, LPCTSTR pszCredTarget, wxWindow *parent) :
wxEAPCredentialsConfigPanel(const eap::config_provider &prov, eap::config_method_with_cred &cfg, LPCTSTR pszCredTarget, wxWindow *parent) :
m_prov(prov),
m_cfg(cfg),
m_target(pszCredTarget),
@ -253,7 +253,7 @@ protected:
else
m_preshared->SetValue(true);
m_cred = *m_cfg.m_preshared;
m_cred = *(_Tcred*)m_cfg.m_preshared.get();
return wxEAPCredentialsConfigPanelBase::TransferDataToWindow();
}
@ -377,7 +377,7 @@ protected:
protected:
const eap::config_provider &m_prov; ///< EAP provider
eap::config_method_with_cred<_Tcred> &m_cfg; ///< EAP method configuration
eap::config_method_with_cred &m_cfg; ///< EAP method configuration
winstd::library m_shell32; ///< shell32.dll resource library reference
wxIcon m_icon; ///< Panel icon
winstd::tstring m_target; ///< Credential Manager target
@ -406,7 +406,7 @@ public:
/// \param[in] parent Parent window
/// \param[in] is_config Is this panel used to pre-enter credentials? When \c true, the "Remember" checkbox is always selected and disabled.
///
wxEAPCredentialsPanelBase(const eap::config_provider &prov, const eap::config_method_with_cred<_Tcred> &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) :
wxEAPCredentialsPanelBase(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) :
m_prov(prov),
m_cfg(cfg),
m_cred(cred),
@ -489,7 +489,7 @@ protected:
protected:
const eap::config_provider &m_prov; ///< Provider configuration
const eap::config_method_with_cred<_Tcred> &m_cfg; ///< Method configuration
const eap::config_method_with_cred &m_cfg; ///< Method configuration
_Tcred &m_cred; ///< Credentials
winstd::tstring m_target; ///< Credential Manager target
bool m_is_config; ///< Is this a configuration dialog?
@ -510,7 +510,7 @@ public:
/// \param[in] parent Parent window
/// \param[in] is_config Is this panel used to pre-enter credentials? When \c true, the "Remember" checkbox is always selected and disabled.
///
wxPasswordCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred<_Tcred> &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) :
wxPasswordCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) :
wxEAPCredentialsPanelBase<_Tcred, _Tbase>(prov, cfg, cred, pszCredTarget, parent, is_config)
{
// Load and set icon.

View File

@ -40,7 +40,7 @@ namespace eap
namespace eap
{
class config_method_pap : public config_method_with_cred<credentials_pap>
class config_method_pap : public config_method_with_cred
{
public:
///

View File

@ -28,19 +28,20 @@ using namespace winstd;
// eap::config_method_pap
//////////////////////////////////////////////////////////////////////
eap::config_method_pap::config_method_pap(_In_ module *mod) : config_method_with_cred<credentials_pap>(mod)
eap::config_method_pap::config_method_pap(_In_ module *mod) : config_method_with_cred(mod)
{
m_preshared.reset(new credentials_pap(mod));
}
eap::config_method_pap::config_method_pap(_In_ const config_method_pap &other) :
config_method_with_cred<credentials_pap>(other)
config_method_with_cred(other)
{
}
eap::config_method_pap::config_method_pap(_Inout_ config_method_pap &&other) :
config_method_with_cred<credentials_pap>(std::move(other))
config_method_with_cred(std::move(other))
{
}
@ -48,7 +49,7 @@ eap::config_method_pap::config_method_pap(_Inout_ config_method_pap &&other) :
eap::config_method_pap& eap::config_method_pap::operator=(_In_ const config_method_pap &other)
{
if (this != &other)
(config_method_with_cred<credentials_pap>&)*this = other;
(config_method_with_cred&)*this = other;
return *this;
}
@ -57,7 +58,7 @@ eap::config_method_pap& eap::config_method_pap::operator=(_In_ const config_meth
eap::config_method_pap& eap::config_method_pap::operator=(_Inout_ config_method_pap &&other)
{
if (this != &other)
(config_method_with_cred<credentials_pap>&&)*this = std::move(other);
(config_method_with_cred&&)*this = std::move(other);
return *this;
}

View File

@ -54,7 +54,7 @@ namespace eap
namespace eap
{
class config_method_tls : public config_method_with_cred<credentials_tls>
class config_method_tls : public config_method_with_cred
{
public:
///

View File

@ -66,15 +66,16 @@ tstring eap::get_cert_title(PCCERT_CONTEXT cert)
// eap::config_method_tls
//////////////////////////////////////////////////////////////////////
eap::config_method_tls::config_method_tls(_In_ module *mod) : config_method_with_cred<credentials_tls>(mod)
eap::config_method_tls::config_method_tls(_In_ module *mod) : config_method_with_cred(mod)
{
m_preshared.reset(new credentials_tls(mod));
}
eap::config_method_tls::config_method_tls(_In_ const config_method_tls &other) :
m_trusted_root_ca(other.m_trusted_root_ca),
m_server_names(other.m_server_names),
config_method_with_cred<credentials_tls>(other)
config_method_with_cred(other)
{
}
@ -82,7 +83,7 @@ eap::config_method_tls::config_method_tls(_In_ const config_method_tls &other) :
eap::config_method_tls::config_method_tls(_Inout_ config_method_tls &&other) :
m_trusted_root_ca(std::move(other.m_trusted_root_ca)),
m_server_names(std::move(other.m_server_names)),
config_method_with_cred<credentials_tls>(std::move(other))
config_method_with_cred(std::move(other))
{
}
@ -90,7 +91,7 @@ eap::config_method_tls::config_method_tls(_Inout_ config_method_tls &&other) :
eap::config_method_tls& eap::config_method_tls::operator=(_In_ const config_method_tls &other)
{
if (this != &other) {
(config_method_with_cred<credentials_tls>&)*this = other;
(config_method_with_cred&)*this = other;
m_trusted_root_ca = other.m_trusted_root_ca;
m_server_names = other.m_server_names;
}
@ -102,7 +103,7 @@ eap::config_method_tls& eap::config_method_tls::operator=(_In_ const config_meth
eap::config_method_tls& eap::config_method_tls::operator=(_Inout_ config_method_tls &&other)
{
if (this != &other) {
(config_method_with_cred<credentials_tls>&&)*this = std::move(other);
(config_method_with_cred&&)*this = std::move(other);
m_trusted_root_ca = std::move(other.m_trusted_root_ca);
m_server_names = std::move(other.m_server_names);
}
@ -123,7 +124,7 @@ bool eap::config_method_tls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *
assert(pConfigRoot);
assert(ppEapError);
if (!config_method_with_cred<credentials_tls>::save(pDoc, pConfigRoot, ppEapError))
if (!config_method_with_cred::save(pDoc, pConfigRoot, ppEapError))
return false;
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
@ -182,7 +183,7 @@ bool eap::config_method_tls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR
{
assert(pConfigRoot);
if (!config_method_with_cred<credentials_tls>::load(pConfigRoot, ppEapError))
if (!config_method_with_cred::load(pConfigRoot, ppEapError))
return false;
std::wstring xpath(eapxml::get_xpath(pConfigRoot));
@ -258,7 +259,7 @@ bool eap::config_method_tls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR
void eap::config_method_tls::operator<<(_Inout_ cursor_out &cursor) const
{
config_method_with_cred<credentials_tls>::operator<<(cursor);
config_method_with_cred::operator<<(cursor);
cursor << m_trusted_root_ca;
cursor << m_server_names ;
}
@ -267,7 +268,7 @@ void eap::config_method_tls::operator<<(_Inout_ cursor_out &cursor) const
size_t eap::config_method_tls::get_pk_size() const
{
return
config_method_with_cred<credentials_tls>::get_pk_size() +
config_method_with_cred::get_pk_size() +
pksizeof(m_trusted_root_ca) +
pksizeof(m_server_names );
}
@ -275,7 +276,7 @@ size_t eap::config_method_tls::get_pk_size() const
void eap::config_method_tls::operator>>(_Inout_ cursor_in &cursor)
{
config_method_with_cred<credentials_tls>::operator>>(cursor);
config_method_with_cred::operator>>(cursor);
cursor >> m_trusted_root_ca;
cursor >> m_server_names ;
}

View File

@ -261,7 +261,7 @@ public:
/// \param[in] parent Parent window
/// \param[in] is_config Is this panel used to pre-enter credentials? When \c true, the "Remember" checkbox is always selected and disabled.
///
wxTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred<eap::credentials_tls> &cfg, eap::credentials_tls &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false);
wxTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, eap::credentials_tls &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false);
protected:
/// \cond internal

View File

@ -311,7 +311,7 @@ bool wxFQDNListValidator::Parse(const wxString &val_in, size_t i_start, size_t i
// wxTLSCredentialsPanel
//////////////////////////////////////////////////////////////////////
wxTLSCredentialsPanel::wxTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred<eap::credentials_tls> &cfg, eap::credentials_tls &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) :
wxTLSCredentialsPanel::wxTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, eap::credentials_tls &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) :
wxEAPCredentialsPanelBase<eap::credentials_tls, wxTLSCredentialsPanelBase>(prov, cfg, cred, pszCredTarget, parent, is_config)
{
// Load and set icon.