Path resolution for error templates.
[shibboleth/sp.git] / shibd / shibd_win32.cpp
index 20eb442..b196ea8 100644 (file)
 #define _CRT_SECURE_NO_DEPRECATE 1\r
 \r
 #include <shibsp/base.h>\r
+#include <string>\r
 #include <windows.h>\r
 \r
+using namespace std;\r
+\r
 extern bool shibd_shutdown;                    // signals shutdown to Unix side\r
 extern const char* shar_schemadir;\r
 extern const char* shar_config;\r
+extern const char* shar_prefix;\r
 extern bool shar_checkonly;\r
 \r
 // internal variables\r
@@ -109,6 +113,11 @@ int main(int argc, char *argv[])
             if (argc > ++i)\r
                 shar_config = argv[i++];\r
         }\r
+        else if (_stricmp( "prefix", argv[i]+1) == 0)\r
+        {\r
+            if (argc > ++i)\r
+                shar_prefix = argv[i++];\r
+        }\r
         else if (_stricmp( "catalogs", argv[i]+1) == 0)\r
         {\r
             if (argc > ++i)\r
@@ -152,8 +161,9 @@ int main(int argc, char *argv[])
         printf("%s -remove <name>    to remove the named service\n", argv[0]);\r
         printf("%s -console          to run as a console app for debugging\n", argv[0]);\r
         printf("%s -check            to run as a console app and check configuration\n", argv[0]);\r
+        printf("\t-prefix <dir> to specify the installation directory\n");\r
         printf("\t-config <file> to specify the config file to use\n");\r
-        printf("\t-catalogs <dir> to specify schema catalogs\n");\r
+        printf("\t-catalogs <catalog1:catalog2> to specify schema catalogs\n");\r
         printf("\nService starting.\nThis may take several seconds. Please wait.\n" );\r
 \r
     SERVICE_TABLE_ENTRY dispatchTable[] =\r
@@ -343,9 +353,6 @@ void CmdInstallService(LPCSTR name)
     SC_HANDLE   schSCManager;\r
 \r
     char szPath[256];\r
-    char dispName[512];\r
-    char realName[512];\r
-    char cmd[2048];\r
 \r
     if ( GetModuleFileName( NULL, szPath, 256 ) == 0 )\r
     {\r
@@ -353,16 +360,15 @@ void CmdInstallService(LPCSTR name)
         return;\r
     }\r
     \r
-    sprintf(dispName,"Shibboleth %s Daemon (%s)",PACKAGE_VERSION,name);\r
-    sprintf(realName,"shibd_%s",name);\r
-    if (shar_config && shar_schemadir)\r
-        sprintf(cmd,"%s -config %s -schemadir %s",szPath,shar_config,shar_schemadir);\r
-    else if (shar_config)\r
-        sprintf(cmd,"%s -config %s",szPath,shar_config);\r
-    else if (shar_schemadir)\r
-        sprintf(cmd,"%s -schemadir %s",szPath,shar_schemadir);\r
-    else\r
-        sprintf(cmd,"%s",szPath);\r
+    string dispName = string("Shibboleth ") + PACKAGE_VERSION + " Daemon (" + name + ")";\r
+    string realName = string("shibd_") + name;\r
+    string cmd(szPath);\r
+    if (shar_prefix)\r
+        cmd = cmd + " -prefix " + shar_prefix;\r
+    if (shar_config)\r
+        cmd = cmd + " -config " + shar_config;\r
+    if (shar_schemadir)\r
+        cmd = cmd + " -schemadir " + shar_schemadir;\r
 \r
     schSCManager = OpenSCManager(\r
                         NULL,                   // machine (NULL == local)\r
@@ -375,13 +381,13 @@ void CmdInstallService(LPCSTR name)
     {\r
         schService = CreateService(\r
             schSCManager,               // SCManager database\r
-            realName,                   // name of service\r
-            dispName,                   // name to display\r
+            realName.c_str(),           // name of service\r
+            dispName.c_str(),           // name to display\r
             SERVICE_ALL_ACCESS,         // desired access\r
             SERVICE_WIN32_OWN_PROCESS,  // service type\r
             SERVICE_AUTO_START,         // start type\r
             SERVICE_ERROR_NORMAL,       // error control type\r
-            cmd,                        // service's command line\r
+            cmd.c_str(),                // service's command line\r
             NULL,                       // no load ordering group\r
             NULL,                       // no tag identifier\r
             NULL,                       // dependencies\r
@@ -390,7 +396,7 @@ void CmdInstallService(LPCSTR name)
 \r
         if ( schService )\r
         {\r
-            printf("%s installed.\n",realName);\r
+            printf("%s installed.\n", realName.c_str());\r
             CloseServiceHandle(schService);\r
         }\r
         else\r
@@ -410,7 +416,7 @@ void CmdRemoveService(LPCSTR name)
     SC_HANDLE   schSCManager;\r
     char        realName[512];\r
 \r
-    sprintf(realName,"shibd_%s",name);\r
+    _snprintf(realName,sizeof(realName),"shibd_%s",name);\r
 \r
     schSCManager = OpenSCManager(\r
                         NULL,                   // machine (NULL == local)\r