Next integration phase, metadata and trust conversion.
[shibboleth/cpp-sp.git] / apache / mod_apache.cpp
index f8ebc7c..7bf01d2 100644 (file)
 #undef _XOPEN_SOURCE    // causes gethostname conflict in unistd.h
 #endif
 
+#ifdef WIN32
+# define _CRT_NONSTDC_NO_DEPRECATE 1
+# define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+
+#include <shibsp/exceptions.h>
+#include <shibsp/SPConfig.h>
+
 // SAML Runtime
 #include <saml/saml.h>
 #include <shib/shib.h>
-#include <shib/shib-threads.h>
 #include <shib-target/shib-target.h>
 #include <xercesc/util/regx/RegularExpression.hpp>
 
+#ifdef WIN32
+# include <winsock.h>
+#endif
+
 #undef _XPG4_2
 
 // Apache specific header files
 #include <unistd.h>            // for getpid()
 #endif
 
-using namespace std;
-using namespace saml;
-using namespace shibboleth;
+using namespace shibsp;
 using namespace shibtarget;
+using namespace xmltooling;
+using namespace std;
 
 extern "C" module MODULE_VAR_EXPORT mod_shib;
 
@@ -68,6 +79,7 @@ namespace {
     char* g_szSHIBConfig = NULL;
     char* g_szSchemaDir = NULL;
     ShibTargetConfig* g_Config = NULL;
+    string g_unsetHeaderValue;
     static const char* g_UserDataKey = "_shib_check_user_";
 }
 
@@ -116,6 +128,7 @@ struct shib_dir_config
     // Content Configuration
     char* szApplicationId;  // Shib applicationId value
     char* szRequireWith;    // require a session using a specific initiator?
+    char* szRedirectToSSL;  // redirect non-SSL requests to SSL port
     int bOff;               // flat-out disable all Shib processing
     int bBasicHijack;       // activate for AuthType Basic?
     int bRequireSession;    // require a session?
@@ -131,6 +144,7 @@ extern "C" void* create_shib_dir_config (SH_AP_POOL* p, char* d)
     dc->bRequireSession = -1;
     dc->bExportAssertion = -1;
     dc->bRequireAll = -1;
+    dc->szRedirectToSSL = NULL;
     dc->szAuthGrpFile = NULL;
     dc->szApplicationId = NULL;
     dc->szRequireWith = NULL;
@@ -165,6 +179,13 @@ extern "C" void* merge_shib_dir_config (SH_AP_POOL* p, void* base, void* sub)
     else
         dc->szRequireWith=NULL;
 
+    if (child->szRedirectToSSL)
+        dc->szRedirectToSSL=ap_pstrdup(p,child->szRedirectToSSL);
+    else if (parent->szRedirectToSSL)
+        dc->szRedirectToSSL=ap_pstrdup(p,parent->szRedirectToSSL);
+    else
+        dc->szRedirectToSSL=NULL;
+
     dc->bOff=((child->bOff==-1) ? parent->bOff : child->bOff);
     dc->bBasicHijack=((child->bBasicHijack==-1) ? parent->bBasicHijack : child->bBasicHijack);
     dc->bRequireSession=((child->bRequireSession==-1) ? parent->bRequireSession : child->bRequireSession);
@@ -183,7 +204,7 @@ extern "C" const char* ap_set_global_string_slot(cmd_parms* parms, void*, const
 extern "C" const char* shib_set_server_string_slot(cmd_parms* parms, void*, const char* arg)
 {
     char* base=(char*)ap_get_module_config(parms->server->module_config,&mod_shib);
-    int offset=(int)parms->info;
+    size_t offset=(size_t)parms->info;
     *((char**)(base + offset))=ap_pstrdup(parms->pool,arg);
     return NULL;
 }
@@ -205,8 +226,15 @@ extern "C" const char* shib_ap_set_file_slot(cmd_parms* parms,
 
 class ShibTargetApache : public ShibTarget
 {
+  mutable string m_body;
+  mutable bool m_gotBody;
+
 public:
-  ShibTargetApache(request_rec* req) {
+  request_rec* m_req;
+  shib_dir_config* m_dc;
+  shib_server_config* m_sc;
+
+  ShibTargetApache(request_rec* req) : m_gotBody(false) {
     m_sc = (shib_server_config*)ap_get_module_config(req->server->module_config, &mod_shib);
     m_dc = (shib_dir_config*)ap_get_module_config(req->per_dir_config, &mod_shib);
 
@@ -222,7 +250,7 @@ public:
 
     m_req = req;
   }
-  ~ShibTargetApache() { }
+  virtual ~ShibTargetApache() {}
 
   virtual void log(ShibLogLevel level, const string &msg) {
     ShibTarget::log(level,msg);
@@ -244,30 +272,32 @@ public:
     char* val = ap_psprintf(m_req->pool, "%s=%s", name.c_str(), value.c_str());
     ap_table_addn(m_req->err_headers_out, "Set-Cookie", val);
   }
-  virtual string getArgs(void) { return string(m_req->args ? m_req->args : ""); }
-  virtual string getPostData(void) {
+  virtual const char* getQueryString() const { return m_req->args; }
+  virtual const char* getRequestBody() const {
+    if (m_gotBody)
+        return m_body.c_str();
     // Read the posted data
     if (ap_setup_client_block(m_req, REQUEST_CHUNKED_ERROR))
-        throw FatalProfileException("Apache function (setup_client_block) failed while reading profile submission.");
+        throw saml::SAMLException("Apache function (setup_client_block) failed while reading POST request body.");
     if (!ap_should_client_block(m_req))
-        throw FatalProfileException("Apache function (should_client_block) failed while reading profile submission.");
+        throw saml::SAMLException("Apache function (should_client_block) failed while reading POST request body.");
     if (m_req->remaining > 1024*1024)
-        throw FatalProfileException("Blocked too-large a submission to profile endpoint.");
-    string cgistr;
+        throw saml::SAMLException("Blocked POST request body larger than size limit.");
+    m_gotBody=true;
     char buff[HUGE_STRING_LEN];
-    ap_hard_timeout("[mod_shib] getPostData", m_req);
+    ap_hard_timeout("[mod_shib] getRequestBody", m_req);
     memset(buff, 0, sizeof(buff));
     while (ap_get_client_block(m_req, buff, sizeof(buff)-1) > 0) {
       ap_reset_timeout(m_req);
-      cgistr += buff;
+      m_body += buff;
       memset(buff, 0, sizeof(buff));
     }
     ap_kill_timeout(m_req);
-
-    return cgistr;
+    return m_body.c_str();
   }
   virtual void clearHeader(const string &name) {
     ap_table_unset(m_req->headers_in, name.c_str());
+    ap_table_set(m_req->headers_in, name.c_str(), g_unsetHeaderValue.c_str());
   }
   virtual void setHeader(const string &name, const string &value) {
     ap_table_set(m_req->headers_in, name.c_str(), value.c_str());
@@ -286,7 +316,7 @@ public:
     const string& msg,
     int code=200,
     const string& content_type="text/html",
-       const Iterator<header_t>& headers=EMPTY(header_t)
+    const saml::Iterator<header_t>& headers=EMPTY(header_t)
     ) {
     m_req->content_type = ap_psprintf(m_req->pool, content_type.c_str());
     while (headers.hasNext()) {
@@ -303,10 +333,6 @@ public:
   }
   virtual void* returnDecline(void) { return (void*)DECLINED; }
   virtual void* returnOK(void) { return (void*)OK; }
-
-  request_rec* m_req;
-  shib_dir_config* m_dc;
-  shib_server_config* m_sc;
 };
 
 /********************************************************************************/
@@ -339,7 +365,7 @@ extern "C" int shib_check_user(request_rec* r)
     // export happened successfully..  this user is ok.
     return OK;
   }
-  catch (SAMLException& e) {
+  catch (saml::SAMLException& e) {
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an exception: %s", e.what());
     return SERVER_ERROR;
   }
@@ -384,7 +410,7 @@ extern "C" int shib_handler(request_rec* r)
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "doHandler() did not do anything.");
     return SERVER_ERROR;
   }
-  catch (SAMLException& e) {
+  catch (saml::SAMLException& e) {
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an exception: %s", e.what());
     return SERVER_ERROR;
   }
@@ -421,7 +447,7 @@ extern "C" int shib_auth_checker(request_rec* r)
     // We're all okay.
     return OK;
   }
-  catch (SAMLException& e) {
+  catch (saml::SAMLException& e) {
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an exception: %s", e.what());
     return SERVER_ERROR;
   }
@@ -447,12 +473,12 @@ public:
     ) const;
 };
 
-IPlugIn* htAccessFactory(const DOMElement* e)
+saml::IPlugIn* htAccessFactory(const DOMElement* e)
 {
     return new htAccessControl();
 }
 
-class ApacheRequestMapper : public virtual IRequestMapper, public virtual IPropertySet
+class ApacheRequestMapper : public virtual IRequestMapper, public virtual PropertySet
 {
 public:
     ApacheRequestMapper(const DOMElement* e);
@@ -466,7 +492,7 @@ public:
     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 IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
+    const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
     const DOMElement* getElement() const;
 
 private:
@@ -476,18 +502,18 @@ private:
     IAccessControl* m_htaccess;
 };
 
-IPlugIn* ApacheRequestMapFactory(const DOMElement* e)
+saml::IPlugIn* ApacheRequestMapFactory(const DOMElement* e)
 {
     return new ApacheRequestMapper(e);
 }
 
 ApacheRequestMapper::ApacheRequestMapper(const DOMElement* e) : m_mapper(NULL), m_staKey(NULL), m_propsKey(NULL), m_htaccess(NULL)
 {
-    IPlugIn* p=SAMLConfig::getConfig().getPlugMgr().newPlugin(shibtarget::XML::XMLRequestMapType,e);
+    saml::IPlugIn* p=saml::SAMLConfig::getConfig().getPlugMgr().newPlugin(shibtarget::XML::XMLRequestMapType,e);
     m_mapper=dynamic_cast<IRequestMapper*>(p);
     if (!m_mapper) {
         delete p;
-        throw UnsupportedExtensionException("Embedded request mapper plugin was not of correct type.");
+        throw saml::UnsupportedExtensionException("Embedded request mapper plugin was not of correct type.");
     }
     m_htaccess=new htAccessControl();
     m_staKey=ThreadKey::create(NULL);
@@ -499,13 +525,13 @@ IRequestMapper::Settings ApacheRequestMapper::getSettings(ShibTarget* st) const
     Settings s=m_mapper->getSettings(st);
     m_staKey->setData(dynamic_cast<ShibTargetApache*>(st));
     m_propsKey->setData((void*)s.first);
-    return pair<const IPropertySet*,IAccessControl*>(this,s.second ? s.second : m_htaccess);
+    return pair<const PropertySet*,IAccessControl*>(this,s.second ? s.second : m_htaccess);
 }
 
 pair<bool,bool> ApacheRequestMapper::getBool(const char* name, const char* ns) const
 {
     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     if (sta && !ns) {
         // Override Apache-settable boolean properties.
         if (name && !strcmp(name,"requireSession") && sta->m_dc->bRequireSession==1)
@@ -519,7 +545,7 @@ pair<bool,bool> ApacheRequestMapper::getBool(const char* name, const char* ns) c
 pair<bool,const char*> ApacheRequestMapper::getString(const char* name, const char* ns) const
 {
     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     if (sta && !ns) {
         // Override Apache-settable string properties.
         if (name && !strcmp(name,"authType")) {
@@ -535,37 +561,51 @@ pair<bool,const char*> ApacheRequestMapper::getString(const char* name, const ch
             return pair<bool,const char*>(true,sta->m_dc->szApplicationId);
         else if (name && !strcmp(name,"requireSessionWith") && sta->m_dc->szRequireWith)
             return pair<bool,const char*>(true,sta->m_dc->szRequireWith);
+        else if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
+            return pair<bool,const char*>(true,sta->m_dc->szRedirectToSSL);
     }
     return s ? s->getString(name,ns) : pair<bool,const char*>(false,NULL);
 }
 
 pair<bool,const XMLCh*> ApacheRequestMapper::getXMLString(const char* name, const char* ns) const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getXMLString(name,ns) : pair<bool,const XMLCh*>(false,NULL);
 }
 
 pair<bool,unsigned int> ApacheRequestMapper::getUnsignedInt(const char* name, const char* ns) const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
+    if (sta && !ns) {
+        // Override Apache-settable int properties.
+        if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
+            return pair<bool,unsigned int>(true,strtol(sta->m_dc->szRedirectToSSL,NULL,10));
+    }
     return s ? s->getUnsignedInt(name,ns) : pair<bool,unsigned int>(false,0);
 }
 
 pair<bool,int> ApacheRequestMapper::getInt(const char* name, const char* ns) const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
+    if (sta && !ns) {
+        // Override Apache-settable int properties.
+        if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
+            return pair<bool,int>(true,atoi(sta->m_dc->szRedirectToSSL));
+    }
     return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
 }
 
-const IPropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
+const PropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getPropertySet(name,ns) : NULL;
 }
 
 const DOMElement* ApacheRequestMapper::getElement() const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getElement() : NULL;
 }
 
@@ -724,16 +764,20 @@ bool htAccessControl::authorized(
             }
         }
         else {
-            Iterator<IAAP*> provs=st->getApplication()->getAAPProviders();
-            AAP wrapper(provs,w);
+            saml::Iterator<shibboleth::IAAP*> provs=st->getApplication()->getAAPProviders();
+            shibboleth::AAP wrapper(provs,w);
             if (wrapper.fail()) {
                 st->log(ShibTarget::LogLevelWarn, string("htAccessControl plugin didn't recognize require rule: ") + w);
                 continue;
             }
 
             bool regexp=false;
-            const char* vals=ap_table_get(sta->m_req->headers_in,wrapper->getHeader());
-            while (*t && vals) {
+            const char* vals;
+            if (!strcmp(wrapper->getHeader(),"REMOTE_USER"))
+                vals=remote_user.c_str();
+            else
+                vals=ap_table_get(sta->m_req->headers_in,wrapper->getHeader());
+            while (*t && vals && *vals) {
                 w=ap_getword_conf(sta->m_req->pool,&t);
                 if (*w=='~') {
                     regexp=true;
@@ -750,13 +794,13 @@ bool htAccessControl::authorized(
                     }
                     
                     string vals_str(vals);
-                    unsigned int j = 0;
+                    int j = 0;
                     for (unsigned int i = 0;  i < vals_str.length();  i++) {
                         if (vals_str.at(i) == ';') {
                             if (i == 0) {
                                 st->log(ShibTarget::LogLevelError, string("htAccessControl plugin found invalid header encoding (") +
                                     vals + "): starts with a semicolon");
-                                throw SAMLException("Invalid information supplied to authorization plugin.");
+                                throw saml::SAMLException("Invalid information supplied to authorization plugin.");
                             }
 
                             if (vals_str.at(i-1) == '\\') {
@@ -888,27 +932,37 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s)
 
     try {
         g_Config=&ShibTargetConfig::getConfig();
-        g_Config->setFeatures(
-            ShibTargetConfig::Listener |
-            ShibTargetConfig::Metadata |
-            ShibTargetConfig::AAP |
-            ShibTargetConfig::RequestMapper |
-            ShibTargetConfig::LocalExtensions |
-            ShibTargetConfig::Logging
+        SPConfig::getConfig().setFeatures(
+            SPConfig::Caching |
+            SPConfig::Listener |
+            SPConfig::Metadata |
+            SPConfig::AAP |
+            SPConfig::RequestMapper |
+            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);
         }
-        SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::htAccessControlType,&htAccessFactory);
-        SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&ApacheRequestMapFactory);
+        saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::htAccessControlType,&htAccessFactory);
+        saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&ApacheRequestMapFactory);
         // We hijack the legacy type so that 1.2 config files will load this plugin
-        SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&ApacheRequestMapFactory);
+        saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&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();
+        saml::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;
+        }
     }
     catch (...) {
         ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize system");
@@ -928,16 +982,14 @@ typedef const char* (*config_fn_t)(void);
 // SHIB Module commands
 
 static command_rec shire_cmds[] = {
-  {"SHIREConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
-   RSRC_CONF, TAKE1, "Path to shibboleth.xml config file."},
   {"ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
-   RSRC_CONF, TAKE1, "Path to shibboleth.xml config file."},
+   RSRC_CONF, TAKE1, "Path to shibboleth.xml config file"},
   {"ShibSchemaDir", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
-   RSRC_CONF, TAKE1, "Path to Shibboleth XML schema directory."},
+   RSRC_CONF, TAKE1, "Path to Shibboleth XML schema directory"},
 
   {"ShibURLScheme", (config_fn_t)shib_set_server_string_slot,
    (void *) XtOffsetOf (shib_server_config, szScheme),
-   RSRC_CONF, TAKE1, "URL scheme to force into generated URLs for a vhost."},
+   RSRC_CONF, TAKE1, "URL scheme to force into generated URLs for a vhost"},
    
   {"ShibDisable", (config_fn_t)ap_set_flag_slot,
    (void *) XtOffsetOf (shib_dir_config, bOff),
@@ -947,22 +999,25 @@ static command_rec shire_cmds[] = {
    OR_AUTHCFG, TAKE1, "Set Shibboleth applicationId property for content"},
   {"ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
    (void *) XtOffsetOf (shib_dir_config, bBasicHijack),
-   OR_AUTHCFG, FLAG, "Respond to AuthType Basic and convert to shib?"},
+   OR_AUTHCFG, FLAG, "Respond to AuthType Basic and convert to shibboleth"},
   {"ShibRequireSession", (config_fn_t)ap_set_flag_slot,
    (void *) XtOffsetOf (shib_dir_config, bRequireSession),
-   OR_AUTHCFG, FLAG, "Initiates a new session if one does not exist."},
+   OR_AUTHCFG, FLAG, "Initiates a new session if one does not exist"},
   {"ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
    (void *) XtOffsetOf (shib_dir_config, szRequireWith),
    OR_AUTHCFG, TAKE1, "Initiates a new session if one does not exist using a specific SessionInitiator"},
   {"ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
    (void *) XtOffsetOf (shib_dir_config, bExportAssertion),
-   OR_AUTHCFG, FLAG, "Export SAML attribute assertion(s) to Shib-Attributes header?"},
+   OR_AUTHCFG, FLAG, "Export SAML attribute assertion(s) to Shib-Attributes header"},
+  {"ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
+   (void *) XtOffsetOf (shib_dir_config, szRedirectToSSL),
+   OR_AUTHCFG, TAKE1, "Redirect non-SSL requests to designated port" },
   {"AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
    (void *) XtOffsetOf (shib_dir_config, szAuthGrpFile),
    OR_AUTHCFG, TAKE1, "text file containing group names and member user IDs"},
   {"ShibRequireAll", (config_fn_t)ap_set_flag_slot,
    (void *) XtOffsetOf (shib_dir_config, bRequireAll),
-   OR_AUTHCFG, FLAG, "All require directives must match!"},
+   OR_AUTHCFG, FLAG, "All require directives must match"},
 
   {NULL}
 };
