2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Apache module implementation
26 #undef _XOPEN_SOURCE // causes gethostname conflict in unistd.h
30 # define _CRT_NONSTDC_NO_DEPRECATE 1
31 # define _CRT_SECURE_NO_DEPRECATE 1
34 #include <shibsp/AbstractSPRequest.h>
35 #include <shibsp/AccessControl.h>
36 #include <shibsp/exceptions.h>
37 #include <shibsp/RequestMapper.h>
38 #include <shibsp/SPConfig.h>
39 #include <shibsp/ServiceProvider.h>
40 #include <shibsp/SessionCache.h>
41 #include <shibsp/attribute/Attribute.h>
42 #include <xercesc/util/XMLUniDefs.hpp>
43 #include <xercesc/util/regx/RegularExpression.hpp>
44 #include <xmltooling/XMLToolingConfig.h>
45 #include <xmltooling/util/NDC.h>
46 #include <xmltooling/util/Threads.h>
47 #include <xmltooling/util/XMLConstants.h>
48 #include <xmltooling/util/XMLHelper.h>
56 // Apache specific header files
58 #include <http_config.h>
59 #include <http_protocol.h>
60 #include <http_main.h>
62 #include <http_core.h>
64 #include <http_request.h>
66 #ifndef SHIB_APACHE_13
67 #include <apr_buckets.h>
68 #include <apr_strings.h>
69 #include <apr_pools.h>
76 #include <unistd.h> // for getpid()
79 using namespace shibsp;
80 using namespace xmltooling;
82 using xercesc::RegularExpression;
83 using xercesc::XMLException;
85 extern "C" module MODULE_VAR_EXPORT mod_shib;
88 char* g_szSHIBConfig = SHIBSP_CONFIG;
89 char* g_szSchemaDir = SHIBSP_SCHEMAS;
90 SPConfig* g_Config = NULL;
91 string g_unsetHeaderValue;
92 bool g_checkSpoofing = true;
93 static const char* g_UserDataKey = "_shib_check_user_";
94 static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
95 static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e);
98 /* Apache 2.2.x headers must be accumulated and set in the output filter.
99 Apache 2.0.49+ supports the filter method.
100 Apache 1.3.x and lesser 2.0.x must write the headers directly. */
102 #if (defined(SHIB_APACHE_20) || defined(SHIB_APACHE_22)) && AP_MODULE_MAGIC_AT_LEAST(20020903,6)
103 #define SHIB_DEFERRED_HEADERS
106 /********************************************************************************/
107 // Basic Apache Configuration code.
110 // per-server module configuration structure
111 struct shib_server_config
116 // creates the per-server configuration
117 extern "C" void* create_shib_server_config(SH_AP_POOL* p, server_rec* s)
119 shib_server_config* sc=(shib_server_config*)ap_pcalloc(p,sizeof(shib_server_config));
124 // overrides server configuration in virtual servers
125 extern "C" void* merge_shib_server_config (SH_AP_POOL* p, void* base, void* sub)
127 shib_server_config* sc=(shib_server_config*)ap_pcalloc(p,sizeof(shib_server_config));
128 shib_server_config* parent=(shib_server_config*)base;
129 shib_server_config* child=(shib_server_config*)sub;
132 sc->szScheme=ap_pstrdup(p,child->szScheme);
133 else if (parent->szScheme)
134 sc->szScheme=ap_pstrdup(p,parent->szScheme);
141 // per-dir module configuration structure
142 struct shib_dir_config
145 char* szAuthGrpFile; // Auth GroupFile name
146 int bRequireAll; // all require directives must match, otherwise OR logic
148 // Content Configuration
149 char* szApplicationId; // Shib applicationId value
150 char* szRequireWith; // require a session using a specific initiator?
151 char* szRedirectToSSL; // redirect non-SSL requests to SSL port
152 int bOff; // flat-out disable all Shib processing
153 int bBasicHijack; // activate for AuthType Basic?
154 int bRequireSession; // require a session?
155 int bExportAssertion; // export SAML assertion to the environment?
156 int bUseEnvVars; // use environment instead of headers?
159 // creates per-directory config structure
160 extern "C" void* create_shib_dir_config (SH_AP_POOL* p, char* d)
162 shib_dir_config* dc=(shib_dir_config*)ap_pcalloc(p,sizeof(shib_dir_config));
164 dc->bBasicHijack = -1;
165 dc->bRequireSession = -1;
166 dc->bExportAssertion = -1;
167 dc->bRequireAll = -1;
168 dc->szRedirectToSSL = NULL;
169 dc->szAuthGrpFile = NULL;
170 dc->szApplicationId = NULL;
171 dc->szRequireWith = NULL;
172 dc->bUseEnvVars = -1;
176 // overrides server configuration in directories
177 extern "C" void* merge_shib_dir_config (SH_AP_POOL* p, void* base, void* sub)
179 shib_dir_config* dc=(shib_dir_config*)ap_pcalloc(p,sizeof(shib_dir_config));
180 shib_dir_config* parent=(shib_dir_config*)base;
181 shib_dir_config* child=(shib_dir_config*)sub;
183 if (child->szAuthGrpFile)
184 dc->szAuthGrpFile=ap_pstrdup(p,child->szAuthGrpFile);
185 else if (parent->szAuthGrpFile)
186 dc->szAuthGrpFile=ap_pstrdup(p,parent->szAuthGrpFile);
188 dc->szAuthGrpFile=NULL;
190 if (child->szApplicationId)
191 dc->szApplicationId=ap_pstrdup(p,child->szApplicationId);
192 else if (parent->szApplicationId)
193 dc->szApplicationId=ap_pstrdup(p,parent->szApplicationId);
195 dc->szApplicationId=NULL;
197 if (child->szRequireWith)
198 dc->szRequireWith=ap_pstrdup(p,child->szRequireWith);
199 else if (parent->szRequireWith)
200 dc->szRequireWith=ap_pstrdup(p,parent->szRequireWith);
202 dc->szRequireWith=NULL;
204 if (child->szRedirectToSSL)
205 dc->szRedirectToSSL=ap_pstrdup(p,child->szRedirectToSSL);
206 else if (parent->szRedirectToSSL)
207 dc->szRedirectToSSL=ap_pstrdup(p,parent->szRedirectToSSL);
209 dc->szRedirectToSSL=NULL;
211 dc->bOff=((child->bOff==-1) ? parent->bOff : child->bOff);
212 dc->bBasicHijack=((child->bBasicHijack==-1) ? parent->bBasicHijack : child->bBasicHijack);
213 dc->bRequireSession=((child->bRequireSession==-1) ? parent->bRequireSession : child->bRequireSession);
214 dc->bExportAssertion=((child->bExportAssertion==-1) ? parent->bExportAssertion : child->bExportAssertion);
215 dc->bRequireAll=((child->bRequireAll==-1) ? parent->bRequireAll : child->bRequireAll);
216 dc->bUseEnvVars=((child->bUseEnvVars==-1) ? parent->bUseEnvVars : child->bUseEnvVars);
220 // per-request module structure
221 struct shib_request_config
223 SH_AP_TABLE *env; // environment vars
224 #ifdef SHIB_DEFERRED_HEADERS
225 SH_AP_TABLE *hdr_out; // headers to browser
226 SH_AP_TABLE *hdr_err; // err headers to browser
230 // create a request record
231 static shib_request_config *init_request_config(request_rec *r)
233 shib_request_config* rc=(shib_request_config*)ap_pcalloc(r->pool,sizeof(shib_request_config));
234 ap_set_module_config (r->request_config, &mod_shib, rc);
235 memset(rc, 0, sizeof(shib_request_config));
236 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_init_rc");
240 // generic global slot handlers
241 extern "C" const char* ap_set_global_string_slot(cmd_parms* parms, void*, const char* arg)
243 *((char**)(parms->info))=ap_pstrdup(parms->pool,arg);
247 extern "C" const char* shib_set_server_string_slot(cmd_parms* parms, void*, const char* arg)
249 char* base=(char*)ap_get_module_config(parms->server->module_config,&mod_shib);
250 size_t offset=(size_t)parms->info;
251 *((char**)(base + offset))=ap_pstrdup(parms->pool,arg);
255 extern "C" const char* shib_ap_set_file_slot(cmd_parms* parms,
256 #ifdef SHIB_APACHE_13
257 char* arg1, char* arg2
259 void* arg1, const char* arg2
263 ap_set_file_slot(parms, arg1, arg2);
267 /********************************************************************************/
268 // Apache ShibTarget subclass(es) here.
270 class ShibTargetApache : public AbstractSPRequest
272 mutable string m_body;
273 mutable bool m_gotBody;
274 mutable vector<string> m_certs;
275 set<string> m_allhttp;
279 shib_dir_config* m_dc;
280 shib_server_config* m_sc;
281 shib_request_config* m_rc;
283 ShibTargetApache(request_rec* req) : m_gotBody(false) {
284 m_sc = (shib_server_config*)ap_get_module_config(req->server->module_config, &mod_shib);
285 m_dc = (shib_dir_config*)ap_get_module_config(req->per_dir_config, &mod_shib);
286 m_rc = (shib_request_config*)ap_get_module_config(req->request_config, &mod_shib);
289 virtual ~ShibTargetApache() {}
291 const char* getScheme() const {
292 return m_sc->szScheme ? m_sc->szScheme : ap_http_method(m_req);
294 const char* getHostname() const {
295 return ap_get_server_name(m_req);
297 int getPort() const {
298 return ap_get_server_port(m_req);
300 const char* getRequestURI() const {
301 return m_req->unparsed_uri;
303 const char* getMethod() const {
304 return m_req->method;
306 string getContentType() const {
307 const char* type = ap_table_get(m_req->headers_in, "Content-Type");
308 return type ? type : "";
310 long getContentLength() const {
311 return m_gotBody ? m_body.length() : m_req->remaining;
313 string getRemoteAddr() const {
314 return m_req->connection->remote_ip;
316 void log(SPLogLevel level, const string& msg) const {
317 AbstractSPRequest::log(level,msg);
320 (level == SPDebug ? APLOG_DEBUG :
321 (level == SPInfo ? APLOG_INFO :
322 (level == SPWarn ? APLOG_WARNING :
323 (level == SPError ? APLOG_ERR : APLOG_CRIT))))|APLOG_NOERRNO,
328 const char* getQueryString() const { return m_req->args; }
329 const char* getRequestBody() const {
330 if (m_gotBody || m_req->method_number==M_GET)
331 return m_body.c_str();
332 #ifdef SHIB_APACHE_13
333 // Read the posted data
334 if (ap_setup_client_block(m_req, REQUEST_CHUNKED_DECHUNK) != OK) {
336 log(SPError, "Apache function (setup_client_block) failed while reading request body.");
337 return m_body.c_str();
339 if (!ap_should_client_block(m_req)) {
341 log(SPError, "Apache function (should_client_block) failed while reading request body.");
342 return m_body.c_str();
344 if (m_req->remaining > 1024*1024)
345 throw opensaml::SecurityPolicyException("Blocked request body larger than 1M size limit.");
348 char buff[HUGE_STRING_LEN];
349 ap_hard_timeout("[mod_shib] getRequestBody", m_req);
350 while ((len=ap_get_client_block(m_req, buff, sizeof(buff))) > 0) {
351 ap_reset_timeout(m_req);
352 m_body.append(buff, len);
354 ap_kill_timeout(m_req);
359 apr_bucket_brigade* bb = apr_brigade_create(m_req->pool, m_req->connection->bucket_alloc);
362 apr_status_t rv = ap_get_brigade(m_req->input_filters, bb, AP_MODE_READBYTES, APR_BLOCK_READ, HUGE_STRING_LEN);
363 if (rv != APR_SUCCESS) {
364 log(SPError, "Apache function (ap_get_brigade) failed while reading request body.");
368 for (bucket = APR_BRIGADE_FIRST(bb); bucket != APR_BRIGADE_SENTINEL(bb); bucket = APR_BUCKET_NEXT(bucket)) {
369 if (APR_BUCKET_IS_EOS(bucket)) {
374 /* We can't do much with this. */
375 if (APR_BUCKET_IS_FLUSH(bucket))
379 apr_bucket_read(bucket, &data, &len, APR_BLOCK_READ);
381 m_body.append(data, len);
383 apr_brigade_cleanup(bb);
385 apr_brigade_destroy(bb);
388 return m_body.c_str();
390 void clearHeader(const char* rawname, const char* cginame) {
391 if (m_dc->bUseEnvVars!=0) {
392 // ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(m_req), "shib_clear_header: env\n");
393 if (m_rc && m_rc->env) ap_table_unset(m_rc->env, rawname);
395 // ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(m_req), "shib_clear_header: hdr\n");
396 if (g_checkSpoofing && ap_is_initial_req(m_req)) {
397 if (m_allhttp.empty()) {
398 // First time, so populate set with "CGI" versions of client-supplied headers.
399 #ifdef SHIB_APACHE_13
400 array_header *hdrs_arr = ap_table_elts(m_req->headers_in);
401 table_entry *hdrs = (table_entry *) hdrs_arr->elts;
403 const apr_array_header_t *hdrs_arr = apr_table_elts(m_req->headers_in);
404 const apr_table_entry_t *hdrs = (const apr_table_entry_t *) hdrs_arr->elts;
406 for (int i = 0; i < hdrs_arr->nelts; ++i) {
409 string cgiversion("HTTP_");
410 const char* pch = hdrs[i].key;
412 cgiversion += (isalnum(*pch) ? toupper(*pch) : '_');
415 m_allhttp.insert(cgiversion);
419 if (m_allhttp.count(cginame) > 0)
420 throw opensaml::SecurityPolicyException("Attempt to spoof header ($1) was detected.", params(1, rawname));
422 ap_table_unset(m_req->headers_in, rawname);
423 ap_table_set(m_req->headers_in, rawname, g_unsetHeaderValue.c_str());
426 void setHeader(const char* name, const char* value) {
427 if (m_dc->bUseEnvVars!=0) {
429 // this happens on subrequests
430 // ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(m_req), "shib_setheader: no_m_rc\n");
431 m_rc = init_request_config(m_req);
433 if (!m_rc->env) m_rc->env = ap_make_table(m_req->pool, 10);
434 // ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(m_req), "shib_set_env: %s=%s\n", name, value?value:"Null");
435 ap_table_set(m_rc->env, name, value?value:"");
438 ap_table_set(m_req->headers_in, name, value);
441 string getHeader(const char* name) const {
442 const char* hdr = ap_table_get(m_req->headers_in, name);
443 return string(hdr ? hdr : "");
445 string getSecureHeader(const char* name) const {
446 if (m_dc->bUseEnvVars!=0) {
448 if (m_rc && m_rc->env)
449 hdr = ap_table_get(m_rc->env, name);
452 return string(hdr ? hdr : "");
454 return getHeader(name);
456 void setRemoteUser(const char* user) {
457 SH_AP_USER(m_req) = user ? ap_pstrdup(m_req->pool, user) : NULL;
459 string getRemoteUser() const {
460 return string(SH_AP_USER(m_req) ? SH_AP_USER(m_req) : "");
462 void setContentType(const char* type) {
463 m_req->content_type = ap_psprintf(m_req->pool, type);
465 void setResponseHeader(const char* name, const char* value) {
466 #ifdef SHIB_DEFERRED_HEADERS
468 // this happens on subrequests
469 m_rc = init_request_config(m_req);
470 ap_table_add(m_rc->hdr_err, name, value);
471 ap_table_add(m_rc->hdr_out, name, value);
473 ap_table_add(m_req->err_headers_out, name, value);
476 long sendResponse(istream& in, long status) {
477 ap_send_http_header(m_req);
481 ap_rwrite(buf,in.gcount(),m_req);
483 if (status!=XMLTOOLING_HTTP_STATUS_OK)
484 m_req->status = status;
487 long sendRedirect(const char* url) {
488 ap_table_set(m_req->headers_out, "Location", url);
491 const vector<string>& getClientCertificates() const {
492 if (m_certs.empty()) {
493 const char* cert = ap_table_get(m_req->subprocess_env, "SSL_CLIENT_CERT");
495 m_certs.push_back(cert);
498 cert = ap_table_get(m_req->subprocess_env, ap_psprintf(m_req->pool, "SSL_CLIENT_CERT_CHAIN_%d", i++));
500 m_certs.push_back(cert);
505 long returnDecline(void) { return DECLINED; }
506 long returnOK(void) { return OK; }
509 /********************************************************************************/
512 extern "C" int shib_check_user(request_rec* r)
514 // Short-circuit entirely?
515 if (((shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib))->bOff==1)
518 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_check_user(%d): ENTER\n", (int)getpid());
520 ostringstream threadid;
521 threadid << "[" << getpid() << "] shib_check_user" << '\0';
522 xmltooling::NDC ndc(threadid.str().c_str());
525 ShibTargetApache sta(r);
527 // Check user authentication and export information, then set the handler bypass
528 pair<bool,long> res = sta.getServiceProvider().doAuthentication(sta,true);
529 apr_pool_userdata_setn((const void*)42,g_UserDataKey,NULL,r->pool);
530 if (res.first) return res.second;
532 // user auth was okay -- export the assertions now
533 res = sta.getServiceProvider().doExport(sta);
534 if (res.first) return res.second;
536 // export happened successfully.. this user is ok.
539 catch (exception& e) {
540 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an exception: %s", e.what());
545 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an uncaught exception!");
551 extern "C" int shib_handler(request_rec* r)
553 // Short-circuit entirely?
554 if (((shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib))->bOff==1)
557 ostringstream threadid;
558 threadid << "[" << getpid() << "] shib_handler" << '\0';
559 xmltooling::NDC ndc(threadid.str().c_str());
561 #ifndef SHIB_APACHE_13
562 // With 2.x, this handler always runs, though last.
563 // We check if shib_check_user ran, because it will detect a handler request
564 // and dispatch it directly.
566 apr_pool_userdata_get(&data,g_UserDataKey,r->pool);
567 if (data==(const void*)42) {
568 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_handler skipped since check_user ran");
573 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_handler(%d): ENTER: %s", (int)getpid(), r->handler);
576 ShibTargetApache sta(r);
578 pair<bool,long> res = sta.getServiceProvider().doHandler(sta);
579 if (res.first) return res.second;
581 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "doHandler() did not do anything.");
584 catch (exception& e) {
585 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an exception: %s", e.what());
590 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an uncaught exception!");
597 * shib_auth_checker() -- a simple resource manager to
598 * process the .htaccess settings
600 extern "C" int shib_auth_checker(request_rec* r)
602 // Short-circuit entirely?
603 if (((shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib))->bOff==1)
606 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_auth_checker(%d): ENTER", (int)getpid());
608 ostringstream threadid;
609 threadid << "[" << getpid() << "] shib_auth_checker" << '\0';
610 xmltooling::NDC ndc(threadid.str().c_str());
613 ShibTargetApache sta(r);
615 pair<bool,long> res = sta.getServiceProvider().doAuthorization(sta);
616 if (res.first) return res.second;
621 catch (exception& e) {
622 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an exception: %s", e.what());
627 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an uncaught exception!");
633 // Access control plugin that enforces htaccess rules
634 class htAccessControl : virtual public AccessControl
638 ~htAccessControl() {}
639 Lockable* lock() {return this;}
641 bool authorized(const SPRequest& request, const Session* session) const;
643 bool checkAttribute(const SPRequest& request, const Attribute* attr, const char* toMatch, RegularExpression* re) const;
646 AccessControl* htAccessFactory(const xercesc::DOMElement* const & e)
648 return new htAccessControl();
651 class ApacheRequestMapper : public virtual RequestMapper, public virtual PropertySet
654 ApacheRequestMapper(const xercesc::DOMElement* e);
655 ~ApacheRequestMapper() { delete m_mapper; delete m_htaccess; delete m_staKey; delete m_propsKey; }
656 Lockable* lock() { return m_mapper->lock(); }
657 void unlock() { m_staKey->setData(NULL); m_propsKey->setData(NULL); m_mapper->unlock(); }
658 Settings getSettings(const SPRequest& request) const;
660 void setParent(const PropertySet*) {}
661 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
662 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
663 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
664 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
665 pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
666 const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const;
667 const xercesc::DOMElement* getElement() const;
670 RequestMapper* m_mapper;
672 ThreadKey* m_propsKey;
673 AccessControl* m_htaccess;
676 RequestMapper* ApacheRequestMapFactory(const xercesc::DOMElement* const & e)
678 return new ApacheRequestMapper(e);
681 ApacheRequestMapper::ApacheRequestMapper(const xercesc::DOMElement* e) : m_mapper(NULL), m_staKey(NULL), m_propsKey(NULL), m_htaccess(NULL)
683 m_mapper=SPConfig::getConfig().RequestMapperManager.newPlugin(XML_REQUEST_MAPPER,e);
684 m_htaccess=new htAccessControl();
685 m_staKey=ThreadKey::create(NULL);
686 m_propsKey=ThreadKey::create(NULL);
689 RequestMapper::Settings ApacheRequestMapper::getSettings(const SPRequest& request) const
691 Settings s=m_mapper->getSettings(request);
692 m_staKey->setData((void*)dynamic_cast<const ShibTargetApache*>(&request));
693 m_propsKey->setData((void*)s.first);
694 return pair<const PropertySet*,AccessControl*>(this,s.second ? s.second : m_htaccess);
697 pair<bool,bool> ApacheRequestMapper::getBool(const char* name, const char* ns) const
699 const ShibTargetApache* sta=reinterpret_cast<const ShibTargetApache*>(m_staKey->getData());
700 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
702 // Override Apache-settable boolean properties.
703 if (name && !strcmp(name,"requireSession") && sta->m_dc->bRequireSession==1)
704 return make_pair(true,true);
705 else if (name && !strcmp(name,"exportAssertion") && sta->m_dc->bExportAssertion==1)
706 return make_pair(true,true);
708 return s ? s->getBool(name,ns) : make_pair(false,false);
711 pair<bool,const char*> ApacheRequestMapper::getString(const char* name, const char* ns) const
713 const ShibTargetApache* sta=reinterpret_cast<const ShibTargetApache*>(m_staKey->getData());
714 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
716 // Override Apache-settable string properties.
717 if (name && !strcmp(name,"authType")) {
718 const char *auth_type=ap_auth_type(sta->m_req);
720 // Check for Basic Hijack
721 if (!strcasecmp(auth_type, "basic") && sta->m_dc->bBasicHijack == 1)
722 auth_type = "shibboleth";
723 return make_pair(true,auth_type);
726 else if (name && !strcmp(name,"applicationId") && sta->m_dc->szApplicationId)
727 return pair<bool,const char*>(true,sta->m_dc->szApplicationId);
728 else if (name && !strcmp(name,"requireSessionWith") && sta->m_dc->szRequireWith)
729 return pair<bool,const char*>(true,sta->m_dc->szRequireWith);
730 else if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
731 return pair<bool,const char*>(true,sta->m_dc->szRedirectToSSL);
733 return s ? s->getString(name,ns) : pair<bool,const char*>(false,NULL);
736 pair<bool,const XMLCh*> ApacheRequestMapper::getXMLString(const char* name, const char* ns) const
738 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
739 return s ? s->getXMLString(name,ns) : pair<bool,const XMLCh*>(false,NULL);
742 pair<bool,unsigned int> ApacheRequestMapper::getUnsignedInt(const char* name, const char* ns) const
744 const ShibTargetApache* sta=reinterpret_cast<const ShibTargetApache*>(m_staKey->getData());
745 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
747 // Override Apache-settable int properties.
748 if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
749 return pair<bool,unsigned int>(true,strtol(sta->m_dc->szRedirectToSSL,NULL,10));
751 return s ? s->getUnsignedInt(name,ns) : pair<bool,unsigned int>(false,0);
754 pair<bool,int> ApacheRequestMapper::getInt(const char* name, const char* ns) const
756 const ShibTargetApache* sta=reinterpret_cast<const ShibTargetApache*>(m_staKey->getData());
757 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
759 // Override Apache-settable int properties.
760 if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
761 return pair<bool,int>(true,atoi(sta->m_dc->szRedirectToSSL));
763 return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
766 const PropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
768 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
769 return s ? s->getPropertySet(name,ns) : NULL;
772 const xercesc::DOMElement* ApacheRequestMapper::getElement() const
774 const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
775 return s ? s->getElement() : NULL;
778 static SH_AP_TABLE* groups_for_user(request_rec* r, const char* user, char* grpfile)
781 SH_AP_TABLE* grps=ap_make_table(r->pool,15);
782 char l[MAX_STRING_LEN];
783 const char *group_name, *ll, *w;
785 #ifdef SHIB_APACHE_13
786 if (!(f=ap_pcfg_openfile(r->pool,grpfile))) {
788 if (ap_pcfg_openfile(&f,r->pool,grpfile) != APR_SUCCESS) {
790 ap_log_rerror(APLOG_MARK,APLOG_DEBUG,SH_AP_R(r),"groups_for_user() could not open group file: %s\n",grpfile);
795 #ifdef SHIB_APACHE_13
796 sp=ap_make_sub_pool(r->pool);
798 if (apr_pool_create(&sp,r->pool) != APR_SUCCESS) {
799 ap_log_rerror(APLOG_MARK,APLOG_ERR,0,r,
800 "groups_for_user() could not create a subpool");
805 while (!(ap_cfg_getline(l,MAX_STRING_LEN,f))) {
806 if ((*l=='#') || (!*l))
811 group_name=ap_getword(sp,&ll,':');
814 w=ap_getword_conf(sp,&ll);
815 if (!strcmp(w,user)) {
816 ap_table_setn(grps,ap_pstrdup(r->pool,group_name),"in");
826 bool htAccessControl::checkAttribute(const SPRequest& request, const Attribute* attr, const char* toMatch, RegularExpression* re) const
828 bool caseSensitive = attr->isCaseSensitive();
829 const vector<string>& vals = attr->getSerializedValues();
830 for (vector<string>::const_iterator v=vals.begin(); v!=vals.end(); ++v) {
832 auto_ptr<XMLCh> trans(fromUTF8(v->c_str()));
833 if (re->matches(trans.get())) {
834 request.log(SPRequest::SPDebug,
835 string("htAccessControl plugin expecting regexp ") + toMatch + ", got " + *v + ": authorization granted"
840 else if ((caseSensitive && *v == toMatch) || (!caseSensitive && !strcasecmp(v->c_str(), toMatch))) {
841 request.log(SPRequest::SPDebug,
842 string("htAccessControl plugin expecting ") + toMatch + ", got " + *v + ": authorization granted."
847 request.log(SPRequest::SPDebug,
848 string("htAccessControl plugin expecting ") + toMatch + ", got " + *v + ": authorization not granted."
855 bool htAccessControl::authorized(const SPRequest& request, const Session* session) const
857 // Make sure the object is our type.
858 const ShibTargetApache* sta=dynamic_cast<const ShibTargetApache*>(&request);
860 throw ConfigurationException("Request wrapper object was not of correct type.");
864 int m=sta->m_req->method_number;
865 bool method_restricted=false;
868 const array_header* reqs_arr=ap_requires(sta->m_req);
872 require_line* reqs=(require_line*)reqs_arr->elts;
874 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(sta->m_req),"REQUIRE nelts: %d", reqs_arr->nelts);
875 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(sta->m_req),"REQUIRE all: %d", sta->m_dc->bRequireAll);
877 vector<bool> auth_OK(reqs_arr->nelts,false);
879 #define SHIB_AP_CHECK_IS_OK { \
880 if (sta->m_dc->bRequireAll < 1) \
886 for (int x=0; x<reqs_arr->nelts; x++) {
888 if (!(reqs[x].method_mask & (1 << m)))
890 method_restricted=true;
891 string remote_user = request.getRemoteUser();
893 t = reqs[x].requirement;
894 w = ap_getword_white(sta->m_req->pool, &t);
896 if (!strcasecmp(w,"shibboleth")) {
897 // This is a dummy rule needed because Apache conflates authn and authz.
898 // Without some require rule, AuthType is ignored and no check_user hooks run.
901 else if (!strcmp(w,"valid-user")) {
903 request.log(SPRequest::SPDebug,"htAccessControl plugin accepting valid-user based on active session");
907 request.log(SPRequest::SPError,"htAccessControl plugin rejecting access for valid-user rule, no session is active");
909 else if (!strcmp(w,"user") && !remote_user.empty()) {
912 w=ap_getword_conf(sta->m_req->pool,&t);
920 // To do regex matching, we have to convert from UTF-8.
921 auto_ptr<XMLCh> trans(fromUTF8(w));
922 RegularExpression re(trans.get());
923 auto_ptr<XMLCh> trans2(fromUTF8(remote_user.c_str()));
924 if (re.matches(trans2.get())) {
925 request.log(SPRequest::SPDebug, string("htAccessControl plugin accepting user (") + w + ")");
929 catch (XMLException& ex) {
930 auto_ptr_char tmp(ex.getMessage());
931 request.log(SPRequest::SPError,
932 string("htAccessControl plugin caught exception while parsing regular expression (") + w + "): " + tmp.get());
935 else if (remote_user==w) {
936 request.log(SPRequest::SPDebug, string("htAccessControl plugin accepting user (") + w + ")");
941 else if (!strcmp(w,"group")) {
942 SH_AP_TABLE* grpstatus=NULL;
943 if (sta->m_dc->szAuthGrpFile && !remote_user.empty()) {
944 request.log(SPRequest::SPDebug,string("htAccessControl plugin using groups file: ") + sta->m_dc->szAuthGrpFile);
945 grpstatus=groups_for_user(sta->m_req,remote_user.c_str(),sta->m_dc->szAuthGrpFile);
951 w=ap_getword_conf(sta->m_req->pool,&t);
952 if (ap_table_get(grpstatus,w)) {
953 request.log(SPRequest::SPDebug, string("htAccessControl plugin accepting group (") + w + ")");
959 // Map alias in rule to the attribute.
961 request.log(SPRequest::SPError, "htAccessControl plugin not given a valid session to evaluate, are you using lazy sessions?");
965 // Find the attribute(s) matching the require rule.
966 pair<multimap<string,Attribute*>::const_iterator,multimap<string,Attribute*>::const_iterator> attrs =
967 session->getAttributes().equal_range(w);
968 if (attrs.first == attrs.second) {
969 request.log(SPRequest::SPWarn, string("htAccessControl rule requires attribute (") + w + "), not found in session");
975 while (!auth_OK[x] && *t) {
976 w=ap_getword_conf(sta->m_req->pool,&t);
983 auto_ptr<RegularExpression> re;
986 auto_ptr<XMLCh> trans(fromUTF8(w));
987 auto_ptr<xercesc::RegularExpression> temp(new xercesc::RegularExpression(trans.get()));
991 for (; !auth_OK[x] && attrs.first!=attrs.second; ++attrs.first) {
992 if (checkAttribute(request, attrs.first->second, w, regexp ? re.get() : NULL)) {
997 catch (XMLException& ex) {
998 auto_ptr_char tmp(ex.getMessage());
999 request.log(SPRequest::SPError,
1000 string("htAccessControl plugin caught exception while parsing regular expression (") + w + "): " + tmp.get()
1007 // check if all require directives are true
1008 bool auth_all_OK = true;
1009 for (int i= 0; i<reqs_arr->nelts; i++) {
1010 auth_all_OK &= auth_OK[i];
1012 if (auth_all_OK || !method_restricted)
1018 #ifndef SHIB_APACHE_13
1021 * Empty cleanup hook, Apache 2.x doesn't check NULL very well...
1023 extern "C" apr_status_t shib_exit(void* data)
1029 ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,0,NULL,"shib_exit() done");
1035 // Initial look at a request - create the per-request structure
1036 static int shib_post_read(request_rec *r)
1038 shib_request_config* rc = init_request_config(r);
1040 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_post_read: E=%s", rc->env?"env":"hdr");
1042 #ifdef SHIB_DEFERRED_HEADERS
1043 rc->hdr_out = ap_make_table(r->pool, 5);
1044 rc->hdr_err = ap_make_table(r->pool, 5);
1049 // fixups: set environment vars
1051 extern "C" int shib_fixups(request_rec* r)
1053 shib_request_config *rc = (shib_request_config*)ap_get_module_config(r->request_config, &mod_shib);
1054 shib_dir_config *dc = (shib_dir_config*)ap_get_module_config(r->per_dir_config, &mod_shib);
1055 if (dc->bOff==1 || dc->bUseEnvVars==0)
1058 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_fixup(%d): ENTER", (int)getpid());
1060 if (rc==NULL || rc->env==NULL || ap_is_empty_table(rc->env))
1063 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r), "shib_fixup adding %d vars", ap_table_elts(rc->env)->nelts);
1064 r->subprocess_env = ap_overlay_tables(r->pool, r->subprocess_env, rc->env);
1071 * Cleanup the (per-process) pool info.
1073 #ifdef SHIB_APACHE_13
1074 extern "C" void shib_child_exit(server_rec* s, SH_AP_POOL* p)
1077 extern "C" apr_status_t shib_child_exit(void* data)
1079 server_rec* s = NULL;
1082 ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit(%d) dealing with g_Config..", (int)getpid());
1085 ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit() done");
1087 #ifndef SHIB_APACHE_13
1093 * shire_child_init()
1094 * Things to do when the child process is initialized.
1095 * (or after the configs are read in apache-2)
1097 #ifdef SHIB_APACHE_13
1098 extern "C" void shib_child_init(server_rec* s, SH_AP_POOL* p)
1100 extern "C" void shib_child_init(apr_pool_t* p, server_rec* s)
1103 // Initialize runtime components.
1105 ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init(%d) starting", (int)getpid());
1108 ap_log_error(APLOG_MARK,APLOG_ERR|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() already initialized!");
1112 g_Config=&SPConfig::getConfig();
1113 g_Config->setFeatures(
1114 SPConfig::Listener |
1116 SPConfig::RequestMapping |
1117 SPConfig::InProcess |
1120 if (!g_Config->init(g_szSchemaDir)) {
1121 ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries");
1124 g_Config->AccessControlManager.registerFactory(HT_ACCESS_CONTROL,&htAccessFactory);
1125 g_Config->RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER,&ApacheRequestMapFactory);
1128 xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();
1129 XercesJanitor<xercesc::DOMDocument> docjanitor(dummydoc);
1130 xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,path);
1131 auto_ptr_XMLCh src(g_szSHIBConfig);
1132 dummy->setAttributeNS(NULL,path,src.get());
1133 dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE);
1135 g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));
1136 g_Config->getServiceProvider()->init();
1138 catch (exception& ex) {
1139 ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),ex.what());
1140 ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to load configuration");
1144 ServiceProvider* sp=g_Config->getServiceProvider();
1145 xmltooling::Locker locker(sp);
1146 const PropertySet* props=sp->getPropertySet("Local");
1148 pair<bool,const char*> unsetValue=props->getString("unsetHeaderValue");
1149 if (unsetValue.first)
1150 g_unsetHeaderValue = unsetValue.second;
1151 pair<bool,bool> checkSpoofing=props->getBool("checkSpoofing");
1152 if (checkSpoofing.first && !checkSpoofing.second)
1153 g_checkSpoofing = false;
1156 // Set the cleanup handler
1157 apr_pool_cleanup_register(p, NULL, &shib_exit, &shib_child_exit);
1159 ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() done");
1163 #ifdef SHIB_DEFERRED_HEADERS
1164 static void set_output_filter(request_rec *r)
1166 ap_add_output_filter("SHIB_HEADERS_OUT", NULL, r, r->connection);
1169 static void set_error_filter(request_rec *r)
1171 ap_add_output_filter("SHIB_HEADERS_ERR", NULL, r, r->connection);
1174 static int _table_add(void *v, const char *key, const char *value)
1176 apr_table_addn((apr_table_t*)v, key, value);
1180 static apr_status_t do_output_filter(ap_filter_t *f, apr_bucket_brigade *in)
1182 request_rec *r = f->r;
1183 shib_request_config *rc = (shib_request_config*) ap_get_module_config(r->request_config, &mod_shib);
1186 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_out_filter: merging %d headers", apr_table_elts(rc->hdr_out)->nelts);
1187 apr_table_do(_table_add,r->headers_out, rc->hdr_out,NULL);
1188 // can't use overlap call because it will collapse Set-Cookie headers
1189 //apr_table_overlap(r->headers_out, rc->hdr_out, APR_OVERLAP_TABLES_MERGE);
1192 /* remove ourselves from the filter chain */
1193 ap_remove_output_filter(f);
1195 /* send the data up the stack */
1196 return ap_pass_brigade(f->next,in);
1199 static apr_status_t do_error_filter(ap_filter_t *f, apr_bucket_brigade *in)
1201 request_rec *r = f->r;
1202 shib_request_config *rc = (shib_request_config*) ap_get_module_config(r->request_config, &mod_shib);
1205 ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(r),"shib_err_filter: merging %d headers", apr_table_elts(rc->hdr_err)->nelts);
1206 apr_table_do(_table_add,r->err_headers_out, rc->hdr_err,NULL);
1207 // can't use overlap call because it will collapse Set-Cookie headers
1208 //apr_table_overlap(r->err_headers_out, rc->hdr_err, APR_OVERLAP_TABLES_MERGE);
1211 /* remove ourselves from the filter chain */
1212 ap_remove_output_filter(f);
1214 /* send the data up the stack */
1215 return ap_pass_brigade(f->next,in);
1217 #endif // SHIB_DEFERRED_HEADERS
1219 typedef const char* (*config_fn_t)(void);
1221 #ifdef SHIB_APACHE_13
1223 // SHIB Module commands
1225 static command_rec shire_cmds[] = {
1226 {"ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
1227 RSRC_CONF, TAKE1, "Path to shibboleth.xml config file"},
1228 {"ShibCatalogs", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
1229 RSRC_CONF, TAKE1, "Paths of XML schema catalogs"},
1230 {"ShibSchemaDir", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
1231 RSRC_CONF, TAKE1, "Paths of XML schema catalogs (deprecated in favor of ShibCatalogs)"},
1233 {"ShibURLScheme", (config_fn_t)shib_set_server_string_slot,
1234 (void *) XtOffsetOf (shib_server_config, szScheme),
1235 RSRC_CONF, TAKE1, "URL scheme to force into generated URLs for a vhost"},
1237 {"ShibDisable", (config_fn_t)ap_set_flag_slot,
1238 (void *) XtOffsetOf (shib_dir_config, bOff),
1239 OR_AUTHCFG, FLAG, "Disable all Shib module activity here to save processing effort"},
1240 {"ShibApplicationId", (config_fn_t)ap_set_string_slot,
1241 (void *) XtOffsetOf (shib_dir_config, szApplicationId),
1242 OR_AUTHCFG, TAKE1, "Set Shibboleth applicationId property for content"},
1243 {"ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
1244 (void *) XtOffsetOf (shib_dir_config, bBasicHijack),
1245 OR_AUTHCFG, FLAG, "Respond to AuthType Basic and convert to shibboleth"},
1246 {"ShibRequireSession", (config_fn_t)ap_set_flag_slot,
1247 (void *) XtOffsetOf (shib_dir_config, bRequireSession),
1248 OR_AUTHCFG, FLAG, "Initiates a new session if one does not exist"},
1249 {"ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
1250 (void *) XtOffsetOf (shib_dir_config, szRequireWith),
1251 OR_AUTHCFG, TAKE1, "Initiates a new session if one does not exist using a specific SessionInitiator"},
1252 {"ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
1253 (void *) XtOffsetOf (shib_dir_config, bExportAssertion),
1254 OR_AUTHCFG, FLAG, "Export SAML attribute assertion(s) to Shib-Attributes header"},
1255 {"ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
1256 (void *) XtOffsetOf (shib_dir_config, szRedirectToSSL),
1257 OR_AUTHCFG, TAKE1, "Redirect non-SSL requests to designated port" },
1258 {"AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
1259 (void *) XtOffsetOf (shib_dir_config, szAuthGrpFile),
1260 OR_AUTHCFG, TAKE1, "text file containing group names and member user IDs"},
1261 {"ShibRequireAll", (config_fn_t)ap_set_flag_slot,
1262 (void *) XtOffsetOf (shib_dir_config, bRequireAll),
1263 OR_AUTHCFG, FLAG, "All require directives must match"},
1264 {"ShibUseEnvironment", (config_fn_t)ap_set_flag_slot,
1265 (void *) XtOffsetOf (shib_dir_config, bUseEnvVars),
1266 OR_AUTHCFG, FLAG, "Export data in environment instead of headers (default)"},
1272 handler_rec shib_handlers[] = {
1273 { "shib-handler", shib_handler },
1277 module MODULE_VAR_EXPORT mod_shib = {
1278 STANDARD_MODULE_STUFF,
1279 NULL, /* initializer */
1280 create_shib_dir_config, /* dir config creater */
1281 merge_shib_dir_config, /* dir merger --- default is to override */
1282 create_shib_server_config, /* server config */
1283 merge_shib_server_config, /* merge server config */
1284 shire_cmds, /* command table */
1285 shib_handlers, /* handlers */
1286 NULL, /* filename translation */
1287 shib_check_user, /* check_user_id */
1288 shib_auth_checker, /* check auth */
1289 NULL, /* check access */
1290 NULL, /* type_checker */
1291 shib_fixups, /* fixups */
1293 NULL, /* header parser */
1294 shib_child_init, /* child_init */
1295 shib_child_exit, /* child_exit */
1296 shib_post_read /* post read-request */
1299 #elif defined(SHIB_APACHE_20) || defined(SHIB_APACHE_22)
1301 extern "C" void shib_register_hooks (apr_pool_t *p)
1303 #ifdef SHIB_DEFERRED_HEADERS
1304 ap_register_output_filter("SHIB_HEADERS_OUT", do_output_filter, NULL, AP_FTYPE_CONTENT_SET);
1305 ap_hook_insert_filter(set_output_filter, NULL, NULL, APR_HOOK_LAST);
1306 ap_register_output_filter("SHIB_HEADERS_ERR", do_error_filter, NULL, AP_FTYPE_CONTENT_SET);
1307 ap_hook_insert_error_filter(set_error_filter, NULL, NULL, APR_HOOK_LAST);
1308 ap_hook_post_read_request(shib_post_read, NULL, NULL, APR_HOOK_MIDDLE);
1310 ap_hook_child_init(shib_child_init, NULL, NULL, APR_HOOK_MIDDLE);
1311 ap_hook_check_user_id(shib_check_user, NULL, NULL, APR_HOOK_MIDDLE);
1312 ap_hook_auth_checker(shib_auth_checker, NULL, NULL, APR_HOOK_FIRST);
1313 ap_hook_handler(shib_handler, NULL, NULL, APR_HOOK_LAST);
1314 ap_hook_fixups(shib_fixups, NULL, NULL, APR_HOOK_MIDDLE);
1317 // SHIB Module commands
1320 static command_rec shib_cmds[] = {
1321 AP_INIT_TAKE1("ShibConfig",
1322 (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
1323 RSRC_CONF, "Path to shibboleth.xml config file"),
1324 AP_INIT_TAKE1("ShibCatalogs",
1325 (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
1326 RSRC_CONF, "Paths of XML schema catalogs"),
1327 AP_INIT_TAKE1("ShibSchemaDir",
1328 (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
1329 RSRC_CONF, "Paths of XML schema catalogs (deprecated in favor of ShibCatalogs)"),
1331 AP_INIT_TAKE1("ShibURLScheme",
1332 (config_fn_t)shib_set_server_string_slot,
1333 (void *) offsetof (shib_server_config, szScheme),
1334 RSRC_CONF, "URL scheme to force into generated URLs for a vhost"),
1336 AP_INIT_FLAG("ShibDisable", (config_fn_t)ap_set_flag_slot,
1337 (void *) offsetof (shib_dir_config, bOff),
1338 OR_AUTHCFG, "Disable all Shib module activity here to save processing effort"),
1339 AP_INIT_TAKE1("ShibApplicationId", (config_fn_t)ap_set_string_slot,
1340 (void *) offsetof (shib_dir_config, szApplicationId),
1341 OR_AUTHCFG, "Set Shibboleth applicationId property for content"),
1342 AP_INIT_FLAG("ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
1343 (void *) offsetof (shib_dir_config, bBasicHijack),
1344 OR_AUTHCFG, "Respond to AuthType Basic and convert to shibboleth"),
1345 AP_INIT_FLAG("ShibRequireSession", (config_fn_t)ap_set_flag_slot,
1346 (void *) offsetof (shib_dir_config, bRequireSession),
1347 OR_AUTHCFG, "Initiates a new session if one does not exist"),
1348 AP_INIT_TAKE1("ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
1349 (void *) offsetof (shib_dir_config, szRequireWith),
1350 OR_AUTHCFG, "Initiates a new session if one does not exist using a specific SessionInitiator"),
1351 AP_INIT_FLAG("ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
1352 (void *) offsetof (shib_dir_config, bExportAssertion),
1353 OR_AUTHCFG, "Export SAML attribute assertion(s) to Shib-Attributes header"),
1354 AP_INIT_TAKE1("ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
1355 (void *) offsetof (shib_dir_config, szRedirectToSSL),
1356 OR_AUTHCFG, "Redirect non-SSL requests to designated port"),
1357 AP_INIT_TAKE1("AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
1358 (void *) offsetof (shib_dir_config, szAuthGrpFile),
1359 OR_AUTHCFG, "Text file containing group names and member user IDs"),
1360 AP_INIT_FLAG("ShibRequireAll", (config_fn_t)ap_set_flag_slot,
1361 (void *) offsetof (shib_dir_config, bRequireAll),
1362 OR_AUTHCFG, "All require directives must match"),
1363 AP_INIT_FLAG("ShibUseEnvironment", (config_fn_t)ap_set_flag_slot,
1364 (void *) offsetof (shib_dir_config, bUseEnvVars),
1365 OR_AUTHCFG, "Export data in environment instead of headers (default)"),
1370 module AP_MODULE_DECLARE_DATA mod_shib = {
1371 STANDARD20_MODULE_STUFF,
1372 create_shib_dir_config, /* create dir config */
1373 merge_shib_dir_config, /* merge dir config --- default is to override */
1374 create_shib_server_config, /* create server config */
1375 merge_shib_server_config, /* merge server config */
1376 shib_cmds, /* command table */
1377 shib_register_hooks /* register hooks */
1381 #error "unsupported Apache version"