VBoxService-win.cpp revision 942d1a32d70995e0b2d6fc8c109432e0613967ac
/* $Id$ */
/** @file
* VBoxService - Guest Additions Service Skeleton, Windows Specific Parts.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include <Windows.h>
#include <process.h>
#include <aclapi.h>
DWORD g_rcWinService = 0;
static SERVICE_TABLE_ENTRY const g_aServiceTable[]=
{
};
/**
* @todo Format code style.
* @todo Add full unicode support.
* @todo Add event log capabilities / check return values.
*/
{
if (NULL == pszObjName)
return ERROR_INVALID_PARAMETER;
/* Get a pointer to the existing DACL. */
if (ERROR_SUCCESS != dwRes)
{
if (dwRes == ERROR_FILE_NOT_FOUND)
VBoxServiceError("AddAceToObjectsSecurityDescriptor: Object not found/installed: %s\n", pszObjName);
else
goto Cleanup;
}
/* Initialize an EXPLICIT_ACCESS structure for the new ACE. */
/* Create a new ACL that merges the new ACE into the existing DACL. */
if (ERROR_SUCCESS != dwRes)
{
goto Cleanup;
}
/* Attach the new ACL as the object's DACL. */
if (ERROR_SUCCESS != dwRes)
{
goto Cleanup;
}
/** @todo get rid of that spaghetti jump ... */
return dwRes;
}
{
if (NULL == g_hWinServiceStatus) /* Program could be in testing mode, so no service environment available. */
return FALSE;
}
int VBoxServiceWinInstall(void)
{
if (NULL == hSCManager) {
return 1;
}
return 1;
}
else
{
VBoxServiceVerbose(0, "Service successfully installed!\n");
}
return 0;
}
int VBoxServiceWinUninstall(void)
{
if (NULL == hSCManager) {
return 1;
}
return 1;
}
{
return 1;
}
else
{
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\System", 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
}
VBoxServiceVerbose(0, "Service successfully uninstalled!\n");
}
return 0;
}
int VBoxServiceWinStart(void)
{
int rc = VINF_SUCCESS;
#ifndef TARGET_NT4
/* Create a well-known SID for the "Builtin Users" group. */
0, 0, 0, 0, 0, 0, 0,
{
}
else
{
if (dwRes != ERROR_SUCCESS)
{
if (dwRes == ERROR_FILE_NOT_FOUND)
{
/* If we don't find our "VBoxMiniRdrDN" (for Shared Folders) object above,
don't report an error; it just might be not installed. Otherwise this
would cause the SCM to hang on starting up the service. */
rc = VINF_SUCCESS;
}
}
}
#endif
if (RT_SUCCESS(rc))
{
/* Notify SCM *before* we're starting the services, because the last services
always starts in main thread (which causes the SCM to wait because of the non-responding
service). */
/*
* Check that at least one service is enabled.
*/
unsigned iMain = VBoxServiceGetStartedServices();
if (RT_FAILURE(rc))
}
if (RT_FAILURE(rc))
return rc;
}
#ifdef TARGET_NT4
#else
#endif
{
#ifndef TARGET_NT4
#endif
switch (dwControl)
{
break;
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
{
}
break;
case SERVICE_CONTROL_SESSIONCHANGE: /* Only Win XP and up. */
#ifndef TARGET_NT4
switch (dwEventType)
{
/*case WTS_SESSION_LOGON:
VBoxServiceVerbose(2, "A user has logged on to the session.\n");
break;
case WTS_SESSION_LOGOFF:
VBoxServiceVerbose(2, "A user has logged off from the session.\n");
break;*/
default:
break;
}
#endif /* TARGET_NT4 */
break;
default:
break;
}
#ifndef TARGET_NT4
return rc;
#endif
}
{
int rc = VINF_SUCCESS;
#ifdef TARGET_NT4
#else
g_hWinServiceStatus = RegisterServiceCtrlHandlerEx (VBOXSERVICE_NAME, VBoxServiceWinCtrlHandler, NULL);
#endif
if (NULL == g_hWinServiceStatus)
{
switch (dwErr)
{
case ERROR_INVALID_NAME:
VBoxServiceError("Invalid service name!\n");
break;
VBoxServiceError("Service does not exist!\n");
break;
default:
break;
}
}
else
{
rc = VBoxServiceWinStart();
}
}