X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=isapi_shib%2Fisapi_shib.cpp;h=1f01f44186083f87ba4677a0228e99cb6030aeac;hb=4f85e385a59229b06f2ae6eef7a58a1d403f8959;hp=f608c722d79598f29560b57b8a842932d96821df;hpb=a532fe2021e9f3858f00dfbc7cfb0eb445519c74;p=shibboleth%2Fsp.git diff --git a/isapi_shib/isapi_shib.cpp b/isapi_shib/isapi_shib.cpp index f608c72..1f01f44 100644 --- a/isapi_shib/isapi_shib.cpp +++ b/isapi_shib/isapi_shib.cpp @@ -88,6 +88,11 @@ namespace { string m_scheme,m_port,m_sslport,m_name; set m_aliases; }; + + struct context_t { + char* m_user; + bool m_checked; + }; HINSTANCE g_hinstDLL; SPConfig* g_Config = NULL; @@ -151,12 +156,6 @@ extern "C" BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) return TRUE; } - LPCSTR schemadir=getenv("SHIBSP_SCHEMAS"); - if (!schemadir) - schemadir=SHIBSP_SCHEMAS; - LPCSTR config=getenv("SHIBSP_CONFIG"); - if (!config) - config=SHIBSP_CONFIG; g_Config=&SPConfig::getConfig(); g_Config->setFeatures( SPConfig::Listener | @@ -166,13 +165,17 @@ extern "C" BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) SPConfig::Logging | SPConfig::Handlers ); - if (!g_Config->init(schemadir)) { + if (!g_Config->init()) { g_Config=NULL; LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "Filter startup failed during library initialization, check native log for help."); return FALSE; } + LPCSTR config=getenv("SHIBSP_CONFIG"); + if (!config) + config=SHIBSP_CONFIG; + try { DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); XercesJanitor docjanitor(dummydoc); @@ -360,7 +363,7 @@ class ShibTargetIsapiF : public AbstractSPRequest public: ShibTargetIsapiF(PHTTP_FILTER_CONTEXT pfc, PHTTP_FILTER_PREPROC_HEADERS pn, const site_t& site) - : m_pfc(pfc), m_pn(pn), m_allhttp(4096) { + : AbstractSPRequest(SHIBSP_LOGCAT".ISAPI"), m_pfc(pfc), m_pn(pn), m_allhttp(4096) { // URL path always come from IIS. dynabuf var(256); @@ -390,6 +393,14 @@ public: m_hostname = var; if (site.m_name!=m_hostname && site.m_aliases.find(m_hostname)==site.m_aliases.end()) m_hostname=site.m_name; + + if (!pfc->pFilterContext) { + pfc->pFilterContext = pfc->AllocMem(pfc, sizeof(context_t), NULL); + if (static_cast(pfc->pFilterContext)) { + static_cast(pfc->pFilterContext)->m_user = NULL; + static_cast(pfc->pFilterContext)->m_checked = false; + } + } } ~ShibTargetIsapiF() { } @@ -438,7 +449,7 @@ public: LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, msg.c_str()); } void clearHeader(const char* rawname, const char* cginame) { - if (g_checkSpoofing) { + if (g_checkSpoofing && m_pfc->pFilterContext && !static_cast(m_pfc->pFilterContext)->m_checked) { if (m_allhttp.empty()) GetServerVariable(m_pfc,"ALL_HTTP",m_allhttp,4096); if (strstr(m_allhttp, cginame)) @@ -462,6 +473,12 @@ public: } void setRemoteUser(const char* user) { setHeader("remote-user", user); + if (m_pfc->pFilterContext) { + if (!user || !*user) + static_cast(m_pfc->pFilterContext)->m_user = NULL; + else if (static_cast(m_pfc->pFilterContext)->m_user = (char*)m_pfc->AllocMem(m_pfc, sizeof(char) * (strlen(user) + 1), NULL)) + strcpy(static_cast(m_pfc->pFilterContext)->m_user, user); + } } string getRemoteUser() const { return getHeader("remote-user"); @@ -549,7 +566,7 @@ extern "C" DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificat if (notificationType==SF_NOTIFY_LOG) { if (pfc->pFilterContext) - ((PHTTP_FILTER_LOG)pvNotification)->pszClientUserName=static_cast(pfc->pFilterContext); + ((PHTTP_FILTER_LOG)pvNotification)->pszClientUserName=static_cast(pfc->pFilterContext)->m_user; return SF_STATUS_REQ_NEXT_NOTIFICATION; } @@ -573,6 +590,8 @@ extern "C" DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificat // "false" because we don't override the Shib settings pair res = stf.getServiceProvider().doAuthentication(stf); + if (pfc->pFilterContext) + static_cast(pfc->pFilterContext)->m_checked = true; if (res.first) return res.second; // "false" because we don't override the Shib settings @@ -640,7 +659,8 @@ class ShibTargetIsapiE : public AbstractSPRequest mutable string m_remote_addr,m_remote_user; public: - ShibTargetIsapiE(LPEXTENSION_CONTROL_BLOCK lpECB, const site_t& site) : m_lpECB(lpECB), m_gotBody(false) { + ShibTargetIsapiE(LPEXTENSION_CONTROL_BLOCK lpECB, const site_t& site) + : AbstractSPRequest(SHIBSP_LOGCAT".ISAPI"), m_lpECB(lpECB), m_gotBody(false) { dynabuf ssl(5); GetServerVariable(lpECB,"HTTPS",ssl,5); bool SSL=(ssl=="on" || ssl=="ON"); @@ -895,7 +915,7 @@ extern "C" DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) // Match site instance to host name, skip if no match. map::const_iterator map_i=g_Sites.find(static_cast(buf)); if (map_i==g_Sites.end()) - return WriteClientError(lpECB, "Shibboleth Extension not configured for this web site."); + return WriteClientError(lpECB, "Shibboleth Extension not configured for web site (check mappings in configuration)."); ShibTargetIsapiE ste(lpECB, map_i->second); pair res = ste.getServiceProvider().doHandler(ste);