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