GuestSessionImpl.cpp revision df3d97ef4590e6a4ca98e649e2a78bea3a9d28bb
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox Main - XXX.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2012 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync* Header Files *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync*******************************************************************************/
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// constructor / destructor
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync// session task classes
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync/////////////////////////////////////////////////////////////////////////////
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsyncGuestSessionTask::GuestSessionTask(GuestSession *pSession)
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if (mProgress.isNull()) /* Progress is optional. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync HRESULT hr = mProgress->SetCurrentOperationProgress(uPercent);
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if (mProgress.isNull()) /* Progress is optional. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync return VERR_COM_UNEXPECTED; /** @todo Find a better rc. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSessionTask::setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg)
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if (mProgress.isNull()) /* Progress is optional. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Utf8StrFmt(GuestSession::tr("Copy flags (%#x) not implemented yet"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Make use of exceptions (+ finally block) here! */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Does our source file exist? */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Source file \"%s\" does not exist or is not a file"),
388b6b190a5407548753b7fde12fa58134ec3563vboxsync RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Could not open source file \"%s\" for reading (%Rrc)"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Could not query file size of \"%s\": %Rrc"),
388b6b190a5407548753b7fde12fa58134ec3563vboxsync procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" to the guest to \"%s\" (%RU64 bytes)"),
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Set arguments.*/
388b6b190a5407548753b7fde12fa58134ec3563vboxsync procInfo.mArguments.push_back(Utf8StrFmt("--output=%s", mDest.c_str())); /** @todo Do we need path conversion? */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Startup process. */
386a7cc6c736c97bb8839df94eef779de7fbfdc1vboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Unable to start guest process: %Rrc"), rc));
388b6b190a5407548753b7fde12fa58134ec3563vboxsync if (cbFileSize) /* If we have nothing to write, take a shortcut. */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /** @todo Not very efficient, but works for now. */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync * Some other error occured? There might be a chance that RTFileRead
388b6b190a5407548753b7fde12fa58134ec3563vboxsync * could not resolve/map the native error code to an IPRT code, so just
388b6b190a5407548753b7fde12fa58134ec3563vboxsync * print a generic error.
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Could not read from file \"%s\" (%Rrc)"),
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Seeking file \"%s\" offset %RU64 failed: %Rrc"),
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Did we reach the end of the content we want to transfer (last chunk)? */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Did we reach the last block which is exactly _64K? */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* ... or does the user want to cancel? */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync || ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Writing to file \"%s\" (offset %RU64) failed: %Rrc"),
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync LogFlowThisFunc(("cbWritten=%RU32, cbToRead=%RU64, cbWrittenTotal=%RU64, cbFileSize=%RU64\n",
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync cbWritten, cbToRead - cbWritten, cbWrittenTotal + cbWritten, cbFileSize));
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Only subtract bytes reported written by the guest. */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Update total bytes written to the guest. */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* Did the user cancel the operation above? */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync /* Update the progress.
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync * Watch out for division by zero. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync ? rc = setProgress((ULONG)(cbWrittenTotal * 100 / cbFileSize))
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* End of file reached? */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync } /* for */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync * Even if we succeeded until here make sure to check whether we really transfered
388b6b190a5407548753b7fde12fa58134ec3563vboxsync * everything.
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
388b6b190a5407548753b7fde12fa58134ec3563vboxsync * to the destination -> access denied. */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
388b6b190a5407548753b7fde12fa58134ec3563vboxsync /* If we did not copy all let the user know. */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RU64 bytes transfered)"),
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync rc = pProcess->waitFor(ProcessWaitForFlag_Terminate,
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed: %Rrc"),
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed with wait result %ld"),
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %ld"),
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync } /* processCreateExInteral */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync } /* RTFileGetSize */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync } /* RTFileOpen */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync } /* RTFileExists */
388b6b190a5407548753b7fde12fa58134ec3563vboxsync catch (int rc2)
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsyncint SessionTaskCopyTo::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, mCopyFileFlags=%x\n",
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mCopyFileFlags));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyTo::taskThread, this,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync "gctlCpyTo");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync/* static */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint SessionTaskCopyTo::taskThread(RTTHREAD Thread, void *pvUser)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync std::auto_ptr<SessionTaskCopyTo> task(static_cast<SessionTaskCopyTo*>(pvUser));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsyncSessionTaskCopyFrom::SessionTaskCopyFrom(GuestSession *pSession,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Make use of exceptions (+ finally block) here! */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Note: There will be races between querying file size + reading the guest file's
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * content because we currently *do not* lock down the guest file when doing the
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * actual operations.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync ** @todo Implement guest file locking!
5366e994777f9d9391cf809dc77610f57270d75dvboxsync rc = pSession->fileQueryInfoInternal(Utf8Str(mSource), objData);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Querying guest file information for \"%s\" failed: %Rrc"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync else if (objData.mType != FsObjType_File) /* Only single files are supported at the moment. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Guest file \"%s\" is not a file"), mSource.c_str()));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE); /** @todo Use the correct open modes! */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Error opening destination file \"%s\": %Rrc"),
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" from guest to the host to \"%s\" (%RI64 bytes)"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync mSource.c_str(), mDest.c_str(), objData.mObjectSize);
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync procInfo.mFlags = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Set arguments.*/
5366e994777f9d9391cf809dc77610f57270d75dvboxsync procInfo.mArguments.push_back(mSource); /* Which file to output? */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Startup process. */
386a7cc6c736c97bb8839df94eef779de7fbfdc1vboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Unable to start guest process: %Rrc"), rc));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Reading from file \"%s\" (offset %RU64) failed: %Rrc"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync rc = RTFileWrite(fileDest, byBuf, cbRead, NULL /* No partial writes */);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Error writing to file \"%s\" (%RU64 bytes left): %Rrc"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Only subtract bytes reported written by the guest. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Update total bytes written to the guest. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(cbWrittenTotal <= (uint64_t)objData.mObjectSize);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Did the user cancel the operation above? */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync rc = setProgress((ULONG)(cbWrittenTotal / ((uint64_t)objData.mObjectSize / 100.0)));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* End of file reached? */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync } /* for */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Even if we succeeded until here make sure to check whether we really transfered
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * everything.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * to the destination -> access denied. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync else if (cbWrittenTotal < (uint64_t)objData.mObjectSize)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* If we did not copy all let the user know. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RU64 bytes transfered)"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync mSource.c_str(), cbWrittenTotal, objData.mObjectSize));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %d"),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync else /* Yay, success! */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync catch (int rc2)
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsyncint SessionTaskCopyFrom::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n",
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mFlags));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyFrom::taskThread, this,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync "gctlCpyFrom");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync/* static */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint SessionTaskCopyFrom::taskThread(RTTHREAD Thread, void *pvUser)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync std::auto_ptr<SessionTaskCopyFrom> task(static_cast<SessionTaskCopyFrom*>(pvUser));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// public initializer/uninitializer for internal purposes only
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncint GuestSession::init(Guest *aGuest, ULONG aSessionID,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync mData.mTimeout = 30 * 60 * 1000; /* Session timeout is 30 mins by default. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Confirm a successful initialization when it's the case. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Uninitializes the instance.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Called from FinalRelease().
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public getters/setters for attributes
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
7e8ef90d3160234df0f254131b87af4243d79476vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Timeout)(ULONG aTimeout)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFunc(("%s cEnvVars=%RU32\n", mData.mName.c_str(), cEnvVars));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync environment.detachTo(ComSafeArrayOutArg(aEnvironment));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Environment)(ComSafeArrayIn(IN_BSTR, aValues))
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (!strEnv.isEmpty()) /* Silently skip empty entries. */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aProcesses));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aDirectories));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestFile> collection(mData.mFiles);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync// private methods
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync/////////////////////////////////////////////////////////////////////////////
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncint GuestSession::directoryClose(ComObjPtr<GuestDirectory> pDirectory)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncint GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
5366e994777f9d9391cf809dc77610f57270d75dvboxsync procInfo.mName = Utf8StrFmt(tr("Creating directory \"%s\"", strPath.c_str()));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* Construct arguments. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync rc = pProcess->waitFor(ProcessWaitForFlag_Terminate, 30 * 1000 /* Timeout */, waitRes);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync HRESULT hr = pProcess->COMGETTER(Status)(&procStatus);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (procStatus == ProcessStatus_TerminatedNormally)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync rc = VERR_BROKEN_PIPE; /** @todo Find a better rc. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* Create the directory object. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* Note: There will be a race between creating and getting/initing the directory
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync object here. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* Add the created directory to our vector. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlowFunc(("Added new directory \"%s\" (Session: %RU32)\n",
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync catch (int rc2)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsyncint GuestSession::directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter,
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync /* Create the directory object. */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync /* Add the created directory to our vector. */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlowFunc(("Added new directory \"%s\" (Session: %RU32)\n",
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync catch (int rc2)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncint GuestSession::dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync rc = pProcess->callbackDispatcher(uContextID, uFunction, pvData, cbData);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncint GuestSession::fileClose(ComObjPtr<GuestFile> pFile)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncint GuestSession::fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
5366e994777f9d9391cf809dc77610f57270d75dvboxsync uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, iOffset=%RI64\n",
5366e994777f9d9391cf809dc77610f57270d75dvboxsync strPath.c_str(), strOpenMode.c_str(), strDisposition.c_str(), uCreationMode, iOffset));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Create the directory object. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Note: There will be a race between creating and getting/initing the directory
5366e994777f9d9391cf809dc77610f57270d75dvboxsync object here. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync strPath, strOpenMode, strDisposition, uCreationMode, iOffset);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Add the created directory to our vector. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlowFunc(("Added new file \"%s\" (Session: %RU32\n",
5366e994777f9d9391cf809dc77610f57270d75dvboxsync catch (int rc2)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync/* Note: Will work on directories and others, too. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncint GuestSession::fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync procInfo.mName = Utf8StrFmt(tr("Querying info for \"%s\""), strPath.c_str());
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync procInfo.mFlags = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync /* Construct arguments. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync int rc = processCreateExInteral(procInfo, pProcess);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync /** @todo Merge with GuestDirectory::read. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlowThisFunc(("rc=%Rrc, cbRead=%RU64, cbStreamOut=%RU32\n",
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync AssertMsgFailed(("Parsing stream block failed: %Rrc\n", rc));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncint GuestSession::fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncconst GuestCredentials& GuestSession::getCredentials(void)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncconst GuestEnvironment& GuestSession::getEnvironment(void)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncint GuestSession::processClose(ComObjPtr<GuestProcess> pProcess)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync LogFlowFunc(("Removing process (Session: %RU32) with process ID=%RU32, guest PID=%RU32 (now total %ld processes)\n",
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync mData.mId, itProcs->second->getProcessID(), itProcs->second->getPID(), mData.mProcesses.size() - 1));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Creates but does *not* start the process yet. See GuestProcess::startProcess() or
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * GuestProcess::startProcessAsync() for that.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @return IPRT status code.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param procInfo
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param pProcess
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncint GuestSession::processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync ProcessArguments::const_iterator it = procInfo.mArguments.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Validate flags. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_NoProfile)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Adjust timeout. If set to 0, we define
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * an infinite timeout. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /** @tood Implement process priority + affinity. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (mData.mProcesses.size() >= VBOX_GUESTCTRL_MAX_PROCESSES)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* Create a new (host-based) process ID and assign it. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /* Is the context ID already used? */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if (!processExists(uNewProcessID, NULL /* pProgress */))
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* Callback with context ID was not found. This means
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * we can use this context ID for our new callback we want
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * to add below. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync break; /* Don't try too hard. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Create the process object. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync rc = pProcess->init(mData.mParent->getConsole() /* Console */, this /* Session */,
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Add the created process to our map. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %ld processes)\n",
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync mData.mId, uNewProcessID, mData.mProcesses.size()));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync catch (int rc2)
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. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync SessionProcesses::iterator it = mData.mProcesses.begin();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSession::startTaskAsync(const Utf8Str &strTaskDesc,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowThisFunc(("strTaskDesc=%s, pTask=%p\n", strTaskDesc.c_str(), pTask));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Create the progress object. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync hr = pProgress->init(static_cast<IGuestSession*>(this),
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Initialize our worker task. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Don't destruct on success. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync catch (int rc2)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * Queries/collects information prior to establishing a guest session.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * This is necessary to know which guest control protocol version to use,
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * among other things (later).
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * @return IPRT status code.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Since the new functions were not implemented yet, force Main to use protocol ver 1. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * Try querying the guest control protocol version running on the guest.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * This is done using the Guest Additions version
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync uint32_t uVerAdditions = pGuest->getAdditionsVersion();
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync mData.mProtocolVersion = ( VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions) >= 4
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync && VBOX_FULL_VERSION_GET_MINOR(uVerAdditions) >= 2) /** @todo What's about v5.0 ? */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Build revision is ignored. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Tell the user but don't bitch too often. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync static short s_gctrlLegacyWarning = 0;
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync if (s_gctrlLegacyWarning++ < 3) /** @todo Find a bit nicer text. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"),
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions), VBOX_FULL_VERSION_GET_MINOR(uVerAdditions), mData.mProtocolVersion));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public methods
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
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));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync SessionTaskCopyFrom *pTask = new SessionTaskCopyFrom(this /* GuestSession */,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest),
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Return progress to the caller. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync 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));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync SessionTaskCopyTo *pTask = new SessionTaskCopyTo(this /* GuestSession */,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest),
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /* Return progress to the caller. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync 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 ComSafeArrayIn(DirectoryCreateFlag_T, aFlags), IGuestDirectory **aDirectory)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return setError(E_INVALIDARG, tr("No directory to create specified"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* aDirectory is optional. */
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);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync int rc = directoryCreateInternal(Utf8Str(aPath), (uint32_t)aMode, fFlags, pDirectory);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* Return directory object to the caller. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Unable to close directory object, rc=%Rrc"), rc);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Could not create directory"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory)
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync if (RT_UNLIKELY((aTemplate) == NULL || *(aTemplate) == '\0'))
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync return setError(E_INVALIDARG, tr("No file to remove specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync try /* Can this be done without exceptions? */
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync procInfo.mName = Utf8StrFmt(tr("Creating temporary directory from template \"%s\"",
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync /* Construct arguments. */
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync procInfo.mArguments.push_back(Bstr(aTemplate)); /* The template we want to use. */
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync catch (...)
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n",
df3d97ef4590e6a4ca98e649e2a78bea3a9d28bbvboxsync return setError(E_FAIL, tr("Error while starting temporary directory creation tool on guest: %Rrc"), rc);
df3d97ef4590e6a4ca98e649e2a78bea3a9d28bbvboxsync return setError(E_FAIL, tr("Error while running temporary directory creation tool: %Rrc"), rc);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync return setError(E_FAIL, tr("No return code after creating temporary directory"));
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync if (RT_FAILURE(streamBlock.GetInt64Ex("rc", &i64rc)))
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync return setError(E_FAIL, tr("No return code after creating temporary directory"));
df3d97ef4590e6a4ca98e649e2a78bea3a9d28bbvboxsync return setError(VBOX_E_IPRT_ERROR, tr("File deletion failed: %Rrc"), rc);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync return setError(E_FAIL, tr("Error while getting return code from creating temporary directory: %Rrc"), 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();
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync int rc = fileQueryInfoInternal(Utf8Str(aPath), objData);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync /** @todo Add more errors here! */
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory existence failed: %Rrc"), rc);
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'))
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return setError(E_INVALIDARG, tr("Directory filters not implemented yet"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync com::SafeArray<DirectoryOpenFlag_T> flags(ComSafeArrayInArg(aFlags));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return setError(E_INVALIDARG, tr("Open flags (%#x) not implemented yet"), fFlags);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync int rc = directoryOpenInternal(Utf8Str(aPath), Utf8Str(aFilter), fFlags, pDirectory);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync /* Return directory object to the caller. */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Unable to close directory object, rc=%Rrc"), rc);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory failed: Invalid parameters given"));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory failed: Unexpectedly aborted"));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncSTDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, 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();
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync int rc = fileQueryInfoInternal(Utf8Str(aPath), objData);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync /** @todo Add more errors here! */
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file existence failed: %Rrc"), rc);
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();
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync try /* Can this be done without exceptions? */
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync procInfo.mName = Utf8StrFmt(tr("Removing file \"%s\"",
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync /* Construct arguments. */
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync procInfo.mArguments.push_back(Bstr(aPath)); /* The directory we want to create. */
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync catch (...)
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n",
df3d97ef4590e6a4ca98e649e2a78bea3a9d28bbvboxsync return setError(E_FAIL, tr("Error while starting delete tool on guest: %Rrc"), rc);
df3d97ef4590e6a4ca98e649e2a78bea3a9d28bbvboxsync return setError(E_FAIL, tr("Error while running delete tool on guest: %Rrc"), rc);
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync return setError(E_FAIL, tr("No return code after deleting file"));
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (RT_FAILURE(streamBlock.GetInt64Ex("rc", &i64rc)))
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync return setError(E_FAIL, tr("No return code after deleting file"));
df3d97ef4590e6a4ca98e649e2a78bea3a9d28bbvboxsync return setError(VBOX_E_IPRT_ERROR, tr("File deletion failed: %Rrc"), rc);
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync return setError(E_FAIL, tr("Error while getting return code from deleting file: %Rrc"), rc);
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("No file to open specified"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (RT_UNLIKELY((aOpenMode) == NULL || *(aOpenMode) == '\0'))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("No open mode specified"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (RT_UNLIKELY((aDisposition) == NULL || *(aDisposition) == '\0'))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("No disposition mode specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate open mode. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate disposition mode. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate creation mode. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync int rc = fileOpenInternal(Utf8Str(aPath), Utf8Str(aOpenMode), Utf8Str(aDisposition),
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Return directory object to the caller. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Add more error info! */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
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();
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync int rc = fileQuerySizeInternal(Utf8Str(aPath), &llSize);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync /** @todo Add more errors here! */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync HRESULT hr = ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinity), aProcess);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return setError(E_INVALIDARG, tr("No command to execute specified"));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync procInfo.mArguments.push_back(Utf8Str(arguments[i]));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * Create the process environment:
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * - Apply the session environment in a first step, and
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * - Apply environment variables specified by this call to
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * have the chance of overwriting/deleting session entries.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync rc = procInfo.mEnvironment.Set(Utf8Str(environment[i]));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mAffinity[i] = affinity[i]; /** @todo Really necessary? Later. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Return guest session to the caller. */
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of 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 */