Migrate manual DLL registration to DllRegisterServer()

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-06-29 15:15:49 +02:00
parent 51fa08cc71
commit 682dc048e9
20 changed files with 513 additions and 32 deletions

View File

@ -26,6 +26,9 @@
<ClCompile Include="Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Register.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\EAPMethod.rc">

View File

@ -30,6 +30,9 @@
<ClCompile Include="Main_UI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Register_UI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\EAPMethod_UI.rc">

Binary file not shown.

View File

@ -18,6 +18,7 @@
<ClCompile Include="PCH.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Register.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="EAPMethod.def" />

Binary file not shown.

View File

@ -21,6 +21,7 @@
<ClCompile Include="PCH_UI.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Register_UI.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="EAPMethod_UI.def" />

View File

@ -27,3 +27,5 @@
#else
#error Unknown EAP Method type.
#endif
extern EAPMETHOD_PEER g_peer;

View File

@ -29,3 +29,5 @@
#else
#error Unknown EAP Method type.
#endif
extern EAPMETHOD_PEER_UI g_peer;

99
EAPMethods/Register.cpp Normal file
View File

@ -0,0 +1,99 @@
/*
Copyright 2020-2020 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 "PCH.h"
using namespace std;
using namespace winstd;
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ LPCTSTR sValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_SZ, reinterpret_cast<LPCBYTE>(sValue), (DWORD)((_tcslen(sValue) + 1) * sizeof(tstring::value_type)));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ const tstring &sValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_SZ, reinterpret_cast<LPCBYTE>(sValue.c_str()), (DWORD)((sValue.length() + 1) * sizeof(tstring::value_type)));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ DWORD dwValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_DWORD, reinterpret_cast<LPCBYTE>(&dwValue), sizeof(dwValue));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
///
/// Registers method in EapHost registry
///
/// \returns S_OK if successful; E_FAIL otherwise
///
STDAPI DllRegisterServer()
{
try {
tstring sz, sz2;
reg_key key_methods, key_author, key_method;
if (!key_methods.open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\services\\EapHost\\Methods"), 0, KEY_CREATE_SUB_KEY)) throw win_runtime_error();
sprintf(sz, _T("%u"), EAPMETHOD_AUTHOR_ID);
if (!key_author.create(key_methods, sz.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
set_value(key_author, NULL, _T(PRODUCT_NAME_STR));
sprintf(sz, _T("%u"), EAPMETHOD_TYPE);
if (!key_method.create(key_author, sz.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
if (!GetModuleFileName(g_peer.m_instance, sz)) throw win_runtime_error("GetModuleFileName failed.");
sprintf(sz2, _T("@%s,-1"), sz.c_str());
set_value(key_method, _T("PeerDllPath") , sz);
set_value(key_method, _T("PeerFriendlyName"), sz2);
set_value(key_method, _T("Properties") , (DWORD)389871807);
return S_OK;
} catch(win_runtime_error &err) {
OutputDebugStr(_T("%hs (error %u)\n"), err.what(), err.number());
return E_FAIL;
} catch(...) {
OutputDebugStr(_T("Registering DLL failed.\n"));
return E_FAIL;
}
}
///
/// Unregisters method from EapHost registry
///
/// \returns Always S_OK
///
STDAPI DllUnregisterServer()
{
try {
tstring sz;
reg_key key_methods;
if (!key_methods.open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\services\\EapHost\\Methods"), 0, KEY_READ)) throw win_runtime_error();
sprintf(sz, _T("%u\\%u"), EAPMETHOD_AUTHOR_ID, EAPMETHOD_TYPE);
if (!key_methods.delete_subkey(sz.c_str())) throw win_runtime_error();
} catch(...) {}
return S_OK;
}

100
EAPMethods/Register_UI.cpp Normal file
View File

@ -0,0 +1,100 @@
/*
Copyright 2020-2020 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 "PCH_UI.h"
using namespace std;
using namespace winstd;
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ LPCTSTR sValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_SZ, reinterpret_cast<LPCBYTE>(sValue), (DWORD)((_tcslen(sValue) + 1) * sizeof(tstring::value_type)));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ const tstring &sValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_SZ, reinterpret_cast<LPCBYTE>(sValue.c_str()), (DWORD)((sValue.length() + 1) * sizeof(tstring::value_type)));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ DWORD dwValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_DWORD, reinterpret_cast<LPCBYTE>(&dwValue), sizeof(dwValue));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
///
/// Registers method UI in EapHost registry
///
/// \returns S_OK if successful; E_FAIL otherwise
///
STDAPI DllRegisterServer()
{
try {
tstring sz;
reg_key key_methods, key_author, key_method;
if (!key_methods.open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\services\\EapHost\\Methods"), 0, KEY_CREATE_SUB_KEY)) throw win_runtime_error();
sprintf(sz, _T("%u"), EAPMETHOD_AUTHOR_ID);
if (!key_author.create(key_methods, sz.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
set_value(key_author, NULL, _T(PRODUCT_NAME_STR));
sprintf(sz, _T("%u"), EAPMETHOD_TYPE);
if (!key_method.create(key_author, sz.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
if (!GetModuleFileName(g_peer.m_instance, sz)) throw win_runtime_error("GetModuleFileName failed.");
set_value(key_method, _T("PeerConfigUIPath") , sz);
set_value(key_method, _T("PeerIdentityPath") , sz);
set_value(key_method, _T("PeerInteractiveUIPath") , sz);
set_value(key_method, _T("PeerInvokePasswordDialog"), (DWORD)0);
set_value(key_method, _T("PeerInvokeUsernameDialog"), (DWORD)0);
return S_OK;
} catch(win_runtime_error &err) {
OutputDebugStr(_T("%hs (error %u)\n"), err.what(), err.number());
return E_FAIL;
} catch(...) {
OutputDebugStr(_T("Registering DLL failed.\n"));
return E_FAIL;
}
}
///
/// Unregisters method UI from EapHost registry
///
/// \returns Always S_OK
///
STDAPI DllUnregisterServer()
{
try {
tstring sz;
reg_key key_methods;
if (!key_methods.open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\services\\EapHost\\Methods"), 0, KEY_READ)) throw win_runtime_error();
sprintf(sz, _T("%u\\%u"), EAPMETHOD_AUTHOR_ID, EAPMETHOD_TYPE);
key_methods.delete_subkey(sz.c_str());
} catch(...) {}
return S_OK;
}

BIN
Makefile

Binary file not shown.

Binary file not shown.

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IgnoreImportLibrary>true</IgnoreImportLibrary>
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
<SubSystem>Windows</SubSystem>
<NoEntryPoint>true</NoEntryPoint>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
</Link>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<ResourceCompile>
<PreprocessorDefinitions>AFX_RESOURCE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

View File

@ -81,7 +81,6 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\include\$(Platform).props" />
<Import Project="..\..\..\include\$(Configuration).props" />
<Import Project="..\..\..\include\ResourceDLL.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
@ -96,15 +95,57 @@
<ItemDefinitionGroup>
<ResourceCompile>
<AdditionalIncludeDirectories>temp\Events.$(Platform).$(Configuration).$(PlatformToolset);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>AFX_TARG_NEU;AFX_TARG_ENU;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>AFX_TARG_NEU;AFX_TARG_ENU;AFX_RESOURCE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>$(IntDir);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<ModuleDefinitionFile>..\src\Events.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<AdditionalIncludeDirectories>$(IntDir);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<ModuleDefinitionFile>..\src\Events.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
<AdditionalIncludeDirectories>$(IntDir);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<ModuleDefinitionFile>..\src\Events.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>$(IntDir);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<ModuleDefinitionFile>..\src\Events.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>$(IntDir);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<ModuleDefinitionFile>..\src\Events.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
<AdditionalIncludeDirectories>$(IntDir);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<ModuleDefinitionFile>..\src\Events.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<CustomBuild Include="..\res\EventsETW.man">
<FileType>Document</FileType>
@ -117,6 +158,23 @@
<ItemGroup>
<ResourceCompile Include="..\res\Events.rc" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\PCH.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\src\Register.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\PCH.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\WinStd\build\WinStd-16.0.vcxproj">
<Project>{47399d91-7eb9-41de-b521-514ba5db0c43}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\src\Events.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
@ -24,4 +24,22 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\Register.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\PCH.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\PCH.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\src\Events.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
</Project>

BIN
lib/Events/src/Events.def Normal file

Binary file not shown.

21
lib/Events/src/PCH.cpp Normal file
View File

@ -0,0 +1,21 @@
/*
Copyright 2020-2020 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 "PCH.h"

31
lib/Events/src/PCH.h Normal file
View File

@ -0,0 +1,31 @@
/*
Copyright 2020-2020 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/>.
*/
#pragma once
#include "../../../include/Version.h"
#include <Windows.h>
#include <evntprov.h>
#include <EventsETW.h>
#include <WinStd/Win.h>
#include <tchar.h>

