[cpp-sp] branch main updated: Implement config callback for Apache to leverage.

Scott Cantor cantor.2 at osu.edu
Tue Jun 17 17:56:56 UTC 2025


This is an automated email from the git hooks/post-receive script.

scantor 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=6dc91d4957477351a81018d405935fb9446bed36

The following commit(s) were added to refs/heads/main by this push:
     new 6dc91d49 Implement config callback for Apache to leverage.
6dc91d49 is described below

commit 6dc91d4957477351a81018d405935fb9446bed36
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jun 17 13:56:48 2025 -0400

    Implement config callback for Apache to leverage.
---
 apache/mod_shib_24.cpp                         | 14 +++++++++-
 shibsp/AgentConfig.h                           | 37 +++++++++++++++++++++++++-
 shibsp/impl/AgentConfig.cpp                    | 26 +++++++++++++-----
 shibsp/session/impl/AbstractSessionCache.cpp   |  2 +-
 shibsp/session/impl/FilesystemSessionCache.cpp | 12 ++++-----
 5 files changed, 75 insertions(+), 16 deletions(-)

diff --git a/apache/mod_shib_24.cpp b/apache/mod_shib_24.cpp
index 829cbdb3..3e965862 100644
--- a/apache/mod_shib_24.cpp
+++ b/apache/mod_shib_24.cpp
@@ -1436,9 +1436,21 @@ apr_status_t shib_post_config(apr_pool_t* p, apr_pool_t*, apr_pool_t*, server_re
         return !OK;
     }
 
-    AgentConfig::getConfig().RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER, &ApacheRequestMapFactory);
+    // Overrides built-in mapping of Native type into XML for non-Apache platforms.
+    class ApacheAgentCallback : public AgentConfig::AgentConfigCallback {
+    public:
+        ApacheAgentCallback() {}
+        virtual ~ApacheAgentCallback() {}
+
+        bool callback(void*) const {
+            AgentConfig::getConfig().RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER, &ApacheRequestMapFactory);
+            return true;
+        }
+    };
 
     g_Config = &AgentConfig::getConfig();
