1 | /* $Id: VBoxServiceInternal.h 38113 2011-07-22 13:57:35Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxService - Guest Additions Services.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2011 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 | #include <VBox/VBoxGuestLib.h>
|
---|
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 | /** The service name.
|
---|
97 | * @note Used on windows to name the service as well as the global mutex. */
|
---|
98 | #define VBOXSERVICE_NAME "VBoxService"
|
---|
99 |
|
---|
100 | #ifdef RT_OS_WINDOWS
|
---|
101 | /** The friendly service name. */
|
---|
102 | # define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
|
---|
103 | /** The service description (only W2K+ atm) */
|
---|
104 | # define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, guest control execution and miscellaneous utilities for guest operating systems."
|
---|
105 | /** The following constant may be defined by including NtStatus.h. */
|
---|
106 | # define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
|
---|
107 | #endif /* RT_OS_WINDOWS */
|
---|
108 |
|
---|
109 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
110 | typedef enum VBOXSERVICECTRLTHREADDATATYPE
|
---|
111 | {
|
---|
112 | kVBoxServiceCtrlThreadDataUnknown = 0,
|
---|
113 | kVBoxServiceCtrlThreadDataExec
|
---|
114 | } VBOXSERVICECTRLTHREADDATATYPE;
|
---|
115 |
|
---|
116 | typedef enum VBOXSERVICECTRLPIPEID
|
---|
117 | {
|
---|
118 | VBOXSERVICECTRLPIPEID_STDIN = 0,
|
---|
119 | VBOXSERVICECTRLPIPEID_STDIN_ERROR,
|
---|
120 | VBOXSERVICECTRLPIPEID_STDIN_WRITABLE,
|
---|
121 | VBOXSERVICECTRLPIPEID_STDIN_INPUT_NOTIFY,
|
---|
122 | VBOXSERVICECTRLPIPEID_STDOUT,
|
---|
123 | VBOXSERVICECTRLPIPEID_STDERR
|
---|
124 | } VBOXSERVICECTRLPIPEID;
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Structure for holding buffered pipe data.
|
---|
128 | */
|
---|
129 | typedef struct
|
---|
130 | {
|
---|
131 | /** The PID the pipe is assigned to. */
|
---|
132 | uint32_t uPID;
|
---|
133 | /** The pipe's Id of enum VBOXSERVICECTRLPIPEID. */
|
---|
134 | uint8_t uPipeId;
|
---|
135 | /** The data buffer. */
|
---|
136 | uint8_t *pbData;
|
---|
137 | /** The amount of allocated buffer space. */
|
---|
138 | uint32_t cbAllocated;
|
---|
139 | /** The actual used/occupied buffer space. */
|
---|
140 | uint32_t cbSize;
|
---|
141 | /** Helper variable for keeping track of what
|
---|
142 | * already was processed and what not. */
|
---|
143 | uint32_t cbOffset;
|
---|
144 | /** Critical section protecting this buffer structure. */
|
---|
145 | RTCRITSECT CritSect;
|
---|
146 | /** Flag indicating whether this pipe buffer accepts new
|
---|
147 | * data to be written to or not. If not enabled, already
|
---|
148 | * (allocated) buffered data still can be read out. */
|
---|
149 | bool fEnabled;
|
---|
150 | /** Set if it's necessary to write to the notification pipe. */
|
---|
151 | bool fNeedNotification;
|
---|
152 | /** Set if the pipe needs to be closed after the next read/write. */
|
---|
153 | bool fPendingClose;
|
---|
154 | /** The notification pipe associated with this buffer.
|
---|
155 | * This is NIL_RTPIPE for output pipes. */
|
---|
156 | RTPIPE hNotificationPipeW;
|
---|
157 | /** The other end of hNotificationPipeW. */
|
---|
158 | RTPIPE hNotificationPipeR;
|
---|
159 | /** The event semaphore for getting notified whether something
|
---|
160 | * has changed, e.g. written or read from this buffer. */
|
---|
161 | RTSEMEVENT hEventSem;
|
---|
162 | } VBOXSERVICECTRLEXECPIPEBUF;
|
---|
163 | /** Pointer to buffered pipe data. */
|
---|
164 | typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Structure for holding guest exection relevant data.
|
---|
168 | */
|
---|
169 | typedef struct
|
---|
170 | {
|
---|
171 | uint32_t uPID;
|
---|
172 | char *pszCmd;
|
---|
173 | uint32_t uFlags;
|
---|
174 | char **papszArgs;
|
---|
175 | uint32_t uNumArgs;
|
---|
176 | char **papszEnv;
|
---|
177 | uint32_t uNumEnvVars;
|
---|
178 | char *pszUser;
|
---|
179 | char *pszPassword;
|
---|
180 | uint32_t uTimeLimitMS;
|
---|
181 |
|
---|
182 | RTPIPE pipeStdInW;
|
---|
183 | VBOXSERVICECTRLEXECPIPEBUF stdIn;
|
---|
184 | VBOXSERVICECTRLEXECPIPEBUF stdOut;
|
---|
185 | VBOXSERVICECTRLEXECPIPEBUF stdErr;
|
---|
186 |
|
---|
187 | } VBOXSERVICECTRLTHREADDATAEXEC;
|
---|
188 | /** Pointer to thread data. */
|
---|
189 | typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
|
---|
190 |
|
---|
191 | /* Structure for holding thread relevant data. */
|
---|
192 | typedef struct VBOXSERVICECTRLTHREAD
|
---|
193 | {
|
---|
194 | /** Node. */
|
---|
195 | RTLISTNODE Node;
|
---|
196 | /** The worker thread. */
|
---|
197 | RTTHREAD Thread;
|
---|
198 | /** Shutdown indicator. */
|
---|
199 | bool volatile fShutdown;
|
---|
200 | /** Indicator set by the service thread exiting. */
|
---|
201 | bool volatile fStopped;
|
---|
202 | /** Whether the service was started or not. */
|
---|
203 | bool fStarted;
|
---|
204 | /** Client ID. */
|
---|
205 | uint32_t uClientID;
|
---|
206 | /** Context ID. */
|
---|
207 | uint32_t uContextID;
|
---|
208 | /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
|
---|
209 | VBOXSERVICECTRLTHREADDATATYPE enmType;
|
---|
210 | /** Pointer to actual thread data, depending on enmType. */
|
---|
211 | void *pvData;
|
---|
212 | } VBOXSERVICECTRLTHREAD;
|
---|
213 | /** Pointer to thread data. */
|
---|
214 | typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
|
---|
215 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
216 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * A guest property cache.
|
---|
220 | */
|
---|
221 | typedef struct VBOXSERVICEVEPROPCACHE
|
---|
222 | {
|
---|
223 | /** The client ID for HGCM communication. */
|
---|
224 | uint32_t uClientID;
|
---|
225 | /** Head in a list of VBOXSERVICEVEPROPCACHEENTRY nodes. */
|
---|
226 | RTLISTNODE NodeHead;
|
---|
227 | /** Critical section for thread-safe use. */
|
---|
228 | RTCRITSECT CritSect;
|
---|
229 | } VBOXSERVICEVEPROPCACHE;
|
---|
230 | /** Pointer to a guest property cache. */
|
---|
231 | typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
|
---|
235 | */
|
---|
236 | typedef struct VBOXSERVICEVEPROPCACHEENTRY
|
---|
237 | {
|
---|
238 | /** Node to successor.
|
---|
239 | * @todo r=bird: This is not really the node to the successor, but
|
---|
240 | * rather the OUR node in the list. If it helps, remember that
|
---|
241 | * its a doubly linked list. */
|
---|
242 | RTLISTNODE NodeSucc;
|
---|
243 | /** Name (and full path) of guest property. */
|
---|
244 | char *pszName;
|
---|
245 | /** The last value stored (for reference). */
|
---|
246 | char *pszValue;
|
---|
247 | /** Reset value to write if property is temporary. If NULL, it will be
|
---|
248 | * deleted. */
|
---|
249 | char *pszValueReset;
|
---|
250 | /** Flags. */
|
---|
251 | uint32_t fFlags;
|
---|
252 | } VBOXSERVICEVEPROPCACHEENTRY;
|
---|
253 | /** Pointer to a cached guest property. */
|
---|
254 | typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
|
---|
255 |
|
---|
256 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
257 |
|
---|
258 | RT_C_DECLS_BEGIN
|
---|
259 |
|
---|
260 | extern char *g_pszProgName;
|
---|
261 | extern int g_cVerbosity;
|
---|
262 | extern uint32_t g_DefaultInterval;
|
---|
263 | extern VBOXSERVICE g_TimeSync;
|
---|
264 | extern VBOXSERVICE g_Clipboard;
|
---|
265 | extern VBOXSERVICE g_Control;
|
---|
266 | extern VBOXSERVICE g_VMInfo;
|
---|
267 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
268 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
269 | extern VBOXSERVICE g_MemBalloon;
|
---|
270 | extern VBOXSERVICE g_VMStatistics;
|
---|
271 | #endif
|
---|
272 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
273 | extern VBOXSERVICE g_PageSharing;
|
---|
274 | #endif
|
---|
275 | #ifdef VBOX_WITH_SHARED_FOLDERS
|
---|
276 | extern VBOXSERVICE g_AutoMount;
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...);
|
---|
280 | extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...);
|
---|
281 | extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
|
---|
282 | extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
|
---|
283 | uint32_t u32Min, uint32_t u32Max);
|
---|
284 | extern int VBoxServiceStartServices(void);
|
---|
285 | extern int VBoxServiceStopServices(void);
|
---|
286 | extern void VBoxServiceMainWait(void);
|
---|
287 | extern int VBoxServiceReportStatus(VBoxGuestFacilityStatus enmStatus);
|
---|
288 | #ifdef RT_OS_WINDOWS
|
---|
289 | extern RTEXITCODE VBoxServiceWinInstall(void);
|
---|
290 | extern RTEXITCODE VBoxServiceWinUninstall(void);
|
---|
291 | extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void);
|
---|
292 | extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint);
|
---|
293 | #endif
|
---|
294 |
|
---|
295 | #ifdef VBOXSERVICE_TOOLBOX
|
---|
296 | extern bool VBoxServiceToolboxMain(int argc, char **argv, RTEXITCODE *prcExit);
|
---|
297 | #endif
|
---|
298 |
|
---|
299 | #ifdef RT_OS_WINDOWS
|
---|
300 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
301 | extern int VBoxServiceVMInfoWinWriteUsers(char **ppszUserList, uint32_t *pcUsersInList);
|
---|
302 | extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
|
---|
303 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
304 | #endif /* RT_OS_WINDOWS */
|
---|
305 |
|
---|
306 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
307 | extern int VBoxServiceGCtrlDirClose(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
308 | extern int VBoxServiceGCtrlDirOpen(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
309 | extern int VBoxServiceGCtrlDirRead(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
310 |
|
---|
311 | extern int VBoxServiceControlExecHandleCmdStartProcess(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
312 | extern int VBoxServiceControlExecHandleCmdSetInput(uint32_t u32ClientId, uint32_t uNumParms, size_t cbMaxBufSize);
|
---|
313 | extern int VBoxServiceControlExecHandleCmdGetOutput(uint32_t u32ClientId, uint32_t uNumParms);
|
---|
314 | extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
|
---|
315 | const char *pszArgs, uint32_t uNumArgs,
|
---|
316 | const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
|
---|
317 | const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
|
---|
318 | extern void VBoxServiceControlExecThreadDestroy(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
|
---|
319 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
320 |
|
---|
321 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
322 | extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
|
---|
323 | #endif
|
---|
324 | #if defined(VBOX_WITH_PAGE_SHARING) && defined(RT_OS_WINDOWS)
|
---|
325 | extern RTEXITCODE VBoxServicePageSharingInitFork(void);
|
---|
326 | #endif
|
---|
327 |
|
---|
328 | RT_C_DECLS_END
|
---|
329 |
|
---|
330 | #endif
|
---|
331 |
|
---|