164
lib/Events/src/Register.cpp Normal file
View File

@ -0,0 +1,164 @@
/*
Copyright 2020-2020 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 "PCH.h"
using namespace std;
using namespace winstd;
HINSTANCE g_hInstance;
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ LPCTSTR sValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_SZ, reinterpret_cast<LPCBYTE>(sValue), (DWORD)((_tcslen(sValue) + 1) * sizeof(tstring::value_type)));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ const tstring &sValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_SZ, reinterpret_cast<LPCBYTE>(sValue.c_str()), (DWORD)((sValue.length() + 1) * sizeof(tstring::value_type)));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
static void set_value(_In_ HKEY hKey, _In_opt_z_ LPCTSTR lpValueName, _In_ DWORD dwValue)
{
LSTATUS s = RegSetValueEx(hKey, lpValueName, 0, REG_DWORD, reinterpret_cast<LPCBYTE>(&dwValue), sizeof(dwValue));
if (s != ERROR_SUCCESS)
throw win_runtime_error(s, "RegSetValueEx failed.");
}
BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
if (fdwReason == DLL_PROCESS_ATTACH) {
#ifdef _DEBUG
//Sleep(10000);
#endif
g_hInstance = hinstDLL;
} else if (fdwReason == DLL_PROCESS_DETACH)
assert(!_CrtDumpMemoryLeaks());
return TRUE;
}
///
/// Registers event source in Windows registry
///
/// \returns S_OK if successful; E_FAIL otherwise
///
STDAPI DllRegisterServer()
{
try {
tstring sz, event_provider_name(_T(VENDOR_NAME_STR) _T("-") _T(PRODUCT_NAME_STR) _T("-EAPMethod"));
tstring_guid event_provider_guid(EAPMETHOD_TRACE_EVENT_PROVIDER);
// Register event channels.
reg_key key_channels, key_channels_operational, key_channels_analytic;
if (!key_channels.open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Channels"), 0, KEY_CREATE_SUB_KEY)) throw win_runtime_error();
sprintf(sz, _T("%s/Operational"), event_provider_name.c_str());
if (!key_channels_operational.create(key_channels, sz.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
set_value(key_channels_operational, _T("OwningPublisher") , event_provider_guid);
set_value(key_channels_operational, _T("Enabled") , (DWORD)0);
set_value(key_channels_operational, _T("Isolation") , (DWORD)0);
set_value(key_channels_operational, _T("ChannelAccess") , _T("O:BAG:SYD:(A;;0xf0007;;;SY)(A;;0x7;;;BA)(A;;0x7;;;SO)(A;;0x3;;;IU)(A;;0x3;;;SU)(A;;0x3;;;S-1-5-3)(A;;0x3;;;S-1-5-33)(A;;0x1;;;S-1-5-32-573)"));
set_value(key_channels_operational, _T("MaxSize") , (DWORD)1048576);
set_value(key_channels_operational, _T("MaxSizeUpper") , (DWORD)0);
set_value(key_channels_operational, _T("Retention") , (DWORD)0);
set_value(key_channels_operational, _T("AutoBackupLogFiles"), (DWORD)0);
set_value(key_channels_operational, _T("Type") , (DWORD)1);
sprintf(sz, _T("%s/Analytic"), event_provider_name.c_str());
if (!key_channels_analytic.create(key_channels, sz.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
set_value(key_channels_analytic, _T("OwningPublisher"), event_provider_guid);
set_value(key_channels_analytic, _T("Enabled") , (DWORD)0);
set_value(key_channels_analytic, _T("Isolation") , (DWORD)0);
set_value(key_channels_analytic, _T("ChannelAccess") , _T("O:BAG:SYD:(A;;0xf0007;;;SY)(A;;0x7;;;BA)(A;;0x7;;;SO)(A;;0x3;;;IU)(A;;0x3;;;SU)(A;;0x3;;;S-1-5-3)(A;;0x3;;;S-1-5-33)(A;;0x1;;;S-1-5-32-573)"));
set_value(key_channels_analytic, _T("MaxSize") , (DWORD)1048576);
set_value(key_channels_analytic, _T("MaxSizeUpper") , (DWORD)0);
set_value(key_channels_analytic, _T("Retention") , (DWORD)4294967295);
set_value(key_channels_analytic, _T("Type") , (DWORD)2);
// Register event publishers.
reg_key key_publishers, key_event_source;
if (!key_publishers.open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Publishers"), 0, KEY_CREATE_SUB_KEY)) throw win_runtime_error();
if (!key_event_source.create(key_publishers, event_provider_guid.c_str(), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
set_value(key_event_source, NULL , event_provider_name);
if (!GetModuleFileName(g_hInstance, sz)) throw win_runtime_error("GetModuleFileName failed.");
set_value(key_event_source, _T("MessageFileName") , sz);
set_value(key_event_source, _T("ResourceFileName"), sz);
set_value(key_event_source, _T("Enabled") , (DWORD)1);
// Bind channels and publishers.
reg_key key_channel_refs, key_channel_refs_operational, key_channel_refs_analytic;
if (!key_channel_refs.create(key_event_source, _T("ChannelReferences"), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
if (!key_channel_refs_operational.create(key_channel_refs, _T("0"), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
sprintf(sz, _T("%s/Operational"), event_provider_name.c_str());
set_value(key_channel_refs_operational, NULL , sz);
set_value(key_channel_refs_operational, _T("Id") , (DWORD)16);
set_value(key_channel_refs_operational, _T("Flags"), (DWORD)0);
if (!key_channel_refs_analytic.create(key_channel_refs, _T("1"), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) throw win_runtime_error();
sprintf(sz, _T("%s/Analytic"), event_provider_name.c_str());
set_value(key_channel_refs_analytic, NULL , sz);
set_value(key_channel_refs_analytic, _T("Id") , (DWORD)17);
set_value(key_channel_refs_analytic, _T("Flags"), (DWORD)0);
set_value(key_channel_refs, _T("Count"), (DWORD)2);
return S_OK;
} catch(win_runtime_error &err) {
OutputDebugStr(_T("%hs (error %u)\n"), err.what(), err.number());
return E_FAIL;
} catch(...) {
OutputDebugStr(_T("Registering DLL failed.\n"));
return E_FAIL;
}
}
///
/// Unregisters event source from Windows registry
///
/// \returns Always S_OK
///
STDAPI DllUnregisterServer()
{
// Unregister event publishers.
try {
reg_key key_publishers;
if (!key_publishers.open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Publishers"), 0, KEY_READ)) throw win_runtime_error();
key_publishers.delete_subkey(tstring_guid(EAPMETHOD_TRACE_EVENT_PROVIDER).c_str());
} catch(...) {}
// Unregister event channels.
try {
reg_key key_channels;
if (!key_channels.open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Channels"), 0, KEY_READ)) throw win_runtime_error();
key_channels.delete_subkey(_T(VENDOR_NAME_STR) _T("-") _T(PRODUCT_NAME_STR) _T("-EAPMethod/Operational"));
key_channels.delete_subkey(_T(VENDOR_NAME_STR) _T("-") _T(PRODUCT_NAME_STR) _T("-EAPMethod/Analytic"));
} catch(...) {}
return S_OK;
}

@ -1 +1 @@
Subproject commit 7c5f20d7563a6ab966164c0cdb48f8e1f64c4742
Subproject commit 85075cd419df9488e13f5ebc8aaaf1d65c72ed66