1 | /* $Id: GuestSessionImpl.h 71406 2018-03-20 14:44:24Z 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 | #include "ThreadTask.h"
|
---|
30 |
|
---|
31 | #include <iprt/isofs.h> /* For UpdateAdditions. */
|
---|
32 |
|
---|
33 | #include <deque>
|
---|
34 |
|
---|
35 | class Guest;
|
---|
36 | class GuestSessionTaskInternalOpen;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Abstract base class for a lenghtly per-session operation which
|
---|
40 | * runs in a Main worker thread.
|
---|
41 | */
|
---|
42 | class GuestSessionTask : public ThreadTask
|
---|
43 | {
|
---|
44 | public:
|
---|
45 |
|
---|
46 | GuestSessionTask(GuestSession *pSession);
|
---|
47 |
|
---|
48 | virtual ~GuestSessionTask(void);
|
---|
49 |
|
---|
50 | public:
|
---|
51 |
|
---|
52 | virtual int Run(void) = 0;
|
---|
53 | void handler()
|
---|
54 | {
|
---|
55 | int vrc = Run();
|
---|
56 | NOREF(vrc);
|
---|
57 | /** @todo
|
---|
58 | *
|
---|
59 | * r=bird: what was your idea WRT to Run status code and async tasks?
|
---|
60 | *
|
---|
61 | */
|
---|
62 | }
|
---|
63 |
|
---|
64 | int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
|
---|
65 |
|
---|
66 | HRESULT Init(const Utf8Str &strTaskDesc)
|
---|
67 | {
|
---|
68 | HRESULT hr = S_OK;
|
---|
69 | setTaskDesc(strTaskDesc);
|
---|
70 | hr = createAndSetProgressObject();
|
---|
71 | return hr;
|
---|
72 | }
|
---|
73 |
|
---|
74 | const ComObjPtr<Progress>& GetProgressObject() const { return mProgress; }
|
---|
75 |
|
---|
76 | protected:
|
---|
77 |
|
---|
78 | /** @name Directory handling primitives.
|
---|
79 | * @{ */
|
---|
80 | int directoryCreate(const com::Utf8Str &strPath, DirectoryCreateFlag_T enmDirecotryCreateFlags, uint32_t uMode,
|
---|
81 | bool fFollowSymlinks);
|
---|
82 | /** @} */
|
---|
83 |
|
---|
84 | /** @name File handling primitives.
|
---|
85 | * @{ */
|
---|
86 | int fileCopyFromEx(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags,
|
---|
87 | PRTFILE pFile, uint64_t cbOffset, uint64_t cbSize);
|
---|
88 | int fileCopyFrom(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
89 | int fileCopyToEx(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags, PRTFILE pFile,
|
---|
90 | uint64_t cbOffset, uint64_t cbSize); /**< r=bird: 'cbOffset' makes no sense what so ever. It should be 'off', or do you mean sizeof(uint64_t)? */
|
---|
91 | int fileCopyTo(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 | /** @name Guest property handling primitives.
|
---|
95 | * @{ */
|
---|
96 | int getGuestProperty(const ComObjPtr<Guest> &pGuest, const Utf8Str &strPath, Utf8Str &strValue);
|
---|
97 | /** @} */
|
---|
98 |
|
---|
99 | /** @name Path handling primitives.
|
---|
100 | * @{ */
|
---|
101 | int pathConstructOnGuest(const Utf8Str &strSourceRoot, const Utf8Str &strSource, const Utf8Str &strDest, Utf8Str &strOut);
|
---|
102 | /** @} */
|
---|
103 |
|
---|
104 | int setProgress(ULONG uPercent);
|
---|
105 | int setProgressSuccess(void);
|
---|
106 | HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
|
---|
107 |
|
---|
108 | inline void setTaskDesc(const Utf8Str &strTaskDesc) throw()
|
---|
109 | {
|
---|
110 | mDesc = strTaskDesc;
|
---|
111 | }
|
---|
112 |
|
---|
113 | HRESULT createAndSetProgressObject();
|
---|
114 |
|
---|
115 | protected:
|
---|
116 |
|
---|
117 | Utf8Str mDesc;
|
---|
118 | /** The guest session object this task is working on. */
|
---|
119 | ComObjPtr<GuestSession> mSession;
|
---|
120 | /** Progress object for getting updated when running
|
---|
121 | * asynchronously. Optional. */
|
---|
122 | ComObjPtr<Progress> mProgress;
|
---|
123 | };
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Task for opening a guest session.
|
---|
127 | */
|
---|
128 | class SessionTaskOpen : public GuestSessionTask
|
---|
129 | {
|
---|
130 | public:
|
---|
131 |
|
---|
132 | SessionTaskOpen(GuestSession *pSession,
|
---|
133 | uint32_t uFlags,
|
---|
134 | uint32_t uTimeoutMS);
|
---|
135 | virtual ~SessionTaskOpen(void);
|
---|
136 | int Run(void);
|
---|
137 |
|
---|
138 | protected:
|
---|
139 |
|
---|
140 | /** Session creation flags. */
|
---|
141 | uint32_t mFlags;
|
---|
142 | /** Session creation timeout (in ms). */
|
---|
143 | uint32_t mTimeoutMS;
|
---|
144 | };
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Task for copying directories from guest to the host.
|
---|
148 | */
|
---|
149 | class SessionTaskCopyDirFrom : public GuestSessionTask
|
---|
150 | {
|
---|
151 | public:
|
---|
152 |
|
---|
153 | SessionTaskCopyDirFrom(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
|
---|
154 | DirectoryCopyFlag_T enmDirCopyFlags);
|
---|
155 | virtual ~SessionTaskCopyDirFrom(void);
|
---|
156 | int Run(void);
|
---|
157 |
|
---|
158 | protected:
|
---|
159 |
|
---|
160 | int directoryCopyToHost(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
|
---|
161 | bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
|
---|
162 | protected:
|
---|
163 |
|
---|
164 | Utf8Str mSource;
|
---|
165 | Utf8Str mDest;
|
---|
166 | Utf8Str mFilter;
|
---|
167 | DirectoryCopyFlag_T mDirCopyFlags;
|
---|
168 | };
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Task for copying directories from host to the guest.
|
---|
172 | */
|
---|
173 | class SessionTaskCopyDirTo : public GuestSessionTask
|
---|
174 | {
|
---|
175 | public:
|
---|
176 |
|
---|
177 | SessionTaskCopyDirTo(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
|
---|
178 | DirectoryCopyFlag_T enmDirCopyFlags);
|
---|
179 | virtual ~SessionTaskCopyDirTo(void);
|
---|
180 | int Run(void);
|
---|
181 |
|
---|
182 | protected:
|
---|
183 |
|
---|
184 | int directoryCopyToGuest(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
|
---|
185 | bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
|
---|
186 | protected:
|
---|
187 |
|
---|
188 | Utf8Str mSource;
|
---|
189 | Utf8Str mDest;
|
---|
190 | Utf8Str mFilter;
|
---|
191 | DirectoryCopyFlag_T mDirCopyFlags;
|
---|
192 | };
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Task for copying files from host to the guest.
|
---|
196 | */
|
---|
197 | class SessionTaskCopyFileTo : public GuestSessionTask
|
---|
198 | {
|
---|
199 | public:
|
---|
200 |
|
---|
201 | SessionTaskCopyFileTo(GuestSession *pSession,
|
---|
202 | const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
203 | SessionTaskCopyFileTo(GuestSession *pSession,
|
---|
204 | PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
|
---|
205 | const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
206 | virtual ~SessionTaskCopyFileTo(void);
|
---|
207 | int Run(void);
|
---|
208 |
|
---|
209 | protected:
|
---|
210 |
|
---|
211 | Utf8Str mSource;
|
---|
212 | PRTFILE mSourceFile;
|
---|
213 | size_t mSourceOffset;
|
---|
214 | uint64_t mSourceSize;
|
---|
215 | Utf8Str mDest;
|
---|
216 | FileCopyFlag_T mFileCopyFlags;
|
---|
217 | };
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Task for copying files from guest to the host.
|
---|
221 | */
|
---|
222 | class SessionTaskCopyFileFrom : public GuestSessionTask
|
---|
223 | {
|
---|
224 | public:
|
---|
225 |
|
---|
226 | SessionTaskCopyFileFrom(GuestSession *pSession,
|
---|
227 | const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
228 | virtual ~SessionTaskCopyFileFrom(void);
|
---|
229 | int Run(void);
|
---|
230 |
|
---|
231 | protected:
|
---|
232 |
|
---|
233 | Utf8Str mSource;
|
---|
234 | Utf8Str mDest;
|
---|
235 | FileCopyFlag_T mFileCopyFlags;
|
---|
236 | };
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Task for automatically updating the Guest Additions on the guest.
|
---|
240 | */
|
---|
241 | class SessionTaskUpdateAdditions : public GuestSessionTask
|
---|
242 | {
|
---|
243 | public:
|
---|
244 |
|
---|
245 | SessionTaskUpdateAdditions(GuestSession *pSession,
|
---|
246 | const Utf8Str &strSource, const ProcessArguments &aArguments,
|
---|
247 | uint32_t uFlags);
|
---|
248 | virtual ~SessionTaskUpdateAdditions(void);
|
---|
249 | int Run(void);
|
---|
250 |
|
---|
251 | protected:
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Suported OS types for automatic updating.
|
---|
255 | */
|
---|
256 | enum eOSType
|
---|
257 | {
|
---|
258 | eOSType_Unknown = 0,
|
---|
259 | eOSType_Windows = 1,
|
---|
260 | eOSType_Linux = 2,
|
---|
261 | eOSType_Solaris = 3
|
---|
262 | };
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Structure representing a file to
|
---|
266 | * get off the .ISO, copied to the guest.
|
---|
267 | */
|
---|
268 | struct InstallerFile
|
---|
269 | {
|
---|
270 | InstallerFile(const Utf8Str &aSource,
|
---|
271 | const Utf8Str &aDest,
|
---|
272 | uint32_t aFlags = 0)
|
---|
273 | : strSource(aSource),
|
---|
274 | strDest(aDest),
|
---|
275 | fFlags(aFlags) { }
|
---|
276 |
|
---|
277 | InstallerFile(const Utf8Str &aSource,
|
---|
278 | const Utf8Str &aDest,
|
---|
279 | uint32_t aFlags,
|
---|
280 | const GuestProcessStartupInfo &aStartupInfo)
|
---|
281 | : strSource(aSource),
|
---|
282 | strDest(aDest),
|
---|
283 | fFlags(aFlags),
|
---|
284 | mProcInfo(aStartupInfo)
|
---|
285 | {
|
---|
286 | mProcInfo.mExecutable = strDest;
|
---|
287 | if (mProcInfo.mName.isEmpty())
|
---|
288 | mProcInfo.mName = strDest;
|
---|
289 | }
|
---|
290 |
|
---|
291 | /** Source file on .ISO. */
|
---|
292 | Utf8Str strSource;
|
---|
293 | /** Destination file on the guest. */
|
---|
294 | Utf8Str strDest;
|
---|
295 | /** File flags. */
|
---|
296 | uint32_t fFlags;
|
---|
297 | /** Optional arguments if this file needs to be
|
---|
298 | * executed. */
|
---|
299 | GuestProcessStartupInfo mProcInfo;
|
---|
300 | };
|
---|
301 |
|
---|
302 | int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
|
---|
303 | int copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional, uint32_t *pcbSize);
|
---|
304 | int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
|
---|
305 |
|
---|
306 | /** Files to handle. */
|
---|
307 | std::vector<InstallerFile> mFiles;
|
---|
308 | /** The (optionally) specified Guest Additions .ISO on the host
|
---|
309 | * which will be used for the updating process. */
|
---|
310 | Utf8Str mSource;
|
---|
311 | /** (Optional) installer command line arguments. */
|
---|
312 | ProcessArguments mArguments;
|
---|
313 | /** Update flags. */
|
---|
314 | uint32_t mFlags;
|
---|
315 | };
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Guest session implementation.
|
---|
319 | */
|
---|
320 | class ATL_NO_VTABLE GuestSession :
|
---|
321 | public GuestSessionWrap,
|
---|
322 | public GuestBase
|
---|
323 | {
|
---|
324 | public:
|
---|
325 | /** @name COM and internal init/term/mapping cruft.
|
---|
326 | * @{ */
|
---|
327 | DECLARE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
328 |
|
---|
329 | int init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds);
|
---|
330 | void uninit(void);
|
---|
331 | HRESULT FinalConstruct(void);
|
---|
332 | void FinalRelease(void);
|
---|
333 | /** @} */
|
---|
334 |
|
---|
335 | private:
|
---|
336 |
|
---|
337 | /** Wrapped @name IGuestSession properties.
|
---|
338 | * @{ */
|
---|
339 | HRESULT getUser(com::Utf8Str &aUser);
|
---|
340 | HRESULT getDomain(com::Utf8Str &aDomain);
|
---|
341 | HRESULT getName(com::Utf8Str &aName);
|
---|
342 | HRESULT getId(ULONG *aId);
|
---|
343 | HRESULT getTimeout(ULONG *aTimeout);
|
---|
344 | HRESULT setTimeout(ULONG aTimeout);
|
---|
345 | HRESULT getProtocolVersion(ULONG *aProtocolVersion);
|
---|
346 | HRESULT getStatus(GuestSessionStatus_T *aStatus);
|
---|
347 | HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
348 | HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
349 | HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase);
|
---|
350 | HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
|
---|
351 | HRESULT getPathStyle(PathStyle_T *aPathStyle);
|
---|
352 | HRESULT getCurrentDirectory(com::Utf8Str &aCurrentDirectory);
|
---|
353 | HRESULT setCurrentDirectory(const com::Utf8Str &aCurrentDirectory);
|
---|
354 | HRESULT getUserDocuments(com::Utf8Str &aUserDocuments);
|
---|
355 | HRESULT getUserHome(com::Utf8Str &aUserHome);
|
---|
356 | HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
|
---|
357 | HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles);
|
---|
358 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
359 | /** @} */
|
---|
360 |
|
---|
361 | /** Wrapped @name IGuestSession methods.
|
---|
362 | * @{ */
|
---|
363 | HRESULT close();
|
---|
364 |
|
---|
365 | HRESULT directoryCopy(const com::Utf8Str &aSource,
|
---|
366 | const com::Utf8Str &aDestination,
|
---|
367 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
368 | ComPtr<IProgress> &aProgress);
|
---|
369 | HRESULT directoryCopyFromGuest(const com::Utf8Str &aSource,
|
---|
370 | const com::Utf8Str &aDestination,
|
---|
371 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
372 | ComPtr<IProgress> &aProgress);
|
---|
373 | HRESULT directoryCopyToGuest(const com::Utf8Str &aSource,
|
---|
374 | const com::Utf8Str &aDestination,
|
---|
375 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
376 | ComPtr<IProgress> &aProgress);
|
---|
377 | HRESULT directoryCreate(const com::Utf8Str &aPath,
|
---|
378 | ULONG aMode,
|
---|
379 | const std::vector<DirectoryCreateFlag_T> &aFlags);
|
---|
380 | HRESULT directoryCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
381 | ULONG aMode,
|
---|
382 | const com::Utf8Str &aPath,
|
---|
383 | BOOL aSecure,
|
---|
384 | com::Utf8Str &aDirectory);
|
---|
385 | HRESULT directoryExists(const com::Utf8Str &aPath,
|
---|
386 | BOOL aFollowSymlinks,
|
---|
387 | BOOL *aExists);
|
---|
388 | HRESULT directoryOpen(const com::Utf8Str &aPath,
|
---|
389 | const com::Utf8Str &aFilter,
|
---|
390 | const std::vector<DirectoryOpenFlag_T> &aFlags,
|
---|
391 | ComPtr<IGuestDirectory> &aDirectory);
|
---|
392 | HRESULT directoryRemove(const com::Utf8Str &aPath);
|
---|
393 | HRESULT directoryRemoveRecursive(const com::Utf8Str &aPath,
|
---|
394 | const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
|
---|
395 | ComPtr<IProgress> &aProgress);
|
---|
396 | HRESULT environmentScheduleSet(const com::Utf8Str &aName,
|
---|
397 | const com::Utf8Str &aValue);
|
---|
398 | HRESULT environmentScheduleUnset(const com::Utf8Str &aName);
|
---|
399 | HRESULT environmentGetBaseVariable(const com::Utf8Str &aName,
|
---|
400 | com::Utf8Str &aValue);
|
---|
401 | HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName,
|
---|
402 | BOOL *aExists);
|
---|
403 |
|
---|
404 | HRESULT fileCopy(const com::Utf8Str &aSource,
|
---|
405 | const com::Utf8Str &aDestination,
|
---|
406 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
407 | ComPtr<IProgress> &aProgress);
|
---|
408 | HRESULT fileCopyToGuest(const com::Utf8Str &aSource,
|
---|
409 | const com::Utf8Str &aDestination,
|
---|
410 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
411 | ComPtr<IProgress> &aProgress);
|
---|
412 | HRESULT fileCopyFromGuest(const com::Utf8Str &aSource,
|
---|
413 | const com::Utf8Str &aDestination,
|
---|
414 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
415 | ComPtr<IProgress> &aProgress);
|
---|
416 | HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
417 | ULONG aMode,
|
---|
418 | const com::Utf8Str &aPath,
|
---|
419 | BOOL aSecure,
|
---|
420 | ComPtr<IGuestFile> &aFile);
|
---|
421 | HRESULT fileExists(const com::Utf8Str &aPath,
|
---|
422 | BOOL aFollowSymlinks,
|
---|
423 | BOOL *aExists);
|
---|
424 | HRESULT fileOpen(const com::Utf8Str &aPath,
|
---|
425 | FileAccessMode_T aAccessMode,
|
---|
426 | FileOpenAction_T aOpenAction,
|
---|
427 | ULONG aCreationMode,
|
---|
428 | ComPtr<IGuestFile> &aFile);
|
---|
429 | HRESULT fileOpenEx(const com::Utf8Str &aPath,
|
---|
430 | FileAccessMode_T aAccessMode,
|
---|
431 | FileOpenAction_T aOpenAction,
|
---|
432 | FileSharingMode_T aSharingMode,
|
---|
433 | ULONG aCreationMode,
|
---|
434 | const std::vector<FileOpenExFlag_T> &aFlags,
|
---|
435 | ComPtr<IGuestFile> &aFile);
|
---|
436 | HRESULT fileQuerySize(const com::Utf8Str &aPath,
|
---|
437 | BOOL aFollowSymlinks,
|
---|
438 | LONG64 *aSize);
|
---|
439 | HRESULT fsObjExists(const com::Utf8Str &aPath,
|
---|
440 | BOOL aFollowSymlinks,
|
---|
441 | BOOL *pfExists);
|
---|
442 | HRESULT fsObjQueryInfo(const com::Utf8Str &aPath,
|
---|
443 | BOOL aFollowSymlinks,
|
---|
444 | ComPtr<IGuestFsObjInfo> &aInfo);
|
---|
445 | HRESULT fsObjRemove(const com::Utf8Str &aPath);
|
---|
446 | HRESULT fsObjRename(const com::Utf8Str &aOldPath,
|
---|
447 | const com::Utf8Str &aNewPath,
|
---|
448 | const std::vector<FsObjRenameFlag_T> &aFlags);
|
---|
449 | HRESULT fsObjMove(const com::Utf8Str &aSource,
|
---|
450 | const com::Utf8Str &aDestination,
|
---|
451 | const std::vector<FsObjMoveFlag_T> &aFlags,
|
---|
452 | ComPtr<IProgress> &aProgress);
|
---|
453 | HRESULT fsObjSetACL(const com::Utf8Str &aPath,
|
---|
454 | BOOL aFollowSymlinks,
|
---|
455 | const com::Utf8Str &aAcl,
|
---|
456 | ULONG aMode);
|
---|
457 | HRESULT processCreate(const com::Utf8Str &aCommand,
|
---|
458 | const std::vector<com::Utf8Str> &aArguments,
|
---|
459 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
460 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
461 | ULONG aTimeoutMS,
|
---|
462 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
463 | HRESULT processCreateEx(const com::Utf8Str &aCommand,
|
---|
464 | const std::vector<com::Utf8Str> &aArguments,
|
---|
465 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
466 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
467 | ULONG aTimeoutMS,
|
---|
468 | ProcessPriority_T aPriority,
|
---|
469 | const std::vector<LONG> &aAffinity,
|
---|
470 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
471 | HRESULT processGet(ULONG aPid,
|
---|
472 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
473 | HRESULT symlinkCreate(const com::Utf8Str &aSource,
|
---|
474 | const com::Utf8Str &aTarget,
|
---|
475 | SymlinkType_T aType);
|
---|
476 | HRESULT symlinkExists(const com::Utf8Str &aSymlink,
|
---|
477 | BOOL *aExists);
|
---|
478 | HRESULT symlinkRead(const com::Utf8Str &aSymlink,
|
---|
479 | const std::vector<SymlinkReadFlag_T> &aFlags,
|
---|
480 | com::Utf8Str &aTarget);
|
---|
481 | HRESULT waitFor(ULONG aWaitFor,
|
---|
482 | ULONG aTimeoutMS,
|
---|
483 | GuestSessionWaitResult_T *aReason);
|
---|
484 | HRESULT waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor,
|
---|
485 | ULONG aTimeoutMS,
|
---|
486 | GuestSessionWaitResult_T *aReason);
|
---|
487 | /** @} */
|
---|
488 |
|
---|
489 | /** Map of guest directories. The key specifies the internal directory ID. */
|
---|
490 | typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
|
---|
491 | /** Map of guest files. The key specifies the internal file ID. */
|
---|
492 | typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
|
---|
493 | /** Map of guest processes. The key specifies the internal process number.
|
---|
494 | * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
|
---|
495 | typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
|
---|
496 |
|
---|
497 | /** Guest session object type enumeration. */
|
---|
498 | enum SESSIONOBJECTTYPE
|
---|
499 | {
|
---|
500 | /** Anonymous object. */
|
---|
501 | SESSIONOBJECTTYPE_ANONYMOUS = 0,
|
---|
502 | /** Session object. */
|
---|
503 | SESSIONOBJECTTYPE_SESSION = 1,
|
---|
504 | /** Directory object. */
|
---|
505 | SESSIONOBJECTTYPE_DIRECTORY = 2,
|
---|
506 | /** File object. */
|
---|
507 | SESSIONOBJECTTYPE_FILE = 3,
|
---|
508 | /** Process object. */
|
---|
509 | SESSIONOBJECTTYPE_PROCESS = 4,
|
---|
510 | /** The usual 32-bit hack. */
|
---|
511 | SESSIONOBJECTTYPE_32BIT_HACK = 0x7fffffff
|
---|
512 | };
|
---|
513 |
|
---|
514 | struct SessionObject
|
---|
515 | {
|
---|
516 | /** Creation timestamp (in ms). */
|
---|
517 | uint64_t tsCreatedMs;
|
---|
518 | /** The object type. */
|
---|
519 | SESSIONOBJECTTYPE enmType;
|
---|
520 | };
|
---|
521 |
|
---|
522 | /** Map containing all objects bound to a guest session.
|
---|
523 | * The key specifies the (global) context ID. */
|
---|
524 | typedef std::map <uint32_t, SessionObject> SessionObjects;
|
---|
525 | /** Queue containing context IDs which are no longer in use.
|
---|
526 | * Useful for quickly retrieving a new, unused context ID. */
|
---|
527 | typedef std::deque <uint32_t> SessionObjectsFree;
|
---|
528 |
|
---|
529 | public:
|
---|
530 | /** @name Public internal methods.
|
---|
531 | * @todo r=bird: Most of these are public for no real reason...
|
---|
532 | * @{ */
|
---|
533 | int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc);
|
---|
534 | inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
|
---|
535 | int i_directoryUnregister(GuestDirectory *pDirectory);
|
---|
536 | int i_directoryRemove(const Utf8Str &strPath, uint32_t uFlags, int *pGuestRc);
|
---|
537 | int i_directoryCreate(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
|
---|
538 | int i_directoryOpen(const GuestDirectoryOpenInfo &openInfo,
|
---|
539 | ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc);
|
---|
540 | int i_directoryQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
541 | int i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
542 | int i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
543 | inline bool i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile);
|
---|
544 | int i_fileUnregister(GuestFile *pFile);
|
---|
545 | int i_fileRemove(const Utf8Str &strPath, int *pGuestRc);
|
---|
546 | int i_fileOpen(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
|
---|
547 | int i_fileQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
548 | int i_fileQuerySize(const Utf8Str &strPath, bool fFollowSymlinks, int64_t *pllSize, int *pGuestRc);
|
---|
549 | int i_fsCreateTemp(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory,
|
---|
550 | Utf8Str &strName, int *pGuestRc);
|
---|
551 | int i_fsQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
552 | const GuestCredentials &i_getCredentials(void);
|
---|
553 | EventSource *i_getEventSource(void) { return mEventSource; }
|
---|
554 | Utf8Str i_getName(void);
|
---|
555 | ULONG i_getId(void) { return mData.mSession.mID; }
|
---|
556 | static Utf8Str i_guestErrorToString(int guestRc);
|
---|
557 | HRESULT i_isReadyExternal(void);
|
---|
558 | int i_onRemove(void);
|
---|
559 | int i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
560 | int i_startSession(int *pGuestRc);
|
---|
561 | int i_startSessionAsync(void);
|
---|
562 | static void i_startSessionThreadTask(GuestSessionTaskInternalOpen *pTask);
|
---|
563 | Guest *i_getParent(void) { return mParent; }
|
---|
564 | uint32_t i_getProtocolVersion(void) { return mData.mProtocolVersion; }
|
---|
565 | int i_objectRegister(SESSIONOBJECTTYPE enmType, uint32_t *puObjectID);
|
---|
566 | int i_objectRegisterEx(SESSIONOBJECTTYPE enmType, uint32_t fFlags, uint32_t *puObjectID);
|
---|
567 | int i_objectUnregister(uint32_t uObjectID);
|
---|
568 | int i_pathRename(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, int *pGuestRc);
|
---|
569 | int i_pathUserDocuments(Utf8Str &strPath, int *prcGuest);
|
---|
570 | int i_pathUserHome(Utf8Str &strPath, int *prcGuest);
|
---|
571 | int i_processUnregister(GuestProcess *pProcess);
|
---|
572 | int i_processCreateEx(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
|
---|
573 | inline bool i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
|
---|
574 | inline int i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
|
---|
575 | int i_sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
|
---|
576 | static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
|
---|
577 | int i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc);
|
---|
578 | int i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */);
|
---|
579 | int i_determineProtocolVersion(void);
|
---|
580 | int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc);
|
---|
581 | int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
582 | GuestSessionStatus_T *pSessionStatus, int *pGuestRc);
|
---|
583 | /** @} */
|
---|
584 |
|
---|
585 | private:
|
---|
586 |
|
---|
587 | /** Pointer to the parent (Guest). */
|
---|
588 | Guest *mParent;
|
---|
589 | /**
|
---|
590 | * The session's event source. This source is used for
|
---|
591 | * serving the internal listener as well as all other
|
---|
592 | * external listeners that may register to it.
|
---|
593 | *
|
---|
594 | * Note: This can safely be used without holding any locks.
|
---|
595 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
596 | * internally there is a lock providing the necessary serialization.
|
---|
597 | */
|
---|
598 | const ComObjPtr<EventSource> mEventSource;
|
---|
599 |
|
---|
600 | struct Data
|
---|
601 | {
|
---|
602 | /** The session credentials. */
|
---|
603 | GuestCredentials mCredentials;
|
---|
604 | /** The session's startup info. */
|
---|
605 | GuestSessionStartupInfo mSession;
|
---|
606 | /** The session's object ID.
|
---|
607 | * Needed for registering wait events which are bound directly to this session. */
|
---|
608 | uint32_t mObjectID;
|
---|
609 | /** The session's current status. */
|
---|
610 | GuestSessionStatus_T mStatus;
|
---|
611 | /** The set of environment changes for the session for use when
|
---|
612 | * creating new guest processes. */
|
---|
613 | GuestEnvironmentChanges mEnvironmentChanges;
|
---|
614 | /** Pointer to the immutable base environment for the session.
|
---|
615 | * @note This is not allocated until the guest reports it to the host. It is
|
---|
616 | * also shared with child processes. */
|
---|
617 | GuestEnvironment const *mpBaseEnvironment;
|
---|
618 | /** Directory objects bound to this session. */
|
---|
619 | SessionDirectories mDirectories;
|
---|
620 | /** File objects bound to this session. */
|
---|
621 | SessionFiles mFiles;
|
---|
622 | /** Process objects bound to this session. */
|
---|
623 | SessionProcesses mProcesses;
|
---|
624 | /** Map of registered session objects (files, directories, ...). */
|
---|
625 | SessionObjects mObjects;
|
---|
626 | /** Queue of object IDs which are not used anymore (free list).
|
---|
627 | * Acts as a "free list" for the mObjects map. */
|
---|
628 | SessionObjectsFree mObjectsFree;
|
---|
629 | /** Guest control protocol version to be used.
|
---|
630 | * Guest Additions < VBox 4.3 have version 1,
|
---|
631 | * any newer version will have version 2. */
|
---|
632 | uint32_t mProtocolVersion;
|
---|
633 | /** Session timeout (in ms). */
|
---|
634 | uint32_t mTimeout;
|
---|
635 | /** The last returned session status
|
---|
636 | * returned from the guest side. */
|
---|
637 | int mRC;
|
---|
638 |
|
---|
639 | Data(void)
|
---|
640 | : mpBaseEnvironment(NULL)
|
---|
641 | { }
|
---|
642 | Data(const Data &rThat)
|
---|
643 | : mCredentials(rThat.mCredentials)
|
---|
644 | , mSession(rThat.mSession)
|
---|
645 | , mStatus(rThat.mStatus)
|
---|
646 | , mEnvironmentChanges(rThat.mEnvironmentChanges)
|
---|
647 | , mpBaseEnvironment(NULL)
|
---|
648 | , mDirectories(rThat.mDirectories)
|
---|
649 | , mFiles(rThat.mFiles)
|
---|
650 | , mProcesses(rThat.mProcesses)
|
---|
651 | , mObjects(rThat.mObjects)
|
---|
652 | , mObjectsFree(rThat.mObjectsFree)
|
---|
653 | , mProtocolVersion(rThat.mProtocolVersion)
|
---|
654 | , mTimeout(rThat.mTimeout)
|
---|
655 | , mRC(rThat.mRC)
|
---|
656 | { }
|
---|
657 | ~Data(void)
|
---|
658 | {
|
---|
659 | if (mpBaseEnvironment)
|
---|
660 | {
|
---|
661 | mpBaseEnvironment->releaseConst();
|
---|
662 | mpBaseEnvironment = NULL;
|
---|
663 | }
|
---|
664 | }
|
---|
665 | } mData;
|
---|
666 | };
|
---|
667 |
|
---|
668 | #endif /* !____H_GUESTSESSIONIMPL */
|
---|
669 |
|
---|