[cpp-sp] 02/02: IIS: Log directly to the event log if we fail before the configuration is loaded

Rod Widdowson rdw at steadingsoftware.com
Thu Jan 23 13:43:28 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=44fdf3dc6b764537b6ff40eec796cb1cf53af24f

commit 44fdf3dc6b764537b6ff40eec796cb1cf53af24f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jan 23 13:41:03 2025 +0000

    IIS: Log directly to the event log if we fail before the configuration is loaded
---
 Projects/vc22/iis.vcxproj                     | 11 +++++++++--
 iis7_shib/register.cpp                        |  9 ++++++++-
 shibsp/logging/impl/NativeEventLog.mc         |  2 ++
 shibsp/logging/impl/WindowsLoggingService.cpp |  4 ++--
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/Projects/vc22/iis.vcxproj b/Projects/vc22/iis.vcxproj
index cc7d0a3f..cc287483 100644
--- a/Projects/vc22/iis.vcxproj
+++ b/Projects/vc22/iis.vcxproj
@@ -31,7 +31,14 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\iis7_shib\IIS7Request.cpp" />
-    <ClCompile Include="..\..\iis7_shib\register.cpp" />
+    <ClCompile Include="..\..\iis7_shib\register.cpp">
+      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)shibsp\$(configuration)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)shibsp\$(configuration)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir)shibsp\$(platform)\$(configuration)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir)shibsp\$(platform)\$(configuration)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)shibsp\$(platform)\$(configuration)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)shibsp\$(platform)\$(configuration)</AdditionalIncludeDirectories>
+    </ClCompile>
     <ClCompile Include="..\..\iis7_shib\ShibHttpModule.cpp" />
     <ClCompile Include="..\..\iis7_shib\ShibUser.cpp" />
   </ItemGroup>
@@ -259,4 +266,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/iis7_shib/register.cpp b/iis7_shib/register.cpp
index 8908ab64..d5a6cc9c 100644
--- a/iis7_shib/register.cpp
+++ b/iis7_shib/register.cpp
@@ -24,6 +24,7 @@
 #include <codecvt> // 16 bit to 8 bit and vice versa chars
 #include <boost/algorithm/string.hpp>
 #include <boost/lexical_cast.hpp>
+#include "NativeEventLog.h"
 
 namespace Config {
     HINSTANCE g_hinstDLL;
@@ -87,7 +88,13 @@ RegisterModule(
 
     g_Config = &AgentConfig::getConfig();
     if (!g_Config->init()) {
-        log.crit("IIS module failed during library initialization, check log for detail");
+        //
+        // There is a bootstrap issue so we will just log to the Event viewer
+        //
+        HANDLE eventSource = ::RegisterEventSourceA(NULL, SHIB_EVENT_SOURCE_NAME);
+        const char* msgs[2]{ "II7 Initialization" ,"IIS module failed during library initialization"};
+        ::ReportEventA(eventSource, EVENTLOG_ERROR_TYPE, (WORD)SHIBSP_CATEGORY_CRIT, SHIBSP_LOG_CRIT);
+        ::DeregisterEventSource(eventSource);
         g_Config=nullptr;
         return E_FAIL;
     }
diff --git a/shibsp/logging/impl/NativeEventLog.mc b/shibsp/logging/impl/NativeEventLog.mc
index f0941fb4..c1b5555d 100644
--- a/shibsp/logging/impl/NativeEventLog.mc
+++ b/shibsp/logging/impl/NativeEventLog.mc
@@ -1,3 +1,5 @@
+;#define SHIB_EVENT_SOURCE_NAME "ShibbolethSPAgent"
+
 MessageId=0x1
 Severity=Error
 SymbolicName=SHIBSP_LOG_CRIT
diff --git a/shibsp/logging/impl/WindowsLoggingService.cpp b/shibsp/logging/impl/WindowsLoggingService.cpp
index 40bea0ce..96d0e2d8 100644
--- a/shibsp/logging/impl/WindowsLoggingService.cpp
+++ b/shibsp/logging/impl/WindowsLoggingService.cpp
@@ -58,10 +58,10 @@ WindowsLoggingService::WindowsLoggingService(const ptree& pt) : AbstractLoggingS
 {
     // No dedicated settings at the moment, might be worth supporting some kind of
     // message formatting.
-    m_EventSource = ::RegisterEventSourceA(NULL, "ShibbolethSPAgent");
+    m_EventSource = ::RegisterEventSourceA(NULL, SHIB_EVENT_SOURCE_NAME);
 
     if (m_EventSource == NULL) {
-        string error("Could not load event source check HKLM\\SYSTEM\\CurrentControlSet\\EventLog\\Application\\ShibbolethSPAgent.  GLE = ");
+        string error("Could not load event source check HKLM\\SYSTEM\\CurrentControlSet\\EventLog\\Application\\" SHIB_EVENT_SOURCE_NAME ".  GLE = ");
         error += to_string(GetLastError());
         throw new ConfigurationException(error.c_str());
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list