1 |
|
---|
2 | /* $Id: GuestSessionImpl.cpp 45434 2013-04-09 13:51:55Z vboxsync $ */
|
---|
3 | /** @file
|
---|
4 | * VirtualBox Main - Guest session handling.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012-2013 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | /*******************************************************************************
|
---|
21 | * Header Files *
|
---|
22 | *******************************************************************************/
|
---|
23 | #include "GuestImpl.h"
|
---|
24 | #include "GuestErrorInfoImpl.h"
|
---|
25 | #include "GuestSessionImpl.h"
|
---|
26 | #include "GuestCtrlImplPrivate.h"
|
---|
27 |
|
---|
28 | #include "Global.h"
|
---|
29 | #include "AutoCaller.h"
|
---|
30 | #include "ProgressImpl.h"
|
---|
31 | #include "VBoxEvents.h"
|
---|
32 | #include "VMMDev.h"
|
---|
33 |
|
---|
34 | #include <memory> /* For auto_ptr. */
|
---|
35 |
|
---|
36 | #include <iprt/cpp/utils.h> /* For unconst(). */
|
---|
37 | #include <iprt/env.h>
|
---|
38 | #include <iprt/file.h> /* For CopyTo/From. */
|
---|
39 |
|
---|
40 | #include <VBox/com/array.h>
|
---|
41 | #include <VBox/com/listeners.h>
|
---|
42 | #include <VBox/version.h>
|
---|
43 |
|
---|
44 | #ifdef LOG_GROUP
|
---|
45 | #undef LOG_GROUP
|
---|
46 | #endif
|
---|
47 | #define LOG_GROUP LOG_GROUP_GUEST_CONTROL
|
---|
48 | #include <VBox/log.h>
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Base class representing an internal
|
---|
53 | * asynchronous session task.
|
---|
54 | */
|
---|
55 | class GuestSessionTaskInternal
|
---|
56 | {
|
---|
57 | public:
|
---|
58 |
|
---|
59 | GuestSessionTaskInternal(GuestSession *pSession)
|
---|
60 | : mSession(pSession),
|
---|
61 | mRC(VINF_SUCCESS) { }
|
---|
62 |
|
---|
63 | virtual ~GuestSessionTaskInternal(void) { }
|
---|
64 |
|
---|
65 | int rc(void) const { return mRC; }
|
---|
66 | bool isOk(void) const { return RT_SUCCESS(mRC); }
|
---|
67 | const ComObjPtr<GuestSession> &Session(void) const { return mSession; }
|
---|
68 |
|
---|
69 | protected:
|
---|
70 |
|
---|
71 | const ComObjPtr<GuestSession> mSession;
|
---|
72 | int mRC;
|
---|
73 | };
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Class for asynchronously opening a guest session.
|
---|
77 | */
|
---|
78 | class GuestSessionTaskInternalOpen : public GuestSessionTaskInternal
|
---|
79 | {
|
---|
80 | public:
|
---|
81 |
|
---|
82 | GuestSessionTaskInternalOpen(GuestSession *pSession)
|
---|
83 | : GuestSessionTaskInternal(pSession) { }
|
---|
84 | };
|
---|
85 |
|
---|
86 | // constructor / destructor
|
---|
87 | /////////////////////////////////////////////////////////////////////////////
|
---|
88 |
|
---|
89 | DEFINE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
90 |
|
---|
91 | HRESULT GuestSession::FinalConstruct(void)
|
---|
92 | {
|
---|
93 | LogFlowThisFunc(("\n"));
|
---|
94 | return BaseFinalConstruct();
|
---|
95 | }
|
---|
96 |
|
---|
97 | void GuestSession::FinalRelease(void)
|
---|
98 | {
|
---|
99 | LogFlowThisFuncEnter();
|
---|
100 | uninit();
|
---|
101 | BaseFinalRelease();
|
---|
102 | LogFlowThisFuncLeave();
|
---|
103 | }
|
---|
104 |
|
---|
105 | // public initializer/uninitializer for internal purposes only
|
---|
106 | /////////////////////////////////////////////////////////////////////////////
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Initializes a guest session but does *not* open in on the guest side
|
---|
110 | * yet. This needs to be done via the openSession() / openSessionAsync calls.
|
---|
111 | *
|
---|
112 | * @return IPRT status code.
|
---|
113 | ** @todo Docs!
|
---|
114 | */
|
---|
115 | int GuestSession::init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo,
|
---|
116 | const GuestCredentials &guestCreds)
|
---|
117 | {
|
---|
118 | LogFlowThisFunc(("pGuest=%p, ssInfo=%p, guestCreds=%p\n",
|
---|
119 | pGuest, &ssInfo, &guestCreds));
|
---|
120 |
|
---|
121 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
122 | AutoInitSpan autoInitSpan(this);
|
---|
123 | AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
|
---|
124 |
|
---|
125 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
126 | autoInitSpan.setSucceeded();
|
---|
127 | return VINF_SUCCESS;
|
---|
128 | #else
|
---|
129 | AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
|
---|
130 |
|
---|
131 | mParent = pGuest;
|
---|
132 |
|
---|
133 | /* Copy over startup info. */
|
---|
134 | /** @todo Use an overloaded copy operator. Later. */
|
---|
135 | mData.mSession.mID = ssInfo.mID;
|
---|
136 | mData.mSession.mIsInternal = ssInfo.mIsInternal;
|
---|
137 | mData.mSession.mName = ssInfo.mName;
|
---|
138 | mData.mSession.mOpenFlags = ssInfo.mOpenFlags;
|
---|
139 | mData.mSession.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
|
---|
140 |
|
---|
141 | /** @todo Use an overloaded copy operator. Later. */
|
---|
142 | mData.mCredentials.mUser = guestCreds.mUser;
|
---|
143 | mData.mCredentials.mPassword = guestCreds.mPassword;
|
---|
144 | mData.mCredentials.mDomain = guestCreds.mDomain;
|
---|
145 |
|
---|
146 | mData.mRC = VINF_SUCCESS;
|
---|
147 | mData.mStatus = GuestSessionStatus_Undefined;
|
---|
148 | mData.mNumObjects = 0;
|
---|
149 |
|
---|
150 | int rc = queryInfo();
|
---|
151 | if (RT_SUCCESS(rc))
|
---|
152 | {
|
---|
153 | unconst(mEventSource).createObject();
|
---|
154 | Assert(!mEventSource.isNull());
|
---|
155 | HRESULT hr = mEventSource->init(static_cast<IGuestSession*>(this));
|
---|
156 | if (FAILED(hr))
|
---|
157 | rc = VERR_COM_UNEXPECTED;
|
---|
158 | }
|
---|
159 |
|
---|
160 | if (RT_SUCCESS(rc))
|
---|
161 | {
|
---|
162 | /* Confirm a successful initialization when it's the case. */
|
---|
163 | autoInitSpan.setSucceeded();
|
---|
164 | }
|
---|
165 | else
|
---|
166 | autoInitSpan.setFailed();
|
---|
167 |
|
---|
168 | LogFlowFuncLeaveRC(rc);
|
---|
169 | return rc;
|
---|
170 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
171 | }
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Uninitializes the instance.
|
---|
175 | * Called from FinalRelease().
|
---|
176 | */
|
---|
177 | void GuestSession::uninit(void)
|
---|
178 | {
|
---|
179 | LogFlowThisFuncEnter();
|
---|
180 |
|
---|
181 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
182 | AutoUninitSpan autoUninitSpan(this);
|
---|
183 | if (autoUninitSpan.uninitDone())
|
---|
184 | return;
|
---|
185 |
|
---|
186 | int rc = VINF_SUCCESS;
|
---|
187 |
|
---|
188 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
189 | LogFlowThisFunc(("Closing directories (%RU64 total)\n",
|
---|
190 | mData.mDirectories.size()));
|
---|
191 | for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
|
---|
192 | itDirs != mData.mDirectories.end(); ++itDirs)
|
---|
193 | {
|
---|
194 | (*itDirs)->uninit();
|
---|
195 | }
|
---|
196 | mData.mDirectories.clear();
|
---|
197 |
|
---|
198 | LogFlowThisFunc(("Closing files (%RU64 total)\n",
|
---|
199 | mData.mFiles.size()));
|
---|
200 | for (SessionFiles::iterator itFiles = mData.mFiles.begin();
|
---|
201 | itFiles != mData.mFiles.end(); ++itFiles)
|
---|
202 | {
|
---|
203 | itFiles->second->uninit();
|
---|
204 | }
|
---|
205 | mData.mFiles.clear();
|
---|
206 |
|
---|
207 | LogFlowThisFunc(("Closing processes (%RU64 total)\n",
|
---|
208 | mData.mProcesses.size()));
|
---|
209 | for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
210 | itProcs != mData.mProcesses.end(); ++itProcs)
|
---|
211 | {
|
---|
212 | itProcs->second->uninit();
|
---|
213 | }
|
---|
214 | mData.mProcesses.clear();
|
---|
215 |
|
---|
216 | LogFlowThisFunc(("mNumObjects=%RU32\n", mData.mNumObjects));
|
---|
217 |
|
---|
218 | unconst(mEventSource).setNull();
|
---|
219 |
|
---|
220 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
221 | LogFlowFuncLeaveRC(rc);
|
---|
222 | }
|
---|
223 |
|
---|
224 | // implementation of public getters/setters for attributes
|
---|
225 | /////////////////////////////////////////////////////////////////////////////
|
---|
226 |
|
---|
227 | STDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
|
---|
228 | {
|
---|
229 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
230 | ReturnComNotImplemented();
|
---|
231 | #else
|
---|
232 | LogFlowThisFuncEnter();
|
---|
233 |
|
---|
234 | CheckComArgOutPointerValid(aUser);
|
---|
235 |
|
---|
236 | AutoCaller autoCaller(this);
|
---|
237 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
238 |
|
---|
239 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
240 |
|
---|
241 | mData.mCredentials.mUser.cloneTo(aUser);
|
---|
242 |
|
---|
243 | LogFlowFuncLeaveRC(S_OK);
|
---|
244 | return S_OK;
|
---|
245 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
246 | }
|
---|
247 |
|
---|
248 | STDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
|
---|
249 | {
|
---|
250 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
251 | ReturnComNotImplemented();
|
---|
252 | #else
|
---|
253 | LogFlowThisFuncEnter();
|
---|
254 |
|
---|
255 | CheckComArgOutPointerValid(aDomain);
|
---|
256 |
|
---|
257 | AutoCaller autoCaller(this);
|
---|
258 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
259 |
|
---|
260 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
261 |
|
---|
262 | mData.mCredentials.mDomain.cloneTo(aDomain);
|
---|
263 |
|
---|
264 | LogFlowFuncLeaveRC(S_OK);
|
---|
265 | return S_OK;
|
---|
266 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
267 | }
|
---|
268 |
|
---|
269 | STDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
|
---|
270 | {
|
---|
271 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
272 | ReturnComNotImplemented();
|
---|
273 | #else
|
---|
274 | LogFlowThisFuncEnter();
|
---|
275 |
|
---|
276 | CheckComArgOutPointerValid(aName);
|
---|
277 |
|
---|
278 | AutoCaller autoCaller(this);
|
---|
279 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
280 |
|
---|
281 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
282 |
|
---|
283 | mData.mSession.mName.cloneTo(aName);
|
---|
284 |
|
---|
285 | LogFlowFuncLeaveRC(S_OK);
|
---|
286 | return S_OK;
|
---|
287 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
288 | }
|
---|
289 |
|
---|
290 | STDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
|
---|
291 | {
|
---|
292 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
293 | ReturnComNotImplemented();
|
---|
294 | #else
|
---|
295 | LogFlowThisFuncEnter();
|
---|
296 |
|
---|
297 | CheckComArgOutPointerValid(aId);
|
---|
298 |
|
---|
299 | AutoCaller autoCaller(this);
|
---|
300 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
301 |
|
---|
302 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
303 |
|
---|
304 | *aId = mData.mSession.mID;
|
---|
305 |
|
---|
306 | LogFlowFuncLeaveRC(S_OK);
|
---|
307 | return S_OK;
|
---|
308 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
309 | }
|
---|
310 |
|
---|
311 | STDMETHODIMP GuestSession::COMGETTER(Status)(GuestSessionStatus_T *aStatus)
|
---|
312 | {
|
---|
313 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
314 | ReturnComNotImplemented();
|
---|
315 | #else
|
---|
316 | LogFlowThisFuncEnter();
|
---|
317 |
|
---|
318 | CheckComArgOutPointerValid(aStatus);
|
---|
319 |
|
---|
320 | AutoCaller autoCaller(this);
|
---|
321 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
322 |
|
---|
323 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
324 |
|
---|
325 | *aStatus = mData.mStatus;
|
---|
326 |
|
---|
327 | LogFlowFuncLeaveRC(S_OK);
|
---|
328 | return S_OK;
|
---|
329 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
330 | }
|
---|
331 |
|
---|
332 | STDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
|
---|
333 | {
|
---|
334 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
335 | ReturnComNotImplemented();
|
---|
336 | #else
|
---|
337 | LogFlowThisFuncEnter();
|
---|
338 |
|
---|
339 | CheckComArgOutPointerValid(aTimeout);
|
---|
340 |
|
---|
341 | AutoCaller autoCaller(this);
|
---|
342 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
343 |
|
---|
344 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
345 |
|
---|
346 | *aTimeout = mData.mTimeout;
|
---|
347 |
|
---|
348 | LogFlowFuncLeaveRC(S_OK);
|
---|
349 | return S_OK;
|
---|
350 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
351 | }
|
---|
352 |
|
---|
353 | STDMETHODIMP GuestSession::COMSETTER(Timeout)(ULONG aTimeout)
|
---|
354 | {
|
---|
355 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
356 | ReturnComNotImplemented();
|
---|
357 | #else
|
---|
358 | LogFlowThisFuncEnter();
|
---|
359 |
|
---|
360 | AutoCaller autoCaller(this);
|
---|
361 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
362 |
|
---|
363 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
364 |
|
---|
365 | mData.mTimeout = aTimeout;
|
---|
366 |
|
---|
367 | LogFlowFuncLeaveRC(S_OK);
|
---|
368 | return S_OK;
|
---|
369 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
370 | }
|
---|
371 |
|
---|
372 | STDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
|
---|
373 | {
|
---|
374 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
375 | ReturnComNotImplemented();
|
---|
376 | #else
|
---|
377 | LogFlowThisFuncEnter();
|
---|
378 |
|
---|
379 | CheckComArgOutSafeArrayPointerValid(aEnvironment);
|
---|
380 |
|
---|
381 | AutoCaller autoCaller(this);
|
---|
382 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
383 |
|
---|
384 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
385 |
|
---|
386 | size_t cEnvVars = mData.mEnvironment.Size();
|
---|
387 | LogFlowThisFunc(("[%s]: cEnvVars=%RU32\n",
|
---|
388 | mData.mSession.mName.c_str(), cEnvVars));
|
---|
389 | com::SafeArray<BSTR> environment(cEnvVars);
|
---|
390 |
|
---|
391 | for (size_t i = 0; i < cEnvVars; i++)
|
---|
392 | {
|
---|
393 | Bstr strEnv(mData.mEnvironment.Get(i));
|
---|
394 | strEnv.cloneTo(&environment[i]);
|
---|
395 | }
|
---|
396 | environment.detachTo(ComSafeArrayOutArg(aEnvironment));
|
---|
397 |
|
---|
398 | LogFlowFuncLeaveRC(S_OK);
|
---|
399 | return S_OK;
|
---|
400 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
401 | }
|
---|
402 |
|
---|
403 | STDMETHODIMP GuestSession::COMSETTER(Environment)(ComSafeArrayIn(IN_BSTR, aValues))
|
---|
404 | {
|
---|
405 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
406 | ReturnComNotImplemented();
|
---|
407 | #else
|
---|
408 | LogFlowThisFuncEnter();
|
---|
409 |
|
---|
410 | AutoCaller autoCaller(this);
|
---|
411 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
412 |
|
---|
413 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
414 |
|
---|
415 | com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
|
---|
416 |
|
---|
417 | int rc = VINF_SUCCESS;
|
---|
418 | for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
|
---|
419 | {
|
---|
420 | Utf8Str strEnv(environment[i]);
|
---|
421 | if (!strEnv.isEmpty()) /* Silently skip empty entries. */
|
---|
422 | rc = mData.mEnvironment.Set(strEnv);
|
---|
423 | }
|
---|
424 |
|
---|
425 | HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
|
---|
426 | LogFlowFuncLeaveRC(hr);
|
---|
427 | return hr;
|
---|
428 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
429 | }
|
---|
430 |
|
---|
431 | STDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
|
---|
432 | {
|
---|
433 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
434 | ReturnComNotImplemented();
|
---|
435 | #else
|
---|
436 | LogFlowThisFuncEnter();
|
---|
437 |
|
---|
438 | CheckComArgOutSafeArrayPointerValid(aProcesses);
|
---|
439 |
|
---|
440 | AutoCaller autoCaller(this);
|
---|
441 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
442 |
|
---|
443 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
444 |
|
---|
445 | SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
|
---|
446 | collection.detachTo(ComSafeArrayOutArg(aProcesses));
|
---|
447 |
|
---|
448 | LogFlowFuncLeaveRC(S_OK);
|
---|
449 | return S_OK;
|
---|
450 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
451 | }
|
---|
452 |
|
---|
453 | STDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
|
---|
454 | {
|
---|
455 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
456 | ReturnComNotImplemented();
|
---|
457 | #else
|
---|
458 | LogFlowThisFuncEnter();
|
---|
459 |
|
---|
460 | CheckComArgOutSafeArrayPointerValid(aDirectories);
|
---|
461 |
|
---|
462 | AutoCaller autoCaller(this);
|
---|
463 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
464 |
|
---|
465 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
466 |
|
---|
467 | SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
|
---|
468 | collection.detachTo(ComSafeArrayOutArg(aDirectories));
|
---|
469 |
|
---|
470 | LogFlowFuncLeaveRC(S_OK);
|
---|
471 | return S_OK;
|
---|
472 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
473 | }
|
---|
474 |
|
---|
475 | STDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
|
---|
476 | {
|
---|
477 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
478 | ReturnComNotImplemented();
|
---|
479 | #else
|
---|
480 | LogFlowThisFuncEnter();
|
---|
481 |
|
---|
482 | CheckComArgOutSafeArrayPointerValid(aFiles);
|
---|
483 |
|
---|
484 | AutoCaller autoCaller(this);
|
---|
485 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
486 |
|
---|
487 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
488 |
|
---|
489 | SafeIfaceArray<IGuestFile> collection(mData.mFiles);
|
---|
490 | collection.detachTo(ComSafeArrayOutArg(aFiles));
|
---|
491 |
|
---|
492 | LogFlowFuncLeaveRC(S_OK);
|
---|
493 | return S_OK;
|
---|
494 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
495 | }
|
---|
496 |
|
---|
497 | STDMETHODIMP GuestSession::COMGETTER(EventSource)(IEventSource ** aEventSource)
|
---|
498 | {
|
---|
499 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
500 | ReturnComNotImplemented();
|
---|
501 | #else
|
---|
502 | LogFlowThisFuncEnter();
|
---|
503 |
|
---|
504 | CheckComArgOutPointerValid(aEventSource);
|
---|
505 |
|
---|
506 | AutoCaller autoCaller(this);
|
---|
507 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
508 |
|
---|
509 | // no need to lock - lifetime constant
|
---|
510 | mEventSource.queryInterfaceTo(aEventSource);
|
---|
511 |
|
---|
512 | LogFlowFuncLeaveRC(S_OK);
|
---|
513 | return S_OK;
|
---|
514 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
515 | }
|
---|
516 |
|
---|
517 | // private methods
|
---|
518 | ///////////////////////////////////////////////////////////////////////////////
|
---|
519 |
|
---|
520 | int GuestSession::closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc)
|
---|
521 | {
|
---|
522 | LogFlowThisFunc(("uFlags=%x, uTimeoutMS=%RU32\n", uFlags, uTimeoutMS));
|
---|
523 |
|
---|
524 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
525 |
|
---|
526 | /* Legacy Guest Additions don't support opening dedicated
|
---|
527 | guest sessions. */
|
---|
528 | if (mData.mProtocolVersion < 2)
|
---|
529 | {
|
---|
530 | LogFlowThisFunc(("Installed Guest Additions don't support closing dedicated sessions, skipping\n"));
|
---|
531 | return VINF_SUCCESS;
|
---|
532 | }
|
---|
533 |
|
---|
534 | /** @todo uFlags validation. */
|
---|
535 |
|
---|
536 | if (mData.mStatus != GuestSessionStatus_Started)
|
---|
537 | return VINF_SUCCESS;
|
---|
538 |
|
---|
539 | uint32_t uContextID;
|
---|
540 | int vrc = generateContextID(mData.mSession.mID, 0 /* Object ID */,
|
---|
541 | &uContextID);
|
---|
542 | if (RT_SUCCESS(vrc))
|
---|
543 | {
|
---|
544 | if (RT_SUCCESS(vrc))
|
---|
545 | {
|
---|
546 | LogFlowThisFunc(("Sending closing request to guest session ID=%RU32, uFlags=%x\n",
|
---|
547 | mData.mSession.mID, uFlags));
|
---|
548 |
|
---|
549 | VBOXHGCMSVCPARM paParms[4];
|
---|
550 | int i = 0;
|
---|
551 | paParms[i++].setUInt32(uContextID);
|
---|
552 | paParms[i++].setUInt32(uFlags);
|
---|
553 |
|
---|
554 | vrc = sendCommand(HOST_SESSION_CLOSE, i, paParms);
|
---|
555 | }
|
---|
556 |
|
---|
557 | if (RT_SUCCESS(vrc))
|
---|
558 | {
|
---|
559 | alock.release(); /* Drop the write lock before waiting. */
|
---|
560 |
|
---|
561 | vrc = waitForStateChange(GuestSessionWaitForFlag_Terminate, uTimeoutMS,
|
---|
562 | NULL /* Session status */, pGuestRc);
|
---|
563 | }
|
---|
564 | }
|
---|
565 |
|
---|
566 | LogFlowFuncLeaveRC(vrc);
|
---|
567 | return vrc;
|
---|
568 | }
|
---|
569 |
|
---|
570 | int GuestSession::directoryRemoveFromList(GuestDirectory *pDirectory)
|
---|
571 | {
|
---|
572 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
573 |
|
---|
574 | for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
|
---|
575 | itDirs != mData.mDirectories.end(); ++itDirs)
|
---|
576 | {
|
---|
577 | if (pDirectory == (*itDirs))
|
---|
578 | {
|
---|
579 | Bstr strName;
|
---|
580 | HRESULT hr = (*itDirs)->COMGETTER(DirectoryName)(strName.asOutParam());
|
---|
581 | ComAssertComRC(hr);
|
---|
582 |
|
---|
583 | Assert(mData.mDirectories.size());
|
---|
584 | LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %ld directories)\n",
|
---|
585 | Utf8Str(strName).c_str(), mData.mSession.mID, mData.mDirectories.size() - 1));
|
---|
586 |
|
---|
587 | mData.mDirectories.erase(itDirs);
|
---|
588 | return VINF_SUCCESS;
|
---|
589 | }
|
---|
590 | }
|
---|
591 |
|
---|
592 | return VERR_NOT_FOUND;
|
---|
593 | }
|
---|
594 |
|
---|
595 | int GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc)
|
---|
596 | {
|
---|
597 | /* pGuestRc is optional. */
|
---|
598 |
|
---|
599 | LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
|
---|
600 | strPath.c_str(), uMode, uFlags));
|
---|
601 |
|
---|
602 | GuestProcessStartupInfo procInfo;
|
---|
603 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
|
---|
604 | procInfo.mFlags = ProcessCreateFlag_Hidden;
|
---|
605 |
|
---|
606 | int vrc = VINF_SUCCESS;
|
---|
607 |
|
---|
608 | /* Construct arguments. */
|
---|
609 | if (uFlags & DirectoryCreateFlag_Parents)
|
---|
610 | procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
|
---|
611 | if (uMode)
|
---|
612 | {
|
---|
613 | procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
|
---|
614 |
|
---|
615 | char szMode[16];
|
---|
616 | if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
|
---|
617 | {
|
---|
618 | procInfo.mArguments.push_back(Utf8Str(szMode));
|
---|
619 | }
|
---|
620 | else
|
---|
621 | vrc = VERR_BUFFER_OVERFLOW;
|
---|
622 | }
|
---|
623 | procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
|
---|
624 |
|
---|
625 | if (RT_SUCCESS(vrc))
|
---|
626 | {
|
---|
627 | int guestRc;
|
---|
628 | GuestProcessTool procTool;
|
---|
629 | vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
630 | if (RT_SUCCESS(vrc))
|
---|
631 | {
|
---|
632 | if (RT_SUCCESS(guestRc))
|
---|
633 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
634 | }
|
---|
635 |
|
---|
636 | if (RT_SUCCESS(vrc))
|
---|
637 | {
|
---|
638 | if (RT_SUCCESS(guestRc))
|
---|
639 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
640 | }
|
---|
641 |
|
---|
642 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
643 | && pGuestRc)
|
---|
644 | {
|
---|
645 | *pGuestRc = guestRc;
|
---|
646 | }
|
---|
647 | }
|
---|
648 |
|
---|
649 | LogFlowFuncLeaveRC(vrc);
|
---|
650 | return vrc;
|
---|
651 | }
|
---|
652 |
|
---|
653 | int GuestSession::directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
|
---|
654 | {
|
---|
655 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
656 |
|
---|
657 | int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
|
---|
658 | if (RT_SUCCESS(vrc))
|
---|
659 | {
|
---|
660 | vrc = objData.mType == FsObjType_Directory
|
---|
661 | ? VINF_SUCCESS : VERR_NOT_A_DIRECTORY;
|
---|
662 | }
|
---|
663 |
|
---|
664 | LogFlowFuncLeaveRC(vrc);
|
---|
665 | return vrc;
|
---|
666 | }
|
---|
667 |
|
---|
668 | int GuestSession::objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath,
|
---|
669 | bool fDirectory, const Utf8Str &strName, int *pGuestRc)
|
---|
670 | {
|
---|
671 | GuestProcessStartupInfo procInfo;
|
---|
672 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
|
---|
673 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
674 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
675 | if (fDirectory)
|
---|
676 | procInfo.mArguments.push_back(Utf8Str("-d"));
|
---|
677 | if (strPath.length()) /* Otherwise use /tmp or equivalent. */
|
---|
678 | {
|
---|
679 | procInfo.mArguments.push_back(Utf8Str("-t"));
|
---|
680 | procInfo.mArguments.push_back(strPath);
|
---|
681 | }
|
---|
682 | procInfo.mArguments.push_back(strTemplate);
|
---|
683 |
|
---|
684 | GuestProcessTool procTool; int guestRc;
|
---|
685 | int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
686 | if (RT_SUCCESS(vrc))
|
---|
687 | {
|
---|
688 | if (RT_SUCCESS(guestRc))
|
---|
689 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
690 | }
|
---|
691 |
|
---|
692 | if (RT_SUCCESS(vrc))
|
---|
693 | {
|
---|
694 | if (RT_SUCCESS(guestRc))
|
---|
695 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
696 | }
|
---|
697 |
|
---|
698 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
699 | && pGuestRc)
|
---|
700 | {
|
---|
701 | *pGuestRc = guestRc;
|
---|
702 | }
|
---|
703 |
|
---|
704 | LogFlowFuncLeaveRC(vrc);
|
---|
705 | return vrc;
|
---|
706 | }
|
---|
707 |
|
---|
708 | int GuestSession::directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter,
|
---|
709 | uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
|
---|
710 | {
|
---|
711 | LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
|
---|
712 | strPath.c_str(), strFilter.c_str(), uFlags));
|
---|
713 |
|
---|
714 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
715 |
|
---|
716 | /* Create the directory object. */
|
---|
717 | HRESULT hr = pDirectory.createObject();
|
---|
718 | if (FAILED(hr))
|
---|
719 | return VERR_COM_UNEXPECTED;
|
---|
720 |
|
---|
721 | int vrc = pDirectory->init(this /* Parent */,
|
---|
722 | strPath, strFilter, uFlags);
|
---|
723 | if (RT_FAILURE(vrc))
|
---|
724 | return vrc;
|
---|
725 |
|
---|
726 | /* Add the created directory to our vector. */
|
---|
727 | mData.mDirectories.push_back(pDirectory);
|
---|
728 |
|
---|
729 | LogFlowFunc(("Added new directory \"%s\" (Session: %RU32)\n",
|
---|
730 | strPath.c_str(), mData.mSession.mID));
|
---|
731 |
|
---|
732 | LogFlowFuncLeaveRC(vrc);
|
---|
733 | return vrc;
|
---|
734 | }
|
---|
735 |
|
---|
736 | int GuestSession::dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
737 | {
|
---|
738 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
739 |
|
---|
740 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
741 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
742 |
|
---|
743 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
744 |
|
---|
745 | uint32_t uFileID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
746 | #ifdef DEBUG
|
---|
747 | LogFlowFunc(("uFileID=%RU32 (%RU32 total)\n",
|
---|
748 | uFileID, mData.mFiles.size()));
|
---|
749 | #endif
|
---|
750 | int rc;
|
---|
751 | SessionFiles::const_iterator itFile
|
---|
752 | = mData.mFiles.find(uFileID);
|
---|
753 | if (itFile != mData.mFiles.end())
|
---|
754 | {
|
---|
755 | ComObjPtr<GuestFile> pFile(itFile->second);
|
---|
756 | Assert(!pFile.isNull());
|
---|
757 |
|
---|
758 | alock.release();
|
---|
759 |
|
---|
760 | rc = pFile->callbackDispatcher(pCtxCb, pSvcCb);
|
---|
761 | }
|
---|
762 | else
|
---|
763 | rc = VERR_NOT_FOUND;
|
---|
764 |
|
---|
765 | LogFlowFuncLeaveRC(rc);
|
---|
766 | return rc;
|
---|
767 | }
|
---|
768 |
|
---|
769 | int GuestSession::dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
770 | {
|
---|
771 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
772 |
|
---|
773 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
774 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
775 |
|
---|
776 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
777 |
|
---|
778 | uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
779 | #ifdef DEBUG
|
---|
780 | LogFlowFunc(("uProcessID=%RU32 (%RU32 total)\n",
|
---|
781 | uProcessID, mData.mProcesses.size()));
|
---|
782 | #endif
|
---|
783 | int rc;
|
---|
784 | SessionProcesses::const_iterator itProc
|
---|
785 | = mData.mProcesses.find(uProcessID);
|
---|
786 | if (itProc != mData.mProcesses.end())
|
---|
787 | {
|
---|
788 | ComObjPtr<GuestProcess> pProcess(itProc->second);
|
---|
789 | Assert(!pProcess.isNull());
|
---|
790 |
|
---|
791 | /* Set protocol version so that pSvcCb can
|
---|
792 | * be interpreted right. */
|
---|
793 | pCtxCb->uProtocol = mData.mProtocolVersion;
|
---|
794 |
|
---|
795 | alock.release();
|
---|
796 | rc = pProcess->callbackDispatcher(pCtxCb, pSvcCb);
|
---|
797 | }
|
---|
798 | else
|
---|
799 | rc = VERR_NOT_FOUND;
|
---|
800 |
|
---|
801 | LogFlowFuncLeaveRC(rc);
|
---|
802 | return rc;
|
---|
803 | }
|
---|
804 |
|
---|
805 | int GuestSession::dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
806 | {
|
---|
807 | AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
|
---|
808 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
809 |
|
---|
810 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
811 |
|
---|
812 | #ifdef DEBUG
|
---|
813 | LogFlowThisFunc(("sessionID=%RU32, CID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
|
---|
814 | mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb));
|
---|
815 | #endif
|
---|
816 |
|
---|
817 | int rc = VINF_SUCCESS;
|
---|
818 | switch (pCbCtx->uFunction)
|
---|
819 | {
|
---|
820 | case GUEST_DISCONNECTED:
|
---|
821 | /** @todo Handle closing all guest objects. */
|
---|
822 | break;
|
---|
823 |
|
---|
824 | case GUEST_SESSION_NOTIFY:
|
---|
825 | {
|
---|
826 | rc = onSessionStatusChange(pCbCtx, pSvcCb);
|
---|
827 | break;
|
---|
828 | }
|
---|
829 |
|
---|
830 | default:
|
---|
831 | /* Silently skip unknown callbacks. */
|
---|
832 | rc = VERR_NOT_SUPPORTED;
|
---|
833 | break;
|
---|
834 | }
|
---|
835 |
|
---|
836 | LogFlowFuncLeaveRC(rc);
|
---|
837 | return rc;
|
---|
838 | }
|
---|
839 |
|
---|
840 | inline bool GuestSession::fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile)
|
---|
841 | {
|
---|
842 | SessionFiles::const_iterator it = mData.mFiles.find(uFileID);
|
---|
843 | if (it != mData.mFiles.end())
|
---|
844 | {
|
---|
845 | if (pFile)
|
---|
846 | *pFile = it->second;
|
---|
847 | return true;
|
---|
848 | }
|
---|
849 | return false;
|
---|
850 | }
|
---|
851 |
|
---|
852 | int GuestSession::fileRemoveFromList(GuestFile *pFile)
|
---|
853 | {
|
---|
854 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
855 |
|
---|
856 | for (SessionFiles::iterator itFiles = mData.mFiles.begin();
|
---|
857 | itFiles != mData.mFiles.end(); ++itFiles)
|
---|
858 | {
|
---|
859 | if (pFile == itFiles->second)
|
---|
860 | {
|
---|
861 | GuestFile *pThis = itFiles->second;
|
---|
862 | AssertPtr(pThis);
|
---|
863 |
|
---|
864 | Bstr strName;
|
---|
865 | HRESULT hr = pThis->COMGETTER(FileName)(strName.asOutParam());
|
---|
866 | ComAssertComRC(hr);
|
---|
867 |
|
---|
868 | Assert(mData.mNumObjects);
|
---|
869 | LogFlowThisFunc(("Removing guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
|
---|
870 | Utf8Str(strName).c_str(), mData.mSession.mID, mData.mFiles.size() - 1, mData.mNumObjects - 1));
|
---|
871 |
|
---|
872 | mData.mFiles.erase(itFiles);
|
---|
873 | mData.mNumObjects--;
|
---|
874 |
|
---|
875 | fireGuestFileRegisteredEvent(mEventSource, this, pFile,
|
---|
876 | false /* Unregistered */);
|
---|
877 | return VINF_SUCCESS;
|
---|
878 | }
|
---|
879 | }
|
---|
880 |
|
---|
881 | return VERR_NOT_FOUND;
|
---|
882 | }
|
---|
883 |
|
---|
884 | int GuestSession::fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc)
|
---|
885 | {
|
---|
886 | GuestProcessStartupInfo procInfo;
|
---|
887 | GuestProcessStream streamOut;
|
---|
888 |
|
---|
889 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM);
|
---|
890 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
891 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
892 | procInfo.mArguments.push_back(strPath); /* The file we want to remove. */
|
---|
893 |
|
---|
894 | GuestProcessTool procTool; int guestRc;
|
---|
895 | int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
896 | if (RT_SUCCESS(vrc))
|
---|
897 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
898 |
|
---|
899 | if (RT_SUCCESS(vrc))
|
---|
900 | {
|
---|
901 | if (RT_SUCCESS(guestRc))
|
---|
902 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
903 | }
|
---|
904 |
|
---|
905 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
906 | && pGuestRc)
|
---|
907 | {
|
---|
908 | *pGuestRc = guestRc;
|
---|
909 | }
|
---|
910 |
|
---|
911 | LogFlowFuncLeaveRC(vrc);
|
---|
912 | return vrc;
|
---|
913 | }
|
---|
914 |
|
---|
915 | int GuestSession::fileOpenInternal(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc)
|
---|
916 | {
|
---|
917 | LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, iOffset=%RI64\n",
|
---|
918 | openInfo.mFileName.c_str(), openInfo.mOpenMode.c_str(), openInfo.mDisposition.c_str(),
|
---|
919 | openInfo.mCreationMode, openInfo.mInitialOffset));
|
---|
920 |
|
---|
921 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
922 |
|
---|
923 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
924 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
925 | return rc;
|
---|
926 |
|
---|
927 | /* Create a new (host-based) file ID and assign it. */
|
---|
928 | uint32_t uNewFileID = 0;
|
---|
929 | ULONG uTries = 0;
|
---|
930 |
|
---|
931 | for (;;)
|
---|
932 | {
|
---|
933 | /* Is the file ID already used? */
|
---|
934 | if (!fileExists(uNewFileID, NULL /* pProgress */))
|
---|
935 | {
|
---|
936 | /* Callback with context ID was not found. This means
|
---|
937 | * we can use this context ID for our new callback we want
|
---|
938 | * to add below. */
|
---|
939 | rc = VINF_SUCCESS;
|
---|
940 | break;
|
---|
941 | }
|
---|
942 | uNewFileID++;
|
---|
943 | if (uNewFileID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
944 | uNewFileID = 0;
|
---|
945 |
|
---|
946 | if (++uTries == UINT32_MAX)
|
---|
947 | break; /* Don't try too hard. */
|
---|
948 | }
|
---|
949 |
|
---|
950 | if (RT_FAILURE(rc))
|
---|
951 | return rc;
|
---|
952 |
|
---|
953 | /* Create the directory object. */
|
---|
954 | HRESULT hr = pFile.createObject();
|
---|
955 | if (FAILED(hr))
|
---|
956 | return VERR_COM_UNEXPECTED;
|
---|
957 |
|
---|
958 | Console *pConsole = mParent->getConsole();
|
---|
959 | AssertPtr(pConsole);
|
---|
960 |
|
---|
961 | rc = pFile->init(pConsole, this /* GuestSession */,
|
---|
962 | uNewFileID, openInfo);
|
---|
963 | if (RT_FAILURE(rc))
|
---|
964 | return rc;
|
---|
965 |
|
---|
966 | int guestRc;
|
---|
967 | rc = pFile->openFile(&guestRc);
|
---|
968 | if (RT_SUCCESS(rc))
|
---|
969 | {
|
---|
970 | /* Add the created file to our vector. */
|
---|
971 | mData.mFiles[uNewFileID] = pFile;
|
---|
972 | mData.mNumObjects++;
|
---|
973 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
974 |
|
---|
975 | LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
|
---|
976 | openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
|
---|
977 |
|
---|
978 | fireGuestFileRegisteredEvent(mEventSource, this, pFile,
|
---|
979 | true /* Registered */);
|
---|
980 | }
|
---|
981 |
|
---|
982 | if (pGuestRc)
|
---|
983 | *pGuestRc = guestRc;
|
---|
984 |
|
---|
985 | LogFlowFuncLeaveRC(rc);
|
---|
986 | return rc;
|
---|
987 | }
|
---|
988 |
|
---|
989 | int GuestSession::fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
|
---|
990 | {
|
---|
991 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
992 |
|
---|
993 | int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
|
---|
994 | if (RT_SUCCESS(vrc))
|
---|
995 | {
|
---|
996 | vrc = objData.mType == FsObjType_File
|
---|
997 | ? VINF_SUCCESS : VERR_NOT_A_FILE;
|
---|
998 | }
|
---|
999 |
|
---|
1000 | LogFlowFuncLeaveRC(vrc);
|
---|
1001 | return vrc;
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | int GuestSession::fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc)
|
---|
1005 | {
|
---|
1006 | AssertPtrReturn(pllSize, VERR_INVALID_POINTER);
|
---|
1007 |
|
---|
1008 | GuestFsObjData objData;
|
---|
1009 | int vrc = fileQueryInfoInternal(strPath, objData, pGuestRc);
|
---|
1010 | if (RT_SUCCESS(vrc))
|
---|
1011 | *pllSize = objData.mObjectSize;
|
---|
1012 |
|
---|
1013 | return vrc;
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | int GuestSession::fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
|
---|
1017 | {
|
---|
1018 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
1019 |
|
---|
1020 | /** @todo Merge this with IGuestFile::queryInfo(). */
|
---|
1021 | GuestProcessStartupInfo procInfo;
|
---|
1022 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
|
---|
1023 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
1024 |
|
---|
1025 | /* Construct arguments. */
|
---|
1026 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
1027 | procInfo.mArguments.push_back(strPath);
|
---|
1028 |
|
---|
1029 | GuestProcessTool procTool; int guestRc;
|
---|
1030 | int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
1031 | if (RT_SUCCESS(vrc))
|
---|
1032 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
1033 | if (RT_SUCCESS(vrc))
|
---|
1034 | {
|
---|
1035 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
1036 | if (RT_SUCCESS(guestRc))
|
---|
1037 | {
|
---|
1038 | GuestProcessStreamBlock curBlock;
|
---|
1039 | vrc = procTool.GetCurrentBlock(OUTPUT_HANDLE_ID_STDOUT, curBlock);
|
---|
1040 | /** @todo Check for more / validate blocks! */
|
---|
1041 | if (RT_SUCCESS(vrc))
|
---|
1042 | vrc = objData.FromStat(curBlock);
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
1047 | && pGuestRc)
|
---|
1048 | {
|
---|
1049 | *pGuestRc = guestRc;
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | LogFlowFuncLeaveRC(vrc);
|
---|
1053 | return vrc;
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | const GuestCredentials& GuestSession::getCredentials(void)
|
---|
1057 | {
|
---|
1058 | return mData.mCredentials;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | const GuestEnvironment& GuestSession::getEnvironment(void)
|
---|
1062 | {
|
---|
1063 | return mData.mEnvironment;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | Utf8Str GuestSession::getName(void)
|
---|
1067 | {
|
---|
1068 | return mData.mSession.mName;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | /* static */
|
---|
1072 | Utf8Str GuestSession::guestErrorToString(int guestRc)
|
---|
1073 | {
|
---|
1074 | Utf8Str strError;
|
---|
1075 |
|
---|
1076 | /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
|
---|
1077 | switch (guestRc)
|
---|
1078 | {
|
---|
1079 | case VERR_INVALID_VM_HANDLE:
|
---|
1080 | strError += Utf8StrFmt(tr("VMM device is not available (is the VM running?)"));
|
---|
1081 | break;
|
---|
1082 |
|
---|
1083 | case VERR_HGCM_SERVICE_NOT_FOUND:
|
---|
1084 | strError += Utf8StrFmt(tr("The guest execution service is not available"));
|
---|
1085 | break;
|
---|
1086 |
|
---|
1087 | case VERR_AUTHENTICATION_FAILURE:
|
---|
1088 | strError += Utf8StrFmt(tr("The specified user was not able to logon on guest"));
|
---|
1089 | break;
|
---|
1090 |
|
---|
1091 | case VERR_TIMEOUT:
|
---|
1092 | strError += Utf8StrFmt(tr("The guest did not respond within time"));
|
---|
1093 | break;
|
---|
1094 |
|
---|
1095 | case VERR_CANCELLED:
|
---|
1096 | strError += Utf8StrFmt(tr("The session operation was canceled"));
|
---|
1097 | break;
|
---|
1098 |
|
---|
1099 | case VERR_PERMISSION_DENIED:
|
---|
1100 | strError += Utf8StrFmt(tr("Invalid user/password credentials"));
|
---|
1101 | break;
|
---|
1102 |
|
---|
1103 | case VERR_MAX_PROCS_REACHED:
|
---|
1104 | strError += Utf8StrFmt(tr("Maximum number of concurrent guest processes has been reached"));
|
---|
1105 | break;
|
---|
1106 |
|
---|
1107 | case VERR_NOT_EQUAL: /** @todo Imprecise to the user; can mean anything and all. */
|
---|
1108 | strError += Utf8StrFmt(tr("Unable to retrieve requested information"));
|
---|
1109 | break;
|
---|
1110 |
|
---|
1111 | case VERR_NOT_FOUND:
|
---|
1112 | strError += Utf8StrFmt(tr("The guest execution service is not ready (yet)"));
|
---|
1113 | break;
|
---|
1114 |
|
---|
1115 | default:
|
---|
1116 | strError += Utf8StrFmt("%Rrc", guestRc);
|
---|
1117 | break;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | return strError;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | /**
|
---|
1124 | * Checks if this session is ready state where it can handle
|
---|
1125 | * all session-bound actions (like guest processes, guest files).
|
---|
1126 | * Only used by official API methods. Will set an external
|
---|
1127 | * error when not ready.
|
---|
1128 | */
|
---|
1129 | HRESULT GuestSession::isReadyExternal(void)
|
---|
1130 | {
|
---|
1131 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1132 |
|
---|
1133 | /** @todo Be a bit more informative. */
|
---|
1134 | if (mData.mStatus != GuestSessionStatus_Started)
|
---|
1135 | return setError(E_UNEXPECTED, tr("Session is not in started state"));
|
---|
1136 |
|
---|
1137 | return S_OK;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | /** No locking! */
|
---|
1141 | int GuestSession::onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
|
---|
1142 | {
|
---|
1143 | AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
|
---|
1144 | /* pCallback is optional. */
|
---|
1145 | AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
|
---|
1146 |
|
---|
1147 | if (pSvcCbData->mParms < 3)
|
---|
1148 | return VERR_INVALID_PARAMETER;
|
---|
1149 |
|
---|
1150 | CALLBACKDATA_SESSION_NOTIFY dataCb;
|
---|
1151 | /* pSvcCb->mpaParms[0] always contains the context ID. */
|
---|
1152 | pSvcCbData->mpaParms[1].getUInt32(&dataCb.uType);
|
---|
1153 | pSvcCbData->mpaParms[2].getUInt32(&dataCb.uResult);
|
---|
1154 |
|
---|
1155 | LogFlowThisFunc(("ID=%RU32, uType=%RU32, guestRc=%Rrc\n",
|
---|
1156 | mData.mSession.mID, dataCb.uType, dataCb.uResult));
|
---|
1157 |
|
---|
1158 | int vrc = VINF_SUCCESS;
|
---|
1159 |
|
---|
1160 | GuestSessionStatus_T sessionStatus = GuestSessionStatus_Undefined;
|
---|
1161 |
|
---|
1162 | int guestRc = dataCb.uResult; /** @todo uint32_t vs. int. */
|
---|
1163 | switch (dataCb.uType)
|
---|
1164 | {
|
---|
1165 | case GUEST_SESSION_NOTIFYTYPE_ERROR:
|
---|
1166 | sessionStatus = GuestSessionStatus_Error;
|
---|
1167 | break;
|
---|
1168 |
|
---|
1169 | case GUEST_SESSION_NOTIFYTYPE_STARTED:
|
---|
1170 | sessionStatus = GuestSessionStatus_Started;
|
---|
1171 | break;
|
---|
1172 |
|
---|
1173 | case GUEST_SESSION_NOTIFYTYPE_TEN:
|
---|
1174 | case GUEST_SESSION_NOTIFYTYPE_TES:
|
---|
1175 | case GUEST_SESSION_NOTIFYTYPE_TEA:
|
---|
1176 | sessionStatus = GuestSessionStatus_Terminated;
|
---|
1177 | break;
|
---|
1178 |
|
---|
1179 | case GUEST_SESSION_NOTIFYTYPE_TOK:
|
---|
1180 | sessionStatus = GuestSessionStatus_TimedOutKilled;
|
---|
1181 | break;
|
---|
1182 |
|
---|
1183 | case GUEST_SESSION_NOTIFYTYPE_TOA:
|
---|
1184 | sessionStatus = GuestSessionStatus_TimedOutAbnormally;
|
---|
1185 | break;
|
---|
1186 |
|
---|
1187 | case GUEST_SESSION_NOTIFYTYPE_DWN:
|
---|
1188 | sessionStatus = GuestSessionStatus_Down;
|
---|
1189 | break;
|
---|
1190 |
|
---|
1191 | case GUEST_SESSION_NOTIFYTYPE_UNDEFINED:
|
---|
1192 | default:
|
---|
1193 | vrc = VERR_NOT_SUPPORTED;
|
---|
1194 | break;
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | if (RT_SUCCESS(vrc))
|
---|
1198 | {
|
---|
1199 | if (RT_FAILURE(guestRc))
|
---|
1200 | sessionStatus = GuestSessionStatus_Error;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | /* Set the session status. */
|
---|
1204 | if (sessionStatus != GuestSessionStatus_Undefined)
|
---|
1205 | {
|
---|
1206 | int rc2 = setSessionStatus(sessionStatus, guestRc);
|
---|
1207 | if (RT_SUCCESS(vrc))
|
---|
1208 | vrc = rc2;
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | LogFlowThisFunc(("ID=%RU32, guestRc=%Rrc\n", mData.mSession.mID, guestRc));
|
---|
1212 |
|
---|
1213 | LogFlowFuncLeaveRC(vrc);
|
---|
1214 | return vrc;
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | int GuestSession::startSessionIntenal(int *pGuestRc)
|
---|
1218 | {
|
---|
1219 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1220 |
|
---|
1221 | LogFlowThisFunc(("mID=%RU32, mName=%s, uProtocolVersion=%RU32, openFlags=%x, openTimeoutMS=%RU32\n",
|
---|
1222 | mData.mSession.mID, mData.mSession.mName.c_str(), mData.mProtocolVersion,
|
---|
1223 | mData.mSession.mOpenFlags, mData.mSession.mOpenTimeoutMS));
|
---|
1224 |
|
---|
1225 | /* Legacy Guest Additions don't support opening dedicated
|
---|
1226 | guest sessions. Simply return success here. */
|
---|
1227 | if (mData.mProtocolVersion < 2)
|
---|
1228 | {
|
---|
1229 | mData.mStatus = GuestSessionStatus_Started;
|
---|
1230 |
|
---|
1231 | LogFlowThisFunc(("Installed Guest Additions don't support opening dedicated sessions, skipping\n"));
|
---|
1232 | return VINF_SUCCESS;
|
---|
1233 | }
|
---|
1234 |
|
---|
1235 | if (mData.mStatus != GuestSessionStatus_Undefined)
|
---|
1236 | return VINF_SUCCESS;
|
---|
1237 |
|
---|
1238 | /** @todo mData.mSession.uFlags validation. */
|
---|
1239 |
|
---|
1240 | /* Set current session status. */
|
---|
1241 | mData.mStatus = GuestSessionStatus_Starting;
|
---|
1242 |
|
---|
1243 | uint32_t uContextID;
|
---|
1244 | int vrc = generateContextID(mData.mSession.mID, 0 /* Object ID */,
|
---|
1245 | &uContextID);
|
---|
1246 | if (RT_SUCCESS(vrc))
|
---|
1247 | {
|
---|
1248 | VBOXHGCMSVCPARM paParms[8];
|
---|
1249 |
|
---|
1250 | int i = 0;
|
---|
1251 | paParms[i++].setUInt32(uContextID);
|
---|
1252 | paParms[i++].setUInt32(mData.mProtocolVersion);
|
---|
1253 | paParms[i++].setPointer((void*)mData.mCredentials.mUser.c_str(),
|
---|
1254 | (ULONG)mData.mCredentials.mUser.length() + 1);
|
---|
1255 | paParms[i++].setPointer((void*)mData.mCredentials.mPassword.c_str(),
|
---|
1256 | (ULONG)mData.mCredentials.mPassword.length() + 1);
|
---|
1257 | paParms[i++].setPointer((void*)mData.mCredentials.mDomain.c_str(),
|
---|
1258 | (ULONG)mData.mCredentials.mDomain.length() + 1);
|
---|
1259 | paParms[i++].setUInt32(mData.mSession.mOpenFlags);
|
---|
1260 |
|
---|
1261 | vrc = sendCommand(HOST_SESSION_CREATE, i, paParms);
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | if (RT_SUCCESS(vrc))
|
---|
1265 | {
|
---|
1266 | alock.release(); /* Drop write lock before waiting. */
|
---|
1267 |
|
---|
1268 | vrc = waitForStateChange(GuestSessionWaitForFlag_Start, 30 * 1000 /* 30s timeout */,
|
---|
1269 | NULL /* Session status */, pGuestRc);
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 | LogFlowFuncLeaveRC(vrc);
|
---|
1273 | return vrc;
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | int GuestSession::startSessionAsync(void)
|
---|
1277 | {
|
---|
1278 | LogFlowThisFuncEnter();
|
---|
1279 |
|
---|
1280 | int vrc;
|
---|
1281 |
|
---|
1282 | try
|
---|
1283 | {
|
---|
1284 | /* Asynchronously open the session on the guest by kicking off a
|
---|
1285 | * worker thread. */
|
---|
1286 | std::auto_ptr<GuestSessionTaskInternalOpen> pTask(new GuestSessionTaskInternalOpen(this));
|
---|
1287 | AssertReturn(pTask->isOk(), pTask->rc());
|
---|
1288 |
|
---|
1289 | vrc = RTThreadCreate(NULL, GuestSession::startSessionThread,
|
---|
1290 | (void *)pTask.get(), 0,
|
---|
1291 | RTTHREADTYPE_MAIN_WORKER, 0,
|
---|
1292 | "gctlSesStart");
|
---|
1293 | if (RT_SUCCESS(vrc))
|
---|
1294 | {
|
---|
1295 | /* pTask is now owned by openSessionThread(), so release it. */
|
---|
1296 | pTask.release();
|
---|
1297 | }
|
---|
1298 | }
|
---|
1299 | catch(std::bad_alloc &)
|
---|
1300 | {
|
---|
1301 | vrc = VERR_NO_MEMORY;
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | LogFlowFuncLeaveRC(vrc);
|
---|
1305 | return vrc;
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | /* static */
|
---|
1309 | DECLCALLBACK(int) GuestSession::startSessionThread(RTTHREAD Thread, void *pvUser)
|
---|
1310 | {
|
---|
1311 | LogFlowFunc(("pvUser=%p\n", pvUser));
|
---|
1312 |
|
---|
1313 | std::auto_ptr<GuestSessionTaskInternalOpen> pTask(static_cast<GuestSessionTaskInternalOpen*>(pvUser));
|
---|
1314 | AssertPtr(pTask.get());
|
---|
1315 |
|
---|
1316 | const ComObjPtr<GuestSession> pSession(pTask->Session());
|
---|
1317 | Assert(!pSession.isNull());
|
---|
1318 |
|
---|
1319 | AutoCaller autoCaller(pSession);
|
---|
1320 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
1321 |
|
---|
1322 | int vrc = pSession->startSessionIntenal(NULL /* Guest rc, ignored */);
|
---|
1323 | /* Nothing to do here anymore. */
|
---|
1324 |
|
---|
1325 | LogFlowFuncLeaveRC(vrc);
|
---|
1326 | return vrc;
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | int GuestSession::processRemoveFromList(GuestProcess *pProcess)
|
---|
1330 | {
|
---|
1331 | AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
|
---|
1332 |
|
---|
1333 | LogFlowThisFunc(("pProcess=%p\n", pProcess));
|
---|
1334 |
|
---|
1335 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1336 |
|
---|
1337 | int rc = VERR_NOT_FOUND;
|
---|
1338 |
|
---|
1339 | ULONG uPID;
|
---|
1340 | HRESULT hr = pProcess->COMGETTER(PID)(&uPID);
|
---|
1341 | ComAssertComRC(hr);
|
---|
1342 |
|
---|
1343 | LogFlowFunc(("Closing process (PID=%RU32) ...\n", uPID));
|
---|
1344 |
|
---|
1345 | SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
1346 | while (itProcs != mData.mProcesses.end())
|
---|
1347 | {
|
---|
1348 | if (pProcess == itProcs->second)
|
---|
1349 | {
|
---|
1350 | GuestProcess *pCurProc = itProcs->second;
|
---|
1351 | AssertPtr(pCurProc);
|
---|
1352 |
|
---|
1353 | hr = pCurProc->COMGETTER(PID)(&uPID);
|
---|
1354 | ComAssertComRC(hr);
|
---|
1355 |
|
---|
1356 | Assert(mData.mNumObjects);
|
---|
1357 | LogFlowFunc(("Removing process ID=%RU32 (Session: %RU32), guest PID=%RU32 (now total %ld processes, %ld objects)\n",
|
---|
1358 | pCurProc->getObjectID(), mData.mSession.mID, uPID, mData.mProcesses.size() - 1, mData.mNumObjects - 1));
|
---|
1359 |
|
---|
1360 | LogFlowFunc(("1\n"));
|
---|
1361 | mData.mProcesses.erase(itProcs);
|
---|
1362 | mData.mNumObjects--;
|
---|
1363 |
|
---|
1364 | LogFlowFunc(("2\n"));
|
---|
1365 | fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, NULL /* Process */,
|
---|
1366 | uPID, false /* Process unregistered */);
|
---|
1367 | LogFlowFunc(("3\n"));
|
---|
1368 | rc = VINF_SUCCESS;
|
---|
1369 | break;
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | LogFlowFunc(("4\n"));
|
---|
1373 | itProcs++;
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | LogFlowFuncLeaveRC(rc);
|
---|
1377 | return rc;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | /**
|
---|
1381 | * Creates but does *not* start the process yet. See GuestProcess::startProcess() or
|
---|
1382 | * GuestProcess::startProcessAsync() for that.
|
---|
1383 | *
|
---|
1384 | * @return IPRT status code.
|
---|
1385 | * @param procInfo
|
---|
1386 | * @param pProcess
|
---|
1387 | */
|
---|
1388 | int GuestSession::processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
|
---|
1389 | {
|
---|
1390 | LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
|
---|
1391 | procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
|
---|
1392 | #ifdef DEBUG
|
---|
1393 | if (procInfo.mArguments.size())
|
---|
1394 | {
|
---|
1395 | LogFlowFunc(("Arguments:"));
|
---|
1396 | ProcessArguments::const_iterator it = procInfo.mArguments.begin();
|
---|
1397 | while (it != procInfo.mArguments.end())
|
---|
1398 | {
|
---|
1399 | LogFlow((" %s", (*it).c_str()));
|
---|
1400 | it++;
|
---|
1401 | }
|
---|
1402 | LogFlow(("\n"));
|
---|
1403 | }
|
---|
1404 | #endif
|
---|
1405 |
|
---|
1406 | /* Validate flags. */
|
---|
1407 | if (procInfo.mFlags)
|
---|
1408 | {
|
---|
1409 | if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
|
---|
1410 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
|
---|
1411 | && !(procInfo.mFlags & ProcessCreateFlag_Hidden)
|
---|
1412 | && !(procInfo.mFlags & ProcessCreateFlag_NoProfile)
|
---|
1413 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
|
---|
1414 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
|
---|
1415 | {
|
---|
1416 | return VERR_INVALID_PARAMETER;
|
---|
1417 | }
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 | if ( (procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
|
---|
1421 | && ( (procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
|
---|
1422 | || (procInfo.mFlags & ProcessCreateFlag_WaitForStdErr)
|
---|
1423 | )
|
---|
1424 | )
|
---|
1425 | {
|
---|
1426 | return VERR_INVALID_PARAMETER;
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | /* Adjust timeout. If set to 0, we define
|
---|
1430 | * an infinite timeout. */
|
---|
1431 | if (procInfo.mTimeoutMS == 0)
|
---|
1432 | procInfo.mTimeoutMS = UINT32_MAX;
|
---|
1433 |
|
---|
1434 | /** @tood Implement process priority + affinity. */
|
---|
1435 |
|
---|
1436 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1437 |
|
---|
1438 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
1439 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
1440 | return rc;
|
---|
1441 |
|
---|
1442 | /* Create a new (host-based) process ID and assign it. */
|
---|
1443 | uint32_t uNewProcessID = 0;
|
---|
1444 | ULONG uTries = 0;
|
---|
1445 |
|
---|
1446 | for (;;)
|
---|
1447 | {
|
---|
1448 | /* Is the context ID already used? */
|
---|
1449 | if (!processExists(uNewProcessID, NULL /* pProgress */))
|
---|
1450 | {
|
---|
1451 | /* Callback with context ID was not found. This means
|
---|
1452 | * we can use this context ID for our new callback we want
|
---|
1453 | * to add below. */
|
---|
1454 | rc = VINF_SUCCESS;
|
---|
1455 | break;
|
---|
1456 | }
|
---|
1457 | uNewProcessID++;
|
---|
1458 | if (uNewProcessID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
1459 | uNewProcessID = 0;
|
---|
1460 |
|
---|
1461 | if (++uTries == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
1462 | break; /* Don't try too hard. */
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | if (RT_FAILURE(rc))
|
---|
1466 | return rc;
|
---|
1467 |
|
---|
1468 | /* Create the process object. */
|
---|
1469 | HRESULT hr = pProcess.createObject();
|
---|
1470 | if (FAILED(hr))
|
---|
1471 | return VERR_COM_UNEXPECTED;
|
---|
1472 |
|
---|
1473 | rc = pProcess->init(mParent->getConsole() /* Console */, this /* Session */,
|
---|
1474 | uNewProcessID, procInfo);
|
---|
1475 | if (RT_FAILURE(rc))
|
---|
1476 | return rc;
|
---|
1477 |
|
---|
1478 | /* Add the created process to our map. */
|
---|
1479 | mData.mProcesses[uNewProcessID] = pProcess;
|
---|
1480 | mData.mNumObjects++;
|
---|
1481 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
1482 |
|
---|
1483 | fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProcess,
|
---|
1484 | 0 /* PID */, true /* Process registered */);
|
---|
1485 |
|
---|
1486 | LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %ld processes, %ld objects)\n",
|
---|
1487 | mData.mSession.mID, uNewProcessID, mData.mProcesses.size(), mData.mNumObjects));
|
---|
1488 |
|
---|
1489 | return rc;
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | inline bool GuestSession::processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess)
|
---|
1493 | {
|
---|
1494 | SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
|
---|
1495 | if (it != mData.mProcesses.end())
|
---|
1496 | {
|
---|
1497 | if (pProcess)
|
---|
1498 | *pProcess = it->second;
|
---|
1499 | return true;
|
---|
1500 | }
|
---|
1501 | return false;
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 | inline int GuestSession::processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
|
---|
1505 | {
|
---|
1506 | AssertReturn(uPID, false);
|
---|
1507 | /* pProcess is optional. */
|
---|
1508 |
|
---|
1509 | SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
1510 | for (; itProcs != mData.mProcesses.end(); itProcs++)
|
---|
1511 | {
|
---|
1512 | ComObjPtr<GuestProcess> pCurProc = itProcs->second;
|
---|
1513 | AutoCaller procCaller(pCurProc);
|
---|
1514 | if (procCaller.rc())
|
---|
1515 | return VERR_COM_INVALID_OBJECT_STATE;
|
---|
1516 |
|
---|
1517 | ULONG uCurPID;
|
---|
1518 | HRESULT hr = pCurProc->COMGETTER(PID)(&uCurPID);
|
---|
1519 | ComAssertComRC(hr);
|
---|
1520 |
|
---|
1521 | if (uCurPID == uPID)
|
---|
1522 | {
|
---|
1523 | if (pProcess)
|
---|
1524 | *pProcess = pCurProc;
|
---|
1525 | return VINF_SUCCESS;
|
---|
1526 | }
|
---|
1527 | }
|
---|
1528 |
|
---|
1529 | return VERR_NOT_FOUND;
|
---|
1530 | }
|
---|
1531 |
|
---|
1532 | int GuestSession::sendCommand(uint32_t uFunction,
|
---|
1533 | uint32_t uParms, PVBOXHGCMSVCPARM paParms)
|
---|
1534 | {
|
---|
1535 | LogFlowThisFuncEnter();
|
---|
1536 |
|
---|
1537 | #ifndef VBOX_GUESTCTRL_TEST_CASE
|
---|
1538 | ComObjPtr<Console> pConsole = mParent->getConsole();
|
---|
1539 | Assert(!pConsole.isNull());
|
---|
1540 |
|
---|
1541 | /* Forward the information to the VMM device. */
|
---|
1542 | VMMDev *pVMMDev = pConsole->getVMMDev();
|
---|
1543 | AssertPtr(pVMMDev);
|
---|
1544 |
|
---|
1545 | LogFlowThisFunc(("uFunction=%RU32, uParms=%RU32\n", uFunction, uParms));
|
---|
1546 | int vrc = pVMMDev->hgcmHostCall(HGCMSERVICE_NAME, uFunction, uParms, paParms);
|
---|
1547 | if (RT_FAILURE(vrc))
|
---|
1548 | {
|
---|
1549 | /** @todo What to do here? */
|
---|
1550 | }
|
---|
1551 | #else
|
---|
1552 | /* Not needed within testcases. */
|
---|
1553 | int vrc = VINF_SUCCESS;
|
---|
1554 | #endif
|
---|
1555 | LogFlowFuncLeaveRC(vrc);
|
---|
1556 | return vrc;
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | /* static */
|
---|
1560 | HRESULT GuestSession::setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
|
---|
1561 | {
|
---|
1562 | AssertPtr(pInterface);
|
---|
1563 | AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n"));
|
---|
1564 |
|
---|
1565 | return pInterface->setError(VBOX_E_IPRT_ERROR, GuestSession::guestErrorToString(guestRc).c_str());
|
---|
1566 | }
|
---|
1567 |
|
---|
1568 | /* Does not do locking; caller is responsible for that! */
|
---|
1569 | int GuestSession::setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc)
|
---|
1570 | {
|
---|
1571 | LogFlowThisFunc(("oldStatus=%ld, newStatus=%ld, sessionRc=%Rrc\n",
|
---|
1572 | mData.mStatus, sessionStatus, sessionRc));
|
---|
1573 |
|
---|
1574 | if (sessionStatus == GuestSessionStatus_Error)
|
---|
1575 | {
|
---|
1576 | AssertMsg(RT_FAILURE(sessionRc), ("Guest rc must be an error (%Rrc)\n", sessionRc));
|
---|
1577 | /* Do not allow overwriting an already set error. If this happens
|
---|
1578 | * this means we forgot some error checking/locking somewhere. */
|
---|
1579 | AssertMsg(RT_SUCCESS(mData.mRC), ("Guest rc already set (to %Rrc)\n", mData.mRC));
|
---|
1580 | }
|
---|
1581 | else
|
---|
1582 | AssertMsg(RT_SUCCESS(sessionRc), ("Guest rc must not be an error (%Rrc)\n", sessionRc));
|
---|
1583 |
|
---|
1584 | if (mData.mStatus != sessionStatus)
|
---|
1585 | {
|
---|
1586 | mData.mStatus = sessionStatus;
|
---|
1587 | mData.mRC = sessionRc;
|
---|
1588 |
|
---|
1589 | ComObjPtr<GuestErrorInfo> errorInfo;
|
---|
1590 | HRESULT hr = errorInfo.createObject();
|
---|
1591 | ComAssertComRC(hr);
|
---|
1592 | int rc2 = errorInfo->init(sessionRc, guestErrorToString(sessionRc));
|
---|
1593 | AssertRC(rc2);
|
---|
1594 |
|
---|
1595 | fireGuestSessionStateChangedEvent(mEventSource, this,
|
---|
1596 | mData.mSession.mID, sessionStatus, errorInfo);
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | return VINF_SUCCESS;
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | int GuestSession::signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */)
|
---|
1603 | {
|
---|
1604 | /*LogFlowThisFunc(("enmWaitResult=%d, rc=%Rrc, mWaitCount=%RU32, mWaitEvent=%p\n",
|
---|
1605 | enmWaitResult, rc, mData.mWaitCount, mData.mWaitEvent));*/
|
---|
1606 |
|
---|
1607 | /* Note: No write locking here -- already done in the caller. */
|
---|
1608 |
|
---|
1609 | int vrc = VINF_SUCCESS;
|
---|
1610 | /*if (mData.mWaitEvent)
|
---|
1611 | vrc = mData.mWaitEvent->Signal(enmWaitResult, rc);*/
|
---|
1612 | LogFlowFuncLeaveRC(vrc);
|
---|
1613 | return vrc;
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | int GuestSession::startTaskAsync(const Utf8Str &strTaskDesc,
|
---|
1617 | GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress)
|
---|
1618 | {
|
---|
1619 | LogFlowThisFunc(("strTaskDesc=%s, pTask=%p\n", strTaskDesc.c_str(), pTask));
|
---|
1620 |
|
---|
1621 | AssertPtrReturn(pTask, VERR_INVALID_POINTER);
|
---|
1622 |
|
---|
1623 | /* Create the progress object. */
|
---|
1624 | HRESULT hr = pProgress.createObject();
|
---|
1625 | if (FAILED(hr))
|
---|
1626 | return VERR_COM_UNEXPECTED;
|
---|
1627 |
|
---|
1628 | hr = pProgress->init(static_cast<IGuestSession*>(this),
|
---|
1629 | Bstr(strTaskDesc).raw(),
|
---|
1630 | TRUE /* aCancelable */);
|
---|
1631 | if (FAILED(hr))
|
---|
1632 | return VERR_COM_UNEXPECTED;
|
---|
1633 |
|
---|
1634 | /* Initialize our worker task. */
|
---|
1635 | std::auto_ptr<GuestSessionTask> task(pTask);
|
---|
1636 |
|
---|
1637 | int rc = task->RunAsync(strTaskDesc, pProgress);
|
---|
1638 | if (RT_FAILURE(rc))
|
---|
1639 | return rc;
|
---|
1640 |
|
---|
1641 | /* Don't destruct on success. */
|
---|
1642 | task.release();
|
---|
1643 |
|
---|
1644 | LogFlowFuncLeaveRC(rc);
|
---|
1645 | return rc;
|
---|
1646 | }
|
---|
1647 |
|
---|
1648 | /**
|
---|
1649 | * Queries/collects information prior to establishing a guest session.
|
---|
1650 | * This is necessary to know which guest control protocol version to use,
|
---|
1651 | * among other things (later).
|
---|
1652 | *
|
---|
1653 | * @return IPRT status code.
|
---|
1654 | */
|
---|
1655 | int GuestSession::queryInfo(void)
|
---|
1656 | {
|
---|
1657 | #ifndef DEBUG_andy
|
---|
1658 | /* Since the new functions are not fully implemented yet, force Main
|
---|
1659 | to use protocol ver 1 so far. */
|
---|
1660 | mData.mProtocolVersion = 1;
|
---|
1661 | #else
|
---|
1662 | #if 1
|
---|
1663 | /* For debugging only: Hardcode version. */
|
---|
1664 | mData.mProtocolVersion = 2;
|
---|
1665 | #else
|
---|
1666 | /*
|
---|
1667 | * Try querying the guest control protocol version running on the guest.
|
---|
1668 | * This is done using the Guest Additions version
|
---|
1669 | */
|
---|
1670 | ComObjPtr<Guest> pGuest = mParent;
|
---|
1671 | Assert(!pGuest.isNull());
|
---|
1672 |
|
---|
1673 | uint32_t uVerAdditions = pGuest->getAdditionsVersion();
|
---|
1674 | mData.mProtocolVersion = ( VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions) >= 4
|
---|
1675 | && VBOX_FULL_VERSION_GET_MINOR(uVerAdditions) >= 3) /** @todo What's about v5.0 ? */
|
---|
1676 | ? 2 /* Guest control 2.0. */
|
---|
1677 | : 1; /* Legacy guest control (VBox < 4.3). */
|
---|
1678 | /* Build revision is ignored. */
|
---|
1679 |
|
---|
1680 | /* Tell the user but don't bitch too often. */
|
---|
1681 | static short s_gctrlLegacyWarning = 0;
|
---|
1682 | if (s_gctrlLegacyWarning++ < 3) /** @todo Find a bit nicer text. */
|
---|
1683 | LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"),
|
---|
1684 | VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions), VBOX_FULL_VERSION_GET_MINOR(uVerAdditions), mData.mProtocolVersion));
|
---|
1685 | #endif
|
---|
1686 | #endif
|
---|
1687 | return VINF_SUCCESS;
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 | int GuestSession::waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc)
|
---|
1691 | {
|
---|
1692 | LogFlowThisFuncEnter();
|
---|
1693 |
|
---|
1694 | AssertReturn(fWaitFlags, VERR_INVALID_PARAMETER);
|
---|
1695 |
|
---|
1696 | /*LogFlowThisFunc(("fWaitFlags=0x%x, uTimeoutMS=%RU32, mStatus=%RU32, mWaitCount=%RU32, mWaitEvent=%p, pGuestRc=%p\n",
|
---|
1697 | fWaitFlags, uTimeoutMS, mData.mStatus, mData.mWaitCount, mData.mWaitEvent, pGuestRc));*/
|
---|
1698 |
|
---|
1699 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1700 |
|
---|
1701 | /* Did some error occur before? Then skip waiting and return. */
|
---|
1702 | if (mData.mStatus == GuestSessionStatus_Error)
|
---|
1703 | {
|
---|
1704 | waitResult = GuestSessionWaitResult_Error;
|
---|
1705 | AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest session indicated an error\n", mData.mRC));
|
---|
1706 | if (pGuestRc)
|
---|
1707 | *pGuestRc = mData.mRC; /* Return last set error. */
|
---|
1708 | return VERR_GSTCTL_GUEST_ERROR;
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | waitResult = GuestSessionWaitResult_None;
|
---|
1712 | if (fWaitFlags & GuestSessionWaitForFlag_Terminate)
|
---|
1713 | {
|
---|
1714 | switch (mData.mStatus)
|
---|
1715 | {
|
---|
1716 | case GuestSessionStatus_Terminated:
|
---|
1717 | case GuestSessionStatus_Down:
|
---|
1718 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
1719 | break;
|
---|
1720 |
|
---|
1721 | case GuestSessionStatus_TimedOutKilled:
|
---|
1722 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
1723 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
1724 | break;
|
---|
1725 |
|
---|
1726 | case GuestSessionStatus_Error:
|
---|
1727 | /* Handled above. */
|
---|
1728 | break;
|
---|
1729 |
|
---|
1730 | case GuestSessionStatus_Started:
|
---|
1731 | waitResult = GuestSessionWaitResult_Start;
|
---|
1732 | break;
|
---|
1733 |
|
---|
1734 | case GuestSessionStatus_Undefined:
|
---|
1735 | case GuestSessionStatus_Starting:
|
---|
1736 | /* Do the waiting below. */
|
---|
1737 | break;
|
---|
1738 |
|
---|
1739 | default:
|
---|
1740 | AssertMsgFailed(("Unhandled session status %ld\n", mData.mStatus));
|
---|
1741 | return VERR_NOT_IMPLEMENTED;
|
---|
1742 | }
|
---|
1743 | }
|
---|
1744 | else if (fWaitFlags & GuestSessionWaitForFlag_Start)
|
---|
1745 | {
|
---|
1746 | switch (mData.mStatus)
|
---|
1747 | {
|
---|
1748 | case GuestSessionStatus_Started:
|
---|
1749 | case GuestSessionStatus_Terminating:
|
---|
1750 | case GuestSessionStatus_Terminated:
|
---|
1751 | case GuestSessionStatus_Down:
|
---|
1752 | waitResult = GuestSessionWaitResult_Start;
|
---|
1753 | break;
|
---|
1754 |
|
---|
1755 | case GuestSessionStatus_Error:
|
---|
1756 | waitResult = GuestSessionWaitResult_Error;
|
---|
1757 | break;
|
---|
1758 |
|
---|
1759 | case GuestSessionStatus_TimedOutKilled:
|
---|
1760 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
1761 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
1762 | break;
|
---|
1763 |
|
---|
1764 | case GuestSessionStatus_Undefined:
|
---|
1765 | case GuestSessionStatus_Starting:
|
---|
1766 | /* Do the waiting below. */
|
---|
1767 | break;
|
---|
1768 |
|
---|
1769 | default:
|
---|
1770 | AssertMsgFailed(("Unhandled session status %ld\n", mData.mStatus));
|
---|
1771 | return VERR_NOT_IMPLEMENTED;
|
---|
1772 | }
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | LogFlowThisFunc(("sessionStatus=%ld, sessionRc=%Rrc, waitResult=%ld\n",
|
---|
1776 | mData.mStatus, mData.mRC, waitResult));
|
---|
1777 |
|
---|
1778 | /* No waiting needed? Return immediately using the last set error. */
|
---|
1779 | if (waitResult != GuestSessionWaitResult_None)
|
---|
1780 | {
|
---|
1781 | if (pGuestRc)
|
---|
1782 | *pGuestRc = mData.mRC; /* Return last set error (if any). */
|
---|
1783 | return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
|
---|
1784 | }
|
---|
1785 |
|
---|
1786 | alock.release(); /* Release lock before waiting. */
|
---|
1787 |
|
---|
1788 | GuestSessionStatus_T sessionStatus;
|
---|
1789 | int vrc = waitForStateChange(fWaitFlags, uTimeoutMS, &sessionStatus, pGuestRc);
|
---|
1790 | if (RT_SUCCESS(vrc))
|
---|
1791 | {
|
---|
1792 | switch (sessionStatus)
|
---|
1793 | {
|
---|
1794 | case GuestSessionStatus_Started:
|
---|
1795 | waitResult = GuestSessionWaitResult_Start;
|
---|
1796 | break;
|
---|
1797 |
|
---|
1798 | case GuestSessionStatus_Terminated:
|
---|
1799 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
1800 | break;
|
---|
1801 |
|
---|
1802 | case GuestSessionStatus_TimedOutKilled:
|
---|
1803 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
1804 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
1805 | break;
|
---|
1806 |
|
---|
1807 | case GuestSessionStatus_Down:
|
---|
1808 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
1809 | break;
|
---|
1810 |
|
---|
1811 | case GuestSessionStatus_Error:
|
---|
1812 | waitResult = GuestSessionWaitResult_Error;
|
---|
1813 | break;
|
---|
1814 |
|
---|
1815 | default:
|
---|
1816 | waitResult = GuestSessionWaitResult_Status;
|
---|
1817 | break;
|
---|
1818 | }
|
---|
1819 | }
|
---|
1820 |
|
---|
1821 | LogFlowFuncLeaveRC(vrc);
|
---|
1822 | return vrc;
|
---|
1823 | }
|
---|
1824 |
|
---|
1825 | int GuestSession::waitForStateChange(uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
1826 | GuestSessionStatus_T *pSessionStatus, int *pGuestRc)
|
---|
1827 | {
|
---|
1828 | /** @todo Param validation. */
|
---|
1829 |
|
---|
1830 | int vrc;
|
---|
1831 |
|
---|
1832 | ComPtr<IEventListener> pListener;
|
---|
1833 | HRESULT hr = mEventSource->CreateListener(pListener.asOutParam());
|
---|
1834 | if (SUCCEEDED(hr))
|
---|
1835 | {
|
---|
1836 | com::SafeArray <VBoxEventType_T> eventTypes(1);
|
---|
1837 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
1838 | hr = mEventSource->RegisterListener(pListener, ComSafeArrayAsInParam(eventTypes), false);
|
---|
1839 | }
|
---|
1840 | else
|
---|
1841 | vrc = VERR_COM_UNEXPECTED;
|
---|
1842 |
|
---|
1843 | if (SUCCEEDED(hr))
|
---|
1844 | {
|
---|
1845 | LogFlowThisFunc(("Waiting for guest session state changed event (timeout=%RU32ms, flags=%x) ...\n",
|
---|
1846 | uTimeoutMS, fWaitFlags));
|
---|
1847 |
|
---|
1848 | vrc = VINF_SUCCESS;
|
---|
1849 |
|
---|
1850 | uint64_t u64Started = RTTimeMilliTS();
|
---|
1851 | bool fSignalled = false;
|
---|
1852 | do
|
---|
1853 | {
|
---|
1854 | unsigned cMsWait;
|
---|
1855 | if (uTimeoutMS == RT_INDEFINITE_WAIT)
|
---|
1856 | cMsWait = 1000;
|
---|
1857 | else
|
---|
1858 | {
|
---|
1859 | uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
|
---|
1860 | if (cMsElapsed >= uTimeoutMS)
|
---|
1861 | break; /* timed out */
|
---|
1862 | cMsWait = RT_MIN(1000, uTimeoutMS - (uint32_t)cMsElapsed);
|
---|
1863 | }
|
---|
1864 |
|
---|
1865 | ComPtr<IEvent> pEvent;
|
---|
1866 | hr = mEventSource->GetEvent(pListener, cMsWait, pEvent.asOutParam());
|
---|
1867 | if ( SUCCEEDED(hr)
|
---|
1868 | && !pEvent.isNull())
|
---|
1869 | {
|
---|
1870 | VBoxEventType_T aType;
|
---|
1871 | hr = pEvent->COMGETTER(Type)(&aType);
|
---|
1872 | ComAssertComRC(hr);
|
---|
1873 | switch (aType)
|
---|
1874 | {
|
---|
1875 | case VBoxEventType_OnGuestSessionStateChanged:
|
---|
1876 | {
|
---|
1877 | ComPtr<IGuestSessionStateChangedEvent> pChangedEvent = pEvent;
|
---|
1878 | Assert(!pChangedEvent.isNull());
|
---|
1879 |
|
---|
1880 | ULONG uSessionID;
|
---|
1881 | pChangedEvent->COMGETTER(Id)(&uSessionID);
|
---|
1882 | if (uSessionID != mData.mSession.mID)
|
---|
1883 | continue; /* Only our own session is of interest. */
|
---|
1884 |
|
---|
1885 | GuestSessionStatus_T sessionStatus;
|
---|
1886 | pChangedEvent->COMGETTER(Status)(&sessionStatus);
|
---|
1887 | if (pSessionStatus)
|
---|
1888 | *pSessionStatus = sessionStatus;
|
---|
1889 |
|
---|
1890 | LogFlowThisFunc(("Got status changed event for session ID=%RU32: %ld\n",
|
---|
1891 | mData.mSession.mID, sessionStatus));
|
---|
1892 |
|
---|
1893 | bool fSignal = false;
|
---|
1894 | if (fWaitFlags)
|
---|
1895 | {
|
---|
1896 | switch (sessionStatus)
|
---|
1897 | {
|
---|
1898 | case GuestSessionStatus_Started:
|
---|
1899 | fSignal = ( fWaitFlags & GuestSessionWaitForFlag_Start
|
---|
1900 | || fWaitFlags & GuestSessionWaitForFlag_Status);
|
---|
1901 | break;
|
---|
1902 |
|
---|
1903 | default:
|
---|
1904 | fSignal = true;
|
---|
1905 | break;
|
---|
1906 | }
|
---|
1907 | }
|
---|
1908 | else
|
---|
1909 | fSignal = true;
|
---|
1910 |
|
---|
1911 | if (!fSignal)
|
---|
1912 | continue;
|
---|
1913 |
|
---|
1914 | ComPtr<IGuestErrorInfo> errorInfo;
|
---|
1915 | hr = pChangedEvent->COMGETTER(Error)(errorInfo.asOutParam());
|
---|
1916 | ComAssertComRC(hr);
|
---|
1917 |
|
---|
1918 | LONG lGuestRc;
|
---|
1919 | hr = errorInfo->COMGETTER(Result)(&lGuestRc);
|
---|
1920 | ComAssertComRC(hr);
|
---|
1921 | if (RT_FAILURE((int)lGuestRc))
|
---|
1922 | vrc = VERR_GSTCTL_GUEST_ERROR;
|
---|
1923 | if (pGuestRc)
|
---|
1924 | *pGuestRc = (int)lGuestRc;
|
---|
1925 |
|
---|
1926 | LogFlowThisFunc(("Status changed event for session ID=%RU32: %ld (%Rrc)\n",
|
---|
1927 | mData.mSession.mID, sessionStatus,
|
---|
1928 | RT_SUCCESS((int)lGuestRc) ? VINF_SUCCESS : (int)lGuestRc));
|
---|
1929 |
|
---|
1930 | fSignalled = true;
|
---|
1931 | break;
|
---|
1932 | }
|
---|
1933 |
|
---|
1934 | default:
|
---|
1935 | AssertMsgFailed(("Unhandled event type %ld\n", aType));
|
---|
1936 | break;
|
---|
1937 | }
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | } while (!fSignalled);
|
---|
1941 |
|
---|
1942 | if ( RT_SUCCESS(vrc)
|
---|
1943 | && !fSignalled)
|
---|
1944 | {
|
---|
1945 | vrc = VERR_TIMEOUT;
|
---|
1946 | }
|
---|
1947 |
|
---|
1948 | mEventSource->UnregisterListener(pListener);
|
---|
1949 | }
|
---|
1950 | else
|
---|
1951 | vrc = VERR_COM_UNEXPECTED;
|
---|
1952 |
|
---|
1953 | LogFlowFuncLeaveRC(vrc);
|
---|
1954 | return vrc;
|
---|
1955 | }
|
---|
1956 |
|
---|
1957 | // implementation of public methods
|
---|
1958 | /////////////////////////////////////////////////////////////////////////////
|
---|
1959 |
|
---|
1960 | STDMETHODIMP GuestSession::Close(void)
|
---|
1961 | {
|
---|
1962 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
1963 | ReturnComNotImplemented();
|
---|
1964 | #else
|
---|
1965 | LogFlowThisFuncEnter();
|
---|
1966 |
|
---|
1967 | AutoCaller autoCaller(this);
|
---|
1968 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
1969 |
|
---|
1970 | /* Close session on guest. */
|
---|
1971 | int guestRc;
|
---|
1972 | int rc = closeSession(0 /* Flags */, 30 * 1000 /* Timeout */,
|
---|
1973 | &guestRc);
|
---|
1974 | /* On failure don't return here, instead do all the cleanup
|
---|
1975 | * work first and then return an error. */
|
---|
1976 |
|
---|
1977 | /* Remove ourselves from the session list. */
|
---|
1978 | int rc2 = mParent->sessionRemove(this);
|
---|
1979 | if (RT_SUCCESS(rc))
|
---|
1980 | rc = rc2;
|
---|
1981 |
|
---|
1982 | /*
|
---|
1983 | * Release autocaller before calling uninit.
|
---|
1984 | */
|
---|
1985 | autoCaller.release();
|
---|
1986 |
|
---|
1987 | uninit();
|
---|
1988 |
|
---|
1989 | LogFlowFuncLeaveRC(rc);
|
---|
1990 | if (RT_FAILURE(rc))
|
---|
1991 | {
|
---|
1992 | if (rc == VERR_GSTCTL_GUEST_ERROR)
|
---|
1993 | return GuestSession::setErrorExternal(this, guestRc);
|
---|
1994 |
|
---|
1995 | return setError(VBOX_E_IPRT_ERROR,
|
---|
1996 | tr("Closing guest session failed with %Rrc"), rc);
|
---|
1997 | }
|
---|
1998 |
|
---|
1999 | return S_OK;
|
---|
2000 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2001 | }
|
---|
2002 |
|
---|
2003 | STDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
|
---|
2004 | {
|
---|
2005 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2006 | ReturnComNotImplemented();
|
---|
2007 | #else
|
---|
2008 | CheckComArgStrNotEmptyOrNull(aSource);
|
---|
2009 | CheckComArgStrNotEmptyOrNull(aDest);
|
---|
2010 | CheckComArgOutPointerValid(aProgress);
|
---|
2011 |
|
---|
2012 | LogFlowThisFuncEnter();
|
---|
2013 |
|
---|
2014 | if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
|
---|
2015 | return setError(E_INVALIDARG, tr("No source specified"));
|
---|
2016 | if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
|
---|
2017 | return setError(E_INVALIDARG, tr("No destination specified"));
|
---|
2018 |
|
---|
2019 | AutoCaller autoCaller(this);
|
---|
2020 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2021 |
|
---|
2022 | uint32_t fFlags = CopyFileFlag_None;
|
---|
2023 | if (aFlags)
|
---|
2024 | {
|
---|
2025 | com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
2026 | for (size_t i = 0; i < flags.size(); i++)
|
---|
2027 | fFlags |= flags[i];
|
---|
2028 | }
|
---|
2029 |
|
---|
2030 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2031 |
|
---|
2032 | HRESULT hr = S_OK;
|
---|
2033 |
|
---|
2034 | try
|
---|
2035 | {
|
---|
2036 | ComObjPtr<Progress> pProgress;
|
---|
2037 | SessionTaskCopyFrom *pTask = new SessionTaskCopyFrom(this /* GuestSession */,
|
---|
2038 | Utf8Str(aSource), Utf8Str(aDest), fFlags);
|
---|
2039 | int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest),
|
---|
2040 | pTask, pProgress);
|
---|
2041 | if (RT_SUCCESS(rc))
|
---|
2042 | {
|
---|
2043 | /* Return progress to the caller. */
|
---|
2044 | hr = pProgress.queryInterfaceTo(aProgress);
|
---|
2045 | }
|
---|
2046 | else
|
---|
2047 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
2048 | tr("Starting task for copying file \"%ls\" from guest to \"%ls\" on the host failed: %Rrc"), rc);
|
---|
2049 | }
|
---|
2050 | catch(std::bad_alloc &)
|
---|
2051 | {
|
---|
2052 | hr = E_OUTOFMEMORY;
|
---|
2053 | }
|
---|
2054 |
|
---|
2055 | return hr;
|
---|
2056 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2057 | }
|
---|
2058 |
|
---|
2059 | STDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
|
---|
2060 | {
|
---|
2061 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2062 | ReturnComNotImplemented();
|
---|
2063 | #else
|
---|
2064 | CheckComArgStrNotEmptyOrNull(aSource);
|
---|
2065 | CheckComArgStrNotEmptyOrNull(aDest);
|
---|
2066 | CheckComArgOutPointerValid(aProgress);
|
---|
2067 |
|
---|
2068 | LogFlowThisFuncEnter();
|
---|
2069 |
|
---|
2070 | if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
|
---|
2071 | return setError(E_INVALIDARG, tr("No source specified"));
|
---|
2072 | if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
|
---|
2073 | return setError(E_INVALIDARG, tr("No destination specified"));
|
---|
2074 |
|
---|
2075 | AutoCaller autoCaller(this);
|
---|
2076 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2077 |
|
---|
2078 | uint32_t fFlags = CopyFileFlag_None;
|
---|
2079 | if (aFlags)
|
---|
2080 | {
|
---|
2081 | com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
2082 | for (size_t i = 0; i < flags.size(); i++)
|
---|
2083 | fFlags |= flags[i];
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2087 |
|
---|
2088 | HRESULT hr = S_OK;
|
---|
2089 |
|
---|
2090 | try
|
---|
2091 | {
|
---|
2092 | ComObjPtr<Progress> pProgress;
|
---|
2093 | SessionTaskCopyTo *pTask = new SessionTaskCopyTo(this /* GuestSession */,
|
---|
2094 | Utf8Str(aSource), Utf8Str(aDest), fFlags);
|
---|
2095 | AssertPtrReturn(pTask, E_OUTOFMEMORY);
|
---|
2096 | int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest),
|
---|
2097 | pTask, pProgress);
|
---|
2098 | if (RT_SUCCESS(rc))
|
---|
2099 | {
|
---|
2100 | /* Return progress to the caller. */
|
---|
2101 | hr = pProgress.queryInterfaceTo(aProgress);
|
---|
2102 | }
|
---|
2103 | else
|
---|
2104 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
2105 | tr("Starting task for copying file \"%ls\" from host to \"%ls\" on the guest failed: %Rrc"), rc);
|
---|
2106 | }
|
---|
2107 | catch(std::bad_alloc &)
|
---|
2108 | {
|
---|
2109 | hr = E_OUTOFMEMORY;
|
---|
2110 | }
|
---|
2111 |
|
---|
2112 | return hr;
|
---|
2113 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2114 | }
|
---|
2115 |
|
---|
2116 | STDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode,
|
---|
2117 | ComSafeArrayIn(DirectoryCreateFlag_T, aFlags))
|
---|
2118 | {
|
---|
2119 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2120 | ReturnComNotImplemented();
|
---|
2121 | #else
|
---|
2122 | LogFlowThisFuncEnter();
|
---|
2123 |
|
---|
2124 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2125 | return setError(E_INVALIDARG, tr("No directory to create specified"));
|
---|
2126 |
|
---|
2127 | AutoCaller autoCaller(this);
|
---|
2128 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2129 |
|
---|
2130 | uint32_t fFlags = DirectoryCreateFlag_None;
|
---|
2131 | if (aFlags)
|
---|
2132 | {
|
---|
2133 | com::SafeArray<DirectoryCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
2134 | for (size_t i = 0; i < flags.size(); i++)
|
---|
2135 | fFlags |= flags[i];
|
---|
2136 |
|
---|
2137 | if (fFlags)
|
---|
2138 | {
|
---|
2139 | if (!(fFlags & DirectoryCreateFlag_Parents))
|
---|
2140 | return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), fFlags);
|
---|
2141 | }
|
---|
2142 | }
|
---|
2143 |
|
---|
2144 | HRESULT hr = S_OK;
|
---|
2145 |
|
---|
2146 | ComObjPtr <GuestDirectory> pDirectory; int guestRc;
|
---|
2147 | int rc = directoryCreateInternal(Utf8Str(aPath), (uint32_t)aMode, fFlags, &guestRc);
|
---|
2148 | if (RT_FAILURE(rc))
|
---|
2149 | {
|
---|
2150 | switch (rc)
|
---|
2151 | {
|
---|
2152 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2153 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2154 | break;
|
---|
2155 |
|
---|
2156 | case VERR_INVALID_PARAMETER:
|
---|
2157 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
|
---|
2158 | break;
|
---|
2159 |
|
---|
2160 | case VERR_BROKEN_PIPE:
|
---|
2161 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
|
---|
2162 | break;
|
---|
2163 |
|
---|
2164 | case VERR_CANT_CREATE:
|
---|
2165 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Could not create directory"));
|
---|
2166 | break;
|
---|
2167 |
|
---|
2168 | default:
|
---|
2169 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
|
---|
2170 | break;
|
---|
2171 | }
|
---|
2172 | }
|
---|
2173 |
|
---|
2174 | return hr;
|
---|
2175 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2176 | }
|
---|
2177 |
|
---|
2178 | STDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, BSTR *aDirectory)
|
---|
2179 | {
|
---|
2180 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2181 | ReturnComNotImplemented();
|
---|
2182 | #else
|
---|
2183 | LogFlowThisFuncEnter();
|
---|
2184 |
|
---|
2185 | if (RT_UNLIKELY((aTemplate) == NULL || *(aTemplate) == '\0'))
|
---|
2186 | return setError(E_INVALIDARG, tr("No template specified"));
|
---|
2187 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2188 | return setError(E_INVALIDARG, tr("No directory name specified"));
|
---|
2189 | CheckComArgOutPointerValid(aDirectory);
|
---|
2190 |
|
---|
2191 | AutoCaller autoCaller(this);
|
---|
2192 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2193 |
|
---|
2194 | HRESULT hr = S_OK;
|
---|
2195 |
|
---|
2196 | Utf8Str strName; int guestRc;
|
---|
2197 | int rc = objectCreateTempInternal(Utf8Str(aTemplate),
|
---|
2198 | Utf8Str(aPath),
|
---|
2199 | true /* Directory */, strName, &guestRc);
|
---|
2200 | if (RT_SUCCESS(rc))
|
---|
2201 | {
|
---|
2202 | strName.cloneTo(aDirectory);
|
---|
2203 | }
|
---|
2204 | else
|
---|
2205 | {
|
---|
2206 | switch (rc)
|
---|
2207 | {
|
---|
2208 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2209 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2210 | break;
|
---|
2211 |
|
---|
2212 | default:
|
---|
2213 | hr = setError(VBOX_E_IPRT_ERROR, tr("Temporary directory creation \"%s\" with template \"%s\" failed: %Rrc"),
|
---|
2214 | Utf8Str(aPath).c_str(), Utf8Str(aTemplate).c_str(), rc);
|
---|
2215 | break;
|
---|
2216 | }
|
---|
2217 | }
|
---|
2218 |
|
---|
2219 | return hr;
|
---|
2220 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2221 | }
|
---|
2222 |
|
---|
2223 | STDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
|
---|
2224 | {
|
---|
2225 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2226 | ReturnComNotImplemented();
|
---|
2227 | #else
|
---|
2228 | LogFlowThisFuncEnter();
|
---|
2229 |
|
---|
2230 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2231 | return setError(E_INVALIDARG, tr("No directory to check existence for specified"));
|
---|
2232 | CheckComArgOutPointerValid(aExists);
|
---|
2233 |
|
---|
2234 | AutoCaller autoCaller(this);
|
---|
2235 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2236 |
|
---|
2237 | HRESULT hr = S_OK;
|
---|
2238 |
|
---|
2239 | GuestFsObjData objData; int guestRc;
|
---|
2240 | int rc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
2241 | if (RT_SUCCESS(rc))
|
---|
2242 | {
|
---|
2243 | *aExists = objData.mType == FsObjType_Directory;
|
---|
2244 | }
|
---|
2245 | else
|
---|
2246 | {
|
---|
2247 | switch (rc)
|
---|
2248 | {
|
---|
2249 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2250 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2251 | break;
|
---|
2252 |
|
---|
2253 | default:
|
---|
2254 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory existence \"%s\" failed: %Rrc"),
|
---|
2255 | Utf8Str(aPath).c_str(), rc);
|
---|
2256 | break;
|
---|
2257 | }
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 | return hr;
|
---|
2261 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2262 | }
|
---|
2263 |
|
---|
2264 | STDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory)
|
---|
2265 | {
|
---|
2266 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2267 | ReturnComNotImplemented();
|
---|
2268 | #else
|
---|
2269 | LogFlowThisFuncEnter();
|
---|
2270 |
|
---|
2271 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2272 | return setError(E_INVALIDARG, tr("No directory to open specified"));
|
---|
2273 | if (RT_UNLIKELY((aFilter) != NULL && *(aFilter) != '\0'))
|
---|
2274 | return setError(E_INVALIDARG, tr("Directory filters are not implemented yet"));
|
---|
2275 | CheckComArgOutPointerValid(aDirectory);
|
---|
2276 |
|
---|
2277 | AutoCaller autoCaller(this);
|
---|
2278 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2279 |
|
---|
2280 | uint32_t fFlags = DirectoryOpenFlag_None;
|
---|
2281 | if (aFlags)
|
---|
2282 | {
|
---|
2283 | com::SafeArray<DirectoryOpenFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
2284 | for (size_t i = 0; i < flags.size(); i++)
|
---|
2285 | fFlags |= flags[i];
|
---|
2286 |
|
---|
2287 | if (fFlags)
|
---|
2288 | return setError(E_INVALIDARG, tr("Open flags (%#x) not implemented yet"), fFlags);
|
---|
2289 | }
|
---|
2290 |
|
---|
2291 | HRESULT hr = S_OK;
|
---|
2292 |
|
---|
2293 | ComObjPtr <GuestDirectory> pDirectory;
|
---|
2294 | int rc = directoryOpenInternal(Utf8Str(aPath), Utf8Str(aFilter), fFlags, pDirectory);
|
---|
2295 | if (RT_SUCCESS(rc))
|
---|
2296 | {
|
---|
2297 | /* Return directory object to the caller. */
|
---|
2298 | hr = pDirectory.queryInterfaceTo(aDirectory);
|
---|
2299 | }
|
---|
2300 | else
|
---|
2301 | {
|
---|
2302 | switch (rc)
|
---|
2303 | {
|
---|
2304 | case VERR_INVALID_PARAMETER:
|
---|
2305 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed; invalid parameters given",
|
---|
2306 | Utf8Str(aPath).c_str()));
|
---|
2307 | break;
|
---|
2308 |
|
---|
2309 | default:
|
---|
2310 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed: %Rrc"),
|
---|
2311 | Utf8Str(aPath).c_str(),rc);
|
---|
2312 | break;
|
---|
2313 | }
|
---|
2314 | }
|
---|
2315 |
|
---|
2316 | return hr;
|
---|
2317 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2318 | }
|
---|
2319 |
|
---|
2320 | STDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
|
---|
2321 | {
|
---|
2322 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2323 | ReturnComNotImplemented();
|
---|
2324 | #else
|
---|
2325 | LogFlowThisFuncEnter();
|
---|
2326 |
|
---|
2327 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2328 | return setError(E_INVALIDARG, tr("No directory to query information for specified"));
|
---|
2329 | CheckComArgOutPointerValid(aInfo);
|
---|
2330 |
|
---|
2331 | AutoCaller autoCaller(this);
|
---|
2332 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2333 |
|
---|
2334 | HRESULT hr = S_OK;
|
---|
2335 |
|
---|
2336 | GuestFsObjData objData; int guestRc;
|
---|
2337 | int vrc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
2338 | if (RT_SUCCESS(vrc))
|
---|
2339 | {
|
---|
2340 | if (objData.mType == FsObjType_Directory)
|
---|
2341 | {
|
---|
2342 | ComObjPtr<GuestFsObjInfo> pFsObjInfo;
|
---|
2343 | hr = pFsObjInfo.createObject();
|
---|
2344 | if (FAILED(hr)) return hr;
|
---|
2345 |
|
---|
2346 | vrc = pFsObjInfo->init(objData);
|
---|
2347 | if (RT_SUCCESS(vrc))
|
---|
2348 | {
|
---|
2349 | hr = pFsObjInfo.queryInterfaceTo(aInfo);
|
---|
2350 | if (FAILED(hr)) return hr;
|
---|
2351 | }
|
---|
2352 | }
|
---|
2353 | }
|
---|
2354 |
|
---|
2355 | if (RT_FAILURE(vrc))
|
---|
2356 | {
|
---|
2357 | switch (vrc)
|
---|
2358 | {
|
---|
2359 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2360 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2361 | break;
|
---|
2362 |
|
---|
2363 | case VERR_NOT_A_DIRECTORY:
|
---|
2364 | hr = setError(VBOX_E_IPRT_ERROR, tr("Element \"%s\" exists but is not a directory",
|
---|
2365 | Utf8Str(aPath).c_str()));
|
---|
2366 | break;
|
---|
2367 |
|
---|
2368 | default:
|
---|
2369 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory information for \"%s\" failed: %Rrc"),
|
---|
2370 | Utf8Str(aPath).c_str(), vrc);
|
---|
2371 | break;
|
---|
2372 | }
|
---|
2373 | }
|
---|
2374 |
|
---|
2375 | return hr;
|
---|
2376 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | STDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
|
---|
2380 | {
|
---|
2381 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2382 | ReturnComNotImplemented();
|
---|
2383 | #else
|
---|
2384 | LogFlowThisFuncEnter();
|
---|
2385 |
|
---|
2386 | AutoCaller autoCaller(this);
|
---|
2387 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2388 |
|
---|
2389 | ReturnComNotImplemented();
|
---|
2390 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2391 | }
|
---|
2392 |
|
---|
2393 | STDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
|
---|
2394 | {
|
---|
2395 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2396 | ReturnComNotImplemented();
|
---|
2397 | #else
|
---|
2398 | LogFlowThisFuncEnter();
|
---|
2399 |
|
---|
2400 | AutoCaller autoCaller(this);
|
---|
2401 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2402 |
|
---|
2403 | ReturnComNotImplemented();
|
---|
2404 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2405 | }
|
---|
2406 |
|
---|
2407 | STDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
|
---|
2408 | {
|
---|
2409 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2410 | ReturnComNotImplemented();
|
---|
2411 | #else
|
---|
2412 | LogFlowThisFuncEnter();
|
---|
2413 |
|
---|
2414 | AutoCaller autoCaller(this);
|
---|
2415 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2416 |
|
---|
2417 | ReturnComNotImplemented();
|
---|
2418 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2419 | }
|
---|
2420 |
|
---|
2421 | STDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
|
---|
2422 | {
|
---|
2423 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2424 | ReturnComNotImplemented();
|
---|
2425 | #else
|
---|
2426 | LogFlowThisFuncEnter();
|
---|
2427 |
|
---|
2428 | AutoCaller autoCaller(this);
|
---|
2429 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2430 |
|
---|
2431 | ReturnComNotImplemented();
|
---|
2432 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2433 | }
|
---|
2434 |
|
---|
2435 | STDMETHODIMP GuestSession::EnvironmentClear(void)
|
---|
2436 | {
|
---|
2437 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2438 | ReturnComNotImplemented();
|
---|
2439 | #else
|
---|
2440 | LogFlowThisFuncEnter();
|
---|
2441 |
|
---|
2442 | AutoCaller autoCaller(this);
|
---|
2443 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2444 |
|
---|
2445 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2446 |
|
---|
2447 | mData.mEnvironment.Clear();
|
---|
2448 |
|
---|
2449 | LogFlowFuncLeaveRC(S_OK);
|
---|
2450 | return S_OK;
|
---|
2451 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2452 | }
|
---|
2453 |
|
---|
2454 | STDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
|
---|
2455 | {
|
---|
2456 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2457 | ReturnComNotImplemented();
|
---|
2458 | #else
|
---|
2459 | LogFlowThisFuncEnter();
|
---|
2460 |
|
---|
2461 | if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
|
---|
2462 | return setError(E_INVALIDARG, tr("No value name specified"));
|
---|
2463 |
|
---|
2464 | CheckComArgOutPointerValid(aValue);
|
---|
2465 |
|
---|
2466 | AutoCaller autoCaller(this);
|
---|
2467 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2468 |
|
---|
2469 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2470 |
|
---|
2471 | Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
|
---|
2472 | strValue.cloneTo(aValue);
|
---|
2473 |
|
---|
2474 | LogFlowFuncLeaveRC(S_OK);
|
---|
2475 | return S_OK;
|
---|
2476 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2477 | }
|
---|
2478 |
|
---|
2479 | STDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
|
---|
2480 | {
|
---|
2481 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2482 | ReturnComNotImplemented();
|
---|
2483 | #else
|
---|
2484 | LogFlowThisFuncEnter();
|
---|
2485 |
|
---|
2486 | if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
|
---|
2487 | return setError(E_INVALIDARG, tr("No value name specified"));
|
---|
2488 |
|
---|
2489 | AutoCaller autoCaller(this);
|
---|
2490 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2491 |
|
---|
2492 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2493 |
|
---|
2494 | int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
|
---|
2495 |
|
---|
2496 | HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
|
---|
2497 | LogFlowFuncLeaveRC(hr);
|
---|
2498 | return hr;
|
---|
2499 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2500 | }
|
---|
2501 |
|
---|
2502 | STDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
|
---|
2503 | {
|
---|
2504 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2505 | ReturnComNotImplemented();
|
---|
2506 | #else
|
---|
2507 | LogFlowThisFuncEnter();
|
---|
2508 |
|
---|
2509 | AutoCaller autoCaller(this);
|
---|
2510 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2511 |
|
---|
2512 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2513 |
|
---|
2514 | mData.mEnvironment.Unset(Utf8Str(aName));
|
---|
2515 |
|
---|
2516 | LogFlowFuncLeaveRC(S_OK);
|
---|
2517 | return S_OK;
|
---|
2518 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | STDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, IGuestFile **aFile)
|
---|
2522 | {
|
---|
2523 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2524 | ReturnComNotImplemented();
|
---|
2525 | #else
|
---|
2526 | LogFlowThisFuncEnter();
|
---|
2527 |
|
---|
2528 | AutoCaller autoCaller(this);
|
---|
2529 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2530 |
|
---|
2531 | ReturnComNotImplemented();
|
---|
2532 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 | STDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
|
---|
2536 | {
|
---|
2537 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2538 | ReturnComNotImplemented();
|
---|
2539 | #else
|
---|
2540 | LogFlowThisFuncEnter();
|
---|
2541 |
|
---|
2542 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2543 | return setError(E_INVALIDARG, tr("No file to check existence for specified"));
|
---|
2544 | CheckComArgOutPointerValid(aExists);
|
---|
2545 |
|
---|
2546 | AutoCaller autoCaller(this);
|
---|
2547 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2548 |
|
---|
2549 | GuestFsObjData objData; int guestRc;
|
---|
2550 | int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
2551 | if (RT_SUCCESS(vrc))
|
---|
2552 | {
|
---|
2553 | *aExists = TRUE;
|
---|
2554 | return S_OK;
|
---|
2555 | }
|
---|
2556 |
|
---|
2557 | HRESULT hr = S_OK;
|
---|
2558 |
|
---|
2559 | switch (vrc)
|
---|
2560 | {
|
---|
2561 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2562 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2563 | break;
|
---|
2564 |
|
---|
2565 | case VERR_NOT_A_FILE:
|
---|
2566 | *aExists = FALSE;
|
---|
2567 | break;
|
---|
2568 |
|
---|
2569 | default:
|
---|
2570 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information for \"%s\" failed: %Rrc"),
|
---|
2571 | Utf8Str(aPath).c_str(), vrc);
|
---|
2572 | break;
|
---|
2573 | }
|
---|
2574 |
|
---|
2575 | return hr;
|
---|
2576 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2577 | }
|
---|
2578 |
|
---|
2579 | STDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
|
---|
2580 | {
|
---|
2581 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2582 | ReturnComNotImplemented();
|
---|
2583 | #else
|
---|
2584 | LogFlowThisFuncEnter();
|
---|
2585 |
|
---|
2586 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2587 | return setError(E_INVALIDARG, tr("No file to remove specified"));
|
---|
2588 |
|
---|
2589 | AutoCaller autoCaller(this);
|
---|
2590 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2591 |
|
---|
2592 | HRESULT hr = S_OK;
|
---|
2593 |
|
---|
2594 | int guestRc;
|
---|
2595 | int vrc = fileRemoveInternal(Utf8Str(aPath), &guestRc);
|
---|
2596 | if (RT_FAILURE(vrc))
|
---|
2597 | {
|
---|
2598 | switch (vrc)
|
---|
2599 | {
|
---|
2600 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2601 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2602 | break;
|
---|
2603 |
|
---|
2604 | default:
|
---|
2605 | hr = setError(VBOX_E_IPRT_ERROR, tr("Removing file \"%s\" failed: %Rrc"),
|
---|
2606 | Utf8Str(aPath).c_str(), vrc);
|
---|
2607 | break;
|
---|
2608 | }
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 | return hr;
|
---|
2612 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2613 | }
|
---|
2614 |
|
---|
2615 | STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
|
---|
2616 | {
|
---|
2617 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2618 | ReturnComNotImplemented();
|
---|
2619 | #else
|
---|
2620 | LogFlowThisFuncEnter();
|
---|
2621 |
|
---|
2622 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2623 | return setError(E_INVALIDARG, tr("No file to open specified"));
|
---|
2624 | if (RT_UNLIKELY((aOpenMode) == NULL || *(aOpenMode) == '\0'))
|
---|
2625 | return setError(E_INVALIDARG, tr("No open mode specified"));
|
---|
2626 | if (RT_UNLIKELY((aDisposition) == NULL || *(aDisposition) == '\0'))
|
---|
2627 | return setError(E_INVALIDARG, tr("No disposition mode specified"));
|
---|
2628 |
|
---|
2629 | CheckComArgOutPointerValid(aFile);
|
---|
2630 |
|
---|
2631 | AutoCaller autoCaller(this);
|
---|
2632 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2633 |
|
---|
2634 | HRESULT hr = isReadyExternal();
|
---|
2635 | if (FAILED(hr))
|
---|
2636 | return hr;
|
---|
2637 |
|
---|
2638 | /** @todo Validate open mode. */
|
---|
2639 | /** @todo Validate disposition mode. */
|
---|
2640 |
|
---|
2641 | /** @todo Validate creation mode. */
|
---|
2642 | uint32_t uCreationMode = 0;
|
---|
2643 |
|
---|
2644 | GuestFileOpenInfo openInfo;
|
---|
2645 | openInfo.mFileName = Utf8Str(aPath);
|
---|
2646 | openInfo.mOpenMode = Utf8Str(aOpenMode);
|
---|
2647 | openInfo.mDisposition = Utf8Str(aDisposition);
|
---|
2648 | openInfo.mCreationMode = aCreationMode;
|
---|
2649 | openInfo.mInitialOffset = aOffset;
|
---|
2650 |
|
---|
2651 | ComObjPtr <GuestFile> pFile; int guestRc;
|
---|
2652 | int vrc = fileOpenInternal(openInfo, pFile, &guestRc);
|
---|
2653 | if (RT_SUCCESS(vrc))
|
---|
2654 | {
|
---|
2655 | /* Return directory object to the caller. */
|
---|
2656 | hr = pFile.queryInterfaceTo(aFile);
|
---|
2657 | }
|
---|
2658 | else
|
---|
2659 | {
|
---|
2660 | switch (vrc)
|
---|
2661 | {
|
---|
2662 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2663 | hr = GuestFile::setErrorExternal(this, guestRc);
|
---|
2664 | break;
|
---|
2665 |
|
---|
2666 | default:
|
---|
2667 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening guest file \"%s\" failed: %Rrc"),
|
---|
2668 | Utf8Str(aPath).c_str(), vrc);
|
---|
2669 | break;
|
---|
2670 | }
|
---|
2671 | }
|
---|
2672 |
|
---|
2673 | return hr;
|
---|
2674 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2675 | }
|
---|
2676 |
|
---|
2677 | STDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
|
---|
2678 | {
|
---|
2679 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2680 | ReturnComNotImplemented();
|
---|
2681 | #else
|
---|
2682 | LogFlowThisFuncEnter();
|
---|
2683 |
|
---|
2684 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2685 | return setError(E_INVALIDARG, tr("No file to query information for specified"));
|
---|
2686 | CheckComArgOutPointerValid(aInfo);
|
---|
2687 |
|
---|
2688 | AutoCaller autoCaller(this);
|
---|
2689 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2690 |
|
---|
2691 | HRESULT hr = S_OK;
|
---|
2692 |
|
---|
2693 | GuestFsObjData objData; int guestRc;
|
---|
2694 | int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
2695 | if (RT_SUCCESS(vrc))
|
---|
2696 | {
|
---|
2697 | ComObjPtr<GuestFsObjInfo> pFsObjInfo;
|
---|
2698 | hr = pFsObjInfo.createObject();
|
---|
2699 | if (FAILED(hr)) return hr;
|
---|
2700 |
|
---|
2701 | vrc = pFsObjInfo->init(objData);
|
---|
2702 | if (RT_SUCCESS(vrc))
|
---|
2703 | {
|
---|
2704 | hr = pFsObjInfo.queryInterfaceTo(aInfo);
|
---|
2705 | if (FAILED(hr)) return hr;
|
---|
2706 | }
|
---|
2707 | }
|
---|
2708 |
|
---|
2709 | if (RT_FAILURE(vrc))
|
---|
2710 | {
|
---|
2711 | switch (vrc)
|
---|
2712 | {
|
---|
2713 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2714 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2715 | break;
|
---|
2716 |
|
---|
2717 | case VERR_NOT_A_FILE:
|
---|
2718 | hr = setError(VBOX_E_IPRT_ERROR, tr("Element exists but is not a file"));
|
---|
2719 | break;
|
---|
2720 |
|
---|
2721 | default:
|
---|
2722 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information failed: %Rrc"), vrc);
|
---|
2723 | break;
|
---|
2724 | }
|
---|
2725 | }
|
---|
2726 |
|
---|
2727 | return hr;
|
---|
2728 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2729 | }
|
---|
2730 |
|
---|
2731 | STDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
|
---|
2732 | {
|
---|
2733 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2734 | ReturnComNotImplemented();
|
---|
2735 | #else
|
---|
2736 | LogFlowThisFuncEnter();
|
---|
2737 |
|
---|
2738 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
2739 | return setError(E_INVALIDARG, tr("No file to query size for specified"));
|
---|
2740 | CheckComArgOutPointerValid(aSize);
|
---|
2741 |
|
---|
2742 | AutoCaller autoCaller(this);
|
---|
2743 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2744 |
|
---|
2745 | HRESULT hr = S_OK;
|
---|
2746 |
|
---|
2747 | int64_t llSize; int guestRc;
|
---|
2748 | int vrc = fileQuerySizeInternal(Utf8Str(aPath), &llSize, &guestRc);
|
---|
2749 | if (RT_SUCCESS(vrc))
|
---|
2750 | {
|
---|
2751 | *aSize = llSize;
|
---|
2752 | }
|
---|
2753 | else
|
---|
2754 | {
|
---|
2755 | switch (vrc)
|
---|
2756 | {
|
---|
2757 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
2758 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
2759 | break;
|
---|
2760 |
|
---|
2761 | default:
|
---|
2762 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), vrc);
|
---|
2763 | break;
|
---|
2764 | }
|
---|
2765 | }
|
---|
2766 |
|
---|
2767 | return hr;
|
---|
2768 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2769 | }
|
---|
2770 |
|
---|
2771 | STDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
|
---|
2772 | {
|
---|
2773 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2774 | ReturnComNotImplemented();
|
---|
2775 | #else
|
---|
2776 | LogFlowThisFuncEnter();
|
---|
2777 |
|
---|
2778 | AutoCaller autoCaller(this);
|
---|
2779 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2780 |
|
---|
2781 | ReturnComNotImplemented();
|
---|
2782 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2783 | }
|
---|
2784 |
|
---|
2785 | STDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
|
---|
2786 | {
|
---|
2787 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2788 | ReturnComNotImplemented();
|
---|
2789 | #else
|
---|
2790 | LogFlowThisFuncEnter();
|
---|
2791 |
|
---|
2792 | AutoCaller autoCaller(this);
|
---|
2793 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2794 |
|
---|
2795 | ReturnComNotImplemented();
|
---|
2796 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2797 | }
|
---|
2798 |
|
---|
2799 | STDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
2800 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
|
---|
2801 | {
|
---|
2802 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2803 | ReturnComNotImplemented();
|
---|
2804 | #else
|
---|
2805 | LogFlowThisFuncEnter();
|
---|
2806 |
|
---|
2807 | com::SafeArray<LONG> affinity;
|
---|
2808 |
|
---|
2809 | return ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
|
---|
2810 | ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
|
---|
2811 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2812 | }
|
---|
2813 |
|
---|
2814 | STDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
2815 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
|
---|
2816 | ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
|
---|
2817 | IGuestProcess **aProcess)
|
---|
2818 | {
|
---|
2819 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2820 | ReturnComNotImplemented();
|
---|
2821 | #else
|
---|
2822 | LogFlowThisFuncEnter();
|
---|
2823 |
|
---|
2824 | if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
|
---|
2825 | return setError(E_INVALIDARG, tr("No command to execute specified"));
|
---|
2826 | CheckComArgOutPointerValid(aProcess);
|
---|
2827 |
|
---|
2828 | AutoCaller autoCaller(this);
|
---|
2829 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2830 |
|
---|
2831 | HRESULT hr = isReadyExternal();
|
---|
2832 | if (FAILED(hr))
|
---|
2833 | return hr;
|
---|
2834 |
|
---|
2835 | GuestProcessStartupInfo procInfo;
|
---|
2836 | procInfo.mCommand = Utf8Str(aCommand);
|
---|
2837 |
|
---|
2838 | if (aArguments)
|
---|
2839 | {
|
---|
2840 | com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
|
---|
2841 | for (size_t i = 0; i < arguments.size(); i++)
|
---|
2842 | procInfo.mArguments.push_back(Utf8Str(arguments[i]));
|
---|
2843 | }
|
---|
2844 |
|
---|
2845 | int rc = VINF_SUCCESS;
|
---|
2846 |
|
---|
2847 | /*
|
---|
2848 | * Create the process environment:
|
---|
2849 | * - Apply the session environment in a first step, and
|
---|
2850 | * - Apply environment variables specified by this call to
|
---|
2851 | * have the chance of overwriting/deleting session entries.
|
---|
2852 | */
|
---|
2853 | procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
|
---|
2854 |
|
---|
2855 | if (aEnvironment)
|
---|
2856 | {
|
---|
2857 | com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
|
---|
2858 | for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
|
---|
2859 | rc = procInfo.mEnvironment.Set(Utf8Str(environment[i]));
|
---|
2860 | }
|
---|
2861 |
|
---|
2862 | if (RT_SUCCESS(rc))
|
---|
2863 | {
|
---|
2864 | if (aFlags)
|
---|
2865 | {
|
---|
2866 | com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
2867 | for (size_t i = 0; i < flags.size(); i++)
|
---|
2868 | procInfo.mFlags |= flags[i];
|
---|
2869 | }
|
---|
2870 |
|
---|
2871 | procInfo.mTimeoutMS = aTimeoutMS;
|
---|
2872 |
|
---|
2873 | if (aAffinity)
|
---|
2874 | {
|
---|
2875 | com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
|
---|
2876 | for (size_t i = 0; i < affinity.size(); i++)
|
---|
2877 | {
|
---|
2878 | if (affinity[i])
|
---|
2879 | procInfo.mAffinity |= (uint64_t)1 << i;
|
---|
2880 | }
|
---|
2881 | }
|
---|
2882 |
|
---|
2883 | procInfo.mPriority = aPriority;
|
---|
2884 |
|
---|
2885 | ComObjPtr<GuestProcess> pProcess;
|
---|
2886 | rc = processCreateExInteral(procInfo, pProcess);
|
---|
2887 | if (RT_SUCCESS(rc))
|
---|
2888 | {
|
---|
2889 | /* Return guest session to the caller. */
|
---|
2890 | HRESULT hr2 = pProcess.queryInterfaceTo(aProcess);
|
---|
2891 | if (FAILED(hr2))
|
---|
2892 | rc = VERR_COM_OBJECT_NOT_FOUND;
|
---|
2893 |
|
---|
2894 | if (RT_SUCCESS(rc))
|
---|
2895 | rc = pProcess->startProcessAsync();
|
---|
2896 | }
|
---|
2897 | }
|
---|
2898 |
|
---|
2899 | if (RT_FAILURE(rc))
|
---|
2900 | {
|
---|
2901 | switch (rc)
|
---|
2902 | {
|
---|
2903 | case VERR_MAX_PROCS_REACHED:
|
---|
2904 | hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of concurrent guest processes per session (%ld) reached"),
|
---|
2905 | VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
2906 | break;
|
---|
2907 |
|
---|
2908 | /** @todo Add more errors here. */
|
---|
2909 |
|
---|
2910 | default:
|
---|
2911 | hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest process, rc=%Rrc"), rc);
|
---|
2912 | break;
|
---|
2913 | }
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 | LogFlowFuncLeaveRC(rc);
|
---|
2917 | return hr;
|
---|
2918 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2919 | }
|
---|
2920 |
|
---|
2921 | STDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
|
---|
2922 | {
|
---|
2923 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2924 | ReturnComNotImplemented();
|
---|
2925 | #else
|
---|
2926 | LogFlowThisFunc(("aPID=%RU32\n", aPID));
|
---|
2927 |
|
---|
2928 | CheckComArgOutPointerValid(aProcess);
|
---|
2929 | if (aPID == 0)
|
---|
2930 | return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
|
---|
2931 |
|
---|
2932 | AutoCaller autoCaller(this);
|
---|
2933 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2934 |
|
---|
2935 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2936 |
|
---|
2937 | HRESULT hr = S_OK;
|
---|
2938 |
|
---|
2939 | ComObjPtr<GuestProcess> pProcess;
|
---|
2940 | int rc = processGetByPID(aPID, &pProcess);
|
---|
2941 | if (RT_FAILURE(rc))
|
---|
2942 | hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPID);
|
---|
2943 |
|
---|
2944 | /* This will set (*aProcess) to NULL if pProgress is NULL. */
|
---|
2945 | HRESULT hr2 = pProcess.queryInterfaceTo(aProcess);
|
---|
2946 | if (SUCCEEDED(hr))
|
---|
2947 | hr = hr2;
|
---|
2948 |
|
---|
2949 | LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", *aProcess, hr));
|
---|
2950 | return hr;
|
---|
2951 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2952 | }
|
---|
2953 |
|
---|
2954 | STDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
|
---|
2955 | {
|
---|
2956 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2957 | ReturnComNotImplemented();
|
---|
2958 | #else
|
---|
2959 | LogFlowThisFuncEnter();
|
---|
2960 |
|
---|
2961 | AutoCaller autoCaller(this);
|
---|
2962 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2963 |
|
---|
2964 | ReturnComNotImplemented();
|
---|
2965 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2966 | }
|
---|
2967 |
|
---|
2968 | STDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
|
---|
2969 | {
|
---|
2970 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2971 | ReturnComNotImplemented();
|
---|
2972 | #else
|
---|
2973 | LogFlowThisFuncEnter();
|
---|
2974 |
|
---|
2975 | AutoCaller autoCaller(this);
|
---|
2976 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2977 |
|
---|
2978 | ReturnComNotImplemented();
|
---|
2979 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2980 | }
|
---|
2981 |
|
---|
2982 | STDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
|
---|
2983 | {
|
---|
2984 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2985 | ReturnComNotImplemented();
|
---|
2986 | #else
|
---|
2987 | LogFlowThisFuncEnter();
|
---|
2988 |
|
---|
2989 | AutoCaller autoCaller(this);
|
---|
2990 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
2991 |
|
---|
2992 | ReturnComNotImplemented();
|
---|
2993 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
2994 | }
|
---|
2995 |
|
---|
2996 | STDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
|
---|
2997 | {
|
---|
2998 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
2999 | ReturnComNotImplemented();
|
---|
3000 | #else
|
---|
3001 | LogFlowThisFuncEnter();
|
---|
3002 |
|
---|
3003 | AutoCaller autoCaller(this);
|
---|
3004 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
3005 |
|
---|
3006 | ReturnComNotImplemented();
|
---|
3007 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
3008 | }
|
---|
3009 |
|
---|
3010 | STDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
|
---|
3011 | {
|
---|
3012 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
3013 | ReturnComNotImplemented();
|
---|
3014 | #else
|
---|
3015 | LogFlowThisFuncEnter();
|
---|
3016 |
|
---|
3017 | AutoCaller autoCaller(this);
|
---|
3018 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
3019 |
|
---|
3020 | ReturnComNotImplemented();
|
---|
3021 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
3022 | }
|
---|
3023 |
|
---|
3024 | STDMETHODIMP GuestSession::WaitFor(ULONG aWaitFlags, ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
|
---|
3025 | {
|
---|
3026 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
3027 | ReturnComNotImplemented();
|
---|
3028 | #else
|
---|
3029 | LogFlowThisFuncEnter();
|
---|
3030 |
|
---|
3031 | CheckComArgOutPointerValid(aReason);
|
---|
3032 |
|
---|
3033 | AutoCaller autoCaller(this);
|
---|
3034 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
3035 |
|
---|
3036 | /*
|
---|
3037 | * Note: Do not hold any locks here while waiting!
|
---|
3038 | */
|
---|
3039 | HRESULT hr = S_OK;
|
---|
3040 |
|
---|
3041 | int guestRc; GuestSessionWaitResult_T waitResult;
|
---|
3042 | int vrc = waitFor(aWaitFlags, aTimeoutMS, waitResult, &guestRc);
|
---|
3043 | if (RT_SUCCESS(vrc))
|
---|
3044 | {
|
---|
3045 | *aReason = waitResult;
|
---|
3046 | }
|
---|
3047 | else
|
---|
3048 | {
|
---|
3049 | switch (vrc)
|
---|
3050 | {
|
---|
3051 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
3052 | hr = GuestSession::setErrorExternal(this, guestRc);
|
---|
3053 | break;
|
---|
3054 |
|
---|
3055 | case VERR_TIMEOUT:
|
---|
3056 | *aReason = GuestSessionWaitResult_Timeout;
|
---|
3057 | break;
|
---|
3058 |
|
---|
3059 | default:
|
---|
3060 | {
|
---|
3061 | const char *pszSessionName = mData.mSession.mName.c_str();
|
---|
3062 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
3063 | tr("Waiting for guest session \"%s\" failed: %Rrc"),
|
---|
3064 | pszSessionName ? pszSessionName : tr("Unnamed"), vrc);
|
---|
3065 | break;
|
---|
3066 | }
|
---|
3067 | }
|
---|
3068 | }
|
---|
3069 |
|
---|
3070 | LogFlowFuncLeaveRC(vrc);
|
---|
3071 | return hr;
|
---|
3072 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
3073 | }
|
---|
3074 |
|
---|
3075 | STDMETHODIMP GuestSession::WaitForArray(ComSafeArrayIn(GuestSessionWaitForFlag_T, aFlags), ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
|
---|
3076 | {
|
---|
3077 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
3078 | ReturnComNotImplemented();
|
---|
3079 | #else
|
---|
3080 | LogFlowThisFuncEnter();
|
---|
3081 |
|
---|
3082 | CheckComArgOutPointerValid(aReason);
|
---|
3083 |
|
---|
3084 | AutoCaller autoCaller(this);
|
---|
3085 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
3086 |
|
---|
3087 | /*
|
---|
3088 | * Note: Do not hold any locks here while waiting!
|
---|
3089 | */
|
---|
3090 | uint32_t fWaitFor = GuestSessionWaitForFlag_None;
|
---|
3091 | com::SafeArray<GuestSessionWaitForFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
3092 | for (size_t i = 0; i < flags.size(); i++)
|
---|
3093 | fWaitFor |= flags[i];
|
---|
3094 |
|
---|
3095 | return WaitFor(fWaitFor, aTimeoutMS, aReason);
|
---|
3096 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
3097 | }
|
---|
3098 |
|
---|