VBoxServiceInternal.h revision 1bf88a54387e004678654cf5158075f59e3be168
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/* $Id$ */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** @file
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * VBoxService - Guest Additions Services.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2007-2009 Sun Microsystems, Inc.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * available from http://www.virtualbox.org. This file is free software;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * General Public License (GPL) as published by the Free Software
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * additional information or have any questions.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync */
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#ifndef ___VBoxServiceInternal_h
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#define ___VBoxServiceInternal_h
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync#include <stdio.h>
e0778e583cb4a0bdc9bcc48f5957e00a01108388vboxsync#ifdef RT_OS_WINDOWS
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# include <Windows.h>
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync# include <process.h> /* Needed for file version information. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#endif
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/**
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * A service descriptor.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsynctypedef struct
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync{
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync /** The short service name. */
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync const char *pszName;
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync /** The longer service name. */
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync const char *pszDescription;
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /** The usage options stuff for the --help screen. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync const char *pszUsage;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /** The option descriptions for the --help screen. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync const char *pszOptions;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync /**
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * Called before parsing arguments.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * @returns VBox status code.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync DECLCALLBACKMEMBER(int, pfnPreInit)(void);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync /**
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Tries to parse the given command line option.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param ppszShort If not NULL it points to the short option iterator. a short argument.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * If NULL examine argv[*pi].
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param argc The argument count.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param argv The argument vector.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param pi The argument vector index. Update if any value(s) are eaten.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync DECLCALLBACKMEMBER(int, pfnOption)(const char **ppszShort, int argc, char **argv, int *pi);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /**
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Called before parsing arguments.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @returns VBox status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync DECLCALLBACKMEMBER(int, pfnInit)(void);
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync /** Called from the worker thread.
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync *
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync * @returns VBox status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @retval VINF_SUCCESS if exitting because *pfTerminate was set.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param pfTerminate Pointer to a per service termination flag to check
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * before and after blocking.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync /**
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync * Stop an service.
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync */
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync DECLCALLBACKMEMBER(void, pfnStop)(void);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /**
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Does termination cleanups.
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @remarks This may be called even if pfnInit hasn't been called!
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync DECLCALLBACKMEMBER(void, pfnTerm)(void);
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync} VBOXSERVICE;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** Pointer to a VBOXSERVICE. */
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsynctypedef VBOXSERVICE *PVBOXSERVICE;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** Pointer to a const VBOXSERVICE. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsynctypedef VBOXSERVICE const *PCVBOXSERVICE;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync#ifdef RT_OS_WINDOWS
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** The service name (needed for mutex creation on Windows). */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#define VBOXSERVICE_NAME "VBoxService"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The friendly service name. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#define VBOXSERVICE_FRIENDLY_NAME "VBoxService"
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync/** The following constant may be defined by including NtStatus.h. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** Structure for storing the looked up user information. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsynctypedef struct
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync{
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync WCHAR szUser [_MAX_PATH];
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync WCHAR szAuthenticationPackage [_MAX_PATH];
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync WCHAR szLogonDomain [_MAX_PATH];
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsync} VBOXSERVICEVMINFOUSER, *PVBOXSERVICEVMINFOUSER;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** Structure for the file information lookup. */
7c1f498692cd2393f8ba68cb62be482495106f93vboxsynctypedef struct
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync{
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync char* pszFilePath;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync char* pszFileName;
4c8907a420ed66a42f729eb08cddf9c1e57f25eavboxsync} VBOXSERVICEVMINFOFILE, *PVBOXSERVICEVMINFOFILE;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** Function prototypes for dynamic loading. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsynctypedef DWORD (WINAPI* fnWTSGetActiveConsoleSessionId)();
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#endif
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync
66b8ee000e49b0cc08a897451350cd6927d77b60vboxsyncRT_C_DECLS_BEGIN
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern char *g_pszProgName;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern int g_cVerbosity;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncextern uint32_t g_DefaultInterval;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncextern int VBoxServiceSyntax(const char *pszFormat, ...);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern int VBoxServiceError(const char *pszFormat, ...);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncextern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncextern unsigned VBoxServiceGetStartedServices(void);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncextern int VBoxServiceStartServices(unsigned iMain);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern int VBoxServiceStopServices(void);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncextern VBOXSERVICE g_TimeSync;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncextern VBOXSERVICE g_Clipboard;
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncextern VBOXSERVICE g_Control;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern VBOXSERVICE g_VMInfo;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern VBOXSERVICE g_Exec;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#ifdef RT_OS_WINDOWS
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern DWORD g_rcWinService;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern SERVICE_STATUS_HANDLE g_hWinServiceStatus;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncextern SERVICE_TABLE_ENTRY const g_aServiceTable[]; /** @todo generate on the fly, see comment in main() from the enabled sub services. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** Installs the service into the registry. */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncextern int VBoxServiceWinInstall(void);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** Uninstalls the service from the registry. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern int VBoxServiceWinUninstall(void);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#ifdef VBOX_WITH_GUEST_PROPS
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** Detects wheter a user is logged on based on the enumerated processes. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern BOOL VboxServiceVMInfoWinIsLoggedIn(VBOXSERVICEVMINFOUSER* a_pUserInfo,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync PLUID a_pSession,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync PLUID a_pLuid,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync DWORD a_dwNumOfProcLUIDs);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** Gets logon user IDs from enumerated processes. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncextern DWORD VboxServiceVMInfoWinGetLUIDsFromProcesses(PLUID *ppLuid);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#endif /* VBOX_WITH_GUEST_PROPS */
85bc82f92f4d7a7b95e96d133c4847b2847703dfvboxsync#endif /* RT_OS_WINDOWS */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncRT_C_DECLS_END
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync