GuestSessionImpl.cpp revision ed9d3db07648c7e3a979105c15ad752ee9ea18de
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * VirtualBox Main - XXX.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Copyright (C) 2012 Oracle Corporation
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * available from http://www.virtualbox.org. This file is free software;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * General Public License (GPL) as published by the Free Software
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/*******************************************************************************
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync* Header Files *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync*******************************************************************************/
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync// constructor / destructor
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/////////////////////////////////////////////////////////////////////////////
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync// public initializer/uninitializer for internal purposes only
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/////////////////////////////////////////////////////////////////////////////
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint GuestSession::init(Guest *aGuest, ULONG aSessionID,
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Enclose the state transition NotReady->InInit->Ready. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync mData.mTimeout = 30 * 60 * 1000; /* Session timeout is 30 mins by default. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Confirm a successful initialization when it's the case. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Uninitializes the instance.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Called from FinalRelease().
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync// implementation of public getters/setters for attributes
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/////////////////////////////////////////////////////////////////////////////
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync LogFlowThisFunc(("%s cEnvVars=%RU32\n", mData.mName.c_str(), cEnvVars));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync environment.detachTo(ComSafeArrayOutArg(aEnvironment));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync collection.detachTo(ComSafeArrayOutArg(aProcesses));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync collection.detachTo(ComSafeArrayOutArg(aDirectories));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync SafeIfaceArray<IGuestFile> collection(mData.mFiles);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync// private methods
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/////////////////////////////////////////////////////////////////////////////
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint GuestSession::directoryClose(ComObjPtr<GuestDirectory> pDirectory)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint GuestSession::dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync = mData.mProcesses.find(VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = pProcess->callbackDispatcher(uContextID, uFunction, pvData, cbData);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint GuestSession::fileClose(ComObjPtr<GuestFile> pFile)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncconst GuestCredentials& GuestSession::getCredentials(void)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncconst GuestEnvironment& GuestSession::getEnvironment(void)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint GuestSession::processClose(ComObjPtr<GuestProcess> pProcess)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint GuestSession::processCreateExInteral(GuestProcessInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Validate flags. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync && !(procInfo.mFlags & ProcessCreateFlag_NoProfile))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Adjust timeout. If set to 0, we define
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * an infinite timeout. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /** @tood Implement process priority + affinity. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (mData.mProcesses.size() >= VBOX_GUESTCTRL_MAX_PROCESSES)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Create a new (host-based) process ID and assign it. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Is the context ID already used? */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (!processExists(uNewProcessID, NULL /* pProgress */))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Callback with context ID was not found. This means
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * we can use this context ID for our new callback we want
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * to add below. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync break; /* Don't try too hard. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Create the process object. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = pProcess->init(mData.mParent->getConsole() /* Console */, this /* Session */,
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* Add the created process to our map. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync catch (int rc2)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncinline bool GuestSession::processExists(ULONG uProcessID, ComObjPtr<GuestProcess> *pProcess)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return true;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return false;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncinline int GuestSession::processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /* pProcess is optional. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync SessionProcesses::iterator it = mData.mProcesses.begin();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync// implementation of public methods
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/////////////////////////////////////////////////////////////////////////////
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode, ULONG aFlags, IGuestDirectory **aProgress)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, IN_BSTR aFlags, IGuestDirectory **aDirectory)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return setError(E_INVALIDARG, tr("No value name specified"));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::EnvironmentSetArray(ComSafeArrayIn(IN_BSTR, aValues))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (!strEnv.isEmpty()) /* Silently skip empty entries. */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestFile **aFile)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync HRESULT hr = ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return setError(E_INVALIDARG, tr("No command to execute specified"));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync procInfo.mArguments.push_back(Utf8Str(arguments[i]));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Create the process environment:
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * - Apply the session environment in a first step, and
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * - Apply environment variables specified by this call to
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * have the chance of overwriting/deleting session entries.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync rc = mData.mEnvironment.Set(Utf8Str(environment[i]));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync procInfo.mAffinity[i] = affinity[i]; /** @todo Really necessary? Later. */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync /* Return guest session to the caller. */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of guest processes (%ld) reached"),
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync /** @todo Add more errors here. */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest process, rc=%Rrc"), rc);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPID);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync /* This will set (*aProcess) to NULL if pProgress is NULL. */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", *aProcess, hr));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::SetTimeout(ULONG aTimeoutMS)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return setError(E_INVALIDARG, tr("Invalid timeout value specified"));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync LogFlowThisFunc(("aTimeoutMS=%RU32\n", mData.mTimeout));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncSTDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */