Bump header file dependencies in specfile
[shibboleth/cpp-sp.git] / shibd / shibd_win32.cpp
index 96315d1..ae8ff46 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2010 Internet2
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /*
@@ -34,6 +38,7 @@ extern const char* shar_schemadir;
 extern const char* shar_config;
 extern const char* shar_prefix;
 extern bool shar_checkonly;
+extern bool shar_version;
 
 // internal variables
 SERVICE_STATUS          ssStatus;       // current status of the service
@@ -43,6 +48,8 @@ BOOL                    bConsole = FALSE;
 char                    szErr[256];
 LPCSTR                  lpszInstall = nullptr;
 LPCSTR                  lpszRemove = nullptr;
+LPCSTR                  lpszStdout = nullptr;
+LPCSTR                  lpszStderr = nullptr;
 
 // internal function prototypes
 VOID WINAPI service_ctrl(DWORD dwCtrlCode);
@@ -76,7 +83,7 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
 }
 
 
-int real_main(int);  // The revised two-phase main() in shar.cpp
+int real_main(int);  // The revised two-phase main() in shibd.cpp
 
 int main(int argc, char *argv[])
 {
@@ -93,6 +100,20 @@ int main(int argc, char *argv[])
             if (argc > ++i)
                 lpszRemove = argv[i++];
         }
+        else if (_stricmp("stdout", argv[i]+1) == 0)
+        {
+            if (argc > ++i) {
+                lpszStdout = argv[i++];
+                freopen(lpszStdout, "a+", stdout);
+            }
+        }
+        else if (_stricmp("stderr", argv[i]+1) == 0)
+        {
+            if (argc > ++i) {
+                lpszStderr = argv[i++];
+                freopen(lpszStderr, "a+", stderr);
+            }
+        }
         else if (_stricmp( "console", argv[i]+1) == 0)
         {
             i++;
@@ -102,7 +123,13 @@ int main(int argc, char *argv[])
         {
             i++;
             bConsole = TRUE;
-            shar_checkonly=true;
+            shar_checkonly = true;
+        }
+        else if (_stricmp( "version", argv[i]+1) == 0)
+        {
+            i++;
+            bConsole = TRUE;
+            shar_version = true;
         }
         else if (_stricmp( "config", argv[i]+1) == 0)
         {
@@ -157,6 +184,9 @@ int main(int argc, char *argv[])
         printf("%s -remove <name>    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("%s -version          to run as a console app and print the version\n", argv[0]);
+        printf("\t-stdout <path> to redirect stdout stream\n");
+        printf("\t-stderr <path> to redirect stderr stream\n");
         printf("\t-prefix <dir> to specify the installation directory\n");
         printf("\t-config <file> to specify the config file to use\n");
         printf("\t-catalogs <catalog1:catalog2> to specify schema catalogs\n");
@@ -365,6 +395,10 @@ void CmdInstallService(LPCSTR name)
         cmd = cmd + " -config " + shar_config;
     if (shar_schemadir)
         cmd = cmd + " -schemadir " + shar_schemadir;
+    if (lpszStdout)
+        cmd = cmd + " -stdout " + lpszStdout;
+    if (lpszStderr)
+        cmd = cmd + " -stderr " + lpszStderr;
 
     schSCManager = OpenSCManager(
                         nullptr,                   // machine (nullptr == local)