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