GuestSessionImpl.cpp revision c99b597540585068d22dde4c9f74730305f24097
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
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// public initializer/uninitializer for internal purposes only
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncint GuestSession::init(Guest *aGuest, ULONG aSessionID,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync mData.mTimeout = 30 * 60 * 1000; /* Session timeout is 30 mins by default. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Confirm a successful initialization when it's the case. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Uninitializes the instance.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Called from FinalRelease().
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("Closing directories (%RU64 total)\n",
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("pFile=%p, cRefs=%RU32\n", (*itDirs), cRefs));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("pFile=%p, cRefs=%RU32\n", (*itFiles), cRefs));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("Closing processes (%RU64 total)\n",
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("pProcess=%p, cRefs=%RU32\n", itProcs->second, cRefs));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("mNumObjects=%RU32\n", mData.mNumObjects));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public getters/setters for attributes
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
7e8ef90d3160234df0f254131b87af4243d79476vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Timeout)(ULONG aTimeout)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFunc(("%s cEnvVars=%RU32\n", mData.mName.c_str(), cEnvVars));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync environment.detachTo(ComSafeArrayOutArg(aEnvironment));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Environment)(ComSafeArrayIn(IN_BSTR, aValues))
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (!strEnv.isEmpty()) /* Silently skip empty entries. */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aProcesses));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aDirectories));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestFile> collection(mData.mFiles);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync// private methods
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync/////////////////////////////////////////////////////////////////////////////
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::directoryRemoveFromList(GuestDirectory *pDirectory)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync HRESULT hr = (*itDirs)->COMGETTER(DirectoryName)(strName.asOutParam());
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %ld directories)\n",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(strName).c_str(), mData.mId, mData.mDirectories.size() - 1));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* Construct arguments. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync guestRc = procTool.TerminatedOk(NULL /* Exit code */);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return RT_SUCCESS(guestRc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync bool fDirectory, const Utf8Str &strName, int *pGuestRc)
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (strPath.length()) /* Otherwise use /tmp or equivalent. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync guestRc = procTool.TerminatedOk(NULL /* Exit code */);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return RT_SUCCESS(guestRc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsyncint GuestSession::directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter,
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the directory object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Add the created directory to our vector. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync LogFlowFunc(("Added new directory \"%s\" (Session: %RU32)\n",
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncint GuestSession::dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync rc = pProcess->callbackDispatcher(uContextID, uFunction, pvData, cbData);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::fileRemoveFromList(GuestFile *pFile)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync HRESULT hr = (*itFiles)->COMGETTER(FileName)(strName.asOutParam());
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("Removing file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Utf8Str(strName).c_str(), mData.mId, mData.mFiles.size() - 1, mData.mNumObjects - 1));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowThisFunc(("pObject=%p, cRefs=%RU32\n", pFile, cRefs));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc)
004d74842597dacc4009803171296dfcf9398c69vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync procInfo.mArguments.push_back(strPath); /* The file we want to remove. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync guestRc = procTool.TerminatedOk(NULL /* Exit code */);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return RT_SUCCESS(guestRc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncint GuestSession::fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile, int *pGuestRc)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, iOffset=%RI64\n",
5366e994777f9d9391cf809dc77610f57270d75dvboxsync strPath.c_str(), strOpenMode.c_str(), strDisposition.c_str(), uCreationMode, iOffset));
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the directory object. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync strPath, strOpenMode, strDisposition, uCreationMode, iOffset, pGuestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /** @todo Handle guestRc. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Add the created directory to our vector. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFunc(("Added new file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync strPath.c_str(), mData.mId, mData.mProcesses.size(), mData.mNumObjects));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQueryInfoInternal(strPath, objData, pGuestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
3ff8aa7d3c74cfbe8da5f77b8ea6c748cc79213avboxsync /** @todo Merge this with IGuestFile::queryInfo(). */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync /* Construct arguments. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync guestRc = procTool.TerminatedOk(NULL /* Exit code */);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.GetCurrentBlock(OUTPUT_HANDLE_ID_STDOUT, curBlock);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /** @todo Check for more / validate blocks! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return RT_SUCCESS(guestRc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncconst GuestCredentials& GuestSession::getCredentials(void)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncconst GuestEnvironment& GuestSession::getEnvironment(void)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::processRemoveFromList(GuestProcess *pProcess)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFunc(("Closing process (PID=%RU32) ...\n", uPID));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFunc(("Removing process (Session: %RU32) with process ID=%RU32, guest PID=%RU32 (now total %ld processes, %ld objects)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mId, pCurProc->getProcessID(), uPID, mData.mProcesses.size() - 1, mData.mNumObjects - 1));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Creates but does *not* start the process yet. See GuestProcess::startProcess() or
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * GuestProcess::startProcessAsync() for that.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @return IPRT status code.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param procInfo
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param pProcess
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncint GuestSession::processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync ProcessArguments::const_iterator it = procInfo.mArguments.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Validate flags. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_NoProfile)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Adjust timeout. If set to 0, we define
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * an infinite timeout. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /** @tood Implement process priority + affinity. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* Create a new (host-based) process ID and assign it. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /* Is the context ID already used? */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if (!processExists(uNewProcessID, NULL /* pProgress */))
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* Callback with context ID was not found. This means
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * we can use this context ID for our new callback we want
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * to add below. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync break; /* Don't try too hard. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the process object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync rc = pProcess->init(mData.mParent->getConsole() /* Console */, this /* Session */,
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Add the created process to our map. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %ld processes, %ld objects)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mId, uNewProcessID, mData.mProcesses.size(), mData.mNumObjects));
ccbdc11833996cb9f3be7868f1ebaefcacafb94dvboxsyncinline bool GuestSession::processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return true;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return false;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncinline int GuestSession::processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /* pProcess is optional. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync SessionProcesses::iterator itProcs = mData.mProcesses.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync for (; itProcs != mData.mProcesses.end(); itProcs++)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ComObjPtr<GuestProcess> pCurProc = itProcs->second;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSession::startTaskAsync(const Utf8Str &strTaskDesc,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowThisFunc(("strTaskDesc=%s, pTask=%p\n", strTaskDesc.c_str(), pTask));
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the progress object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync hr = pProgress->init(static_cast<IGuestSession*>(this),
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Initialize our worker task. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Don't destruct on success. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * Queries/collects information prior to establishing a guest session.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * This is necessary to know which guest control protocol version to use,
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * among other things (later).
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * @return IPRT status code.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Since the new functions were not implemented yet, force Main to use protocol ver 1. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * Try querying the guest control protocol version running on the guest.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * This is done using the Guest Additions version
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync uint32_t uVerAdditions = pGuest->getAdditionsVersion();
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync mData.mProtocolVersion = ( VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions) >= 4
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync && VBOX_FULL_VERSION_GET_MINOR(uVerAdditions) >= 2) /** @todo What's about v5.0 ? */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Build revision is ignored. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Tell the user but don't bitch too often. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync static short s_gctrlLegacyWarning = 0;
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync if (s_gctrlLegacyWarning++ < 3) /** @todo Find a bit nicer text. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"),
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions), VBOX_FULL_VERSION_GET_MINOR(uVerAdditions), mData.mProtocolVersion));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public methods
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync /* Remove ourselves from the session list. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * Release autocaller before calling uninit.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return setError(E_INVALIDARG, tr("No source specified"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return setError(E_INVALIDARG, tr("No destination specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
c99b597540585068d22dde4c9f74730305f24097vboxsync SessionTaskCopyFrom *pTask = new SessionTaskCopyFrom(this /* GuestSession */,
c99b597540585068d22dde4c9f74730305f24097vboxsync int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest),
c99b597540585068d22dde4c9f74730305f24097vboxsync /* Return progress to the caller. */
c99b597540585068d22dde4c9f74730305f24097vboxsync tr("Starting task for copying file \"%ls\" from guest to \"%ls\" on the host failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return setError(E_INVALIDARG, tr("No source specified"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return setError(E_INVALIDARG, tr("No destination specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
c99b597540585068d22dde4c9f74730305f24097vboxsync SessionTaskCopyTo *pTask = new SessionTaskCopyTo(this /* GuestSession */,
c99b597540585068d22dde4c9f74730305f24097vboxsync int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest),
c99b597540585068d22dde4c9f74730305f24097vboxsync /* Return progress to the caller. */
c99b597540585068d22dde4c9f74730305f24097vboxsync tr("Starting task for copying file \"%ls\" from host to \"%ls\" on the guest failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncSTDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode,
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return setError(E_INVALIDARG, tr("No directory to create specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync com::SafeArray<DirectoryCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), fFlags);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync ComObjPtr <GuestDirectory> pDirectory; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = directoryCreateInternal(Utf8Str(aPath), (uint32_t)aMode, fFlags, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Could not create directory"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
3641904508e6a0671c21a083a2ed03ebad8d976cvboxsyncSTDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, BSTR *aDirectory)
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync if (RT_UNLIKELY((aTemplate) == NULL || *(aTemplate) == '\0'))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return setError(E_INVALIDARG, tr("No template specified"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return setError(E_INVALIDARG, tr("No directory name specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = objectCreateTempInternal(Utf8Str(aTemplate),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Temporary directory creation \"%s\" with template \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(), Utf8Str(aTemplate).c_str(), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return setError(E_INVALIDARG, tr("No directory to check existence for specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory existence \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsyncSTDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return setError(E_INVALIDARG, tr("No directory to open specified"));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if (RT_UNLIKELY((aFilter) != NULL && *(aFilter) != '\0'))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return setError(E_INVALIDARG, tr("Directory filters are not implemented yet"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync com::SafeArray<DirectoryOpenFlag_T> flags(ComSafeArrayInArg(aFlags));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return setError(E_INVALIDARG, tr("Open flags (%#x) not implemented yet"), fFlags);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync int rc = directoryOpenInternal(Utf8Str(aPath), Utf8Str(aFilter), fFlags, pDirectory);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Return directory object to the caller. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed; invalid parameters given",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return setError(E_INVALIDARG, tr("No directory to query information for specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Element \"%s\" exists but is not a directory",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory information for \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP 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 */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncSTDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
92e624e40b06b4dc6d0a8222e1de33bd3e879a63vboxsyncSTDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, IGuestFile **aFile)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return setError(E_INVALIDARG, tr("No file to check existence for specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information for \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsyncSTDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync return setError(E_INVALIDARG, tr("No file to remove specified"));
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileRemoveInternal(Utf8Str(aPath), &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Removing file \"%s\" failed: %Rrc"),
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("No file to open specified"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (RT_UNLIKELY((aOpenMode) == NULL || *(aOpenMode) == '\0'))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("No open mode specified"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (RT_UNLIKELY((aDisposition) == NULL || *(aDisposition) == '\0'))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("No disposition mode specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate open mode. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate disposition mode. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate creation mode. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileOpenInternal(Utf8Str(aPath), Utf8Str(aOpenMode), Utf8Str(aDisposition),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Return directory object to the caller. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
c4d2656b949ac8efc3c83eb540ec25a9c889b9d6vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening file \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return setError(E_INVALIDARG, tr("No file to query information for specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Element exists but is not a file"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information failed: %Rrc"), vrc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync return setError(E_INVALIDARG, tr("No file to query size for specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQuerySizeInternal(Utf8Str(aPath), &llSize, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), vrc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return setError(E_INVALIDARG, tr("No command to execute specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync procInfo.mArguments.push_back(Utf8Str(arguments[i]));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * Create the process environment:
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * - Apply the session environment in a first step, and
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * - Apply environment variables specified by this call to
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * have the chance of overwriting/deleting session entries.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync rc = procInfo.mEnvironment.Set(Utf8Str(environment[i]));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mAffinity[i] = affinity[i]; /** @todo Really necessary? Later. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Return guest session to the caller. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of guest objects per session (%ld) reached"),
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /** @todo Add more errors here. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest process, rc=%Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncSTDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPID);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /* This will set (*aProcess) to NULL if pProgress is NULL. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", *aProcess, hr));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP 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 */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */