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