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