1 | /* $Id: VBoxServiceInternal.h 27926 2010-04-01 08:58:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxService - Guest Additions Services.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2010 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___VBoxServiceInternal_h
|
---|
23 | #define ___VBoxServiceInternal_h
|
---|
24 |
|
---|
25 | #include <stdio.h>
|
---|
26 | #ifdef RT_OS_WINDOWS
|
---|
27 | # include <Windows.h>
|
---|
28 | # include <process.h> /* Needed for file version information. */
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * A service descriptor.
|
---|
33 | */
|
---|
34 | typedef struct
|
---|
35 | {
|
---|
36 | /** The short service name. */
|
---|
37 | const char *pszName;
|
---|
38 | /** The longer service name. */
|
---|
39 | const char *pszDescription;
|
---|
40 | /** The usage options stuff for the --help screen. */
|
---|
41 | const char *pszUsage;
|
---|
42 | /** The option descriptions for the --help screen. */
|
---|
43 | const char *pszOptions;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Called before parsing arguments.
|
---|
47 | * @returns VBox status code.
|
---|
48 | */
|
---|
49 | DECLCALLBACKMEMBER(int, pfnPreInit)(void);
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Tries to parse the given command line option.
|
---|
53 | *
|
---|
54 | * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
|
---|
55 | * @param ppszShort If not NULL it points to the short option iterator. a short argument.
|
---|
56 | * If NULL examine argv[*pi].
|
---|
57 | * @param argc The argument count.
|
---|
58 | * @param argv The argument vector.
|
---|
59 | * @param pi The argument vector index. Update if any value(s) are eaten.
|
---|
60 | */
|
---|
61 | DECLCALLBACKMEMBER(int, pfnOption)(const char **ppszShort, int argc, char **argv, int *pi);
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Called before parsing arguments.
|
---|
65 | * @returns VBox status code.
|
---|
66 | */
|
---|
67 | DECLCALLBACKMEMBER(int, pfnInit)(void);
|
---|
68 |
|
---|
69 | /** Called from the worker thread.
|
---|
70 | *
|
---|
71 | * @returns VBox status code.
|
---|
72 | * @retval VINF_SUCCESS if exitting because *pfTerminate was set.
|
---|
73 | * @param pfTerminate Pointer to a per service termination flag to check
|
---|
74 | * before and after blocking.
|
---|
75 | */
|
---|
76 | DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Stop an service.
|
---|
80 | */
|
---|
81 | DECLCALLBACKMEMBER(void, pfnStop)(void);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Does termination cleanups.
|
---|
85 | *
|
---|
86 | * @remarks This may be called even if pfnInit hasn't been called!
|
---|
87 | */
|
---|
88 | DECLCALLBACKMEMBER(void, pfnTerm)(void);
|
---|
89 | } VBOXSERVICE;
|
---|
90 | /** Pointer to a VBOXSERVICE. */
|
---|
91 | typedef VBOXSERVICE *PVBOXSERVICE;
|
---|
92 | /** Pointer to a const VBOXSERVICE. */
|
---|
93 | typedef VBOXSERVICE const *PCVBOXSERVICE;
|
---|
94 |
|
---|
95 | #ifdef RT_OS_WINDOWS
|
---|
96 | /** The service name (needed for mutex creation on Windows). */
|
---|
97 | # define VBOXSERVICE_NAME "VBoxService"
|
---|
98 | /** The friendly service name. */
|
---|
99 | # define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
|
---|
100 | /** The service description (only W2K+ atm) */
|
---|
101 | # define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, remote sysprep execution and miscellaneous utilities for guest operating systems."
|
---|
102 | /** The following constant may be defined by including NtStatus.h. */
|
---|
103 | # define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
|
---|
104 | /** Structure for storing the looked up user information. */
|
---|
105 | typedef struct
|
---|
106 | {
|
---|
107 | WCHAR wszUser[_MAX_PATH];
|
---|
108 | WCHAR wszAuthenticationPackage[_MAX_PATH];
|
---|
109 | WCHAR wszLogonDomain[_MAX_PATH];
|
---|
110 | } VBOXSERVICEVMINFOUSER, *PVBOXSERVICEVMINFOUSER;
|
---|
111 | /** Structure for the file information lookup. */
|
---|
112 | typedef struct
|
---|
113 | {
|
---|
114 | char *pszFilePath;
|
---|
115 | char *pszFileName;
|
---|
116 | } VBOXSERVICEVMINFOFILE, *PVBOXSERVICEVMINFOFILE;
|
---|
117 | /** Structure for process information lookup. */
|
---|
118 | typedef struct
|
---|
119 | {
|
---|
120 | DWORD id;
|
---|
121 | LUID luid;
|
---|
122 | } VBOXSERVICEVMINFOPROC, *PVBOXSERVICEVMINFOPROC;
|
---|
123 | /** Function prototypes for dynamic loading. */
|
---|
124 | typedef DWORD (WINAPI *PFNWTSGETACTIVECONSOLESESSIONID)(void);
|
---|
125 | #endif /* RT_OS_WINDOWS */
|
---|
126 |
|
---|
127 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
128 | /* Structure for holding process execution data. */
|
---|
129 | typedef struct _VBoxServiceControlProcessData
|
---|
130 | {
|
---|
131 | char szCmd[_1K];
|
---|
132 | uint32_t uFlags;
|
---|
133 | char szArgs[_1K];
|
---|
134 | uint32_t uNumArgs;
|
---|
135 | char szEnv[_64K];
|
---|
136 | uint32_t cbEnv;
|
---|
137 | uint32_t uNumEnvVars;
|
---|
138 | char szStdIn[_1K];
|
---|
139 | char szStdOut[_1K];
|
---|
140 | char szStdErr[_1K];
|
---|
141 | char szUser[128];
|
---|
142 | char szPassword[128];
|
---|
143 | uint32_t uTimeLimitMS;
|
---|
144 | } VBOXSERVICECTRLPROCDATA;
|
---|
145 | /** Pointer to execution data. */
|
---|
146 | typedef VBOXSERVICECTRLPROCDATA *PVBOXSERVICECTRLPROCDATA;
|
---|
147 | /**
|
---|
148 | * For buffering process input supplied by the client.
|
---|
149 | */
|
---|
150 | typedef struct _VBoxServiceControlStdInBuf
|
---|
151 | {
|
---|
152 | /** The mount of buffered data. */
|
---|
153 | size_t cb;
|
---|
154 | /** The current data offset. */
|
---|
155 | size_t off;
|
---|
156 | /** The data buffer. */
|
---|
157 | char *pch;
|
---|
158 | /** The amount of allocated buffer space. */
|
---|
159 | size_t cbAllocated;
|
---|
160 | /** Send further input into the bit bucket (stdin is dead). */
|
---|
161 | bool fBitBucket;
|
---|
162 | /** The CRC-32 for standard input (received part). */
|
---|
163 | uint32_t uCrc32;
|
---|
164 | } VBOXSERVICECTRLSTDINBUF;
|
---|
165 | /** Pointer to a standard input buffer. */
|
---|
166 | typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | RT_C_DECLS_BEGIN
|
---|
170 |
|
---|
171 | extern char *g_pszProgName;
|
---|
172 | extern int g_cVerbosity;
|
---|
173 | extern uint32_t g_DefaultInterval;
|
---|
174 |
|
---|
175 | extern int VBoxServiceSyntax(const char *pszFormat, ...);
|
---|
176 | extern int VBoxServiceError(const char *pszFormat, ...);
|
---|
177 | extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
|
---|
178 | extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);
|
---|
179 | extern unsigned VBoxServiceGetStartedServices(void);
|
---|
180 | extern int VBoxServiceStartServices(unsigned iMain);
|
---|
181 | extern int VBoxServiceStopServices(void);
|
---|
182 |
|
---|
183 | extern VBOXSERVICE g_TimeSync;
|
---|
184 | extern VBOXSERVICE g_Clipboard;
|
---|
185 | extern VBOXSERVICE g_Control;
|
---|
186 | extern VBOXSERVICE g_VMInfo;
|
---|
187 | extern VBOXSERVICE g_Exec;
|
---|
188 | extern VBOXSERVICE g_CpuHotPlug;
|
---|
189 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
190 | extern VBOXSERVICE g_MemBalloon;
|
---|
191 | extern VBOXSERVICE g_VMStatistics;
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | #ifdef RT_OS_WINDOWS
|
---|
195 | extern DWORD g_rcWinService;
|
---|
196 | extern SERVICE_TABLE_ENTRY const g_aServiceTable[]; /** @todo generate on the fly, see comment in main() from the enabled sub services. */
|
---|
197 | extern PFNWTSGETACTIVECONSOLESESSIONID g_pfnWTSGetActiveConsoleSessionId; /* VBoxServiceVMInfo-win.cpp */
|
---|
198 |
|
---|
199 | extern int VBoxServiceWinInstall(void);
|
---|
200 | extern int VBoxServiceWinUninstall(void);
|
---|
201 | extern BOOL VBoxServiceWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint);
|
---|
202 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
203 | extern bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
|
---|
204 | extern bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);
|
---|
205 | extern int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);
|
---|
206 | extern void VBoxServiceVMInfoWinProcessesFree(PVBOXSERVICEVMINFOPROC paProcs);
|
---|
207 | extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
|
---|
208 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
209 | #endif /* RT_OS_WINDOWS */
|
---|
210 |
|
---|
211 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
212 | extern int VBoxServiceControlExecProcess(PVBOXSERVICECTRLPROCDATA pExecData,
|
---|
213 | const char * const *papszArgs,
|
---|
214 | const char * const *papszEnv);
|
---|
215 | #endif
|
---|
216 |
|
---|
217 | #ifdef VBOXSERVICE_MANAGEMENT
|
---|
218 | extern uint32_t VBoxServiceBalloonQueryChunks(void);
|
---|
219 | #endif
|
---|
220 |
|
---|
221 | RT_C_DECLS_END
|
---|
222 |
|
---|
223 | #endif
|
---|
224 |
|
---|