New -lite library and elimination of SAML libraries from modules.
[shibboleth/cpp-sp.git] / apache / mod_apache.cpp
index 96bcf78..aac8ac4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2005 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 # define _CRT_SECURE_NO_DEPRECATE 1
 #endif
 
+#include <shibsp/AbstractSPRequest.h>
 #include <shibsp/AccessControl.h>
 #include <shibsp/exceptions.h>
 #include <shibsp/RequestMapper.h>
 #include <shibsp/SPConfig.h>
+#include <shibsp/ServiceProvider.h>
+#include <shibsp/SessionCache.h>
+#include <shibsp/attribute/Attribute.h>
 
-// SAML Runtime
-#include <saml/saml.h>
-#include <shib/shib.h>
-#include <shib-target/shib-target.h>
 #include <xercesc/util/regx/RegularExpression.hpp>
+#include <xmltooling/XMLToolingConfig.h>
 #include <xmltooling/util/NDC.h>
 #include <xmltooling/util/Threads.h>
+#include <xmltooling/util/XMLConstants.h>
+#include <xmltooling/util/XMLHelper.h>
 
 #ifdef WIN32
 # include <winsock.h>
 #endif
 
 using namespace shibsp;
-using namespace shibtarget;
 using namespace xmltooling;
 using namespace std;
+using xercesc::RegularExpression;
+using xercesc::XMLException;
 
 extern "C" module MODULE_VAR_EXPORT mod_shib;
 
 namespace {
-    char* g_szSHIBConfig = NULL;
-    char* g_szSchemaDir = NULL;
-    ShibTargetConfig* g_Config = NULL;
+    char* g_szSHIBConfig = SHIBSP_CONFIG;
+    char* g_szSchemaDir = SHIBSP_SCHEMAS;
+    SPConfig* g_Config = NULL;
     string g_unsetHeaderValue;
     static const char* g_UserDataKey = "_shib_check_user_";
+    static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
+    static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e);
 }
 
 /* Apache 2.2.x headers must be accumulated and set in the output filter.
@@ -259,11 +265,11 @@ extern "C" const char* shib_ap_set_file_slot(cmd_parms* parms,
 /********************************************************************************/
 // Apache ShibTarget subclass(es) here.
 
-class ShibTargetApache : public ShibTarget
+class ShibTargetApache : public AbstractSPRequest
 {
   mutable string m_body;
   mutable bool m_gotBody;
-  vector<XSECCryptoX509*> m_certs;
+  vector<string> m_certs;
 
 public:
   request_rec* m_req;
@@ -276,13 +282,6 @@ public:
     m_dc = (shib_dir_config*)ap_get_module_config(req->per_dir_config, &mod_shib);
     m_rc = (shib_request_config*)ap_get_module_config(req->request_config, &mod_shib);
     m_req = req;
-
-    init(
-        m_sc->szScheme ? m_sc->szScheme : ap_http_method(req),
-           ap_get_server_name(req),
-        (int)ap_get_server_port(req),
-           req->unparsed_uri
-        );
   }
   virtual ~ShibTargetApache() {}
 
@@ -325,15 +324,21 @@ public:
   }
   const char* getQueryString() const { return m_req->args; }
   const char* getRequestBody() const {
-    if (m_gotBody)
+    if (m_gotBody || m_req->method_number==M_GET)
         return m_body.c_str();
     // Read the posted data
-    if (ap_setup_client_block(m_req, REQUEST_CHUNKED_ERROR))
-        throw opensaml::BindingException("Apache function (setup_client_block) failed while reading POST request body.");
-    if (!ap_should_client_block(m_req))
-        throw opensaml::BindingException("Apache function (should_client_block) failed while reading POST request body.");
+    if (ap_setup_client_block(m_req, REQUEST_CHUNKED_DECHUNK) != OK) {
+        m_gotBody=true;
+        log(SPError, "Apache function (setup_client_block) failed while reading request body.");
+        return m_body.c_str();
+    }
+    if (!ap_should_client_block(m_req)) {
+        m_gotBody=true;
+        log(SPError, "Apache function (should_client_block) failed while reading request body.");
+        return m_body.c_str();
+    }
     if (m_req->remaining > 1024*1024)
-        throw opensaml::BindingException("Blocked POST request body larger than size limit.");
+        throw opensaml::SecurityPolicyException("Blocked request body larger than 1M size limit.");
     m_gotBody=true;
     char buff[HUGE_STRING_LEN];
     ap_hard_timeout("[mod_shib] getRequestBody", m_req);
@@ -413,13 +418,13 @@ public:
         in.read(buf,1024);
         ap_rwrite(buf,in.gcount(),m_req);
     }
