GuestSessionImpl.cpp revision 7b9f0c34e9ea328981c99e97054bdf8684d9d620
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox Main - XXX.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2012 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync* Header Files *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync*******************************************************************************/
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// constructor / destructor
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// public initializer/uninitializer for internal purposes only
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint GuestSession::init(Guest *aGuest, ULONG aSessionID,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync mData.mTimeout = 30 * 60 * 1000; /* Session timeout is 30 mins by default. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Confirm a successful initialization when it's the case. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Uninitializes the instance.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Called from FinalRelease().
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync// implementation of public getters/setters for attributes
388b6b190a5407548753b7fde12fa58134ec3563vboxsync/////////////////////////////////////////////////////////////////////////////
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Timeout)(ULONG aTimeout)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync LogFlowThisFunc(("%s cEnvVars=%RU32\n", mData.mName.c_str(), cEnvVars));
388b6b190a5407548753b7fde12fa58134ec3563vboxsync environment.detachTo(ComSafeArrayOutArg(aEnvironment));
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
388b6b190a5407548753b7fde12fa58134ec3563vboxsync collection.detachTo(ComSafeArrayOutArg(aProcesses));
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
388b6b190a5407548753b7fde12fa58134ec3563vboxsync SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
388b6b190a5407548753b7fde12fa58134ec3563vboxsync collection.detachTo(ComSafeArrayOutArg(aDirectories));
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
388b6b190a5407548753b7fde12fa58134ec3563vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync SafeIfaceArray<IGuestFile> collection(mData.mFiles);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync// private methods
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync/////////////////////////////////////////////////////////////////////////////
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSession::directoryClose(ComObjPtr<GuestDirectory> pDirectory)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSession::dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync rc = pProcess->callbackDispatcher(uContextID, uFunction, pvData, cbData);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSession::fileClose(ComObjPtr<GuestFile> pFile)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncconst GuestCredentials& GuestSession::getCredentials(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncconst GuestEnvironment& GuestSession::getEnvironment(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint GuestSession::processClose(ComObjPtr<GuestProcess> pProcess)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint GuestSession::processCreateExInteral(GuestProcessInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync /* Validate flags. */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync && !(procInfo.mFlags & ProcessCreateFlag_NoProfile)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Adjust timeout. If set to 0, we define
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * an infinite timeout. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /** @tood Implement process priority + affinity. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync if (mData.mProcesses.size() >= VBOX_GUESTCTRL_MAX_PROCESSES)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Create a new (host-based) process ID and assign it. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Is the context ID already used? */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!processExists(uNewProcessID, NULL /* pProgress */))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Callback with context ID was not found. This means
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync * we can use this context ID for our new callback we want
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * to add below. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break; /* Don't try too hard. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* Create the process object. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = pProcess->init(mData.mParent->getConsole() /* Console */, this /* Session */,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Add the created process to our map. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32\n",
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync catch (int rc2)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncinline bool GuestSession::processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return true;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return false;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncinline int GuestSession::processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* pProcess is optional. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SessionProcesses::iterator it = mData.mProcesses.begin();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Queries/collects information prior to establishing a guest session.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This is necessary to know which guest control protocol version to use,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * among other things (later).
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @return IPRT status code.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Try querying the guest control protocol version running on the guest.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This is done using the Guest Additions version
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uint32_t uVerAdditions = pGuest->getAdditionsVersion();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mData.mProtocolVersion = ( VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions) >= 4
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync && VBOX_FULL_VERSION_GET_MINOR(uVerAdditions) >= 2 )
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Build revision is ignored. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Tell the user but don't bitch too often. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync static short s_gctrlLegacyWarning = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (s_gctrlLegacyWarning++ < 3) /** @todo Find a bit nicer text. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions), VBOX_FULL_VERSION_GET_MINOR(uVerAdditions), mData.mProtocolVersion));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public methods
7e8ef90d3160234df0f254131b87af4243d79476vboxsync/////////////////////////////////////////////////////////////////////////////
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
7e8ef90d3160234df0f254131b87af4243d79476vboxsyncSTDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncSTDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode, ULONG aFlags, IGuestDirectory **aProgress)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsyncSTDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsyncSTDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, IN_BSTR aFlags, IGuestDirectory **aDirectory)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncSTDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncSTDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncSTDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncSTDMETHODIMP GuestSession::EnvironmentSetArray(ComSafeArrayIn(IN_BSTR, aValues))
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (!strEnv.isEmpty()) /* Silently skip empty entries. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsyncSTDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncSTDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestFile **aFile)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncSTDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncSTDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncSTDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncSTDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncSTDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncSTDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsyncSTDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncSTDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync HRESULT hr = ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsyncSTDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
7e8ef90d3160234df0f254131b87af4243d79476vboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
7e8ef90d3160234df0f254131b87af4243d79476vboxsync ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync return setError(E_INVALIDARG, tr("No command to execute specified"));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync procInfo.mArguments.push_back(Utf8Str(arguments[i]));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Create the process environment:
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * - Apply the session environment in a first step, and
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * - Apply environment variables specified by this call to
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * have the chance of overwriting/deleting session entries.
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync rc = procInfo.mEnvironment.Set(Utf8Str(environment[i]));
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync procInfo.mAffinity[i] = affinity[i]; /** @todo Really necessary? Later. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /* Return guest session to the caller. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of guest processes per session (%ld) reached"),
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /** @todo Add more errors here. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest process, rc=%Rrc"), rc);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncSTDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPID);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* This will set (*aProcess) to NULL if pProgress is NULL. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", *aProcess, hr));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::SetTimeout(ULONG aTimeoutMS)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync return setError(E_INVALIDARG, tr("Invalid timeout value specified"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowThisFunc(("aTimeoutMS=%RU32\n", mData.mTimeout));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsyncSTDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsyncSTDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncSTDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */