Inner EAP method support progress continues...

This commit is contained in:
2016-10-03 15:48:54 +02:00
parent c53ed21d55
commit 7d13222838
5 changed files with 77 additions and 20 deletions

View File

@@ -100,6 +100,7 @@ namespace eap
virtual const wchar_t* get_method_str() const; virtual const wchar_t* get_method_str() const;
public: 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
}; };
} }

View File

@@ -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) : eap::config_method_eapmsg::config_method_eapmsg(_In_ const config_method_eapmsg &other) :
m_type(other.m_type), m_type (other.m_type ),
config_method(other) m_cfg_blob (other.m_cfg_blob),
config_method(other )
{ {
} }
eap::config_method_eapmsg::config_method_eapmsg(_Inout_ config_method_eapmsg &&other) : eap::config_method_eapmsg::config_method_eapmsg(_Inout_ config_method_eapmsg &&other) :
m_type(std::move(other.m_type)), m_type (std::move(other.m_type )),
config_method(std::move(other)) 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) { if (this != &other) {
(config_method&)*this = other; (config_method&)*this = other;
m_type = other.m_type; m_type = other.m_type;
m_cfg_blob = other.m_cfg_blob;
} }
return *this; 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) eap::config_method_eapmsg& eap::config_method_eapmsg::operator=(_Inout_ config_method_eapmsg &&other)
{ {
if (this != &other) { if (this != &other) {
(config_method&&)*this = std::move(other); (config_method&&)*this = std::move(other );
m_type = std::move(other.m_type); m_type = std::move(other.m_type );
m_cfg_blob = std::move(other.m_cfg_blob);
} }
return *this; 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 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"; return L"EAPMsg";
} }

View File

@@ -60,8 +60,9 @@ public:
wxEAPMethodTypeClientData(const EAP_METHOD_TYPE &type, DWORD properties); wxEAPMethodTypeClientData(const EAP_METHOD_TYPE &type, DWORD properties);
public: public:
EAP_METHOD_TYPE m_type; ///< EapHost method type EAP_METHOD_TYPE m_type; ///< EapHost method type
DWORD m_properties; ///< Method properties DWORD m_properties; ///< Method properties
eap::sanitizing_blob m_cfg_blob; ///< Method configuration BLOB
}; };
@@ -79,9 +80,14 @@ public:
protected: protected:
/// \cond internal /// \cond internal
virtual bool TransferDataToWindow();
virtual bool TransferDataFromWindow();
virtual void OnUpdateUI(wxUpdateUIEvent& event); virtual void OnUpdateUI(wxUpdateUIEvent& event);
virtual void OnSettings(wxCommandEvent& event); virtual void OnSettings(wxCommandEvent& event);
/// \endcond /// \endcond
protected:
eap::config_method_eapmsg &m_cfg; ///< Method configuration
}; };

View File

@@ -38,10 +38,11 @@ wxEAPMethodTypeClientData::wxEAPMethodTypeClientData(const EAP_METHOD_TYPE &type
// wxEAPMsgMethodConfigPanel // 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(prov);
UNREFERENCED_PARAMETER(cfg);
// Load and set icon. // Load and set icon.
winstd::library lib_shell32; winstd::library lib_shell32;
@@ -49,8 +50,8 @@ wxEAPMsgMethodConfigPanel::wxEAPMsgMethodConfigPanel(const eap::config_provider
m_method_icon->SetIcon(wxLoadIconFromResource(lib_shell32, MAKEINTRESOURCE(175))); m_method_icon->SetIcon(wxLoadIconFromResource(lib_shell32, MAKEINTRESOURCE(175)));
winstd::eap_method_info_array methods; winstd::eap_method_info_array methods;
std::unique_ptr<EAP_ERROR, winstd::EapHostPeerFreeErrorMemory_delete> error; winstd::eap_error error;
DWORD dwResult = EapHostPeerGetMethods(&methods, &std::addressof(error)->_Myptr); DWORD dwResult = EapHostPeerGetMethods(&methods, &error._Myptr);
if (dwResult == ERROR_SUCCESS) { if (dwResult == ERROR_SUCCESS) {
for (DWORD i = 0; i < methods.dwNumberOfMethods; i++) 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)); 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<wxEAPMethodTypeClientData*>(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<const wxEAPMethodTypeClientData*>(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) void wxEAPMsgMethodConfigPanel::OnUpdateUI(wxUpdateUIEvent& event)
{ {
wxEAPMsgMethodConfigPanelBase::OnUpdateUI(event); wxEAPMsgMethodConfigPanelBase::OnUpdateUI(event);
@@ -79,15 +116,24 @@ void wxEAPMsgMethodConfigPanel::OnSettings(wxCommandEvent& event)
wxEAPMsgMethodConfigPanelBase::OnSettings(event); wxEAPMsgMethodConfigPanelBase::OnSettings(event);
int sel = m_method->GetSelection(); int sel = m_method->GetSelection();
const wxEAPMethodTypeClientData *data = wxEAPMethodTypeClientData *data =
sel != wxNOT_FOUND && m_method->HasClientObjectData() ? sel != wxNOT_FOUND && m_method->HasClientObjectData() ?
dynamic_cast<const wxEAPMethodTypeClientData*>(m_method->GetClientObject(sel)) : dynamic_cast<wxEAPMethodTypeClientData*>(m_method->GetClientObject(sel)) :
NULL; NULL;
if (data && (data->m_properties & eapPropSupportsConfig)) { if (data && (data->m_properties & eapPropSupportsConfig)) {
DWORD cfg_data_size = 0; DWORD cfg_data_size = 0;
std::unique_ptr<BYTE[], winstd::EapHostPeerFreeMemory_delete> cfg_data; winstd::eap_blob cfg_data;
std::unique_ptr<EAP_ERROR, winstd::EapHostPeerFreeErrorMemory_delete> error; winstd::eap_error error;
DWORD dwResult = EapHostPeerInvokeConfigUI(GetHWND(), 0, data->m_type, 0, NULL, &cfg_data_size, &std::addressof(cfg_data)->_Myptr, &std::addressof(error)->_Myptr); 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);
} }
} }