[cpp-sp] 01/02: Initial Implementatiom of Windiows Event Viewer Logging service
Rod Widdowson
rdw at steadingsoftware.com
Thu Jan 23 13:43:27 UTC 2025
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository cpp-sp.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=eb25014d9db0f464cad687ab740c6087d71103f7
commit eb25014d9db0f464cad687ab740c6087d71103f7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Jan 22 20:33:40 2025 +0000
Initial Implementatiom of Windiows Event Viewer Logging service
---
Projects/vc22/shibsp.vcxproj | 55 +++++++++--
Projects/vc22/shibsp.vcxproj.filters | 8 ++
shibsp/logging/impl/AbstractLoggingService.cpp | 4 +-
shibsp/logging/impl/NativeEventLog.mc | 67 +++++++++++++
shibsp/logging/impl/WindowsLoggingService.cpp | 129 +++++++++++++++++++++++++
5 files changed, 255 insertions(+), 8 deletions(-)
diff --git a/Projects/vc22/shibsp.vcxproj b/Projects/vc22/shibsp.vcxproj
index 0ac8fc12..6f5105e6 100644
--- a/Projects/vc22/shibsp.vcxproj
+++ b/Projects/vc22/shibsp.vcxproj
@@ -142,6 +142,14 @@
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
+ <ClCompile Include="..\..\shibsp\logging\impl\WindowsLoggingService.cpp">
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(intdir)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(intdir)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(intdir)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(intdir)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(intdir)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(intdir)</AdditionalIncludeDirectories>
+ </ClCompile>
<ClCompile Include="..\..\shibsp\platform\iis\ModuleConfig.cpp" />
<ClCompile Include="..\..\shibsp\remoting\impl\AbstractHTTPRemotingService.cpp" />
<ClCompile Include="..\..\shibsp\remoting\impl\AbstractRemotingService.cpp" />
@@ -169,6 +177,41 @@
<ItemGroup>
<ResourceCompile Include="..\..\shibsp\shibsp.rc" />
</ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\shibsp\logging\impl\NativeEventLog.mc">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">if not exist $(IntDir) md $(IntDir)
+mc.exe -h $(IntDir) -r $(IntDir) $(ProjectDir)..\..\shibsp\logging\impl\%(Filename).mc
+rc.exe /D _UNICODE /D UNICODE /l"0x0409" /nologo /fo"$(IntDir)\%(Filename).res" $(IntDir)\%(Filename).rc</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">if not exist $(IntDir) md $(IntDir)
+mc.exe -h $(IntDir) -r $(IntDir) $(ProjectDir)..\..\shibsp\logging\impl\%(Filename).mc
+rc.exe /D _UNICODE /D UNICODE /l"0x0409" /nologo /fo"$(IntDir)\%(Filename).res" $(IntDir)\%(Filename).rc</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">if not exist $(IntDir) md $(IntDir)
+mc.exe -h $(IntDir) -r $(IntDir) $(ProjectDir)..\..\shibsp\logging\impl\%(Filename).mc
+rc.exe /D _UNICODE /D UNICODE /l"0x0409" /nologo /fo"$(IntDir)\%(Filename).res" $(IntDir)\%(Filename).rc</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">if not exist $(IntDir) md $(IntDir)
+mc.exe -h $(IntDir) -r $(IntDir) $(ProjectDir)..\..\shibsp\logging\impl\%(Filename).mc
+rc.exe /D _UNICODE /D UNICODE /l"0x0409" /nologo /fo"$(IntDir)\%(Filename).res" $(IntDir)\%(Filename).rc</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">if not exist $(IntDir) md $(IntDir)
+mc.exe -h $(IntDir) -r $(IntDir) $(ProjectDir)..\..\shibsp\logging\impl\%(Filename).mc
+rc.exe /D _UNICODE /D UNICODE /l"0x0409" /nologo /fo"$(IntDir)\%(Filename).res" $(IntDir)\%(Filename).rc</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">if not exist $(IntDir) md $(IntDir)
+mc.exe -h $(IntDir) -r $(IntDir) $(ProjectDir)..\..\shibsp\logging\impl\%(Filename).mc
+rc.exe /D _UNICODE /D UNICODE /l"0x0409" /nologo /fo"$(IntDir)\%(Filename).res" $(IntDir)\%(Filename).rc</Command>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)%(Filename).rc;$(IntDir)%(Filename).h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)%(Filename).rc;$(IntDir)%(Filename).h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(IntDir)%(Filename).rc;$(IntDir)%(Filename).h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(IntDir)%(Filename).rc;$(IntDir)%(Filename).h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)%(Filename).rc;$(IntDir)%(Filename).h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)%(Filename).rc;$(IntDir)%(Filename).h</Outputs>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
+ </CustomBuild>
+ </ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
@@ -284,7 +327,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
- <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Ws2_32.lib;$(IntDir)\NativeEventLog.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -305,7 +348,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
- <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Ws2_32.lib;$(IntDir)\NativeEventLog.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -322,7 +365,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
- <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Ws2_32.lib;$(IntDir)\NativeEventLog.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
@@ -339,7 +382,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
- <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Ws2_32.lib;$(IntDir)\NativeEventLog.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -360,7 +403,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
- <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Ws2_32.lib;$(IntDir)\NativeEventLog.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
@@ -381,7 +424,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
- <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Ws2_32.lib;$(IntDir)\NativeEventLog.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/Projects/vc22/shibsp.vcxproj.filters b/Projects/vc22/shibsp.vcxproj.filters
index f1371348..eccf12aa 100644
--- a/Projects/vc22/shibsp.vcxproj.filters
+++ b/Projects/vc22/shibsp.vcxproj.filters
@@ -383,10 +383,18 @@
<ClCompile Include="..\..\shibsp\remoting\impl\SecretSource.cpp">
<Filter>Source Files\Remoting</Filter>
</ClCompile>
+ <ClCompile Include="..\..\shibsp\logging\impl\WindowsLoggingService.cpp">
+ <Filter>Source Files\Logging</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\shibsp\shibsp.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\shibsp\logging\impl\NativeEventLog.mc">
+ <Filter>Resource Files</Filter>
+ </CustomBuild>
+ </ItemGroup>
</Project>
\ No newline at end of file
diff --git a/shibsp/logging/impl/AbstractLoggingService.cpp b/shibsp/logging/impl/AbstractLoggingService.cpp
index 782e0eda..bb44872a 100644
--- a/shibsp/logging/impl/AbstractLoggingService.cpp
+++ b/shibsp/logging/impl/AbstractLoggingService.cpp
@@ -41,7 +41,7 @@ namespace shibsp {
extern LoggingService* SHIBSP_DLLLOCAL ConsoleLoggingServiceFactory(ptree& pt, bool);
#ifdef WIN32
- // extern LoggingService* SHIBSP_DLLLOCAL WindowsLoggingServiceFactory(ptree& pt, bool);
+ extern LoggingService* SHIBSP_DLLLOCAL WindowsLoggingServiceFactory(ptree& pt, bool);
#else
extern LoggingService* SHIBSP_DLLLOCAL SyslogLoggingServiceFactory(ptree& pt, bool);
#endif
@@ -52,7 +52,7 @@ void SHIBSP_API shibsp::registerLoggingServices()
AgentConfig& conf=AgentConfig::getConfig();
conf.LoggingServiceManager.registerFactory(CONSOLE_LOGGING_SERVICE, ConsoleLoggingServiceFactory);
#ifdef WIN32
- // conf.LoggingServiceManager.registerFactory(WINDOWS_LOGGING_SERVICE, WindowsLoggingServiceFactory);
+ conf.LoggingServiceManager.registerFactory(WINDOWS_LOGGING_SERVICE, WindowsLoggingServiceFactory);
#else
conf.LoggingServiceManager.registerFactory(SYSLOG_LOGGING_SERVICE, SyslogLoggingServiceFactory);
#endif
diff --git a/shibsp/logging/impl/NativeEventLog.mc b/shibsp/logging/impl/NativeEventLog.mc
new file mode 100644
index 00000000..f0941fb4
--- /dev/null
+++ b/shibsp/logging/impl/NativeEventLog.mc
@@ -0,0 +1,67 @@
+MessageId=0x1
+Severity=Error
+SymbolicName=SHIBSP_LOG_CRIT
+Language=English
+CRITICAL [%1] : [%2]
+.
+
+MessageId=+1
+SymbolicName=SHIBSP_LOG_ERROR
+Language=English
+Error [%1] : [%2]
+.
+
+MessageId=+1
+Severity=Warning
+SymbolicName=SHIBSP_LOG_WARN
+Language=English
+Warn [%1] : [%2]
+.
+
+MessageId=+1
+Severity=Informational
+SymbolicName=SHIBSP_LOG_INFO
+Language=English
+Info [%1] : [%2]
+.
+
+MessageId=+1
+Severity=Success
+SymbolicName=SHIBSP_LOG_DEBUG
+Language=English
+Debug [%1] : [%2]
+.
+
+MessageId=+1
+SymbolicName=SHIBSP_CATEGORY_CRIT
+Language=English
+CRITICAL Category
+.
+
+MessageId=+1
+SymbolicName=SHIBSP_CATEGORY_ERROR
+Language=English
+Error Category
+.
+
+MessageId=+1
+Severity=Warning
+SymbolicName=SHIBSP_CATEGORY_WARN
+Language=English
+War Category
+.
+
+MessageId=+1
+Severity=Informational
+SymbolicName=SHIBSP_CATEGORY_INFO
+Language=English
+Info Category
+.
+
+MessageId=+1
+Severity=Success
+SymbolicName=SHIBSP_CATEGORY_DEBUG
+Language=English
+Debug Category
+.
+
diff --git a/shibsp/logging/impl/WindowsLoggingService.cpp b/shibsp/logging/impl/WindowsLoggingService.cpp
new file mode 100644
index 00000000..40bea0ce
--- /dev/null
+++ b/shibsp/logging/impl/WindowsLoggingService.cpp
@@ -0,0 +1,129 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /**
+ * logging/impl/WindowsLoggingService.cpp
+ *
+ * Logging service implementation using the Windows Even log.
+ */
+
+#include "internal.h"
+#include "logging/impl/AbstractLoggingService.h"
+#include "exceptions.h"
+#include "logging/priority.h"
+#include "NativeEventLog.h"
+
+#include <boost/property_tree/ptree.hpp>
+
+#include <Windows.h>
+
+using namespace shibsp;
+using namespace boost::property_tree;
+using namespace std;
+
+namespace shibsp {
+
+ class WindowsLoggingService : public virtual AbstractLoggingService {
+ public:
+ WindowsLoggingService(const ptree& pt);
+ ~WindowsLoggingService();
+
+ void outputMessage(const Category& category, Priority::Value prio, const string& message) {
+ outputMessage(category, prio, message.c_str());
+ }
+ void outputMessage(const Category& category, Priority::Value prio, const char* message);
+
+ protected:
+
+ HANDLE m_EventSource;
+ };
+
+ LoggingService* SHIBSP_DLLLOCAL WindowsLoggingServiceFactory(ptree& pt, bool) {
+ return new WindowsLoggingService(pt);
+ }
+}
+
+WindowsLoggingService::WindowsLoggingService(const ptree& pt) : AbstractLoggingService(pt)
+{
+ // No dedicated settings at the moment, might be worth supporting some kind of
+ // message formatting.
+ m_EventSource = ::RegisterEventSourceA(NULL, "ShibbolethSPAgent");
+
+ if (m_EventSource == NULL) {
+ string error("Could not load event source check HKLM\\SYSTEM\\CurrentControlSet\\EventLog\\Application\\ShibbolethSPAgent. GLE = ");
+ error += to_string(GetLastError());
+ throw new ConfigurationException(error.c_str());
+ }
+}
+
+WindowsLoggingService::~WindowsLoggingService() {
+
+ if (m_EventSource) {
+ ::DeregisterEventSource(m_EventSource);
+ }
+}
+
+static DWORD EventIdFor(const DWORD priority) {
+
+ if (priority < Priority::PriorityLevel::SHIB_ERROR) {
+ return SHIBSP_LOG_CRIT;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_WARN) {
+ return SHIBSP_LOG_ERROR;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_INFO) {
+ return SHIBSP_LOG_WARN;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_DEBUG) {
+ return SHIBSP_LOG_INFO;
+ }
+ return SHIBSP_LOG_DEBUG;
+}
+
+static WORD EventTypeFor(const DWORD priority) {
+ if (priority < Priority::PriorityLevel::SHIB_WARN) {
+ return EVENTLOG_ERROR_TYPE;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_INFO) {
+ return EVENTLOG_WARNING_TYPE;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_DEBUG) {
+ return EVENTLOG_INFORMATION_TYPE;
+ }
+ return EVENTLOG_SUCCESS;
+}
+
+static WORD EventCategoryFor(const DWORD priority) {
+
+ if (priority < Priority::PriorityLevel::SHIB_ERROR) {
+ return (WORD) SHIBSP_CATEGORY_CRIT;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_WARN) {
+ return (WORD) SHIBSP_CATEGORY_ERROR;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_INFO) {
+ return (WORD) SHIBSP_CATEGORY_WARN;
+ }
+ if (priority < Priority::PriorityLevel::SHIB_DEBUG) {
+ return (WORD) SHIBSP_CATEGORY_INFO;
+ }
+ return (WORD) SHIBSP_CATEGORY_DEBUG;
+}
+
+
+void WindowsLoggingService::outputMessage(const Category& category, Priority::Value priority, const char* message)
+{
+ const char* msgs[2] {category.getName().c_str(),message};
+ ::ReportEventA(m_EventSource, EventTypeFor(priority), EventCategoryFor(priority), EventIdFor(priority), NULL, 2, 0, msgs, NULL);
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list