[9360] | 1 | /* $Id: GuestCtrlImpl.cpp 46526 2013-06-13 12:24:29Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[35170] | 3 | * VirtualBox COM class implementation: Guest
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[45415] | 7 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 | #include "GuestImpl.h"
|
---|
[42354] | 19 | #include "GuestSessionImpl.h"
|
---|
[38085] | 20 | #include "GuestCtrlImplPrivate.h"
|
---|
[9360] | 21 |
|
---|
| 22 | #include "Global.h"
|
---|
[1] | 23 | #include "ConsoleImpl.h"
|
---|
[28132] | 24 | #include "ProgressImpl.h"
|
---|
[45415] | 25 | #include "VBoxEvents.h"
|
---|
[1] | 26 | #include "VMMDev.h"
|
---|
| 27 |
|
---|
[25860] | 28 | #include "AutoCaller.h"
|
---|
[1] | 29 |
|
---|
[21219] | 30 | #include <VBox/VMMDev.h>
|
---|
[27741] | 31 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
| 32 | # include <VBox/com/array.h>
|
---|
[34831] | 33 | # include <VBox/com/ErrorInfo.h>
|
---|
[27741] | 34 | #endif
|
---|
[25346] | 35 | #include <iprt/cpp/utils.h>
|
---|
[33301] | 36 | #include <iprt/file.h>
|
---|
[27767] | 37 | #include <iprt/getopt.h>
|
---|
[33492] | 38 | #include <iprt/isofs.h>
|
---|
[32866] | 39 | #include <iprt/list.h>
|
---|
| 40 | #include <iprt/path.h>
|
---|
[35346] | 41 | #include <VBox/vmm/pgm.h>
|
---|
[1] | 42 |
|
---|
[33494] | 43 | #include <memory>
|
---|
| 44 |
|
---|
[42897] | 45 | #ifdef LOG_GROUP
|
---|
| 46 | #undef LOG_GROUP
|
---|
| 47 | #endif
|
---|
| 48 | #define LOG_GROUP LOG_GROUP_GUEST_CONTROL
|
---|
| 49 | #include <VBox/log.h>
|
---|
| 50 |
|
---|
| 51 |
|
---|
[1] | 52 | // public methods only for internal purposes
|
---|
| 53 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 54 |
|
---|
[28288] | 55 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
[1] | 56 | /**
|
---|
[28286] | 57 | * Static callback function for receiving updates on guest control commands
|
---|
| 58 | * from the guest. Acts as a dispatcher for the actual class instance.
|
---|
[28233] | 59 | *
|
---|
| 60 | * @returns VBox status code.
|
---|
| 61 | *
|
---|
| 62 | * @todo
|
---|
| 63 | *
|
---|
| 64 | */
|
---|
[42864] | 65 | /* static */
|
---|
[37589] | 66 | DECLCALLBACK(int) Guest::notifyCtrlDispatcher(void *pvExtension,
|
---|
| 67 | uint32_t u32Function,
|
---|
[44863] | 68 | void *pvData,
|
---|
| 69 | uint32_t cbData)
|
---|
[28206] | 70 | {
|
---|
| 71 | using namespace guestControl;
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | * No locking, as this is purely a notification which does not make any
|
---|
| 75 | * changes to the object state.
|
---|
| 76 | */
|
---|
[42214] | 77 | LogFlowFunc(("pvExtension=%p, u32Function=%RU32, pvParms=%p, cbParms=%RU32\n",
|
---|
[44863] | 78 | pvExtension, u32Function, pvData, cbData));
|
---|
[28286] | 79 | ComObjPtr<Guest> pGuest = reinterpret_cast<Guest *>(pvExtension);
|
---|
[42214] | 80 | Assert(!pGuest.isNull());
|
---|
[28206] | 81 |
|
---|
[42214] | 82 | /*
|
---|
| 83 | * For guest control 2.0 using the legacy commands we need to do the following here:
|
---|
| 84 | * - Get the callback header to access the context ID
|
---|
| 85 | * - Get the context ID of the callback
|
---|
| 86 | * - Extract the session ID out of the context ID
|
---|
| 87 | * - Dispatch the whole stuff to the appropriate session (if still exists)
|
---|
| 88 | */
|
---|
[44863] | 89 | if (cbData != sizeof(VBOXGUESTCTRLHOSTCALLBACK))
|
---|
| 90 | return VERR_NOT_SUPPORTED;
|
---|
| 91 | PVBOXGUESTCTRLHOSTCALLBACK pSvcCb = (PVBOXGUESTCTRLHOSTCALLBACK)pvData;
|
---|
| 92 | AssertPtr(pSvcCb);
|
---|
[42214] | 93 |
|
---|
[44863] | 94 | if (!pSvcCb->mParms) /* At least context ID must be present. */
|
---|
| 95 | return VERR_INVALID_PARAMETER;
|
---|
[42214] | 96 |
|
---|
[44863] | 97 | uint32_t uContextID;
|
---|
| 98 | int rc = pSvcCb->mpaParms[0].getUInt32(&uContextID);
|
---|
| 99 | AssertMsgRC(rc, ("Unable to extract callback context ID, pvData=%p\n", pSvcCb));
|
---|
| 100 | if (RT_FAILURE(rc))
|
---|
| 101 | return rc;
|
---|
[42272] | 102 | #ifdef DEBUG
|
---|
[42897] | 103 | LogFlowFunc(("CID=%RU32, uSession=%RU32, uObject=%RU32, uCount=%RU32\n",
|
---|
[44863] | 104 | uContextID,
|
---|
| 105 | VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID),
|
---|
| 106 | VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID),
|
---|
| 107 | VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID)));
|
---|
[42272] | 108 | #endif
|
---|
[42214] | 109 |
|
---|
[44863] | 110 | VBOXGUESTCTRLHOSTCBCTX ctxCb = { u32Function, uContextID };
|
---|
| 111 | rc = pGuest->dispatchToSession(&ctxCb, pSvcCb);
|
---|
[42354] | 112 | LogFlowFuncLeaveRC(rc);
|
---|
[28286] | 113 | return rc;
|
---|
| 114 | }
|
---|
[38290] | 115 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
[35455] | 116 |
|
---|
[46526] | 117 | STDMETHODIMP Guest::UpdateGuestAdditions(IN_BSTR aSource, ComSafeArrayIn(IN_BSTR, aArguments),
|
---|
| 118 | ComSafeArrayIn(AdditionsUpdateFlag_T, aFlags), IProgress **aProgress)
|
---|
[33492] | 119 | {
|
---|
| 120 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 121 | ReturnComNotImplemented();
|
---|
| 122 | #else /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 123 | CheckComArgStrNotEmptyOrNull(aSource);
|
---|
| 124 | CheckComArgOutPointerValid(aProgress);
|
---|
| 125 |
|
---|
| 126 | AutoCaller autoCaller(this);
|
---|
| 127 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 128 |
|
---|
[34398] | 129 | /* Validate flags. */
|
---|
[42693] | 130 | uint32_t fFlags = AdditionsUpdateFlag_None;
|
---|
[34398] | 131 | if (aFlags)
|
---|
| 132 | {
|
---|
[42693] | 133 | com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 134 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 135 | fFlags |= flags[i];
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | if (fFlags)
|
---|
| 139 | {
|
---|
| 140 | if (!(fFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly))
|
---|
[34398] | 141 | return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), aFlags);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[46524] | 144 | int rc = VINF_SUCCESS;
|
---|
| 145 |
|
---|
| 146 | ProcessArguments aArgs;
|
---|
| 147 | if (aArguments)
|
---|
| 148 | {
|
---|
| 149 | try
|
---|
| 150 | {
|
---|
| 151 | com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
|
---|
| 152 | for (size_t i = 0; i < arguments.size(); i++)
|
---|
| 153 | aArgs.push_back(Utf8Str(arguments[i]));
|
---|
| 154 | }
|
---|
| 155 | catch(std::bad_alloc &)
|
---|
| 156 | {
|
---|
| 157 | rc = VERR_NO_MEMORY;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[42693] | 161 | HRESULT hr = S_OK;
|
---|
[42864] | 162 |
|
---|
[44935] | 163 | /*
|
---|
| 164 | * Create an anonymous session. This is required to run the Guest Additions
|
---|
| 165 | * update process with administrative rights.
|
---|
| 166 | */
|
---|
| 167 | GuestSessionStartupInfo startupInfo;
|
---|
| 168 | startupInfo.mName = "Updating Guest Additions";
|
---|
| 169 |
|
---|
| 170 | GuestCredentials guestCreds;
|
---|
| 171 | RT_ZERO(guestCreds);
|
---|
| 172 |
|
---|
[42693] | 173 | ComObjPtr<GuestSession> pSession;
|
---|
[46524] | 174 | if (RT_SUCCESS(rc))
|
---|
| 175 | rc = sessionCreate(startupInfo, guestCreds, pSession);
|
---|
[42693] | 176 | if (RT_FAILURE(rc))
|
---|
| 177 | {
|
---|
| 178 | switch (rc)
|
---|
| 179 | {
|
---|
| 180 | case VERR_MAX_PROCS_REACHED:
|
---|
[45415] | 181 | hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of concurrent guest sessions (%ld) reached"),
|
---|
[42693] | 182 | VBOX_GUESTCTRL_MAX_SESSIONS);
|
---|
| 183 | break;
|
---|
[33492] | 184 |
|
---|
[42693] | 185 | /** @todo Add more errors here. */
|
---|
| 186 |
|
---|
| 187 | default:
|
---|
| 188 | hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest session: %Rrc"), rc);
|
---|
| 189 | break;
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | else
|
---|
| 193 | {
|
---|
[42702] | 194 | Assert(!pSession.isNull());
|
---|
[44935] | 195 | int guestRc;
|
---|
[45010] | 196 | rc = pSession->startSessionIntenal(&guestRc);
|
---|
[42693] | 197 | if (RT_FAILURE(rc))
|
---|
| 198 | {
|
---|
[44935] | 199 | /** @todo Handle guestRc! */
|
---|
| 200 |
|
---|
| 201 | hr = setError(VBOX_E_IPRT_ERROR, tr("Could not open guest session: %Rrc"), rc);
|
---|
[42693] | 202 | }
|
---|
| 203 | else
|
---|
| 204 | {
|
---|
[43170] | 205 | try
|
---|
[42693] | 206 | {
|
---|
[43170] | 207 | ComObjPtr<Progress> pProgress;
|
---|
| 208 | SessionTaskUpdateAdditions *pTask = new SessionTaskUpdateAdditions(pSession /* GuestSession */,
|
---|
[46524] | 209 | Utf8Str(aSource), aArgs, fFlags);
|
---|
[43170] | 210 | rc = pSession->startTaskAsync(tr("Updating Guest Additions"), pTask, pProgress);
|
---|
| 211 | if (RT_SUCCESS(rc))
|
---|
| 212 | {
|
---|
| 213 | /* Return progress to the caller. */
|
---|
| 214 | hr = pProgress.queryInterfaceTo(aProgress);
|
---|
| 215 | }
|
---|
| 216 | else
|
---|
| 217 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 218 | tr("Starting task for updating Guest Additions on the guest failed: %Rrc"), rc);
|
---|
[42693] | 219 | }
|
---|
[43170] | 220 | catch(std::bad_alloc &)
|
---|
| 221 | {
|
---|
| 222 | hr = E_OUTOFMEMORY;
|
---|
| 223 | }
|
---|
[42693] | 224 | }
|
---|
| 225 | }
|
---|
[42695] | 226 | return hr;
|
---|
[33492] | 227 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 228 | }
|
---|
[37375] | 229 |
|
---|
[42105] | 230 | // private methods
|
---|
| 231 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 232 |
|
---|
[44863] | 233 | int Guest::dispatchToSession(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[42214] | 234 | {
|
---|
[44863] | 235 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
[42272] | 236 |
|
---|
[44863] | 237 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 238 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 239 |
|
---|
[44935] | 240 | LogFlowFunc(("uFunction=%RU32, uContextID=%RU32, uProtocol=%RU32\n",
|
---|
| 241 | pCtxCb->uFunction, pCtxCb->uContextID, pCtxCb->uProtocol));
|
---|
| 242 |
|
---|
[42214] | 243 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 244 |
|
---|
[44863] | 245 | uint32_t uSessionID = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtxCb->uContextID);
|
---|
[42436] | 246 | #ifdef DEBUG
|
---|
[44863] | 247 | LogFlowFunc(("uSessionID=%RU32 (%zu total)\n",
|
---|
[42436] | 248 | uSessionID, mData.mGuestSessions.size()));
|
---|
| 249 | #endif
|
---|
[42214] | 250 | GuestSessions::const_iterator itSession
|
---|
[42436] | 251 | = mData.mGuestSessions.find(uSessionID);
|
---|
[44863] | 252 |
|
---|
| 253 | int rc;
|
---|
[42214] | 254 | if (itSession != mData.mGuestSessions.end())
|
---|
| 255 | {
|
---|
| 256 | ComObjPtr<GuestSession> pSession(itSession->second);
|
---|
| 257 | Assert(!pSession.isNull());
|
---|
| 258 |
|
---|
| 259 | alock.release();
|
---|
[44863] | 260 |
|
---|
| 261 | bool fDispatch = true;
|
---|
| 262 | #ifdef DEBUG
|
---|
| 263 | /*
|
---|
| 264 | * Pre-check: If we got a status message with an error and VERR_TOO_MUCH_DATA
|
---|
| 265 | * it means that that guest could not handle the entire message
|
---|
| 266 | * because of its exceeding size. This should not happen on daily
|
---|
| 267 | * use but testcases might try this. It then makes no sense to dispatch
|
---|
| 268 | * this further because we don't have a valid context ID.
|
---|
| 269 | */
|
---|
| 270 | if ( pCtxCb->uFunction == GUEST_EXEC_STATUS
|
---|
| 271 | && pSvcCb->mParms >= 5)
|
---|
| 272 | {
|
---|
| 273 | CALLBACKDATA_PROC_STATUS dataCb;
|
---|
| 274 | /* pSvcCb->mpaParms[0] always contains the context ID. */
|
---|
| 275 | pSvcCb->mpaParms[1].getUInt32(&dataCb.uPID);
|
---|
| 276 | pSvcCb->mpaParms[2].getUInt32(&dataCb.uStatus);
|
---|
| 277 | pSvcCb->mpaParms[3].getUInt32(&dataCb.uFlags);
|
---|
| 278 | pSvcCb->mpaParms[4].getPointer(&dataCb.pvData, &dataCb.cbData);
|
---|
| 279 |
|
---|
| 280 | if ( (dataCb.uStatus == PROC_STS_ERROR)
|
---|
| 281 | && (dataCb.uFlags == VERR_TOO_MUCH_DATA))
|
---|
| 282 | {
|
---|
| 283 | LogFlowFunc(("Requested command with too much data, skipping dispatching ...\n"));
|
---|
| 284 |
|
---|
| 285 | Assert(dataCb.uPID == 0);
|
---|
| 286 | fDispatch = false;
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 | #endif
|
---|
| 290 | if (fDispatch)
|
---|
| 291 | {
|
---|
| 292 | switch (pCtxCb->uFunction)
|
---|
| 293 | {
|
---|
| 294 | case GUEST_DISCONNECTED:
|
---|
[44935] | 295 | rc = pSession->dispatchToThis(pCtxCb, pSvcCb);
|
---|
| 296 | break;
|
---|
[44863] | 297 |
|
---|
| 298 | case GUEST_SESSION_NOTIFY:
|
---|
| 299 | rc = pSession->dispatchToThis(pCtxCb, pSvcCb);
|
---|
| 300 | break;
|
---|
| 301 |
|
---|
| 302 | case GUEST_EXEC_STATUS:
|
---|
| 303 | case GUEST_EXEC_OUTPUT:
|
---|
| 304 | case GUEST_EXEC_INPUT_STATUS:
|
---|
| 305 | case GUEST_EXEC_IO_NOTIFY:
|
---|
| 306 | rc = pSession->dispatchToProcess(pCtxCb, pSvcCb);
|
---|
| 307 | break;
|
---|
| 308 |
|
---|
| 309 | case GUEST_FILE_NOTIFY:
|
---|
| 310 | rc = pSession->dispatchToFile(pCtxCb, pSvcCb);
|
---|
| 311 | break;
|
---|
| 312 |
|
---|
| 313 | default:
|
---|
| 314 | rc = VERR_NOT_SUPPORTED;
|
---|
| 315 | break;
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | else
|
---|
| 319 | rc = VERR_NOT_FOUND;
|
---|
[42214] | 320 | }
|
---|
[42272] | 321 | else
|
---|
| 322 | rc = VERR_NOT_FOUND;
|
---|
| 323 |
|
---|
| 324 | LogFlowFuncLeaveRC(rc);
|
---|
| 325 | return rc;
|
---|
[42214] | 326 | }
|
---|
| 327 |
|
---|
[42897] | 328 | int Guest::sessionRemove(GuestSession *pSession)
|
---|
[42084] | 329 | {
|
---|
[42897] | 330 | LogFlowThisFuncEnter();
|
---|
| 331 |
|
---|
[42105] | 332 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 333 |
|
---|
[42897] | 334 | int rc = VERR_NOT_FOUND;
|
---|
| 335 |
|
---|
| 336 | LogFlowFunc(("Closing session (ID=%RU32) ...\n", pSession->getId()));
|
---|
| 337 |
|
---|
[45415] | 338 | GuestSessions::iterator itSessions = mData.mGuestSessions.begin();
|
---|
| 339 | while (itSessions != mData.mGuestSessions.end())
|
---|
[42105] | 340 | {
|
---|
[42160] | 341 | if (pSession == itSessions->second)
|
---|
[42105] | 342 | {
|
---|
[42897] | 343 | LogFlowFunc(("Removing session (pSession=%p, ID=%RU32) (now total %ld sessions)\n",
|
---|
[42919] | 344 | (GuestSession *)itSessions->second, itSessions->second->getId(), mData.mGuestSessions.size() - 1));
|
---|
[42897] | 345 |
|
---|
[45415] | 346 | mData.mGuestSessions.erase(itSessions);
|
---|
[42897] | 347 |
|
---|
[45415] | 348 | fireGuestSessionRegisteredEvent(mEventSource, pSession,
|
---|
| 349 | false /* Unregistered */);
|
---|
[42897] | 350 | rc = VINF_SUCCESS;
|
---|
| 351 | break;
|
---|
[42105] | 352 | }
|
---|
[45415] | 353 |
|
---|
| 354 | itSessions++;
|
---|
[42105] | 355 | }
|
---|
| 356 |
|
---|
[42897] | 357 | LogFlowFuncLeaveRC(rc);
|
---|
| 358 | return rc;
|
---|
[42105] | 359 | }
|
---|
| 360 |
|
---|
[44935] | 361 | int Guest::sessionCreate(const GuestSessionStartupInfo &ssInfo,
|
---|
| 362 | const GuestCredentials &guestCreds, ComObjPtr<GuestSession> &pGuestSession)
|
---|
[42160] | 363 | {
|
---|
| 364 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 365 |
|
---|
| 366 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
[42272] | 367 | if (mData.mGuestSessions.size() >= VBOX_GUESTCTRL_MAX_SESSIONS)
|
---|
| 368 | return rc;
|
---|
| 369 |
|
---|
[42160] | 370 | try
|
---|
| 371 | {
|
---|
| 372 | /* Create a new session ID and assign it. */
|
---|
| 373 | uint32_t uNewSessionID = 0;
|
---|
| 374 | uint32_t uTries = 0;
|
---|
| 375 |
|
---|
| 376 | for (;;)
|
---|
| 377 | {
|
---|
[42272] | 378 | /* Is the context ID already used? */
|
---|
| 379 | if (!sessionExists(uNewSessionID))
|
---|
[42160] | 380 | {
|
---|
| 381 | rc = VINF_SUCCESS;
|
---|
| 382 | break;
|
---|
| 383 | }
|
---|
[42272] | 384 | uNewSessionID++;
|
---|
[42634] | 385 | if (uNewSessionID >= VBOX_GUESTCTRL_MAX_SESSIONS)
|
---|
| 386 | uNewSessionID = 0;
|
---|
[42160] | 387 |
|
---|
[44935] | 388 | if (++uTries == VBOX_GUESTCTRL_MAX_SESSIONS)
|
---|
[42160] | 389 | break; /* Don't try too hard. */
|
---|
| 390 | }
|
---|
| 391 | if (RT_FAILURE(rc)) throw rc;
|
---|
| 392 |
|
---|
| 393 | /* Create the session object. */
|
---|
| 394 | HRESULT hr = pGuestSession.createObject();
|
---|
| 395 | if (FAILED(hr)) throw VERR_COM_UNEXPECTED;
|
---|
| 396 |
|
---|
[44935] | 397 | /** @todo Use an overloaded copy operator. Later. */
|
---|
| 398 | GuestSessionStartupInfo startupInfo;
|
---|
| 399 | startupInfo.mID = uNewSessionID; /* Assign new session ID. */
|
---|
| 400 | startupInfo.mName = ssInfo.mName;
|
---|
| 401 | startupInfo.mOpenFlags = ssInfo.mOpenFlags;
|
---|
| 402 | startupInfo.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
|
---|
| 403 |
|
---|
| 404 | GuestCredentials guestCredentials;
|
---|
| 405 | if (!guestCreds.mUser.isEmpty())
|
---|
| 406 | {
|
---|
| 407 | /** @todo Use an overloaded copy operator. Later. */
|
---|
| 408 | guestCredentials.mUser = guestCreds.mUser;
|
---|
| 409 | guestCredentials.mPassword = guestCreds.mPassword;
|
---|
| 410 | guestCredentials.mDomain = guestCreds.mDomain;
|
---|
| 411 | }
|
---|
| 412 | else
|
---|
| 413 | {
|
---|
| 414 | /* Internal (annonymous) session. */
|
---|
| 415 | startupInfo.mIsInternal = true;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | rc = pGuestSession->init(this, startupInfo, guestCredentials);
|
---|
[44863] | 419 | if (RT_FAILURE(rc)) throw rc;
|
---|
[42160] | 420 |
|
---|
[44863] | 421 | /*
|
---|
| 422 | * Add session object to our session map. This is necessary
|
---|
| 423 | * before calling openSession because the guest calls back
|
---|
[45415] | 424 | * with the creation result of this session.
|
---|
[44863] | 425 | */
|
---|
[42194] | 426 | mData.mGuestSessions[uNewSessionID] = pGuestSession;
|
---|
[42436] | 427 |
|
---|
[45415] | 428 | fireGuestSessionRegisteredEvent(mEventSource, pGuestSession,
|
---|
| 429 | true /* Registered */);
|
---|
[42160] | 430 | }
|
---|
| 431 | catch (int rc2)
|
---|
| 432 | {
|
---|
| 433 | rc = rc2;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
[44863] | 436 | LogFlowFuncLeaveRC(rc);
|
---|
[42160] | 437 | return rc;
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | inline bool Guest::sessionExists(uint32_t uSessionID)
|
---|
| 441 | {
|
---|
| 442 | GuestSessions::const_iterator itSessions = mData.mGuestSessions.find(uSessionID);
|
---|
| 443 | return (itSessions == mData.mGuestSessions.end()) ? false : true;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
[42105] | 446 | // implementation of public methods
|
---|
| 447 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 448 |
|
---|
| 449 | STDMETHODIMP Guest::CreateSession(IN_BSTR aUser, IN_BSTR aPassword, IN_BSTR aDomain, IN_BSTR aSessionName, IGuestSession **aGuestSession)
|
---|
| 450 | {
|
---|
[42084] | 451 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 452 | ReturnComNotImplemented();
|
---|
| 453 | #else /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 454 |
|
---|
[42214] | 455 | LogFlowFuncEnter();
|
---|
| 456 |
|
---|
[44935] | 457 | /* Do not allow anonymous sessions (with system rights) with public API. */
|
---|
[42084] | 458 | if (RT_UNLIKELY((aUser) == NULL || *(aUser) == '\0'))
|
---|
| 459 | return setError(E_INVALIDARG, tr("No user name specified"));
|
---|
[42105] | 460 | CheckComArgOutPointerValid(aGuestSession);
|
---|
[42214] | 461 | /* Rest is optional. */
|
---|
[42084] | 462 |
|
---|
| 463 | AutoCaller autoCaller(this);
|
---|
| 464 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 465 |
|
---|
[44935] | 466 | GuestSessionStartupInfo startupInfo;
|
---|
| 467 | startupInfo.mName = aSessionName;
|
---|
[42214] | 468 |
|
---|
[44935] | 469 | GuestCredentials guestCreds;
|
---|
| 470 | guestCreds.mUser = aUser;
|
---|
| 471 | guestCreds.mPassword = aPassword;
|
---|
| 472 | guestCreds.mDomain = aDomain;
|
---|
| 473 |
|
---|
[42354] | 474 | ComObjPtr<GuestSession> pSession;
|
---|
[44935] | 475 | int rc = sessionCreate(startupInfo, guestCreds, pSession);
|
---|
[42354] | 476 | if (RT_SUCCESS(rc))
|
---|
| 477 | {
|
---|
| 478 | /* Return guest session to the caller. */
|
---|
| 479 | HRESULT hr2 = pSession.queryInterfaceTo(aGuestSession);
|
---|
| 480 | if (FAILED(hr2))
|
---|
| 481 | rc = VERR_COM_OBJECT_NOT_FOUND;
|
---|
| 482 | }
|
---|
[42214] | 483 |
|
---|
[44935] | 484 | if (RT_SUCCESS(rc))
|
---|
| 485 | {
|
---|
[45415] | 486 | /* Start (fork) the session asynchronously
|
---|
| 487 | * on the guest. */
|
---|
| 488 | rc = pSession->startSessionAsync();
|
---|
[44935] | 489 | }
|
---|
| 490 |
|
---|
| 491 | HRESULT hr = S_OK;
|
---|
| 492 |
|
---|
[42354] | 493 | if (RT_FAILURE(rc))
|
---|
| 494 | {
|
---|
| 495 | switch (rc)
|
---|
| 496 | {
|
---|
| 497 | case VERR_MAX_PROCS_REACHED:
|
---|
[45415] | 498 | hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of concurrent guest sessions (%ld) reached"),
|
---|
[42436] | 499 | VBOX_GUESTCTRL_MAX_SESSIONS);
|
---|
[42354] | 500 | break;
|
---|
| 501 |
|
---|
| 502 | /** @todo Add more errors here. */
|
---|
| 503 |
|
---|
[44935] | 504 | default:
|
---|
| 505 | hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest session: %Rrc"), rc);
|
---|
[42354] | 506 | break;
|
---|
| 507 | }
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | LogFlowFuncLeaveRC(rc);
|
---|
[42214] | 511 | return hr;
|
---|
[42084] | 512 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 513 | }
|
---|
| 514 |
|
---|
[42411] | 515 | STDMETHODIMP Guest::FindSession(IN_BSTR aSessionName, ComSafeArrayOut(IGuestSession *, aSessions))
|
---|
| 516 | {
|
---|
[42546] | 517 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
[42411] | 518 | ReturnComNotImplemented();
|
---|
[42546] | 519 | #else /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 520 |
|
---|
| 521 | CheckComArgOutSafeArrayPointerValid(aSessions);
|
---|
| 522 |
|
---|
| 523 | LogFlowFuncEnter();
|
---|
| 524 |
|
---|
| 525 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 526 |
|
---|
| 527 | Utf8Str strName(aSessionName);
|
---|
| 528 | std::list < ComObjPtr<GuestSession> > listSessions;
|
---|
| 529 |
|
---|
| 530 | GuestSessions::const_iterator itSessions = mData.mGuestSessions.begin();
|
---|
| 531 | while (itSessions != mData.mGuestSessions.end())
|
---|
| 532 | {
|
---|
[42566] | 533 | if (strName.contains(itSessions->second->getName())) /** @todo Use a (simple) pattern match (IPRT?). */
|
---|
[42546] | 534 | listSessions.push_back(itSessions->second);
|
---|
| 535 | itSessions++;
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | LogFlowFunc(("Sessions with \"%ls\" = %RU32\n",
|
---|
| 539 | aSessionName, listSessions.size()));
|
---|
| 540 |
|
---|
| 541 | if (listSessions.size())
|
---|
| 542 | {
|
---|
| 543 | SafeIfaceArray<IGuestSession> sessionIfacs(listSessions);
|
---|
| 544 | sessionIfacs.detachTo(ComSafeArrayOutArg(aSessions));
|
---|
| 545 |
|
---|
| 546 | return S_OK;
|
---|
| 547 | }
|
---|
| 548 |
|
---|
| 549 | return setErrorNoLog(VBOX_E_OBJECT_NOT_FOUND,
|
---|
| 550 | tr("Could not find sessions with name '%ls'"),
|
---|
| 551 | aSessionName);
|
---|
| 552 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
[42411] | 553 | }
|
---|
| 554 |
|
---|