VBoxService.cpp revision 0f5387ab2b3728b4cc428083ce9ad305396bb721
/** @file
* VBoxService - Guest Additions Service
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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.
*/
#include "VBoxService.h"
#include "VBoxSeamless.h"
#include "VBoxClipboard.h"
#include "VBoxDisplay.h"
#include "VBoxRestore.h"
#include "VBoxVRDP.h"
#include "VBoxGuest.h"
#include <VBoxHook.h>
#include "resource.h"
#include <malloc.h>
#include <VBoxGuestInternal.h>
#include "helpers.h"
#include <sddl.h>
/* global variables */
/* prototypes */
#ifdef DEBUG
/**
* Helper function to send a message to WinDbg
*
* @param String message string
*/
{
return;
}
#endif
/* The service table. */
static VBOXSERVICEINFO vboxServiceTable[] =
{
{
"Display",
},
{
"Shared Clipboard",
},
{
"Seamless Windows",
},
#ifdef VBOX_WITH_MANAGEMENT
{
"Guest Management",
},
#endif
{
"Restore",
},
#endif
{
"VRDP",
},
{
}
};
{
if (!pEnv->hStopEvent)
{
/* Could not create event. */
return VERR_NOT_SUPPORTED;
}
{
int rc = VINF_SUCCESS;
bool fStartThread = false;
{
}
if (VBOX_FAILURE (rc))
{
}
else
{
{
unsigned threadid;
0, /* stacksize */
0, /* initflag */
&threadid);
{
}
}
if (VBOX_FAILURE (rc))
{
dprintf(("Failed to start the thread.\n"));
if (pTable->pfnDestroy)
{
}
}
else
{
}
}
/* Advance to next table element. */
pTable++;
}
return VINF_SUCCESS;
}
{
if (!pEnv->hStopEvent)
{
return;
}
/* Signal to all threads. */
{
{
{
/* There is a thread, wait for termination. */
}
if (pTable->pfnDestroy)
{
}
}
/* Advance to next table element. */
pTable++;
}
}
void WINAPI VBoxServiceStart(void)
{
dprintf(("VBoxService: Start\n"));
/* open VBox guest driver */
NULL,
NULL);
if (gVBoxDriver == INVALID_HANDLE_VALUE)
{
}
{
/* create a custom window class */
WNDCLASS windowClass = {0};
if (!RegisterClass(&windowClass))
status = GetLastError();
}
{
/* create our window */
"VirtualBoxTool", "VirtualBoxTool",
if (!gToolWindow)
status = GetLastError();
else
{
/* move the window beneach the mouse pointer so that we get access to it */
/* change the mouse pointer so that we can go for a hardware shape */
/* move back our tool window */
}
}
{
{
return;
}
/* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore */
if (!ret)
if (GetVersionEx(&info))
{
dprintf(("VBoxService: Windows version major %d minor %d\n", info.dwMajorVersion, info.dwMinorVersion));
}
/* For Vista and up we need to change the integrity of the security descriptor too */
if (dwMajorVersion >= 6)
{
BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR *SecurityDescriptor, PULONG SecurityDescriptorSize);
if (hModule)
{
*(uintptr_t *)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA = (uintptr_t)GetProcAddress(hModule, "ConvertStringSecurityDescriptorToSecurityDescriptorA");
dprintf(("pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %x\n", pfnConvertStringSecurityDescriptorToSecurityDescriptorA));
{
ret = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
if (!ret)
if (!ret)
if (!ret)
}
}
}
if (ghSeamlessNotifyEvent == NULL)
{
return;
}
}
/*
* Start services listed in the vboxServiceTable.
*/
{
if (VBOX_FAILURE (rc))
{
}
}
/* terminate service if something went wrong */
{
return;
}
BOOL fTrayIconCreated = false;
/* prepare the system tray icon */
sprintf(ndata.szTip, "innotek VirtualBox Guest Additions %d.%d.%d", VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD);
/* Boost thread priority to make sure we wake up early for seamless window notifications (not sure if it actually makes any difference though) */
/*
* Main execution loop
* Wait for the stop semaphore to be posted or a window event to arrive
*/
while(true)
{
if (waitResult == WAIT_OBJECT_0)
{
dprintf(("VBoxService: exit\n"));
/* exit */
break;
}
else
{
/* seamless window notification */
}
else
{
/* timeout or a window message, handle it */
{
{
dprintf(("VBoxService: WM_QUIT!\n"));
continue;
}
}
/* we might have to repeat this operation because the shell might not be loaded yet */
if (!fTrayIconCreated)
{
}
}
}
dprintf(("VBoxService: returned from main loop, exiting...\n"));
/* remove the system tray icon */
dprintf(("VBoxService: waiting for display change thread...\n"));
dprintf(("VBoxService: destroying tool window...\n"));
/* destroy the tool window */
dprintf(("VBoxService: leaving service main function\n"));
return;
}
/**
* Main function
*/
{
dprintf(("VBoxService: WinMain\n"));
VBoxServiceStart ();
return 0;
}
/**
* Window procedure for our tool window
*/
{
switch (msg)
{
case WM_CLOSE:
break;
case WM_DESTROY:
break;
break;
break;
case WM_VBOX_SEAMLESS_UPDATE:
break;
case WM_VBOX_RESTORED:
break;
case WM_VBOX_CHECK_VRDP:
break;
default:
}
return 0;
}