-/*
- * Copyright 2001-2007 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.
*/
/*
* shar_win32.cpp -- the SHAR "main" code on Win32
- *
- * Created By: Scott Cantor (cantor.2@osu.edu)
- *
- * $Id: shar_win32.cpp 2150 2007-02-02 04:06:15 +0000 (Fri, 02 Feb 2007) cantor $
*/
#include "config_win32.h"
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
DWORD dwErr = 0;
BOOL bConsole = FALSE;
char szErr[256];
-LPCSTR lpszInstall = NULL;
-LPCSTR lpszRemove = NULL;
+LPCSTR lpszInstall = nullptr;
+LPCSTR lpszRemove = nullptr;
+LPCSTR lpszStdout = nullptr;
+LPCSTR lpszStderr = nullptr;
// internal function prototypes
VOID WINAPI service_ctrl(DWORD dwCtrlCode);
}
-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[])
{
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++;
{
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)
{
SetConsoleCtrlHandler(&BreakHandler,TRUE);
if ((i=real_main(1))!=0)
{
- LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "shibd startup failed, check shibd.log for further details");
+ LogEvent(nullptr, EVENTLOG_ERROR_TYPE, 2100, nullptr, "shibd startup failed, check shibd.log for further details");
return i;
}
return real_main(0);
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");
SERVICE_TABLE_ENTRY dispatchTable[] =
{
{ "SHIBD", (LPSERVICE_MAIN_FUNCTION)service_main },
- { NULL, NULL }
+ { nullptr, nullptr }
};
if (!StartServiceCtrlDispatcher(dispatchTable))
- LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "StartServiceCtrlDispatcher failed.");
+ LogEvent(nullptr, EVENTLOG_ERROR_TYPE, 2100, nullptr, "StartServiceCtrlDispatcher failed.");
return 0;
}
if (real_main(1)!=0)
{
- LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "shibd startup failed, check shibd.log for further details");
+ LogEvent(nullptr, EVENTLOG_ERROR_TYPE, 2100, nullptr, "shibd startup failed, check shibd.log for further details");
return;
}
- LogEvent(NULL, EVENTLOG_INFORMATION_TYPE, 7700, NULL, "shibd started successfully.");
+ LogEvent(nullptr, EVENTLOG_INFORMATION_TYPE, 7700, nullptr, "shibd started successfully.");
if (!ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 0))
return;
VOID ServiceStop()
{
if (!bConsole)
- LogEvent(NULL, EVENTLOG_INFORMATION_TYPE, 7701, NULL, "shibd stopping...");
+ LogEvent(nullptr, EVENTLOG_INFORMATION_TYPE, 7701, nullptr, "shibd stopping...");
shibd_shutdown=true;
}
// Report the status of the service to the service control manager.
//
if (!(fResult = SetServiceStatus(sshStatusHandle, &ssStatus)))
- LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "SetServiceStatus failed.");
+ LogEvent(nullptr, EVENTLOG_ERROR_TYPE, 2100, nullptr, "SetServiceStatus failed.");
}
return fResult;
}
char szPath[256];
- if ( GetModuleFileName( NULL, szPath, 256 ) == 0 )
+ if ( GetModuleFileName( nullptr, szPath, 256 ) == 0 )
{
printf("Unable to install %s - %s\n", name, GetLastErrorText(szErr, 256));
return;
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(
- NULL, // machine (NULL == local)
- NULL, // database (NULL == default)
+ nullptr, // machine (nullptr == local)
+ nullptr, // database (nullptr == default)
SC_MANAGER_ALL_ACCESS // access required
);
SERVICE_AUTO_START, // start type
SERVICE_ERROR_NORMAL, // error control type
cmd.c_str(), // service's command line
- NULL, // no load ordering group
- NULL, // no tag identifier
- NULL, // dependencies
- NULL, // LocalSystem account
- NULL); // no password
+ nullptr, // no load ordering group
+ nullptr, // no tag identifier
+ nullptr, // dependencies
+ nullptr, // LocalSystem account
+ nullptr); // no password
if ( schService )
{
_snprintf(realName,sizeof(realName),"shibd_%s",name);
schSCManager = OpenSCManager(
- NULL, // machine (NULL == local)
- NULL, // database (NULL == default)
+ nullptr, // machine (nullptr == local)
+ nullptr, // database (nullptr == default)
SC_MANAGER_ALL_ACCESS // access required
);
if ( schSCManager )
LPTSTR GetLastErrorText( LPSTR lpszBuf, DWORD dwSize )
{
DWORD dwRet;
- LPSTR lpszTemp = NULL;
+ LPSTR lpszTemp = nullptr;
dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
- NULL,
+ nullptr,
GetLastError(),
LANG_NEUTRAL,
(LPSTR)&lpszTemp,
0,
- NULL );
+ nullptr );
// supplied buffer is not long enough
if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) )
PSID lpUserSid,
LPCSTR message)
{
- LPCSTR messages[] = {message, NULL};
+ LPCSTR messages[] = {message, nullptr};
HANDLE hElog = RegisterEventSource(lpUNCServerName, "Shibboleth Daemon");
- BOOL res = ReportEvent(hElog, wType, 0, dwEventID, lpUserSid, 1, 0, messages, NULL);
+ BOOL res = ReportEvent(hElog, wType, 0, dwEventID, lpUserSid, 1, 0, messages, nullptr);
return (DeregisterEventSource(hElog) && res);
}