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