4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* $Id$ */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** @file
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync * VBoxManage - Implementation of the controlvm command.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/*
f6b53aa7a361c1f26a3287a95172653219470233vboxsync * Copyright (C) 2006-2015 Oracle Corporation
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * available from http://www.virtualbox.org. This file is free software;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * you can redistribute it and/or modify it under the terms of the GNU
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * General Public License (GPL) as published by the Free Software
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/*******************************************************************************
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync* Header Files *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*******************************************************************************/
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/com.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/string.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/Guid.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/array.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/ErrorInfo.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/errorprint.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/com/VirtualBox.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/ctype.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/err.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/getopt.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/stream.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/string.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/uuid.h>
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync#include <iprt/file.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/log.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include "VBoxManage.h"
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#include <list>
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/**
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Parses a number.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * @returns Valid number on success.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @returns 0 if invalid number. All necessary bitching has been done.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * @param psz Pointer to the nic number.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncstatic unsigned parseNum(const char *psz, unsigned cMaxNum, const char *name)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t u32;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync char *pszNext;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int rc = RTStrToUInt32Ex(psz, &pszNext, 10, &u32);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ( RT_SUCCESS(rc)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && *pszNext == '\0'
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && u32 >= 1
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && u32 <= cMaxNum)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return (unsigned)u32;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid %s number '%s'", name, psz);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
376b92d26cc4fad78e813cf33afcc0784adc9b19vboxsyncunsigned int getMaxNics(IVirtualBox* vbox, IMachine* mach)
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync{
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<ISystemProperties> info;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ChipsetType_T aChipset;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ULONG NetworkAdapterCount = 0;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync HRESULT rc;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync do {
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync CHECK_ERROR_BREAK(vbox, COMGETTER(SystemProperties)(info.asOutParam()));
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync CHECK_ERROR_BREAK(mach, COMGETTER(ChipsetType)(&aChipset));
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync CHECK_ERROR_BREAK(info, GetMaxNetworkAdapters(aChipset, &NetworkAdapterCount));
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
376b92d26cc4fad78e813cf33afcc0784adc9b19vboxsync return (unsigned int)NetworkAdapterCount;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync } while (0);
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync return 0;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync}
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncint handleControlVM(HandlerArg *a)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync using namespace com;
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync bool fNeedsSaving = false;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync HRESULT rc;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc < 2)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return errorSyntax(USAGE_CONTROLVM, "Not enough parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* try to find the given machine */
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<IMachine> machine;
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync machine.asOutParam()));
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return 1;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* open a session for the VM */
f409459bdd4c15cdb8d7fb6c6d54338cce9ac814vboxsync CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync ComPtr<IConsole> console;
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync ComPtr<IMachine> sessionMachine;
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync do
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the associated console */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* ... and session machine */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* which command? */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[1], "pause"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, Pause());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "resume"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, Resume());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "reset"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, Reset());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync else if (!strcmp(a->argv[1], "unplugcpu"))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if (a->argc <= 1 + 1)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync errorArgument("Missing argument to '%s'. Expected CPU number.", a->argv[1]);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync rc = E_FAIL;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync break;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync unsigned n = parseNum(a->argv[2], 32, "CPU");
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(sessionMachine, HotUnplugCPU(n));
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync else if (!strcmp(a->argv[1], "plugcpu"))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if (a->argc <= 1 + 1)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync errorArgument("Missing argument to '%s'. Expected CPU number.", a->argv[1]);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync rc = E_FAIL;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync break;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync unsigned n = parseNum(a->argv[2], 32, "CPU");
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(sessionMachine, HotPlugCPU(n));
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync else if (!strcmp(a->argv[1], "cpuexecutioncap"))
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync {
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync if (a->argc <= 1 + 1)
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync {
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync errorArgument("Missing argument to '%s'. Expected execution cap number.", a->argv[1]);
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync rc = E_FAIL;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync }
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync unsigned n = parseNum(a->argv[2], 100, "ExecutionCap");
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync
9cb702c3a5fd2287c57c7c1e98a61ba9e357b4devboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(CPUExecutionCap)(n));
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync }
6fe1329154975472e055284198df7fa8e64dee3avboxsync else if (!strcmp(a->argv[1], "clipboard"))
6fe1329154975472e055284198df7fa8e64dee3avboxsync {
6fe1329154975472e055284198df7fa8e64dee3avboxsync if (a->argc <= 1 + 1)
6fe1329154975472e055284198df7fa8e64dee3avboxsync {
6fe1329154975472e055284198df7fa8e64dee3avboxsync errorArgument("Missing argument to '%s'. Expected clipboard mode.", a->argv[1]);
6fe1329154975472e055284198df7fa8e64dee3avboxsync rc = E_FAIL;
6fe1329154975472e055284198df7fa8e64dee3avboxsync break;
6fe1329154975472e055284198df7fa8e64dee3avboxsync }
6fe1329154975472e055284198df7fa8e64dee3avboxsync
6fe1329154975472e055284198df7fa8e64dee3avboxsync ClipboardMode_T mode;
6fe1329154975472e055284198df7fa8e64dee3avboxsync if (!strcmp(a->argv[2], "disabled"))
6fe1329154975472e055284198df7fa8e64dee3avboxsync mode = ClipboardMode_Disabled;
6fe1329154975472e055284198df7fa8e64dee3avboxsync else if (!strcmp(a->argv[2], "hosttoguest"))
6fe1329154975472e055284198df7fa8e64dee3avboxsync mode = ClipboardMode_HostToGuest;
6fe1329154975472e055284198df7fa8e64dee3avboxsync else if (!strcmp(a->argv[2], "guesttohost"))
6fe1329154975472e055284198df7fa8e64dee3avboxsync mode = ClipboardMode_GuestToHost;
6fe1329154975472e055284198df7fa8e64dee3avboxsync else if (!strcmp(a->argv[2], "bidirectional"))
6fe1329154975472e055284198df7fa8e64dee3avboxsync mode = ClipboardMode_Bidirectional;
6fe1329154975472e055284198df7fa8e64dee3avboxsync else
6fe1329154975472e055284198df7fa8e64dee3avboxsync {
6fe1329154975472e055284198df7fa8e64dee3avboxsync errorArgument("Invalid '%s' argument '%s'.", a->argv[1], a->argv[2]);
6fe1329154975472e055284198df7fa8e64dee3avboxsync rc = E_FAIL;
6fe1329154975472e055284198df7fa8e64dee3avboxsync }
6fe1329154975472e055284198df7fa8e64dee3avboxsync if (SUCCEEDED(rc))
6fe1329154975472e055284198df7fa8e64dee3avboxsync {
6fe1329154975472e055284198df7fa8e64dee3avboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(ClipboardMode)(mode));
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
6fe1329154975472e055284198df7fa8e64dee3avboxsync }
6fe1329154975472e055284198df7fa8e64dee3avboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync else if (!strcmp(a->argv[1], "draganddrop"))
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync if (a->argc <= 1 + 1)
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
1a3b02207c6b6aca1b7bdd50fc2e79defe4e405evboxsync errorArgument("Missing argument to '%s'. Expected drag and drop mode.", a->argv[1]);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync rc = E_FAIL;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync break;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDMode_T mode;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync if (!strcmp(a->argv[2], "disabled"))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync mode = DnDMode_Disabled;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync else if (!strcmp(a->argv[2], "hosttoguest"))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync mode = DnDMode_HostToGuest;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync else if (!strcmp(a->argv[2], "guesttohost"))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync mode = DnDMode_GuestToHost;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync else if (!strcmp(a->argv[2], "bidirectional"))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync mode = DnDMode_Bidirectional;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync else
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync errorArgument("Invalid '%s' argument '%s'.", a->argv[1], a->argv[2]);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync rc = E_FAIL;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync if (SUCCEEDED(rc))
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(DnDMode)(mode));
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "poweroff"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IProgress> progress;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = showProgress(progress);
ae16af2d7d3c99d359094a7f19f5937efc2e66bdvboxsync CHECK_PROGRESS_ERROR(progress, ("Failed to power off machine"));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "savestate"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync /* first pause so we don't trigger a live save which needs more time/resources */
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync bool fPaused = false;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync rc = console->Pause();
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync if (FAILED(rc))
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync {
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync bool fError = true;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync if (rc == VBOX_E_INVALID_VM_STATE)
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync {
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync /* check if we are already paused */
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync MachineState_T machineState;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync CHECK_ERROR_BREAK(console, COMGETTER(State)(&machineState));
8b7ee9f7ebabcdbf40fececa0d6321d97d5143d8vboxsync /* the error code was lost by the previous instruction */
8b7ee9f7ebabcdbf40fececa0d6321d97d5143d8vboxsync rc = VBOX_E_INVALID_VM_STATE;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync if (machineState != MachineState_Paused)
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync {
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync RTMsgError("Machine in invalid state %d -- %s\n",
31a693ce9a8a9ebbecdcea9f24ce7f912aef4cd1vboxsync machineState, machineStateToName(machineState, false));
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync }
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync else
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync {
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync fError = false;
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync fPaused = true;
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync }
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync }
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync if (fError)
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync break;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync }
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IProgress> progress;
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync CHECK_ERROR(sessionMachine, SaveState(progress.asOutParam()));
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync if (FAILED(rc))
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync {
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync if (!fPaused)
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync console->Resume();
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync break;
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = showProgress(progress);
ae16af2d7d3c99d359094a7f19f5937efc2e66bdvboxsync CHECK_PROGRESS_ERROR(progress, ("Failed to save machine state"));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync {
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync if (!fPaused)
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync console->Resume();
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "acpipowerbutton"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, PowerButton());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "acpisleepbutton"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, SleepButton());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "keyboardputscancode"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
29d55b79593710186ceda5a557fdab1727972175vboxsync ComPtr<IKeyboard> pKeyboard;
29d55b79593710186ceda5a557fdab1727972175vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(pKeyboard.asOutParam()));
29d55b79593710186ceda5a557fdab1727972175vboxsync if (!pKeyboard)
29d55b79593710186ceda5a557fdab1727972175vboxsync {
29d55b79593710186ceda5a557fdab1727972175vboxsync RTMsgError("Guest not running");
29d55b79593710186ceda5a557fdab1727972175vboxsync rc = E_FAIL;
29d55b79593710186ceda5a557fdab1727972175vboxsync break;
29d55b79593710186ceda5a557fdab1727972175vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'. Expected IBM PC AT set 2 keyboard scancode(s) as hex byte(s).", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync std::list<LONG> llScancodes;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Process the command line. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int i;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync for (i = 1 + 1; i < a->argc; i++)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ( RT_C_IS_XDIGIT (a->argv[i][0])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && RT_C_IS_XDIGIT (a->argv[i][1])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && a->argv[i][2] == 0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint8_t u8Scancode;
42aef05f4b27fb393967e581be04be455064c80avboxsync int irc = RTStrToUInt8Ex(a->argv[i], NULL, 16, &u8Scancode);
42aef05f4b27fb393967e581be04be455064c80avboxsync if (RT_FAILURE (irc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTMsgError("Converting '%s' returned %Rrc!", a->argv[i], rc);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync llScancodes.push_back(u8Scancode);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTMsgError("Error: '%s' is not a hex byte!", a->argv[i]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Send scancodes to the VM. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync com::SafeArray<LONG> saScancodes(llScancodes);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ULONG codesStored = 0;
29d55b79593710186ceda5a557fdab1727972175vboxsync CHECK_ERROR_BREAK(pKeyboard, PutScancodes(ComSafeArrayAsInParam(saScancodes),
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync &codesStored));
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (codesStored < saScancodes.size())
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTMsgError("Only %d scancodes were stored", codesStored);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[1], "setlinkstate", 12))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Get the number of network adapters */
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(&a->argv[1][12], NetworkAdapterCount, "NIC");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!n)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the corresponding network adapter */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<INetworkAdapter> adapter;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (adapter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "on"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(adapter, COMSETTER(CableConnected)(TRUE));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "off"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(adapter, COMSETTER(CableConnected)(FALSE));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync errorArgument("Invalid link state '%s'", Utf8Str(a->argv[2]).c_str());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* here the order in which strncmp is called is important
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * cause nictracefile can be very well compared with
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * nictrace and nic and thus everything will always fail
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * if the order is changed
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[1], "nictracefile", 12))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Get the number of network adapters */
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(&a->argv[1][12], NetworkAdapterCount, "NIC");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!n)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 2)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the corresponding network adapter */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<INetworkAdapter> adapter;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (adapter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync BOOL fEnabled;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync adapter->COMGETTER(Enabled)(&fEnabled);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (fEnabled)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argv[2])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_RET(adapter, COMSETTER(TraceFile)(Bstr(a->argv[2]).raw()), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid filename or filename not specified for NIC %lu", n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync RTMsgError("The NIC %d is currently disabled and thus its tracefile can't be changed", n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[1], "nictrace", 8))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Get the number of network adapters */
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(&a->argv[1][8], NetworkAdapterCount, "NIC");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!n)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 2)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the corresponding network adapter */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<INetworkAdapter> adapter;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (adapter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync BOOL fEnabled;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync adapter->COMGETTER(Enabled)(&fEnabled);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (fEnabled)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "on"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(TraceEnabled)(TRUE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "off"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(TraceEnabled)(FALSE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync errorArgument("Invalid nictrace%lu argument '%s'", n, Utf8Str(a->argv[2]).c_str());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync RTMsgError("The NIC %d is currently disabled and thus its trace flag can't be changed", n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4f3d37f3c8ea851c3d57304fac430764b77a84dcvboxsync else if( a->argc > 2
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync && !strncmp(a->argv[1], "natpf", 5))
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync /* Get the number of network adapters */
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync unsigned n = parseNum(&a->argv[1][5], NetworkAdapterCount, "NIC");
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (!n)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync rc = E_FAIL;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync break;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (a->argc <= 2)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync rc = E_FAIL;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync break;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync /* get the corresponding network adapter */
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ComPtr<INetworkAdapter> adapter;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (!adapter)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync rc = E_FAIL;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync break;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
885f154412c8dc99c44809cf0d5b7f07342a455evboxsync ComPtr<INATEngine> engine;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync CHECK_ERROR(adapter, COMGETTER(NATEngine)(engine.asOutParam()));
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (!engine)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync rc = E_FAIL;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync break;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (!strcmp(a->argv[2], "delete"))
4f3d37f3c8ea851c3d57304fac430764b77a84dcvboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (a->argc >= 3)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync CHECK_ERROR(engine, RemoveRedirect(Bstr(a->argv[3]).raw()));
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync else
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync#define ITERATE_TO_NEXT_TERM(ch) \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync do { \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync while (*ch != ',') \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync { \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (*ch == 0) \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync { \
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync return errorSyntax(USAGE_CONTROLVM, \
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync "Missing or invalid argument to '%s'", \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync a->argv[1]); \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync } \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ch++; \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync } \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync *ch = '\0'; \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ch++; \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync } while(0)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strName;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strProto;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strHostIp;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strHostPort;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strGuestIp;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strGuestPort;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *strRaw = RTStrDup(a->argv[2]);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync char *ch = strRaw;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strName = RTStrStrip(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ITERATE_TO_NEXT_TERM(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strProto = RTStrStrip(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ITERATE_TO_NEXT_TERM(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strHostIp = RTStrStrip(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ITERATE_TO_NEXT_TERM(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strHostPort = RTStrStrip(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ITERATE_TO_NEXT_TERM(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strGuestIp = RTStrStrip(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ITERATE_TO_NEXT_TERM(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strGuestPort = RTStrStrip(ch);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync NATProtocol_T proto;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (RTStrICmp(strProto, "udp") == 0)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync proto = NATProtocol_UDP;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync else if (RTStrICmp(strProto, "tcp") == 0)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync proto = NATProtocol_TCP;
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync else
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync {
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync return errorSyntax(USAGE_CONTROLVM,
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync "Wrong rule proto '%s' specified -- only 'udp' and 'tcp' are allowed.",
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync strProto);
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync CHECK_ERROR(engine, AddRedirect(Bstr(strName).raw(), proto, Bstr(strHostIp).raw(),
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync RTStrToUInt16(strHostPort), Bstr(strGuestIp).raw(), RTStrToUInt16(strGuestPort)));
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync#undef ITERATE_TO_NEXT_TERM
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (SUCCEEDED(rc))
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync fNeedsSaving = true;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync else if (!strncmp(a->argv[1], "nicproperty", 11))
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync /* Get the number of network adapters */
885f154412c8dc99c44809cf0d5b7f07342a455evboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync unsigned n = parseNum(&a->argv[1][11], NetworkAdapterCount, "NIC");
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (!n)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync rc = E_FAIL;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync break;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (a->argc <= 2)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync rc = E_FAIL;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync break;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync /* get the corresponding network adapter */
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync ComPtr<INetworkAdapter> adapter;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (adapter)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync BOOL fEnabled;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync adapter->COMGETTER(Enabled)(&fEnabled);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (fEnabled)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync /* Parse 'name=value' */
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync char *pszProperty = RTStrDup(a->argv[2]);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (pszProperty)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync char *pDelimiter = strchr(pszProperty, '=');
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (pDelimiter)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync *pDelimiter = '\0';
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync Bstr bstrName = pszProperty;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync Bstr bstrValue = &pDelimiter[1];
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR(adapter, SetProperty(bstrName.raw(), bstrValue.raw()));
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync if (SUCCEEDED(rc))
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync fNeedsSaving = true;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync else
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync errorArgument("Invalid nicproperty%d argument '%s'", n, a->argv[2]);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync rc = E_FAIL;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync RTStrFree(pszProperty);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync else
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for nicproperty%d '%s'\n", n, a->argv[2]);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync rc = E_FAIL;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (FAILED(rc))
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync break;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync else
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync RTMsgError("The NIC %d is currently disabled and thus its properties can't be changed", n);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync else if (!strncmp(a->argv[1], "nicpromisc", 10))
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync {
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync /* Get the number of network adapters */
885f154412c8dc99c44809cf0d5b7f07342a455evboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync unsigned n = parseNum(&a->argv[1][10], NetworkAdapterCount, "NIC");
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync if (!n)
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync {
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync rc = E_FAIL;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync break;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync }
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync if (a->argc <= 2)
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync {
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync rc = E_FAIL;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync break;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync }
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync /* get the corresponding network adapter */
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync ComPtr<INetworkAdapter> adapter;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync if (adapter)
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync {
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync BOOL fEnabled;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync adapter->COMGETTER(Enabled)(&fEnabled);
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync if (fEnabled)
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync {
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync if (!strcmp(a->argv[2], "deny"))
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync else if ( !strcmp(a->argv[2], "allow-vms")
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync || !strcmp(a->argv[2], "allow-network"))
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync else if (!strcmp(a->argv[2], "allow-all"))
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync else
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync {
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync errorArgument("Unknown promiscuous mode policy '%s'", a->argv[2]);
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync rc = E_INVALIDARG;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync break;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync }
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync CHECK_ERROR(adapter, COMSETTER(PromiscModePolicy)(enmPromiscModePolicy));
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync if (SUCCEEDED(rc))
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync fNeedsSaving = true;
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync }
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync else
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync RTMsgError("The NIC %d is currently disabled and thus its promiscuous mode can't be changed", n);
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync }
a38afdea3cc827dc5964b4ba39a5cae6dbae23bdvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[1], "nic", 3))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Get the number of network adapters */
885f154412c8dc99c44809cf0d5b7f07342a455evboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(&a->argv[1][3], NetworkAdapterCount, "NIC");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!n)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 2)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the corresponding network adapter */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<INetworkAdapter> adapter;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (adapter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync BOOL fEnabled;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync adapter->COMGETTER(Enabled)(&fEnabled);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (fEnabled)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "null"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Null), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "nat"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc == 4)
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_RET(adapter, COMSETTER(NATNetwork)(Bstr(a->argv[3]).raw()), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_NAT), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if ( !strcmp(a->argv[2], "bridged")
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync || !strcmp(a->argv[2], "hostif")) /* backward compatibility */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(BridgedInterface)(Bstr(a->argv[3]).raw()), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "intnet"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_RET(adapter, COMSETTER(InternalNetwork)(Bstr(a->argv[3]).raw()), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Internal), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if defined(VBOX_WITH_NETFLT)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "hostonly"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(HostOnlyInterface)(Bstr(a->argv[3]).raw()), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync else if (!strcmp(a->argv[2], "generic"))
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (a->argc <= 3)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync rc = E_FAIL;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync break;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(GenericDriver)(Bstr(a->argv[3]).raw()), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync else if (!strcmp(a->argv[2], "natnetwork"))
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync {
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync if (a->argc <= 3)
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync {
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync rc = E_FAIL;
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync break;
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync }
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync CHECK_ERROR_RET(adapter, COMSETTER(NATNetwork)(Bstr(a->argv[3]).raw()), 1);
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_NATNetwork), 1);
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync /** @todo obsolete, remove eventually */
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync else if (!strcmp(a->argv[2], "vde"))
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync if (a->argc <= 3)
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync rc = E_FAIL;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync break;
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic), 1);
56349fc0a23f96f82208016f8f59f8377bb284b1vboxsync CHECK_ERROR_RET(adapter, SetProperty(Bstr("name").raw(), Bstr(a->argv[3]).raw()), 1);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync errorArgument("Invalid type '%s' specfied for NIC %lu", Utf8Str(a->argv[2]).c_str(), n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync RTMsgError("The NIC %d is currently disabled and thus its attachment type can't be changed", n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if ( !strcmp(a->argv[1], "vrde")
3933885bc0c2c93436d858a14564c6179ec72872vboxsync || !strcmp(a->argv[1], "vrdp"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (!strcmp(a->argv[1], "vrdp"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync RTStrmPrintf(g_pStdErr, "Warning: 'vrdp' is deprecated. Use 'vrde'.\n");
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ComPtr<IVRDEServer> vrdeServer;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ASSERT(vrdeServer);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (vrdeServer)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "on"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(TRUE));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "off"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(FALSE));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Invalid remote desktop server state '%s'", Utf8Str(a->argv[2]).c_str());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync else if ( !strcmp(a->argv[1], "vrdeport")
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync || !strcmp(a->argv[1], "vrdpport"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync if (!strcmp(a->argv[1], "vrdpport"))
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync RTStrmPrintf(g_pStdErr, "Warning: 'vrdpport' is deprecated. Use 'vrdeport'.\n");
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
a72b5355eb89aafe6bfcc8912cf02645d7cccceavboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ComPtr<IVRDEServer> vrdeServer;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ASSERT(vrdeServer);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (vrdeServer)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync Bstr ports;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "default"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ports = "0";
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ports = a->argv[2];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_BREAK(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), ports.raw()));
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if ( !strcmp(a->argv[1], "vrdevideochannelquality")
3933885bc0c2c93436d858a14564c6179ec72872vboxsync || !strcmp(a->argv[1], "vrdpvideochannelquality"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (!strcmp(a->argv[1], "vrdpvideochannelquality"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync RTStrmPrintf(g_pStdErr, "Warning: 'vrdpvideochannelquality' is deprecated. Use 'vrdevideochannelquality'.\n");
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc <= 1 + 1)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ComPtr<IVRDEServer> vrdeServer;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ASSERT(vrdeServer);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (vrdeServer)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
060f7ec6ae5c99df18341ef2e1f3e91f4b0c89f1vboxsync Bstr value = a->argv[2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
060f7ec6ae5c99df18341ef2e1f3e91f4b0c89f1vboxsync CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(), value.raw()));
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync else if (!strcmp(a->argv[1], "vrdeproperty"))
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync {
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync if (a->argc <= 1 + 1)
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync {
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync rc = E_FAIL;
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync break;
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ComPtr<IVRDEServer> vrdeServer;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ASSERT(vrdeServer);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (vrdeServer)
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync /* Parse 'name=value' */
3933885bc0c2c93436d858a14564c6179ec72872vboxsync char *pszProperty = RTStrDup(a->argv[2]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (pszProperty)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync char *pDelimiter = strchr(pszProperty, '=');
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (pDelimiter)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync *pDelimiter = '\0';
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync Bstr bstrName = pszProperty;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync Bstr bstrValue = &pDelimiter[1];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync if (SUCCEEDED(rc))
f80ead6d4496030f4b89cfcbd3a1569c8f39f7cevboxsync fNeedsSaving = true;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync errorArgument("Invalid vrdeproperty argument '%s'", a->argv[2]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync RTStrFree(pszProperty);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for VRDE property '%s'\n", a->argv[2]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (FAILED(rc))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync break;
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync }
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if ( !strcmp(a->argv[1], "usbattach")
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync || !strcmp(a->argv[1], "usbdetach"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc < 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Not enough parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync else if (a->argc == 4 || a->argc > 5)
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync {
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync errorSyntax(USAGE_CONTROLVM, "Wrong number of arguments");
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync rc = E_FAIL;
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync break;
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool attach = !strcmp(a->argv[1], "usbattach");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync Bstr usbId = a->argv[2];
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync Bstr captureFilename;
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync if (a->argc == 5)
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync {
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync if (!strcmp(a->argv[3], "--capturefile"))
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync captureFilename = a->argv[4];
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync else
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync {
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync errorArgument("Invalid parameter '%s'", a->argv[3]);
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync rc = E_FAIL;
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync break;
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync }
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync }
501181107e73684ab109521ba371063734cd1d76vboxsync
501181107e73684ab109521ba371063734cd1d76vboxsync Guid guid(usbId);
501181107e73684ab109521ba371063734cd1d76vboxsync if (!guid.isValid())
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync // assume address
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (attach)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<IHost> host;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync SafeIfaceArray <IHostUSBDevice> coll;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(coll)));
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<IHostUSBDevice> dev;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_BREAK(host, FindUSBDeviceByAddress(Bstr(a->argv[2]).raw(),
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync dev.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(dev, COMGETTER(Id)(usbId.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync SafeIfaceArray <IUSBDevice> coll;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(coll)));
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<IUSBDevice> dev;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_BREAK(console, FindUSBDeviceByAddress(Bstr(a->argv[2]).raw(),
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync dev.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(dev, COMGETTER(Id)(usbId.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
501181107e73684ab109521ba371063734cd1d76vboxsync else if (guid.isZero())
501181107e73684ab109521ba371063734cd1d76vboxsync {
501181107e73684ab109521ba371063734cd1d76vboxsync errorArgument("Zero UUID argument '%s'", a->argv[2]);
501181107e73684ab109521ba371063734cd1d76vboxsync rc = E_FAIL;
501181107e73684ab109521ba371063734cd1d76vboxsync break;
501181107e73684ab109521ba371063734cd1d76vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (attach)
dcc837f3a6f10996beb8aa7965f67f7f6c273fb4vboxsync CHECK_ERROR_BREAK(console, AttachUSBDevice(usbId.raw(), captureFilename.raw()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<IUSBDevice> dev;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_BREAK(console, DetachUSBDevice(usbId.raw(),
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync dev.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "setvideomodehint"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
28ae9ced88db55943497a8bb98682bc2be513476vboxsync if (a->argc != 5 && a->argc != 6 && a->argc != 7 && a->argc != 9)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
28ae9ced88db55943497a8bb98682bc2be513476vboxsync bool fEnabled = true;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync uint32_t uXRes = RTStrToUInt32(a->argv[2]);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync uint32_t uYRes = RTStrToUInt32(a->argv[3]);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync uint32_t uBpp = RTStrToUInt32(a->argv[4]);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync uint32_t uDisplayIdx = 0;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync bool fChangeOrigin = false;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync int32_t iOriginX = 0;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync int32_t iOriginY = 0;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync if (a->argc >= 6)
28ae9ced88db55943497a8bb98682bc2be513476vboxsync uDisplayIdx = RTStrToUInt32(a->argv[5]);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync if (a->argc >= 7)
28ae9ced88db55943497a8bb98682bc2be513476vboxsync {
28ae9ced88db55943497a8bb98682bc2be513476vboxsync int vrc = parseBool(a->argv[6], &fEnabled);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync if (RT_FAILURE(vrc))
28ae9ced88db55943497a8bb98682bc2be513476vboxsync {
28ae9ced88db55943497a8bb98682bc2be513476vboxsync errorSyntax(USAGE_CONTROLVM, "Either \"yes\" or \"no\" is expected");
28ae9ced88db55943497a8bb98682bc2be513476vboxsync rc = E_FAIL;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync break;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync }
28ae9ced88db55943497a8bb98682bc2be513476vboxsync fEnabled = !RTStrICmp(a->argv[6], "yes");
28ae9ced88db55943497a8bb98682bc2be513476vboxsync }
28ae9ced88db55943497a8bb98682bc2be513476vboxsync if (a->argc == 9)
28ae9ced88db55943497a8bb98682bc2be513476vboxsync {
28ae9ced88db55943497a8bb98682bc2be513476vboxsync iOriginX = RTStrToInt32(a->argv[7]);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync iOriginY = RTStrToInt32(a->argv[8]);
28ae9ced88db55943497a8bb98682bc2be513476vboxsync fChangeOrigin = true;
28ae9ced88db55943497a8bb98682bc2be513476vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
03a954338932c2b34361f1d27ae2029828db0958vboxsync ComPtr<IDisplay> pDisplay;
03a954338932c2b34361f1d27ae2029828db0958vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
03a954338932c2b34361f1d27ae2029828db0958vboxsync if (!pDisplay)
03a954338932c2b34361f1d27ae2029828db0958vboxsync {
29d55b79593710186ceda5a557fdab1727972175vboxsync RTMsgError("Guest not running");
03a954338932c2b34361f1d27ae2029828db0958vboxsync rc = E_FAIL;
03a954338932c2b34361f1d27ae2029828db0958vboxsync break;
03a954338932c2b34361f1d27ae2029828db0958vboxsync }
03a954338932c2b34361f1d27ae2029828db0958vboxsync CHECK_ERROR_BREAK(pDisplay, SetVideoModeHint(uDisplayIdx, fEnabled,
03a954338932c2b34361f1d27ae2029828db0958vboxsync fChangeOrigin, iOriginX, iOriginY,
03a954338932c2b34361f1d27ae2029828db0958vboxsync uXRes, uYRes, uBpp));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "setcredentials"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool fAllowLocalLogon = true;
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync if ( a->argc == 7
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync || ( a->argc == 8
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync && ( !strcmp(a->argv[3], "-p")
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync || !strcmp(a->argv[3], "--passwordfile"))))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync if ( strcmp(a->argv[5 + (a->argc - 7)], "--allowlocallogon")
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync && strcmp(a->argv[5 + (a->argc - 7)], "-allowlocallogon"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid parameter '%s'", a->argv[5]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync if (!strcmp(a->argv[6 + (a->argc - 7)], "no"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fAllowLocalLogon = false;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync else if ( a->argc != 5
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync && ( a->argc != 6
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync || ( strcmp(a->argv[3], "-p")
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync && strcmp(a->argv[3], "--passwordfile"))))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync Utf8Str passwd, domain;
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync if (a->argc == 5 || a->argc == 7)
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync {
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync passwd = a->argv[3];
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync domain = a->argv[4];
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync }
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync else
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync {
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync RTEXITCODE rcExit = readPasswordFile(a->argv[4], &passwd);
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync if (rcExit != RTEXITCODE_SUCCESS)
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync {
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync rc = E_FAIL;
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync break;
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync }
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync domain = a->argv[5];
5af5f66dd66e8ed177bcb8b429a1c2f3093ab406vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync ComPtr<IGuest> pGuest;
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Guest)(pGuest.asOutParam()));
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync if (!pGuest)
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync {
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync RTMsgError("Guest not running");
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync rc = E_FAIL;
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync break;
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync }
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync CHECK_ERROR_BREAK(pGuest, SetCredentials(Bstr(a->argv[2]).raw(),
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync Bstr(passwd).raw(),
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync Bstr(domain).raw(),
e4cab07522ccc54b3232ed0f7b6c11ddc3a99572vboxsync fAllowLocalLogon));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
c9e3f6ad81ea9a279ffb537720699e552882c40avboxsync#if 0 /* TODO: review & remove */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "dvdattach"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr uuid;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc != 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IMedium> dvdMedium;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* unmount? */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "none"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* nothing to do, NULL object will cause unmount */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* host drive? */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[2], "host:", 5))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IHost> host;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = host->FindHostDVDDrive(Bstr(a->argv[2] + 5), dvdMedium.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!dvdMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid host DVD drive name \"%s\"",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync a->argv[2] + 5);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* first assume it's a UUID */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uuid = a->argv[2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = a->virtualBox->GetDVDImage(uuid, dvdMedium.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc) || !dvdMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* must be a filename, check if it's in the collection */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = a->virtualBox->FindDVDImage(Bstr(a->argv[2]), dvdMedium.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* not registered, do that on the fly */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!dvdMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr emptyUUID;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(a->argv[2]), emptyUUID, dvdMedium.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!dvdMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /** @todo generalize this, allow arbitrary number of DVD drives
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * and as a consequence multiple attachments and different
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * storage controllers. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (dvdMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync dvdMedium->COMGETTER(Id)(uuid.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uuid = Guid().toString();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller"), 1, 0, uuid, FALSE /* aForce */));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "floppyattach"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr uuid;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc != 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IMedium> floppyMedium;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* unmount? */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "none"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* nothing to do, NULL object will cause unmount */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* host drive? */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[2], "host:", 5))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IHost> host;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync host->FindHostFloppyDrive(Bstr(a->argv[2] + 5), floppyMedium.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!floppyMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid host floppy drive name \"%s\"",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync a->argv[2] + 5);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* first assume it's a UUID */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uuid = a->argv[2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = a->virtualBox->GetFloppyImage(uuid, floppyMedium.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc) || !floppyMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* must be a filename, check if it's in the collection */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = a->virtualBox->FindFloppyImage(Bstr(a->argv[2]), floppyMedium.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* not registered, do that on the fly */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!floppyMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr emptyUUID;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(a->argv[2]), emptyUUID, floppyMedium.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!floppyMedium)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync floppyMedium->COMGETTER(Id)(uuid.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller"), 0, 0, uuid, FALSE /* aForce */));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
c9e3f6ad81ea9a279ffb537720699e552882c40avboxsync#endif /* obsolete dvdattach/floppyattach */
21ed14a0d745501ffc9a68be81c0abadc777b628vboxsync else if (!strcmp(a->argv[1], "guestmemoryballoon"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc != 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t uVal;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int vrc;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (vrc != VINF_SUCCESS)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Error parsing guest memory balloon size '%s'", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
629169500a4e1696f37dd3118a791d68278f71davboxsync /* guest is running; update IGuest */
c970e7d40b648d5c8f3e2b060692e670d85997d1vboxsync ComPtr<IGuest> pGuest;
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync rc = console->COMGETTER(Guest)(pGuest.asOutParam());
629169500a4e1696f37dd3118a791d68278f71davboxsync if (SUCCEEDED(rc))
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync {
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync if (!pGuest)
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync {
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync RTMsgError("Guest not running");
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync rc = E_FAIL;
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync break;
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync }
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync CHECK_ERROR(pGuest, COMSETTER(MemoryBalloonSize)(uVal));
58ff90b6beb1ca44c2c8c03a190082a455ee55ebvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "teleport"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr bstrHostname;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t uMaxDowntime = 250 /*ms*/;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t uPort = UINT32_MAX;
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync uint32_t cMsTimeout = 0;
94c4b844625733fedcd2b473c207981b31316bd9vboxsync Utf8Str strPassword;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync static const RTGETOPTDEF s_aTeleportOptions[] =
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync { "--host", 'h', RTGETOPT_REQ_STRING }, /** @todo RTGETOPT_FLAG_MANDATORY */
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync { "--hostname", 'h', RTGETOPT_REQ_STRING }, /** @todo remove this */
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync { "--maxdowntime", 'd', RTGETOPT_REQ_UINT32 },
94c4b844625733fedcd2b473c207981b31316bd9vboxsync { "--port", 'P', RTGETOPT_REQ_UINT32 }, /** @todo RTGETOPT_FLAG_MANDATORY */
94c4b844625733fedcd2b473c207981b31316bd9vboxsync { "--passwordfile", 'p', RTGETOPT_REQ_STRING },
94c4b844625733fedcd2b473c207981b31316bd9vboxsync { "--password", 'W', RTGETOPT_REQ_STRING },
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync { "--timeout", 't', RTGETOPT_REQ_UINT32 },
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync { "--detailed-progress", 'D', RTGETOPT_REQ_NOTHING }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync };
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTGETOPTSTATE GetOptState;
fb1975a6972d89de9e515bed0248db93f04ec9d8vboxsync RTGetOptInit(&GetOptState, a->argc, a->argv, s_aTeleportOptions, RT_ELEMENTS(s_aTeleportOptions), 2, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int ch;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTGETOPTUNION Value;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync while ( SUCCEEDED(rc)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && (ch = RTGetOpt(&GetOptState, &Value)))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync switch (ch)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync case 'h': bstrHostname = Value.psz; break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync case 'd': uMaxDowntime = Value.u32; break;
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync case 'D': g_fDetailedProgress = true; break;
94c4b844625733fedcd2b473c207981b31316bd9vboxsync case 'P': uPort = Value.u32; break;
94c4b844625733fedcd2b473c207981b31316bd9vboxsync case 'p':
94c4b844625733fedcd2b473c207981b31316bd9vboxsync {
94c4b844625733fedcd2b473c207981b31316bd9vboxsync RTEXITCODE rcExit = readPasswordFile(Value.psz, &strPassword);
94c4b844625733fedcd2b473c207981b31316bd9vboxsync if (rcExit != RTEXITCODE_SUCCESS)
94c4b844625733fedcd2b473c207981b31316bd9vboxsync rc = E_FAIL;
94c4b844625733fedcd2b473c207981b31316bd9vboxsync break;
94c4b844625733fedcd2b473c207981b31316bd9vboxsync }
94c4b844625733fedcd2b473c207981b31316bd9vboxsync case 'W': strPassword = Value.psz; break;
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync case 't': cMsTimeout = Value.u32; break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync default:
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorGetOpt(USAGE_CONTROLVM, ch, &Value);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IProgress> progress;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync CHECK_ERROR_BREAK(console, Teleport(bstrHostname.raw(), uPort,
94c4b844625733fedcd2b473c207981b31316bd9vboxsync Bstr(strPassword).raw(),
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync uMaxDowntime,
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync progress.asOutParam()));
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync if (cMsTimeout)
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync {
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync rc = progress->COMSETTER(Timeout)(cMsTimeout);
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync if (FAILED(rc) && rc != VBOX_E_INVALID_OBJECT_STATE)
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync CHECK_ERROR_BREAK(progress, COMSETTER(Timeout)(cMsTimeout)); /* lazyness */
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync }
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = showProgress(progress);
ae16af2d7d3c99d359094a7f19f5937efc2e66bdvboxsync CHECK_PROGRESS_ERROR(progress, ("Teleportation failed"));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync else if (!strcmp(a->argv[1], "screenshotpng"))
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync {
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync if (a->argc <= 2 || a->argc > 4)
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync {
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync rc = E_FAIL;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync break;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync int vrc;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync uint32_t iScreen = 0;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync if (a->argc == 4)
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync {
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &iScreen);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync if (vrc != VINF_SUCCESS)
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync {
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync errorArgument("Error parsing display number '%s'", a->argv[3]);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync rc = E_FAIL;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync break;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync ComPtr<IDisplay> pDisplay;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
1991e77b43953f6187cca21f5616093e9aa60bd3vboxsync if (!pDisplay)
1991e77b43953f6187cca21f5616093e9aa60bd3vboxsync {
29d55b79593710186ceda5a557fdab1727972175vboxsync RTMsgError("Guest not running");
1991e77b43953f6187cca21f5616093e9aa60bd3vboxsync rc = E_FAIL;
1991e77b43953f6187cca21f5616093e9aa60bd3vboxsync break;
1991e77b43953f6187cca21f5616093e9aa60bd3vboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync ULONG width, height, bpp;
77b95150000f2ef9778e43783401ed80eaed6949vboxsync LONG xOrigin, yOrigin;
b7307c9c040a1a8aed0dbabed6574466d0bff2e4vboxsync GuestMonitorStatus_T monitorStatus;
b7307c9c040a1a8aed0dbabed6574466d0bff2e4vboxsync CHECK_ERROR_BREAK(pDisplay, GetScreenResolution(iScreen, &width, &height, &bpp, &xOrigin, &yOrigin, &monitorStatus));
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync com::SafeArray<BYTE> saScreenshot;
d01bb88591e2ae070aa233b99c81e58598d557e1vboxsync CHECK_ERROR_BREAK(pDisplay, TakeScreenShotToArray(iScreen, width, height, BitmapFormat_PNG, ComSafeArrayAsOutParam(saScreenshot)));
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync RTFILE pngFile = NIL_RTFILE;
844af57b369279e0d79e59b433ab16aa83b47df2vboxsync vrc = RTFileOpen(&pngFile, a->argv[2], RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_TRUNCATE | RTFILE_O_DENY_ALL);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync if (RT_FAILURE(vrc))
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync RTMsgError("Failed to create file '%s' (%Rrc)", a->argv[2], vrc);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync rc = E_FAIL;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync break;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync vrc = RTFileWrite(pngFile, saScreenshot.raw(), saScreenshot.size(), NULL);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync if (RT_FAILURE(vrc))
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync RTMsgError("Failed to write screenshot to file '%s' (%Rrc)", a->argv[2], vrc);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync rc = E_FAIL;
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync }
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync RTFileClose(pngFile);
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync#ifdef VBOX_WITH_VPX
83c104811df01cb433cd1c36a7811113f4214e6evboxsync /*
83c104811df01cb433cd1c36a7811113f4214e6evboxsync * Note: Commands starting with "vcp" are the deprecated versions and are
83c104811df01cb433cd1c36a7811113f4214e6evboxsync * kept to ensure backwards compatibility.
83c104811df01cb433cd1c36a7811113f4214e6evboxsync */
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocap")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpenabled"))
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync if (a->argc != 3)
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync rc = E_FAIL;
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync break;
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync }
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync if (!strcmp(a->argv[2], "on"))
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync CHECK_ERROR_RET(sessionMachine, COMSETTER(VideoCaptureEnabled)(TRUE), 1);
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync }
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync else if (!strcmp(a->argv[2], "off"))
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync CHECK_ERROR_RET(sessionMachine, COMSETTER(VideoCaptureEnabled)(FALSE), 1);
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync }
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync else
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync errorArgument("Invalid state '%s'", Utf8Str(a->argv[2]).c_str());
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync rc = E_FAIL;
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync break;
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync }
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocapscreens")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpscreens"))
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync {
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync ULONG cMonitors = 64;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync CHECK_ERROR_BREAK(machine, COMGETTER(MonitorCount)(&cMonitors));
1a3fdaf7f4fdfc0680a7091ba9c1e7309098ff2bvboxsync com::SafeArray<BOOL> saScreens(cMonitors);
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync if ( a->argc == 3
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync && !strcmp(a->argv[2], "all"))
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync /* enable all screens */
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync for (unsigned i = 0; i < cMonitors; i++)
1a3fdaf7f4fdfc0680a7091ba9c1e7309098ff2bvboxsync saScreens[i] = true;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync }
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync else if ( a->argc == 3
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync && !strcmp(a->argv[2], "none"))
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync /* disable all screens */
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync for (unsigned i = 0; i < cMonitors; i++)
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync saScreens[i] = false;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync /** @todo r=andy What if this is specified? */
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync }
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync else
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync {
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync /* enable selected screens */
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync for (unsigned i = 0; i < cMonitors; i++)
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync saScreens[i] = false;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync for (int i = 2; SUCCEEDED(rc) && i < a->argc; i++)
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync {
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync uint32_t iScreen;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync int vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &iScreen);
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync if (vrc != VINF_SUCCESS)
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync {
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync errorArgument("Error parsing display number '%s'", a->argv[i]);
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync rc = E_FAIL;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync break;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync }
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync if (iScreen >= cMonitors)
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync {
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync errorArgument("Invalid screen ID specified '%u'", iScreen);
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync rc = E_FAIL;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync break;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync }
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync saScreens[iScreen] = true;
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync }
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync }
1a3fdaf7f4fdfc0680a7091ba9c1e7309098ff2bvboxsync
1a3fdaf7f4fdfc0680a7091ba9c1e7309098ff2bvboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureScreens)(ComSafeArrayAsInParam(saScreens)));
48890ac9b4b339e0341e826b5c26ce6408729987vboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocapfile")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpfile"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 3)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureFile)(Bstr(a->argv[3]).raw()));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync else if (!strcmp(a->argv[1], "videocapres"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 4)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync uint32_t uVal;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (RT_FAILURE(vrc))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorArgument("Error parsing width '%s'", a->argv[2]);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureWidth)(uVal));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &uVal);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (RT_FAILURE(vrc))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorArgument("Error parsing height '%s'", a->argv[3]);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureHeight)(uVal));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if (!strcmp(a->argv[1], "vcpwidth")) /* Deprecated; keeping for compatibility. */
83c104811df01cb433cd1c36a7811113f4214e6evboxsync {
83c104811df01cb433cd1c36a7811113f4214e6evboxsync uint32_t uVal;
83c104811df01cb433cd1c36a7811113f4214e6evboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
83c104811df01cb433cd1c36a7811113f4214e6evboxsync if (RT_FAILURE(vrc))
83c104811df01cb433cd1c36a7811113f4214e6evboxsync {
83c104811df01cb433cd1c36a7811113f4214e6evboxsync errorArgument("Error parsing width '%s'", a->argv[2]);
83c104811df01cb433cd1c36a7811113f4214e6evboxsync rc = E_FAIL;
83c104811df01cb433cd1c36a7811113f4214e6evboxsync break;
83c104811df01cb433cd1c36a7811113f4214e6evboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureWidth)(uVal));
83c104811df01cb433cd1c36a7811113f4214e6evboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if (!strcmp(a->argv[1], "vcpheight")) /* Deprecated; keeping for compatibility. */
83c104811df01cb433cd1c36a7811113f4214e6evboxsync {
83c104811df01cb433cd1c36a7811113f4214e6evboxsync uint32_t uVal;
83c104811df01cb433cd1c36a7811113f4214e6evboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
83c104811df01cb433cd1c36a7811113f4214e6evboxsync if (RT_FAILURE(vrc))
83c104811df01cb433cd1c36a7811113f4214e6evboxsync {
83c104811df01cb433cd1c36a7811113f4214e6evboxsync errorArgument("Error parsing height '%s'", a->argv[2]);
83c104811df01cb433cd1c36a7811113f4214e6evboxsync rc = E_FAIL;
83c104811df01cb433cd1c36a7811113f4214e6evboxsync break;
83c104811df01cb433cd1c36a7811113f4214e6evboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureHeight)(uVal));
83c104811df01cb433cd1c36a7811113f4214e6evboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocaprate")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcprate"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 3)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync uint32_t uVal;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (RT_FAILURE(vrc))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorArgument("Error parsing rate '%s'", a->argv[2]);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureRate)(uVal));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocapfps")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpfps"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 3)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync uint32_t uVal;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (RT_FAILURE(vrc))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorArgument("Error parsing FPS '%s'", a->argv[2]);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureFPS)(uVal));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocapmaxtime")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpmaxtime"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 3)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync uint32_t uVal;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (RT_FAILURE(vrc))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorArgument("Error parsing maximum time '%s'", a->argv[2]);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureMaxTime)(uVal));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocapmaxsize")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpmaxsize"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 3)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync uint32_t uVal;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync int vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (RT_FAILURE(vrc))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorArgument("Error parsing maximum file size '%s'", a->argv[2]);
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureMaxFileSize)(uVal));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
83c104811df01cb433cd1c36a7811113f4214e6evboxsync else if ( !strcmp(a->argv[1], "videocapopts")
83c104811df01cb433cd1c36a7811113f4214e6evboxsync || !strcmp(a->argv[1], "vcpoptions"))
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync if (a->argc != 3)
f6b53aa7a361c1f26a3287a95172653219470233vboxsync {
f6b53aa7a361c1f26a3287a95172653219470233vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
f6b53aa7a361c1f26a3287a95172653219470233vboxsync rc = E_FAIL;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync break;
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync
f6b53aa7a361c1f26a3287a95172653219470233vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(VideoCaptureOptions)(Bstr(a->argv[3]).raw()));
f6b53aa7a361c1f26a3287a95172653219470233vboxsync }
f6b53aa7a361c1f26a3287a95172653219470233vboxsync#endif /* VBOX_WITH_VPX */
101e307bb33304d9dda53a7652510880e8228b13vboxsync else if (!strcmp(a->argv[1], "webcam"))
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync if (a->argc < 3)
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
101e307bb33304d9dda53a7652510880e8228b13vboxsync rc = E_FAIL;
101e307bb33304d9dda53a7652510880e8228b13vboxsync break;
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
101e307bb33304d9dda53a7652510880e8228b13vboxsync
101e307bb33304d9dda53a7652510880e8228b13vboxsync ComPtr<IEmulatedUSB> pEmulatedUSB;
101e307bb33304d9dda53a7652510880e8228b13vboxsync CHECK_ERROR_BREAK(console, COMGETTER(EmulatedUSB)(pEmulatedUSB.asOutParam()));
101e307bb33304d9dda53a7652510880e8228b13vboxsync if (!pEmulatedUSB)
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync RTMsgError("Guest not running");
101e307bb33304d9dda53a7652510880e8228b13vboxsync rc = E_FAIL;
101e307bb33304d9dda53a7652510880e8228b13vboxsync break;
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
101e307bb33304d9dda53a7652510880e8228b13vboxsync
101e307bb33304d9dda53a7652510880e8228b13vboxsync if (!strcmp(a->argv[2], "attach"))
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync Bstr path("");
101e307bb33304d9dda53a7652510880e8228b13vboxsync if (a->argc >= 4)
101e307bb33304d9dda53a7652510880e8228b13vboxsync path = a->argv[3];
101e307bb33304d9dda53a7652510880e8228b13vboxsync Bstr settings("");
101e307bb33304d9dda53a7652510880e8228b13vboxsync if (a->argc >= 5)
101e307bb33304d9dda53a7652510880e8228b13vboxsync settings = a->argv[4];
101e307bb33304d9dda53a7652510880e8228b13vboxsync CHECK_ERROR_BREAK(pEmulatedUSB, WebcamAttach(path.raw(), settings.raw()));
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
101e307bb33304d9dda53a7652510880e8228b13vboxsync else if (!strcmp(a->argv[2], "detach"))
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync Bstr path("");
101e307bb33304d9dda53a7652510880e8228b13vboxsync if (a->argc >= 4)
101e307bb33304d9dda53a7652510880e8228b13vboxsync path = a->argv[3];
101e307bb33304d9dda53a7652510880e8228b13vboxsync CHECK_ERROR_BREAK(pEmulatedUSB, WebcamDetach(path.raw()));
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
101e307bb33304d9dda53a7652510880e8228b13vboxsync else if (!strcmp(a->argv[2], "list"))
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync com::SafeArray <BSTR> webcams;
101e307bb33304d9dda53a7652510880e8228b13vboxsync CHECK_ERROR_BREAK(pEmulatedUSB, COMGETTER(Webcams)(ComSafeArrayAsOutParam(webcams)));
101e307bb33304d9dda53a7652510880e8228b13vboxsync for (size_t i = 0; i < webcams.size(); ++i)
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync RTPrintf("%ls\n", webcams[i][0]? webcams[i]: Bstr("default").raw());
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
101e307bb33304d9dda53a7652510880e8228b13vboxsync else
101e307bb33304d9dda53a7652510880e8228b13vboxsync {
101e307bb33304d9dda53a7652510880e8228b13vboxsync errorArgument("Invalid argument to '%s'", a->argv[1]);
101e307bb33304d9dda53a7652510880e8228b13vboxsync rc = E_FAIL;
101e307bb33304d9dda53a7652510880e8228b13vboxsync break;
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync }
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync else if (!strcmp(a->argv[1], "addencpassword"))
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync {
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync if ( a->argc != 4
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync && a->argc != 6)
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync {
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync break;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync }
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync if ( strcmp(a->argv[4], "--removeonsuspend")
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync || ( strcmp(a->argv[5], "yes")
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync && strcmp(a->argv[5], "no")))
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync {
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync errorSyntax(USAGE_CONTROLVM, "Invalid parameters");
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync break;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync }
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync BOOL fRemoveOnSuspend = FALSE;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync Bstr bstrPwId(a->argv[2]);
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync Bstr bstrPw(a->argv[3]);
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync if ( a->argc == 6
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync && !strcmp(a->argv[5], "yes"))
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync fRemoveOnSuspend = TRUE;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync CHECK_ERROR_BREAK(console, AddDiskEncryptionPassword(bstrPwId.raw(), bstrPw.raw(), fRemoveOnSuspend));
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync }
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync else if (!strcmp(a->argv[1], "removeencpassword"))
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync {
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync if (a->argc != 3)
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync {
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync break;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync }
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync Bstr bstrPwId(a->argv[2]);
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync CHECK_ERROR_BREAK(console, RemoveDiskEncryptionPassword(bstrPwId.raw()));
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync }
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync else if (!strcmp(a->argv[1], "removeallencpasswords"))
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync {
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync CHECK_ERROR_BREAK(console, ClearAllDiskEncryptionPasswords());
101e307bb33304d9dda53a7652510880e8228b13vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync errorSyntax(USAGE_CONTROLVM, "Invalid parameter '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync } while (0);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync /* The client has to trigger saving the state explicitely. */
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync if (fNeedsSaving)
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync CHECK_ERROR(sessionMachine, SaveSettings());
0dffbbe0c5f4a9b76066b09d41ca2dca5a4ab3e6vboxsync
825c2485cf84eec495985ffd605a1c9cddee8c32vboxsync a->session->UnlockMachine();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return SUCCEEDED(rc) ? 0 : 1;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}