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