1 | /* $Id: VBoxServiceInternal.h 30601 2010-07-05 11:22:54Z 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 |
|
---|
105 | #endif /* RT_OS_WINDOWS */
|
---|
106 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
107 |
|
---|
108 | enum VBOXSERVICECTRLTHREADDATATYPE
|
---|
109 | {
|
---|
110 | VBoxServiceCtrlThreadDataUnknown = 0,
|
---|
111 | VBoxServiceCtrlThreadDataExec = 1
|
---|
112 | };
|
---|
113 |
|
---|
114 | typedef struct
|
---|
115 | {
|
---|
116 | uint8_t *pbData;
|
---|
117 | uint32_t cbSize;
|
---|
118 | uint32_t cbOffset;
|
---|
119 | uint32_t cbRead;
|
---|
120 | RTCRITSECT CritSect;
|
---|
121 | } VBOXSERVICECTRLEXECPIPEBUF;
|
---|
122 | /** Pointer to thread data. */
|
---|
123 | typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
|
---|
124 |
|
---|
125 | /* Structure for holding guest exection relevant data. */
|
---|
126 | typedef struct
|
---|
127 | {
|
---|
128 | uint32_t uPID;
|
---|
129 | char *pszCmd;
|
---|
130 | uint32_t uFlags;
|
---|
131 | char **papszArgs;
|
---|
132 | uint32_t uNumArgs;
|
---|
133 | char **papszEnv;
|
---|
134 | uint32_t uNumEnvVars;
|
---|
135 | char *pszUser;
|
---|
136 | char *pszPassword;
|
---|
137 | uint32_t uTimeLimitMS;
|
---|
138 |
|
---|
139 | VBOXSERVICECTRLEXECPIPEBUF stdOut;
|
---|
140 | VBOXSERVICECTRLEXECPIPEBUF stdErr;
|
---|
141 |
|
---|
142 | } VBOXSERVICECTRLTHREADDATAEXEC;
|
---|
143 | /** Pointer to thread data. */
|
---|
144 | typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
|
---|
145 |
|
---|
146 | /* Structure for holding thread relevant data. */
|
---|
147 | typedef struct VBOXSERVICECTRLTHREAD
|
---|
148 | {
|
---|
149 | /** Node. */
|
---|
150 | RTLISTNODE Node;
|
---|
151 | /** The worker thread. */
|
---|
152 | RTTHREAD Thread;
|
---|
153 | /** Shutdown indicator. */
|
---|
154 | bool volatile fShutdown;
|
---|
155 | /** Indicator set by the service thread exiting. */
|
---|
156 | bool volatile fStopped;
|
---|
157 | /** Whether the service was started or not. */
|
---|
158 | bool fStarted;
|
---|
159 | /** Client ID. */
|
---|
160 | uint32_t uClientID;
|
---|
161 | /** Context ID. */
|
---|
162 | uint32_t uContextID;
|
---|
163 | /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
|
---|
164 | VBOXSERVICECTRLTHREADDATATYPE enmType;
|
---|
165 | /** Pointer to actual thread data, depending on enmType. */
|
---|
166 | void *pvData;
|
---|
167 | } VBOXSERVICECTRLTHREAD;
|
---|
168 | /** Pointer to thread data. */
|
---|
169 | typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * For buffering process input supplied by the client.
|
---|
173 | */
|
---|
174 | typedef struct VBOXSERVICECTRLSTDINBUF
|
---|
175 | {
|
---|
176 | /** The mount of buffered data. */
|
---|
177 | size_t cb;
|
---|
178 | /** The current data offset. */
|
---|
179 | size_t off;
|
---|
180 | /** The data buffer. */
|
---|
181 | char *pch;
|
---|
182 | /** The amount of allocated buffer space. */
|
---|
183 | size_t cbAllocated;
|
---|
184 | /** Send further input into the bit bucket (stdin is dead). */
|
---|
185 | bool fBitBucket;
|
---|
186 | /** The CRC-32 for standard input (received part). */
|
---|
187 | uint32_t uCrc32;
|
---|
188 | } VBOXSERVICECTRLSTDINBUF;
|
---|
189 | /** Pointer to a standard input buffer. */
|
---|
190 | typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
|
---|
191 |
|
---|
192 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
193 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * A guest property cache.
|
---|
197 | */
|
---|
198 | typedef struct VBOXSERVICEVEPROPCACHE
|
---|
199 | {
|
---|
200 | /** The client ID for HGCM communication. */
|
---|
201 | uint32_t uClientID;
|
---|
202 | /** Head in a list of VBOXSERVICEVEPROPCACHEENTRY nodes. */
|
---|
203 | RTLISTNODE NodeHead;
|
---|
204 | /** Critical section for thread-safe use. */
|
---|
205 | RTCRITSECT CritSect;
|
---|
206 | } VBOXSERVICEVEPROPCACHE;
|
---|
207 | /** Pointer to a guest property cache. */
|
---|
208 | typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
|
---|
212 | */
|
---|
213 | typedef struct VBOXSERVICEVEPROPCACHEENTRY
|
---|
214 | {
|
---|
215 | /** Node to successor.
|
---|
216 | * @todo r=bird: This is not really the node to the successor, but
|
---|
217 | * rather the OUR node in the list. If it helps, remember that
|
---|
218 | * its a doubly linked list. */
|
---|
219 | RTLISTNODE NodeSucc;
|
---|
220 | /** Name (and full path) of guest property. */
|
---|
221 | char *pszName;
|
---|
222 | /** The last value stored (for reference). */
|
---|
223 | char *pszValue;
|
---|
224 | /** Reset value to write if property is temporary. If NULL, it will be
|
---|
225 | * deleted. */
|
---|
226 | char *pszValueReset;
|
---|
227 | /** Flags. */
|
---|
228 | uint32_t fFlags;
|
---|
229 | } VBOXSERVICEVEPROPCACHEENTRY;
|
---|
230 | /** Pointer to a cached guest property. */
|
---|
231 | typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
|
---|
232 |
|
---|
233 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
234 |
|
---|
235 | RT_C_DECLS_BEGIN
|
---|
236 |
|
---|
237 | extern char *g_pszProgName;
|
---|
238 | extern int g_cVerbosity;
|
---|
239 | extern uint32_t g_DefaultInterval;
|
---|
240 | extern VBOXSERVICE g_TimeSync;
|
---|
241 | extern VBOXSERVICE g_Clipboard;
|
---|
242 | extern VBOXSERVICE g_Control;
|
---|
243 | extern VBOXSERVICE g_VMInfo;
|
---|
244 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
245 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
246 | extern VBOXSERVICE g_MemBalloon;
|
---|
247 | extern VBOXSERVICE g_VMStatistics;
|
---|
248 | #endif
|
---|
249 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
250 | extern VBOXSERVICE g_PageSharing;
|
---|
251 | #endif
|
---|
252 |
|
---|
253 | extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...);
|
---|
254 | extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...);
|
---|
255 | extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
|
---|
256 | extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
|
---|
257 | uint32_t u32Min, uint32_t u32Max);
|
---|
258 | extern int VBoxServiceStartServices(void);
|
---|
259 | extern int VBoxServiceStopServices(void);
|
---|
260 | extern void VBoxServiceMainWait(void);
|
---|
261 | #ifdef RT_OS_WINDOWS
|
---|
262 | extern RTEXITCODE VBoxServiceWinInstall(void);
|
---|
263 | extern RTEXITCODE VBoxServiceWinUninstall(void);
|
---|
264 | extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void);
|
---|
265 | extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint);
|
---|
266 | #endif
|
---|
267 |
|
---|
268 | #ifdef RT_OS_WINDOWS
|
---|
269 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
270 | extern int VBoxServiceVMInfoWinWriteUsers(char **ppszUserList, uint32_t *pcUsersInList);
|
---|
271 | extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
|
---|
272 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
273 | #endif /* RT_OS_WINDOWS */
|
---|
274 |
|
---|
275 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
276 | extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
|
---|
277 | const char *pszArgs, uint32_t uNumArgs,
|
---|
278 | const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
|
---|
279 | const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
|
---|
280 | extern void VBoxServiceControlExecDestroyThreadData(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
|
---|
281 | extern int VBoxServiceControlExecReadPipeBufferContent(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
|
---|
282 | uint8_t *pbBuffer, uint32_t cbBuffer, uint32_t *pcbToRead);
|
---|
283 | extern int VBoxServiceControlExecWritePipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
|
---|
284 | uint8_t *pbData, uint32_t cbData);
|
---|
285 | #endif
|
---|
286 |
|
---|
287 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
288 | extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
|
---|
289 | #endif
|
---|
290 | #if defined(VBOX_WITH_PAGE_SHARING) && defined(RT_OS_WINDOWS)
|
---|
291 | extern RTEXITCODE VBoxServicePageSharingInitFork(void);
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | RT_C_DECLS_END
|
---|
295 |
|
---|
296 | #endif
|
---|
297 |
|
---|