VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestSessionImpl.h@ 71976

Last change on this file since 71976 was 71976, checked in by vboxsync, 7 years ago

Guest Control/Main: Added stubs for IGuestSession:copy[From|To]Guest() (@bugref{9135}) and implemented internal source specification handling for sharing as much code as possible across all the guest session copy methods. Work in progress.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.3 KB
Line 
1/* $Id: GuestSessionImpl.h 71976 2018-04-23 10:52:51Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Guest session handling.
4 */
5
6/*
7 * Copyright (C) 2012-2018 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 ____H_GUESTSESSIONIMPL
19#define ____H_GUESTSESSIONIMPL
20
21#include "GuestSessionWrap.h"
22#include "EventImpl.h"
23
24#include "GuestCtrlImplPrivate.h"
25#include "GuestProcessImpl.h"
26#include "GuestDirectoryImpl.h"
27#include "GuestFileImpl.h"
28#include "GuestFsObjInfoImpl.h"
29
30#include <deque>
31
32class GuestSessionTaskInternalOpen; /* Needed for i_startSessionThreadTask(). */
33
34/**
35 * Guest session implementation.
36 */
37class ATL_NO_VTABLE GuestSession :
38 public GuestSessionWrap,
39 public GuestBase
40{
41public:
42 /** @name COM and internal init/term/mapping cruft.
43 * @{ */
44 DECLARE_EMPTY_CTOR_DTOR(GuestSession)
45
46 int init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds);
47 void uninit(void);
48 HRESULT FinalConstruct(void);
49 void FinalRelease(void);
50 /** @} */
51
52private:
53
54 /** Wrapped @name IGuestSession properties.
55 * @{ */
56 HRESULT getUser(com::Utf8Str &aUser);
57 HRESULT getDomain(com::Utf8Str &aDomain);
58 HRESULT getName(com::Utf8Str &aName);
59 HRESULT getId(ULONG *aId);
60 HRESULT getTimeout(ULONG *aTimeout);
61 HRESULT setTimeout(ULONG aTimeout);
62 HRESULT getProtocolVersion(ULONG *aProtocolVersion);
63 HRESULT getStatus(GuestSessionStatus_T *aStatus);
64 HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges);
65 HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges);
66 HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase);
67 HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
68 HRESULT getPathStyle(PathStyle_T *aPathStyle);
69 HRESULT getCurrentDirectory(com::Utf8Str &aCurrentDirectory);
70 HRESULT setCurrentDirectory(const com::Utf8Str &aCurrentDirectory);
71 HRESULT getUserDocuments(com::Utf8Str &aUserDocuments);
72 HRESULT getUserHome(com::Utf8Str &aUserHome);
73 HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
74 HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles);
75 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
76 /** @} */
77
78 /** Wrapped @name IGuestSession methods.
79 * @{ */
80 HRESULT close();
81
82 HRESULT copyFromGuest(const std::vector<com::Utf8Str> &aSources,
83 const std::vector<com::Utf8Str> &aFilters,
84 const std::vector<FsObjType_T> &aTypes,
85 const std::vector<GuestCopyFlag_T> &aFlags,
86 const com::Utf8Str &aDestination,
87 ComPtr<IProgress> &aProgress);
88 HRESULT copyToGuest(const std::vector<com::Utf8Str> &aSources,
89 const std::vector<com::Utf8Str> &aFilters,
90 const std::vector<FsObjType_T> &aTypes,
91 const std::vector<GuestCopyFlag_T> &aFlags,
92 const com::Utf8Str &aDestination,
93 ComPtr<IProgress> &aProgress);
94
95 HRESULT directoryCopy(const com::Utf8Str &aSource,
96 const com::Utf8Str &aDestination,
97 const std::vector<DirectoryCopyFlag_T> &aFlags,
98 ComPtr<IProgress> &aProgress);
99 HRESULT directoryCopyFromGuest(const com::Utf8Str &aSource,
100 const com::Utf8Str &aDestination,
101 const std::vector<DirectoryCopyFlag_T> &aFlags,
102 ComPtr<IProgress> &aProgress);
103 HRESULT directoryCopyToGuest(const com::Utf8Str &aSource,
104 const com::Utf8Str &aDestination,
105 const std::vector<DirectoryCopyFlag_T> &aFlags,
106 ComPtr<IProgress> &aProgress);
107 HRESULT directoryCreate(const com::Utf8Str &aPath,
108 ULONG aMode,
109 const std::vector<DirectoryCreateFlag_T> &aFlags);
110 HRESULT directoryCreateTemp(const com::Utf8Str &aTemplateName,
111 ULONG aMode,
112 const com::Utf8Str &aPath,
113 BOOL aSecure,
114 com::Utf8Str &aDirectory);
115 HRESULT directoryExists(const com::Utf8Str &aPath,
116 BOOL aFollowSymlinks,
117 BOOL *aExists);
118 HRESULT directoryOpen(const com::Utf8Str &aPath,
119 const com::Utf8Str &aFilter,
120 const std::vector<DirectoryOpenFlag_T> &aFlags,
121 ComPtr<IGuestDirectory> &aDirectory);
122 HRESULT directoryRemove(const com::Utf8Str &aPath);
123 HRESULT directoryRemoveRecursive(const com::Utf8Str &aPath,
124 const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
125 ComPtr<IProgress> &aProgress);
126 HRESULT environmentScheduleSet(const com::Utf8Str &aName,
127 const com::Utf8Str &aValue);
128 HRESULT environmentScheduleUnset(const com::Utf8Str &aName);
129 HRESULT environmentGetBaseVariable(const com::Utf8Str &aName,
130 com::Utf8Str &aValue);
131 HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName,
132 BOOL *aExists);
133
134 HRESULT fileCopy(const com::Utf8Str &aSource,
135 const com::Utf8Str &aDestination,
136 const std::vector<FileCopyFlag_T> &aFlags,
137 ComPtr<IProgress> &aProgress);
138 HRESULT fileCopyToGuest(const com::Utf8Str &aSource,
139 const com::Utf8Str &aDestination,
140 const std::vector<FileCopyFlag_T> &aFlags,
141 ComPtr<IProgress> &aProgress);
142 HRESULT fileCopyFromGuest(const com::Utf8Str &aSource,
143 const com::Utf8Str &aDestination,
144 const std::vector<FileCopyFlag_T> &aFlags,
145 ComPtr<IProgress> &aProgress);
146 HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
147 ULONG aMode,
148 const com::Utf8Str &aPath,
149 BOOL aSecure,
150 ComPtr<IGuestFile> &aFile);
151 HRESULT fileExists(const com::Utf8Str &aPath,
152 BOOL aFollowSymlinks,
153 BOOL *aExists);
154 HRESULT fileOpen(const com::Utf8Str &aPath,
155 FileAccessMode_T aAccessMode,
156 FileOpenAction_T aOpenAction,
157 ULONG aCreationMode,
158 ComPtr<IGuestFile> &aFile);
159 HRESULT fileOpenEx(const com::Utf8Str &aPath,
160 FileAccessMode_T aAccessMode,
161 FileOpenAction_T aOpenAction,
162 FileSharingMode_T aSharingMode,
163 ULONG aCreationMode,
164 const std::vector<FileOpenExFlag_T> &aFlags,
165 ComPtr<IGuestFile> &aFile);
166 HRESULT fileQuerySize(const com::Utf8Str &aPath,
167 BOOL aFollowSymlinks,
168 LONG64 *aSize);
169 HRESULT fsObjExists(const com::Utf8Str &aPath,
170 BOOL aFollowSymlinks,
171 BOOL *pfExists);
172 HRESULT fsObjQueryInfo(const com::Utf8Str &aPath,
173 BOOL aFollowSymlinks,
174 ComPtr<IGuestFsObjInfo> &aInfo);
175 HRESULT fsObjRemove(const com::Utf8Str &aPath);
176 HRESULT fsObjRename(const com::Utf8Str &aOldPath,
177 const com::Utf8Str &aNewPath,
178 const std::vector<FsObjRenameFlag_T> &aFlags);
179 HRESULT fsObjMove(const com::Utf8Str &aSource,
180 const com::Utf8Str &aDestination,
181 const std::vector<FsObjMoveFlag_T> &aFlags,
182 ComPtr<IProgress> &aProgress);
183 HRESULT fsObjSetACL(const com::Utf8Str &aPath,
184 BOOL aFollowSymlinks,
185 const com::Utf8Str &aAcl,
186 ULONG aMode);
187 HRESULT processCreate(const com::Utf8Str &aCommand,
188 const std::vector<com::Utf8Str> &aArguments,
189 const std::vector<com::Utf8Str> &aEnvironment,
190 const std::vector<ProcessCreateFlag_T> &aFlags,
191 ULONG aTimeoutMS,
192 ComPtr<IGuestProcess> &aGuestProcess);
193 HRESULT processCreateEx(const com::Utf8Str &aCommand,
194 const std::vector<com::Utf8Str> &aArguments,
195 const std::vector<com::Utf8Str> &aEnvironment,
196 const std::vector<ProcessCreateFlag_T> &aFlags,
197 ULONG aTimeoutMS,
198 ProcessPriority_T aPriority,
199 const std::vector<LONG> &aAffinity,
200 ComPtr<IGuestProcess> &aGuestProcess);
201 HRESULT processGet(ULONG aPid,
202 ComPtr<IGuestProcess> &aGuestProcess);
203 HRESULT symlinkCreate(const com::Utf8Str &aSource,
204 const com::Utf8Str &aTarget,
205 SymlinkType_T aType);
206 HRESULT symlinkExists(const com::Utf8Str &aSymlink,
207 BOOL *aExists);
208 HRESULT symlinkRead(const com::Utf8Str &aSymlink,
209 const std::vector<SymlinkReadFlag_T> &aFlags,
210 com::Utf8Str &aTarget);
211 HRESULT waitFor(ULONG aWaitFor,
212 ULONG aTimeoutMS,
213 GuestSessionWaitResult_T *aReason);
214 HRESULT waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor,
215 ULONG aTimeoutMS,
216 GuestSessionWaitResult_T *aReason);
217 /** @} */
218
219 /** Map of guest directories. The key specifies the internal directory ID. */
220 typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
221 /** Map of guest files. The key specifies the internal file ID. */
222 typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
223 /** Map of guest processes. The key specifies the internal process number.
224 * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
225 typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
226
227 /** Guest session object type enumeration. */
228 enum SESSIONOBJECTTYPE
229 {
230 /** Anonymous object. */
231 SESSIONOBJECTTYPE_ANONYMOUS = 0,
232 /** Session object. */
233 SESSIONOBJECTTYPE_SESSION = 1,
234 /** Directory object. */
235 SESSIONOBJECTTYPE_DIRECTORY = 2,
236 /** File object. */
237 SESSIONOBJECTTYPE_FILE = 3,
238 /** Process object. */
239 SESSIONOBJECTTYPE_PROCESS = 4,
240 /** The usual 32-bit hack. */
241 SESSIONOBJECTTYPE_32BIT_HACK = 0x7fffffff
242 };
243
244 struct SessionObject
245 {
246 /** Creation timestamp (in ms). */
247 uint64_t tsCreatedMs;
248 /** The object type. */
249 SESSIONOBJECTTYPE enmType;
250 };
251
252 /** Map containing all objects bound to a guest session.
253 * The key specifies the (global) context ID. */
254 typedef std::map <uint32_t, SessionObject> SessionObjects;
255 /** Queue containing context IDs which are no longer in use.
256 * Useful for quickly retrieving a new, unused context ID. */
257 typedef std::deque <uint32_t> SessionObjectsFree;
258
259public:
260 /** @name Public internal methods.
261 * @todo r=bird: Most of these are public for no real reason...
262 * @{ */
263 int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc);
264 inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
265 int i_directoryUnregister(GuestDirectory *pDirectory);
266 int i_directoryRemove(const Utf8Str &strPath, uint32_t uFlags, int *pGuestRc);
267 int i_directoryCreate(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
268 int i_directoryOpen(const GuestDirectoryOpenInfo &openInfo,
269 ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc);
270 int i_directoryQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
271 int i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
272 int i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
273 inline bool i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile);
274 int i_fileUnregister(GuestFile *pFile);
275 int i_fileRemove(const Utf8Str &strPath, int *pGuestRc);
276 int i_fileOpenEx(const com::Utf8Str &aPath, FileAccessMode_T aAccessMode, FileOpenAction_T aOpenAction,
277 FileSharingMode_T aSharingMode, ULONG aCreationMode,
278 const std::vector<FileOpenExFlag_T> &aFlags,
279 ComObjPtr<GuestFile> &pFile, int *prcGuest);
280 int i_fileOpen(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
281 int i_fileQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
282 int i_fileQuerySize(const Utf8Str &strPath, bool fFollowSymlinks, int64_t *pllSize, int *pGuestRc);
283 int i_fsCreateTemp(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory,
284 Utf8Str &strName, int *pGuestRc);
285 int i_fsQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
286 const GuestCredentials &i_getCredentials(void);
287 EventSource *i_getEventSource(void) { return mEventSource; }
288 Utf8Str i_getName(void);
289 ULONG i_getId(void) { return mData.mSession.mID; }
290 static Utf8Str i_guestErrorToString(int guestRc);
291 HRESULT i_isReadyExternal(void);
292 int i_onRemove(void);
293 int i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
294 PathStyle_T i_getPathStyle(void);
295 int i_startSession(int *pGuestRc);
296 int i_startSessionAsync(void);
297 static void i_startSessionThreadTask(GuestSessionTaskInternalOpen *pTask);
298 Guest *i_getParent(void) { return mParent; }
299 uint32_t i_getProtocolVersion(void) { return mData.mProtocolVersion; }
300 int i_objectRegister(SESSIONOBJECTTYPE enmType, uint32_t *puObjectID);
301 int i_objectRegisterEx(SESSIONOBJECTTYPE enmType, uint32_t fFlags, uint32_t *puObjectID);
302 int i_objectUnregister(uint32_t uObjectID);
303 int i_pathRename(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, int *pGuestRc);
304 int i_pathUserDocuments(Utf8Str &strPath, int *prcGuest);
305 int i_pathUserHome(Utf8Str &strPath, int *prcGuest);
306 int i_processUnregister(GuestProcess *pProcess);
307 int i_processCreateEx(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
308 inline bool i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
309 inline int i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
310 int i_sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
311 static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
312 int i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc);
313 int i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */);
314 int i_determineProtocolVersion(void);
315 int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc);
316 int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
317 GuestSessionStatus_T *pSessionStatus, int *pGuestRc);
318 /** @} */
319
320private:
321
322 /** Pointer to the parent (Guest). */
323 Guest *mParent;
324 /**
325 * The session's event source. This source is used for
326 * serving the internal listener as well as all other
327 * external listeners that may register to it.
328 *
329 * Note: This can safely be used without holding any locks.
330 * An AutoCaller suffices to prevent it being destroy while in use and
331 * internally there is a lock providing the necessary serialization.
332 */
333 const ComObjPtr<EventSource> mEventSource;
334
335 struct Data
336 {
337 /** The session credentials. */
338 GuestCredentials mCredentials;
339 /** The session's startup info. */
340 GuestSessionStartupInfo mSession;
341 /** The session's object ID.
342 * Needed for registering wait events which are bound directly to this session. */
343 uint32_t mObjectID;
344 /** The session's current status. */
345 GuestSessionStatus_T mStatus;
346 /** The set of environment changes for the session for use when
347 * creating new guest processes. */
348 GuestEnvironmentChanges mEnvironmentChanges;
349 /** Pointer to the immutable base environment for the session.
350 * @note This is not allocated until the guest reports it to the host. It is
351 * also shared with child processes. */
352 GuestEnvironment const *mpBaseEnvironment;
353 /** Directory objects bound to this session. */
354 SessionDirectories mDirectories;
355 /** File objects bound to this session. */
356 SessionFiles mFiles;
357 /** Process objects bound to this session. */
358 SessionProcesses mProcesses;
359 /** Map of registered session objects (files, directories, ...). */
360 SessionObjects mObjects;
361 /** Queue of object IDs which are not used anymore (free list).
362 * Acts as a "free list" for the mObjects map. */
363 SessionObjectsFree mObjectsFree;
364 /** Guest control protocol version to be used.
365 * Guest Additions < VBox 4.3 have version 1,
366 * any newer version will have version 2. */
367 uint32_t mProtocolVersion;
368 /** Session timeout (in ms). */
369 uint32_t mTimeout;
370 /** The last returned session status
371 * returned from the guest side. */
372 int mRC;
373
374 Data(void)
375 : mpBaseEnvironment(NULL)
376 { }
377 Data(const Data &rThat)
378 : mCredentials(rThat.mCredentials)
379 , mSession(rThat.mSession)
380 , mStatus(rThat.mStatus)
381 , mEnvironmentChanges(rThat.mEnvironmentChanges)
382 , mpBaseEnvironment(NULL)
383 , mDirectories(rThat.mDirectories)
384 , mFiles(rThat.mFiles)
385 , mProcesses(rThat.mProcesses)
386 , mObjects(rThat.mObjects)
387 , mObjectsFree(rThat.mObjectsFree)
388 , mProtocolVersion(rThat.mProtocolVersion)
389 , mTimeout(rThat.mTimeout)
390 , mRC(rThat.mRC)
391 { }
392 ~Data(void)
393 {
394 if (mpBaseEnvironment)
395 {
396 mpBaseEnvironment->releaseConst();
397 mpBaseEnvironment = NULL;
398 }
399 }
400 } mData;
401};
402
403#endif /* !____H_GUESTSESSIONIMPL */
404
Note: See TracBrowser for help on using the repository browser.

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