VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h@ 28800

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
1/* $Id: VBoxServiceInternal.h 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VBoxService - Guest Additions Services.
4 */
5
6/*
7 * Copyright (C) 2007-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___VBoxServiceInternal_h
19#define ___VBoxServiceInternal_h
20
21#include <stdio.h>
22#ifdef RT_OS_WINDOWS
23# include <Windows.h>
24# include <process.h> /* Needed for file version information. */
25#endif
26
27#ifdef VBOX_WITH_GUEST_CONTROL
28# include <iprt/list.h>
29#endif
30
31/**
32 * A service descriptor.
33 */
34typedef struct
35{
36 /** The short service name. */
37 const char *pszName;
38 /** The longer service name. */
39 const char *pszDescription;
40 /** The usage options stuff for the --help screen. */
41 const char *pszUsage;
42 /** The option descriptions for the --help screen. */
43 const char *pszOptions;
44
45 /**
46 * Called before parsing arguments.
47 * @returns VBox status code.
48 */
49 DECLCALLBACKMEMBER(int, pfnPreInit)(void);
50
51 /**
52 * Tries to parse the given command line option.
53 *
54 * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
55 * @param ppszShort If not NULL it points to the short option iterator. a short argument.
56 * If NULL examine argv[*pi].
57 * @param argc The argument count.
58 * @param argv The argument vector.
59 * @param pi The argument vector index. Update if any value(s) are eaten.
60 */
61 DECLCALLBACKMEMBER(int, pfnOption)(const char **ppszShort, int argc, char **argv, int *pi);
62
63 /**
64 * Called before parsing arguments.
65 * @returns VBox status code.
66 */
67 DECLCALLBACKMEMBER(int, pfnInit)(void);
68
69 /** Called from the worker thread.
70 *
71 * @returns VBox status code.
72 * @retval VINF_SUCCESS if exitting because *pfTerminate was set.
73 * @param pfTerminate Pointer to a per service termination flag to check
74 * before and after blocking.
75 */
76 DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
77
78 /**
79 * Stop an service.
80 */
81 DECLCALLBACKMEMBER(void, pfnStop)(void);
82
83 /**
84 * Does termination cleanups.
85 *
86 * @remarks This may be called even if pfnInit hasn't been called!
87 */
88 DECLCALLBACKMEMBER(void, pfnTerm)(void);
89} VBOXSERVICE;
90/** Pointer to a VBOXSERVICE. */
91typedef VBOXSERVICE *PVBOXSERVICE;
92/** Pointer to a const VBOXSERVICE. */
93typedef VBOXSERVICE const *PCVBOXSERVICE;
94
95#ifdef RT_OS_WINDOWS
96/** The service name (needed for mutex creation on Windows). */
97# define VBOXSERVICE_NAME "VBoxService"
98/** The friendly service name. */
99# define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
100/** The service description (only W2K+ atm) */
101# define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, remote sysprep execution and miscellaneous utilities for guest operating systems."
102/** The following constant may be defined by including NtStatus.h. */
103# define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
104/** Structure for storing the looked up user information. */
105typedef struct
106{
107 WCHAR wszUser[_MAX_PATH];
108 WCHAR wszAuthenticationPackage[_MAX_PATH];
109 WCHAR wszLogonDomain[_MAX_PATH];
110} VBOXSERVICEVMINFOUSER, *PVBOXSERVICEVMINFOUSER;
111/** Structure for the file information lookup. */
112typedef struct
113{
114 char *pszFilePath;
115 char *pszFileName;
116} VBOXSERVICEVMINFOFILE, *PVBOXSERVICEVMINFOFILE;
117/** Structure for process information lookup. */
118typedef struct
119{
120 DWORD id;
121 LUID luid;
122} VBOXSERVICEVMINFOPROC, *PVBOXSERVICEVMINFOPROC;
123/** Function prototypes for dynamic loading. */
124typedef DWORD (WINAPI *PFNWTSGETACTIVECONSOLESESSIONID)(void);
125#endif /* RT_OS_WINDOWS */
126
127#ifdef VBOX_WITH_GUEST_CONTROL
128enum VBOXSERVICECTRLTHREADDATATYPE
129{
130 VBoxServiceCtrlThreadDataUnknown = 0,
131 VBoxServiceCtrlThreadDataExec = 1
132};
133
134typedef struct
135{
136 uint8_t *pbData;
137 uint32_t cbSize;
138 uint32_t cbOffset;
139 uint32_t cbRead;
140} VBOXSERVICECTRLEXECPIPEBUF;
141/** Pointer to thread data. */
142typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
143
144/* Structure for holding guest exection relevant data. */
145typedef struct
146{
147 uint32_t uPID;
148 char *pszCmd;
149 uint32_t uFlags;
150 char **papszArgs;
151 uint32_t uNumArgs;
152 char **papszEnv;
153 uint32_t uNumEnvVars;
154 char *pszStdIn;
155 char *pszStdOut;
156 char *pszStdErr;
157 char *pszUser;
158 char *pszPassword;
159 uint32_t uTimeLimitMS;
160
161 VBOXSERVICECTRLEXECPIPEBUF stdOut;
162 VBOXSERVICECTRLEXECPIPEBUF stdErr;
163
164} VBOXSERVICECTRLTHREADDATAEXEC;
165/** Pointer to thread data. */
166typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
167
168/* Structure for holding thread relevant data. */
169typedef struct
170{
171 /** Node. */
172 RTLISTNODE Node;
173 /** The worker thread. */
174 RTTHREAD Thread;
175 /** Shutdown indicator. */
176 bool volatile fShutdown;
177 /** Indicator set by the service thread exiting. */
178 bool volatile fStopped;
179 /** Whether the service was started or not. */
180 bool fStarted;
181 /** Client ID. */
182 uint32_t uClientID;
183 /** Context ID. */
184 uint32_t uContextID;
185 /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
186 VBOXSERVICECTRLTHREADDATATYPE enmType;
187 /** Pointer to actual thread data, depending on enmType. */
188 void *pvData;
189} VBOXSERVICECTRLTHREAD;
190/** Pointer to thread data. */
191typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
192
193/**
194 * For buffering process input supplied by the client.
195 */
196typedef struct
197{
198 /** The mount of buffered data. */
199 size_t cb;
200 /** The current data offset. */
201 size_t off;
202 /** The data buffer. */
203 char *pch;
204 /** The amount of allocated buffer space. */
205 size_t cbAllocated;
206 /** Send further input into the bit bucket (stdin is dead). */
207 bool fBitBucket;
208 /** The CRC-32 for standard input (received part). */
209 uint32_t uCrc32;
210} VBOXSERVICECTRLSTDINBUF;
211/** Pointer to a standard input buffer. */
212typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
213#endif
214
215RT_C_DECLS_BEGIN
216
217extern char *g_pszProgName;
218extern int g_cVerbosity;
219extern uint32_t g_DefaultInterval;
220
221extern int VBoxServiceSyntax(const char *pszFormat, ...);
222extern int VBoxServiceError(const char *pszFormat, ...);
223extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
224extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);
225extern unsigned VBoxServiceGetStartedServices(void);
226extern int VBoxServiceStartServices(unsigned iMain);
227extern int VBoxServiceStopServices(void);
228
229extern VBOXSERVICE g_TimeSync;
230extern VBOXSERVICE g_Clipboard;
231extern VBOXSERVICE g_Control;
232extern VBOXSERVICE g_VMInfo;
233extern VBOXSERVICE g_Exec;
234extern VBOXSERVICE g_CpuHotPlug;
235#ifdef VBOXSERVICE_MANAGEMENT
236extern VBOXSERVICE g_MemBalloon;
237extern VBOXSERVICE g_VMStatistics;
238#endif
239#ifdef VBOX_WITH_PAGE_SHARING
240extern VBOXSERVICE g_PageSharing;
241#endif
242
243#ifdef RT_OS_WINDOWS
244extern DWORD g_rcWinService;
245extern SERVICE_TABLE_ENTRY const g_aServiceTable[]; /** @todo generate on the fly, see comment in main() from the enabled sub services. */
246extern PFNWTSGETACTIVECONSOLESESSIONID g_pfnWTSGetActiveConsoleSessionId; /* VBoxServiceVMInfo-win.cpp */
247
248extern int VBoxServiceWinInstall(void);
249extern int VBoxServiceWinUninstall(void);
250extern BOOL VBoxServiceWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint);
251# ifdef VBOX_WITH_GUEST_PROPS
252extern bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
253extern bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);
254extern int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);
255extern void VBoxServiceVMInfoWinProcessesFree(PVBOXSERVICEVMINFOPROC paProcs);
256extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
257# endif /* VBOX_WITH_GUEST_PROPS */
258#endif /* RT_OS_WINDOWS */
259
260#ifdef VBOX_WITH_GUEST_CONTROL
261extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
262 const char *pszArgs, uint32_t uNumArgs,
263 const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
264 const char *pszStdIn, const char *pszStdOut, const char *pszStdErr,
265 const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
266extern void VBoxServiceControlExecDestroyThreadData(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
267extern int VBoxServiceControlExecReadPipeBufferContent(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
268 uint8_t *pbBuffer, uint32_t cbBuffer, uint32_t *pcbToRead);
269extern int VBoxServiceControlExecWritePipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
270 uint8_t *pbData, uint32_t cbData);
271#endif
272
273#ifdef VBOXSERVICE_MANAGEMENT
274extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
275#endif
276
277RT_C_DECLS_END
278
279#endif
280
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette