1 | /* $Id: VBoxServiceInternal.h 29040 2010-05-04 20:09:03Z 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 | #include <iprt/list.h>
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * A service descriptor.
|
---|
32 | */
|
---|
33 | typedef struct
|
---|
34 | {
|
---|
35 | /** The short service name. */
|
---|
36 | const char *pszName;
|
---|
37 | /** The longer service name. */
|
---|
38 | const char *pszDescription;
|
---|
39 | /** The usage options stuff for the --help screen. */
|
---|
40 | const char *pszUsage;
|
---|
41 | /** The option descriptions for the --help screen. */
|
---|
42 | const char *pszOptions;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Called before parsing arguments.
|
---|
46 | * @returns VBox status code.
|
---|
47 | */
|
---|
48 | DECLCALLBACKMEMBER(int, pfnPreInit)(void);
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Tries to parse the given command line option.
|
---|
52 | *
|
---|
53 | * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
|
---|
54 | * @param ppszShort If not NULL it points to the short option iterator. a short argument.
|
---|
55 | * If NULL examine argv[*pi].
|
---|
56 | * @param argc The argument count.
|
---|
57 | * @param argv The argument vector.
|
---|
58 | * @param pi The argument vector index. Update if any value(s) are eaten.
|
---|
59 | */
|
---|
60 | DECLCALLBACKMEMBER(int, pfnOption)(const char **ppszShort, int argc, char **argv, int *pi);
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Called before parsing arguments.
|
---|
64 | * @returns VBox status code.
|
---|
65 | */
|
---|
66 | DECLCALLBACKMEMBER(int, pfnInit)(void);
|
---|
67 |
|
---|
68 | /** Called from the worker thread.
|
---|
69 | *
|
---|
70 | * @returns VBox status code.
|
---|
71 | * @retval VINF_SUCCESS if exitting because *pfTerminate was set.
|
---|
72 | * @param pfTerminate Pointer to a per service termination flag to check
|
---|
73 | * before and after blocking.
|
---|
74 | */
|
---|
75 | DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Stop an service.
|
---|
79 | */
|
---|
80 | DECLCALLBACKMEMBER(void, pfnStop)(void);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Does termination cleanups.
|
---|
84 | *
|
---|
85 | * @remarks This may be called even if pfnInit hasn't been called!
|
---|
86 | */
|
---|
87 | DECLCALLBACKMEMBER(void, pfnTerm)(void);
|
---|
88 | } VBOXSERVICE;
|
---|
89 | /** Pointer to a VBOXSERVICE. */
|
---|
90 | typedef VBOXSERVICE *PVBOXSERVICE;
|
---|
91 | /** Pointer to a const VBOXSERVICE. */
|
---|
92 | typedef VBOXSERVICE const *PCVBOXSERVICE;
|
---|
93 |
|
---|
94 | #ifdef RT_OS_WINDOWS
|
---|
95 |
|
---|
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. */
|
---|
105 | typedef 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. */
|
---|
112 | typedef struct
|
---|
113 | {
|
---|
114 | char *pszFilePath;
|
---|
115 | char *pszFileName;
|
---|
116 | } VBOXSERVICEVMINFOFILE, *PVBOXSERVICEVMINFOFILE;
|
---|
117 | /** Structure for process information lookup. */
|
---|
118 | typedef struct
|
---|
119 | {
|
---|
120 | DWORD id;
|
---|
121 | LUID luid;
|
---|
122 | } VBOXSERVICEVMINFOPROC, *PVBOXSERVICEVMINFOPROC;
|
---|
123 | /** Function prototypes for dynamic loading. */
|
---|
124 | typedef DWORD (WINAPI *PFNWTSGETACTIVECONSOLESESSIONID)(void);
|
---|
125 |
|
---|
126 | #endif /* RT_OS_WINDOWS */
|
---|
127 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
128 |
|
---|
129 | enum VBOXSERVICECTRLTHREADDATATYPE
|
---|
130 | {
|
---|
131 | VBoxServiceCtrlThreadDataUnknown = 0,
|
---|
132 | VBoxServiceCtrlThreadDataExec = 1
|
---|
133 | };
|
---|
134 |
|
---|
135 | typedef struct
|
---|
136 | {
|
---|
137 | uint8_t *pbData;
|
---|
138 | uint32_t cbSize;
|
---|
139 | uint32_t cbOffset;
|
---|
140 | uint32_t cbRead;
|
---|
141 | RTCRITSECT CritSect;
|
---|
142 | } VBOXSERVICECTRLEXECPIPEBUF;
|
---|
143 | /** Pointer to thread data. */
|
---|
144 | typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
|
---|
145 |
|
---|
146 | /* Structure for holding guest exection relevant data. */
|
---|
147 | typedef struct
|
---|
148 | {
|
---|
149 | uint32_t uPID;
|
---|
150 | char *pszCmd;
|
---|
151 | uint32_t uFlags;
|
---|
152 | char **papszArgs;
|
---|
153 | uint32_t uNumArgs;
|
---|
154 | char **papszEnv;
|
---|
155 | uint32_t uNumEnvVars;
|
---|
156 | char *pszStdIn;
|
---|
157 | char *pszStdOut;
|
---|
158 | char *pszStdErr;
|
---|
159 | char *pszUser;
|
---|
160 | char *pszPassword;
|
---|
161 | uint32_t uTimeLimitMS;
|
---|
162 |
|
---|
163 | VBOXSERVICECTRLEXECPIPEBUF stdOut;
|
---|
164 | VBOXSERVICECTRLEXECPIPEBUF stdErr;
|
---|
165 |
|
---|
166 | } VBOXSERVICECTRLTHREADDATAEXEC;
|
---|
167 | /** Pointer to thread data. */
|
---|
168 | typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
|
---|
169 |
|
---|
170 | /* Structure for holding thread relevant data. */
|
---|
171 | typedef struct VBOXSERVICECTRLTHREAD
|
---|
172 | {
|
---|
173 | /** Node. */
|
---|
174 | RTLISTNODE Node;
|
---|
175 | /** The worker thread. */
|
---|
176 | RTTHREAD Thread;
|
---|
177 | /** Shutdown indicator. */
|
---|
178 | bool volatile fShutdown;
|
---|
179 | /** Indicator set by the service thread exiting. */
|
---|
180 | bool volatile fStopped;
|
---|
181 | /** Whether the service was started or not. */
|
---|
182 | bool fStarted;
|
---|
183 | /** Client ID. */
|
---|
184 | uint32_t uClientID;
|
---|
185 | /** Context ID. */
|
---|
186 | uint32_t uContextID;
|
---|
187 | /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
|
---|
188 | VBOXSERVICECTRLTHREADDATATYPE enmType;
|
---|
189 | /** Pointer to actual thread data, depending on enmType. */
|
---|
190 | void *pvData;
|
---|
191 | } VBOXSERVICECTRLTHREAD;
|
---|
192 | /** Pointer to thread data. */
|
---|
193 | typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * For buffering process input supplied by the client.
|
---|
197 | */
|
---|
198 | typedef struct VBOXSERVICECTRLSTDINBUF
|
---|
199 | {
|
---|
200 | /** The mount of buffered data. */
|
---|
201 | size_t cb;
|
---|
202 | /** The current data offset. */
|
---|
203 | size_t off;
|
---|
204 | /** The data buffer. */
|
---|
205 | char *pch;
|
---|
206 | /** The amount of allocated buffer space. */
|
---|
207 | size_t cbAllocated;
|
---|
208 | /** Send further input into the bit bucket (stdin is dead). */
|
---|
209 | bool fBitBucket;
|
---|
210 | /** The CRC-32 for standard input (received part). */
|
---|
211 | uint32_t uCrc32;
|
---|
212 | } VBOXSERVICECTRLSTDINBUF;
|
---|
213 | /** Pointer to a standard input buffer. */
|
---|
214 | typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
|
---|
215 |
|
---|
216 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
217 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * A guest property cache.
|
---|
221 | */
|
---|
222 | typedef struct VBOXSERVICEVEPROPCACHE
|
---|
223 | {
|
---|
224 | /** The client ID for HGCM communication. */
|
---|
225 | uint32_t uClientID;
|
---|
226 | /** List of VBOXSERVICEVEPROPCACHEENTRY nodes. */
|
---|
227 | RTLISTNODE ListEntries;
|
---|
228 | /** Critical section for thread-safe use. */
|
---|
229 | RTCRITSECT CritSect;
|
---|
230 | } VBOXSERVICEVEPROPCACHE;
|
---|
231 | /** Pointer to a guest property cache. */
|
---|
232 | typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
|
---|
236 | */
|
---|
237 | typedef struct VBOXSERVICEVEPROPCACHEENTRY
|
---|
238 | {
|
---|
239 | /** Node. */
|
---|
240 | RTLISTNODE Node;
|
---|
241 | /** Name (and full path) of guest property. */
|
---|
242 | char *pszName;
|
---|
243 | /** The last value stored (for reference). */
|
---|
244 | char *pszValue;
|
---|
245 | /** Reset value to write if property is temporary. If NULL, it will be
|
---|
246 | * deleted. */
|
---|
247 | char *pszValueReset;
|
---|
248 | /** Flags. */
|
---|
249 | uint32_t fFlags;
|
---|
250 | } VBOXSERVICEVEPROPCACHEENTRY;
|
---|
251 | /** Pointer to a cached guest property. */
|
---|
252 | typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
|
---|
253 |
|
---|
254 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
255 |
|
---|
256 | RT_C_DECLS_BEGIN
|
---|
257 |
|
---|
258 | extern char *g_pszProgName;
|
---|
259 | extern int g_cVerbosity;
|
---|
260 | extern uint32_t g_DefaultInterval;
|
---|
261 |
|
---|
262 | extern int VBoxServiceSyntax(const char *pszFormat, ...);
|
---|
263 | extern int VBoxServiceError(const char *pszFormat, ...);
|
---|
264 | extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
|
---|
265 | extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);
|
---|
266 | extern unsigned VBoxServiceGetStartedServices(void);
|
---|
267 | extern int VBoxServiceStartServices(unsigned iMain);
|
---|
268 | extern int VBoxServiceStopServices(void);
|
---|
269 |
|
---|
270 | extern VBOXSERVICE g_TimeSync;
|
---|
271 | extern VBOXSERVICE g_Clipboard;
|
---|
272 | extern VBOXSERVICE g_Control;
|
---|
273 | extern VBOXSERVICE g_VMInfo;
|
---|
274 | extern VBOXSERVICE g_Exec;
|
---|
275 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
276 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
277 | extern VBOXSERVICE g_MemBalloon;
|
---|
278 | extern VBOXSERVICE g_VMStatistics;
|
---|
279 | #endif
|
---|
280 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
281 | extern VBOXSERVICE g_PageSharing;
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | #ifdef RT_OS_WINDOWS
|
---|
285 | extern DWORD g_rcWinService;
|
---|
286 | extern SERVICE_TABLE_ENTRY const g_aServiceTable[]; /** @todo generate on the fly, see comment in main() from the enabled sub services. */
|
---|
287 | extern PFNWTSGETACTIVECONSOLESESSIONID g_pfnWTSGetActiveConsoleSessionId; /* VBoxServiceVMInfo-win.cpp */
|
---|
288 |
|
---|
289 | extern int VBoxServiceWinInstall(void);
|
---|
290 | extern int VBoxServiceWinUninstall(void);
|
---|
291 | extern BOOL VBoxServiceWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint);
|
---|
292 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
293 | extern bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
|
---|
294 | extern bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);
|
---|
295 | extern int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);
|
---|
296 | extern void VBoxServiceVMInfoWinProcessesFree(PVBOXSERVICEVMINFOPROC paProcs);
|
---|
297 | extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
|
---|
298 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
299 | #endif /* RT_OS_WINDOWS */
|
---|
300 |
|
---|
301 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
302 | extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
|
---|
303 | const char *pszArgs, uint32_t uNumArgs,
|
---|
304 | const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
|
---|
305 | const char *pszStdIn, const char *pszStdOut, const char *pszStdErr,
|
---|
306 | const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
|
---|
307 | extern void VBoxServiceControlExecDestroyThreadData(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
|
---|
308 | extern int VBoxServiceControlExecReadPipeBufferContent(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
|
---|
309 | uint8_t *pbBuffer, uint32_t cbBuffer, uint32_t *pcbToRead);
|
---|
310 | extern int VBoxServiceControlExecWritePipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
|
---|
311 | uint8_t *pbData, uint32_t cbData);
|
---|
312 | #endif
|
---|
313 |
|
---|
314 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
315 | extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
|
---|
316 | #endif
|
---|
317 |
|
---|
318 | RT_C_DECLS_END
|
---|
319 |
|
---|
320 | #endif
|
---|
321 |
|
---|