@@ -995,7 +1050,7 @@ module MODULE_VAR_EXPORT mod_shib = {
     NULL                       /* post read-request */
 };
 
-#elif defined(SHIB_APACHE_20)
+#elif defined(SHIB_APACHE_20) || defined(SHIB_APACHE_22)
 
 extern "C" void shib_register_hooks (apr_pool_t *p)
 {
@@ -1011,40 +1066,43 @@ extern "C" {
 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."),
+               RSRC_CONF, "Path to shibboleth.xml config file"),
   AP_INIT_TAKE1("ShibSchemaDir",
      (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
-      RSRC_CONF, "Path to Shibboleth XML schema directory."),
+      RSRC_CONF, "Path to Shibboleth XML schema directory"),
 
   AP_INIT_TAKE1("ShibURLScheme",
      (config_fn_t)shib_set_server_string_slot,
      (void *) offsetof (shib_server_config, szScheme),
-      RSRC_CONF, "URL scheme to force into generated URLs for a vhost."),
+      RSRC_CONF, "URL scheme to force into generated URLs for a vhost"),
 
   AP_INIT_FLAG("ShibDisable", (config_fn_t)ap_set_flag_slot,
-         (void *) offsetof (shib_dir_config, bOff),
+        (void *) offsetof (shib_dir_config, bOff),
         OR_AUTHCFG, "Disable all Shib module activity here to save processing effort"),
   AP_INIT_TAKE1("ShibApplicationId", (config_fn_t)ap_set_string_slot,
-         (void *) offsetof (shib_dir_config, szApplicationId),
+        (void *) offsetof (shib_dir_config, szApplicationId),
         OR_AUTHCFG, "Set Shibboleth applicationId property for content"),
   AP_INIT_FLAG("ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
-              (void *) offsetof (shib_dir_config, bBasicHijack),
-              OR_AUTHCFG, "Respond to AuthType Basic and convert to shib?"),
+        (void *) offsetof (shib_dir_config, bBasicHijack),
+        OR_AUTHCFG, "Respond to AuthType Basic and convert to shibboleth"),
   AP_INIT_FLAG("ShibRequireSession", (config_fn_t)ap_set_flag_slot,
-         (void *) offsetof (shib_dir_config, bRequireSession),
-        OR_AUTHCFG, "Initiates a new session if one does not exist."),
+        (void *) offsetof (shib_dir_config, bRequireSession),
+        OR_AUTHCFG, "Initiates a new session if one does not exist"),
   AP_INIT_TAKE1("ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
-         (void *) offsetof (shib_dir_config, szRequireWith),
+        (void *) offsetof (shib_dir_config, szRequireWith),
         OR_AUTHCFG, "Initiates a new session if one does not exist using a specific SessionInitiator"),
   AP_INIT_FLAG("ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
-         (void *) offsetof (shib_dir_config, bExportAssertion),
-        OR_AUTHCFG, "Export SAML attribute assertion(s) to Shib-Attributes header?"),
+        (void *) offsetof (shib_dir_config, bExportAssertion),
+        OR_AUTHCFG, "Export SAML attribute assertion(s) to Shib-Attributes header"),
+  AP_INIT_TAKE1("ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
+        (void *) offsetof (shib_dir_config, szRedirectToSSL),
+        OR_AUTHCFG, "Redirect non-SSL requests to designated port"),
   AP_INIT_TAKE1("AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
                (void *) offsetof (shib_dir_config, szAuthGrpFile),
                OR_AUTHCFG, "Text file containing group names and member user IDs"),
   AP_INIT_FLAG("ShibRequireAll", (config_fn_t)ap_set_flag_slot,
-              (void *) offsetof (shib_dir_config, bRequireAll),
-              OR_AUTHCFG, "All require directives must match!"),
+        (void *) offsetof (shib_dir_config, bRequireAll),
+        OR_AUTHCFG, "All require directives must match"),
 
   {NULL}
 };