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