-    return ((status==SAML_HTTP_STATUS_OK) ? DONE : status);
+    return ((status==XMLTOOLING_HTTP_STATUS_OK) ? DONE : status);
   }
   long sendRedirect(const char* url) {
     ap_table_set(m_req->headers_out, "Location", url);
     return REDIRECT;
   }
-  const vector<XSECCryptoX509*>& getClientCertificates() const {
+  const vector<string>& getClientCertificates() const {
       return m_certs;
   }
   long returnDecline(void) { return DECLINED; }
@@ -445,12 +450,12 @@ extern "C" int shib_check_user(request_rec* r)
     ShibTargetApache sta(r);
 
     // Check user authentication and export information, then set the handler bypass
-    pair<bool,long> res = sta.doCheckAuthN(true);
+    pair<bool,long> res = sta.getServiceProvider().doAuthentication(sta,true);
     apr_pool_userdata_setn((const void*)42,g_UserDataKey,NULL,r->pool);
     if (res.first) return res.second;
 
     // user auth was okay -- export the assertions now
-    res = sta.doExportAssertions();
+    res = sta.getServiceProvider().doExport(sta);
     if (res.first) return res.second;
 
     // export happened successfully..  this user is ok.
@@ -495,7 +500,7 @@ extern "C" int shib_handler(request_rec* r)
   try {
     ShibTargetApache sta(r);
 
-    pair<bool,long> res = sta.doHandler();
+    pair<bool,long> res = sta.getServiceProvider().doHandler(sta);
     if (res.first) return res.second;
 
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "doHandler() did not do anything.");
@@ -532,7 +537,7 @@ extern "C" int shib_auth_checker(request_rec* r)
   try {
     ShibTargetApache sta(r);
 
-    pair<bool,long> res = sta.doCheckAuthZ();
+    pair<bool,long> res = sta.getServiceProvider().doAuthorization(sta);
     if (res.first) return res.second;
 
     // We're all okay.
@@ -558,10 +563,12 @@ public:
     ~htAccessControl() {}
     Lockable* lock() {return this;}
     void unlock() {}
-    bool authorized(SPRequest& request, Session* session) const;
+    bool authorized(const SPRequest& request, const Session* session) const;
+private:
+    bool checkAttribute(const SPRequest& request, const Attribute* attr, const char* toMatch, RegularExpression* re) const;
 };
 
-AccessControl* htAccessFactory(const DOMElement* const & e)
+AccessControl* htAccessFactory(const xercesc::DOMElement* const & e)
 {
     return new htAccessControl();
 }
@@ -569,19 +576,20 @@ AccessControl* htAccessFactory(const DOMElement* const & e)
 class ApacheRequestMapper : public virtual RequestMapper, public virtual PropertySet
 {
 public:
-    ApacheRequestMapper(const DOMElement* e);
+    ApacheRequestMapper(const xercesc::DOMElement* e);
     ~ApacheRequestMapper() { delete m_mapper; delete m_htaccess; delete m_staKey; delete m_propsKey; }
     Lockable* lock() { return m_mapper->lock(); }
     void unlock() { m_staKey->setData(NULL); m_propsKey->setData(NULL); m_mapper->unlock(); }
     Settings getSettings(const SPRequest& request) const;
     
+    void setParent(const PropertySet*) {}
     pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
     pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
     pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
     pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
     pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
-    const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
-    const DOMElement* getElement() const;
+    const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const;
+    const xercesc::DOMElement* getElement() const;
 
 private:
     RequestMapper* m_mapper;
@@ -590,12 +598,12 @@ private:
     AccessControl* m_htaccess;
 };
 
-RequestMapper* ApacheRequestMapFactory(const DOMElement* const & e)
+RequestMapper* ApacheRequestMapFactory(const xercesc::DOMElement* const & e)
 {
     return new ApacheRequestMapper(e);
 }
 
-ApacheRequestMapper::ApacheRequestMapper(const DOMElement* e) : m_mapper(NULL), m_staKey(NULL), m_propsKey(NULL), m_htaccess(NULL)
+ApacheRequestMapper::ApacheRequestMapper(const xercesc::DOMElement* e) : m_mapper(NULL), m_staKey(NULL), m_propsKey(NULL), m_htaccess(NULL)
 {
     m_mapper=SPConfig::getConfig().RequestMapperManager.newPlugin(XML_REQUEST_MAPPER,e);
     m_htaccess=new htAccessControl();
@@ -686,7 +694,7 @@ const PropertySet* ApacheRequestMapper::getPropertySet(const char* name, const c
     return s ? s->getPropertySet(name,ns) : NULL;
 }
 
-const DOMElement* ApacheRequestMapper::getElement() const
+const xercesc::DOMElement* ApacheRequestMapper::getElement() const
 {
     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getElement() : NULL;
@@ -740,10 +748,39 @@ static SH_AP_TABLE* groups_for_user(request_rec* r, const char* user, char* grpf
     return grps;
 }
 
-bool htAccessControl::authorized(SPRequest& request, Session* session) const
+bool htAccessControl::checkAttribute(const SPRequest& request, const Attribute* attr, const char* toMatch, RegularExpression* re) const
+{
+    bool caseSensitive = attr->isCaseSensitive();
+    const vector<string>& vals = attr->getSerializedValues();
+    for (vector<string>::const_iterator v=vals.begin(); v!=vals.end(); ++v) {
+        if (re) {
+            auto_ptr<XMLCh> trans(fromUTF8(v->c_str()));
+            if (re->matches(trans.get())) {
+                request.log(SPRequest::SPDebug,
+                    string("htAccessControl plugin expecting regexp ") + toMatch + ", got " + *v + ": authorization granted"
+                    );
+                return true;
+            }
+        }
+        else if ((caseSensitive && *v == toMatch) || (!caseSensitive && !strcasecmp(v->c_str(), toMatch))) {
+            request.log(SPRequest::SPDebug,
+                string("htAccessControl plugin expecting ") + toMatch + ", got " + *v + ": authorization granted."
+                );
+            return true;
+        }
+        else {
+            request.log(SPRequest::SPDebug,
+                string("htAccessControl plugin expecting ") + toMatch + ", got " + *v + ": authorization not granted."
+                );
+        }
+    }
+    return false;
+}
+
+bool htAccessControl::authorized(const SPRequest& request, const Session* session) const
 {
     // Make sure the object is our type.
-    ShibTargetApache* sta=dynamic_cast<ShibTargetApache*>(&request);
+    const ShibTargetApache* sta=dynamic_cast<const ShibTargetApache*>(&request);
     if (!sta)
         throw ConfigurationException("Request wrapper object was not of correct type.");
 
@@ -833,7 +870,7 @@ bool htAccessControl::authorized(SPRequest& request, Session* session) const
                 grpstatus=groups_for_user(sta->m_req,remote_user.c_str(),sta->m_dc->szAuthGrpFile);
             }
             if (!grpstatus)
-                return false;
+                continue;
     
             while (*t) {
                 w=ap_getword_conf(sta->m_req->pool,&t);
@@ -844,26 +881,23 @@ bool htAccessControl::authorized(SPRequest& request, Session* session) const
             }
         }
         else {
-            saml::Iterator<shibboleth::IAAP*> provs=dynamic_cast<const IApplication&>(request.getSPApplication()).getAAPProviders();
-            shibboleth::AAP wrapper(provs,w);
-            if (wrapper.fail()) {
-                request.log(SPRequest::SPWarn, string("htAccessControl plugin didn't recognize require rule: ") + w);
+            // Map alias in rule to the attribute.
+            if (!session) {
+                request.log(SPRequest::SPError, "htAccessControl plugin not given a valid session to evaluate, are you using lazy sessions?");
+                continue;
+            }
+            
+            // Find the attribute(s) matching the require rule.
+            pair<multimap<string,Attribute*>::const_iterator,multimap<string,Attribute*>::const_iterator> attrs =
+                session->getAttributes().equal_range(w);
+            if (attrs.first == attrs.second) {
+                request.log(SPRequest::SPWarn, string("htAccessControl rule requires attribute (") + w + "), not found in session");
                 continue;
             }
 
             bool regexp=false;
-            const char* vals;
-            if (!strcmp(wrapper->getHeader(),"REMOTE_USER"))
-                vals=remote_user.c_str();
-            else
-                if (sta->m_dc->bUseEnvVars!=0) {
-                   if (sta->m_rc && sta->m_rc->env) vals=ap_table_get(sta->m_rc->env,wrapper->getHeader());
-                   else vals = NULL;
-                } else {
-                   vals=ap_table_get(sta->m_req->headers_in,wrapper->getHeader());
-                }
 
-            while (*t && vals && *vals) {
+            while (!auth_OK[x] && *t) {
                 w=ap_getword_conf(sta->m_req->pool,&t);
                 if (*w=='~') {
                     regexp=true;
@@ -875,71 +909,21 @@ bool htAccessControl::authorized(SPRequest& request, Session* session) const
                     if (regexp) {
                         delete re.release();
                         auto_ptr<XMLCh> trans(fromUTF8(w));
-                        auto_ptr<RegularExpression> temp(new RegularExpression(trans.get()));
+                        auto_ptr<xercesc::RegularExpression> temp(new xercesc::RegularExpression(trans.get()));
                         re=temp;
                     }
                     
-                    string vals_str(vals);
-                    int j = 0;
-                    for (unsigned int i = 0;  i < vals_str.length();  i++) {
-                        if (vals_str.at(i) == ';') {
-                            if (i == 0) {
-                                request.log(SPRequest::SPError, string("htAccessControl plugin found invalid header encoding (") +
-                                    vals + "): starts with a semicolon");
-                                throw saml::SAMLException("Invalid information supplied to authorization plugin.");
-                            }
-
-                            if (vals_str.at(i-1) == '\\') {
-                                vals_str.erase(i-1, 1);
-                                i--;
-                                continue;
-                            }
-
-                            string val = vals_str.substr(j, i-j);
-                            j = i+1;
-                            if (regexp) {
-                                auto_ptr<XMLCh> trans(fromUTF8(val.c_str()));
-                                if (re->matches(trans.get())) {
-                                    request.log(SPRequest::SPDebug, string("htAccessControl plugin expecting ") + w +
-                                       ", got " + val + ": authorization granted");
-                                    SHIB_AP_CHECK_IS_OK;
-                                }
-                            }
-                            else if ((wrapper->getCaseSensitive() && val==w) || (!wrapper->getCaseSensitive() && !strcasecmp(val.c_str(),w))) {
-                                request.log(SPRequest::SPDebug, string("htAccessControl plugin expecting ") + w +
-                                    ", got " + val + ": authorization granted.");
-                                SHIB_AP_CHECK_IS_OK;
-                            }
-                            else {
-                                request.log(SPRequest::SPDebug, string("htAccessControl plugin expecting ") + w +
-                                    ", got " + val + ": authoritzation not granted.");
-                            }
-                        }
-                    }
-    
-                    string val = vals_str.substr(j, vals_str.length()-j);
-                    if (regexp) {
-                        auto_ptr<XMLCh> trans(fromUTF8(val.c_str()));
-                        if (re->matches(trans.get())) {
-                            request.log(SPRequest::SPDebug, string("htAccessControl plugin expecting ") + w +
-                                ", got " + val + ": authorization granted.");
+                    for (; !auth_OK[x] && attrs.first!=attrs.second; ++attrs.first) {
+                        if (checkAttribute(request, attrs.first->second, w, regexp ? re.get() : NULL)) {
                             SHIB_AP_CHECK_IS_OK;
                         }
                     }
-                    else if ((wrapper->getCaseSensitive() && val==w) || (!wrapper->getCaseSensitive() && !strcasecmp(val.c_str(),w))) {
-                        request.log(SPRequest::SPDebug, string("htAccessControl plugin expecting ") + w +
-                            ", got " + val + ": authorization granted");
-                        SHIB_AP_CHECK_IS_OK;
-                    }
-                    else {
-                            request.log(SPRequest::SPDebug, string("htAccessControl plugin expecting ") + w +
-                                ", got " + val + ": authorization not granted");
-                    }
                 }
                 catch (XMLException& ex) {
                     auto_ptr_char tmp(ex.getMessage());
-                    request.log(SPRequest::SPError, string("htAccessControl plugin caught exception while parsing regular expression (")
-                        + w + "): " + tmp.get());
+                    request.log(SPRequest::SPError,
+                        string("htAccessControl plugin caught exception while parsing regular expression (") + w + "): " + tmp.get()
+                        );
                 }
             }
         }
@@ -964,7 +948,7 @@ bool htAccessControl::authorized(SPRequest& request, Session* session) const
 extern "C" apr_status_t shib_exit(void* data)
 {
     if (g_Config) {
-        g_Config->shutdown();
+        g_Config->term();
         g_Config = NULL;
     }
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,0,NULL,"shib_exit() done");
@@ -1021,7 +1005,7 @@ extern "C" apr_status_t shib_child_exit(void* data)
 #endif
 
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit(%d) dealing with g_Config..", (int)getpid());
-    g_Config->shutdown();
+    g_Config->term();
     g_Config = NULL;
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit() done");
 
@@ -1050,43 +1034,47 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s)
         exit(1);
     }
 
+    g_Config=&SPConfig::getConfig();
+    g_Config->setFeatures(
+        SPConfig::Listener |
+        SPConfig::Caching |
+        SPConfig::RequestMapping |
+        SPConfig::InProcess |
+        SPConfig::Logging
+        );
+    if (!g_Config->init(g_szSchemaDir)) {
+        ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries");
+        exit(1);
+    }
+    g_Config->AccessControlManager.registerFactory(HT_ACCESS_CONTROL,&htAccessFactory);
+    g_Config->RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER,&ApacheRequestMapFactory);
+    
     try {
-        g_Config=&ShibTargetConfig::getConfig();
-        SPConfig::getConfig().setFeatures(
-            SPConfig::Caching |
-            SPConfig::Listener |
-            SPConfig::Metadata |
-            SPConfig::AAP |
-            SPConfig::RequestMapping |
-            SPConfig::InProcess |
-            SPConfig::Logging
-            );
-        if (!g_Config->init(g_szSchemaDir)) {
-            ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries");
-            exit(1);
-        }
-        SPConfig::getConfig().AccessControlManager.registerFactory(HT_ACCESS_CONTROL,&htAccessFactory);
-        SPConfig::getConfig().RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER,&ApacheRequestMapFactory);
-        
-        if (!g_Config->load(g_szSHIBConfig)) {
-            ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to load configuration");
-            exit(1);
-        }
-
-        IConfig* conf=g_Config->getINI();
-        xmltooling::Locker locker(conf);
-        const PropertySet* props=conf->getPropertySet("Local");
-        if (props) {
-            pair<bool,const char*> unsetValue=props->getString("unsetHeaderValue");
-            if (unsetValue.first)
-                g_unsetHeaderValue = unsetValue.second;
-        }
+        xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();
+        XercesJanitor<xercesc::DOMDocument> docjanitor(dummydoc);
+        xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,path);
+        auto_ptr_XMLCh src(g_szSHIBConfig);
+        dummy->setAttributeNS(NULL,path,src.get());
+        dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE);
+
+        g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));
+        g_Config->getServiceProvider()->init();
     }
