1 | /* $Id: VBoxServiceInternal.h 76563 2019-01-01 03:53:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxService - Guest Additions Services.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2019 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 | extern VBOXSERVICE g_Clipboard;
|
---|
170 | extern VBOXSERVICE g_Control;
|
---|
171 | extern VBOXSERVICE g_VMInfo;
|
---|
172 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
173 | #ifdef VBOX_WITH_VBOXSERVICE_MANAGEMENT
|
---|
174 | extern VBOXSERVICE g_MemBalloon;
|
---|
175 | extern VBOXSERVICE g_VMStatistics;
|
---|
176 | #endif
|
---|
177 | #ifdef VBOX_WITH_VBOXSERVICE_PAGE_SHARING
|
---|
178 | extern VBOXSERVICE g_PageSharing;
|
---|
179 | #endif
|
---|
180 | #ifdef VBOX_WITH_SHARED_FOLDERS
|
---|
181 | extern VBOXSERVICE g_AutoMount;
|
---|
182 | #endif
|
---|
183 | #ifdef DEBUG
|
---|
184 | extern RTCRITSECT g_csLog; /* For guest process stdout dumping. */
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | extern RTEXITCODE VGSvcSyntax(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
188 | extern RTEXITCODE VGSvcError(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
189 | extern void VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
|
---|
190 | extern int VGSvcLogCreate(const char *pszLogFile);
|
---|
191 | extern void VGSvcLogV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
|
---|
192 | extern void VGSvcLogDestroy(void);
|
---|
193 | extern int VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
|
---|
194 | uint32_t u32Min, uint32_t u32Max);
|
---|
195 |
|
---|
196 | /* Exposing the following bits because of windows: */
|
---|
197 | extern int VGSvcStartServices(void);
|
---|
198 | extern int VGSvcStopServices(void);
|
---|
199 | extern void VGSvcMainWait(void);
|
---|
200 | extern int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus);
|
---|
201 | #ifdef RT_OS_WINDOWS
|
---|
202 | extern void VGSvcWinResolveApis(void);
|
---|
203 | extern RTEXITCODE VGSvcWinInstall(void);
|
---|
204 | extern RTEXITCODE VGSvcWinUninstall(void);
|
---|
205 | extern RTEXITCODE VGSvcWinEnterCtrlDispatcher(void);
|
---|
206 | extern void VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint);
|
---|
207 | # ifdef TH32CS_SNAPHEAPLIST
|
---|
208 | extern decltype(CreateToolhelp32Snapshot) *g_pfnCreateToolhelp32Snapshot;
|
---|
209 | extern decltype(Process32First) *g_pfnProcess32First;
|
---|
210 | extern decltype(Process32Next) *g_pfnProcess32Next;
|
---|
211 | extern decltype(Module32First) *g_pfnModule32First;
|
---|
212 | extern decltype(Module32Next) *g_pfnModule32Next;
|
---|
213 | # endif
|
---|
214 | extern decltype(GetSystemTimeAdjustment) *g_pfnGetSystemTimeAdjustment;
|
---|
215 | extern decltype(SetSystemTimeAdjustment) *g_pfnSetSystemTimeAdjustment;
|
---|
216 | # ifdef IPRT_INCLUDED_nt_nt_h
|
---|
217 | extern decltype(ZwQuerySystemInformation) *g_pfnZwQuerySystemInformation;
|
---|
218 | # endif
|
---|
219 | extern ULONG (WINAPI *g_pfnGetAdaptersInfo)(struct _IP_ADAPTER_INFO *, PULONG);
|
---|
220 | #ifdef WINSOCK_VERSION
|
---|
221 | extern decltype(WSAStartup) *g_pfnWSAStartup;
|
---|
222 | extern decltype(WSACleanup) *g_pfnWSACleanup;
|
---|
223 | extern decltype(WSASocketA) *g_pfnWSASocketA;
|
---|
224 | extern decltype(WSAIoctl) *g_pfnWSAIoctl;
|
---|
225 | extern decltype(WSAGetLastError) *g_pfnWSAGetLastError;
|
---|
226 | extern decltype(closesocket) *g_pfnclosesocket;
|
---|
227 | extern decltype(inet_ntoa) *g_pfninet_ntoa;
|
---|
228 | # endif /* WINSOCK_VERSION */
|
---|
229 |
|
---|
230 | #ifdef SE_INTERACTIVE_LOGON_NAME
|
---|
231 | extern decltype(LsaNtStatusToWinError) *g_pfnLsaNtStatusToWinError;
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
235 | extern int VGSvcVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList);
|
---|
236 | extern int VGSvcVMInfoWinGetComponentVersions(uint32_t uClientID);
|
---|
237 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
238 |
|
---|
239 | #endif /* RT_OS_WINDOWS */
|
---|
240 |
|
---|
241 | #ifdef VBOX_WITH_VBOXSERVICE_MANAGEMENT
|
---|
242 | extern uint32_t VGSvcBalloonQueryPages(uint32_t cbPage);
|
---|
243 | #endif
|
---|
244 | #if defined(VBOX_WITH_VBOXSERVICE_PAGE_SHARING)
|
---|
245 | extern RTEXITCODE VGSvcPageSharingWorkerChild(void);
|
---|
246 | #endif
|
---|
247 | extern int VGSvcVMInfoSignal(void);
|
---|
248 |
|
---|
249 | RT_C_DECLS_END
|
---|
250 |
|
---|
251 | #endif /* !GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h */
|
---|
252 |
|
---|