GuestSessionImpl.cpp revision dea3e7faa80f4aab41e08945b9308fd2e3ffe7fc
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/* $Id$ */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/** @file
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * VirtualBox Main - Guest session handling.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Copyright (C) 2012-2013 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
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
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync* Header Files *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync*******************************************************************************/
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#include "GuestImpl.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "GuestSessionImpl.h"
7b9f0c34e9ea328981c99e97054bdf8684d9d620vboxsync#include "GuestCtrlImplPrivate.h"
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync#include "VirtualBoxErrorInfoImpl.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "Global.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "AutoCaller.h"
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#include "ProgressImpl.h"
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include "VBoxEvents.h"
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#include "VMMDev.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync#include <memory> /* For auto_ptr. */
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include <iprt/cpp/utils.h> /* For unconst(). */
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync#include <iprt/env.h>
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#include <iprt/file.h> /* For CopyTo/From. */
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include <VBox/com/array.h>
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include <VBox/com/listeners.h>
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync#include <VBox/version.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#ifdef LOG_GROUP
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync #undef LOG_GROUP
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#endif
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/log.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/**
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Base class representing an internal
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * asynchronous session task.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncclass GuestSessionTaskInternal
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncpublic:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync GuestSessionTaskInternal(GuestSession *pSession)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync : mSession(pSession),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mRC(VINF_SUCCESS) { }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync virtual ~GuestSessionTaskInternal(void) { }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int rc(void) const { return mRC; }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync bool isOk(void) const { return RT_SUCCESS(mRC); }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const ComObjPtr<GuestSession> &Session(void) const { return mSession; }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncprotected:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const ComObjPtr<GuestSession> mSession;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int mRC;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync};
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/**
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Class for asynchronously opening a guest session.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncclass GuestSessionTaskInternalOpen : public GuestSessionTaskInternal
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncpublic:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync GuestSessionTaskInternalOpen(GuestSession *pSession)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync : GuestSessionTaskInternal(pSession) { }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync};
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/**
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Internal listener class to serve events in an
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * active manner, e.g. without polling delays.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncclass GuestSessionListener
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncpublic:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestSessionListener(void)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HRESULT init(GuestSession *pSession)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
e38a1f5933935fe8db152ea06dac5aa1be27d870vboxsync AssertPtrReturn(pSession, E_POINTER);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync mSession = pSession;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return S_OK;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync void uninit(void)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
e38a1f5933935fe8db152ea06dac5aa1be27d870vboxsync mSession = NULL;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync switch (aType)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case VBoxEventType_OnGuestSessionStateChanged:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
e38a1f5933935fe8db152ea06dac5aa1be27d870vboxsync AssertPtrReturn(mSession, E_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc2 = mSession->signalWaitEvent(aType, aEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#ifdef DEBUG_andy
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("Signalling events of type=%RU32, session=%p resulted in rc=%Rrc\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync aType, mSession, rc2));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#endif
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync default:
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertMsgFailed(("Unhandled event %RU32\n", aType));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return S_OK;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncprivate:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
e38a1f5933935fe8db152ea06dac5aa1be27d870vboxsync GuestSession *mSession;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync};
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsynctypedef ListenerImpl<GuestSessionListener, GuestSession*> GuestSessionListenerImpl;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
581f0625e43a928987623d7cf59e1b1ab61ca6c8vboxsyncVBOX_LISTENER_DECLARE(GuestSessionListenerImpl)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// constructor / destructor
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncDEFINE_EMPTY_CTOR_DTOR(GuestSession)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncHRESULT GuestSession::FinalConstruct(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
3f5dd727ecbcf3e99217c70f04bc2340beb9072cvboxsync LogFlowThisFuncEnter();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return BaseFinalConstruct();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncvoid GuestSession::FinalRelease(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowThisFuncEnter();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uninit();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync BaseFinalRelease();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// public initializer/uninitializer for internal purposes only
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
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 *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @return IPRT status code.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ** @todo Docs!
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncint GuestSession::init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const GuestCredentials &guestCreds)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("pGuest=%p, ssInfo=%p, guestCreds=%p\n",
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pGuest, &ssInfo, &guestCreds));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoInitSpan autoInitSpan(this);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync autoInitSpan.setSucceeded();
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync return VINF_SUCCESS;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#else
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mParent = pGuest;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Copy over startup info. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo Use an overloaded copy operator. Later. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mID = ssInfo.mID;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mIsInternal = ssInfo.mIsInternal;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mName = ssInfo.mName;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mOpenFlags = ssInfo.mOpenFlags;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo Use an overloaded copy operator. Later. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mCredentials.mUser = guestCreds.mUser;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mCredentials.mPassword = guestCreds.mPassword;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mCredentials.mDomain = guestCreds.mDomain;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mData.mRC = VINF_SUCCESS;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mStatus = GuestSessionStatus_Undefined;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mNumObjects = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HRESULT hr;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int rc = queryInfo();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (RT_SUCCESS(rc))
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync hr = unconst(mEventSource).createObject();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (FAILED(hr))
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync rc = VERR_NO_MEMORY;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync else
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
c2590a722c15520a45551ed7dc02d4831fb1a48evboxsync hr = mEventSource->init();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (FAILED(hr))
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync rc = VERR_COM_UNEXPECTED;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_SUCCESS(rc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync try
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestSessionListener *pListener = new GuestSessionListener();
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComObjPtr<GuestSessionListenerImpl> thisListener;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync hr = thisListener.createObject();
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (SUCCEEDED(hr))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync hr = thisListener->init(pListener, this);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (SUCCEEDED(hr))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync com::SafeArray <VBoxEventType_T> eventTypes;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync hr = mEventSource->RegisterListener(thisListener,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComSafeArrayAsInParam(eventTypes),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync TRUE /* Active listener */);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (SUCCEEDED(hr))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync mLocalListener = thisListener;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = RTCritSectInit(&mWaitEventCritSect);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertRC(rc);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = VERR_COM_UNEXPECTED;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = VERR_COM_UNEXPECTED;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync catch(std::bad_alloc &)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = VERR_NO_MEMORY;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(rc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Confirm a successful initialization when it's the case. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync autoInitSpan.setSucceeded();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync else
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync autoInitSpan.setFailed();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("mName=%s, mID=%RU32, mIsInternal=%RTbool, rc=%Rrc\n",
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal, rc));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return rc;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Uninitializes the instance.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Called from FinalRelease().
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncvoid GuestSession::uninit(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoUninitSpan autoUninitSpan(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (autoUninitSpan.uninitDone())
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFuncEnter();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync int rc = VINF_SUCCESS;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#ifdef VBOX_WITH_GUEST_CONTROL
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Closing directories (%zu total)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mDirectories.size()));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync itDirs != mData.mDirectories.end(); ++itDirs)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Assert(mData.mNumObjects);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync mData.mNumObjects--;
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync itDirs->second->i_onRemove();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync itDirs->second->uninit();
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync mData.mDirectories.clear();
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Closing files (%zu total)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mFiles.size()));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (SessionFiles::iterator itFiles = mData.mFiles.begin();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync itFiles != mData.mFiles.end(); ++itFiles)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Assert(mData.mNumObjects);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync mData.mNumObjects--;
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync itFiles->second->i_onRemove();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync itFiles->second->uninit();
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync mData.mFiles.clear();
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Closing processes (%zu total)\n",
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mProcesses.size()));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync itProcs != mData.mProcesses.end(); ++itProcs)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Assert(mData.mNumObjects);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync mData.mNumObjects--;
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync itProcs->second->i_onRemove();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync itProcs->second->uninit();
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync mData.mProcesses.clear();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync AssertMsg(mData.mNumObjects == 0,
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync ("mNumObjects=%RU32 when it should be 0\n", mData.mNumObjects));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync baseUninit();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFuncLeaveRC(rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public getters/setters for attributes
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutPointerValid(aUser);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync mData.mCredentials.mUser.cloneTo(aUser);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutPointerValid(aDomain);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync mData.mCredentials.mDomain.cloneTo(aDomain);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutPointerValid(aName);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mName.cloneTo(aName);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutPointerValid(aId);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *aId = mData.mSession.mID;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return S_OK;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Status)(GuestSessionStatus_T *aStatus)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ReturnComNotImplemented();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#else
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFuncEnter();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync CheckComArgOutPointerValid(aStatus);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AutoCaller autoCaller(this);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *aStatus = mData.mStatus;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutPointerValid(aTimeout);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *aTimeout = mData.mTimeout;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Timeout)(ULONG aTimeout)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync{
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
7e8ef90d3160234df0f254131b87af4243d79476vboxsync ReturnComNotImplemented();
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#else
7e8ef90d3160234df0f254131b87af4243d79476vboxsync LogFlowThisFuncEnter();
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync AutoCaller autoCaller(this);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync mData.mTimeout = aTimeout;
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
7e8ef90d3160234df0f254131b87af4243d79476vboxsync return S_OK;
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
7e8ef90d3160234df0f254131b87af4243d79476vboxsync}
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncSTDMETHODIMP GuestSession::COMGETTER(ProtocolVersion)(ULONG *aVersion)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync{
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#ifndef VBOX_WITH_GUEST_CONTROL
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync ReturnComNotImplemented();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#else
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFuncEnter();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync CheckComArgOutPointerValid(aVersion);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync AutoCaller autoCaller(this);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync *aVersion = mData.mProtocolVersion;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync return S_OK;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync}
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutSafeArrayPointerValid(aEnvironment);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync size_t cEnvVars = mData.mEnvironment.Size();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("[%s]: cEnvVars=%RU32\n",
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mName.c_str(), cEnvVars));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync com::SafeArray<BSTR> environment(cEnvVars);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync for (size_t i = 0; i < cEnvVars; i++)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Bstr strEnv(mData.mEnvironment.Get(i));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync strEnv.cloneTo(&environment[i]);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync environment.detachTo(ComSafeArrayOutArg(aEnvironment));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsyncSTDMETHODIMP GuestSession::COMSETTER(Environment)(ComSafeArrayIn(IN_BSTR, aValues))
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync{
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync ReturnComNotImplemented();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#else
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync LogFlowThisFuncEnter();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync AutoCaller autoCaller(this);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync int rc = VINF_SUCCESS;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync Utf8Str strEnv(environment[i]);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (!strEnv.isEmpty()) /* Silently skip empty entries. */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync rc = mData.mEnvironment.Set(strEnv);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync }
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync LogFlowFuncLeaveRC(hr);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync return hr;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync}
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutSafeArrayPointerValid(aProcesses);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aProcesses));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowFunc(("mProcesses=%zu\n", collection.size()));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutSafeArrayPointerValid(aDirectories);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aDirectories));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowFunc(("mDirectories=%zu\n", collection.size()));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync CheckComArgOutSafeArrayPointerValid(aFiles);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync SafeIfaceArray<IGuestFile> collection(mData.mFiles);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync collection.detachTo(ComSafeArrayOutArg(aFiles));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowFunc(("mFiles=%zu\n", collection.size()));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncSTDMETHODIMP GuestSession::COMGETTER(EventSource)(IEventSource ** aEventSource)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync ReturnComNotImplemented();
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#else
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync LogFlowThisFuncEnter();
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync CheckComArgOutPointerValid(aEventSource);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AutoCaller autoCaller(this);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync // no need to lock - lifetime constant
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mEventSource.queryInterfaceTo(aEventSource);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return S_OK;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync// private methods
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync///////////////////////////////////////////////////////////////////////////////
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowThisFunc(("uFlags=%x, uTimeoutMS=%RU32\n", uFlags, uTimeoutMS));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Guest Additions < 4.3 don't support closing dedicated
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync guest sessions, skip. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (mData.mProtocolVersion < 2)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("Installed Guest Additions don't support closing dedicated sessions, skipping\n"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo uFlags validation. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (mData.mStatus != GuestSessionStatus_Started)
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Session ID=%RU32 not started (anymore), status now is: %RU32\n",
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync mData.mSession.mID, mData.mStatus));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return VINF_SUCCESS;
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int vrc;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestWaitEvent *pEvent = NULL;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestEventTypes eventTypes;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync try
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync eventTypes, &pEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync catch (std::bad_alloc)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = VERR_NO_MEMORY;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(vrc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return vrc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync LogFlowThisFunc(("Sending closing request to guest session ID=%RU32, uFlags=%x\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync mData.mSession.mID, uFlags));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync VBOXHGCMSVCPARM paParms[4];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int i = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setUInt32(pEvent->ContextID());
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setUInt32(uFlags);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Drop the write lock before waiting. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = sendCommand(HOST_SESSION_CLOSE, i, paParms);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_SUCCESS(vrc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = waitForStatusChange(pEvent, GuestSessionWaitForFlag_Terminate, uTimeoutMS,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync NULL /* Session status */, pGuestRc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync unregisterWaitEvent(pEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uFlags, int *pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strPath.c_str(), uMode, uFlags));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestProcessStartupInfo procInfo;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mFlags = ProcessCreateFlag_Hidden;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync try
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Construct arguments. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync if (uFlags)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync if (uFlags & DirectoryCreateFlag_Parents)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync else
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync vrc = VERR_INVALID_PARAMETER;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync }
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (uMode)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync char szMode[16];
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str(szMode));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = VERR_BUFFER_OVERFLOW;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync catch (std::bad_alloc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = VERR_NO_MEMORY;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync vrc = GuestProcessTool::i_run(this, procInfo, pGuestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return vrc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncinline bool GuestSession::directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionDirectories::const_iterator it = mData.mDirectories.find(uDirID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (it != mData.mDirectories.end())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (pDir)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync *pDir = it->second;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return false;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = objData.mType == FsObjType_Directory
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ? VINF_SUCCESS : VERR_NOT_A_DIRECTORY;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return vrc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::directoryRemoveFromList(GuestDirectory *pDirectory)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync int rc = VERR_NOT_FOUND;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync SessionDirectories::iterator itDirs = mData.mDirectories.begin();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync while (itDirs != mData.mDirectories.end())
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (pDirectory == itDirs->second)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /* Make sure to consume the pointer before the one of the
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * iterator gets released. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync ComObjPtr<GuestDirectory> pDir = pDirectory;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Bstr strName;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = itDirs->second->COMGETTER(DirectoryName)(strName.asOutParam());
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ComAssertComRC(hr);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Assert(mData.mDirectories.size());
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Assert(mData.mNumObjects);
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));
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pDirectory->i_onRemove();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync mData.mDirectories.erase(itDirs);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync mData.mNumObjects--;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync pDir.setNull();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync break;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync itDirs++;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFuncLeaveRC(rc);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync return rc;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryRemoveInternal(const Utf8Str &strPath, uint32_t uFlags,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int *pGuestRc)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertReturn(!(uFlags & ~DIRREMOVE_FLAG_VALID_MASK), VERR_INVALID_PARAMETER);
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s, uFlags=0x%x\n", strPath.c_str(), uFlags));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestWaitEvent *pEvent = NULL;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync &pEvent);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return vrc;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Prepare HGCM call. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync VBOXHGCMSVCPARM paParms[8];
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int i = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setUInt32(pEvent->ContextID());
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setPointer((void*)strPath.c_str(),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync (ULONG)strPath.length() + 1);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setUInt32(uFlags);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release(); /* Drop write lock before sending. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = sendCommand(HOST_DIR_REMOVE, i, paParms);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = pEvent->Wait(30 * 1000);
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync if ( vrc == VERR_GSTCTL_GUEST_ERROR
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync && pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync *pGuestRc = pEvent->GuestResult();
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync unregisterWaitEvent(pEvent);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync LogFlowFuncLeaveRC(vrc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return vrc;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync}
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath,
81dfa298981df637a707b142ebd03cb7d3385097vboxsync bool fDirectory, Utf8Str &strName, int *pGuestRc)
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync{
81dfa298981df637a707b142ebd03cb7d3385097vboxsync LogFlowThisFunc(("strTemplate=%s, strPath=%s, fDirectory=%RTbool\n",
81dfa298981df637a707b142ebd03cb7d3385097vboxsync strTemplate.c_str(), strPath.c_str(), fDirectory));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync GuestProcessStartupInfo procInfo;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync try
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (fDirectory)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("-d"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (strPath.length()) /* Otherwise use /tmp or equivalent. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("-t"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strPath);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strTemplate);
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync catch (std::bad_alloc)
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = VERR_NO_MEMORY;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
81dfa298981df637a707b142ebd03cb7d3385097vboxsync /** @todo Use an internal HGCM command for this operation, since
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * we now can run in a user-dedicated session. */
81dfa298981df637a707b142ebd03cb7d3385097vboxsync int guestRc; GuestCtrlStreamObjects stdOut;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync vrc = GuestProcessTool::i_runEx(this, procInfo,
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync &stdOut, 1 /* cStrmOutObjects */,
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync &guestRc);
81dfa298981df637a707b142ebd03cb7d3385097vboxsync if ( RT_SUCCESS(vrc)
81dfa298981df637a707b142ebd03cb7d3385097vboxsync && RT_SUCCESS(guestRc))
81dfa298981df637a707b142ebd03cb7d3385097vboxsync {
81dfa298981df637a707b142ebd03cb7d3385097vboxsync GuestFsObjData objData;
81dfa298981df637a707b142ebd03cb7d3385097vboxsync if (!stdOut.empty())
81dfa298981df637a707b142ebd03cb7d3385097vboxsync {
81dfa298981df637a707b142ebd03cb7d3385097vboxsync vrc = objData.FromMkTemp(stdOut.at(0));
81dfa298981df637a707b142ebd03cb7d3385097vboxsync if (RT_FAILURE(vrc))
81dfa298981df637a707b142ebd03cb7d3385097vboxsync {
81dfa298981df637a707b142ebd03cb7d3385097vboxsync guestRc = vrc;
81dfa298981df637a707b142ebd03cb7d3385097vboxsync vrc = VERR_GSTCTL_GUEST_ERROR;
81dfa298981df637a707b142ebd03cb7d3385097vboxsync }
81dfa298981df637a707b142ebd03cb7d3385097vboxsync }
81dfa298981df637a707b142ebd03cb7d3385097vboxsync else
81dfa298981df637a707b142ebd03cb7d3385097vboxsync vrc = VERR_NO_DATA;
81dfa298981df637a707b142ebd03cb7d3385097vboxsync
81dfa298981df637a707b142ebd03cb7d3385097vboxsync if (RT_SUCCESS(vrc))
81dfa298981df637a707b142ebd03cb7d3385097vboxsync strName = objData.mName;
81dfa298981df637a707b142ebd03cb7d3385097vboxsync }
81dfa298981df637a707b142ebd03cb7d3385097vboxsync
81dfa298981df637a707b142ebd03cb7d3385097vboxsync if (pGuestRc)
81dfa298981df637a707b142ebd03cb7d3385097vboxsync *pGuestRc = guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync}
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::directoryOpenInternal(const GuestDirectoryOpenInfo &openInfo,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync{
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync openInfo.mPath.c_str(), openInfo.mFilter.c_str(), openInfo.mFlags));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc = VERR_MAX_PROCS_REACHED;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Create a new (host-based) directory ID and assign it. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uNewDirID = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ULONG uTries = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync for (;;)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Is the directory ID already used? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!directoryExists(uNewDirID, NULL /* pDirectory */))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
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 rc = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uNewDirID++;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (uNewDirID == VBOX_GUESTCTRL_MAX_OBJECTS)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uNewDirID = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (++uTries == UINT32_MAX)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break; /* Don't try too hard. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the directory object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync HRESULT hr = pDirectory.createObject();
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (FAILED(hr))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return VERR_COM_UNEXPECTED;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Console *pConsole = mParent->getConsole();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtr(pConsole);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = pDirectory->init(pConsole, this /* Parent */,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uNewDirID, openInfo);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_FAILURE(vrc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return vrc;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
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 */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync try
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Add the created directory to our map. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mData.mDirectories[uNewDirID] = pDirectory;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mData.mNumObjects++;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
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
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release(); /* Release lock before firing off event. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Fire off a VBoxEventType_OnGuestDirectoryRegistered event? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync catch (std::bad_alloc &)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_NO_MEMORY;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Nothing further to do here yet. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync *pGuestRc = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync LogFlowFuncLeaveRC(vrc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return vrc;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync}
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::dispatchToDirectory(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (pSvcCb->mParms < 3)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return VERR_INVALID_PARAMETER;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uDirID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync#ifdef DEBUG
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("uDirID=%RU32 (%zu total)\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uDirID, mData.mFiles.size()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync#endif
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionDirectories::const_iterator itDir
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync = mData.mDirectories.find(uDirID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (itDir != mData.mDirectories.end())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<GuestDirectory> pDirectory(itDir->second);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(!pDirectory.isNull());
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pDirectory->i_callbackDispatcher(pCtxCb, pSvcCb);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_NOT_FOUND;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(rc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t uFileID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#ifdef DEBUG
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("uFileID=%RU32 (%zu total)\n",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uFileID, mData.mFiles.size()));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync SessionFiles::const_iterator itFile
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync = mData.mFiles.find(uFileID);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (itFile != mData.mFiles.end())
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync ComObjPtr<GuestFile> pFile(itFile->second);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(!pFile.isNull());
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync alock.release();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pFile->i_callbackDispatcher(pCtxCb, pSvcCb);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VERR_NOT_FOUND;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(rc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uObjectID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
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 if (itProc == mData.mProcesses.end())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionFiles::const_iterator itFile = mData.mFiles.find(uObjectID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (itFile != mData.mFiles.end())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = dispatchToFile(pCtxCb, pSvcCb);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync SessionDirectories::const_iterator itDir = mData.mDirectories.find(uObjectID);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (itDir != mData.mDirectories.end())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = dispatchToDirectory(pCtxCb, pSvcCb);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_NOT_FOUND;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = dispatchToProcess(pCtxCb, pSvcCb);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(rc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync#ifdef DEBUG
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowFunc(("uProcessID=%RU32 (%zu total)\n",
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync uProcessID, mData.mProcesses.size()));
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync#endif
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync int rc;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync SessionProcesses::const_iterator itProc
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync = mData.mProcesses.find(uProcessID);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (itProc != mData.mProcesses.end())
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync#ifdef DEBUG_andy
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync ULONG cRefs = itProc->second->AddRef();
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync Assert(cRefs >= 2);
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync LogFlowFunc(("pProcess=%p, cRefs=%RU32\n", &itProc->second, cRefs - 1));
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync itProc->second->Release();
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync#endif
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync ComObjPtr<GuestProcess> pProcess(itProc->second);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync Assert(!pProcess.isNull());
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Set protocol version so that pSvcCb can
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * be interpreted right. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pCtxCb->uProtocol = mData.mProtocolVersion;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync alock.release();
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pProcess->i_callbackDispatcher(pCtxCb, pSvcCb);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync else
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync rc = VERR_NOT_FOUND;
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync LogFlowFuncLeaveRC(rc);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync return rc;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync}
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#ifdef DEBUG
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("sessionID=%RU32, CID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync switch (pCbCtx->uFunction)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case GUEST_DISCONNECTED:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /** @todo Handle closing all guest objects. */
234b7b45e964034cabd288cd60a28a020855cad4vboxsync rc = VERR_INTERNAL_ERROR;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case GUEST_SESSION_NOTIFY: /* Guest Additions >= 4.3.0. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync rc = onSessionStatusChange(pCbCtx, pSvcCb);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync default:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Silently skip unknown callbacks. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync rc = VERR_NOT_SUPPORTED;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(rc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncinline bool GuestSession::fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync SessionFiles::const_iterator it = mData.mFiles.find(uFileID);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (it != mData.mFiles.end())
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pFile)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *pFile = it->second;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return true;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return false;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::fileRemoveFromList(GuestFile *pFile)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync int rc = VERR_NOT_FOUND;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync SessionFiles::iterator itFiles = mData.mFiles.begin();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync while (itFiles != mData.mFiles.end())
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pFile == itFiles->second)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* Make sure to consume the pointer before the one of thfe
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * iterator gets released. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync ComObjPtr<GuestFile> pCurFile = pFile;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Bstr strName;
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync HRESULT hr = pCurFile->COMGETTER(FileName)(strName.asOutParam());
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ComAssertComRC(hr);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Assert(mData.mNumObjects);
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));
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pFile->i_onRemove();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync mData.mFiles.erase(itFiles);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mNumObjects--;
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Release lock before firing off event. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync fireGuestFileRegisteredEvent(mEventSource, this, pCurFile,
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync false /* Unregistered */);
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync pCurFile.setNull();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync break;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync itFiles++;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFuncLeaveRC(rc);
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync return rc;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc)
004d74842597dacc4009803171296dfcf9398c69vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
004d74842597dacc4009803171296dfcf9398c69vboxsync GuestProcessStartupInfo procInfo;
004d74842597dacc4009803171296dfcf9398c69vboxsync GuestProcessStream streamOut;
004d74842597dacc4009803171296dfcf9398c69vboxsync
004d74842597dacc4009803171296dfcf9398c69vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
004d74842597dacc4009803171296dfcf9398c69vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync try
004d74842597dacc4009803171296dfcf9398c69vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strPath); /* The file we want to remove. */
004d74842597dacc4009803171296dfcf9398c69vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync catch (std::bad_alloc)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = VERR_NO_MEMORY;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync vrc = GuestProcessTool::i_run(this, procInfo, pGuestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
004d74842597dacc4009803171296dfcf9398c69vboxsync}
004d74842597dacc4009803171296dfcf9398c69vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::fileOpenInternal(const GuestFileOpenInfo &openInfo,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<GuestFile> &pFile, int *pGuestRc)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync{
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(),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mCreationMode, openInfo.mInitialOffset));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync /* Guest Additions < 4.3 don't support handling
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync guest files, skip. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync if (mData.mProtocolVersion < 2)
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync {
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync LogFlowThisFunc(("Installed Guest Additions don't support handling guest files, skipping\n"));
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync return VERR_NOT_SUPPORTED;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync }
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc = VERR_MAX_PROCS_REACHED;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Create a new (host-based) file ID and assign it. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t uNewFileID = 0;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync ULONG uTries = 0;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync for (;;)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Is the file ID already used? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!fileExists(uNewFileID, NULL /* pFile */))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
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 rc = VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uNewFileID++;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (uNewFileID == VBOX_GUESTCTRL_MAX_OBJECTS)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uNewFileID = 0;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (++uTries == UINT32_MAX)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break; /* Don't try too hard. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_FAILURE(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the directory object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync HRESULT hr = pFile.createObject();
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (FAILED(hr))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return VERR_COM_UNEXPECTED;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Console *pConsole = mParent->getConsole();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtr(pConsole);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = pFile->init(pConsole, this /* GuestSession */,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uNewFileID, openInfo);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_FAILURE(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync /*
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 */
81096b0da0061583a511da27088643aa949a1ec9vboxsync try
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync /* Add the created file to our vector. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync mData.mFiles[uNewFileID] = pFile;
81096b0da0061583a511da27088643aa949a1ec9vboxsync mData.mNumObjects++;
81096b0da0061583a511da27088643aa949a1ec9vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
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));
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync alock.release(); /* Release lock before firing off event. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync fireGuestFileRegisteredEvent(mEventSource, this, pFile,
81096b0da0061583a511da27088643aa949a1ec9vboxsync true /* Registered */);
81096b0da0061583a511da27088643aa949a1ec9vboxsync }
81096b0da0061583a511da27088643aa949a1ec9vboxsync catch (std::bad_alloc &)
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync rc = VERR_NO_MEMORY;
81096b0da0061583a511da27088643aa949a1ec9vboxsync }
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync if (RT_SUCCESS(rc))
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync int guestRc;
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pFile->i_openFile(30 * 1000 /* 30s timeout */, &guestRc);
81096b0da0061583a511da27088643aa949a1ec9vboxsync if ( rc == VERR_GSTCTL_GUEST_ERROR
81096b0da0061583a511da27088643aa949a1ec9vboxsync && pGuestRc)
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync *pGuestRc = guestRc;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync }
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync }
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(rc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync}
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync{
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = objData.mType == FsObjType_File
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync ? VINF_SUCCESS : VERR_NOT_A_FILE;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync LogFlowFuncLeaveRC(vrc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return vrc;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync}
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync{
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync AssertPtrReturn(pllSize, VERR_INVALID_POINTER);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync GuestFsObjData objData;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQueryInfoInternal(strPath, objData, pGuestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *pllSize = objData.mObjectSize;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return vrc;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync}
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncint GuestSession::fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync{
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
3ff8aa7d3c74cfbe8da5f77b8ea6c748cc79213avboxsync /** @todo Merge this with IGuestFile::queryInfo(). */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync GuestProcessStartupInfo procInfo;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync try
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Construct arguments. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mArguments.push_back(strPath);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync catch (std::bad_alloc)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = VERR_NO_MEMORY;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int guestRc; GuestCtrlStreamObjects stdOut;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync vrc = GuestProcessTool::i_runEx(this, procInfo,
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync &stdOut, 1 /* cStrmOutObjects */,
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( RT_SUCCESS(vrc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && RT_SUCCESS(guestRc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!stdOut.empty())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = objData.FromStat(stdOut.at(0));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = VERR_NO_DATA;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
aff627cebfd8951ebb2949640489d07264738328vboxsync if ( vrc == VERR_GSTCTL_GUEST_ERROR
e94bac0e97b56692161549c95d72512b1eaa78ccvboxsync && pGuestRc)
e94bac0e97b56692161549c95d72512b1eaa78ccvboxsync *pGuestRc = guestRc;
e94bac0e97b56692161549c95d72512b1eaa78ccvboxsync
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync vrc, guestRc));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync}
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncconst GuestCredentials& GuestSession::getCredentials(void)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync{
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync return mData.mCredentials;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync}
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncconst GuestEnvironment& GuestSession::getEnvironment(void)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync{
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync return mData.mEnvironment;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync}
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsyncUtf8Str GuestSession::getName(void)
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return mData.mSession.mName;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/* static */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncUtf8Str GuestSession::guestErrorToString(int guestRc)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Utf8Str strError;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (guestRc)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_INVALID_VM_HANDLE:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("VMM device is not available (is the VM running?)"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_HGCM_SERVICE_NOT_FOUND:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The guest execution service is not available"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_AUTHENTICATION_FAILURE:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The specified user was not able to logon on guest"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_TIMEOUT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The guest did not respond within time"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_CANCELLED:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The session operation was canceled"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_PERMISSION_DENIED:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("Invalid user/password credentials"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_MAX_PROCS_REACHED:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync strError += Utf8StrFmt(tr("Maximum number of concurrent guest processes has been reached"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
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 break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case VERR_NOT_FOUND:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt(tr("The guest execution service is not ready (yet)"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync default:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync strError += Utf8StrFmt("%Rrc", guestRc);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return strError;
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync}
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync/**
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 */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncHRESULT GuestSession::isReadyExternal(void)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /** @todo Be a bit more informative. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (mData.mStatus != GuestSessionStatus_Started)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return setError(E_UNEXPECTED, tr("Session is not in started state"));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return S_OK;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync/**
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync * Called by IGuest right before this session gets removed from
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync * the public session list.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsyncint GuestSession::onRemove(void)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync{
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFuncEnter();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync int vrc = VINF_SUCCESS;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
4517f3d60a86111c8b70238b29d59f26c15291a7vboxsync /*
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * Note: The event source stuff holds references to this object,
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * so make sure that this is cleaned up *before* calling uninit.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync if (!mEventSource.isNull())
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync mEventSource->UnregisterListener(mLocalListener);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync mLocalListener.setNull();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync unconst(mEventSource).setNull();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync }
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFuncLeaveRC(vrc);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync return vrc;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync}
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/** No locking! */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint GuestSession::onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* pCallback is optional. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pSvcCbData->mParms < 3)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return VERR_INVALID_PARAMETER;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync CALLBACKDATA_SESSION_NOTIFY dataCb;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* pSvcCb->mpaParms[0] always contains the context ID. */
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync int vrc = pSvcCbData->mpaParms[1].getUInt32(&dataCb.uType);
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync AssertRCReturn(vrc, vrc);
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync vrc = pSvcCbData->mpaParms[2].getUInt32(&dataCb.uResult);
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync AssertRCReturn(vrc, vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("ID=%RU32, uType=%RU32, guestRc=%Rrc\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mSession.mID, dataCb.uType, dataCb.uResult));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync GuestSessionStatus_T sessionStatus = GuestSessionStatus_Undefined;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int guestRc = dataCb.uResult; /** @todo uint32_t vs. int. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (dataCb.uType)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case GUEST_SESSION_NOTIFYTYPE_ERROR:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_Error;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_STARTED:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_Started;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_TEN:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_TES:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_TEA:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_Terminated;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_TOK:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_TimedOutKilled;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_TOA:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_TimedOutAbnormally;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GUEST_SESSION_NOTIFYTYPE_DWN:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_Down;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GUEST_SESSION_NOTIFYTYPE_UNDEFINED:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync default:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync vrc = VERR_NOT_SUPPORTED;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(vrc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_FAILURE(guestRc))
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync sessionStatus = GuestSessionStatus_Error;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* Set the session status. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync if (RT_SUCCESS(vrc))
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync vrc = setSessionStatus(sessionStatus, guestRc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("ID=%RU32, guestRc=%Rrc\n", mData.mSession.mID, guestRc));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncint GuestSession::startSessionInternal(int *pGuestRc)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
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));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Guest Additions < 4.3 don't support opening dedicated
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync guest sessions. Simply return success here. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (mData.mProtocolVersion < 2)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mStatus = GuestSessionStatus_Started;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFunc(("Installed Guest Additions don't support opening dedicated sessions, skipping\n"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (mData.mStatus != GuestSessionStatus_Undefined)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return VINF_SUCCESS;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /** @todo mData.mSession.uFlags validation. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Set current session status. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mData.mStatus = GuestSessionStatus_Starting;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mData.mRC = VINF_SUCCESS; /* Clear previous error, if any. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int vrc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestWaitEvent *pEvent = NULL;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestEventTypes eventTypes;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync try
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync eventTypes, &pEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync catch (std::bad_alloc)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = VERR_NO_MEMORY;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(vrc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return vrc;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync VBOXHGCMSVCPARM paParms[8];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int i = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setUInt32(pEvent->ContextID());
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setUInt32(mData.mProtocolVersion);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setPointer((void*)mData.mCredentials.mUser.c_str(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync (ULONG)mData.mCredentials.mUser.length() + 1);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setPointer((void*)mData.mCredentials.mPassword.c_str(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync (ULONG)mData.mCredentials.mPassword.length() + 1);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setPointer((void*)mData.mCredentials.mDomain.c_str(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync (ULONG)mData.mCredentials.mDomain.length() + 1);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paParms[i++].setUInt32(mData.mSession.mOpenFlags);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Drop write lock before sending. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = sendCommand(HOST_SESSION_CREATE, i, paParms);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_SUCCESS(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = waitForStatusChange(pEvent, GuestSessionWaitForFlag_Start,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync 30 * 1000 /* 30s timeout */,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync NULL /* Session status */, pGuestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
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.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mData.mStatus = GuestSessionStatus_Error;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mData.mRC = vrc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync unregisterWaitEvent(pEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncint GuestSession::startSessionAsync(void)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowThisFuncEnter();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int vrc;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync try
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Asynchronously open the session on the guest by kicking off a
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * worker thread. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync std::auto_ptr<GuestSessionTaskInternalOpen> pTask(new GuestSessionTaskInternalOpen(this));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertReturn(pTask->isOk(), pTask->rc());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync vrc = RTThreadCreate(NULL, GuestSession::startSessionThread,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync (void *)pTask.get(), 0,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync RTTHREADTYPE_MAIN_WORKER, 0,
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync "gctlSesStart");
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(vrc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* pTask is now owned by openSessionThread(), so release it. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pTask.release();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync catch(std::bad_alloc &)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync vrc = VERR_NO_MEMORY;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowFuncLeaveRC(vrc);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return vrc;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/* static */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncDECLCALLBACK(int) GuestSession::startSessionThread(RTTHREAD Thread, void *pvUser)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowFunc(("pvUser=%p\n", pvUser));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync std::auto_ptr<GuestSessionTaskInternalOpen> pTask(static_cast<GuestSessionTaskInternalOpen*>(pvUser));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertPtr(pTask.get());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const ComObjPtr<GuestSession> pSession(pTask->Session());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(!pSession.isNull());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AutoCaller autoCaller(pSession);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync int vrc = pSession->startSessionInternal(NULL /* Guest rc, ignored */);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Nothing to do here anymore. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowFuncLeaveRC(vrc);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return vrc;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint GuestSession::pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uFlags, int *pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertReturn(!(uFlags & ~PATHRENAME_FLAG_VALID_MASK), VERR_INVALID_PARAMETER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strSource=%s, strDest=%s, uFlags=0x%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strSource.c_str(), strDest.c_str(), uFlags));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestWaitEvent *pEvent = NULL;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync &pEvent);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return vrc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Prepare HGCM call. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync VBOXHGCMSVCPARM paParms[8];
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int i = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setUInt32(pEvent->ContextID());
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setPointer((void*)strSource.c_str(),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync (ULONG)strSource.length() + 1);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setPointer((void*)strDest.c_str(),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync (ULONG)strDest.length() + 1);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync paParms[i++].setUInt32(uFlags);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync alock.release(); /* Drop write lock before sending. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = sendCommand(HOST_PATH_RENAME, i, paParms);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = pEvent->Wait(30 * 1000);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( vrc == VERR_GSTCTL_GUEST_ERROR
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && pGuestRc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync *pGuestRc = pEvent->GuestResult();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync unregisterWaitEvent(pEvent);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return vrc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint GuestSession::processRemoveFromList(GuestProcess *pProcess)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowThisFunc(("pProcess=%p\n", pProcess));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync int rc = VERR_NOT_FOUND;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ULONG uPID;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync HRESULT hr = pProcess->COMGETTER(PID)(&uPID);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync ComAssertComRC(hr);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("Removing process (PID=%RU32) ...\n", uPID));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync SessionProcesses::iterator itProcs = mData.mProcesses.begin();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync while (itProcs != mData.mProcesses.end())
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync if (pProcess == itProcs->second)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync#ifdef DEBUG_andy
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync ULONG cRefs = pProcess->AddRef();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Assert(cRefs >= 2);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowFunc(("pProcess=%p, cRefs=%RU32\n", pProcess, cRefs - 1));
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync pProcess->Release();
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync#endif
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /* Make sure to consume the pointer before the one of the
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * iterator gets released. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync ComObjPtr<GuestProcess> pProc = pProcess;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync hr = pProc->COMGETTER(PID)(&uPID);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ComAssertComRC(hr);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync Assert(mData.mProcesses.size());
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Assert(mData.mNumObjects);
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));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync rc = pProcess->i_onRemove();
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync mData.mProcesses.erase(itProcs);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mData.mNumObjects--;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Release lock before firing off event. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProc,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync uPID, false /* Process unregistered */);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync pProc.setNull();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync break;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync itProcs++;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlowFuncLeaveRC(rc);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync return rc;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync/**
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Creates but does *not* start the process yet. See GuestProcess::startProcess() or
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * GuestProcess::startProcessAsync() for that.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync *
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @return IPRT status code.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param procInfo
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param pProcess
5366e994777f9d9391cf809dc77610f57270d75dvboxsync */
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncint GuestSession::processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync#ifdef DEBUG
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (procInfo.mArguments.size())
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlowFunc(("Arguments:"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync ProcessArguments::const_iterator it = procInfo.mArguments.begin();
5366e994777f9d9391cf809dc77610f57270d75dvboxsync while (it != procInfo.mArguments.end())
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow((" %s", (*it).c_str()));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync it++;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow(("\n"));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
5366e994777f9d9391cf809dc77610f57270d75dvboxsync#endif
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Validate flags. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (procInfo.mFlags)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync && !(procInfo.mFlags & ProcessCreateFlag_Hidden)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_NoProfile)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return VERR_INVALID_PARAMETER;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync if ( (procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync && ( (procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync || (procInfo.mFlags & ProcessCreateFlag_WaitForStdErr)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync )
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync )
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync {
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync return VERR_INVALID_PARAMETER;
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync }
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Adjust timeout. If set to 0, we define
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * an infinite timeout. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (procInfo.mTimeoutMS == 0)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mTimeoutMS = UINT32_MAX;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /** @tood Implement process priority + affinity. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync int rc = VERR_MAX_PROCS_REACHED;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync return rc;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* Create a new (host-based) process ID and assign it. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync uint32_t uNewProcessID = 0;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync ULONG uTries = 0;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync for (;;)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /* Is the context ID already used? */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!processExists(uNewProcessID, NULL /* pProcess */))
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync {
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 rc = VINF_SUCCESS;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync break;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync }
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync uNewProcessID++;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (uNewProcessID == VBOX_GUESTCTRL_MAX_OBJECTS)
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync uNewProcessID = 0;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (++uTries == VBOX_GUESTCTRL_MAX_OBJECTS)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync break; /* Don't try too hard. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync }
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (RT_FAILURE(rc))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return rc;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the process object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync HRESULT hr = pProcess.createObject();
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (FAILED(hr))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return VERR_COM_UNEXPECTED;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync rc = pProcess->init(mParent->getConsole() /* Console */, this /* Session */,
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync uNewProcessID, procInfo);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (RT_FAILURE(rc))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return rc;
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Add the created process to our map. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync try
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync {
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync mData.mProcesses[uNewProcessID] = pProcess;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync mData.mNumObjects++;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync
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));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync alock.release(); /* Release lock before firing off event. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProcess,
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync 0 /* PID */, true /* Process registered */);
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync }
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync catch (std::bad_alloc &)
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync {
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync rc = VERR_NO_MEMORY;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return rc;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
ccbdc11833996cb9f3be7868f1ebaefcacafb94dvboxsyncinline bool GuestSession::processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync{
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (it != mData.mProcesses.end())
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (pProcess)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync *pProcess = it->second;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return true;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return false;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync}
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncinline int GuestSession::processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync{
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AssertReturn(uPID, false);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /* pProcess is optional. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync SessionProcesses::iterator itProcs = mData.mProcesses.begin();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync for (; itProcs != mData.mProcesses.end(); itProcs++)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ComObjPtr<GuestProcess> pCurProc = itProcs->second;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AutoCaller procCaller(pCurProc);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (procCaller.rc())
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return VERR_COM_INVALID_OBJECT_STATE;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ULONG uCurPID;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync HRESULT hr = pCurProc->COMGETTER(PID)(&uCurPID);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ComAssertComRC(hr);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (uCurPID == uPID)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (pProcess)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync *pProcess = pCurProc;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return VINF_SUCCESS;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return VERR_NOT_FOUND;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncint GuestSession::sendCommand(uint32_t uFunction,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t uParms, PVBOXHGCMSVCPARM paParms)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowThisFuncEnter();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#ifndef VBOX_GUESTCTRL_TEST_CASE
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync ComObjPtr<Console> pConsole = mParent->getConsole();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(!pConsole.isNull());
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Forward the information to the VMM device. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync VMMDev *pVMMDev = pConsole->getVMMDev();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertPtr(pVMMDev);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowThisFunc(("uFunction=%RU32, uParms=%RU32\n", uFunction, uParms));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int vrc = pVMMDev->hgcmHostCall(HGCMSERVICE_NAME, uFunction, uParms, paParms);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_FAILURE(vrc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /** @todo What to do here? */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Not needed within testcases. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int vrc = VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlowFuncLeaveRC(vrc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return vrc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/* static */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncHRESULT GuestSession::setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertPtr(pInterface);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n"));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return pInterface->setError(VBOX_E_IPRT_ERROR, GuestSession::guestErrorToString(guestRc).c_str());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync/* Does not do locking; caller is responsible for that! */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint GuestSession::setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("oldStatus=%RU32, newStatus=%RU32, sessionRc=%Rrc\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mStatus, sessionStatus, sessionRc));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (sessionStatus == GuestSessionStatus_Error)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
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 }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync else
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertMsg(RT_SUCCESS(sessionRc), ("Guest rc must not be an error (%Rrc)\n", sessionRc));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (mData.mStatus != sessionStatus)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mStatus = sessionStatus;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mRC = sessionRc;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync ComObjPtr<VirtualBoxErrorInfo> errorInfo;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync HRESULT hr = errorInfo.createObject();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync ComAssertComRC(hr);
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync int rc2 = errorInfo->initEx(VBOX_E_IPRT_ERROR, sessionRc,
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync COM_IIDOF(IGuestSession), getComponentName(),
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync guestErrorToString(sessionRc));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertRC(rc2);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync fireGuestSessionStateChangedEvent(mEventSource, this,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync mData.mSession.mID, sessionStatus, errorInfo);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return VINF_SUCCESS;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint GuestSession::signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*LogFlowThisFunc(("enmWaitResult=%d, rc=%Rrc, mWaitCount=%RU32, mWaitEvent=%p\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync enmWaitResult, rc, mData.mWaitCount, mData.mWaitEvent));*/
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* Note: No write locking here -- already done in the caller. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync int vrc = VINF_SUCCESS;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*if (mData.mWaitEvent)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync vrc = mData.mWaitEvent->Signal(enmWaitResult, rc);*/
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowFuncLeaveRC(vrc);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return vrc;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncint GuestSession::startTaskAsync(const Utf8Str &strTaskDesc,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync{
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowThisFunc(("strTaskDesc=%s, pTask=%p\n", strTaskDesc.c_str(), pTask));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync AssertPtrReturn(pTask, VERR_INVALID_POINTER);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Create the progress object. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync HRESULT hr = pProgress.createObject();
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (FAILED(hr))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return VERR_COM_UNEXPECTED;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync hr = pProgress->init(static_cast<IGuestSession*>(this),
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync Bstr(strTaskDesc).raw(),
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync TRUE /* aCancelable */);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (FAILED(hr))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return VERR_COM_UNEXPECTED;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Initialize our worker task. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync std::auto_ptr<GuestSessionTask> task(pTask);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync int rc = task->RunAsync(strTaskDesc, pProgress);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (RT_FAILURE(rc))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return rc;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* Don't destruct on success. */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync task.release();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync LogFlowFuncLeaveRC(rc);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return rc;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync}
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync/**
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 *
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * @return IPRT status code.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsyncint GuestSession::queryInfo(void)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync{
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /*
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * Try querying the guest control protocol version running on the guest.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * This is done using the Guest Additions version
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync ComObjPtr<Guest> pGuest = mParent;
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync Assert(!pGuest.isNull());
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
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);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync#ifdef DEBUG_andy
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* Hardcode the to-used protocol version; nice for testing side effects. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync mData.mProtocolVersion = 2;
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync#else
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync mData.mProtocolVersion = (
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* VBox 5.0 and up. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uVBoxMajor >= 5
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* VBox 4.3 and up. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync || (uVBoxMajor == 4 && uVBoxMinor >= 3))
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync ? 2 /* Guest control 2.0. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync : 1; /* Legacy guest control (VBox < 4.3). */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Build revision is ignored. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync#endif
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("uVerAdditions=%RU32 (%RU32.%RU32), mProtocolVersion=%RU32\n",
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uVerAdditions, uVBoxMajor, uVBoxMinor, mData.mProtocolVersion));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* Tell the user but don't bitch too often. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync static short s_gctrlLegacyWarning = 0;
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync if ( mData.mProtocolVersion < 2
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"),
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uVBoxMajor, uVBoxMinor, mData.mProtocolVersion));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync return VINF_SUCCESS;
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync}
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncint GuestSession::waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlowThisFuncEnter();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AssertReturn(fWaitFlags, VERR_INVALID_PARAMETER);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
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
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Did some error occur before? Then skip waiting and return. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (mData.mStatus == GuestSessionStatus_Error)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Error;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest session indicated an error\n", mData.mRC));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (pGuestRc)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *pGuestRc = mData.mRC; /* Return last set error. */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return VERR_GSTCTL_GUEST_ERROR;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Guest Additions < 4.3 don't support session handling, skip. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (mData.mProtocolVersion < 2)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync waitResult = GuestSessionWaitResult_WaitFlagNotSupported;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("Installed Guest Additions don't support waiting for dedicated sessions, skipping\n"));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync return VINF_SUCCESS;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_None;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (fWaitFlags & GuestSessionWaitForFlag_Terminate)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync switch (mData.mStatus)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Terminated:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Down:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Terminate;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_TimedOutKilled:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_TimedOutAbnormally:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Timeout;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Error:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Handled above. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Started:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Start;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Undefined:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Starting:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Do the waiting below. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync default:
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertMsgFailed(("Unhandled session status %RU32\n", mData.mStatus));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return VERR_NOT_IMPLEMENTED;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync else if (fWaitFlags & GuestSessionWaitForFlag_Start)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync switch (mData.mStatus)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Started:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Terminating:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Terminated:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Down:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Start;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Error:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Error;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_TimedOutKilled:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_TimedOutAbnormally:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync waitResult = GuestSessionWaitResult_Timeout;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Undefined:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case GuestSessionStatus_Starting:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* Do the waiting below. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync default:
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertMsgFailed(("Unhandled session status %RU32\n", mData.mStatus));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return VERR_NOT_IMPLEMENTED;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("sessionStatus=%RU32, sessionRc=%Rrc, waitResult=%RU32\n",
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync mData.mStatus, mData.mRC, waitResult));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* No waiting needed? Return immediately using the last set error. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (waitResult != GuestSessionWaitResult_None)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (pGuestRc)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *pGuestRc = mData.mRC; /* Return last set error (if any). */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int vrc;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestWaitEvent *pEvent = NULL;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestEventTypes eventTypes;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync try
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync eventTypes, &pEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync catch (std::bad_alloc)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = VERR_NO_MEMORY;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(vrc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return vrc;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync alock.release(); /* Release lock before waiting. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync GuestSessionStatus_T sessionStatus;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = waitForStatusChange(pEvent, fWaitFlags,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync uTimeoutMS, &sessionStatus, pGuestRc);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (RT_SUCCESS(vrc))
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync switch (sessionStatus)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GuestSessionStatus_Started:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync waitResult = GuestSessionWaitResult_Start;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GuestSessionStatus_Terminated:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync waitResult = GuestSessionWaitResult_Terminate;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GuestSessionStatus_TimedOutKilled:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GuestSessionStatus_TimedOutAbnormally:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync waitResult = GuestSessionWaitResult_Timeout;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GuestSessionStatus_Down:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync waitResult = GuestSessionWaitResult_Terminate;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case GuestSessionStatus_Error:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync waitResult = GuestSessionWaitResult_Error;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync default:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync waitResult = GuestSessionWaitResult_Status;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync unregisterWaitEvent(pEvent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlowFuncLeaveRC(vrc);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return vrc;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncint GuestSession::waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestSessionStatus_T *pSessionStatus, int *pGuestRc)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync VBoxEventType_T evtType;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComPtr<IEvent> pIEvent;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int vrc = waitForEvent(pEvent, uTimeoutMS,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync &evtType, pIEvent.asOutParam());
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_SUCCESS(vrc))
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Assert(evtType == VBoxEventType_OnGuestSessionStateChanged);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComPtr<IGuestSessionStateChangedEvent> pChangedEvent = pIEvent;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Assert(!pChangedEvent.isNull());
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestSessionStatus_T sessionStatus;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pChangedEvent->COMGETTER(Status)(&sessionStatus);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (pSessionStatus)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync *pSessionStatus = sessionStatus;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync ComPtr<IVirtualBoxErrorInfo> errorInfo;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HRESULT hr = pChangedEvent->COMGETTER(Error)(errorInfo.asOutParam());
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComAssertComRC(hr);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync LONG lGuestRc;
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync hr = errorInfo->COMGETTER(ResultDetail)(&lGuestRc);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ComAssertComRC(hr);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE((int)lGuestRc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync vrc = VERR_GSTCTL_GUEST_ERROR;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (pGuestRc)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync *pGuestRc = (int)lGuestRc;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync LogFlowThisFunc(("Status changed event for session ID=%RU32, new status is: %RU32 (%Rrc)\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync mData.mSession.mID, sessionStatus,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync RT_SUCCESS((int)lGuestRc) ? VINF_SUCCESS : (int)lGuestRc));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlowFuncLeaveRC(vrc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return vrc;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// implementation of public methods
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/////////////////////////////////////////////////////////////////////////////
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::Close(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync AutoCaller autoCaller(this);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync /* Close session on guest. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync int guestRc = VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc = closeSession(0 /* Flags */, 30 * 1000 /* Timeout */,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync &guestRc);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* On failure don't return here, instead do all the cleanup
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * work first and then return an error. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync /* Remove ourselves from the session list. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync int rc2 = mParent->sessionRemove(this);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (rc2 == VERR_NOT_FOUND) /* Not finding the session anymore isn't critical. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc2 = VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(rc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync rc = rc2;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync rc, guestRc));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_FAILURE(rc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync if (rc == VERR_GSTCTL_GUEST_ERROR)
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync return GuestSession::setErrorExternal(this, guestRc);
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return setError(VBOX_E_IPRT_ERROR,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync tr("Closing guest session failed with %Rrc"), rc);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync CheckComArgStrNotEmptyOrNull(aSource);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync CheckComArgStrNotEmptyOrNull(aDest);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync CheckComArgOutPointerValid(aProgress);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
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"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint32_t fFlags = CopyFileFlag_None;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (aFlags)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (size_t i = 0; i < flags.size(); i++)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync fFlags |= flags[i];
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync HRESULT hr = S_OK;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
c99b597540585068d22dde4c9f74730305f24097vboxsync try
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync ComObjPtr<Progress> pProgress;
c99b597540585068d22dde4c9f74730305f24097vboxsync SessionTaskCopyFrom *pTask = new SessionTaskCopyFrom(this /* GuestSession */,
c99b597540585068d22dde4c9f74730305f24097vboxsync Utf8Str(aSource), Utf8Str(aDest), fFlags);
c99b597540585068d22dde4c9f74730305f24097vboxsync int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest),
c99b597540585068d22dde4c9f74730305f24097vboxsync pTask, pProgress);
c99b597540585068d22dde4c9f74730305f24097vboxsync if (RT_SUCCESS(rc))
c99b597540585068d22dde4c9f74730305f24097vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync /* Return progress to the caller. */
c99b597540585068d22dde4c9f74730305f24097vboxsync hr = pProgress.queryInterfaceTo(aProgress);
c99b597540585068d22dde4c9f74730305f24097vboxsync }
c99b597540585068d22dde4c9f74730305f24097vboxsync else
c99b597540585068d22dde4c9f74730305f24097vboxsync hr = setError(VBOX_E_IPRT_ERROR,
c99b597540585068d22dde4c9f74730305f24097vboxsync tr("Starting task for copying file \"%ls\" from guest to \"%ls\" on the host failed: %Rrc"), rc);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
c99b597540585068d22dde4c9f74730305f24097vboxsync catch(std::bad_alloc &)
c99b597540585068d22dde4c9f74730305f24097vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync hr = E_OUTOFMEMORY;
c99b597540585068d22dde4c9f74730305f24097vboxsync }
c99b597540585068d22dde4c9f74730305f24097vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncSTDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync CheckComArgStrNotEmptyOrNull(aSource);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync CheckComArgStrNotEmptyOrNull(aDest);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync CheckComArgOutPointerValid(aProgress);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
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"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint32_t fFlags = CopyFileFlag_None;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (aFlags)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync for (size_t i = 0; i < flags.size(); i++)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync fFlags |= flags[i];
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync HRESULT hr = S_OK;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
c99b597540585068d22dde4c9f74730305f24097vboxsync try
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync ComObjPtr<Progress> pProgress;
c99b597540585068d22dde4c9f74730305f24097vboxsync SessionTaskCopyTo *pTask = new SessionTaskCopyTo(this /* GuestSession */,
c99b597540585068d22dde4c9f74730305f24097vboxsync Utf8Str(aSource), Utf8Str(aDest), fFlags);
02651f98b4320e70a300ba1ebe95270096ebfd4dvboxsync AssertPtrReturn(pTask, E_OUTOFMEMORY);
c99b597540585068d22dde4c9f74730305f24097vboxsync int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest),
c99b597540585068d22dde4c9f74730305f24097vboxsync pTask, pProgress);
c99b597540585068d22dde4c9f74730305f24097vboxsync if (RT_SUCCESS(rc))
c99b597540585068d22dde4c9f74730305f24097vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync /* Return progress to the caller. */
c99b597540585068d22dde4c9f74730305f24097vboxsync hr = pProgress.queryInterfaceTo(aProgress);
c99b597540585068d22dde4c9f74730305f24097vboxsync }
c99b597540585068d22dde4c9f74730305f24097vboxsync else
c99b597540585068d22dde4c9f74730305f24097vboxsync hr = setError(VBOX_E_IPRT_ERROR,
c99b597540585068d22dde4c9f74730305f24097vboxsync tr("Starting task for copying file \"%ls\" from host to \"%ls\" on the guest failed: %Rrc"), rc);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
c99b597540585068d22dde4c9f74730305f24097vboxsync catch(std::bad_alloc &)
c99b597540585068d22dde4c9f74730305f24097vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync hr = E_OUTOFMEMORY;
c99b597540585068d22dde4c9f74730305f24097vboxsync }
c99b597540585068d22dde4c9f74730305f24097vboxsync
c99b597540585068d22dde4c9f74730305f24097vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncSTDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode,
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync ComSafeArrayIn(DirectoryCreateFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return setError(E_INVALIDARG, tr("No directory to create specified"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync uint32_t fFlags = DirectoryCreateFlag_None;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (aFlags)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync com::SafeArray<DirectoryCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync for (size_t i = 0; i < flags.size(); i++)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync fFlags |= flags[i];
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (fFlags)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (!(fFlags & DirectoryCreateFlag_Parents))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), fFlags);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync HRESULT hr = S_OK;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync ComObjPtr <GuestDirectory> pDirectory; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = directoryCreateInternal(Utf8Str(aPath), (uint32_t)aMode, fFlags, &guestRc);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (RT_FAILURE(rc))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync switch (rc)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
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"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync case VERR_INVALID_PARAMETER:
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync break;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync case VERR_BROKEN_PIPE:
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync break;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync default:
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync break;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
3641904508e6a0671c21a083a2ed03ebad8d976cvboxsyncSTDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, BSTR *aDirectory)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
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"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync CheckComArgOutPointerValid(aDirectory);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync HRESULT hr = S_OK;
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str strName; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = objectCreateTempInternal(Utf8Str(aTemplate),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync true /* Directory */, strName, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(rc))
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync {
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync strName.cloneTo(aDirectory);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync else
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (rc)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync default:
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);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return setError(E_INVALIDARG, tr("No directory to check existence for specified"));
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync CheckComArgOutPointerValid(aExists);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync HRESULT hr = S_OK;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync GuestFsObjData objData; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (RT_SUCCESS(rc))
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync *aExists = objData.mType == FsObjType_Directory;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync }
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync else
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync switch (rc)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory existence \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(), rc);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync break;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync }
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync }
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsyncSTDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
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"));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync CheckComArgOutPointerValid(aDirectory);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync uint32_t fFlags = DirectoryOpenFlag_None;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if (aFlags)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync com::SafeArray<DirectoryOpenFlag_T> flags(ComSafeArrayInArg(aFlags));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync for (size_t i = 0; i < flags.size(); i++)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync fFlags |= flags[i];
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if (fFlags)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return setError(E_INVALIDARG, tr("Open flags (%#x) not implemented yet"), fFlags);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync HRESULT hr = S_OK;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestDirectoryOpenInfo openInfo;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync openInfo.mPath = Utf8Str(aPath);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync openInfo.mFilter = Utf8Str(aFilter);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync openInfo.mFlags = fFlags;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr <GuestDirectory> pDirectory; int guestRc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc = directoryOpenInternal(openInfo, pDirectory, &guestRc);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if (RT_SUCCESS(rc))
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Return directory object to the caller. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = pDirectory.queryInterfaceTo(aDirectory);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync else
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync switch (rc)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case VERR_INVALID_PARAMETER:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed; invalid parameters given",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str()));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync break;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GSTCTL_GUEST_ERROR:
18e3d4704ed7b57260b0d4e3ea12c224b3f81840vboxsync hr = GuestDirectory::i_setErrorExternal(this, guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(),rc);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync break;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return setError(E_INVALIDARG, tr("No directory to query information for specified"));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync CheckComArgOutPointerValid(aInfo);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync HRESULT hr = S_OK;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync GuestFsObjData objData; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (objData.mType == FsObjType_Directory)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync ComObjPtr<GuestFsObjInfo> pFsObjInfo;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = pFsObjInfo.createObject();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (FAILED(hr)) return hr;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = pFsObjInfo->init(objData);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = pFsObjInfo.queryInterfaceTo(aInfo);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (FAILED(hr)) return hr;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_FAILURE(vrc))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (vrc)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case VERR_NOT_A_DIRECTORY:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Element \"%s\" exists but is not a directory",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str()));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory information for \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(), vrc);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No directory to remove specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = isReadyExternal();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* No flags; only remove the directory when empty. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uFlags = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int guestRc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = directoryRemoveInternal(Utf8Str(aPath), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync switch (vrc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_NOT_SUPPORTED:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling removing guest directories not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GSTCTL_GUEST_ERROR:
18e3d4704ed7b57260b0d4e3ea12c224b3f81840vboxsync hr = GuestDirectory::i_setErrorExternal(this, guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync default:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Removing guest directory \"%s\" failed: %Rrc"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8Str(aPath).c_str(), vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No directory to remove recursively specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = isReadyExternal();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<Progress> pProgress;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = pProgress.createObject();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (SUCCEEDED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = pProgress->init(static_cast<IGuestSession *>(this),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Bstr(tr("Removing guest directory")).raw(),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync TRUE /*aCancelable*/);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
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 hr = pProgress->notifyComplete(S_OK);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Remove the directory + all its contents. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uFlags = DIRREMOVE_FLAG_RECURSIVE
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync | DIRREMOVE_FLAG_CONTENT_AND_DIR;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int guestRc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = directoryRemoveInternal(Utf8Str(aPath), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync switch (vrc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_NOT_SUPPORTED:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling removing guest directories recursively not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GSTCTL_GUEST_ERROR:
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync hr = GuestFile::i_setErrorExternal(this, guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync default:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Recursively removing guest directory \"%s\" failed: %Rrc"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8Str(aPath).c_str(), vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pProgress.queryInterfaceTo(aProgress);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No source directory to rename specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No destination directory to rename the source to specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = isReadyExternal();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* No flags; only remove the directory when empty. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uFlags = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int guestRc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = pathRenameInternal(Utf8Str(aSource), Utf8Str(aDest), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync switch (vrc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_NOT_SUPPORTED:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling renaming guest directories not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GSTCTL_GUEST_ERROR:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Renaming guest directory failed: %Rrc"), guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync default:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Renaming guest directory \"%s\" failed: %Rrc"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8Str(aSource).c_str(), vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSTDMETHODIMP GuestSession::EnvironmentClear(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync mData.mEnvironment.Clear();
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return S_OK;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncSTDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync{
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#ifndef VBOX_WITH_GUEST_CONTROL
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync ReturnComNotImplemented();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync CheckComArgOutPointerValid(aValue);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync AutoCaller autoCaller(this);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync strValue.cloneTo(aValue);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return setError(E_INVALIDARG, tr("No value name specified"));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowFuncLeaveRC(hr);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync mData.mEnvironment.Unset(Utf8Str(aName));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFuncLeave();
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
92e624e40b06b4dc6d0a8222e1de33bd3e879a63vboxsyncSTDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, IGuestFile **aFile)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return setError(E_INVALIDARG, tr("No file to check existence for specified"));
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync CheckComArgOutPointerValid(aExists);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync GuestFsObjData objData; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *aExists = TRUE;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return S_OK;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync HRESULT hr = S_OK;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (vrc)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case VERR_NOT_A_FILE:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *aExists = FALSE;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information for \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(), vrc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync }
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsyncSTDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync{
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync ReturnComNotImplemented();
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync#else
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync LogFlowThisFuncEnter();
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync return setError(E_INVALIDARG, tr("No file to remove specified"));
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync AutoCaller autoCaller(this);
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync HRESULT hr = S_OK;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileRemoveInternal(Utf8Str(aPath), &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_FAILURE(vrc))
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (vrc)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Removing file \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(), vrc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return hr;
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync}
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsyncSTDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, IGuestFile **aFile)
81096b0da0061583a511da27088643aa949a1ec9vboxsync{
81096b0da0061583a511da27088643aa949a1ec9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
81096b0da0061583a511da27088643aa949a1ec9vboxsync ReturnComNotImplemented();
81096b0da0061583a511da27088643aa949a1ec9vboxsync#else
81096b0da0061583a511da27088643aa949a1ec9vboxsync LogFlowThisFuncEnter();
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync Bstr strSharingMode = ""; /* Sharing mode is ignored. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync return FileOpenEx(aPath, aOpenMode, aDisposition, strSharingMode.raw(), aCreationMode,
81096b0da0061583a511da27088643aa949a1ec9vboxsync 0 /* aOffset */, aFile);
81096b0da0061583a511da27088643aa949a1ec9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
81096b0da0061583a511da27088643aa949a1ec9vboxsync}
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsyncSTDMETHODIMP GuestSession::FileOpenEx(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, IN_BSTR aSharingMode,
81096b0da0061583a511da27088643aa949a1ec9vboxsync ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
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. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync CheckComArgOutPointerValid(aFile);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync HRESULT hr = isReadyExternal();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (FAILED(hr))
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return hr;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /** @todo Validate creation mode. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync uint32_t uCreationMode = 0;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync GuestFileOpenInfo openInfo;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mFileName = Utf8Str(aPath);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mOpenMode = Utf8Str(aOpenMode);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mDisposition = Utf8Str(aDisposition);
81096b0da0061583a511da27088643aa949a1ec9vboxsync openInfo.mSharingMode = Utf8Str(aSharingMode);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mCreationMode = aCreationMode;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync openInfo.mInitialOffset = aOffset;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync uint64_t uFlagsIgnored;
81096b0da0061583a511da27088643aa949a1ec9vboxsync int vrc = RTFileModeToFlagsEx(openInfo.mOpenMode.c_str(),
81096b0da0061583a511da27088643aa949a1ec9vboxsync openInfo.mDisposition.c_str(),
81096b0da0061583a511da27088643aa949a1ec9vboxsync openInfo.mSharingMode.c_str(),
81096b0da0061583a511da27088643aa949a1ec9vboxsync &uFlagsIgnored);
81096b0da0061583a511da27088643aa949a1ec9vboxsync if (RT_FAILURE(vrc))
81096b0da0061583a511da27088643aa949a1ec9vboxsync return setError(E_INVALIDARG, tr("Invalid open mode / disposition / sharing mode specified"));
81096b0da0061583a511da27088643aa949a1ec9vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync ComObjPtr <GuestFile> pFile; int guestRc;
81096b0da0061583a511da27088643aa949a1ec9vboxsync vrc = fileOpenInternal(openInfo, pFile, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Return directory object to the caller. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync hr = pFile.queryInterfaceTo(aFile);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
5366e994777f9d9391cf809dc77610f57270d75dvboxsync else
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (vrc)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync case VERR_NOT_SUPPORTED:
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync hr = setError(VBOX_E_IPRT_ERROR,
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync tr("Handling guest files not supported by installed Guest Additions"));
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync break;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsync hr = GuestFile::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync default:
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Opening guest file \"%s\" failed: %Rrc"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Utf8Str(aPath).c_str(), vrc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return setError(E_INVALIDARG, tr("No file to query information for specified"));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync CheckComArgOutPointerValid(aInfo);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync HRESULT hr = S_OK;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync GuestFsObjData objData; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync ComObjPtr<GuestFsObjInfo> pFsObjInfo;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = pFsObjInfo.createObject();
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (FAILED(hr)) return hr;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = pFsObjInfo->init(objData);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = pFsObjInfo.queryInterfaceTo(aInfo);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (FAILED(hr)) return hr;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_FAILURE(vrc))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (vrc)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case VERR_NOT_A_FILE:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Element exists but is not a file"));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information failed: %Rrc"), vrc);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync return setError(E_INVALIDARG, tr("No file to query size for specified"));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync CheckComArgOutPointerValid(aSize);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync HRESULT hr = S_OK;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int64_t llSize; int guestRc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int vrc = fileQuerySizeInternal(Utf8Str(aPath), &llSize, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(vrc))
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync *aSize = llSize;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync else
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (vrc)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync hr = GuestProcess::i_setErrorExternal(this, guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), vrc);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync break;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No source file to rename specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return setError(E_INVALIDARG, tr("No destination file to rename the source to specified"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = isReadyExternal();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* No flags; only remove the directory when empty. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t uFlags = 0;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int guestRc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int vrc = pathRenameInternal(Utf8Str(aSource), Utf8Str(aDest), uFlags, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync switch (vrc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_NOT_SUPPORTED:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Handling renaming guest files not supported by installed Guest Additions"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GSTCTL_GUEST_ERROR:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Proper guestRc to text translation needed. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync tr("Renaming guest file failed: %Rrc"), guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync default:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Renaming guest file \"%s\" failed: %Rrc"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8Str(aSource).c_str(), vrc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync com::SafeArray<LONG> affinityIgnored;
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinityIgnored), aProcess);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
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),
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync IGuestProcess **aProcess)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return setError(E_INVALIDARG, tr("No command to execute specified"));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync CheckComArgOutPointerValid(aProcess);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync HRESULT hr = isReadyExternal();
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (FAILED(hr))
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return hr;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync GuestProcessStartupInfo procInfo;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync procInfo.mCommand = Utf8Str(aCommand);
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (aArguments)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync for (size_t i = 0; i < arguments.size(); i++)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync procInfo.mArguments.push_back(Utf8Str(arguments[i]));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync int rc = VINF_SUCCESS;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /*
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.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (aEnvironment)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
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 }
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync if (RT_SUCCESS(rc))
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (aFlags)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync for (size_t i = 0; i < flags.size(); i++)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync procInfo.mFlags |= flags[i];
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync procInfo.mTimeoutMS = aTimeoutMS;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (aAffinity)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync for (size_t i = 0; i < affinity.size(); i++)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (affinity[i])
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync procInfo.mAffinity |= (uint64_t)1 << i;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync procInfo.mPriority = aPriority;
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync ComObjPtr<GuestProcess> pProcess;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync rc = processCreateExInteral(procInfo, pProcess);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (RT_SUCCESS(rc))
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /* Return guest session to the caller. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync HRESULT hr2 = pProcess.queryInterfaceTo(aProcess);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (FAILED(hr2))
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync rc = VERR_COM_OBJECT_NOT_FOUND;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (RT_SUCCESS(rc))
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync rc = pProcess->i_startProcessAsync();
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync }
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (RT_FAILURE(rc))
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync switch (rc)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync case VERR_MAX_PROCS_REACHED:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of concurrent guest processes per session (%ld) reached"),
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync VBOX_GUESTCTRL_MAX_OBJECTS);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync break;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /** @todo Add more errors here. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync default:
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest process, rc=%Rrc"), rc);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync break;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync }
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync }
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync LogFlowFuncLeaveRC(rc);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncSTDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlowThisFunc(("PID=%RU32\n", aPID));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync CheckComArgOutPointerValid(aProcess);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (aPID == 0)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync HRESULT hr = S_OK;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync ComObjPtr<GuestProcess> pProcess;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync int rc = processGetByPID(aPID, &pProcess);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (RT_FAILURE(rc))
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPID);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /* This will set (*aProcess) to NULL if pProgress is NULL. */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync HRESULT hr2 = pProcess.queryInterfaceTo(aProcess);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (SUCCEEDED(hr))
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync hr = hr2;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", *aProcess, hr));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsyncSTDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncSTDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowThisFuncEnter();
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AutoCaller autoCaller(this);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ReturnComNotImplemented();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncSTDMETHODIMP GuestSession::WaitFor(ULONG aWaitFlags, ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync ReturnComNotImplemented();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#else
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlowThisFuncEnter();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync CheckComArgOutPointerValid(aReason);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AutoCaller autoCaller(this);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Note: Do not hold any locks here while waiting!
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync HRESULT hr = S_OK;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync int guestRc; GuestSessionWaitResult_T waitResult;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync int vrc = waitFor(aWaitFlags, aTimeoutMS, waitResult, &guestRc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (RT_SUCCESS(vrc))
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *aReason = waitResult;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync else
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync switch (vrc)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case VERR_GSTCTL_GUEST_ERROR:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync hr = GuestSession::setErrorExternal(this, guestRc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case VERR_TIMEOUT:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *aReason = GuestSessionWaitResult_Timeout;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync default:
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync const char *pszSessionName = mData.mSession.mName.c_str();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync hr = setError(VBOX_E_IPRT_ERROR,
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync tr("Waiting for guest session \"%s\" failed: %Rrc"),
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pszSessionName ? pszSessionName : tr("Unnamed"), vrc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlowFuncLeaveRC(vrc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return hr;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncSTDMETHODIMP GuestSession::WaitForArray(ComSafeArrayIn(GuestSessionWaitForFlag_T, aFlags), ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#ifndef VBOX_WITH_GUEST_CONTROL
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync ReturnComNotImplemented();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#else
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlowThisFuncEnter();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync CheckComArgOutPointerValid(aReason);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AutoCaller autoCaller(this);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Note: Do not hold any locks here while waiting!
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync uint32_t fWaitFor = GuestSessionWaitForFlag_None;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync com::SafeArray<GuestSessionWaitForFlag_T> flags(ComSafeArrayInArg(aFlags));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync for (size_t i = 0; i < flags.size(); i++)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync fWaitFor |= flags[i];
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return WaitFor(fWaitFor, aTimeoutMS, aReason);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync