1 | /* $Id: VBoxServiceInternal.h 105677 2024-08-14 19:02:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxService - Guest Additions Services.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h
|
---|
29 | #define GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifdef RT_OS_WINDOWS
|
---|
35 | # include <iprt/win/windows.h>
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #include <iprt/list.h>
|
---|
39 | #include <iprt/critsect.h>
|
---|
40 | #include <iprt/path.h> /* RTPATH_MAX */
|
---|
41 | #include <iprt/stdarg.h>
|
---|
42 |
|
---|
43 | #include <VBox/VBoxGuestLib.h>
|
---|
44 | #include <VBox/HostServices/GuestControlSvc.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | #if !defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
|
---|
48 | /** Special argv[1] value that indicates that argv is UTF-8.
|
---|
49 | * This causes RTR3Init to be called with RTR3INIT_FLAGS_UTF8_ARGV and helps
|
---|
50 | * work around potential issues caused by a user's locale config not being
|
---|
51 | * UTF-8. See @bugref{10153}.
|
---|
52 | *
|
---|
53 | * @note We don't need this on windows and it would be harmful to enable it
|
---|
54 | * as the argc/argv vs __argc/__argv comparison would fail and we would
|
---|
55 | * not use the unicode command line to create a UTF-8 argv. Since the
|
---|
56 | * original argv is ANSI, it may be missing codepoints not present in
|
---|
57 | * the ANSI code page of the process. */
|
---|
58 | # define VBOXSERVICE_ARG1_UTF8_ARGV "--utf8-argv"
|
---|
59 | #endif
|
---|
60 | /** RTProcCreateEx flags corresponding to VBOXSERVICE_ARG1_UTF8_ARGV. */
|
---|
61 | #ifdef VBOXSERVICE_ARG1_UTF8_ARGV
|
---|
62 | # define VBOXSERVICE_PROC_F_UTF8_ARGV RTPROC_FLAGS_UTF8_ARGV
|
---|
63 | #else
|
---|
64 | # define VBOXSERVICE_PROC_F_UTF8_ARGV 0
|
---|
65 | #endif
|
---|
66 |
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * A service descriptor.
|
---|
70 | */
|
---|
71 | typedef struct
|
---|
72 | {
|
---|
73 | /** The short service name. */
|
---|
74 | const char *pszName;
|
---|
75 | /** The longer service name. */
|
---|
76 | const char *pszDescription;
|
---|
77 | /** The usage options stuff for the --help screen. */
|
---|
78 | const char *pszUsage;
|
---|
79 | /** The option descriptions for the --help screen. */
|
---|
80 | const char *pszOptions;
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Called before parsing arguments.
|
---|
84 | * @returns VBox status code.
|
---|
85 | */
|
---|
86 | DECLCALLBACKMEMBER(int, pfnPreInit,(void));
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Tries to parse the given command line option.
|
---|
90 | *
|
---|
91 | * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
|
---|
92 | * @param ppszShort If not NULL it points to the short option iterator. a short argument.
|
---|
93 | * If NULL examine argv[*pi].
|
---|
94 | * @param argc The argument count.
|
---|
95 | * @param argv The argument vector.
|
---|
96 | * @param pi The argument vector index. Update if any value(s) are eaten.
|
---|
97 | */
|
---|
98 | DECLCALLBACKMEMBER(int, pfnOption,(const char **ppszShort, int argc, char **argv, int *pi));
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Called before parsing arguments.
|
---|
102 | * @returns VBox status code.
|
---|
103 | */
|
---|
104 | DECLCALLBACKMEMBER(int, pfnInit,(void));
|
---|
105 |
|
---|
106 | /** Called from the worker thread.
|
---|
107 | *
|
---|
108 | * @returns VBox status code.
|
---|
109 | * @retval VINF_SUCCESS if exitting because *pfShutdown was set.
|
---|
110 | * @param pfShutdown Pointer to a per service termination flag to check
|
---|
111 | * before and after blocking.
|
---|
112 | */
|
---|
113 | DECLCALLBACKMEMBER(int, pfnWorker,(bool volatile *pfShutdown));
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Stops a service.
|
---|
117 | */
|
---|
118 | DECLCALLBACKMEMBER(void, pfnStop,(void));
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Does termination cleanups.
|
---|
122 | *
|
---|
123 | * @remarks This may be called even if pfnInit hasn't been called!
|
---|
124 | */
|
---|
125 | DECLCALLBACKMEMBER(void, pfnTerm,(void));
|
---|
126 | } VBOXSERVICE;
|
---|
127 | /** Pointer to a VBOXSERVICE. */
|
---|
128 | typedef VBOXSERVICE *PVBOXSERVICE;
|
---|
129 | /** Pointer to a const VBOXSERVICE. */
|
---|
130 | typedef VBOXSERVICE const *PCVBOXSERVICE;
|
---|
131 |
|
---|
132 | /* Default call-backs for services which do not need special behaviour. */
|
---|
133 | DECLCALLBACK(int) VGSvcDefaultPreInit(void);
|
---|
134 | DECLCALLBACK(int) VGSvcDefaultOption(const char **ppszShort, int argc, char **argv, int *pi);
|
---|
135 | DECLCALLBACK(int) VGSvcDefaultInit(void);
|
---|
136 | DECLCALLBACK(void) VGSvcDefaultTerm(void);
|
---|
137 |
|
---|
138 | /** The service name.
|
---|
139 | * @note Used on windows to name the service as well as the global mutex. */
|
---|
140 | #define VBOXSERVICE_NAME "VBoxService"
|
---|
141 |
|
---|
142 | #ifdef RT_OS_WINDOWS
|
---|
143 | /** The friendly service name. */
|
---|
144 | # define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
|
---|
145 | /** The service description (only W2K+ atm) */
|
---|
146 | # define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, guest control execution and miscellaneous utilities for guest operating systems."
|
---|
147 | /** The following constant may be defined by including NtStatus.h. */
|
---|
148 | # define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
|
---|
149 | #endif /* RT_OS_WINDOWS */
|
---|
150 |
|
---|
151 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
152 | /**
|
---|
153 | * A guest property cache.
|
---|
154 | */
|
---|
155 | typedef struct VBOXSERVICEVEPROPCACHE
|
---|
156 | {
|
---|
157 | /** The client ID for HGCM communication. */
|
---|
158 | uint32_t uClientID;
|
---|
159 | /** Head in a list of VBOXSERVICEVEPROPCACHEENTRY nodes. */
|
---|
160 | RTLISTANCHOR NodeHead;
|
---|
161 | /** Critical section for thread-safe use. */
|
---|
162 | RTCRITSECT CritSect;
|
---|
163 | } VBOXSERVICEVEPROPCACHE;
|
---|
164 | /** Pointer to a guest property cache. */
|
---|
165 | typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
|
---|
169 | */
|
---|
170 | typedef struct VBOXSERVICEVEPROPCACHEENTRY
|
---|
171 | {
|
---|
172 | /** Node to successor.
|
---|
173 | * @todo r=bird: This is not really the node to the successor, but
|
---|
174 | * rather the OUR node in the list. If it helps, remember that
|
---|
175 | * its a doubly linked list. */
|
---|
176 | RTLISTNODE NodeSucc;
|
---|
177 | /** Name (and full path) of guest property. */
|
---|
178 | char *pszName;
|
---|
179 | /** The last value stored (for reference). */
|
---|
180 | char *pszValue;
|
---|
181 | /** Reset value to write if property is temporary. If NULL, it will be
|
---|
182 | * deleted. */
|
---|
183 | char *pszValueReset;
|
---|
184 | /** Flags. */
|
---|
185 | uint32_t fFlags;
|
---|
186 | } VBOXSERVICEVEPROPCACHEENTRY;
|
---|
187 | /** Pointer to a cached guest property. */
|
---|
188 | typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
|
---|
189 |
|
---|
190 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
191 |
|
---|
192 | RT_C_DECLS_BEGIN
|
---|
193 |
|
---|
194 | extern char *g_pszProgName;
|
---|
195 | extern unsigned g_cVerbosity;
|
---|
196 | extern char g_szLogFile[RTPATH_MAX + 128];
|
---|
197 | extern uint32_t g_DefaultInterval;
|
---|
198 | extern VBOXSERVICE g_TimeSync;
|
---|
199 | #ifdef VBOX_WITH_VBOXSERVICE_CLIPBOARD
|
---|
200 | extern VBOXSERVICE g_Clipboard;
|
---|
201 | #endif
|
---|
202 | extern VBOXSERVICE g_Control;
|
---|
203 | extern VBOXSERVICE g_VMInfo;
|
---|
204 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
205 | #ifdef VBOX_WITH_VBOXSERVICE_MANAGEMENT
|
---|
206 | extern VBOXSERVICE g_MemBalloon;
|
---|
207 | extern VBOXSERVICE g_VMStatistics;
|
---|
208 | #endif
|
---|
209 | #ifdef VBOX_WITH_VBOXSERVICE_PAGE_SHARING
|
---|
210 | extern VBOXSERVICE g_PageSharing;
|
---|
211 | #endif
|
---|
212 | #ifdef VBOX_WITH_SHARED_FOLDERS
|
---|
213 | extern VBOXSERVICE g_AutoMount;
|
---|
214 | #endif
|
---|
215 |
|
---|
216 | #ifdef RT_OS_WINDOWS
|
---|
217 | extern VBOXSERVICE g_DisplayConfig;
|
---|
218 | #endif
|
---|
219 |
|
---|
220 | #ifdef DEBUG
|
---|
221 | extern RTCRITSECT g_csLog; /* For guest process stdout dumping. */
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | extern RTEXITCODE VGSvcSyntax(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
225 | extern RTEXITCODE VGSvcError(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
226 | extern void VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
|
---|
227 | extern int VGSvcLogCreate(const char *pszLogFile);
|
---|
228 | extern void VGSvcLogV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
|
---|
229 | extern void VGSvcLogDestroy(void);
|
---|
230 | extern int VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
|
---|
231 | uint32_t u32Min, uint32_t u32Max);
|
---|
232 |
|
---|
233 | /* Exposing the following bits because of windows: */
|
---|
234 | extern int VGSvcStartServices(void);
|
---|
235 | extern int VGSvcStopServices(void);
|
---|
236 | extern void VGSvcMainWait(void);
|
---|
237 | extern int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus);
|
---|
238 | #ifdef RT_OS_WINDOWS
|
---|
239 | extern void VGSvcWinResolveApis(void);
|
---|
240 | extern RTEXITCODE VGSvcWinInstall(void);
|
---|
241 | extern RTEXITCODE VGSvcWinUninstall(void);
|
---|
242 | extern RTEXITCODE VGSvcWinEnterCtrlDispatcher(void);
|
---|
243 | extern void VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint);
|
---|
244 | # ifdef TH32CS_SNAPHEAPLIST
|
---|
245 | extern decltype(CreateToolhelp32Snapshot) *g_pfnCreateToolhelp32Snapshot;
|
---|
246 | extern decltype(Process32First) *g_pfnProcess32First;
|
---|
247 | extern decltype(Process32Next) *g_pfnProcess32Next;
|
---|
248 | extern decltype(Module32First) *g_pfnModule32First;
|
---|
249 | extern decltype(Module32Next) *g_pfnModule32Next;
|
---|
250 | # endif
|
---|
251 | extern decltype(GetSystemTimeAdjustment) *g_pfnGetSystemTimeAdjustment;
|
---|
252 | extern decltype(SetSystemTimeAdjustment) *g_pfnSetSystemTimeAdjustment;
|
---|
253 | # ifdef IPRT_INCLUDED_nt_nt_h
|
---|
254 | extern decltype(ZwQuerySystemInformation) *g_pfnZwQuerySystemInformation;
|
---|
255 | # endif
|
---|
256 | extern ULONG (WINAPI *g_pfnGetAdaptersInfo)(struct _IP_ADAPTER_INFO *, PULONG);
|
---|
257 | #ifdef WINSOCK_VERSION
|
---|
258 | extern decltype(WSAStartup) *g_pfnWSAStartup;
|
---|
259 | extern decltype(WSACleanup) *g_pfnWSACleanup;
|
---|
260 | extern decltype(WSASocketA) *g_pfnWSASocketA;
|
---|
261 | extern decltype(WSAIoctl) *g_pfnWSAIoctl;
|
---|
262 | extern decltype(WSAGetLastError) *g_pfnWSAGetLastError;
|
---|
263 | extern decltype(closesocket) *g_pfnclosesocket;
|
---|
264 | extern decltype(inet_ntoa) *g_pfninet_ntoa;
|
---|
265 | # endif /* WINSOCK_VERSION */
|
---|
266 |
|
---|
267 | #ifdef SE_INTERACTIVE_LOGON_NAME
|
---|
268 | extern decltype(LsaNtStatusToWinError) *g_pfnLsaNtStatusToWinError;
|
---|
269 | #endif
|
---|
270 |
|
---|
271 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
272 | extern int VGSvcVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList);
|
---|
273 | extern int VGSvcVMInfoWinGetComponentVersions(uint32_t uClientID);
|
---|
274 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
275 |
|
---|
276 | #endif /* RT_OS_WINDOWS */
|
---|
277 |
|
---|
278 | #ifdef VBOX_WITH_MEMBALLOON
|
---|
279 | extern uint32_t VGSvcBalloonQueryPages(uint32_t cbPage);
|
---|
280 | #endif
|
---|
281 | #if defined(VBOX_WITH_VBOXSERVICE_PAGE_SHARING)
|
---|
282 | extern RTEXITCODE VGSvcPageSharingWorkerChild(void);
|
---|
283 | #endif
|
---|
284 | extern int VGSvcVMInfoSignal(void);
|
---|
285 |
|
---|
286 | RT_C_DECLS_END
|
---|
287 |
|
---|
288 | #endif /* !GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h */
|
---|
289 |
|
---|