From 87f8c5b1383ce267075073f2184f282450e16e09 Mon Sep 17 00:00:00 2001 From: cantor Date: Wed, 30 Jan 2008 22:14:39 +0000 Subject: [PATCH] Path resolution for error templates. Add prefix parameter and config support to various modules. Pull defaulted settings from Apache config. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2714 cb58f699-b61c-0410-a6fe-9272a202ed29 --- apache/mod_apache.cpp | 16 ++++++++++--- configs/Makefile.am | 2 -- configs/apache.config.in | 8 ------- configs/apache2.config.in | 8 ------- configs/apache22.config.in | 8 ------- fastcgi/shibauthorizer.cpp | 16 ++++--------- fastcgi/shibresponder.cpp | 16 ++++--------- isapi_shib/isapi_shib.cpp | 12 ++++------ msi/scripts/shib_edit_config_files.vbs | 21 +++------------- nsapi_shib/nsapi_shib.cpp | 19 +++++++-------- shibd/shibd.cpp | 40 +++++++++++++++---------------- shibd/shibd_win32.cpp | 44 +++++++++++++++++++--------------- shibsp/SPConfig.cpp | 18 +++++++------- shibsp/SPConfig.h | 19 ++++++++------- shibsp/ServiceProvider.cpp | 4 +++- shibsp/base.h | 6 ++--- shibsp/handler/impl/LogoutHandler.cpp | 4 +++- shibsp/internal.h | 19 --------------- shibsp/paths.h.in | 8 +++---- 19 files changed, 116 insertions(+), 172 deletions(-) diff --git a/apache/mod_apache.cpp b/apache/mod_apache.cpp index 9ba9f9c..11a8106 100644 --- a/apache/mod_apache.cpp +++ b/apache/mod_apache.cpp @@ -85,8 +85,9 @@ using xercesc::XMLException; extern "C" module MODULE_VAR_EXPORT mod_shib; namespace { - char* g_szSHIBConfig = SHIBSP_CONFIG; - char* g_szSchemaDir = SHIBSP_SCHEMAS; + char* g_szSHIBConfig = NULL; + char* g_szSchemaDir = NULL; + char* g_szPrefix = NULL; SPConfig* g_Config = NULL; string g_unsetHeaderValue; bool g_checkSpoofing = true; @@ -1262,12 +1263,17 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s) SPConfig::Logging | SPConfig::Handlers ); - if (!g_Config->init(g_szSchemaDir)) { + if (!g_Config->init(g_szSchemaDir, g_szPrefix)) { ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries"); exit(1); } g_Config->AccessControlManager.registerFactory(HT_ACCESS_CONTROL,&htAccessFactory); g_Config->RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER,&ApacheRequestMapFactory); + + if (!g_szSHIBConfig) + g_szSHIBConfig=getenv("SHIBSP_CONFIG"); + if (!g_szSHIBConfig) + g_szSHIBConfig=SHIBSP_CONFIG; try { xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); @@ -1369,6 +1375,8 @@ typedef const char* (*config_fn_t)(void); // SHIB Module commands static command_rec shire_cmds[] = { + {"ShibPrefix", (config_fn_t)ap_set_global_string_slot, &g_szPrefix, + RSRC_CONF, TAKE1, "Shibboleth installation directory"}, {"ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig, RSRC_CONF, TAKE1, "Path to shibboleth.xml config file"}, {"ShibCatalogs", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir, @@ -1473,6 +1481,8 @@ extern "C" void shib_register_hooks (apr_pool_t *p) extern "C" { static command_rec shib_cmds[] = { + AP_INIT_TAKE1("ShibPrefix", (config_fn_t)ap_set_global_string_slot, &g_szPrefix, + RSRC_CONF, "Shibboleth installation directory"), AP_INIT_TAKE1("ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig, RSRC_CONF, "Path to shibboleth.xml config file"), AP_INIT_TAKE1("ShibCatalogs", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir, diff --git a/configs/Makefile.am b/configs/Makefile.am index affbfee..afb642d 100644 --- a/configs/Makefile.am +++ b/configs/Makefile.am @@ -55,8 +55,6 @@ do-build-file: -e 's:@-PKGSYSCONFDIR-@:${pkgsysconfdir}:g' \ -e 's:@-PKGDOCDIR-@:${pkgdocdir}:g' \ -e 's:@-PKGXMLDIR-@:${pkgxmldir}:g' \ - -e 's:@-XMLTOOLINGXMLDIR-@:${XMLTOOLINGXMLDIR}:g' \ - -e 's:@-OPENSAMLXMLDIR-@:${OPENSAMLXMLDIR}:g' \ -e 's:@-PKGLOGDIR-@:${pkglogdir}:g' \ -e 's:@-SHIRELOGDIR-@:${shirelogdir}:g' \ -e 's:@-PKGRUNDIR-@:${pkgrundir}:g' diff --git a/configs/apache.config.in b/configs/apache.config.in index ce3422e..bce4a7e 100644 --- a/configs/apache.config.in +++ b/configs/apache.config.in @@ -13,14 +13,6 @@ LoadModule mod_shib @-PKGLIBDIR-@/mod_shib_13.so # -# Global Configuration -# This is the XML file that contains all the global, non-apache-specific -# configuration. Look at this file for most of your configuration parameters. -# -ShibSchemaDir @-XMLTOOLINGXMLDIR-@/catalog.xml:@-OPENSAMLXMLDIR-@/saml20-catalog.xml:@-OPENSAMLXMLDIR-@/saml11-catalog.xml:@-PKGXMLDIR-@/catalog.xml -ShibConfig @-PKGSYSCONFDIR-@/shibboleth2.xml - -# # An Apache handler needs to be established for the "handler" location. # This applies the handler to any requests for a resource with a ".sso" # extension. diff --git a/configs/apache2.config.in b/configs/apache2.config.in index 0fade4b..7ea0bb7 100644 --- a/configs/apache2.config.in +++ b/configs/apache2.config.in @@ -13,14 +13,6 @@ LoadModule mod_shib @-PKGLIBDIR-@/mod_shib_20.so # -# Global Configuration -# This is the XML file that contains all the global, non-apache-specific -# configuration. Look at this file for most of your configuration parameters. -# -ShibSchemaDir @-XMLTOOLINGXMLDIR-@/catalog.xml:@-OPENSAMLXMLDIR-@/saml20-catalog.xml:@-OPENSAMLXMLDIR-@/saml11-catalog.xml:@-PKGXMLDIR-@/catalog.xml -ShibConfig @-PKGSYSCONFDIR-@/shibboleth2.xml - -# # Used for example logo and style sheet in error templates. # diff --git a/configs/apache22.config.in b/configs/apache22.config.in index 744bc38..6823db5 100644 --- a/configs/apache22.config.in +++ b/configs/apache22.config.in @@ -13,14 +13,6 @@ LoadModule mod_shib @-PKGLIBDIR-@/mod_shib_22.so # -# Global Configuration -# This is the XML file that contains all the global, non-apache-specific -# configuration. Look at this file for most of your configuration parameters. -# -ShibSchemaDir @-XMLTOOLINGXMLDIR-@/catalog.xml:@-OPENSAMLXMLDIR-@/saml20-catalog.xml:@-OPENSAMLXMLDIR-@/saml11-catalog.xml:@-PKGXMLDIR-@/catalog.xml -ShibConfig @-PKGSYSCONFDIR-@/shibboleth2.xml - -# # Used for example logo and style sheet in error templates. # diff --git a/fastcgi/shibauthorizer.cpp b/fastcgi/shibauthorizer.cpp index f0fd99e..65fc832 100644 --- a/fastcgi/shibauthorizer.cpp +++ b/fastcgi/shibauthorizer.cpp @@ -236,16 +236,6 @@ static void print_error(const char* msg) int main(void) { - const char* schemadir=getenv("SHIBSP_SCHEMAS"); - if (!schemadir) - schemadir=SHIBSP_SCHEMAS; - const char* config=getenv("SHIBSP_CONFIG"); - if (!config) - config=SHIBSP_CONFIG; - - cerr << "SHIBSP_CONFIG = " << config << endl - << "SHIBSP_SCHEMAS = " << schemadir << endl; - SPConfig* g_Config=&SPConfig::getConfig(); g_Config->setFeatures( SPConfig::Listener | @@ -255,11 +245,15 @@ int main(void) SPConfig::Logging | SPConfig::Handlers ); - if (!g_Config->init(schemadir)) { + if (!g_Config->init()) { cerr << "failed to initialize Shibboleth libraries" << endl; exit(1); } + const char* config=getenv("SHIBSP_CONFIG"); + if (!config) + config=SHIBSP_CONFIG; + try { DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); XercesJanitor docjanitor(dummydoc); diff --git a/fastcgi/shibresponder.cpp b/fastcgi/shibresponder.cpp index 940ebe3..f40a2e7 100644 --- a/fastcgi/shibresponder.cpp +++ b/fastcgi/shibresponder.cpp @@ -269,16 +269,6 @@ static void print_error(const char* msg) { int main(void) { - const char* schemadir=getenv("SHIBSP_SCHEMAS"); - if (!schemadir) - schemadir=SHIBSP_SCHEMAS; - const char* config=getenv("SHIBSP_CONFIG"); - if (!config) - config=SHIBSP_CONFIG; - - cerr << "SHIBSP_CONFIG = " << config << endl - << "SHIBSP_SCHEMAS = " << schemadir << endl; - SPConfig* g_Config=&SPConfig::getConfig(); g_Config->setFeatures( SPConfig::Listener | @@ -288,11 +278,15 @@ int main(void) SPConfig::Logging | SPConfig::Handlers ); - if (!g_Config->init(schemadir)) { + if (!g_Config->init()) { cerr << "failed to initialize Shibboleth libraries" << endl; exit(1); } + const char* config=getenv("SHIBSP_CONFIG"); + if (!config) + config=SHIBSP_CONFIG; + try { DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); XercesJanitor docjanitor(dummydoc); diff --git a/isapi_shib/isapi_shib.cpp b/isapi_shib/isapi_shib.cpp index d286c4b..bff7387 100644 --- a/isapi_shib/isapi_shib.cpp +++ b/isapi_shib/isapi_shib.cpp @@ -151,12 +151,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 +160,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); diff --git a/msi/scripts/shib_edit_config_files.vbs b/msi/scripts/shib_edit_config_files.vbs index 175b533..8316b59 100644 --- a/msi/scripts/shib_edit_config_files.vbs +++ b/msi/scripts/shib_edit_config_files.vbs @@ -81,13 +81,8 @@ if (Err = 0) then FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger" ConfigFile = DistDir & "apache.config.in" - ReplaceInFile ConfigFile, "@-XMLTOOLINGXMLDIR-@", ConvertedDir & "/share/xml/xmltooling" - ReplaceInFile ConfigFile, "@-OPENSAMLXMLDIR-@", ConvertedDir & "/share/xml/opensaml" - ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth" - ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;" - ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth" - ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth" ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth" + ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth" If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false End If @@ -97,13 +92,8 @@ if (Err = 0) then FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config" ConfigFile = DistDir & "apache2.config.in" - ReplaceInFile ConfigFile, "@-XMLTOOLINGXMLDIR-@", ConvertedDir & "/share/xml/xmltooling" - ReplaceInFile ConfigFile, "@-OPENSAMLXMLDIR-@", ConvertedDir & "/share/xml/opensaml" - ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth" - ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;" - ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth" - ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth" ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth" + ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth" If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false End If @@ -113,13 +103,8 @@ if (Err = 0) then FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config" ConfigFile = DistDir & "apache22.config.in" - ReplaceInFile ConfigFile, "@-XMLTOOLINGXMLDIR-@", ConvertedDir & "/share/xml/xmltooling" - ReplaceInFile ConfigFile, "@-OPENSAMLXMLDIR-@", ConvertedDir & "/share/xml/opensaml" - ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth" - ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;" - ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth" - ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth" ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth" + ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth" If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false End If diff --git a/nsapi_shib/nsapi_shib.cpp b/nsapi_shib/nsapi_shib.cpp index 962499f..7719018 100644 --- a/nsapi_shib/nsapi_shib.cpp +++ b/nsapi_shib/nsapi_shib.cpp @@ -120,15 +120,8 @@ extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, ::Session* sn, Request* log_error(LOG_INFORM,"nsapi_shib_init",sn,rq,"nsapi_shib loaded for host (%s)",g_ServerName.c_str()); const char* schemadir=pblock_findval("shib-schemas",pb); - if (!schemadir) - schemadir=getenv("SHIBSP_SCHEMAS"); - if (!schemadir) - schemadir=SHIBSP_SCHEMAS; - const char* config=pblock_findval("shib-config",pb); - if (!config) - config=getenv("SHIBSP_CONFIG"); - if (!config) - config=SHIBSP_CONFIG; + const char* prefix=pblock_findval("shib-prefix",pb); + g_Config=&SPConfig::getConfig(); g_Config->setFeatures( SPConfig::Listener | @@ -138,7 +131,7 @@ extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, ::Session* sn, Request* SPConfig::Logging | SPConfig::Handlers ); - if (!g_Config->init(schemadir)) { + if (!g_Config->init(schemadir,prefix)) { g_Config=NULL; pblock_nvinsert("error","unable to initialize Shibboleth libraries",pb); return REQ_ABORTED; @@ -146,6 +139,12 @@ extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, ::Session* sn, Request* g_Config->RequestMapperManager.registerFactory(XML_REQUEST_MAPPER,&SunRequestMapFactory); + const char* config=pblock_findval("shib-config",pb); + if (!config) + config=getenv("SHIBSP_CONFIG"); + if (!config) + config=SHIBSP_CONFIG; + try { xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); XercesJanitor docjanitor(dummydoc); diff --git a/shibd/shibd.cpp b/shibd/shibd.cpp index 526d624..7f61f15 100644 --- a/shibd/shibd.cpp +++ b/shibd/shibd.cpp @@ -58,6 +58,7 @@ using namespace std; bool shibd_shutdown = false; const char* shar_config = NULL; const char* shar_schemadir = NULL; +const char* shar_prefix = NULL; bool shar_checkonly = false; bool shar_version = false; static int unlink_socket = 0; @@ -119,19 +120,16 @@ int real_main(int preinit) SPConfig::OutOfProcess | (shar_checkonly ? SPConfig::RequestMapping : SPConfig::Logging) ); - if (!shar_config) - shar_config=getenv("SHIBSP_CONFIG"); - if (!shar_schemadir) - shar_schemadir=getenv("SHIBSP_SCHEMAS"); - if (!shar_schemadir) - shar_schemadir=SHIBSP_SCHEMAS; - if (!shar_config) - shar_config=SHIBSP_CONFIG; - if (!conf.init(shar_schemadir)) { + if (!conf.init(shar_schemadir, shar_prefix)) { fprintf(stderr, "configuration is invalid, see console for specific problems\n"); return -1; } + if (!shar_config) + shar_config=getenv("SHIBSP_CONFIG"); + if (!shar_config) + shar_config=SHIBSP_CONFIG; + try { static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e); @@ -215,7 +213,8 @@ static int setup_signals(void) static void usage(char* whoami) { - fprintf(stderr, "usage: %s [-fcdt]\n", whoami); + fprintf(stderr, "usage: %s [-dcxtfpvh]\n", whoami); + fprintf(stderr, " -d\tinstallation prefix to use.\n"); fprintf(stderr, " -c\tconfig file to use.\n"); fprintf(stderr, " -x\tXML schema catalogs to use.\n"); fprintf(stderr, " -t\tcheck configuration file for problems.\n"); @@ -230,8 +229,11 @@ static int parse_args(int argc, char* argv[]) { int opt; - while ((opt = getopt(argc, argv, "c:x:p:ftvh")) > 0) { + while ((opt = getopt(argc, argv, "d:c:x:p:ftvh")) > 0) { switch (opt) { + case 'd': + shar_prefix=optarg; + break; case 'c': shar_config=optarg; break; @@ -269,15 +271,6 @@ int main(int argc, char *argv[]) if (setup_signals() != 0) return -1; - if (!shar_config) - shar_config=getenv("SHIBSP_CONFIG"); - if (!shar_schemadir) - shar_schemadir=getenv("SHIBSP_SCHEMAS"); - if (!shar_schemadir) - shar_schemadir=SHIBSP_SCHEMAS; - if (!shar_config) - shar_config=SHIBSP_CONFIG; - // initialize the shib-target library SPConfig& conf=SPConfig::getConfig(); conf.setFeatures( @@ -291,11 +284,16 @@ int main(int argc, char *argv[]) SPConfig::OutOfProcess | (shar_checkonly ? SPConfig::RequestMapping : SPConfig::Logging) ); - if (!conf.init(shar_schemadir)) { + if (!conf.init(shar_schemadir, shar_prefix)) { fprintf(stderr, "configuration is invalid, check console for specific problems\n"); return -1; } + if (!shar_config) + shar_config=getenv("SHIBSP_CONFIG"); + if (!shar_config) + shar_config=SHIBSP_CONFIG; + try { static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e); diff --git a/shibd/shibd_win32.cpp b/shibd/shibd_win32.cpp index 20eb442..b196ea8 100644 --- a/shibd/shibd_win32.cpp +++ b/shibd/shibd_win32.cpp @@ -28,11 +28,15 @@ #define _CRT_SECURE_NO_DEPRECATE 1 #include +#include #include +using namespace std; + extern bool shibd_shutdown; // signals shutdown to Unix side extern const char* shar_schemadir; extern const char* shar_config; +extern const char* shar_prefix; extern bool shar_checkonly; // internal variables @@ -109,6 +113,11 @@ int main(int argc, char *argv[]) if (argc > ++i) shar_config = argv[i++]; } + else if (_stricmp( "prefix", argv[i]+1) == 0) + { + if (argc > ++i) + shar_prefix = argv[i++]; + } else if (_stricmp( "catalogs", argv[i]+1) == 0) { if (argc > ++i) @@ -152,8 +161,9 @@ int main(int argc, char *argv[]) printf("%s -remove to remove the named service\n", argv[0]); printf("%s -console to run as a console app for debugging\n", argv[0]); printf("%s -check to run as a console app and check configuration\n", argv[0]); + printf("\t-prefix to specify the installation directory\n"); printf("\t-config to specify the config file to use\n"); - printf("\t-catalogs to specify schema catalogs\n"); + printf("\t-catalogs to specify schema catalogs\n"); printf("\nService starting.\nThis may take several seconds. Please wait.\n" ); SERVICE_TABLE_ENTRY dispatchTable[] = @@ -343,9 +353,6 @@ void CmdInstallService(LPCSTR name) SC_HANDLE schSCManager; char szPath[256]; - char dispName[512]; - char realName[512]; - char cmd[2048]; if ( GetModuleFileName( NULL, szPath, 256 ) == 0 ) { @@ -353,16 +360,15 @@ void CmdInstallService(LPCSTR name) return; } - sprintf(dispName,"Shibboleth %s Daemon (%s)",PACKAGE_VERSION,name); - sprintf(realName,"shibd_%s",name); - if (shar_config && shar_schemadir) - sprintf(cmd,"%s -config %s -schemadir %s",szPath,shar_config,shar_schemadir); - else if (shar_config) - sprintf(cmd,"%s -config %s",szPath,shar_config); - else if (shar_schemadir) - sprintf(cmd,"%s -schemadir %s",szPath,shar_schemadir); - else - sprintf(cmd,"%s",szPath); + string dispName = string("Shibboleth ") + PACKAGE_VERSION + " Daemon (" + name + ")"; + string realName = string("shibd_") + name; + string cmd(szPath); + if (shar_prefix) + cmd = cmd + " -prefix " + shar_prefix; + if (shar_config) + cmd = cmd + " -config " + shar_config; + if (shar_schemadir) + cmd = cmd + " -schemadir " + shar_schemadir; schSCManager = OpenSCManager( NULL, // machine (NULL == local) @@ -375,13 +381,13 @@ void CmdInstallService(LPCSTR name) { schService = CreateService( schSCManager, // SCManager database - realName, // name of service - dispName, // name to display + realName.c_str(), // name of service + dispName.c_str(), // name to display SERVICE_ALL_ACCESS, // desired access SERVICE_WIN32_OWN_PROCESS, // service type SERVICE_AUTO_START, // start type SERVICE_ERROR_NORMAL, // error control type - cmd, // service's command line + cmd.c_str(), // service's command line NULL, // no load ordering group NULL, // no tag identifier NULL, // dependencies @@ -390,7 +396,7 @@ void CmdInstallService(LPCSTR name) if ( schService ) { - printf("%s installed.\n",realName); + printf("%s installed.\n", realName.c_str()); CloseServiceHandle(schService); } else @@ -410,7 +416,7 @@ void CmdRemoveService(LPCSTR name) SC_HANDLE schSCManager; char realName[512]; - sprintf(realName,"shibd_%s",name); + _snprintf(realName,sizeof(realName),"shibd_%s",name); schSCManager = OpenSCManager( NULL, // machine (NULL == local) diff --git a/shibsp/SPConfig.cpp b/shibsp/SPConfig.cpp index f2dfe8a..772c404 100644 --- a/shibsp/SPConfig.cpp +++ b/shibsp/SPConfig.cpp @@ -85,7 +85,7 @@ DECL_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md); #endif namespace shibsp { - SPInternalConfig g_config; + SPConfig g_config; } SPConfig& SPConfig::getConfig() @@ -93,18 +93,13 @@ SPConfig& SPConfig::getConfig() return g_config; } -SPInternalConfig& SPInternalConfig::getInternalConfig() -{ - return g_config; -} - void SPConfig::setServiceProvider(ServiceProvider* serviceProvider) { delete m_serviceProvider; m_serviceProvider = serviceProvider; } -bool SPInternalConfig::init(const char* catalog_path) +bool SPConfig::init(const char* catalog_path, const char* inst_prefix) { #ifdef _DEBUG NDC ndc("init"); @@ -117,6 +112,11 @@ bool SPInternalConfig::init(const char* catalog_path) loglevel = SHIBSP_LOGGING; XMLToolingConfig::getConfig().log_config(loglevel); + if (!inst_prefix) + inst_prefix = getenv("SHIBSP_PREFIX"); + if (!inst_prefix) + inst_prefix = SHIBSP_PREFIX; + if (!catalog_path) catalog_path = getenv("SHIBSP_SCHEMAS"); if (!catalog_path) @@ -136,7 +136,7 @@ bool SPInternalConfig::init(const char* catalog_path) } #endif XMLToolingConfig::getConfig().getPathResolver()->setDefaultPackageName(PACKAGE_NAME); - XMLToolingConfig::getConfig().getPathResolver()->setDefaultPrefix(getenv("SHIBSP_PREFIX") ? getenv("SHIBSP_PREFIX") : SHIBSP_PREFIX); + XMLToolingConfig::getConfig().getPathResolver()->setDefaultPrefix(inst_prefix); XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine()); XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp"); @@ -198,7 +198,7 @@ bool SPInternalConfig::init(const char* catalog_path) return true; } -void SPInternalConfig::term() +void SPConfig::term() { #ifdef _DEBUG NDC ndc("term"); diff --git a/shibsp/SPConfig.h b/shibsp/SPConfig.h index 75cac61..81499cd 100644 --- a/shibsp/SPConfig.h +++ b/shibsp/SPConfig.h @@ -63,8 +63,14 @@ namespace shibsp { */ class SHIBSP_API SPConfig { - MAKE_NONCOPYABLE(SPConfig); + MAKE_NONCOPYABLE(SPConfig); public: + SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(NULL), +#ifndef SHIBSP_LITE + m_artifactResolver(NULL), +#endif + m_features(0) {} + virtual ~SPConfig() {} /** @@ -119,9 +125,10 @@ namespace shibsp { * before using any library classes. * * @param catalog_path delimited set of schema catalog files to load + * @param inst_prefix installation prefix for software * @return true iff initialization was successful */ - virtual bool init(const char* catalog_path)=0; + virtual bool init(const char* catalog_path=NULL, const char* inst_prefix=NULL); /** * Shuts down library @@ -129,7 +136,7 @@ namespace shibsp { * Each process using the library SHOULD call this function exactly once * before terminating itself. */ - virtual void term()=0; + virtual void term(); /** * Sets the global ServiceProvider instance. @@ -264,12 +271,6 @@ namespace shibsp { xmltooling::PluginManager< Handler,std::string,std::pair > SingleLogoutServiceManager; protected: - SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(NULL), -#ifndef SHIBSP_LITE - m_artifactResolver(NULL), -#endif - m_features(0) {} - /** Global ServiceProvider instance. */ ServiceProvider* m_serviceProvider; diff --git a/shibsp/ServiceProvider.cpp b/shibsp/ServiceProvider.cpp index 529d834..df7cf81 100644 --- a/shibsp/ServiceProvider.cpp +++ b/shibsp/ServiceProvider.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,8 @@ namespace shibsp { pathname=props->getString(page); } if (pathname.first) { - ifstream infile(pathname.second); + string fname(pathname.second); + ifstream infile(XMLToolingConfig::getConfig().getPathResolver()->resolve(fname, PathResolver::XMLTOOLING_CFG_FILE).c_str()); if (infile) { tp.setPropertySet(props); stringstream str; diff --git a/shibsp/base.h b/shibsp/base.h index 6dc2d89..9eb4cf3 100644 --- a/shibsp/base.h +++ b/shibsp/base.h @@ -74,15 +74,15 @@ # define SHIBSP_SCHEMAS "c:/opt/shibboleth-sp/share/xml/xmltooling/catalog.xml;c:/opt/shibboleth-sp/share/xml/opensaml/saml20-catalog.xml;c:/opt/shibboleth-sp/share/xml/opensaml/saml11-catalog.xml;c:/opt/shibboleth-sp/share/xml/shibboleth/catalog.xml" /** - * Default path to configuration file on Windows. + * Default name of configuration file on Windows. */ -# define SHIBSP_CONFIG "c:/opt/shibboleth-sp/etc/shibboleth/shibboleth2.xml" +# define SHIBSP_CONFIG "shibboleth2.xml" /** * Controls default logging level of console tools and other situations * where fully-configured logging isn't used. */ -#define SHIBSP_LOGGING "c:/opt/shibboleth-sp/etc/shibboleth/console.logger" +#define SHIBSP_LOGGING "console.logger" /** * Default prefix for installation (used to resolve relative paths). diff --git a/shibsp/handler/impl/LogoutHandler.cpp b/shibsp/handler/impl/LogoutHandler.cpp index 8bd3d56..3ef1cd2 100644 --- a/shibsp/handler/impl/LogoutHandler.cpp +++ b/shibsp/handler/impl/LogoutHandler.cpp @@ -30,6 +30,7 @@ #include #include +#include #include using namespace shibsp; @@ -46,7 +47,8 @@ pair LogoutHandler::sendLogoutPage( response.setContentType("text/html"); response.setResponseHeader("Expires","01-Jan-1997 12:00:00 GMT"); response.setResponseHeader("Cache-Control","private,no-store,no-cache"); - ifstream infile(prop.second); + string fname(prop.second); + ifstream infile(XMLToolingConfig::getConfig().getPathResolver()->resolve(fname, PathResolver::XMLTOOLING_CFG_FILE).c_str()); if (!infile) throw ConfigurationException("Unable to access $1 HTML template.", params(1,local ? "localLogout" : "globalLogout")); TemplateParameters tp; diff --git a/shibsp/internal.h b/shibsp/internal.h index e10017b..1b5e9e5 100644 --- a/shibsp/internal.h +++ b/shibsp/internal.h @@ -48,23 +48,4 @@ using namespace xmltooling::logging; using namespace xercesc; -namespace shibsp { - - /// @cond OFF - class SPInternalConfig : public SPConfig - { - public: - SPInternalConfig() {} - - static SPInternalConfig& getInternalConfig(); - - bool init(const char* catalog_path); - void term(); - - private: - }; - /// @endcond - -}; - #endif /* __shibsp_internal_h__ */ diff --git a/shibsp/paths.h.in b/shibsp/paths.h.in index 3511b89..9f5e2b1 100644 --- a/shibsp/paths.h.in +++ b/shibsp/paths.h.in @@ -29,14 +29,14 @@ #define SHIBSP_SCHEMAS "@-XMLTOOLINGXMLDIR-@/catalog.xml:@-OPENSAMLXMLDIR-@/saml20-catalog.xml:@-OPENSAMLXMLDIR-@/saml11-catalog.xml:@-PKGXMLDIR-@/catalog.xml" /** - * Default location of SP configuration file. + * Default name of SP configuration file. */ -#define SHIBSP_CONFIG "@-PKGSYSCONFDIR-@/shibboleth2.xml" +#define SHIBSP_CONFIG "shibboleth2.xml" /** - * Default location of SP console tool logging file. + * Default name of SP console tool logging file. */ -#define SHIBSP_LOGGING "@-PKGSYSCONFDIR-@/console.logger" +#define SHIBSP_LOGGING "console.logger" /** * Default prefix for installation (used to resolve relative paths). -- 2.1.4