VBoxManageControlVM.cpp revision 8b7ee9f7ebabcdbf40fececa0d6321d97d5143d8
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* $Id$ */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** @file
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * VBoxManage - Implementation of the controlvm command.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/*
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Copyright (C) 2006-2011 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/EventQueue.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
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>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/file.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <VBox/log.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include "VBoxManage.h"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#include <list>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/**
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Parses a number.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @returns Valid number on success.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * @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
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncunsigned int getMaxNics(IVirtualBox* vbox, IMachine* mach)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr <ISystemProperties> info;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ChipsetType_T aChipset;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ULONG NetworkAdapterCount = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync HRESULT rc;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync do {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(vbox, COMGETTER(SystemProperties)(info.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(mach, COMGETTER(ChipsetType)(&aChipset));
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync CHECK_ERROR_BREAK(info, GetMaxNetworkAdapters(aChipset, &NetworkAdapterCount));
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync return (unsigned int)NetworkAdapterCount;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync } while (0);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return 0;
f409459bdd4c15cdb8d7fb6c6d54338cce9ac814vboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncint handleControlVM(HandlerArg *a)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync using namespace com;
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 */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr <IMachine> machine;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync machine.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return 1;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* open a session for the VM */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync do
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the associated console */
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync ComPtr<IConsole> console;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync /* ... and session machine */
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync ComPtr<IMachine> sessionMachine;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()));
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync /* which command? */
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if (!strcmp(a->argv[1], "pause"))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(console, Pause());
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync else if (!strcmp(a->argv[1], "resume"))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(console, Resume());
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync else if (!strcmp(a->argv[1], "reset"))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync CHECK_ERROR_BREAK(console, Reset());
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }
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;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync }
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync unsigned n = parseNum(a->argv[2], 32, "CPU");
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync CHECK_ERROR_BREAK(sessionMachine, HotUnplugCPU(n));
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync }
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync else if (!strcmp(a->argv[1], "plugcpu"))
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync {
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync if (a->argc <= 1 + 1)
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync {
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync errorArgument("Missing argument to '%s'. Expected CPU number.", a->argv[1]);
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync rc = E_FAIL;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(a->argv[2], 32, "CPU");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(sessionMachine, HotPlugCPU(n));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "cpuexecutioncap"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync errorArgument("Missing argument to '%s'. Expected execution cap number.", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(a->argv[2], 100, "ExecutionCap");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync CHECK_ERROR_BREAK(sessionMachine, COMSETTER(CPUExecutionCap)(n));
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync }
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync else if (!strcmp(a->argv[1], "poweroff"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync ComPtr<IProgress> progress;
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam()));
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync rc = showProgress(progress);
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync CHECK_PROGRESS_ERROR(progress, ("Failed to power off machine"));
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "savestate"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* first pause so we don't trigger a live save which needs more time/resources */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = console->Pause();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (rc == VBOX_E_INVALID_VM_STATE)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* check if we are already paused */
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync MachineState_T machineState;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, COMGETTER(State)(&machineState));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* the error code was lost by the previous instruction */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = VBOX_E_INVALID_VM_STATE;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (machineState != MachineState_Paused)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTMsgError("Machine in invalid state %d -- %s\n",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync machineState, machineStateToName(machineState, false));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IProgress> progress;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(console, SaveState(progress.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync console->Resume();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = showProgress(progress);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_PROGRESS_ERROR(progress, ("Failed to save machine state"));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync console->Resume();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "acpipowerbutton"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, PowerButton());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync else if (!strcmp(a->argv[1], "acpisleepbutton"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, SleepButton());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync else if (!strcmp(a->argv[1], "keyboardputscancode"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IKeyboard> keyboard;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(keyboard.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
42aef05f4b27fb393967e581be04be455064c80avboxsync errorArgument("Missing argument to '%s'. Expected IBM PC AT set 2 keyboard scancode(s) as hex byte(s).", a->argv[1]);
42aef05f4b27fb393967e581be04be455064c80avboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync std::list<LONG> llScancodes;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Process the command line. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync int i;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync for (i = 1 + 1; i < a->argc; i++)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ( RT_C_IS_XDIGIT (a->argv[i][0])
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync && RT_C_IS_XDIGIT (a->argv[i][1])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && a->argv[i][2] == 0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint8_t u8Scancode;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int irc = RTStrToUInt8Ex(a->argv[i], NULL, 16, &u8Scancode);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (RT_FAILURE (irc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTMsgError("Converting '%s' returned %Rrc!", a->argv[i], rc);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync break;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync llScancodes.push_back(u8Scancode);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync 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
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Send scancodes to the VM. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync com::SafeArray<LONG> saScancodes(llScancodes);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ULONG codesStored = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(keyboard, PutScancodes(ComSafeArrayAsInParam(saScancodes),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync &codesStored));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (codesStored < saScancodes.size())
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 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 */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
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;
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync 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 {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid link state '%s'", Utf8Str(a->argv[2]).c_str());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
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 */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 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;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync 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 {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(TraceFile)(Bstr(a->argv[2]).raw()), 1);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid filename or filename not specified for NIC %lu", n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 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 */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
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 }
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync else if (!strcmp(a->argv[2], "off"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(TraceEnabled)(FALSE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync errorArgument("Invalid nictrace%lu argument '%s'", n, Utf8Str(a->argv[2]).c_str());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync else
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync RTMsgError("The NIC %d is currently disabled and thus its trace flag can't be changed", n);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync else if( a->argc > 2
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync && !strncmp(a->argv[1], "natpf", 5))
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync /* Get the number of network adapters */
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, sessionMachine);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync ComPtr<INATEngine> engine;
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 }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync CHECK_ERROR(adapter, COMGETTER(NatDriver)(engine.asOutParam()));
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (!engine)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync rc = E_FAIL;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync break;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (!strcmp(a->argv[2], "delete"))
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
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 != ',') \
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync { \
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync if (*ch == 0) \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync { \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync return errorSyntax(USAGE_CONTROLVM, \
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync "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)
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync proto = NATProtocol_UDP;
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync else if (RTStrICmp(strProto, "tcp") == 0)
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync proto = NATProtocol_TCP;
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync else
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync {
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync return errorSyntax(USAGE_CONTROLVM,
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync "Wrong rule proto '%s' specified -- only 'udp' and 'tcp' are allowed.",
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync strProto);
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
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 /* commit changes */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (SUCCEEDED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(sessionMachine, SaveSettings());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[1], "nicproperty", 11))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Get the number of network adapters */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ULONG NetworkAdapterCount = getMaxNics(a->virtualBox,sessionMachine) ;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync unsigned n = parseNum(&a->argv[1][11], 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 /* Parse 'name=value' */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync char *pszProperty = RTStrDup(a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pszProperty)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync char *pDelimiter = strchr(pszProperty, '=');
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pDelimiter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *pDelimiter = '\0';
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr bstrName = pszProperty;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync Bstr bstrValue = &pDelimiter[1];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(adapter, SetProperty(bstrName.raw(), bstrValue.raw()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid nicproperty%d argument '%s'", n, a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTStrFree(pszProperty);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for nicproperty%d '%s'\n", n, a->argv[2]);
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTMsgError("The NIC %d is currently disabled and thus its properties can't be changed", n);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strncmp(a->argv[1], "nic", 3))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Get the number of network adapters */
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync 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 }
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* get the corresponding network adapter */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<INetworkAdapter> adapter;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (adapter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync BOOL fEnabled;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync adapter->COMGETTER(Enabled)(&fEnabled);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (fEnabled)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "null"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Null), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if (!strcmp(a->argv[2], "nat"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc == 4)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(NATNetwork)(Bstr(a->argv[3]).raw()), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync 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 {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(BridgedInterface)(Bstr(a->argv[3]).raw()), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[2], "intnet"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 3)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(InternalNetwork)(Bstr(a->argv[3]).raw()), 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 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 {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc <= 3)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
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);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_RET(adapter, COMSETTER(HostOnlyInterface)(Bstr(a->argv[3]).raw()), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync#endif
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if (!strcmp(a->argv[2], "generic"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc <= 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(GenericDriver)(Bstr(a->argv[3]).raw()), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync /** @todo obsolete, remove eventually */
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if (!strcmp(a->argv[2], "vde"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc <= 3)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Missing argument to '%s'", a->argv[2]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(Enabled)(TRUE), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_RET(adapter, SetProperty(Bstr("name").raw(), Bstr(a->argv[3]).raw()), 1);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Invalid type '%s' specfied for NIC %lu", Utf8Str(a->argv[2]).c_str(), n);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTMsgError("The NIC %d is currently disabled and thus its attachment type can't be changed", n);
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync }
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync }
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync else if ( !strcmp(a->argv[1], "vrde")
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync || !strcmp(a->argv[1], "vrdp"))
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync {
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync if (!strcmp(a->argv[1], "vrdp"))
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync RTStrmPrintf(g_pStdErr, "Warning: 'vrdp' is deprecated. Use 'vrde'.\n");
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc <= 1 + 1)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ComPtr<IVRDEServer> vrdeServer;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
3933885bc0c2c93436d858a14564c6179ec72872vboxsync ASSERT(vrdeServer);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (vrdeServer)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (!strcmp(a->argv[2], "on"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(TRUE));
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if (!strcmp(a->argv[2], "off"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(FALSE));
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync errorArgument("Invalid remote desktop server state '%s'", Utf8Str(a->argv[2]).c_str());
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rc = E_FAIL;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync break;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync else if ( !strcmp(a->argv[1], "vrdeport")
3933885bc0c2c93436d858a14564c6179ec72872vboxsync || !strcmp(a->argv[1], "vrdpport"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (!strcmp(a->argv[1], "vrdpport"))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync RTStrmPrintf(g_pStdErr, "Warning: 'vrdpport' is deprecated. Use 'vrdeport'.\n");
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if (a->argc <= 1 + 1)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IVRDEServer> vrdeServer;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ASSERT(vrdeServer);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (vrdeServer)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr ports;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "default"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ports = "0";
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ports = a->argv[2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), ports.raw()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if ( !strcmp(a->argv[1], "vrdevideochannelquality")
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync || !strcmp(a->argv[1], "vrdpvideochannelquality"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[1], "vrdpvideochannelquality"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTStrmPrintf(g_pStdErr, "Warning: 'vrdpvideochannelquality' is deprecated. Use 'vrdevideochannelquality'.\n");
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync if (a->argc <= 1 + 1)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IVRDEServer> vrdeServer;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync ASSERT(vrdeServer);
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync if (vrdeServer)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr value = a->argv[2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(), value.raw()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "vrdeproperty"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc <= 1 + 1)
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync {
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IVRDEServer> vrdeServer;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ASSERT(vrdeServer);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (vrdeServer)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Parse 'name=value' */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync char *pszProperty = RTStrDup(a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pszProperty)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync char *pDelimiter = strchr(pszProperty, '=');
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pDelimiter)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *pDelimiter = '\0';
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr bstrName = pszProperty;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr bstrValue = &pDelimiter[1];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid vrdeproperty argument '%s'", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTStrFree(pszProperty);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for VRDE property '%s'\n", a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (FAILED(rc))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
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");
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync rc = E_FAIL;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync break;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync }
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool attach = !strcmp(a->argv[1], "usbattach");
c9e3f6ad81ea9a279ffb537720699e552882c40avboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr usbId = a->argv[2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (Guid(usbId).isEmpty())
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync // assume address
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (attach)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 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)));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr <IHostUSBDevice> dev;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(host, FindUSBDeviceByAddress(Bstr(a->argv[2]).raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 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)));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr <IUSBDevice> dev;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, FindUSBDeviceByAddress(Bstr(a->argv[2]).raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync dev.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(dev, COMGETTER(Id)(usbId.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (attach)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, AttachUSBDevice(usbId.raw()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr <IUSBDevice> dev;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, DetachUSBDevice(usbId.raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync dev.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "setvideomodehint"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc != 5 && a->argc != 6)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t xres = RTStrToUInt32(a->argv[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t yres = RTStrToUInt32(a->argv[3]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t bpp = RTStrToUInt32(a->argv[4]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t displayIdx = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc == 6)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync displayIdx = RTStrToUInt32(a->argv[5]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IDisplay> display;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(display, SetVideoModeHint(xres, yres, bpp, displayIdx));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (!strcmp(a->argv[1], "setcredentials"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool fAllowLocalLogon = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc == 7)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ( strcmp(a->argv[5], "--allowlocallogon")
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync && strcmp(a->argv[5], "-allowlocallogon"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid parameter '%s'", a->argv[5]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[6], "no"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fAllowLocalLogon = false;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else if (a->argc != 5)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync ComPtr<IGuest> guest;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(console, COMGETTER(Guest)(guest.asOutParam()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CHECK_ERROR_BREAK(guest, SetCredentials(Bstr(a->argv[2]).raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr(a->argv[3]).raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr(a->argv[4]).raw(),
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fAllowLocalLogon));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#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];
c9e3f6ad81ea9a279ffb537720699e552882c40avboxsync rc = a->virtualBox->GetDVDImage(uuid, dvdMedium.asOutParam());
21ed14a0d745501ffc9a68be81c0abadc777b628vboxsync 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 }
629169500a4e1696f37dd3118a791d68278f71davboxsync
629169500a4e1696f37dd3118a791d68278f71davboxsync /** @todo generalize this, allow arbitrary number of DVD drives
629169500a4e1696f37dd3118a791d68278f71davboxsync * and as a consequence multiple attachments and different
629169500a4e1696f37dd3118a791d68278f71davboxsync * storage controllers. */
629169500a4e1696f37dd3118a791d68278f71davboxsync 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"))
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Bstr uuid;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc != 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync rc = E_FAIL;
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync break;
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync }
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync ComPtr<IMedium> floppyMedium;
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* unmount? */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (!strcmp(a->argv[2], "none"))
fb1975a6972d89de9e515bed0248db93f04ec9d8vboxsync {
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)
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorArgument("Invalid host floppy drive name \"%s\"",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync a->argv[2] + 5);
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync 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 {
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync /* must be a filename, check if it's in the collection */
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync rc = a->virtualBox->FindFloppyImage(Bstr(a->argv[2]), floppyMedium.asOutParam());
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync /* not registered, do that on the fly */
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync if (!floppyMedium)
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync {
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync Bstr emptyUUID;
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(a->argv[2]), emptyUUID, floppyMedium.asOutParam()));
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync }
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync }
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync if (!floppyMedium)
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync {
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync 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 */));
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif /* obsolete dvdattach/floppyattach */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync else if (!strcmp(a->argv[1], "guestmemoryballoon"))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (a->argc != 3)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync rc = E_FAIL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync break;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint32_t uVal;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int vrc;
825c2485cf84eec495985ffd605a1c9cddee8c32vboxsync 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;
break;
}
/* guest is running; update IGuest */
ComPtr <IGuest> guest;
rc = console->COMGETTER(Guest)(guest.asOutParam());
if (SUCCEEDED(rc))
CHECK_ERROR(guest, COMSETTER(MemoryBalloonSize)(uVal));
}
else if (!strcmp(a->argv[1], "teleport"))
{
Bstr bstrHostname;
uint32_t uMaxDowntime = 250 /*ms*/;
uint32_t uPort = UINT32_MAX;
uint32_t cMsTimeout = 0;
Bstr bstrPassword("");
static const RTGETOPTDEF s_aTeleportOptions[] =
{
{ "--host", 'h', RTGETOPT_REQ_STRING }, /** @todo RTGETOPT_FLAG_MANDATORY */
{ "--hostname", 'h', RTGETOPT_REQ_STRING }, /** @todo remove this */
{ "--maxdowntime", 'd', RTGETOPT_REQ_UINT32 },
{ "--port", 'p', RTGETOPT_REQ_UINT32 }, /** @todo RTGETOPT_FLAG_MANDATORY */
{ "--password", 'P', RTGETOPT_REQ_STRING },
{ "--timeout", 't', RTGETOPT_REQ_UINT32 },
{ "--detailed-progress", 'D', RTGETOPT_REQ_NOTHING }
};
RTGETOPTSTATE GetOptState;
RTGetOptInit(&GetOptState, a->argc, a->argv, s_aTeleportOptions, RT_ELEMENTS(s_aTeleportOptions), 2, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
int ch;
RTGETOPTUNION Value;
while ( SUCCEEDED(rc)
&& (ch = RTGetOpt(&GetOptState, &Value)))
{
switch (ch)
{
case 'h': bstrHostname = Value.psz; break;
case 'd': uMaxDowntime = Value.u32; break;
case 'D': g_fDetailedProgress = true; break;
case 'p': uPort = Value.u32; break;
case 'P': bstrPassword = Value.psz; break;
case 't': cMsTimeout = Value.u32; break;
default:
errorGetOpt(USAGE_CONTROLVM, ch, &Value);
rc = E_FAIL;
break;
}
}
if (FAILED(rc))
break;
ComPtr<IProgress> progress;
CHECK_ERROR_BREAK(console, Teleport(bstrHostname.raw(), uPort,
bstrPassword.raw(),
uMaxDowntime,
progress.asOutParam()));
if (cMsTimeout)
{
rc = progress->COMSETTER(Timeout)(cMsTimeout);
if (FAILED(rc) && rc != VBOX_E_INVALID_OBJECT_STATE)
CHECK_ERROR_BREAK(progress, COMSETTER(Timeout)(cMsTimeout)); /* lazyness */
}
rc = showProgress(progress);
CHECK_PROGRESS_ERROR(progress, ("Teleportation failed"));
}
else if (!strcmp(a->argv[1], "screenshotpng"))
{
if (a->argc <= 2 || a->argc > 4)
{
errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
rc = E_FAIL;
break;
}
int vrc;
uint32_t displayIdx = 0;
if (a->argc == 4)
{
vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &displayIdx);
if (vrc != VINF_SUCCESS)
{
errorArgument("Error parsing display number '%s'", a->argv[3]);
rc = E_FAIL;
break;
}
}
ComPtr<IDisplay> pDisplay;
CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
ULONG width, height, bpp;
CHECK_ERROR_BREAK(pDisplay, GetScreenResolution(displayIdx, &width, &height, &bpp));
com::SafeArray<BYTE> saScreenshot;
CHECK_ERROR_BREAK(pDisplay, TakeScreenShotPNGToArray(displayIdx, width, height, ComSafeArrayAsOutParam(saScreenshot)));
RTFILE pngFile = NIL_RTFILE;
vrc = RTFileOpen(&pngFile, a->argv[2], RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_TRUNCATE);
if (RT_FAILURE(vrc))
{
RTMsgError("Failed to create file '%s'. rc=%Rrc", a->argv[2], vrc);
rc = E_FAIL;
break;
}
vrc = RTFileWrite(pngFile, saScreenshot.raw(), saScreenshot.size(), NULL);
if (RT_FAILURE(vrc))
{
RTMsgError("Failed to write screenshot to file '%s'. rc=%Rrc", a->argv[2], vrc);
rc = E_FAIL;
}
RTFileClose(pngFile);
}
else
{
errorSyntax(USAGE_CONTROLVM, "Invalid parameter '%s'", a->argv[1]);
rc = E_FAIL;
}
} while (0);
a->session->UnlockMachine();
return SUCCEEDED(rc) ? 0 : 1;
}