From 7d13222838c56c9c58682f8513d7ac0100b63327 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 3 Oct 2016 15:48:54 +0200 Subject: [PATCH] Inner EAP method support progress continues... --- lib/EAPMsg/include/Config.h | 3 +- lib/EAPMsg/src/Config.cpp | 18 +++++---- lib/EAPMsg_UI/include/EAPMsg_UI.h | 10 ++++- lib/EAPMsg_UI/src/EAPMsg_UI.cpp | 64 ++++++++++++++++++++++++++----- lib/WinStd | 2 +- 5 files changed, 77 insertions(+), 20 deletions(-) diff --git a/lib/EAPMsg/include/Config.h b/lib/EAPMsg/include/Config.h index de7499b..c028d2c 100644 --- a/lib/EAPMsg/include/Config.h +++ b/lib/EAPMsg/include/Config.h @@ -100,6 +100,7 @@ namespace eap virtual const wchar_t* get_method_str() const; public: - EAP_METHOD_TYPE m_type; + EAP_METHOD_TYPE m_type; ///< EapHost method type: (EAP type, vendor ID, vendor type, author ID) tuple + sanitizing_blob m_cfg_blob; ///< Method configuration BLOB }; } diff --git a/lib/EAPMsg/src/Config.cpp b/lib/EAPMsg/src/Config.cpp index d6bff22..3ba8a94 100644 --- a/lib/EAPMsg/src/Config.cpp +++ b/lib/EAPMsg/src/Config.cpp @@ -35,15 +35,17 @@ eap::config_method_eapmsg::config_method_eapmsg(_In_ module &mod, _In_ unsigned eap::config_method_eapmsg::config_method_eapmsg(_In_ const config_method_eapmsg &other) : - m_type(other.m_type), - config_method(other) + m_type (other.m_type ), + m_cfg_blob (other.m_cfg_blob), + config_method(other ) { } eap::config_method_eapmsg::config_method_eapmsg(_Inout_ config_method_eapmsg &&other) : - m_type(std::move(other.m_type)), - config_method(std::move(other)) + m_type (std::move(other.m_type )), + m_cfg_blob (std::move(other.m_cfg_blob)), + config_method(std::move(other )) { } @@ -53,6 +55,7 @@ eap::config_method_eapmsg& eap::config_method_eapmsg::operator=(_In_ const confi if (this != &other) { (config_method&)*this = other; m_type = other.m_type; + m_cfg_blob = other.m_cfg_blob; } return *this; @@ -62,8 +65,9 @@ eap::config_method_eapmsg& eap::config_method_eapmsg::operator=(_In_ const confi eap::config_method_eapmsg& eap::config_method_eapmsg::operator=(_Inout_ config_method_eapmsg &&other) { if (this != &other) { - (config_method&&)*this = std::move(other); - m_type = std::move(other.m_type); + (config_method&&)*this = std::move(other ); + m_type = std::move(other.m_type ); + m_cfg_blob = std::move(other.m_cfg_blob); } return *this; @@ -84,6 +88,6 @@ eap_type_t eap::config_method_eapmsg::get_method_id() const const wchar_t* eap::config_method_eapmsg::get_method_str() const { - // TODO: Query registry for EAP method name (PeerFriendlyName). + // TODO: Query registry for EAP method name (PeerFriendlyName using RegLoadMUIString()). return L"EAPMsg"; } diff --git a/lib/EAPMsg_UI/include/EAPMsg_UI.h b/lib/EAPMsg_UI/include/EAPMsg_UI.h index 8c39677..1ef81e2 100644 --- a/lib/EAPMsg_UI/include/EAPMsg_UI.h +++ b/lib/EAPMsg_UI/include/EAPMsg_UI.h @@ -60,8 +60,9 @@ public: wxEAPMethodTypeClientData(const EAP_METHOD_TYPE &type, DWORD properties); public: - EAP_METHOD_TYPE m_type; ///< EapHost method type - DWORD m_properties; ///< Method properties + EAP_METHOD_TYPE m_type; ///< EapHost method type + DWORD m_properties; ///< Method properties + eap::sanitizing_blob m_cfg_blob; ///< Method configuration BLOB }; @@ -79,9 +80,14 @@ public: protected: /// \cond internal + virtual bool TransferDataToWindow(); + virtual bool TransferDataFromWindow(); virtual void OnUpdateUI(wxUpdateUIEvent& event); virtual void OnSettings(wxCommandEvent& event); /// \endcond + +protected: + eap::config_method_eapmsg &m_cfg; ///< Method configuration }; diff --git a/lib/EAPMsg_UI/src/EAPMsg_UI.cpp b/lib/EAPMsg_UI/src/EAPMsg_UI.cpp index b757d0c..ba0f87f 100644 --- a/lib/EAPMsg_UI/src/EAPMsg_UI.cpp +++ b/lib/EAPMsg_UI/src/EAPMsg_UI.cpp @@ -38,10 +38,11 @@ wxEAPMethodTypeClientData::wxEAPMethodTypeClientData(const EAP_METHOD_TYPE &type // wxEAPMsgMethodConfigPanel ////////////////////////////////////////////////////////////////////// -wxEAPMsgMethodConfigPanel::wxEAPMsgMethodConfigPanel(const eap::config_provider &prov, eap::config_method_eapmsg &cfg, wxWindow *parent) : wxEAPMsgMethodConfigPanelBase(parent) +wxEAPMsgMethodConfigPanel::wxEAPMsgMethodConfigPanel(const eap::config_provider &prov, eap::config_method_eapmsg &cfg, wxWindow *parent) : + m_cfg(cfg), + wxEAPMsgMethodConfigPanelBase(parent) { UNREFERENCED_PARAMETER(prov); - UNREFERENCED_PARAMETER(cfg); // Load and set icon. winstd::library lib_shell32; @@ -49,8 +50,8 @@ wxEAPMsgMethodConfigPanel::wxEAPMsgMethodConfigPanel(const eap::config_provider m_method_icon->SetIcon(wxLoadIconFromResource(lib_shell32, MAKEINTRESOURCE(175))); winstd::eap_method_info_array methods; - std::unique_ptr error; - DWORD dwResult = EapHostPeerGetMethods(&methods, &std::addressof(error)->_Myptr); + winstd::eap_error error; + DWORD dwResult = EapHostPeerGetMethods(&methods, &error._Myptr); if (dwResult == ERROR_SUCCESS) { for (DWORD i = 0; i < methods.dwNumberOfMethods; i++) m_method->Append(methods.pEapMethods[i].pwszFriendlyName, new wxEAPMethodTypeClientData(methods.pEapMethods[i].eaptype, methods.pEapMethods[i].eapProperties)); @@ -61,6 +62,42 @@ wxEAPMsgMethodConfigPanel::wxEAPMsgMethodConfigPanel(const eap::config_provider } +bool wxEAPMsgMethodConfigPanel::TransferDataToWindow() +{ + if (m_method->HasClientObjectData()) { + // Find configured method and set its selection and configuration BLOB. + for (unsigned int i = 0, n = m_method->GetCount(); i < n; i++) { + wxEAPMethodTypeClientData *data = dynamic_cast(m_method->GetClientObject(i)); + if (data->m_type == m_cfg.m_type) { + m_method->SetSelection(i); + data->m_cfg_blob = m_cfg.m_cfg_blob; + } + } + } + + return wxEAPMsgMethodConfigPanelBase::TransferDataToWindow(); +} + + +bool wxEAPMsgMethodConfigPanel::TransferDataFromWindow() +{ + wxCHECK(wxEAPMsgMethodConfigPanelBase::TransferDataFromWindow(), false); + + int sel = m_method->GetSelection(); + const wxEAPMethodTypeClientData *data = + sel != wxNOT_FOUND && m_method->HasClientObjectData() ? + dynamic_cast(m_method->GetClientObject(sel)) : + NULL; + if (data) { + // Save method selection and configuration. + m_cfg.m_type = data->m_type; + m_cfg.m_cfg_blob = data->m_cfg_blob; + } + + return true; +} + + void wxEAPMsgMethodConfigPanel::OnUpdateUI(wxUpdateUIEvent& event) { wxEAPMsgMethodConfigPanelBase::OnUpdateUI(event); @@ -79,15 +116,24 @@ void wxEAPMsgMethodConfigPanel::OnSettings(wxCommandEvent& event) wxEAPMsgMethodConfigPanelBase::OnSettings(event); int sel = m_method->GetSelection(); - const wxEAPMethodTypeClientData *data = + wxEAPMethodTypeClientData *data = sel != wxNOT_FOUND && m_method->HasClientObjectData() ? - dynamic_cast(m_method->GetClientObject(sel)) : + dynamic_cast(m_method->GetClientObject(sel)) : NULL; if (data && (data->m_properties & eapPropSupportsConfig)) { DWORD cfg_data_size = 0; - std::unique_ptr cfg_data; - std::unique_ptr error; - DWORD dwResult = EapHostPeerInvokeConfigUI(GetHWND(), 0, data->m_type, 0, NULL, &cfg_data_size, &std::addressof(cfg_data)->_Myptr, &std::addressof(error)->_Myptr); + winstd::eap_blob cfg_data; + winstd::eap_error error; + DWORD dwResult = EapHostPeerInvokeConfigUI(GetHWND(), 0, data->m_type, (DWORD)data->m_cfg_blob.size(), data->m_cfg_blob.data(), &cfg_data_size, &cfg_data._Myptr, &error._Myptr); + if (dwResult == ERROR_SUCCESS) { + const BYTE *_cfg_data = cfg_data.get(); + data->m_cfg_blob.assign(_cfg_data, _cfg_data + cfg_data_size); + } else if (dwResult == ERROR_CANCELLED) { + // Not really an error. + } else if (error) + wxLogError(_("Configuring EAP method failed (error %u, %s, %s)."), error->dwWinError, error->pRootCauseString, error->pRepairString); + else + wxLogError(_("Configuring EAP method failed (error %u)."), dwResult); } } diff --git a/lib/WinStd b/lib/WinStd index 7b0b38a..71c6300 160000 --- a/lib/WinStd +++ b/lib/WinStd @@ -1 +1 @@ -Subproject commit 7b0b38aab38c777d2b058baaab62fe55cba09b64 +Subproject commit 71c630085df8151af99cfdcf52f67ac52f44dcfe