-    catch (...) {
-        ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize system");
+    catch (exception& ex) {
+        ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),ex.what());
+        ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to load configuration");
         exit(1);
     }
 
+    ServiceProvider* sp=g_Config->getServiceProvider();
+    xmltooling::Locker locker(sp);
+    const PropertySet* props=sp->getPropertySet("Local");
+    if (props) {
+        pair<bool,const char*> unsetValue=props->getString("unsetHeaderValue");
+        if (unsetValue.first)
+            g_unsetHeaderValue = unsetValue.second;
+    }
+
     // Set the cleanup handler
     apr_pool_cleanup_register(p, NULL, &shib_exit, &shib_child_exit);
 
@@ -1105,6 +1093,12 @@ static void set_error_filter(request_rec *r)
    ap_add_output_filter("SHIB_HEADERS_ERR", NULL, r, r->connection);
 }
 
+static int _table_add(void *v, const char *key, const char *value)
+{
+    apr_table_addn((apr_table_t*)v, key, value);
+    return 1;
+}
+
 static apr_status_t do_output_filter(ap_filter_t *f, apr_bucket_brigade *in)
 {
     request_rec *r = f->r;
@@ -1112,7 +1106,9 @@ static apr_status_t do_output_filter(ap_filter_t *f, apr_bucket_brigade *in)
 
     if (rc) {
         ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_out_filter: merging %d headers", apr_table_elts(rc->hdr_out)->nelts);
-        apr_table_overlap(r->headers_out, rc->hdr_out, APR_OVERLAP_TABLES_MERGE);
+        apr_table_do(_table_add,r->headers_out, rc->hdr_out,NULL);
+        // can't use overlap call because it will collapse Set-Cookie headers
+        //apr_table_overlap(r->headers_out, rc->hdr_out, APR_OVERLAP_TABLES_MERGE);
     }
 
     /* remove ourselves from the filter chain */
@@ -1129,7 +1125,9 @@ static apr_status_t do_error_filter(ap_filter_t *f, apr_bucket_brigade *in)
 
     if (rc) {
         ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_err_filter: merging %d headers", apr_table_elts(rc->hdr_err)->nelts);
-        apr_table_overlap(r->err_headers_out, rc->hdr_err, APR_OVERLAP_TABLES_MERGE);
+        apr_table_do(_table_add,r->err_headers_out, rc->hdr_err,NULL);
+        // can't use overlap call because it will collapse Set-Cookie headers
+        //apr_table_overlap(r->err_headers_out, rc->hdr_err, APR_OVERLAP_TABLES_MERGE);
     }
 
     /* remove ourselves from the filter chain */
@@ -1149,8 +1147,10 @@ typedef const char* (*config_fn_t)(void);
 static command_rec shire_cmds[] = {
   {"ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
    RSRC_CONF, TAKE1, "Path to shibboleth.xml config file"},
+  {"ShibCatalogs", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
+   RSRC_CONF, TAKE1, "Paths of XML schema catalogs"},
   {"ShibSchemaDir", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
-   RSRC_CONF, TAKE1, "Path to Shibboleth XML schema directory"},
+   RSRC_CONF, TAKE1, "Paths of XML schema catalogs (deprecated in favor of ShibCatalogs)"},
 
   {"ShibURLScheme", (config_fn_t)shib_set_server_string_slot,
    (void *) XtOffsetOf (shib_server_config, szScheme),
@@ -1243,9 +1243,12 @@ static command_rec shib_cmds[] = {
   AP_INIT_TAKE1("ShibConfig",
                (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
                RSRC_CONF, "Path to shibboleth.xml config file"),
+  AP_INIT_TAKE1("ShibCatalogs",
+     (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
+      RSRC_CONF, "Paths of XML schema catalogs"),
   AP_INIT_TAKE1("ShibSchemaDir",
      (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
-      RSRC_CONF, "Path to Shibboleth XML schema directory"),
+      RSRC_CONF, "Paths of XML schema catalogs (deprecated in favor of ShibCatalogs)"),
 
   AP_INIT_TAKE1("ShibURLScheme",
      (config_fn_t)shib_set_server_string_slot,