1 | /* $Id: VBoxServiceInternal.h 33540 2010-10-28 09:27:05Z 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 | /** The service name (needed for mutex creation on Windows). */
|
---|
95 | #define VBOXSERVICE_NAME "VBoxService"
|
---|
96 |
|
---|
97 | #ifdef RT_OS_WINDOWS
|
---|
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 | #endif /* RT_OS_WINDOWS */
|
---|
105 |
|
---|
106 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
107 | typedef enum VBOXSERVICECTRLTHREADDATATYPE
|
---|
108 | {
|
---|
109 | kVBoxServiceCtrlThreadDataUnknown = 0,
|
---|
110 | kVBoxServiceCtrlThreadDataExec
|
---|
111 | } VBOXSERVICECTRLTHREADDATATYPE;
|
---|
112 |
|
---|
113 | typedef enum VBOXSERVICECTRLPIPEID
|
---|
114 | {
|
---|
115 | VBOXSERVICECTRLPIPEID_STDIN_ERROR = 0,
|
---|
116 | VBOXSERVICECTRLPIPEID_STDIN_WRITABLE,
|
---|
117 | VBOXSERVICECTRLPIPEID_STDIN_INPUT_NOTIFY,
|
---|
118 | VBOXSERVICECTRLPIPEID_STDOUT,
|
---|
119 | VBOXSERVICECTRLPIPEID_STDERR
|
---|
120 | } VBOXSERVICECTRLPIPEID;
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Structure for holding buffered pipe data.
|
---|
124 | */
|
---|
125 | typedef struct
|
---|
126 | {
|
---|
127 | /** The data buffer. */
|
---|
128 | uint8_t *pbData;
|
---|
129 | /** The amount of allocated buffer space. */
|
---|
130 | uint32_t cbAllocated;
|
---|
131 | /** The actual used/occupied buffer space. */
|
---|
132 | uint32_t cbSize;
|
---|
133 | /** Helper variable for keeping track of what
|
---|
134 | * already was processed and what not. */
|
---|
135 | uint32_t cbOffset;
|
---|
136 | /** Critical section protecting this buffer structure. */
|
---|
137 | RTCRITSECT CritSect;
|
---|
138 | /** Indicates the health condition of the child process. */
|
---|
139 | bool fAlive;
|
---|
140 | /** Set if it's necessary to write to the notification pipe. */
|
---|
141 | bool fNeedNotification;
|
---|
142 | /** Set if the pipe needs to be closed after the next read/write. */
|
---|
143 | bool fPendingClose;
|
---|
144 | /** The notification pipe associated with this buffer.
|
---|
145 | * This is NIL_RTPIPE for output pipes. */
|
---|
146 | RTPIPE hNotificationPipeW;
|
---|
147 | /** The other end of hNotificationPipeW. */
|
---|
148 | RTPIPE hNotificationPipeR;
|
---|
149 | } VBOXSERVICECTRLEXECPIPEBUF;
|
---|
150 | /** Pointer to buffered pipe data. */
|
---|
151 | typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Structure for holding guest exection relevant data.
|
---|
155 | */
|
---|
156 | typedef struct
|
---|
157 | {
|
---|
158 | uint32_t uPID;
|
---|
159 | char *pszCmd;
|
---|
160 | uint32_t uFlags;
|
---|
161 | char **papszArgs;
|
---|
162 | uint32_t uNumArgs;
|
---|
163 | char **papszEnv;
|
---|
164 | uint32_t uNumEnvVars;
|
---|
165 | char *pszUser;
|
---|
166 | char *pszPassword;
|
---|
167 | uint32_t uTimeLimitMS;
|
---|
168 |
|
---|
169 | RTPIPE pipeStdInW;
|
---|
170 | VBOXSERVICECTRLEXECPIPEBUF stdIn;
|
---|
171 | VBOXSERVICECTRLEXECPIPEBUF stdOut;
|
---|
172 | VBOXSERVICECTRLEXECPIPEBUF stdErr;
|
---|
173 |
|
---|
174 | } VBOXSERVICECTRLTHREADDATAEXEC;
|
---|
175 | /** Pointer to thread data. */
|
---|
176 | typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
|
---|
177 |
|
---|
178 | /* Structure for holding thread relevant data. */
|
---|
179 | typedef struct VBOXSERVICECTRLTHREAD
|
---|
180 | {
|
---|
181 | /** Node. */
|
---|
182 | RTLISTNODE Node;
|
---|
183 | /** The worker thread. */
|
---|
184 | RTTHREAD Thread;
|
---|
185 | /** Shutdown indicator. */
|
---|
186 | bool volatile fShutdown;
|
---|
187 | /** Indicator set by the service thread exiting. */
|
---|
188 | bool volatile fStopped;
|
---|
189 | /** Whether the service was started or not. */
|
---|
190 | bool fStarted;
|
---|
191 | /** Client ID. */
|
---|
192 | uint32_t uClientID;
|
---|
193 | /** Context ID. */
|
---|
194 | uint32_t uContextID;
|
---|
195 | /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
|
---|
196 | VBOXSERVICECTRLTHREADDATATYPE enmType;
|
---|
197 | /** Pointer to actual thread data, depending on enmType. */
|
---|
198 | void *pvData;
|
---|
199 | } VBOXSERVICECTRLTHREAD;
|
---|
200 | /** Pointer to thread data. */
|
---|
201 | typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
|
---|
202 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
203 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * A guest property cache.
|
---|
207 | */
|
---|
208 | typedef struct VBOXSERVICEVEPROPCACHE
|
---|
209 | {
|
---|
210 | /** The client ID for HGCM communication. */
|
---|
211 | uint32_t uClientID;
|
---|
212 | /** Head in a list of VBOXSERVICEVEPROPCACHEENTRY nodes. */
|
---|
213 | RTLISTNODE NodeHead;
|
---|
214 | /** Critical section for thread-safe use. */
|
---|
215 | RTCRITSECT CritSect;
|
---|
216 | } VBOXSERVICEVEPROPCACHE;
|
---|
217 | /** Pointer to a guest property cache. */
|
---|
218 | typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
|
---|
222 | */
|
---|
223 | typedef struct VBOXSERVICEVEPROPCACHEENTRY
|
---|
224 | {
|
---|
225 | /** Node to successor.
|
---|
226 | * @todo r=bird: This is not really the node to the successor, but
|
---|
227 | * rather the OUR node in the list. If it helps, remember that
|
---|
228 | * its a doubly linked list. */
|
---|
229 | RTLISTNODE NodeSucc;
|
---|
230 | /** Name (and full path) of guest property. */
|
---|
231 | char *pszName;
|
---|
232 | /** The last value stored (for reference). */
|
---|
233 | char *pszValue;
|
---|
234 | /** Reset value to write if property is temporary. If NULL, it will be
|
---|
235 | * deleted. */
|
---|
236 | char *pszValueReset;
|
---|
237 | /** Flags. */
|
---|
238 | uint32_t fFlags;
|
---|
239 | } VBOXSERVICEVEPROPCACHEENTRY;
|
---|
240 | /** Pointer to a cached guest property. */
|
---|
241 | typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
|
---|
242 |
|
---|
243 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
244 |
|
---|
245 | RT_C_DECLS_BEGIN
|
---|
246 |
|
---|
247 | extern char *g_pszProgName;
|
---|
248 | extern int g_cVerbosity;
|
---|
249 | extern uint32_t g_DefaultInterval;
|
---|
250 | extern VBOXSERVICE g_TimeSync;
|
---|
251 | extern VBOXSERVICE g_Clipboard;
|
---|
252 | extern VBOXSERVICE g_Control;
|
---|
253 | extern VBOXSERVICE g_VMInfo;
|
---|
254 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
255 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
256 | extern VBOXSERVICE g_MemBalloon;
|
---|
257 | extern VBOXSERVICE g_VMStatistics;
|
---|
258 | #endif
|
---|
259 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
260 | extern VBOXSERVICE g_PageSharing;
|
---|
261 | #endif
|
---|
262 | #ifdef VBOX_WITH_SHARED_FOLDERS
|
---|
263 | extern VBOXSERVICE g_AutoMount;
|
---|
264 | #endif
|
---|
265 |
|
---|
266 | extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...);
|
---|
267 | extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...);
|
---|
268 | extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
|
---|
269 | extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
|
---|
270 | uint32_t u32Min, uint32_t u32Max);
|
---|
271 | extern int VBoxServiceStartServices(void);
|
---|
272 | extern int VBoxServiceStopServices(void);
|
---|
273 | extern void VBoxServiceMainWait(void);
|
---|
274 | #ifdef RT_OS_WINDOWS
|
---|
275 | extern RTEXITCODE VBoxServiceWinInstall(void);
|
---|
276 | extern RTEXITCODE VBoxServiceWinUninstall(void);
|
---|
277 | extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void);
|
---|
278 | extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint);
|
---|
279 | #endif
|
---|
280 |
|
---|
281 | #ifdef VBOXSERVICE_TOOLBOX
|
---|
282 | extern int VBoxServiceToolboxMain(int argc, char **argv);
|
---|
283 | #endif
|
---|
284 |
|
---|
285 | #ifdef RT_OS_WINDOWS
|
---|
286 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
287 | extern int VBoxServiceVMInfoWinWriteUsers(char **ppszUserList, uint32_t *pcUsersInList);
|
---|
288 | extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
|
---|
289 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
290 | #endif /* RT_OS_WINDOWS */
|
---|
291 |
|
---|
292 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
293 | extern int VBoxServiceControlExecHandleCmdStartProcess(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
294 | extern int VBoxServiceControlExecHandleCmdSetInput(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
295 | extern int VBoxServiceControlExecHandleCmdGetOutput(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
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 *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
|
---|
300 | extern void VBoxServiceControlExecDestroyThreadData(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
|
---|
301 | extern void VBoxServiceControlExecDeletePipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf);
|
---|
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, bool fPendingClose, uint32_t *pcbWritten);
|
---|
306 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
307 |
|
---|
308 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
309 | extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
|
---|
310 | #endif
|
---|
311 | #if defined(VBOX_WITH_PAGE_SHARING) && defined(RT_OS_WINDOWS)
|
---|
312 | extern RTEXITCODE VBoxServicePageSharingInitFork(void);
|
---|
313 | #endif
|
---|
314 |
|
---|
315 | RT_C_DECLS_END
|
---|
316 |
|
---|
317 | #endif
|
---|
318 |
|
---|