Next integration phase, metadata and trust conversion.
[shibboleth/cpp-sp.git] / apache / mod_apache.cpp
1 /*
2  *  Copyright 2001-2005 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * mod_apache.cpp -- the core Apache Module code
19  *
20  * Created by:  Derek Atkins <derek@ihtfp.com>
21  *
22  * $Id$
23  */
24
25 #ifdef SOLARIS2
26 #undef _XOPEN_SOURCE    // causes gethostname conflict in unistd.h
27 #endif
28
29 #ifdef WIN32
30 # define _CRT_NONSTDC_NO_DEPRECATE 1
31 # define _CRT_SECURE_NO_DEPRECATE 1
32 #endif
33
34 #include <shibsp/exceptions.h>
35 #include <shibsp/SPConfig.h>
36
37 // SAML Runtime
38 #include <saml/saml.h>
39 #include <shib/shib.h>
40 #include <shib-target/shib-target.h>
41 #include <xercesc/util/regx/RegularExpression.hpp>
42
43 #ifdef WIN32
44 # include <winsock.h>
45 #endif
46
47 #undef _XPG4_2
48
49 // Apache specific header files
50 #include <httpd.h>
51 #include <http_config.h>
52 #include <http_protocol.h>
53 #include <http_main.h>
54 #define CORE_PRIVATE
55 #include <http_core.h>
56 #include <http_log.h>
57
58 #ifndef SHIB_APACHE_13
59 #include <http_request.h>
60 #include <apr_strings.h>
61 #include <apr_pools.h>
62 #endif
63
64 #include <fstream>
65 #include <sstream>
66
67 #ifdef HAVE_UNISTD_H
68 #include <unistd.h>             // for getpid()
69 #endif
70
71 using namespace shibsp;
72 using namespace shibtarget;
73 using namespace xmltooling;
74 using namespace std;
75
76 extern "C" module MODULE_VAR_EXPORT mod_shib;
77
78 namespace {
79     char* g_szSHIBConfig = NULL;
80     char* g_szSchemaDir = NULL;
81     ShibTargetConfig* g_Config = NULL;
82     string g_unsetHeaderValue;
83     static const char* g_UserDataKey = "_shib_check_user_";
84 }
85
86 /********************************************************************************/
87 // Basic Apache Configuration code.
88 //
89
90 // per-server module configuration structure
91 struct shib_server_config
92 {
93     char* szScheme;
94 };
95
96 // creates the per-server configuration
97 extern "C" void* create_shib_server_config(SH_AP_POOL* p, server_rec* s)
98 {
99     shib_server_config* sc=(shib_server_config*)ap_pcalloc(p,sizeof(shib_server_config));
100     sc->szScheme = NULL;
101     return sc;
102 }
103
104 // overrides server configuration in virtual servers
105 extern "C" void* merge_shib_server_config (SH_AP_POOL* p, void* base, void* sub)
106 {
107     shib_server_config* sc=(shib_server_config*)ap_pcalloc(p,sizeof(shib_server_config));
108     shib_server_config* parent=(shib_server_config*)base;
109     shib_server_config* child=(shib_server_config*)sub;
110
111     if (child->szScheme)
112         sc->szScheme=ap_pstrdup(p,child->szScheme);
113     else if (parent->szScheme)
114         sc->szScheme=ap_pstrdup(p,parent->szScheme);
115     else
116         sc->szScheme=NULL;
117
118     return sc;
119 }
120
121 // per-dir module configuration structure
122 struct shib_dir_config
123 {
124     // RM Configuration
125     char* szAuthGrpFile;    // Auth GroupFile name
126     int bRequireAll;        // all require directives must match, otherwise OR logic
127
128     // Content Configuration
129     char* szApplicationId;  // Shib applicationId value
130     char* szRequireWith;    // require a session using a specific initiator?
131     char* szRedirectToSSL;  // redirect non-SSL requests to SSL port
132     int bOff;               // flat-out disable all Shib processing
133     int bBasicHijack;       // activate for AuthType Basic?
134     int bRequireSession;    // require a session?
135     int bExportAssertion;   // export SAML assertion to the environment?
136 };
137
138 // creates per-directory config structure
139 extern "C" void* create_shib_dir_config (SH_AP_POOL* p, char* d)
140 {
141     shib_dir_config* dc=(shib_dir_config*)ap_pcalloc(p,sizeof(shib_dir_config));
142     dc->bOff = -1;
143     dc->bBasicHijack = -1;
144     dc->bRequireSession = -1;
145     dc->bExportAssertion = -1;
146     dc->bRequireAll = -1;
147     dc->szRedirectToSSL = NULL;
148     dc->szAuthGrpFile = NULL;
149     dc->szApplicationId = NULL;
150     dc->szRequireWith = NULL;
151     return dc;
152 }
153
154 // overrides server configuration in directories
155 extern "C" void* merge_shib_dir_config (SH_AP_POOL* p, void* base, void* sub)
156 {
157     shib_dir_config* dc=(shib_dir_config*)ap_pcalloc(p,sizeof(shib_dir_config));
158     shib_dir_config* parent=(shib_dir_config*)base;
159     shib_dir_config* child=(shib_dir_config*)sub;
160
161     if (child->szAuthGrpFile)
162         dc->szAuthGrpFile=ap_pstrdup(p,child->szAuthGrpFile);
163     else if (parent->szAuthGrpFile)
164         dc->szAuthGrpFile=ap_pstrdup(p,parent->szAuthGrpFile);
165     else
166         dc->szAuthGrpFile=NULL;
167
168     if (child->szApplicationId)
169         dc->szApplicationId=ap_pstrdup(p,child->szApplicationId);
170     else if (parent->szApplicationId)
171         dc->szApplicationId=ap_pstrdup(p,parent->szApplicationId);
172     else
173         dc->szApplicationId=NULL;
174
175     if (child->szRequireWith)
176         dc->szRequireWith=ap_pstrdup(p,child->szRequireWith);
177     else if (parent->szRequireWith)
178         dc->szRequireWith=ap_pstrdup(p,parent->szRequireWith);
179     else
180         dc->szRequireWith=NULL;
181
182     if (child->szRedirectToSSL)
183         dc->szRedirectToSSL=ap_pstrdup(p,child->szRedirectToSSL);
184     else if (parent->szRedirectToSSL)
185         dc->szRedirectToSSL=ap_pstrdup(p,parent->szRedirectToSSL);
186     else
187         dc->szRedirectToSSL=NULL;
188
189     dc->bOff=((child->bOff==-1) ? parent->bOff : child->bOff);
190     dc->bBasicHijack=((child->bBasicHijack==-1) ? parent->bBasicHijack : child->bBasicHijack);
191     dc->bRequireSession=((child->bRequireSession==-1) ? parent->bRequireSession : child->bRequireSession);
192     dc->bExportAssertion=((child->bExportAssertion==-1) ? parent->bExportAssertion : child->bExportAssertion);
193     dc->bRequireAll=((child->bRequireAll==-1) ? parent->bRequireAll : child->bRequireAll);
194     return dc;
195 }
196
197 // generic global slot handlers
198 extern "C" const char* ap_set_global_string_slot(cmd_parms* parms, void*, const char* arg)
199 {
200     *((char**)(parms->info))=ap_pstrdup(parms->pool,arg);
201     return NULL;
202 }
203
204 extern "C" const char* shib_set_server_string_slot(cmd_parms* parms, void*, const char* arg)
205 {
206     char* base=(char*)ap_get_module_config(parms->server->module_config,&mod_shib);
207     size_t offset=(size_t)parms->info;
208     *((char**)(base + offset))=ap_pstrdup(parms->pool,arg);
209     return NULL;
210 }
211
212 extern "C" const char* shib_ap_set_file_slot(cmd_parms* parms,
213 #ifdef SHIB_APACHE_13
214                                              char* arg1, char* arg2
215 #else
216                                              void* arg1, const char* arg2
217 #endif
218                                              )
219 {
220   ap_set_file_slot(parms, arg1, arg2);
221   return DECLINE_CMD;
222 }
223
224 /********************************************************************************/
225 // Apache ShibTarget subclass(es) here.
226
227 class ShibTargetApache : public ShibTarget
228 {
229   mutable string m_body;
230   mutable bool m_gotBody;
231
232 public:
233   request_rec* m_req;
234   shib_dir_config* m_dc;
235   shib_server_config* m_sc;
236
237   ShibTargetApache(request_rec* req) : m_gotBody(false) {
238     m_sc = (shib_server_config*)ap_get_module_config(req->server->module_config, &mod_shib);
239     m_dc = (shib_dir_config*)ap_get_module_config(req->per_dir_config, &mod_shib);
240
241     init(
242         m_sc->szScheme ? m_sc->szScheme : ap_http_method(req),
243             ap_get_server_name(req),
244         (int)ap_get_server_port(req),
245             req->unparsed_uri,
246         ap_table_get(req->headers_in, "Content-type"),
247             req->connection->remote_ip,
248         req->method
249         );
250
251     m_req = req;
252   }
253   virtual ~ShibTargetApache() {}
254
255   virtual void log(ShibLogLevel level, const string &msg) {
256     ShibTarget::log(level,msg);
257 #ifdef SHIB_APACHE_13
258     ap_log_rerror(APLOG_MARK,
259         (level == LogLevelDebug ? APLOG_DEBUG :
260             (level == LogLevelInfo ? APLOG_INFO :
261             (level == LogLevelWarn ? APLOG_WARNING : APLOG_ERR)))|APLOG_NOERRNO, SH_AP_R(m_req), msg.c_str());
262 #else
263     if (level == LogLevelError)
264         ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(m_req), msg.c_str());
265 #endif
266   }
267   virtual string getCookies(void) const {
268     const char *c = ap_table_get(m_req->headers_in, "Cookie");
269     return string(c ? c : "");
270   }
271   virtual void setCookie(const string &name, const string &value) {
272     char* val = ap_psprintf(m_req->pool, "%s=%s", name.c_str(), value.c_str());
273     ap_table_addn(m_req->err_headers_out, "Set-Cookie", val);
274   }
275   virtual const char* getQueryString() const { return m_req->args; }
276   virtual const char* getRequestBody() const {
277     if (m_gotBody)
278         return m_body.c_str();
279     // Read the posted data
280     if (ap_setup_client_block(m_req, REQUEST_CHUNKED_ERROR))
281         throw saml::SAMLException("Apache function (setup_client_block) failed while reading POST request body.");
282     if (!ap_should_client_block(m_req))
283         throw saml::SAMLException("Apache function (should_client_block) failed while reading POST request body.");
284     if (m_req->remaining > 1024*1024)
285         throw saml::SAMLException("Blocked POST request body larger than size limit.");
286     m_gotBody=true;
287     char buff[HUGE_STRING_LEN];
288     ap_hard_timeout("[mod_shib] getRequestBody", m_req);
289     memset(buff, 0, sizeof(buff));
290     while (ap_get_client_block(m_req, buff, sizeof(buff)-1) > 0) {
291       ap_reset_timeout(m_req);
292       m_body += buff;
293       memset(buff, 0, sizeof(buff));
294     }
295     ap_kill_timeout(m_req);
296     return m_body.c_str();
297   }
298   virtual void clearHeader(const string &name) {
299     ap_table_unset(m_req->headers_in, name.c_str());
300     ap_table_set(m_req->headers_in, name.c_str(), g_unsetHeaderValue.c_str());
301   }
302   virtual void setHeader(const string &name, const string &value) {
303     ap_table_set(m_req->headers_in, name.c_str(), value.c_str());
304   }
305   virtual string getHeader(const string &name) {
306     const char *hdr = ap_table_get(m_req->headers_in, name.c_str());
307     return string(hdr ? hdr : "");
308   }
309   virtual void setRemoteUser(const string &user) {
310     SH_AP_USER(m_req) = ap_pstrdup(m_req->pool, user.c_str());
311   }
312   virtual string getRemoteUser(void) {
313     return string(SH_AP_USER(m_req) ? SH_AP_USER(m_req) : "");
314   }
315   virtual void* sendPage(
316     const string& msg,
317     int code=200,
318     const string& content_type="text/html",
319     const saml::Iterator<header_t>& headers=EMPTY(header_t)
320     ) {
321     m_req->content_type = ap_psprintf(m_req->pool, content_type.c_str());
322     while (headers.hasNext()) {
323         const header_t& h=headers.next();
324         ap_table_set(m_req->headers_out, h.first.c_str(), h.second.c_str());
325     }
326     ap_send_http_header(m_req);
327     ap_rprintf(m_req, msg.c_str());
328     return (void*)((code==200) ? DONE : code);
329   }
330   virtual void* sendRedirect(const string& url) {
331     ap_table_set(m_req->headers_out, "Location", url.c_str());
332     return (void*)REDIRECT;
333   }
334   virtual void* returnDecline(void) { return (void*)DECLINED; }
335   virtual void* returnOK(void) { return (void*)OK; }
336 };
337
338 /********************************************************************************/
339 // Apache handlers
340
341 extern "C" int shib_check_user(request_rec* r)
342 {
343   // Short-circuit entirely?
344   if (((shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib))->bOff==1)
345     return DECLINED;
346     
347   ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_check_user(%d): ENTER\n", (int)getpid());
348
349   ostringstream threadid;
350   threadid << "[" << getpid() << "] shib_check_user" << '\0';
351   saml::NDC ndc(threadid.str().c_str());
352
353   try {
354     ShibTargetApache sta(r);
355
356     // Check user authentication and export information, then set the handler bypass
357     pair<bool,void*> res = sta.doCheckAuthN(true);
358     apr_pool_userdata_setn((const void*)42,g_UserDataKey,NULL,r->pool);
359     if (res.first) return (int)res.second;
360
361     // user auth was okay -- export the assertions now
362     res = sta.doExportAssertions();
363     if (res.first) return (int)res.second;
364
365     // export happened successfully..  this user is ok.
366     return OK;
367   }
368   catch (saml::SAMLException& e) {
369     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an exception: %s", e.what());
370     return SERVER_ERROR;
371   }
372 #ifndef _DEBUG
373   catch (...) {
374     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an uncaught exception!");
375     return SERVER_ERROR;
376   }
377 #endif
378 }
379
380 extern "C" int shib_handler(request_rec* r)
381 {
382   // Short-circuit entirely?
383   if (((shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib))->bOff==1)
384     return DECLINED;
385
386   ostringstream threadid;
387   threadid << "[" << getpid() << "] shib_handler" << '\0';
388   saml::NDC ndc(threadid.str().c_str());
389
390 #ifndef SHIB_APACHE_13
391   // With 2.x, this handler always runs, though last.
392   // We check if shib_check_user ran, because it will detect a handler request
393   // and dispatch it directly.
394   void* data;
395   apr_pool_userdata_get(&data,g_UserDataKey,r->pool);
396   if (data==(const void*)42) {
397     ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_handler skipped since check_user ran");
398     return DECLINED;
399   }
400 #endif
401
402   ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_handler(%d): ENTER: %s", (int)getpid(), r->handler);
403
404   try {
405     ShibTargetApache sta(r);
406
407     pair<bool,void*> res = sta.doHandler();
408     if (res.first) return (int)res.second;
409
410     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "doHandler() did not do anything.");
411     return SERVER_ERROR;
412   }
413   catch (saml::SAMLException& e) {
414     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an exception: %s", e.what());
415     return SERVER_ERROR;
416   }
417 #ifndef _DEBUG
418   catch (...) {
419     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an uncaught exception!");
420     return SERVER_ERROR;
421   }
422 #endif
423 }
424
425 /*
426  * shib_auth_checker() -- a simple resource manager to
427  * process the .htaccess settings
428  */
429 extern "C" int shib_auth_checker(request_rec* r)
430 {
431   // Short-circuit entirely?
432   if (((shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib))->bOff==1)
433     return DECLINED;
434
435   ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_auth_checker(%d): ENTER", (int)getpid());
436
437   ostringstream threadid;
438   threadid << "[" << getpid() << "] shib_auth_checker" << '\0';
439   saml::NDC ndc(threadid.str().c_str());
440
441   try {
442     ShibTargetApache sta(r);
443
444     pair<bool,void*> res = sta.doCheckAuthZ();
445     if (res.first) return (int)res.second;
446
447     // We're all okay.
448     return OK;
449   }
450   catch (saml::SAMLException& e) {
451     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an exception: %s", e.what());
452     return SERVER_ERROR;
453   }
454 #ifndef _DEBUG
455   catch (...) {
456     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an uncaught exception!");
457     return SERVER_ERROR;
458   }
459 #endif
460 }
461
462 // Access control plugin that enforces htaccess rules
463 class htAccessControl : virtual public IAccessControl
464 {
465 public:
466     htAccessControl() {}
467     ~htAccessControl() {}
468     void lock() {}
469     void unlock() {}
470     bool authorized(
471         ShibTarget* st,
472         ISessionCacheEntry* entry
473     ) const;
474 };
475
476 saml::IPlugIn* htAccessFactory(const DOMElement* e)
477 {
478     return new htAccessControl();
479 }
480
481 class ApacheRequestMapper : public virtual IRequestMapper, public virtual PropertySet
482 {
483 public:
484     ApacheRequestMapper(const DOMElement* e);
485     ~ApacheRequestMapper() { delete m_mapper; delete m_htaccess; delete m_staKey; delete m_propsKey; }
486     void lock() { m_mapper->lock(); }
487     void unlock() { m_staKey->setData(NULL); m_propsKey->setData(NULL); m_mapper->unlock(); }
488     Settings getSettings(ShibTarget* st) const;
489     
490     pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
491     pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
492     pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
493     pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
494     pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
495     const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
496     const DOMElement* getElement() const;
497
498 private:
499     IRequestMapper* m_mapper;
500     ThreadKey* m_staKey;
501     ThreadKey* m_propsKey;
502     IAccessControl* m_htaccess;
503 };
504
505 saml::IPlugIn* ApacheRequestMapFactory(const DOMElement* e)
506 {
507     return new ApacheRequestMapper(e);
508 }
509
510 ApacheRequestMapper::ApacheRequestMapper(const DOMElement* e) : m_mapper(NULL), m_staKey(NULL), m_propsKey(NULL), m_htaccess(NULL)
511 {
512     saml::IPlugIn* p=saml::SAMLConfig::getConfig().getPlugMgr().newPlugin(shibtarget::XML::XMLRequestMapType,e);
513     m_mapper=dynamic_cast<IRequestMapper*>(p);
514     if (!m_mapper) {
515         delete p;
516         throw saml::UnsupportedExtensionException("Embedded request mapper plugin was not of correct type.");
517     }
518     m_htaccess=new htAccessControl();
519     m_staKey=ThreadKey::create(NULL);
520     m_propsKey=ThreadKey::create(NULL);
521 }
522
523 IRequestMapper::Settings ApacheRequestMapper::getSettings(ShibTarget* st) const
524 {
525     Settings s=m_mapper->getSettings(st);
526     m_staKey->setData(dynamic_cast<ShibTargetApache*>(st));
527     m_propsKey->setData((void*)s.first);
528     return pair<const PropertySet*,IAccessControl*>(this,s.second ? s.second : m_htaccess);
529 }
530
531 pair<bool,bool> ApacheRequestMapper::getBool(const char* name, const char* ns) const
532 {
533     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
534     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
535     if (sta && !ns) {
536         // Override Apache-settable boolean properties.
537         if (name && !strcmp(name,"requireSession") && sta->m_dc->bRequireSession==1)
538             return make_pair(true,true);
539         else if (name && !strcmp(name,"exportAssertion") && sta->m_dc->bExportAssertion==1)
540             return make_pair(true,true);
541     }
542     return s ? s->getBool(name,ns) : make_pair(false,false);
543 }
544
545 pair<bool,const char*> ApacheRequestMapper::getString(const char* name, const char* ns) const
546 {
547     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
548     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
549     if (sta && !ns) {
550         // Override Apache-settable string properties.
551         if (name && !strcmp(name,"authType")) {
552             const char *auth_type=ap_auth_type(sta->m_req);
553             if (auth_type) {
554                 // Check for Basic Hijack
555                 if (!strcasecmp(auth_type, "basic") && sta->m_dc->bBasicHijack == 1)
556                     auth_type = "shibboleth";
557                 return make_pair(true,auth_type);
558             }
559         }
560         else if (name && !strcmp(name,"applicationId") && sta->m_dc->szApplicationId)
561             return pair<bool,const char*>(true,sta->m_dc->szApplicationId);
562         else if (name && !strcmp(name,"requireSessionWith") && sta->m_dc->szRequireWith)
563             return pair<bool,const char*>(true,sta->m_dc->szRequireWith);
564         else if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
565             return pair<bool,const char*>(true,sta->m_dc->szRedirectToSSL);
566     }
567     return s ? s->getString(name,ns) : pair<bool,const char*>(false,NULL);
568 }
569
570 pair<bool,const XMLCh*> ApacheRequestMapper::getXMLString(const char* name, const char* ns) const
571 {
572     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
573     return s ? s->getXMLString(name,ns) : pair<bool,const XMLCh*>(false,NULL);
574 }
575
576 pair<bool,unsigned int> ApacheRequestMapper::getUnsignedInt(const char* name, const char* ns) const
577 {
578     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
579     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
580     if (sta && !ns) {
581         // Override Apache-settable int properties.
582         if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
583             return pair<bool,unsigned int>(true,strtol(sta->m_dc->szRedirectToSSL,NULL,10));
584     }
585     return s ? s->getUnsignedInt(name,ns) : pair<bool,unsigned int>(false,0);
586 }
587
588 pair<bool,int> ApacheRequestMapper::getInt(const char* name, const char* ns) const
589 {
590     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
591     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
592     if (sta && !ns) {
593         // Override Apache-settable int properties.
594         if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
595             return pair<bool,int>(true,atoi(sta->m_dc->szRedirectToSSL));
596     }
597     return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
598 }
599
600 const PropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
601 {
602     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
603     return s ? s->getPropertySet(name,ns) : NULL;
604 }
605
606 const DOMElement* ApacheRequestMapper::getElement() const
607 {
608     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
609     return s ? s->getElement() : NULL;
610 }
611
612 static SH_AP_TABLE* groups_for_user(request_rec* r, const char* user, char* grpfile)
613 {
614     SH_AP_CONFIGFILE* f;
615     SH_AP_TABLE* grps=ap_make_table(r->pool,15);
616     char l[MAX_STRING_LEN];
617     const char *group_name, *ll, *w;
618
619 #ifdef SHIB_APACHE_13
620     if (!(f=ap_pcfg_openfile(r->pool,grpfile))) {
621 #else
622     if (ap_pcfg_openfile(&f,r->pool,grpfile) != APR_SUCCESS) {
623 #endif
624         ap_log_rerror(APLOG_MARK,APLOG_DEBUG,SH_AP_R(r),"groups_for_user() could not open group file: %s\n",grpfile);
625         return NULL;
626     }
627
628     SH_AP_POOL* sp;
629 #ifdef SHIB_APACHE_13
630     sp=ap_make_sub_pool(r->pool);
631 #else
632     if (apr_pool_create(&sp,r->pool) != APR_SUCCESS) {
633         ap_log_rerror(APLOG_MARK,APLOG_ERR,0,r,
634             "groups_for_user() could not create a subpool");
635         return NULL;
636     }
637 #endif
638
639     while (!(ap_cfg_getline(l,MAX_STRING_LEN,f))) {
640         if ((*l=='#') || (!*l))
641             continue;
642         ll = l;
643         ap_clear_pool(sp);
644
645         group_name=ap_getword(sp,&ll,':');
646
647         while (*ll) {
648             w=ap_getword_conf(sp,&ll);
649             if (!strcmp(w,user)) {
650                 ap_table_setn(grps,ap_pstrdup(r->pool,group_name),"in");
651                 break;
652             }
653         }
654     }
655     ap_cfg_closefile(f);
656     ap_destroy_pool(sp);
657     return grps;
658 }
659
660 bool htAccessControl::authorized(
661     ShibTarget* st,
662     ISessionCacheEntry* entry
663 ) const
664 {
665     // Make sure the object is our type.
666     ShibTargetApache* sta=dynamic_cast<ShibTargetApache*>(st);
667     if (!sta)
668         throw ConfigurationException("Request wrapper object was not of correct type.");
669
670     // mod_auth clone
671
672     int m=sta->m_req->method_number;
673     bool method_restricted=false;
674     const char *t, *w;
675     
676     const array_header* reqs_arr=ap_requires(sta->m_req);
677     if (!reqs_arr)
678         return true;
679
680     require_line* reqs=(require_line*)reqs_arr->elts;
681     
682     ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(sta->m_req),"REQUIRE nelts: %d", reqs_arr->nelts);
683     ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(sta->m_req),"REQUIRE all: %d", sta->m_dc->bRequireAll);
684
685     vector<bool> auth_OK(reqs_arr->nelts,false);
686
687 #define SHIB_AP_CHECK_IS_OK {           \
688      if (sta->m_dc->bRequireAll < 1)    \
689          return true;                   \
690      auth_OK[x] = true;                 \
691      continue;                          \
692 }
693
694     for (int x=0; x<reqs_arr->nelts; x++) {
695         auth_OK[x] = false;
696         if (!(reqs[x].method_mask & (1 << m)))
697             continue;
698         method_restricted=true;
699         string remote_user = st->getRemoteUser();
700
701         t = reqs[x].requirement;
702         w = ap_getword_white(sta->m_req->pool, &t);
703
704         if (!strcasecmp(w,"shibboleth")) {
705             // This is a dummy rule needed because Apache conflates authn and authz.
706             // Without some require rule, AuthType is ignored and no check_user hooks run.
707             SHIB_AP_CHECK_IS_OK;
708         }
709         else if (!strcmp(w,"valid-user")) {
710             if (entry) {
711                 st->log(ShibTarget::LogLevelDebug,"htAccessControl plugin accepting valid-user based on active session");
712                 SHIB_AP_CHECK_IS_OK;
713             }
714             else
715                 st->log(ShibTarget::LogLevelError,"htAccessControl plugin rejecting access for valid-user rule, no session is active");
716         }
717         else if (!strcmp(w,"user") && !remote_user.empty()) {
718             bool regexp=false;
719             while (*t) {
720                 w=ap_getword_conf(sta->m_req->pool,&t);
721                 if (*w=='~') {
722                     regexp=true;
723                     continue;
724                 }
725                 
726                 if (regexp) {
727                     try {
728                         // To do regex matching, we have to convert from UTF-8.
729                         auto_ptr<XMLCh> trans(fromUTF8(w));
730                         RegularExpression re(trans.get());
731                         auto_ptr<XMLCh> trans2(fromUTF8(remote_user.c_str()));
732                         if (re.matches(trans2.get())) {
733                             st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin accepting user (") + w + ")");
734                             SHIB_AP_CHECK_IS_OK;
735                         }
736                     }
737                     catch (XMLException& ex) {
738                         auto_ptr_char tmp(ex.getMessage());
739                         st->log(ShibTarget::LogLevelError,
740                             string("htAccessControl plugin caught exception while parsing regular expression (") + w + "): " + tmp.get());
741                     }
742                 }
743                 else if (remote_user==w) {
744                     st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin accepting user (") + w + ")");
745                     SHIB_AP_CHECK_IS_OK;
746                 }
747             }
748         }
749         else if (!strcmp(w,"group")) {
750             SH_AP_TABLE* grpstatus=NULL;
751             if (sta->m_dc->szAuthGrpFile && !remote_user.empty()) {
752                 st->log(ShibTarget::LogLevelDebug,string("htAccessControl plugin using groups file: ") + sta->m_dc->szAuthGrpFile);
753                 grpstatus=groups_for_user(sta->m_req,remote_user.c_str(),sta->m_dc->szAuthGrpFile);
754             }
755             if (!grpstatus)
756                 return false;
757     
758             while (*t) {
759                 w=ap_getword_conf(sta->m_req->pool,&t);
760                 if (ap_table_get(grpstatus,w)) {
761                     st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin accepting group (") + w + ")");
762                     SHIB_AP_CHECK_IS_OK;
763                 }
764             }
765         }
766         else {
767             saml::Iterator<shibboleth::IAAP*> provs=st->getApplication()->getAAPProviders();
768             shibboleth::AAP wrapper(provs,w);
769             if (wrapper.fail()) {
770                 st->log(ShibTarget::LogLevelWarn, string("htAccessControl plugin didn't recognize require rule: ") + w);
771                 continue;
772             }
773
774             bool regexp=false;
775             const char* vals;
776             if (!strcmp(wrapper->getHeader(),"REMOTE_USER"))
777                 vals=remote_user.c_str();
778             else
779                 vals=ap_table_get(sta->m_req->headers_in,wrapper->getHeader());
780             while (*t && vals && *vals) {
781                 w=ap_getword_conf(sta->m_req->pool,&t);
782                 if (*w=='~') {
783                     regexp=true;
784                     continue;
785                 }
786
787                 try {
788                     auto_ptr<RegularExpression> re;
789                     if (regexp) {
790                         delete re.release();
791                         auto_ptr<XMLCh> trans(fromUTF8(w));
792                         auto_ptr<RegularExpression> temp(new RegularExpression(trans.get()));
793                         re=temp;
794                     }
795                     
796                     string vals_str(vals);
797                     int j = 0;
798                     for (unsigned int i = 0;  i < vals_str.length();  i++) {
799                         if (vals_str.at(i) == ';') {
800                             if (i == 0) {
801                                 st->log(ShibTarget::LogLevelError, string("htAccessControl plugin found invalid header encoding (") +
802                                     vals + "): starts with a semicolon");
803                                 throw saml::SAMLException("Invalid information supplied to authorization plugin.");
804                             }
805
806                             if (vals_str.at(i-1) == '\\') {
807                                 vals_str.erase(i-1, 1);
808                                 i--;
809                                 continue;
810                             }
811
812                             string val = vals_str.substr(j, i-j);
813                             j = i+1;
814                             if (regexp) {
815                                 auto_ptr<XMLCh> trans(fromUTF8(val.c_str()));
816                                 if (re->matches(trans.get())) {
817                                     st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin expecting ") + w +
818                                        ", got " + val + ": authorization granted");
819                                     SHIB_AP_CHECK_IS_OK;
820                                 }
821                             }
822                             else if ((wrapper->getCaseSensitive() && val==w) || (!wrapper->getCaseSensitive() && !strcasecmp(val.c_str(),w))) {
823                                 st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin expecting ") + w +
824                                     ", got " + val + ": authorization granted.");
825                                 SHIB_AP_CHECK_IS_OK;
826                             }
827                             else {
828                                 st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin expecting ") + w +
829                                     ", got " + val + ": authoritzation not granted.");
830                             }
831                         }
832                     }
833     
834                     string val = vals_str.substr(j, vals_str.length()-j);
835                     if (regexp) {
836                         auto_ptr<XMLCh> trans(fromUTF8(val.c_str()));
837                         if (re->matches(trans.get())) {
838                             st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin expecting ") + w +
839                                 ", got " + val + ": authorization granted.");
840                             SHIB_AP_CHECK_IS_OK;
841                         }
842                     }
843                     else if ((wrapper->getCaseSensitive() && val==w) || (!wrapper->getCaseSensitive() && !strcasecmp(val.c_str(),w))) {
844                         st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin expecting ") + w +
845                             ", got " + val + ": authorization granted");
846                         SHIB_AP_CHECK_IS_OK;
847                     }
848                     else {
849                             st->log(ShibTarget::LogLevelDebug, string("htAccessControl plugin expecting ") + w +
850                                 ", got " + val + ": authorization not granted");
851                     }
852                 }
853                 catch (XMLException& ex) {
854                     auto_ptr_char tmp(ex.getMessage());
855                     st->log(ShibTarget::LogLevelError, string("htAccessControl plugin caught exception while parsing regular expression (")
856                         + w + "): " + tmp.get());
857                 }
858             }
859         }
860     }
861
862     // check if all require directives are true
863     bool auth_all_OK = true;
864     for (int i= 0; i<reqs_arr->nelts; i++) {
865         auth_all_OK &= auth_OK[i];
866     }
867     if (auth_all_OK || !method_restricted)
868         return true;
869
870     return false;
871 }
872
873 #ifndef SHIB_APACHE_13
874 /*
875  * shib_exit()
876  *  Empty cleanup hook, Apache 2.x doesn't check NULL very well...
877  */
878 extern "C" apr_status_t shib_exit(void* data)
879 {
880     if (g_Config) {
881         g_Config->shutdown();
882         g_Config = NULL;
883     }
884     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,0,NULL,"shib_exit() done\n");
885     return OK;
886 }
887 #endif
888
889
890 /*
891  * shib_child_exit()
892  *  Cleanup the (per-process) pool info.
893  */
894 #ifdef SHIB_APACHE_13
895 extern "C" void shib_child_exit(server_rec* s, SH_AP_POOL* p)
896 {
897 #else
898 extern "C" apr_status_t shib_child_exit(void* data)
899 {
900   server_rec* s = NULL;
901 #endif
902
903     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit(%d) dealing with g_Config..", (int)getpid());
904     g_Config->shutdown();
905     g_Config = NULL;
906     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit() done\n");
907
908 #ifndef SHIB_APACHE_13
909     return OK;
910 #endif
911 }
912
913 /* 
914  * shire_child_init()
915  *  Things to do when the child process is initialized.
916  *  (or after the configs are read in apache-2)
917  */
918 #ifdef SHIB_APACHE_13
919 extern "C" void shib_child_init(server_rec* s, SH_AP_POOL* p)
920 #else
921 extern "C" void shib_child_init(apr_pool_t* p, server_rec* s)
922 #endif
923 {
924     // Initialize runtime components.
925
926     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init(%d) starting", (int)getpid());
927
928     if (g_Config) {
929         ap_log_error(APLOG_MARK,APLOG_ERR|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() already initialized!");
930         exit(1);
931     }
932
933     try {
934         g_Config=&ShibTargetConfig::getConfig();
935         SPConfig::getConfig().setFeatures(
936             SPConfig::Caching |
937             SPConfig::Listener |
938             SPConfig::Metadata |
939             SPConfig::AAP |
940             SPConfig::RequestMapper |
941             SPConfig::InProcess |
942             SPConfig::Logging
943             );
944         if (!g_Config->init(g_szSchemaDir)) {
945             ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries");
946             exit(1);
947         }
948         saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::htAccessControlType,&htAccessFactory);
949         saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&ApacheRequestMapFactory);
950         // We hijack the legacy type so that 1.2 config files will load this plugin
951         saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&ApacheRequestMapFactory);
952         
953         if (!g_Config->load(g_szSHIBConfig)) {
954             ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to load configuration");
955             exit(1);
956         }
957
958         IConfig* conf=g_Config->getINI();
959         saml::Locker locker(conf);
960         const PropertySet* props=conf->getPropertySet("Local");
961         if (props) {
962             pair<bool,const char*> unsetValue=props->getString("unsetHeaderValue");
963             if (unsetValue.first)
964                 g_unsetHeaderValue = unsetValue.second;
965         }
966     }
967     catch (...) {
968         ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize system");
969         exit(1);
970     }
971
972     // Set the cleanup handler
973     apr_pool_cleanup_register(p, NULL, &shib_exit, &shib_child_exit);
974
975     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() done");
976 }
977
978 typedef const char* (*config_fn_t)(void);
979
980 #ifdef SHIB_APACHE_13
981
982 // SHIB Module commands
983
984 static command_rec shire_cmds[] = {
985   {"ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
986    RSRC_CONF, TAKE1, "Path to shibboleth.xml config file"},
987   {"ShibSchemaDir", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
988    RSRC_CONF, TAKE1, "Path to Shibboleth XML schema directory"},
989
990   {"ShibURLScheme", (config_fn_t)shib_set_server_string_slot,
991    (void *) XtOffsetOf (shib_server_config, szScheme),
992    RSRC_CONF, TAKE1, "URL scheme to force into generated URLs for a vhost"},
993    
994   {"ShibDisable", (config_fn_t)ap_set_flag_slot,
995    (void *) XtOffsetOf (shib_dir_config, bOff),
996    OR_AUTHCFG, FLAG, "Disable all Shib module activity here to save processing effort"},
997   {"ShibApplicationId", (config_fn_t)ap_set_string_slot,
998    (void *) XtOffsetOf (shib_dir_config, szApplicationId),
999    OR_AUTHCFG, TAKE1, "Set Shibboleth applicationId property for content"},
1000   {"ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
1001    (void *) XtOffsetOf (shib_dir_config, bBasicHijack),
1002    OR_AUTHCFG, FLAG, "Respond to AuthType Basic and convert to shibboleth"},
1003   {"ShibRequireSession", (config_fn_t)ap_set_flag_slot,
1004    (void *) XtOffsetOf (shib_dir_config, bRequireSession),
1005    OR_AUTHCFG, FLAG, "Initiates a new session if one does not exist"},
1006   {"ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
1007    (void *) XtOffsetOf (shib_dir_config, szRequireWith),
1008    OR_AUTHCFG, TAKE1, "Initiates a new session if one does not exist using a specific SessionInitiator"},
1009   {"ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
1010    (void *) XtOffsetOf (shib_dir_config, bExportAssertion),
1011    OR_AUTHCFG, FLAG, "Export SAML attribute assertion(s) to Shib-Attributes header"},
1012   {"ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
1013    (void *) XtOffsetOf (shib_dir_config, szRedirectToSSL),
1014    OR_AUTHCFG, TAKE1, "Redirect non-SSL requests to designated port" },
1015   {"AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
1016    (void *) XtOffsetOf (shib_dir_config, szAuthGrpFile),
1017    OR_AUTHCFG, TAKE1, "text file containing group names and member user IDs"},
1018   {"ShibRequireAll", (config_fn_t)ap_set_flag_slot,
1019    (void *) XtOffsetOf (shib_dir_config, bRequireAll),
1020    OR_AUTHCFG, FLAG, "All require directives must match"},
1021
1022   {NULL}
1023 };
1024
1025 extern "C"{
1026 handler_rec shib_handlers[] = {
1027   { "shib-handler", shib_handler },
1028   { NULL }
1029 };
1030
1031 module MODULE_VAR_EXPORT mod_shib = {
1032     STANDARD_MODULE_STUFF,
1033     NULL,                        /* initializer */
1034     create_shib_dir_config,     /* dir config creater */
1035     merge_shib_dir_config,      /* dir merger --- default is to override */
1036     create_shib_server_config, /* server config */
1037     merge_shib_server_config,   /* merge server config */
1038     shire_cmds,                 /* command table */
1039     shib_handlers,              /* handlers */
1040     NULL,                       /* filename translation */
1041     shib_check_user,            /* check_user_id */
1042     shib_auth_checker,          /* check auth */
1043     NULL,                       /* check access */
1044     NULL,                       /* type_checker */
1045     NULL,                       /* fixups */
1046     NULL,                       /* logger */
1047     NULL,                       /* header parser */
1048     shib_child_init,            /* child_init */
1049     shib_child_exit,            /* child_exit */
1050     NULL                        /* post read-request */
1051 };
1052
1053 #elif defined(SHIB_APACHE_20) || defined(SHIB_APACHE_22)
1054
1055 extern "C" void shib_register_hooks (apr_pool_t *p)
1056 {
1057   ap_hook_child_init(shib_child_init, NULL, NULL, APR_HOOK_MIDDLE);
1058   ap_hook_check_user_id(shib_check_user, NULL, NULL, APR_HOOK_MIDDLE);
1059   ap_hook_auth_checker(shib_auth_checker, NULL, NULL, APR_HOOK_FIRST);
1060   ap_hook_handler(shib_handler, NULL, NULL, APR_HOOK_LAST);
1061 }
1062
1063 // SHIB Module commands
1064
1065 extern "C" {
1066 static command_rec shib_cmds[] = {
1067   AP_INIT_TAKE1("ShibConfig",
1068                 (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
1069                 RSRC_CONF, "Path to shibboleth.xml config file"),
1070   AP_INIT_TAKE1("ShibSchemaDir",
1071      (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
1072       RSRC_CONF, "Path to Shibboleth XML schema directory"),
1073
1074   AP_INIT_TAKE1("ShibURLScheme",
1075      (config_fn_t)shib_set_server_string_slot,
1076      (void *) offsetof (shib_server_config, szScheme),
1077       RSRC_CONF, "URL scheme to force into generated URLs for a vhost"),
1078
1079   AP_INIT_FLAG("ShibDisable", (config_fn_t)ap_set_flag_slot,
1080         (void *) offsetof (shib_dir_config, bOff),
1081         OR_AUTHCFG, "Disable all Shib module activity here to save processing effort"),
1082   AP_INIT_TAKE1("ShibApplicationId", (config_fn_t)ap_set_string_slot,
1083         (void *) offsetof (shib_dir_config, szApplicationId),
1084         OR_AUTHCFG, "Set Shibboleth applicationId property for content"),
1085   AP_INIT_FLAG("ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
1086         (void *) offsetof (shib_dir_config, bBasicHijack),
1087         OR_AUTHCFG, "Respond to AuthType Basic and convert to shibboleth"),
1088   AP_INIT_FLAG("ShibRequireSession", (config_fn_t)ap_set_flag_slot,
1089         (void *) offsetof (shib_dir_config, bRequireSession),
1090         OR_AUTHCFG, "Initiates a new session if one does not exist"),
1091   AP_INIT_TAKE1("ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
1092         (void *) offsetof (shib_dir_config, szRequireWith),
1093         OR_AUTHCFG, "Initiates a new session if one does not exist using a specific SessionInitiator"),
1094   AP_INIT_FLAG("ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
1095         (void *) offsetof (shib_dir_config, bExportAssertion),
1096         OR_AUTHCFG, "Export SAML attribute assertion(s) to Shib-Attributes header"),
1097   AP_INIT_TAKE1("ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
1098         (void *) offsetof (shib_dir_config, szRedirectToSSL),
1099         OR_AUTHCFG, "Redirect non-SSL requests to designated port"),
1100   AP_INIT_TAKE1("AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
1101                 (void *) offsetof (shib_dir_config, szAuthGrpFile),
1102                 OR_AUTHCFG, "Text file containing group names and member user IDs"),
1103   AP_INIT_FLAG("ShibRequireAll", (config_fn_t)ap_set_flag_slot,
1104         (void *) offsetof (shib_dir_config, bRequireAll),
1105         OR_AUTHCFG, "All require directives must match"),
1106
1107   {NULL}
1108 };
1109
1110 module AP_MODULE_DECLARE_DATA mod_shib = {
1111     STANDARD20_MODULE_STUFF,
1112     create_shib_dir_config,     /* create dir config */
1113     merge_shib_dir_config,      /* merge dir config --- default is to override */
1114     create_shib_server_config,  /* create server config */
1115     merge_shib_server_config,   /* merge server config */
1116     shib_cmds,                  /* command table */
1117     shib_register_hooks         /* register hooks */
1118 };
1119
1120 #else
1121 #error "undefined APACHE version"
1122 #endif
1123
1124 }