GuestSessionImpl.cpp revision dea3e7faa80f4aab41e08945b9308fd2e3ffe7fc
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * VirtualBox Main - Guest session handling.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Copyright (C) 2012-2013 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*******************************************************************************/
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Base class representing an internal
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * asynchronous session task.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync virtual ~GuestSessionTaskInternal(void) { }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const ComObjPtr<GuestSession> &Session(void) const { return mSession; }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Class for asynchronously opening a guest session.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncclass GuestSessionTaskInternalOpen : public GuestSessionTaskInternal
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync GuestSessionTaskInternalOpen(GuestSession *pSession)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Internal listener class to serve events in an
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * active manner, e.g. without polling delays.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc2 = mSession->signalWaitEvent(aType, aEvent);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("Signalling events of type=%RU32, session=%p resulted in rc=%Rrc\n",
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertMsgFailed(("Unhandled event %RU32\n", aType));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsynctypedef ListenerImpl<GuestSessionListener, GuestSession*> GuestSessionListenerImpl;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// constructor / destructor
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// public initializer/uninitializer for internal purposes only
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Initializes a guest session but does *not* open in on the guest side
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * yet. This needs to be done via the openSession() / openSessionAsync calls.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @return IPRT status code.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ** @todo Docs!
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncint GuestSession::init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("pGuest=%p, ssInfo=%p, guestCreds=%p\n",
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Copy over startup info. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo Use an overloaded copy operator. Later. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo Use an overloaded copy operator. Later. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mCredentials.mPassword = guestCreds.mPassword;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestSessionListener *pListener = new GuestSessionListener();
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Confirm a successful initialization when it's the case. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("mName=%s, mID=%RU32, mIsInternal=%RTbool, rc=%Rrc\n",
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal, rc));
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Uninitializes the instance.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Called from FinalRelease().
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Closing directories (%zu total)\n",
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Closing processes (%zu total)\n",
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync ("mNumObjects=%RU32 when it should be 0\n", mData.mNumObjects));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
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();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Status)(GuestSessionStatus_T *aStatus)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync 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 */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncSTDMETHODIMP GuestSession::COMGETTER(ProtocolVersion)(ULONG *aVersion)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
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));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowFunc(("mProcesses=%zu\n", collection.size()));
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));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowFunc(("mDirectories=%zu\n", collection.size()));
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 */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncSTDMETHODIMP GuestSession::COMGETTER(EventSource)(IEventSource ** aEventSource)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync // no need to lock - lifetime constant
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync// private methods
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync///////////////////////////////////////////////////////////////////////////////
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowThisFunc(("uFlags=%x, uTimeoutMS=%RU32\n", uFlags, uTimeoutMS));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Guest Additions < 4.3 don't support closing dedicated
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync guest sessions, skip. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("Installed Guest Additions don't support closing dedicated sessions, skipping\n"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo uFlags validation. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Session ID=%RU32 not started (anymore), status now is: %RU32\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync LogFlowThisFunc(("Sending closing request to guest session ID=%RU32, uFlags=%x\n",
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Drop the write lock before waiting. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = waitForStatusChange(pEvent, GuestSessionWaitForFlag_Terminate, uTimeoutMS,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Construct arguments. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync vrc = GuestProcessTool::i_run(this, procInfo, pGuestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncinline bool GuestSession::directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionDirectories::const_iterator it = mData.mDirectories.find(uDirID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return false;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::directoryRemoveFromList(GuestDirectory *pDirectory)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync SessionDirectories::iterator itDirs = mData.mDirectories.begin();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /* Make sure to consume the pointer before the one of the
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * iterator gets released. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = itDirs->second->COMGETTER(DirectoryName)(strName.asOutParam());
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %zu processes, %RU32 objects)\n",
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Utf8Str(strName).c_str(), mData.mSession.mID, mData.mDirectories.size() - 1, mData.mNumObjects - 1));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryRemoveInternal(const Utf8Str &strPath, uint32_t uFlags,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertReturn(!(uFlags & ~DIRREMOVE_FLAG_VALID_MASK), VERR_INVALID_PARAMETER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s, uFlags=0x%x\n", strPath.c_str(), uFlags));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Prepare HGCM call. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release(); /* Drop write lock before sending. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath,
81dfa298981df637a707b142ebd03cb7d3385097vboxsync LogFlowThisFunc(("strTemplate=%s, strPath=%s, fDirectory=%RTbool\n",
81dfa298981df637a707b142ebd03cb7d3385097vboxsync strTemplate.c_str(), strPath.c_str(), fDirectory));
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (strPath.length()) /* Otherwise use /tmp or equivalent. */
81dfa298981df637a707b142ebd03cb7d3385097vboxsync /** @todo Use an internal HGCM command for this operation, since
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * we now can run in a user-dedicated session. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryOpenInternal(const GuestDirectoryOpenInfo &openInfo,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync openInfo.mPath.c_str(), openInfo.mFilter.c_str(), openInfo.mFlags));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Create a new (host-based) directory ID and assign it. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Is the directory ID already used? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!directoryExists(uNewDirID, NULL /* pDirectory */))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Callback with context ID was not found. This means
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * we can use this context ID for our new callback we want
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * to add below. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break; /* Don't try too hard. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the directory object. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = pDirectory->init(pConsole, this /* Parent */,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Since this is a synchronous guest call we have to
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * register the file object first, releasing the session's
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * lock and then proceed with the actual opening command
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * -- otherwise the file's opening callback would hang
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * because the session's lock still is in place.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Add the created directory to our map. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("Added new guest directory \"%s\" (Session: %RU32) (now total %zu dirs, %RU32 objects)\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync openInfo.mPath.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release(); /* Release lock before firing off event. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Fire off a VBoxEventType_OnGuestDirectoryRegistered event? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Nothing further to do here yet. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::dispatchToDirectory(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uDirID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<GuestDirectory> pDirectory(itDir->second);
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pDirectory->i_callbackDispatcher(pCtxCb, pSvcCb);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t uFileID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uObjectID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Since we don't know which type the object is, we need to through all
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * all objects. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Speed this up by adding an object type to the callback context! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionProcesses::const_iterator itProc = mData.mProcesses.find(uObjectID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionFiles::const_iterator itFile = mData.mFiles.find(uObjectID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionDirectories::const_iterator itDir = mData.mDirectories.find(uObjectID);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync LogFlowFunc(("pProcess=%p, cRefs=%RU32\n", &itProc->second, cRefs - 1));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Set protocol version so that pSvcCb can
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * be interpreted right. */
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pProcess->i_callbackDispatcher(pCtxCb, pSvcCb);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("sessionID=%RU32, CID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /** @todo Handle closing all guest objects. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case GUEST_SESSION_NOTIFY: /* Guest Additions >= 4.3.0. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Silently skip unknown callbacks. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncinline bool GuestSession::fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync SessionFiles::const_iterator it = mData.mFiles.find(uFileID);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return true;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return false;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::fileRemoveFromList(GuestFile *pFile)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync SessionFiles::iterator itFiles = mData.mFiles.begin();
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* Make sure to consume the pointer before the one of thfe
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * iterator gets released. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync HRESULT hr = pCurFile->COMGETTER(FileName)(strName.asOutParam());
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowThisFunc(("Removing guest file \"%s\" (Session: %RU32) (now total %zu files, %RU32 objects)\n",
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Utf8Str(strName).c_str(), mData.mSession.mID, mData.mFiles.size() - 1, mData.mNumObjects - 1));
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Release lock before firing off event. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync fireGuestFileRegisteredEvent(mEventSource, this, pCurFile,
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync false /* Unregistered */);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strPath); /* The file we want to remove. */
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync vrc = GuestProcessTool::i_run(this, procInfo, pGuestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::fileOpenInternal(const GuestFileOpenInfo &openInfo,
81096b0da0061583a511da27088643aa949a1ec9vboxsync LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, uOffset=%RU64\n",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mFileName.c_str(), openInfo.mOpenMode.c_str(), openInfo.mDisposition.c_str(),
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync /* Guest Additions < 4.3 don't support handling
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync guest files, skip. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync LogFlowThisFunc(("Installed Guest Additions don't support handling guest files, skipping\n"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Create a new (host-based) file ID and assign it. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Is the file ID already used? */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Callback with context ID was not found. This means
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * we can use this context ID for our new callback we want
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * to add below. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break; /* Don't try too hard. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the directory object. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = pFile->init(pConsole, this /* GuestSession */,
81096b0da0061583a511da27088643aa949a1ec9vboxsync * Since this is a synchronous guest call we have to
81096b0da0061583a511da27088643aa949a1ec9vboxsync * register the file object first, releasing the session's
81096b0da0061583a511da27088643aa949a1ec9vboxsync * lock and then proceed with the actual opening command
81096b0da0061583a511da27088643aa949a1ec9vboxsync * -- otherwise the file's opening callback would hang
81096b0da0061583a511da27088643aa949a1ec9vboxsync * because the session's lock still is in place.
81096b0da0061583a511da27088643aa949a1ec9vboxsync /* Add the created file to our vector. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %zu files, %RU32 objects)\n",
81096b0da0061583a511da27088643aa949a1ec9vboxsync openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
81096b0da0061583a511da27088643aa949a1ec9vboxsync alock.release(); /* Release lock before firing off event. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync fireGuestFileRegisteredEvent(mEventSource, this, pFile,
81096b0da0061583a511da27088643aa949a1ec9vboxsync true /* Registered */);
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pFile->i_openFile(30 * 1000 /* 30s timeout */, &guestRc);
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);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Construct arguments. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncconst GuestCredentials& GuestSession::getCredentials(void)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncconst GuestEnvironment& GuestSession::getEnvironment(void)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/* static */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncUtf8Str GuestSession::guestErrorToString(int guestRc)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("VMM device is not available (is the VM running?)"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The guest execution service is not available"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The specified user was not able to logon on guest"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The guest did not respond within time"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The session operation was canceled"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("Invalid user/password credentials"));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync strError += Utf8StrFmt(tr("Maximum number of concurrent guest processes has been reached"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_NOT_EQUAL: /** @todo Imprecise to the user; can mean anything and all. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("Unable to retrieve requested information"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The guest execution service is not ready (yet)"));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Checks if this session is ready state where it can handle
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * all session-bound actions (like guest processes, guest files).
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Only used by official API methods. Will set an external
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * error when not ready.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /** @todo Be a bit more informative. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return setError(E_UNEXPECTED, tr("Session is not in started state"));
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync * Called by IGuest right before this session gets removed from
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync * the public session list.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * Note: The event source stuff holds references to this object,
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * so make sure that this is cleaned up *before* calling uninit.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/** No locking! */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint GuestSession::onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* pCallback is optional. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* pSvcCb->mpaParms[0] always contains the context ID. */
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync int vrc = pSvcCbData->mpaParms[1].getUInt32(&dataCb.uType);
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync vrc = pSvcCbData->mpaParms[2].getUInt32(&dataCb.uResult);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("ID=%RU32, uType=%RU32, guestRc=%Rrc\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mSession.mID, dataCb.uType, dataCb.uResult));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync GuestSessionStatus_T sessionStatus = GuestSessionStatus_Undefined;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int guestRc = dataCb.uResult; /** @todo uint32_t vs. int. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_TimedOutAbnormally;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* Set the session status. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("ID=%RU32, guestRc=%Rrc\n", mData.mSession.mID, guestRc));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncint GuestSession::startSessionInternal(int *pGuestRc)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("mID=%RU32, mName=%s, uProtocolVersion=%RU32, openFlags=%x, openTimeoutMS=%RU32\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mSession.mID, mData.mSession.mName.c_str(), mData.mProtocolVersion,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mSession.mOpenFlags, mData.mSession.mOpenTimeoutMS));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Guest Additions < 4.3 don't support opening dedicated
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync guest sessions. Simply return success here. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("Installed Guest Additions don't support opening dedicated sessions, skipping\n"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo mData.mSession.uFlags validation. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Set current session status. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mData.mRC = VINF_SUCCESS; /* Clear previous error, if any. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setPointer((void*)mData.mCredentials.mUser.c_str(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setPointer((void*)mData.mCredentials.mPassword.c_str(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setPointer((void*)mData.mCredentials.mDomain.c_str(),
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Drop write lock before sending. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = sendCommand(HOST_SESSION_CREATE, i, paParms);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = waitForStatusChange(pEvent, GuestSessionWaitForFlag_Start,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Unable to start guest session - update its current state.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Since there is no (official API) way to recover a failed guest session
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * this also marks the end state. Internally just calling this
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * same function again will work though.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Asynchronously open the session on the guest by kicking off a
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * worker thread. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync std::auto_ptr<GuestSessionTaskInternalOpen> pTask(new GuestSessionTaskInternalOpen(this));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync vrc = RTThreadCreate(NULL, GuestSession::startSessionThread,
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync "gctlSesStart");
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* pTask is now owned by openSessionThread(), so release it. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/* static */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncDECLCALLBACK(int) GuestSession::startSessionThread(RTTHREAD Thread, void *pvUser)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync std::auto_ptr<GuestSessionTaskInternalOpen> pTask(static_cast<GuestSessionTaskInternalOpen*>(pvUser));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const ComObjPtr<GuestSession> pSession(pTask->Session());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync int vrc = pSession->startSessionInternal(NULL /* Guest rc, ignored */);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Nothing to do here anymore. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertReturn(!(uFlags & ~PATHRENAME_FLAG_VALID_MASK), VERR_INVALID_PARAMETER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strSource=%s, strDest=%s, uFlags=0x%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Prepare HGCM call. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release(); /* Drop write lock before sending. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::processRemoveFromList(GuestProcess *pProcess)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("Removing process (PID=%RU32) ...\n", uPID));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync SessionProcesses::iterator itProcs = mData.mProcesses.begin();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("pProcess=%p, cRefs=%RU32\n", pProcess, cRefs - 1));
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /* Make sure to consume the pointer before the one of the
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * iterator gets released. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("Removing process ID=%RU32 (Session: %RU32), guest PID=%RU32 (now total %zu processes, %RU32 objects)\n",
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync pProcess->getObjectID(), mData.mSession.mID, uPID, mData.mProcesses.size() - 1, mData.mNumObjects - 1));
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Release lock before firing off event. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProc,
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))
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync if ( (procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync && ( (procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync || (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? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!processExists(uNewProcessID, NULL /* pProcess */))
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. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync rc = pProcess->init(mParent->getConsole() /* Console */, this /* Session */,
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Add the created process to our map. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %zu processes, %RU32 objects)\n",
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync mData.mSession.mID, uNewProcessID, mData.mProcesses.size(), mData.mNumObjects));
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync alock.release(); /* Release lock before firing off event. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProcess,
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;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync ComObjPtr<Console> pConsole = mParent->getConsole();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Forward the information to the VMM device. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowThisFunc(("uFunction=%RU32, uParms=%RU32\n", uFunction, uParms));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int vrc = pVMMDev->hgcmHostCall(HGCMSERVICE_NAME, uFunction, uParms, paParms);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /** @todo What to do here? */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Not needed within testcases. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/* static */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncHRESULT GuestSession::setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return pInterface->setError(VBOX_E_IPRT_ERROR, GuestSession::guestErrorToString(guestRc).c_str());
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync/* Does not do locking; caller is responsible for that! */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint GuestSession::setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("oldStatus=%RU32, newStatus=%RU32, sessionRc=%Rrc\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertMsg(RT_FAILURE(sessionRc), ("Guest rc must be an error (%Rrc)\n", sessionRc));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* Do not allow overwriting an already set error. If this happens
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * this means we forgot some error checking/locking somewhere. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertMsg(RT_SUCCESS(mData.mRC), ("Guest rc already set (to %Rrc)\n", mData.mRC));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertMsg(RT_SUCCESS(sessionRc), ("Guest rc must not be an error (%Rrc)\n", sessionRc));
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync int rc2 = errorInfo->initEx(VBOX_E_IPRT_ERROR, sessionRc,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync fireGuestSessionStateChangedEvent(mEventSource, this,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint GuestSession::signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*LogFlowThisFunc(("enmWaitResult=%d, rc=%Rrc, mWaitCount=%RU32, mWaitEvent=%p\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync enmWaitResult, rc, mData.mWaitCount, mData.mWaitEvent));*/
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* Note: No write locking here -- already done in the caller. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*if (mData.mWaitEvent)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync vrc = mData.mWaitEvent->Signal(enmWaitResult, rc);*/
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.
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();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uint32_t uVBoxMajor = VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uint32_t uVBoxMinor = VBOX_FULL_VERSION_GET_MINOR(uVerAdditions);
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* Hardcode the to-used protocol version; nice for testing side effects. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* VBox 5.0 and up. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* VBox 4.3 and up. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Build revision is ignored. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("uVerAdditions=%RU32 (%RU32.%RU32), mProtocolVersion=%RU32\n",
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uVerAdditions, uVBoxMajor, uVBoxMinor, mData.mProtocolVersion));
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Tell the user but don't bitch too often. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync static short s_gctrlLegacyWarning = 0;
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync && 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"),
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncint GuestSession::waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*LogFlowThisFunc(("fWaitFlags=0x%x, uTimeoutMS=%RU32, mStatus=%RU32, mWaitCount=%RU32, mWaitEvent=%p, pGuestRc=%p\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync fWaitFlags, uTimeoutMS, mData.mStatus, mData.mWaitCount, mData.mWaitEvent, pGuestRc));*/
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Did some error occur before? Then skip waiting and return. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest session indicated an error\n", mData.mRC));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *pGuestRc = mData.mRC; /* Return last set error. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Guest Additions < 4.3 don't support session handling, skip. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync waitResult = GuestSessionWaitResult_WaitFlagNotSupported;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("Installed Guest Additions don't support waiting for dedicated sessions, skipping\n"));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (fWaitFlags & GuestSessionWaitForFlag_Terminate)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Handled above. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Do the waiting below. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertMsgFailed(("Unhandled session status %RU32\n", mData.mStatus));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync else if (fWaitFlags & GuestSessionWaitForFlag_Start)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Do the waiting below. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertMsgFailed(("Unhandled session status %RU32\n", mData.mStatus));
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("sessionStatus=%RU32, sessionRc=%Rrc, waitResult=%RU32\n",
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* No waiting needed? Return immediately using the last set error. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *pGuestRc = mData.mRC; /* Return last set error (if any). */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Release lock before waiting. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncint GuestSession::waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestSessionStatus_T *pSessionStatus, int *pGuestRc)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Assert(evtType == VBoxEventType_OnGuestSessionStateChanged);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComPtr<IGuestSessionStateChangedEvent> pChangedEvent = pIEvent;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HRESULT hr = pChangedEvent->COMGETTER(Error)(errorInfo.asOutParam());
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync hr = errorInfo->COMGETTER(ResultDetail)(&lGuestRc);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Status changed event for session ID=%RU32, new status is: %RU32 (%Rrc)\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync RT_SUCCESS((int)lGuestRc) ? VINF_SUCCESS : (int)lGuestRc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public methods
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync /* Close session on guest. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc = closeSession(0 /* Flags */, 30 * 1000 /* Timeout */,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* On failure don't return here, instead do all the cleanup
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * work first and then return an error. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync /* Remove ourselves from the session list. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (rc2 == VERR_NOT_FOUND) /* Not finding the session anymore isn't critical. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync return GuestSession::setErrorExternal(this, guestRc);
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);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /** @todo Handle VERR_NOT_EQUAL (meaning process exit code <> 0). */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync 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: 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: %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),
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_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);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_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);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr <GuestDirectory> pDirectory; int guestRc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc = directoryOpenInternal(openInfo, pDirectory, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Return directory object to the caller. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed; invalid parameters given",
18e3d4704ed7b57260b0d4e3ea12c224b3f81840vboxsync hr = GuestDirectory::i_setErrorExternal(this, guestRc);
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);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_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)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No directory to remove specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* No flags; only remove the directory when empty. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = directoryRemoveInternal(Utf8Str(aPath), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling removing guest directories not supported by installed Guest Additions"));
18e3d4704ed7b57260b0d4e3ea12c224b3f81840vboxsync hr = GuestDirectory::i_setErrorExternal(this, guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Removing guest directory \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No directory to remove recursively specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = pProgress->init(static_cast<IGuestSession *>(this),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Note: At the moment we don't supply progress information while
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * deleting a guest directory recursively. So just complete
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * the progress object right now. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Implement progress reporting on guest directory deletion! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Remove the directory + all its contents. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = directoryRemoveInternal(Utf8Str(aPath), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling removing guest directories recursively not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Recursively removing guest directory \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No source directory to rename specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No destination directory to rename the source to specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* No flags; only remove the directory when empty. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = pathRenameInternal(Utf8Str(aSource), Utf8Str(aDest), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling renaming guest directories not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Renaming guest directory failed: %Rrc"), guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Renaming guest directory \"%s\" failed: %Rrc"),
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);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_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);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Removing file \"%s\" failed: %Rrc"),
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
81096b0da0061583a511da27088643aa949a1ec9vboxsyncSTDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, IGuestFile **aFile)
81096b0da0061583a511da27088643aa949a1ec9vboxsync Bstr strSharingMode = ""; /* Sharing mode is ignored. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync return FileOpenEx(aPath, aOpenMode, aDisposition, strSharingMode.raw(), aCreationMode,
81096b0da0061583a511da27088643aa949a1ec9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
81096b0da0061583a511da27088643aa949a1ec9vboxsyncSTDMETHODIMP GuestSession::FileOpenEx(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, IN_BSTR aSharingMode,
81096b0da0061583a511da27088643aa949a1ec9vboxsync 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"));
81096b0da0061583a511da27088643aa949a1ec9vboxsync /* aSharingMode is optional. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate creation mode. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync int vrc = RTFileModeToFlagsEx(openInfo.mOpenMode.c_str(),
81096b0da0061583a511da27088643aa949a1ec9vboxsync return setError(E_INVALIDARG, tr("Invalid open mode / disposition / sharing mode specified"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Return directory object to the caller. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync tr("Handling guest files not supported by installed Guest Additions"));
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening guest 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);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_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);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_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))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No source file to rename specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No destination file to rename the source to specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* No flags; only remove the directory when empty. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = pathRenameInternal(Utf8Str(aSource), Utf8Str(aDest), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling renaming guest files not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Proper guestRc to text translation needed. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Renaming guest file \"%s\" failed: %Rrc"),
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),
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinityIgnored), 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));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Return guest session to the caller. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of concurrent guest processes 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 */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncSTDMETHODIMP GuestSession::WaitFor(ULONG aWaitFlags, ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Note: Do not hold any locks here while waiting!
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync int vrc = waitFor(aWaitFlags, aTimeoutMS, waitResult, &guestRc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync hr = GuestSession::setErrorExternal(this, guestRc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync const char *pszSessionName = mData.mSession.mName.c_str();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync tr("Waiting for guest session \"%s\" failed: %Rrc"),
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pszSessionName ? pszSessionName : tr("Unnamed"), vrc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncSTDMETHODIMP GuestSession::WaitForArray(ComSafeArrayIn(GuestSessionWaitForFlag_T, aFlags), ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Note: Do not hold any locks here while waiting!
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync com::SafeArray<GuestSessionWaitForFlag_T> flags(ComSafeArrayInArg(aFlags));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */