1 | /* $Id: VBoxServiceInternal.h 28968 2010-05-03 11:47:26Z 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 | # include <iprt/semaphore.h>
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * A service descriptor.
|
---|
34 | */
|
---|
35 | typedef struct
|
---|
36 | {
|
---|
37 | /** The short service name. */
|
---|
38 | const char *pszName;
|
---|
39 | /** The longer service name. */
|
---|
40 | const char *pszDescription;
|
---|
41 | /** The usage options stuff for the --help screen. */
|
---|
42 | const char *pszUsage;
|
---|
43 | /** The option descriptions for the --help screen. */
|
---|
44 | const char *pszOptions;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Called before parsing arguments.
|
---|
48 | * @returns VBox status code.
|
---|
49 | */
|
---|
50 | DECLCALLBACKMEMBER(int, pfnPreInit)(void);
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Tries to parse the given command line option.
|
---|
54 | *
|
---|
55 | * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
|
---|
56 | * @param ppszShort If not NULL it points to the short option iterator. a short argument.
|
---|
57 | * If NULL examine argv[*pi].
|
---|
58 | * @param argc The argument count.
|
---|
59 | * @param argv The argument vector.
|
---|
60 | * @param pi The argument vector index. Update if any value(s) are eaten.
|
---|
61 | */
|
---|
62 | DECLCALLBACKMEMBER(int, pfnOption)(const char **ppszShort, int argc, char **argv, int *pi);
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Called before parsing arguments.
|
---|
66 | * @returns VBox status code.
|
---|
67 | */
|
---|
68 | DECLCALLBACKMEMBER(int, pfnInit)(void);
|
---|
69 |
|
---|
70 | /** Called from the worker thread.
|
---|
71 | *
|
---|
72 | * @returns VBox status code.
|
---|
73 | * @retval VINF_SUCCESS if exitting because *pfTerminate was set.
|
---|
74 | * @param pfTerminate Pointer to a per service termination flag to check
|
---|
75 | * before and after blocking.
|
---|
76 | */
|
---|
77 | DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Stop an service.
|
---|
81 | */
|
---|
82 | DECLCALLBACKMEMBER(void, pfnStop)(void);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Does termination cleanups.
|
---|
86 | *
|
---|
87 | * @remarks This may be called even if pfnInit hasn't been called!
|
---|
88 | */
|
---|
89 | DECLCALLBACKMEMBER(void, pfnTerm)(void);
|
---|
90 | } VBOXSERVICE;
|
---|
91 | /** Pointer to a VBOXSERVICE. */
|
---|
92 | typedef VBOXSERVICE *PVBOXSERVICE;
|
---|
93 | /** Pointer to a const VBOXSERVICE. */
|
---|
94 | typedef VBOXSERVICE const *PCVBOXSERVICE;
|
---|
95 |
|
---|
96 | #ifdef RT_OS_WINDOWS
|
---|
97 | /** The service name (needed for mutex creation on Windows). */
|
---|
98 | # define VBOXSERVICE_NAME "VBoxService"
|
---|
99 | /** The friendly service name. */
|
---|
100 | # define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
|
---|
101 | /** The service description (only W2K+ atm) */
|
---|
102 | # define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, remote sysprep execution and miscellaneous utilities for guest operating systems."
|
---|
103 | /** The following constant may be defined by including NtStatus.h. */
|
---|
104 | # define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
|
---|
105 | /** Structure for storing the looked up user information. */
|
---|
106 | typedef struct
|
---|
107 | {
|
---|
108 | WCHAR wszUser[_MAX_PATH];
|
---|
109 | WCHAR wszAuthenticationPackage[_MAX_PATH];
|
---|
110 | WCHAR wszLogonDomain[_MAX_PATH];
|
---|
111 | } VBOXSERVICEVMINFOUSER, *PVBOXSERVICEVMINFOUSER;
|
---|
112 | /** Structure for the file information lookup. */
|
---|
113 | typedef struct
|
---|
114 | {
|
---|
115 | char *pszFilePath;
|
---|
116 | char *pszFileName;
|
---|
117 | } VBOXSERVICEVMINFOFILE, *PVBOXSERVICEVMINFOFILE;
|
---|
118 | /** Structure for process information lookup. */
|
---|
119 | typedef struct
|
---|
120 | {
|
---|
121 | DWORD id;
|
---|
122 | LUID luid;
|
---|
123 | } VBOXSERVICEVMINFOPROC, *PVBOXSERVICEVMINFOPROC;
|
---|
124 | /** Function prototypes for dynamic loading. */
|
---|
125 | typedef DWORD (WINAPI *PFNWTSGETACTIVECONSOLESESSIONID)(void);
|
---|
126 | #endif /* RT_OS_WINDOWS */
|
---|
127 |
|
---|
128 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
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 | RTSEMMUTEX mtx;
|
---|
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
|
---|
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
|
---|
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 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
216 |
|
---|
217 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
218 | /**
|
---|
219 | * A guest property cache.
|
---|
220 | */
|
---|
221 | typedef struct
|
---|
222 | {
|
---|
223 | /** The client ID for HGCM communication. */
|
---|
224 | uint32_t uClientID;
|
---|
225 | RTLISTNODE Node;
|
---|
226 | } VBOXSERVICEVEPROPCACHE;
|
---|
227 | /** Pointer to a guest property cache. */
|
---|
228 | typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Handling guest properties used by the VM information service.
|
---|
232 | */
|
---|
233 | typedef struct
|
---|
234 | {
|
---|
235 | /** Node. */
|
---|
236 | RTLISTNODE Node;
|
---|
237 | /** Name (and full path) of guest property. */
|
---|
238 | char *pszName;
|
---|
239 | /** The last value stored (for reference). */
|
---|
240 | char *pszValue;
|
---|
241 | /** Reset value to write if property is temporary. */
|
---|
242 | char *pszValueReset;
|
---|
243 | /** Flags. */
|
---|
244 | uint32_t uFlags;
|
---|
245 | } VBOXSERVICEVEPROPCACHEENTRY;
|
---|
246 | /** Pointer to a cached guest property. */
|
---|
247 | typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
|
---|
248 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
249 |
|
---|
250 | RT_C_DECLS_BEGIN
|
---|
251 |
|
---|
252 | extern char *g_pszProgName;
|
---|
253 | extern int g_cVerbosity;
|
---|
254 | extern uint32_t g_DefaultInterval;
|
---|
255 |
|
---|
256 | extern int VBoxServiceSyntax(const char *pszFormat, ...);
|
---|
257 | extern int VBoxServiceError(const char *pszFormat, ...);
|
---|
258 | extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
|
---|
259 | extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);
|
---|
260 | extern unsigned VBoxServiceGetStartedServices(void);
|
---|
261 | extern int VBoxServiceStartServices(unsigned iMain);
|
---|
262 | extern int VBoxServiceStopServices(void);
|
---|
263 |
|
---|
264 | extern VBOXSERVICE g_TimeSync;
|
---|
265 | extern VBOXSERVICE g_Clipboard;
|
---|
266 | extern VBOXSERVICE g_Control;
|
---|
267 | extern VBOXSERVICE g_VMInfo;
|
---|
268 | extern VBOXSERVICE g_Exec;
|
---|
269 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
270 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
271 | extern VBOXSERVICE g_MemBalloon;
|
---|
272 | extern VBOXSERVICE g_VMStatistics;
|
---|
273 | #endif
|
---|
274 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
275 | extern VBOXSERVICE g_PageSharing;
|
---|
276 | #endif
|
---|
277 |
|
---|
278 | #ifdef RT_OS_WINDOWS
|
---|
279 | extern DWORD g_rcWinService;
|
---|
280 | extern SERVICE_TABLE_ENTRY const g_aServiceTable[]; /** @todo generate on the fly, see comment in main() from the enabled sub services. */
|
---|
281 | extern PFNWTSGETACTIVECONSOLESESSIONID g_pfnWTSGetActiveConsoleSessionId; /* VBoxServiceVMInfo-win.cpp */
|
---|
282 |
|
---|
283 | extern int VBoxServiceWinInstall(void);
|
---|
284 | extern int VBoxServiceWinUninstall(void);
|
---|
285 | extern BOOL VBoxServiceWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint);
|
---|
286 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
287 | extern bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
|
---|
288 | extern bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);
|
---|
289 | extern int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);
|
---|
290 | extern void VBoxServiceVMInfoWinProcessesFree(PVBOXSERVICEVMINFOPROC paProcs);
|
---|
291 | extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
|
---|
292 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
293 | #endif /* RT_OS_WINDOWS */
|
---|
294 |
|
---|
295 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
296 | extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
|
---|
297 | const char *pszArgs, uint32_t uNumArgs,
|
---|
298 | const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
|
---|
299 | const char *pszStdIn, const char *pszStdOut, const char *pszStdErr,
|
---|
300 | const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
|
---|
301 | extern void VBoxServiceControlExecDestroyThreadData(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
|
---|
302 | extern int VBoxServiceControlExecReadPipeBufferContent(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
|
---|
303 | uint8_t *pbBuffer, uint32_t cbBuffer, uint32_t *pcbToRead);
|
---|
304 | extern int VBoxServiceControlExecWritePipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
|
---|
305 | uint8_t *pbData, uint32_t cbData);
|
---|
306 | #endif
|
---|
307 |
|
---|
308 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
309 | extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
|
---|
310 | #endif
|
---|
311 |
|
---|
312 | RT_C_DECLS_END
|
---|
313 |
|
---|
314 | #endif
|
---|
315 |
|
---|