+    ApacheAgentCallback callback;
+    g_Config->setCallback(&callback);
     try {
         if (!g_Config->init(g_szPrefix, g_szConfigFile, true)) {
             ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_NOERRNO, 0, s, "post_config: shib_module failed to initialize libraries");
diff --git a/shibsp/AgentConfig.h b/shibsp/AgentConfig.h
index d80ff911..db96cc9d 100644
--- a/shibsp/AgentConfig.h
+++ b/shibsp/AgentConfig.h
@@ -51,10 +51,37 @@ namespace shibsp {
     class SHIBSP_API AgentConfig
     {
         MAKE_NONCOPYABLE(AgentConfig);
-    public:
+
+    protected:
         AgentConfig();
+
+    public:
         virtual ~AgentConfig();
 
+        /**
+         * Callback interface for post-initialization work prior to Agent creation.
+         */
+        class SHIBSP_API AgentConfigCallback
+        {
+            MAKE_NONCOPYABLE(AgentConfigCallback);
+            
+        protected:
+            AgentConfigCallback();
+
+        public:
+            virtual ~AgentConfigCallback();
+
+            /**
+             * Method invoked by initialization routine prior to instantiating
+             * the Agent implementation.
+             * 
+             * @param arg callback argument if needed
+             * 
+             * @return true iff initialization should proceed
+             */
+            virtual bool callback(void* arg) const=0;
+        };
+
         /**
          * Returns the global configuration object for the agent.
          *
@@ -69,6 +96,14 @@ namespace shibsp {
          */
         virtual void setCommandLine(bool flag)=0;
 
+        /**
+         * Installs a callback to invoke prior to Agent instantiation.
+         * 
+         * @param callback callback to invoke
+         * @param arg argument to callback if any
+         */
+        virtual void setCallback(const AgentConfigCallback* callback, void* arg=nullptr)=0;
+
         /**
          * Initializes agent/library.
          *
diff --git a/shibsp/impl/AgentConfig.cpp b/shibsp/impl/AgentConfig.cpp
index b78010ad..9e9940db 100644
--- a/shibsp/impl/AgentConfig.cpp
+++ b/shibsp/impl/AgentConfig.cpp
@@ -60,13 +60,17 @@ namespace shibsp {
     class SHIBSP_DLLLOCAL AgentInternalConfig : public AgentConfig
     {
     public:
-        AgentInternalConfig() : m_initCount(0), m_cli(false) {}
+        AgentInternalConfig() : m_initCount(0), m_cli(false), m_callback(nullptr), m_callback_arg(nullptr) {}
         ~AgentInternalConfig() {}
 
         void setCommandLine(bool flag) {
             m_cli = flag;
         }
 
+        void setCallback(const AgentConfigCallback* callback, void* arg=nullptr) {
+            m_callback = callback;
+        }
+
         bool init(const char* inst_prefix=nullptr, const char* config_file=nullptr, bool rethrow=false);
         bool start();
         void term();
@@ -94,6 +98,8 @@ namespace shibsp {
         mutex m_lock;
         ptree m_config;
         bool m_cli;
+        const AgentConfigCallback* m_callback;
+        void* m_callback_arg;
         PathResolver m_pathResolver;
         URLEncoder m_urlEncoder;
         vector<void*> m_libhandles;
@@ -125,6 +131,14 @@ AgentConfig::~AgentConfig()
 {
 }
 
+AgentConfig::AgentConfigCallback::AgentConfigCallback()
+{
+}
+
+AgentConfig::AgentConfigCallback::~AgentConfigCallback()
+{
+}
+
 shibsp::Category& AgentConfig::deprecation() const
 {
     return Category::getInstance(SHIBSP_LOGCAT".DEPRECATION");
@@ -243,14 +257,12 @@ bool AgentInternalConfig::_init(const char* inst_prefix, const char* config_file
         registerSessionCaches();
         registerAgents();
 
-        /*
-        // Yes, this isn't secure, will review where we do any random generation
-        // after full code cleanup is done.
-        srand(static_cast<unsigned int>(std::time(nullptr)));
-        */
-
         loadExtensions(log);
 
+        if (m_callback && !m_callback->callback(m_callback_arg)) {
+            return false;
+        }
+
         // Check for an overridden "agent-type" under the "global" subtree.
         static const char AGENT_TYPE_PROP_PATH[] = "global.agentType";
         string type = m_config.get(AGENT_TYPE_PROP_PATH, DEFAULT_AGENT);
diff --git a/shibsp/session/impl/AbstractSessionCache.cpp b/shibsp/session/impl/AbstractSessionCache.cpp
index 9d743321..a7479ef3 100644
--- a/shibsp/session/impl/AbstractSessionCache.cpp
+++ b/shibsp/session/impl/AbstractSessionCache.cpp
@@ -315,7 +315,7 @@ unique_lock<Session> AbstractSessionCache::find(SPRequest& request, bool checkTi
 
     const char* key = m_cookieManager->getCookieValue(request);
     if (!key) {
-        m_log.debug("no session cookie present, no session found");
+        m_log.debug("no session cookie present");
         return unique_lock<Session>();
     }
 
diff --git a/shibsp/session/impl/FilesystemSessionCache.cpp b/shibsp/session/impl/FilesystemSessionCache.cpp
index 2ee9fc02..07c8aff3 100644
--- a/shibsp/session/impl/FilesystemSessionCache.cpp
+++ b/shibsp/session/impl/FilesystemSessionCache.cpp
@@ -416,8 +416,10 @@ void* FilesystemSessionCache::file_cleanup_fn(void* p)
             break;
         }
 
-        time_t now = time(nullptr);
+        pcache->m_spilog.debug("file cleanup thread running");
 
+        time_t now = time(nullptr);
+        
         // When we wake up, we check the timestamp on the tracking file to determine if we need to do work.
         // This should limit runs across all processes to roughly as much as we intend.
         time_t lastCleanup = FileSupport::getModificationTime(cleanupTracker.c_str());
@@ -443,14 +445,12 @@ void* FilesystemSessionCache::file_cleanup_fn(void* p)
 
         try {
             for (auto& dir_entry : filesystem::directory_iterator{pcache->m_dir}) {
-                if (!dir_entry.is_regular_file()) {
+                if (!dir_entry.is_regular_file() || dir_entry.path() == cleanupTracker) {
                     continue;
                 }
-
+                
                 auto filename = dir_entry.path().filename();
-                if (filename == cleanupTracker) {
-                    continue;
-                } else if (filename.string().size() != 32) {
+                if (filename.string().size() != 32) {
                     pcache->m_spilog.warn("skipping unexpected filename (%s)", filename.c_str());
                     continue;
                 }

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


More information about the commits mailing list