VBoxService.cpp revision 240f7d7012a5f64bcde850bcf048531a710d81cf
/* $Id$ */
/** @file
* VBoxService - The Guest Additions Helper Service.
*/
/*
* Copyright (C) 2008 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.
*/
#include "VBoxService.h"
#ifdef VBOX_WITH_GUEST_PROPS
#include "VBoxVMInfo.h"
#endif
#include "resource.h"
/* Global variables. */
/* Prototypes. */
/* The service table. */
static VBOXSERVICEINFO vboxServiceTable[] =
{
#ifdef VBOX_WITH_GUEST_PROPS
{
"VMInfo",
},
#endif
{
}
};
/**
* @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) {
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;
}
return dwRes;
}
{
if (NULL == gvboxServiceStatusHandle) /* Program could be in testing mode, so no service environment available. */
return;
ss.dwCheckPoint = 0;
}
{
Log(("VBoxService: Starting services ...\n"));
if (!pEnv->hStopEvent)
{
/* Could not create event. */
return VERR_NOT_SUPPORTED;
}
{
int rc = VINF_SUCCESS;
bool fStartThread = false;
{
}
if (RT_FAILURE (rc))
{
}
else
{
{
unsigned threadid;
0, /* stacksize */
0, /* initflag */
&threadid);
{
}
}
if (RT_FAILURE (rc))
{
if (pTable->pfnDestroy)
{
}
}
else
{
}
}
/* Advance to next table element. */
pTable++;
}
Log(("VBoxService: All threads started.\n"));
return VINF_SUCCESS;
}
{
/* Signal to all threads. */
{
Log(("VBoxService: Setting stop event ...\n"));
}
{
{
{
/* There is a thread, wait for termination. */
}
if (pTable->pfnDestroy)
{
}
}
/* Advance to next table element. */
pTable++;
}
}
void vboxServiceStart()
{
{
return;
}
/* Create a well-known SID for the "Builtin Users" group. */
0, 0, 0, 0, 0, 0, 0,
{
}
/* Start service threads. */
/** @todo Add error handling. */
}
{
switch (dwControl)
{
break;
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
{
/* Don't close VBox driver here - the service might be
* started again. */
}
break;
case SERVICE_CONTROL_SESSIONCHANGE: /* Only Win XP and up. */
switch (dwEventType)
{
case WTS_SESSION_LOGON:
Log(("VBoxService: A user has logged on to the session.\n"));
break;
case WTS_SESSION_LOGOFF:
Log(("VBoxService: A user has logged off from the session.\n"));
break;
default:
break;
}
break;
default:
break;
}
return rc;
}
{
Log(("VBoxService: Registering service control handler ...\n"));
gvboxServiceStatusHandle = RegisterServiceCtrlHandlerEx (VBOXSERVICE_NAME, ServiceCtrlHandler, NULL);
if (NULL == gvboxServiceStatusHandle)
{
switch (dwErr)
{
case ERROR_INVALID_NAME:
writeLog("VBoxService: Invalid service name!\n");
break;
writeLog("VBoxService: Service does not exist!\n");
break;
default:
break;
}
}
else
{
while (1) {
}
}
}
int Install ()
{
writeLog("VBoxService: Installing service ...\n");
if (NULL == hSCManager) {
return 1;
}
return 1;
}
else
{
writeLog("VBoxService: Service successfully installed!\n");
}
return 0;
}
int Uninstall ()
{
writeLog("VBoxService: Uninstalling service ...\n");
if (NULL == hSCManager) {
return 1;
}
return 1;
}
{
return 1;
}
else
{
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\System"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
}
writeLog("VBoxService: Service successfully uninstalled!\n");
}
return 0;
}
{
char szBuffer[1024] = { 0 };
}
{
_tprintf(_T("Version: %d.%d.%d.%d\n\n"), VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
}
{
/* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
if ( (hMutexAppRunning != NULL)
&& (GetLastError() == ERROR_ALREADY_EXISTS))
{
/* Close the mutex for this application instance. */
}
if (RT_FAILURE(rc))
{
return rc;
}
rc = VbglR3Init();
if (RT_FAILURE(rc))
{
writeLog("VBoxService: Failed to contact the VirtualBox host! Program maybe not running in a VM? Error: %d\n", rc);
return rc;
}
LogRel(("VBoxService: Started.\n"));
static SERVICE_TABLE_ENTRY const s_serviceTable[]=
{
};
if (argc > 1)
{
Install();
Uninstall();
{
while (1) {
}
}
else {
}
}
else /* Normal service. */
{
}
/* Release instance mutex. */
if (hMutexAppRunning != NULL) {
}
writeLog("VBoxService: Ended.\n");
VbglR3Term();
return 0;
}