VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp@ 42213

Last change on this file since 42213 was 42194, checked in by vboxsync, 13 years ago

Guest Control 2.0: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.3 KB
Line 
1
2/* $Id: GuestSessionImpl.cpp 42194 2012-07-17 14:58:32Z vboxsync $ */
3/** @file
4 * VirtualBox Main - XXX.
5 */
6
7/*
8 * Copyright (C) 2012 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 "GuestSessionImpl.h"
25
26#include "Global.h"
27#include "AutoCaller.h"
28#include "Logging.h"
29
30#include <iprt/env.h>
31
32#include <VBox/com/array.h>
33
34
35// constructor / destructor
36/////////////////////////////////////////////////////////////////////////////
37
38DEFINE_EMPTY_CTOR_DTOR(GuestSession)
39
40HRESULT GuestSession::FinalConstruct(void)
41{
42 LogFlowThisFunc(("\n"));
43 return BaseFinalConstruct();
44}
45
46void GuestSession::FinalRelease(void)
47{
48 LogFlowThisFuncEnter();
49 uninit();
50 BaseFinalRelease();
51 LogFlowThisFuncLeave();
52}
53
54// public initializer/uninitializer for internal purposes only
55/////////////////////////////////////////////////////////////////////////////
56
57int GuestSession::init(Guest *aGuest, uint32_t aSessionID,
58 Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName)
59{
60 LogFlowThisFuncEnter();
61
62 AssertPtrReturn(aGuest, VERR_INVALID_POINTER);
63 AssertReturn(aSessionID, VERR_INVALID_PARAMETER);
64
65 /* Enclose the state transition NotReady->InInit->Ready. */
66 AutoInitSpan autoInitSpan(this);
67 AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
68
69 mData.mParent = aGuest;
70 mData.mId = aSessionID;
71
72 mData.mCredentials.mUser = aUser;
73 mData.mCredentials.mPassword = aPassword;
74 mData.mCredentials.mDomain = aDomain;
75 mData.mName = aName;
76
77 /* Confirm a successful initialization when it's the case. */
78 autoInitSpan.setSucceeded();
79
80 LogFlowFuncLeaveRC(VINF_SUCCESS);
81 return VINF_SUCCESS;
82}
83
84/**
85 * Uninitializes the instance.
86 * Called from FinalRelease().
87 */
88void GuestSession::uninit(void)
89{
90 LogFlowThisFuncEnter();
91
92 /* Enclose the state transition Ready->InUninit->NotReady. */
93 AutoUninitSpan autoUninitSpan(this);
94 if (autoUninitSpan.uninitDone())
95 return;
96
97#ifdef VBOX_WITH_GUEST_CONTROL
98 for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
99 itDirs != mData.mDirectories.end(); ++itDirs)
100 {
101 (*itDirs)->uninit();
102 (*itDirs).setNull();
103 }
104 mData.mDirectories.clear();
105
106 for (SessionFiles::iterator itFiles = mData.mFiles.begin();
107 itFiles != mData.mFiles.end(); ++itFiles)
108 {
109 (*itFiles)->uninit();
110 (*itFiles).setNull();
111 }
112 mData.mFiles.clear();
113
114 for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
115 itProcs != mData.mProcesses.end(); ++itProcs)
116 {
117 itProcs->second->uninit();
118 itProcs->second.setNull();
119 }
120 mData.mProcesses.clear();
121
122 mData.mParent->sessionClose(this);
123
124 LogFlowThisFuncLeave();
125#endif
126}
127
128// implementation of public getters/setters for attributes
129/////////////////////////////////////////////////////////////////////////////
130
131STDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
132{
133#ifndef VBOX_WITH_GUEST_CONTROL
134 ReturnComNotImplemented();
135#else
136 LogFlowThisFuncEnter();
137
138 CheckComArgOutPointerValid(aUser);
139
140 AutoCaller autoCaller(this);
141 if (FAILED(autoCaller.rc())) return autoCaller.rc();
142
143 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
144
145 mData.mCredentials.mUser.cloneTo(aUser);
146
147 LogFlowFuncLeaveRC(S_OK);
148 return S_OK;
149#endif /* VBOX_WITH_GUEST_CONTROL */
150}
151
152STDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
153{
154#ifndef VBOX_WITH_GUEST_CONTROL
155 ReturnComNotImplemented();
156#else
157 LogFlowThisFuncEnter();
158
159 CheckComArgOutPointerValid(aDomain);
160
161 AutoCaller autoCaller(this);
162 if (FAILED(autoCaller.rc())) return autoCaller.rc();
163
164 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
165
166 mData.mCredentials.mDomain.cloneTo(aDomain);
167
168 LogFlowFuncLeaveRC(S_OK);
169 return S_OK;
170#endif /* VBOX_WITH_GUEST_CONTROL */
171}
172
173STDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
174{
175#ifndef VBOX_WITH_GUEST_CONTROL
176 ReturnComNotImplemented();
177#else
178 LogFlowThisFuncEnter();
179
180 CheckComArgOutPointerValid(aName);
181
182 AutoCaller autoCaller(this);
183 if (FAILED(autoCaller.rc())) return autoCaller.rc();
184
185 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
186
187 mData.mName.cloneTo(aName);
188
189 LogFlowFuncLeaveRC(S_OK);
190 return S_OK;
191#endif /* VBOX_WITH_GUEST_CONTROL */
192}
193
194STDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
195{
196#ifndef VBOX_WITH_GUEST_CONTROL
197 ReturnComNotImplemented();
198#else
199 LogFlowThisFuncEnter();
200
201 CheckComArgOutPointerValid(aId);
202
203 AutoCaller autoCaller(this);
204 if (FAILED(autoCaller.rc())) return autoCaller.rc();
205
206 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
207
208 *aId = mData.mId;
209
210 LogFlowFuncLeaveRC(S_OK);
211 return S_OK;
212#endif /* VBOX_WITH_GUEST_CONTROL */
213}
214
215STDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
216{
217#ifndef VBOX_WITH_GUEST_CONTROL
218 ReturnComNotImplemented();
219#else
220 LogFlowThisFuncEnter();
221
222 CheckComArgOutPointerValid(aTimeout);
223
224 AutoCaller autoCaller(this);
225 if (FAILED(autoCaller.rc())) return autoCaller.rc();
226
227 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
228
229 *aTimeout = mData.mTimeout;
230
231 LogFlowFuncLeaveRC(S_OK);
232 return S_OK;
233#endif /* VBOX_WITH_GUEST_CONTROL */
234}
235
236STDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
237{
238#ifndef VBOX_WITH_GUEST_CONTROL
239 ReturnComNotImplemented();
240#else
241 LogFlowThisFuncEnter();
242
243 CheckComArgOutSafeArrayPointerValid(aEnvironment);
244
245 AutoCaller autoCaller(this);
246 if (FAILED(autoCaller.rc())) return autoCaller.rc();
247
248 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
249
250 size_t cEnvVars = mData.mEnvironment.Size();
251 LogFlowThisFunc(("%s cEnvVars=%RU32\n", mData.mName.c_str(), cEnvVars));
252 com::SafeArray<BSTR> environment(cEnvVars);
253
254 for (size_t i = 0; i < cEnvVars; i++)
255 {
256 Bstr strEnv(mData.mEnvironment.Get(i));
257 strEnv.cloneTo(&environment[i]);
258 }
259 environment.detachTo(ComSafeArrayOutArg(aEnvironment));
260
261 LogFlowFuncLeaveRC(S_OK);
262 return S_OK;
263#endif /* VBOX_WITH_GUEST_CONTROL */
264}
265
266STDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
267{
268#ifndef VBOX_WITH_GUEST_CONTROL
269 ReturnComNotImplemented();
270#else
271 LogFlowThisFuncEnter();
272
273 CheckComArgOutSafeArrayPointerValid(aProcesses);
274
275 AutoCaller autoCaller(this);
276 if (FAILED(autoCaller.rc())) return autoCaller.rc();
277
278 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
279
280 SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
281 collection.detachTo(ComSafeArrayOutArg(aProcesses));
282
283 LogFlowFuncLeaveRC(S_OK);
284 return S_OK;
285#endif /* VBOX_WITH_GUEST_CONTROL */
286}
287
288STDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
289{
290#ifndef VBOX_WITH_GUEST_CONTROL
291 ReturnComNotImplemented();
292#else
293 LogFlowThisFuncEnter();
294
295 CheckComArgOutSafeArrayPointerValid(aDirectories);
296
297 AutoCaller autoCaller(this);
298 if (FAILED(autoCaller.rc())) return autoCaller.rc();
299
300 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
301
302 SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
303 collection.detachTo(ComSafeArrayOutArg(aDirectories));
304
305 LogFlowFuncLeaveRC(S_OK);
306 return S_OK;
307#endif /* VBOX_WITH_GUEST_CONTROL */
308}
309
310STDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
311{
312#ifndef VBOX_WITH_GUEST_CONTROL
313 ReturnComNotImplemented();
314#else
315 LogFlowThisFuncEnter();
316
317 CheckComArgOutSafeArrayPointerValid(aFiles);
318
319 AutoCaller autoCaller(this);
320 if (FAILED(autoCaller.rc())) return autoCaller.rc();
321
322 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
323
324 SafeIfaceArray<IGuestFile> collection(mData.mFiles);
325 collection.detachTo(ComSafeArrayOutArg(aFiles));
326
327 LogFlowFuncLeaveRC(S_OK);
328 return S_OK;
329#endif /* VBOX_WITH_GUEST_CONTROL */
330}
331
332// private methods
333/////////////////////////////////////////////////////////////////////////////
334
335int GuestSession::directoryClose(ComObjPtr<GuestDirectory> pDirectory)
336{
337 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
338
339 for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
340 itDirs != mData.mDirectories.end(); ++itDirs)
341 {
342 if (pDirectory == (*itDirs))
343 {
344 mData.mDirectories.erase(itDirs);
345 return VINF_SUCCESS;
346 }
347 }
348
349 return VERR_NOT_FOUND;
350}
351
352int GuestSession::fileClose(ComObjPtr<GuestFile> pFile)
353{
354 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
355
356 for (SessionFiles::iterator itFiles = mData.mFiles.begin();
357 itFiles != mData.mFiles.end(); ++itFiles)
358 {
359 if (pFile == (*itFiles))
360 {
361 mData.mFiles.erase(itFiles);
362 return VINF_SUCCESS;
363 }
364 }
365
366 return VERR_NOT_FOUND;
367}
368
369const GuestCredentials& GuestSession::getCredentials(void)
370{
371 return mData.mCredentials;
372}
373
374const GuestEnvironment& GuestSession::getEnvironment(void)
375{
376 return mData.mEnvironment;
377}
378
379int GuestSession::processClose(ComObjPtr<GuestProcess> pProcess)
380{
381 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
382
383 for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
384 itProcs != mData.mProcesses.end(); ++itProcs)
385 {
386 if (pProcess == itProcs->second)
387 {
388 mData.mProcesses.erase(itProcs);
389 return VINF_SUCCESS;
390 }
391 }
392
393 return VERR_NOT_FOUND;
394}
395
396int GuestSession::processCreateExInteral(GuestProcessInfo &aProcInfo, IGuestProcess **aProcess)
397{
398 AssertPtrReturn(aProcess, VERR_INVALID_POINTER);
399
400 /* Validate flags. */
401 if (aProcInfo.mFlags)
402 {
403 if ( !(aProcInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
404 && !(aProcInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
405 && !(aProcInfo.mFlags & ProcessCreateFlag_Hidden)
406 && !(aProcInfo.mFlags & ProcessCreateFlag_NoProfile))
407 {
408 return VERR_INVALID_PARAMETER;
409 }
410 }
411
412 /* Adjust timeout. If set to 0, we define
413 * an infinite timeout. */
414 if (aProcInfo.mTimeoutMS == 0)
415 aProcInfo.mTimeoutMS = UINT32_MAX;
416
417 /** @tood Implement process priority + affinity. */
418
419 int rc = VERR_MAX_THRDS_REACHED;
420
421 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
422
423 /* Create a new (host-based) process ID and assign it. */
424 uint32_t uNewProcessID = 0;
425 uint32_t uTries = 0;
426
427 for (;;)
428 {
429 /* Is the context ID already used? Try next ID ... */
430 if (!processExists(uNewProcessID++))
431 {
432 /* Callback with context ID was not found. This means
433 * we can use this context ID for our new callback we want
434 * to add below. */
435 rc = VINF_SUCCESS;
436 break;
437 }
438
439 if (++uTries == UINT32_MAX)
440 break; /* Don't try too hard. */
441 }
442 if (RT_FAILURE(rc)) throw rc;
443
444 ComObjPtr<GuestProcess> pGuestProcess;
445 try
446 {
447 /* Create the session object. */
448 HRESULT hr = pGuestProcess.createObject();
449 if (FAILED(hr)) throw VERR_COM_UNEXPECTED;
450
451 rc = pGuestProcess->init(mData.mParent->getConsole() /* Console */, this /* Session */,
452 uNewProcessID, aProcInfo);
453 if (RT_FAILURE(rc)) throw rc;
454
455 mData.mProcesses[uNewProcessID] = pGuestProcess;
456
457 /* Return guest session to the caller. */
458 hr = pGuestProcess.queryInterfaceTo(aProcess);
459 if (FAILED(hr)) throw VERR_COM_OBJECT_NOT_FOUND;
460 }
461 catch (int rc2)
462 {
463 rc = rc2;
464 }
465
466 return rc;
467}
468
469inline bool GuestSession::processExists(uint32_t uProcessID)
470{
471 AssertReturn(uProcessID, false);
472
473 SessionProcesses::const_iterator itProcesses = mData.mProcesses.find(uProcessID);
474 return (itProcesses == mData.mProcesses.end()) ? false : true;
475}
476
477// implementation of public methods
478/////////////////////////////////////////////////////////////////////////////
479
480STDMETHODIMP GuestSession::Close(void)
481{
482#ifndef VBOX_WITH_GUEST_CONTROL
483 ReturnComNotImplemented();
484#else
485 LogFlowThisFuncEnter();
486
487 uninit();
488
489 LogFlowFuncLeaveRC(S_OK);
490 return S_OK;
491#endif /* VBOX_WITH_GUEST_CONTROL */
492}
493
494STDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress)
495{
496#ifndef VBOX_WITH_GUEST_CONTROL
497 ReturnComNotImplemented();
498#else
499 LogFlowThisFuncEnter();
500
501 AutoCaller autoCaller(this);
502 if (FAILED(autoCaller.rc())) return autoCaller.rc();
503
504 ReturnComNotImplemented();
505#endif /* VBOX_WITH_GUEST_CONTROL */
506}
507
508STDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress)
509{
510#ifndef VBOX_WITH_GUEST_CONTROL
511 ReturnComNotImplemented();
512#else
513 LogFlowThisFuncEnter();
514
515 AutoCaller autoCaller(this);
516 if (FAILED(autoCaller.rc())) return autoCaller.rc();
517
518 ReturnComNotImplemented();
519#endif /* VBOX_WITH_GUEST_CONTROL */
520}
521
522STDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode, ULONG aFlags, IGuestDirectory **aProgress)
523{
524#ifndef VBOX_WITH_GUEST_CONTROL
525 ReturnComNotImplemented();
526#else
527 LogFlowThisFuncEnter();
528
529 AutoCaller autoCaller(this);
530 if (FAILED(autoCaller.rc())) return autoCaller.rc();
531
532 ReturnComNotImplemented();
533#endif /* VBOX_WITH_GUEST_CONTROL */
534}
535
536STDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory)
537{
538#ifndef VBOX_WITH_GUEST_CONTROL
539 ReturnComNotImplemented();
540#else
541 LogFlowThisFuncEnter();
542
543 AutoCaller autoCaller(this);
544 if (FAILED(autoCaller.rc())) return autoCaller.rc();
545
546 ReturnComNotImplemented();
547#endif /* VBOX_WITH_GUEST_CONTROL */
548}
549
550STDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
551{
552#ifndef VBOX_WITH_GUEST_CONTROL
553 ReturnComNotImplemented();
554#else
555 LogFlowThisFuncEnter();
556
557 AutoCaller autoCaller(this);
558 if (FAILED(autoCaller.rc())) return autoCaller.rc();
559
560 ReturnComNotImplemented();
561#endif /* VBOX_WITH_GUEST_CONTROL */
562}
563
564STDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, IN_BSTR aFlags, IGuestDirectory **aDirectory)
565{
566#ifndef VBOX_WITH_GUEST_CONTROL
567 ReturnComNotImplemented();
568#else
569 LogFlowThisFuncEnter();
570
571 AutoCaller autoCaller(this);
572 if (FAILED(autoCaller.rc())) return autoCaller.rc();
573
574 ReturnComNotImplemented();
575#endif /* VBOX_WITH_GUEST_CONTROL */
576}
577
578STDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
579{
580#ifndef VBOX_WITH_GUEST_CONTROL
581 ReturnComNotImplemented();
582#else
583 LogFlowThisFuncEnter();
584
585 AutoCaller autoCaller(this);
586 if (FAILED(autoCaller.rc())) return autoCaller.rc();
587
588 ReturnComNotImplemented();
589#endif /* VBOX_WITH_GUEST_CONTROL */
590}
591
592STDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
593{
594#ifndef VBOX_WITH_GUEST_CONTROL
595 ReturnComNotImplemented();
596#else
597 LogFlowThisFuncEnter();
598
599 AutoCaller autoCaller(this);
600 if (FAILED(autoCaller.rc())) return autoCaller.rc();
601
602 ReturnComNotImplemented();
603#endif /* VBOX_WITH_GUEST_CONTROL */
604}
605
606STDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
607{
608#ifndef VBOX_WITH_GUEST_CONTROL
609 ReturnComNotImplemented();
610#else
611 LogFlowThisFuncEnter();
612
613 AutoCaller autoCaller(this);
614 if (FAILED(autoCaller.rc())) return autoCaller.rc();
615
616 ReturnComNotImplemented();
617#endif /* VBOX_WITH_GUEST_CONTROL */
618}
619
620STDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
621{
622#ifndef VBOX_WITH_GUEST_CONTROL
623 ReturnComNotImplemented();
624#else
625 LogFlowThisFuncEnter();
626
627 AutoCaller autoCaller(this);
628 if (FAILED(autoCaller.rc())) return autoCaller.rc();
629
630 ReturnComNotImplemented();
631#endif /* VBOX_WITH_GUEST_CONTROL */
632}
633
634STDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
635{
636#ifndef VBOX_WITH_GUEST_CONTROL
637 ReturnComNotImplemented();
638#else
639 LogFlowThisFuncEnter();
640
641 AutoCaller autoCaller(this);
642 if (FAILED(autoCaller.rc())) return autoCaller.rc();
643
644 ReturnComNotImplemented();
645#endif /* VBOX_WITH_GUEST_CONTROL */
646}
647
648STDMETHODIMP GuestSession::EnvironmentClear(void)
649{
650#ifndef VBOX_WITH_GUEST_CONTROL
651 ReturnComNotImplemented();
652#else
653 LogFlowThisFuncEnter();
654
655 AutoCaller autoCaller(this);
656 if (FAILED(autoCaller.rc())) return autoCaller.rc();
657
658 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
659
660 mData.mEnvironment.Clear();
661
662 LogFlowFuncLeaveRC(S_OK);
663 return S_OK;
664#endif /* VBOX_WITH_GUEST_CONTROL */
665}
666
667STDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
668{
669#ifndef VBOX_WITH_GUEST_CONTROL
670 ReturnComNotImplemented();
671#else
672 LogFlowThisFuncEnter();
673
674 if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
675 return setError(E_INVALIDARG, tr("No value name specified"));
676
677 CheckComArgOutPointerValid(aValue);
678
679 AutoCaller autoCaller(this);
680 if (FAILED(autoCaller.rc())) return autoCaller.rc();
681
682 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
683
684 Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
685 strValue.cloneTo(aValue);
686
687 LogFlowFuncLeaveRC(S_OK);
688 return S_OK;
689#endif /* VBOX_WITH_GUEST_CONTROL */
690}
691
692STDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
693{
694#ifndef VBOX_WITH_GUEST_CONTROL
695 ReturnComNotImplemented();
696#else
697 LogFlowThisFuncEnter();
698
699 if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
700 return setError(E_INVALIDARG, tr("No value name specified"));
701
702 AutoCaller autoCaller(this);
703 if (FAILED(autoCaller.rc())) return autoCaller.rc();
704
705 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
706
707 int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
708
709 HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
710 LogFlowFuncLeaveRC(hr);
711 return hr;
712#endif /* VBOX_WITH_GUEST_CONTROL */
713}
714
715STDMETHODIMP GuestSession::EnvironmentSetArray(ComSafeArrayIn(IN_BSTR, aValues))
716{
717#ifndef VBOX_WITH_GUEST_CONTROL
718 ReturnComNotImplemented();
719#else
720 LogFlowThisFuncEnter();
721
722 AutoCaller autoCaller(this);
723 if (FAILED(autoCaller.rc())) return autoCaller.rc();
724
725 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
726
727 com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
728
729 int rc = VINF_SUCCESS;
730 for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
731 {
732 Utf8Str strEnv(environment[i]);
733 if (!strEnv.isEmpty()) /* Silently skip empty entries. */
734 rc = mData.mEnvironment.Set(strEnv);
735 }
736
737 HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
738 LogFlowFuncLeaveRC(hr);
739 return hr;
740#endif /* VBOX_WITH_GUEST_CONTROL */
741}
742
743STDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
744{
745#ifndef VBOX_WITH_GUEST_CONTROL
746 ReturnComNotImplemented();
747#else
748 LogFlowThisFuncEnter();
749
750 AutoCaller autoCaller(this);
751 if (FAILED(autoCaller.rc())) return autoCaller.rc();
752
753 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
754
755 mData.mEnvironment.Unset(Utf8Str(aName));
756
757 LogFlowFuncLeaveRC(S_OK);
758 return S_OK;
759#endif /* VBOX_WITH_GUEST_CONTROL */
760}
761
762STDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestFile **aFile)
763{
764#ifndef VBOX_WITH_GUEST_CONTROL
765 ReturnComNotImplemented();
766#else
767 LogFlowThisFuncEnter();
768
769 AutoCaller autoCaller(this);
770 if (FAILED(autoCaller.rc())) return autoCaller.rc();
771
772 ReturnComNotImplemented();
773#endif /* VBOX_WITH_GUEST_CONTROL */
774}
775
776STDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
777{
778#ifndef VBOX_WITH_GUEST_CONTROL
779 ReturnComNotImplemented();
780#else
781 LogFlowThisFuncEnter();
782
783 AutoCaller autoCaller(this);
784 if (FAILED(autoCaller.rc())) return autoCaller.rc();
785
786 ReturnComNotImplemented();
787#endif /* VBOX_WITH_GUEST_CONTROL */
788}
789
790STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
791{
792#ifndef VBOX_WITH_GUEST_CONTROL
793 ReturnComNotImplemented();
794#else
795 LogFlowThisFuncEnter();
796
797 AutoCaller autoCaller(this);
798 if (FAILED(autoCaller.rc())) return autoCaller.rc();
799
800 ReturnComNotImplemented();
801#endif /* VBOX_WITH_GUEST_CONTROL */
802}
803
804STDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
805{
806#ifndef VBOX_WITH_GUEST_CONTROL
807 ReturnComNotImplemented();
808#else
809 LogFlowThisFuncEnter();
810
811 AutoCaller autoCaller(this);
812 if (FAILED(autoCaller.rc())) return autoCaller.rc();
813
814 ReturnComNotImplemented();
815#endif /* VBOX_WITH_GUEST_CONTROL */
816}
817
818STDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
819{
820#ifndef VBOX_WITH_GUEST_CONTROL
821 ReturnComNotImplemented();
822#else
823 LogFlowThisFuncEnter();
824
825 AutoCaller autoCaller(this);
826 if (FAILED(autoCaller.rc())) return autoCaller.rc();
827
828 ReturnComNotImplemented();
829#endif /* VBOX_WITH_GUEST_CONTROL */
830}
831
832STDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
833{
834#ifndef VBOX_WITH_GUEST_CONTROL
835 ReturnComNotImplemented();
836#else
837 LogFlowThisFuncEnter();
838
839 AutoCaller autoCaller(this);
840 if (FAILED(autoCaller.rc())) return autoCaller.rc();
841
842 ReturnComNotImplemented();
843#endif /* VBOX_WITH_GUEST_CONTROL */
844}
845
846STDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
847{
848#ifndef VBOX_WITH_GUEST_CONTROL
849 ReturnComNotImplemented();
850#else
851 LogFlowThisFuncEnter();
852
853 AutoCaller autoCaller(this);
854 if (FAILED(autoCaller.rc())) return autoCaller.rc();
855
856 ReturnComNotImplemented();
857#endif /* VBOX_WITH_GUEST_CONTROL */
858}
859
860STDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
861{
862#ifndef VBOX_WITH_GUEST_CONTROL
863 ReturnComNotImplemented();
864#else
865 LogFlowThisFuncEnter();
866
867 AutoCaller autoCaller(this);
868 if (FAILED(autoCaller.rc())) return autoCaller.rc();
869
870 ReturnComNotImplemented();
871#endif /* VBOX_WITH_GUEST_CONTROL */
872}
873
874STDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
875 ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
876{
877#ifndef VBOX_WITH_GUEST_CONTROL
878 ReturnComNotImplemented();
879#else
880 LogFlowThisFuncEnter();
881
882 com::SafeArray<LONG> affinity;
883
884 return ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
885 ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
886#endif /* VBOX_WITH_GUEST_CONTROL */
887}
888
889STDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
890 ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
891 ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
892 IGuestProcess **aProcess)
893{
894#ifndef VBOX_WITH_GUEST_CONTROL
895 ReturnComNotImplemented();
896#else
897 LogFlowThisFuncEnter();
898
899 AutoCaller autoCaller(this);
900 if (FAILED(autoCaller.rc())) return autoCaller.rc();
901
902 CheckComArgOutPointerValid(aProcess);
903
904 GuestProcessInfo procInfo;
905
906 procInfo.mCommand = Utf8Str(aCommand);
907
908 com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
909 procInfo.mArguments.reserve(arguments.size());
910 for (size_t i = 0; i < arguments.size(); i++)
911 procInfo.mArguments[i] = Utf8Str(Bstr(arguments[i]));
912
913 int rc = VINF_SUCCESS;
914
915 /* Create the process environment:
916 * - Apply the session environment in a first step, and
917 * - Apply environment variables specified by this call to
918 * have the chance of overwriting/deleting session entries.
919 */
920 procInfo.mEnvironment = mData.mEnvironment;
921 com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
922 for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
923 rc = mData.mEnvironment.Set(Utf8Str(environment[i]));
924
925 if (RT_SUCCESS(rc))
926 {
927
928 com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
929 for (size_t i = 0; i < flags.size(); i++)
930 procInfo.mFlags |= flags[i];
931
932 procInfo.mTimeoutMS = aTimeoutMS;
933
934 com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
935 procInfo.mAffinity.reserve(affinity.size());
936 for (size_t i = 0; i < affinity.size(); i++)
937 procInfo.mAffinity[i] = affinity[i]; /** @todo Really necessary? Later. */
938
939 procInfo.mPriority = aPriority;
940
941 rc = processCreateExInteral(procInfo, aProcess);
942 }
943
944 HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
945 LogFlowFuncLeaveRC(hr);
946 return hr;
947#endif /* VBOX_WITH_GUEST_CONTROL */
948}
949
950STDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
951{
952#ifndef VBOX_WITH_GUEST_CONTROL
953 ReturnComNotImplemented();
954#else
955 LogFlowThisFuncEnter();
956
957 AutoCaller autoCaller(this);
958 if (FAILED(autoCaller.rc())) return autoCaller.rc();
959
960 ReturnComNotImplemented();
961#endif /* VBOX_WITH_GUEST_CONTROL */
962}
963
964STDMETHODIMP GuestSession::SetTimeout(ULONG aTimeoutMS)
965{
966#ifndef VBOX_WITH_GUEST_CONTROL
967 ReturnComNotImplemented();
968#else
969 LogFlowThisFuncEnter();
970
971 AutoCaller autoCaller(this);
972 if (FAILED(autoCaller.rc())) return autoCaller.rc();
973
974 ReturnComNotImplemented();
975#endif /* VBOX_WITH_GUEST_CONTROL */
976}
977
978STDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
979{
980#ifndef VBOX_WITH_GUEST_CONTROL
981 ReturnComNotImplemented();
982#else
983 LogFlowThisFuncEnter();
984
985 AutoCaller autoCaller(this);
986 if (FAILED(autoCaller.rc())) return autoCaller.rc();
987
988 ReturnComNotImplemented();
989#endif /* VBOX_WITH_GUEST_CONTROL */
990}
991
992STDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
993{
994#ifndef VBOX_WITH_GUEST_CONTROL
995 ReturnComNotImplemented();
996#else
997 LogFlowThisFuncEnter();
998
999 AutoCaller autoCaller(this);
1000 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1001
1002 ReturnComNotImplemented();
1003#endif /* VBOX_WITH_GUEST_CONTROL */
1004}
1005
1006STDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
1007{
1008#ifndef VBOX_WITH_GUEST_CONTROL
1009 ReturnComNotImplemented();
1010#else
1011 LogFlowThisFuncEnter();
1012
1013 AutoCaller autoCaller(this);
1014 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1015
1016 ReturnComNotImplemented();
1017#endif /* VBOX_WITH_GUEST_CONTROL */
1018}
1019
1020STDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
1021{
1022#ifndef VBOX_WITH_GUEST_CONTROL
1023 ReturnComNotImplemented();
1024#else
1025 LogFlowThisFuncEnter();
1026
1027 AutoCaller autoCaller(this);
1028 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1029
1030 ReturnComNotImplemented();
1031#endif /* VBOX_WITH_GUEST_CONTROL */
1032}
1033
1034STDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
1035{
1036#ifndef VBOX_WITH_GUEST_CONTROL
1037 ReturnComNotImplemented();
1038#else
1039 LogFlowThisFuncEnter();
1040
1041 AutoCaller autoCaller(this);
1042 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1043
1044 ReturnComNotImplemented();
1045#endif /* VBOX_WITH_GUEST_CONTROL */
1046}
1047
Note: See TracBrowser for help on using the repository browser.

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