VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h@ 28738

Last change on this file since 28738 was 28560, checked in by vboxsync, 15 years ago

Additions: s/BYTE/uint8_t/g

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: VBoxServiceInternal.h 28560 2010-04-21 11:56:08Z 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#ifdef VBOX_WITH_GUEST_CONTROL
32# include <iprt/list.h>
33#endif
34
35/**
36 * A service descriptor.
37 */
38typedef 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 *pfTerminate was set.
77 * @param pfTerminate Pointer to a per service termination flag to check
78 * before and after blocking.
79 */
80 DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
81
82 /**
83 * Stop an 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. */
95typedef VBOXSERVICE *PVBOXSERVICE;
96/** Pointer to a const VBOXSERVICE. */
97typedef VBOXSERVICE const *PCVBOXSERVICE;
98
99#ifdef RT_OS_WINDOWS
100/** The service name (needed for mutex creation on Windows). */
101# define VBOXSERVICE_NAME "VBoxService"
102/** The friendly service name. */
103# define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
104/** The service description (only W2K+ atm) */
105# define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, remote sysprep execution and miscellaneous utilities for guest operating systems."
106/** The following constant may be defined by including NtStatus.h. */
107# define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
108/** Structure for storing the looked up user information. */
109typedef struct
110{
111 WCHAR wszUser[_MAX_PATH];
112 WCHAR wszAuthenticationPackage[_MAX_PATH];
113 WCHAR wszLogonDomain[_MAX_PATH];
114} VBOXSERVICEVMINFOUSER, *PVBOXSERVICEVMINFOUSER;
115/** Structure for the file information lookup. */
116typedef struct
117{
118 char *pszFilePath;
119 char *pszFileName;
120} VBOXSERVICEVMINFOFILE, *PVBOXSERVICEVMINFOFILE;
121/** Structure for process information lookup. */
122typedef struct
123{
124 DWORD id;
125 LUID luid;
126} VBOXSERVICEVMINFOPROC, *PVBOXSERVICEVMINFOPROC;
127/** Function prototypes for dynamic loading. */
128typedef DWORD (WINAPI *PFNWTSGETACTIVECONSOLESESSIONID)(void);
129#endif /* RT_OS_WINDOWS */
130
131#ifdef VBOX_WITH_GUEST_CONTROL
132enum VBOXSERVICECTRLTHREADDATATYPE
133{
134 VBoxServiceCtrlThreadDataUnknown = 0,
135 VBoxServiceCtrlThreadDataExec = 1
136};
137
138typedef struct
139{
140 uint8_t *pbData;
141 uint32_t cbSize;
142 uint32_t cbOffset;
143 uint32_t cbRead;
144} VBOXSERVICECTRLEXECPIPEBUF;
145/** Pointer to thread data. */
146typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
147
148/* Structure for holding guest exection relevant data. */
149typedef struct
150{
151 uint32_t uPID;
152 char *pszCmd;
153 uint32_t uFlags;
154 char **papszArgs;
155 uint32_t uNumArgs;
156 char **papszEnv;
157 uint32_t uNumEnvVars;
158 char *pszStdIn;
159 char *pszStdOut;
160 char *pszStdErr;
161 char *pszUser;
162 char *pszPassword;
163 uint32_t uTimeLimitMS;
164
165 VBOXSERVICECTRLEXECPIPEBUF stdOut;
166 VBOXSERVICECTRLEXECPIPEBUF stdErr;
167
168} VBOXSERVICECTRLTHREADDATAEXEC;
169/** Pointer to thread data. */
170typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
171
172/* Structure for holding thread relevant data. */
173typedef struct
174{
175 /** Node. */
176 RTLISTNODE Node;
177 /** The worker thread. */
178 RTTHREAD Thread;
179 /** Shutdown indicator. */
180 bool volatile fShutdown;
181 /** Indicator set by the service thread exiting. */
182 bool volatile fStopped;
183 /** Whether the service was started or not. */
184 bool fStarted;
185 /** Client ID. */
186 uint32_t uClientID;
187 /** Context ID. */
188 uint32_t uContextID;
189 /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
190 VBOXSERVICECTRLTHREADDATATYPE enmType;
191 /** Pointer to actual thread data, depending on enmType. */
192 void *pvData;
193} VBOXSERVICECTRLTHREAD;
194/** Pointer to thread data. */
195typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
196
197/**
198 * For buffering process input supplied by the client.
199 */
200typedef struct
201{
202 /** The mount of buffered data. */
203 size_t cb;
204 /** The current data offset. */
205 size_t off;
206 /** The data buffer. */
207 char *pch;
208 /** The amount of allocated buffer space. */
209 size_t cbAllocated;
210 /** Send further input into the bit bucket (stdin is dead). */
211 bool fBitBucket;
212 /** The CRC-32 for standard input (received part). */
213 uint32_t uCrc32;
214} VBOXSERVICECTRLSTDINBUF;
215/** Pointer to a standard input buffer. */
216typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
217#endif
218
219RT_C_DECLS_BEGIN
220
221extern char *g_pszProgName;
222extern int g_cVerbosity;
223extern uint32_t g_DefaultInterval;
224
225extern int VBoxServiceSyntax(const char *pszFormat, ...);
226extern int VBoxServiceError(const char *pszFormat, ...);
227extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
228extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);
229extern unsigned VBoxServiceGetStartedServices(void);
230extern int VBoxServiceStartServices(unsigned iMain);
231extern int VBoxServiceStopServices(void);
232
233extern VBOXSERVICE g_TimeSync;
234extern VBOXSERVICE g_Clipboard;
235extern VBOXSERVICE g_Control;
236extern VBOXSERVICE g_VMInfo;
237extern VBOXSERVICE g_Exec;
238extern VBOXSERVICE g_CpuHotPlug;
239#ifdef VBOXSERVICE_MANAGEMENT
240extern VBOXSERVICE g_MemBalloon;
241extern VBOXSERVICE g_VMStatistics;
242#endif
243#ifdef VBOX_WITH_PAGE_SHARING
244extern VBOXSERVICE g_PageSharing;
245#endif
246
247#ifdef RT_OS_WINDOWS
248extern DWORD g_rcWinService;
249extern SERVICE_TABLE_ENTRY const g_aServiceTable[]; /** @todo generate on the fly, see comment in main() from the enabled sub services. */
250extern PFNWTSGETACTIVECONSOLESESSIONID g_pfnWTSGetActiveConsoleSessionId; /* VBoxServiceVMInfo-win.cpp */
251
252extern int VBoxServiceWinInstall(void);
253extern int VBoxServiceWinUninstall(void);
254extern BOOL VBoxServiceWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint);
255# ifdef VBOX_WITH_GUEST_PROPS
256extern bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
257extern bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);
258extern int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);
259extern void VBoxServiceVMInfoWinProcessesFree(PVBOXSERVICEVMINFOPROC paProcs);
260extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
261# endif /* VBOX_WITH_GUEST_PROPS */
262#endif /* RT_OS_WINDOWS */
263
264#ifdef VBOX_WITH_GUEST_CONTROL
265extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
266 const char *pszArgs, uint32_t uNumArgs,
267 const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
268 const char *pszStdIn, const char *pszStdOut, const char *pszStdErr,
269 const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
270extern void VBoxServiceControlExecDestroyThreadData(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
271extern int VBoxServiceControlExecReadPipeBufferContent(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
272 uint8_t *pbBuffer, uint32_t cbBuffer, uint32_t *pcbToRead);
273extern int VBoxServiceControlExecWritePipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf,
274 uint8_t *pbData, uint32_t cbData);
275#endif
276
277#ifdef VBOXSERVICE_MANAGEMENT
278extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
279#endif
280
281RT_C_DECLS_END
282
283#endif
284
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette