[12599] | 1 | /* $Id: VBoxManageControlVM.cpp 105266 2024-07-11 07:49:37Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[34913] | 3 | * VBoxManage - Implementation of the controlvm command.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
[57358] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[1] | 32 | #include <VBox/com/com.h>
|
---|
| 33 | #include <VBox/com/string.h>
|
---|
| 34 | #include <VBox/com/Guid.h>
|
---|
[7379] | 35 | #include <VBox/com/array.h>
|
---|
[1] | 36 | #include <VBox/com/ErrorInfo.h>
|
---|
[20928] | 37 | #include <VBox/com/errorprint.h>
|
---|
[1] | 38 | #include <VBox/com/VirtualBox.h>
|
---|
| 39 |
|
---|
[14619] | 40 | #include <iprt/ctype.h>
|
---|
[24903] | 41 | #include <iprt/getopt.h>
|
---|
[1] | 42 | #include <iprt/stream.h>
|
---|
| 43 | #include <iprt/string.h>
|
---|
[64907] | 44 | #include <iprt/thread.h>
|
---|
[1] | 45 | #include <iprt/uuid.h>
|
---|
[36720] | 46 | #include <iprt/file.h>
|
---|
[14814] | 47 | #include <VBox/log.h>
|
---|
[1] | 48 |
|
---|
| 49 | #include "VBoxManage.h"
|
---|
[88079] | 50 | #include "VBoxManageUtils.h"
|
---|
[1] | 51 |
|
---|
[32701] | 52 | #include <list>
|
---|
[1] | 53 |
|
---|
[93708] | 54 | DECLARE_TRANSLATION_CONTEXT(ControlVM);
|
---|
[92372] | 55 |
|
---|
[18396] | 56 | /**
|
---|
[3494] | 57 | * Parses a number.
|
---|
[1] | 58 | *
|
---|
[3494] | 59 | * @returns Valid number on success.
|
---|
[33540] | 60 | * @returns 0 if invalid number. All necessary bitching has been done.
|
---|
[1] | 61 | * @param psz Pointer to the nic number.
|
---|
| 62 | */
|
---|
[24903] | 63 | static unsigned parseNum(const char *psz, unsigned cMaxNum, const char *name)
|
---|
[1] | 64 | {
|
---|
| 65 | uint32_t u32;
|
---|
| 66 | char *pszNext;
|
---|
[98298] | 67 | int vrc = RTStrToUInt32Ex(psz, &pszNext, 10, &u32);
|
---|
| 68 | if ( RT_SUCCESS(vrc)
|
---|
[1] | 69 | && *pszNext == '\0'
|
---|
| 70 | && u32 >= 1
|
---|
[3494] | 71 | && u32 <= cMaxNum)
|
---|
[1] | 72 | return (unsigned)u32;
|
---|
[93708] | 73 | errorArgument(ControlVM::tr("Invalid %s number '%s'."), name, psz);
|
---|
[1] | 74 | return 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[64906] | 77 | #define KBDCHARDEF_MOD_NONE 0x00
|
---|
| 78 | #define KBDCHARDEF_MOD_SHIFT 0x01
|
---|
[35761] | 79 |
|
---|
[64906] | 80 | typedef struct KBDCHARDEF
|
---|
| 81 | {
|
---|
| 82 | uint8_t u8Scancode;
|
---|
| 83 | uint8_t u8Modifiers;
|
---|
| 84 | } KBDCHARDEF;
|
---|
| 85 |
|
---|
| 86 | static const KBDCHARDEF g_aASCIIChars[0x80] =
|
---|
| 87 | {
|
---|
| 88 | /* 0x00 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 89 | /* 0x01 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 90 | /* 0x02 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 91 | /* 0x03 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 92 | /* 0x04 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 93 | /* 0x05 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 94 | /* 0x06 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 95 | /* 0x07 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 96 | /* 0x08 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
[65399] | 97 | /* 0x09 ' ' */ {0x0f, KBDCHARDEF_MOD_NONE},
|
---|
[64906] | 98 | /* 0x0A ' ' */ {0x1c, KBDCHARDEF_MOD_NONE},
|
---|
| 99 | /* 0x0B ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 100 | /* 0x0C ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 101 | /* 0x0D ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 102 | /* 0x0E ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 103 | /* 0x0F ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 104 | /* 0x10 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 105 | /* 0x11 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 106 | /* 0x12 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 107 | /* 0x13 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 108 | /* 0x14 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 109 | /* 0x15 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 110 | /* 0x16 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 111 | /* 0x17 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 112 | /* 0x18 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 113 | /* 0x19 ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 114 | /* 0x1A ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 115 | /* 0x1B ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 116 | /* 0x1C ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 117 | /* 0x1D ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 118 | /* 0x1E ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 119 | /* 0x1F ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 120 | /* 0x20 ' ' */ {0x39, KBDCHARDEF_MOD_NONE},
|
---|
[65399] | 121 | /* 0x21 '!' */ {0x02, KBDCHARDEF_MOD_SHIFT},
|
---|
[64906] | 122 | /* 0x22 '"' */ {0x28, KBDCHARDEF_MOD_SHIFT},
|
---|
| 123 | /* 0x23 '#' */ {0x04, KBDCHARDEF_MOD_SHIFT},
|
---|
| 124 | /* 0x24 '$' */ {0x05, KBDCHARDEF_MOD_SHIFT},
|
---|
| 125 | /* 0x25 '%' */ {0x06, KBDCHARDEF_MOD_SHIFT},
|
---|
| 126 | /* 0x26 '&' */ {0x08, KBDCHARDEF_MOD_SHIFT},
|
---|
| 127 | /* 0x27 ''' */ {0x28, KBDCHARDEF_MOD_NONE},
|
---|
| 128 | /* 0x28 '(' */ {0x0a, KBDCHARDEF_MOD_SHIFT},
|
---|
| 129 | /* 0x29 ')' */ {0x0b, KBDCHARDEF_MOD_SHIFT},
|
---|
| 130 | /* 0x2A '*' */ {0x09, KBDCHARDEF_MOD_SHIFT},
|
---|
| 131 | /* 0x2B '+' */ {0x0d, KBDCHARDEF_MOD_SHIFT},
|
---|
| 132 | /* 0x2C ',' */ {0x33, KBDCHARDEF_MOD_NONE},
|
---|
| 133 | /* 0x2D '-' */ {0x0c, KBDCHARDEF_MOD_NONE},
|
---|
| 134 | /* 0x2E '.' */ {0x34, KBDCHARDEF_MOD_NONE},
|
---|
| 135 | /* 0x2F '/' */ {0x35, KBDCHARDEF_MOD_NONE},
|
---|
| 136 | /* 0x30 '0' */ {0x0b, KBDCHARDEF_MOD_NONE},
|
---|
| 137 | /* 0x31 '1' */ {0x02, KBDCHARDEF_MOD_NONE},
|
---|
| 138 | /* 0x32 '2' */ {0x03, KBDCHARDEF_MOD_NONE},
|
---|
| 139 | /* 0x33 '3' */ {0x04, KBDCHARDEF_MOD_NONE},
|
---|
| 140 | /* 0x34 '4' */ {0x05, KBDCHARDEF_MOD_NONE},
|
---|
| 141 | /* 0x35 '5' */ {0x06, KBDCHARDEF_MOD_NONE},
|
---|
| 142 | /* 0x36 '6' */ {0x07, KBDCHARDEF_MOD_NONE},
|
---|
| 143 | /* 0x37 '7' */ {0x08, KBDCHARDEF_MOD_NONE},
|
---|
| 144 | /* 0x38 '8' */ {0x09, KBDCHARDEF_MOD_NONE},
|
---|
| 145 | /* 0x39 '9' */ {0x0a, KBDCHARDEF_MOD_NONE},
|
---|
| 146 | /* 0x3A ':' */ {0x27, KBDCHARDEF_MOD_SHIFT},
|
---|
| 147 | /* 0x3B ';' */ {0x27, KBDCHARDEF_MOD_NONE},
|
---|
| 148 | /* 0x3C '<' */ {0x33, KBDCHARDEF_MOD_SHIFT},
|
---|
| 149 | /* 0x3D '=' */ {0x0d, KBDCHARDEF_MOD_NONE},
|
---|
| 150 | /* 0x3E '>' */ {0x34, KBDCHARDEF_MOD_SHIFT},
|
---|
| 151 | /* 0x3F '?' */ {0x35, KBDCHARDEF_MOD_SHIFT},
|
---|
| 152 | /* 0x40 '@' */ {0x03, KBDCHARDEF_MOD_SHIFT},
|
---|
| 153 | /* 0x41 'A' */ {0x1e, KBDCHARDEF_MOD_SHIFT},
|
---|
| 154 | /* 0x42 'B' */ {0x30, KBDCHARDEF_MOD_SHIFT},
|
---|
| 155 | /* 0x43 'C' */ {0x2e, KBDCHARDEF_MOD_SHIFT},
|
---|
| 156 | /* 0x44 'D' */ {0x20, KBDCHARDEF_MOD_SHIFT},
|
---|
| 157 | /* 0x45 'E' */ {0x12, KBDCHARDEF_MOD_SHIFT},
|
---|
| 158 | /* 0x46 'F' */ {0x21, KBDCHARDEF_MOD_SHIFT},
|
---|
| 159 | /* 0x47 'G' */ {0x22, KBDCHARDEF_MOD_SHIFT},
|
---|
| 160 | /* 0x48 'H' */ {0x23, KBDCHARDEF_MOD_SHIFT},
|
---|
| 161 | /* 0x49 'I' */ {0x17, KBDCHARDEF_MOD_SHIFT},
|
---|
| 162 | /* 0x4A 'J' */ {0x24, KBDCHARDEF_MOD_SHIFT},
|
---|
| 163 | /* 0x4B 'K' */ {0x25, KBDCHARDEF_MOD_SHIFT},
|
---|
| 164 | /* 0x4C 'L' */ {0x26, KBDCHARDEF_MOD_SHIFT},
|
---|
| 165 | /* 0x4D 'M' */ {0x32, KBDCHARDEF_MOD_SHIFT},
|
---|
| 166 | /* 0x4E 'N' */ {0x31, KBDCHARDEF_MOD_SHIFT},
|
---|
| 167 | /* 0x4F 'O' */ {0x18, KBDCHARDEF_MOD_SHIFT},
|
---|
| 168 | /* 0x50 'P' */ {0x19, KBDCHARDEF_MOD_SHIFT},
|
---|
| 169 | /* 0x51 'Q' */ {0x10, KBDCHARDEF_MOD_SHIFT},
|
---|
| 170 | /* 0x52 'R' */ {0x13, KBDCHARDEF_MOD_SHIFT},
|
---|
| 171 | /* 0x53 'S' */ {0x1f, KBDCHARDEF_MOD_SHIFT},
|
---|
| 172 | /* 0x54 'T' */ {0x14, KBDCHARDEF_MOD_SHIFT},
|
---|
| 173 | /* 0x55 'U' */ {0x16, KBDCHARDEF_MOD_SHIFT},
|
---|
| 174 | /* 0x56 'V' */ {0x2f, KBDCHARDEF_MOD_SHIFT},
|
---|
| 175 | /* 0x57 'W' */ {0x11, KBDCHARDEF_MOD_SHIFT},
|
---|
| 176 | /* 0x58 'X' */ {0x2d, KBDCHARDEF_MOD_SHIFT},
|
---|
| 177 | /* 0x59 'Y' */ {0x15, KBDCHARDEF_MOD_SHIFT},
|
---|
| 178 | /* 0x5A 'Z' */ {0x2c, KBDCHARDEF_MOD_SHIFT},
|
---|
| 179 | /* 0x5B '[' */ {0x1a, KBDCHARDEF_MOD_NONE},
|
---|
| 180 | /* 0x5C '\' */ {0x2b, KBDCHARDEF_MOD_NONE},
|
---|
| 181 | /* 0x5D ']' */ {0x1b, KBDCHARDEF_MOD_NONE},
|
---|
| 182 | /* 0x5E '^' */ {0x07, KBDCHARDEF_MOD_SHIFT},
|
---|
| 183 | /* 0x5F '_' */ {0x0c, KBDCHARDEF_MOD_SHIFT},
|
---|
| 184 | /* 0x60 '`' */ {0x28, KBDCHARDEF_MOD_NONE},
|
---|
| 185 | /* 0x61 'a' */ {0x1e, KBDCHARDEF_MOD_NONE},
|
---|
| 186 | /* 0x62 'b' */ {0x30, KBDCHARDEF_MOD_NONE},
|
---|
| 187 | /* 0x63 'c' */ {0x2e, KBDCHARDEF_MOD_NONE},
|
---|
| 188 | /* 0x64 'd' */ {0x20, KBDCHARDEF_MOD_NONE},
|
---|
| 189 | /* 0x65 'e' */ {0x12, KBDCHARDEF_MOD_NONE},
|
---|
| 190 | /* 0x66 'f' */ {0x21, KBDCHARDEF_MOD_NONE},
|
---|
| 191 | /* 0x67 'g' */ {0x22, KBDCHARDEF_MOD_NONE},
|
---|
| 192 | /* 0x68 'h' */ {0x23, KBDCHARDEF_MOD_NONE},
|
---|
| 193 | /* 0x69 'i' */ {0x17, KBDCHARDEF_MOD_NONE},
|
---|
| 194 | /* 0x6A 'j' */ {0x24, KBDCHARDEF_MOD_NONE},
|
---|
| 195 | /* 0x6B 'k' */ {0x25, KBDCHARDEF_MOD_NONE},
|
---|
| 196 | /* 0x6C 'l' */ {0x26, KBDCHARDEF_MOD_NONE},
|
---|
| 197 | /* 0x6D 'm' */ {0x32, KBDCHARDEF_MOD_NONE},
|
---|
| 198 | /* 0x6E 'n' */ {0x31, KBDCHARDEF_MOD_NONE},
|
---|
| 199 | /* 0x6F 'o' */ {0x18, KBDCHARDEF_MOD_NONE},
|
---|
| 200 | /* 0x70 'p' */ {0x19, KBDCHARDEF_MOD_NONE},
|
---|
| 201 | /* 0x71 'q' */ {0x10, KBDCHARDEF_MOD_NONE},
|
---|
| 202 | /* 0x72 'r' */ {0x13, KBDCHARDEF_MOD_NONE},
|
---|
| 203 | /* 0x73 's' */ {0x1f, KBDCHARDEF_MOD_NONE},
|
---|
| 204 | /* 0x74 't' */ {0x14, KBDCHARDEF_MOD_NONE},
|
---|
| 205 | /* 0x75 'u' */ {0x16, KBDCHARDEF_MOD_NONE},
|
---|
| 206 | /* 0x76 'v' */ {0x2f, KBDCHARDEF_MOD_NONE},
|
---|
| 207 | /* 0x77 'w' */ {0x11, KBDCHARDEF_MOD_NONE},
|
---|
| 208 | /* 0x78 'x' */ {0x2d, KBDCHARDEF_MOD_NONE},
|
---|
| 209 | /* 0x79 'y' */ {0x15, KBDCHARDEF_MOD_NONE},
|
---|
| 210 | /* 0x7A 'z' */ {0x2c, KBDCHARDEF_MOD_NONE},
|
---|
| 211 | /* 0x7B '{' */ {0x1a, KBDCHARDEF_MOD_SHIFT},
|
---|
| 212 | /* 0x7C '|' */ {0x2b, KBDCHARDEF_MOD_SHIFT},
|
---|
| 213 | /* 0x7D '}' */ {0x1b, KBDCHARDEF_MOD_SHIFT},
|
---|
| 214 | /* 0x7E '~' */ {0x29, KBDCHARDEF_MOD_SHIFT},
|
---|
| 215 | /* 0x7F ' ' */ {0x00, KBDCHARDEF_MOD_NONE},
|
---|
| 216 | };
|
---|
| 217 |
|
---|
| 218 | static HRESULT keyboardPutScancodes(IKeyboard *pKeyboard, const std::list<LONG> &llScancodes)
|
---|
| 219 | {
|
---|
| 220 | /* Send scancodes to the VM. */
|
---|
| 221 | com::SafeArray<LONG> saScancodes(llScancodes);
|
---|
| 222 |
|
---|
[95140] | 223 | HRESULT hrc = S_OK;
|
---|
[64907] | 224 | size_t i;
|
---|
[64906] | 225 | for (i = 0; i < saScancodes.size(); ++i)
|
---|
| 226 | {
|
---|
[95140] | 227 | hrc = pKeyboard->PutScancode(saScancodes[i]);
|
---|
| 228 | if (FAILED(hrc))
|
---|
[64906] | 229 | {
|
---|
[93708] | 230 | RTMsgError(ControlVM::tr("Failed to send a scancode."));
|
---|
[64906] | 231 | break;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | RTThreadSleep(10); /* "Typing" too fast causes lost characters. */
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[95140] | 237 | return hrc;
|
---|
[64906] | 238 | }
|
---|
| 239 |
|
---|
| 240 | static void keyboardCharsToScancodes(const char *pch, size_t cchMax, std::list<LONG> &llScancodes, bool *pfShift)
|
---|
| 241 | {
|
---|
| 242 | size_t cchProcessed = 0;
|
---|
| 243 | const char *p = pch;
|
---|
| 244 | while (cchProcessed < cchMax)
|
---|
| 245 | {
|
---|
| 246 | ++cchProcessed;
|
---|
| 247 | const uint8_t c = (uint8_t)*p++;
|
---|
| 248 | if (c < RT_ELEMENTS(g_aASCIIChars))
|
---|
| 249 | {
|
---|
| 250 | const KBDCHARDEF *d = &g_aASCIIChars[c];
|
---|
| 251 | if (d->u8Scancode)
|
---|
| 252 | {
|
---|
| 253 | const bool fNeedShift = RT_BOOL(d->u8Modifiers & KBDCHARDEF_MOD_SHIFT);
|
---|
| 254 | if (*pfShift != fNeedShift)
|
---|
| 255 | {
|
---|
| 256 | *pfShift = fNeedShift;
|
---|
| 257 | /* Press or release the SHIFT key. */
|
---|
| 258 | llScancodes.push_back(0x2a | (fNeedShift? 0x00: 0x80));
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | llScancodes.push_back(d->u8Scancode);
|
---|
| 262 | llScancodes.push_back(d->u8Scancode | 0x80);
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | static HRESULT keyboardPutString(IKeyboard *pKeyboard, int argc, char **argv)
|
---|
| 269 | {
|
---|
| 270 | std::list<LONG> llScancodes;
|
---|
| 271 | bool fShift = false;
|
---|
| 272 |
|
---|
| 273 | /* Convert command line string(s) to the en-us keyboard scancodes. */
|
---|
| 274 | int i;
|
---|
| 275 | for (i = 1 + 1; i < argc; ++i)
|
---|
| 276 | {
|
---|
[72826] | 277 | if (!llScancodes.empty())
|
---|
[64906] | 278 | {
|
---|
| 279 | /* Insert a SPACE before the next string. */
|
---|
| 280 | llScancodes.push_back(0x39);
|
---|
| 281 | llScancodes.push_back(0x39 | 0x80);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | keyboardCharsToScancodes(argv[i], strlen(argv[i]), llScancodes, &fShift);
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | /* Release SHIFT if pressed. */
|
---|
| 288 | if (fShift)
|
---|
| 289 | llScancodes.push_back(0x2a | 0x80);
|
---|
| 290 |
|
---|
| 291 | return keyboardPutScancodes(pKeyboard, llScancodes);
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | static HRESULT keyboardPutFile(IKeyboard *pKeyboard, const char *pszFilename)
|
---|
| 295 | {
|
---|
| 296 | std::list<LONG> llScancodes;
|
---|
| 297 | bool fShift = false;
|
---|
| 298 |
|
---|
| 299 | RTFILE File = NIL_RTFILE;
|
---|
| 300 | int vrc = RTFileOpen(&File, pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
|
---|
| 301 | if (RT_SUCCESS(vrc))
|
---|
| 302 | {
|
---|
| 303 | uint64_t cbFile = 0;
|
---|
[80585] | 304 | vrc = RTFileQuerySize(File, &cbFile);
|
---|
[64906] | 305 | if (RT_SUCCESS(vrc))
|
---|
| 306 | {
|
---|
| 307 | const uint64_t cbFileMax = _64K;
|
---|
| 308 | if (cbFile <= cbFileMax)
|
---|
| 309 | {
|
---|
| 310 | const size_t cbBuffer = _4K;
|
---|
| 311 | char *pchBuf = (char *)RTMemAlloc(cbBuffer);
|
---|
| 312 | if (pchBuf)
|
---|
| 313 | {
|
---|
| 314 | size_t cbRemaining = (size_t)cbFile;
|
---|
| 315 | while (cbRemaining > 0)
|
---|
| 316 | {
|
---|
| 317 | const size_t cbToRead = cbRemaining > cbBuffer ? cbBuffer : cbRemaining;
|
---|
| 318 |
|
---|
| 319 | size_t cbRead = 0;
|
---|
| 320 | vrc = RTFileRead(File, pchBuf, cbToRead, &cbRead);
|
---|
| 321 | if (RT_FAILURE(vrc) || cbRead == 0)
|
---|
| 322 | break;
|
---|
| 323 |
|
---|
| 324 | keyboardCharsToScancodes(pchBuf, cbRead, llScancodes, &fShift);
|
---|
| 325 | cbRemaining -= cbRead;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | RTMemFree(pchBuf);
|
---|
| 329 | }
|
---|
| 330 | else
|
---|
[93708] | 331 | RTMsgError(ControlVM::tr("Out of memory allocating %d bytes.", "", cbBuffer), cbBuffer);
|
---|
[64906] | 332 | }
|
---|
| 333 | else
|
---|
[93708] | 334 | RTMsgError(ControlVM::tr("File size %RI64 is greater than %RI64: '%s'."), cbFile, cbFileMax, pszFilename);
|
---|
[64906] | 335 | }
|
---|
| 336 | else
|
---|
[93708] | 337 | RTMsgError(ControlVM::tr("Cannot get size of file '%s': %Rrc."), pszFilename, vrc);
|
---|
[64906] | 338 |
|
---|
| 339 | RTFileClose(File);
|
---|
| 340 | }
|
---|
| 341 | else
|
---|
[93708] | 342 | RTMsgError(ControlVM::tr("Cannot open file '%s': %Rrc."), pszFilename, vrc);
|
---|
[64906] | 343 |
|
---|
| 344 | /* Release SHIFT if pressed. */
|
---|
| 345 | if (fShift)
|
---|
| 346 | llScancodes.push_back(0x2a | 0x80);
|
---|
| 347 |
|
---|
| 348 | return keyboardPutScancodes(pKeyboard, llScancodes);
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 |
|
---|
[56118] | 352 | RTEXITCODE handleControlVM(HandlerArg *a)
|
---|
[18782] | 353 | {
|
---|
[24903] | 354 | using namespace com;
|
---|
[54523] | 355 | bool fNeedsSaving = false;
|
---|
[95140] | 356 | HRESULT hrc;
|
---|
[1] | 357 |
|
---|
[16052] | 358 | if (a->argc < 2)
|
---|
[93708] | 359 | return errorSyntax(ControlVM::tr("Not enough parameters."));
|
---|
[1] | 360 |
|
---|
| 361 | /* try to find the given machine */
|
---|
[47908] | 362 | ComPtr<IMachine> machine;
|
---|
[33294] | 363 | CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
|
---|
| 364 | machine.asOutParam()));
|
---|
[95140] | 365 | if (FAILED(hrc))
|
---|
[56118] | 366 | return RTEXITCODE_FAILURE;
|
---|
[1] | 367 |
|
---|
| 368 | /* open a session for the VM */
|
---|
[56118] | 369 | CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE);
|
---|
[1] | 370 |
|
---|
[54523] | 371 | ComPtr<IConsole> console;
|
---|
| 372 | ComPtr<IMachine> sessionMachine;
|
---|
| 373 |
|
---|
[1] | 374 | do
|
---|
| 375 | {
|
---|
| 376 | /* get the associated console */
|
---|
[23934] | 377 | CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
|
---|
[75251] | 378 | if (!console)
|
---|
[93708] | 379 | return RTMsgErrorExit(RTEXITCODE_FAILURE, ControlVM::tr("Machine '%s' is not currently running."), a->argv[0]);
|
---|
[75251] | 380 |
|
---|
[1] | 381 | /* ... and session machine */
|
---|
[23934] | 382 | CHECK_ERROR_BREAK(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()));
|
---|
[1] | 383 |
|
---|
| 384 | /* which command? */
|
---|
[18782] | 385 | if (!strcmp(a->argv[1], "pause"))
|
---|
[1] | 386 | {
|
---|
[93708] | 387 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_PAUSE);
|
---|
[23934] | 388 | CHECK_ERROR_BREAK(console, Pause());
|
---|
[1] | 389 | }
|
---|
[18782] | 390 | else if (!strcmp(a->argv[1], "resume"))
|
---|
[1] | 391 | {
|
---|
[93708] | 392 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RESUME);
|
---|
[23934] | 393 | CHECK_ERROR_BREAK(console, Resume());
|
---|
[1] | 394 | }
|
---|
[18782] | 395 | else if (!strcmp(a->argv[1], "reset"))
|
---|
[1] | 396 | {
|
---|
[93708] | 397 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RESET);
|
---|
[23934] | 398 | CHECK_ERROR_BREAK(console, Reset());
|
---|
[1] | 399 | }
|
---|
[25901] | 400 | else if (!strcmp(a->argv[1], "unplugcpu"))
|
---|
| 401 | {
|
---|
[93708] | 402 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_UNPLUGCPU);
|
---|
[25901] | 403 | if (a->argc <= 1 + 1)
|
---|
| 404 | {
|
---|
[93708] | 405 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 406 | hrc = E_FAIL;
|
---|
[25901] | 407 | break;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | unsigned n = parseNum(a->argv[2], 32, "CPU");
|
---|
| 411 |
|
---|
| 412 | CHECK_ERROR_BREAK(sessionMachine, HotUnplugCPU(n));
|
---|
| 413 | }
|
---|
| 414 | else if (!strcmp(a->argv[1], "plugcpu"))
|
---|
| 415 | {
|
---|
[93708] | 416 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_PLUGCPU);
|
---|
[25901] | 417 | if (a->argc <= 1 + 1)
|
---|
| 418 | {
|
---|
[93708] | 419 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 420 | hrc = E_FAIL;
|
---|
[25901] | 421 | break;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | unsigned n = parseNum(a->argv[2], 32, "CPU");
|
---|
| 425 |
|
---|
| 426 | CHECK_ERROR_BREAK(sessionMachine, HotPlugCPU(n));
|
---|
| 427 | }
|
---|
[32885] | 428 | else if (!strcmp(a->argv[1], "cpuexecutioncap"))
|
---|
| 429 | {
|
---|
[93708] | 430 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_CPUEXECUTIONCAP);
|
---|
[32885] | 431 | if (a->argc <= 1 + 1)
|
---|
| 432 | {
|
---|
[93708] | 433 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 434 | hrc = E_FAIL;
|
---|
[32885] | 435 | break;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | unsigned n = parseNum(a->argv[2], 100, "ExecutionCap");
|
---|
| 439 |
|
---|
[34604] | 440 | CHECK_ERROR_BREAK(sessionMachine, COMSETTER(CPUExecutionCap)(n));
|
---|
[32885] | 441 | }
|
---|
[68485] | 442 | else if (!strcmp(a->argv[1], "audioin"))
|
---|
| 443 | {
|
---|
[93708] | 444 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_AUDIOIN);
|
---|
[95423] | 445 |
|
---|
| 446 | ComPtr<IAudioSettings> audioSettings;
|
---|
| 447 | CHECK_ERROR_BREAK(sessionMachine, COMGETTER(AudioSettings)(audioSettings.asOutParam()));
|
---|
[68485] | 448 | ComPtr<IAudioAdapter> adapter;
|
---|
[95423] | 449 | CHECK_ERROR_BREAK(audioSettings, COMGETTER(Adapter)(adapter.asOutParam()));
|
---|
[68485] | 450 | if (adapter)
|
---|
| 451 | {
|
---|
[93708] | 452 | bool fEnabled;
|
---|
| 453 | if (RT_FAILURE(parseBool(a->argv[2], &fEnabled)))
|
---|
[68485] | 454 | {
|
---|
[93708] | 455 | errorSyntax(ControlVM::tr("Invalid value '%s'."), a->argv[2]);
|
---|
[95140] | 456 | hrc = E_FAIL;
|
---|
[68485] | 457 | break;
|
---|
| 458 | }
|
---|
[93708] | 459 | CHECK_ERROR_RET(adapter, COMSETTER(EnabledIn)(fEnabled), RTEXITCODE_FAILURE);
|
---|
| 460 | fNeedsSaving = true;
|
---|
[68485] | 461 | }
|
---|
| 462 | else
|
---|
| 463 | {
|
---|
[93708] | 464 | errorSyntax(ControlVM::tr("Audio adapter not enabled in VM configuration."));
|
---|
[95140] | 465 | hrc = E_FAIL;
|
---|
[68485] | 466 | break;
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 | else if (!strcmp(a->argv[1], "audioout"))
|
---|
| 470 | {
|
---|
[93708] | 471 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_AUDIOOUT);
|
---|
[95423] | 472 |
|
---|
| 473 | ComPtr<IAudioSettings> audioSettings;
|
---|
| 474 | CHECK_ERROR_BREAK(sessionMachine, COMGETTER(AudioSettings)(audioSettings.asOutParam()));
|
---|
[68485] | 475 | ComPtr<IAudioAdapter> adapter;
|
---|
[95423] | 476 | CHECK_ERROR_BREAK(audioSettings, COMGETTER(Adapter)(adapter.asOutParam()));
|
---|
[68485] | 477 | if (adapter)
|
---|
| 478 | {
|
---|
[93708] | 479 | bool fEnabled;
|
---|
| 480 | if (RT_FAILURE(parseBool(a->argv[2], &fEnabled)))
|
---|
[68485] | 481 | {
|
---|
[93708] | 482 | errorSyntax(ControlVM::tr("Invalid value '%s'."), a->argv[2]);
|
---|
[95140] | 483 | hrc = E_FAIL;
|
---|
[68485] | 484 | break;
|
---|
| 485 | }
|
---|
[93708] | 486 | CHECK_ERROR_RET(adapter, COMSETTER(EnabledOut)(fEnabled), RTEXITCODE_FAILURE);
|
---|
| 487 | fNeedsSaving = true;
|
---|
[68485] | 488 | }
|
---|
| 489 | else
|
---|
| 490 | {
|
---|
[93708] | 491 | errorSyntax(ControlVM::tr("Audio adapter not enabled in VM configuration."));
|
---|
[95140] | 492 | hrc = E_FAIL;
|
---|
[68485] | 493 | break;
|
---|
| 494 | }
|
---|
| 495 | }
|
---|
[81287] | 496 | #ifdef VBOX_WITH_SHARED_CLIPBOARD
|
---|
[41925] | 497 | else if (!strcmp(a->argv[1], "clipboard"))
|
---|
| 498 | {
|
---|
| 499 | if (a->argc <= 1 + 1)
|
---|
| 500 | {
|
---|
[93708] | 501 | errorArgument(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 502 | hrc = E_FAIL;
|
---|
[41925] | 503 | break;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
[63300] | 506 | ClipboardMode_T mode = ClipboardMode_Disabled; /* Shut up MSC */
|
---|
[81287] | 507 | if (!strcmp(a->argv[2], "mode"))
|
---|
[41925] | 508 | {
|
---|
[93708] | 509 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_CLIPBOARD_MODE);
|
---|
| 510 | if (a->argc <= 1 + 2)
|
---|
| 511 | {
|
---|
| 512 | errorSyntax(ControlVM::tr("Missing argument to '%s %s'."), a->argv[1], a->argv[2]);
|
---|
[95140] | 513 | hrc = E_FAIL;
|
---|
[93708] | 514 | break;
|
---|
| 515 | }
|
---|
| 516 |
|
---|
[81287] | 517 | if (!strcmp(a->argv[3], "disabled"))
|
---|
| 518 | mode = ClipboardMode_Disabled;
|
---|
| 519 | else if (!strcmp(a->argv[3], "hosttoguest"))
|
---|
| 520 | mode = ClipboardMode_HostToGuest;
|
---|
| 521 | else if (!strcmp(a->argv[3], "guesttohost"))
|
---|
| 522 | mode = ClipboardMode_GuestToHost;
|
---|
| 523 | else if (!strcmp(a->argv[3], "bidirectional"))
|
---|
| 524 | mode = ClipboardMode_Bidirectional;
|
---|
| 525 | else
|
---|
| 526 | {
|
---|
[93708] | 527 | errorSyntax(ControlVM::tr("Invalid '%s %s' argument '%s'."), a->argv[1], a->argv[2], a->argv[3]);
|
---|
[95140] | 528 | hrc = E_FAIL;
|
---|
[81287] | 529 | break;
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | CHECK_ERROR_BREAK(sessionMachine, COMSETTER(ClipboardMode)(mode));
|
---|
[95140] | 533 | if (SUCCEEDED(hrc))
|
---|
[81287] | 534 | fNeedsSaving = true;
|
---|
[41925] | 535 | }
|
---|
[81287] | 536 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
| 537 | else if (!strcmp(a->argv[2], "filetransfers"))
|
---|
[41925] | 538 | {
|
---|
[93708] | 539 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_CLIPBOARD_FILETRANSFERS);
|
---|
[81287] | 540 | if (a->argc <= 1 + 2)
|
---|
| 541 | {
|
---|
[93708] | 542 | errorSyntax(ControlVM::tr("Missing argument to '%s %s'."), a->argv[1], a->argv[2]);
|
---|
[95140] | 543 | hrc = E_FAIL;
|
---|
[81287] | 544 | break;
|
---|
| 545 | }
|
---|
| 546 |
|
---|
[93708] | 547 | bool fEnabled;
|
---|
| 548 | if (RT_FAILURE(parseBool(a->argv[3], &fEnabled)))
|
---|
[81287] | 549 | {
|
---|
[93708] | 550 | errorSyntax(ControlVM::tr("Invalid '%s %s' argument '%s'."), a->argv[1], a->argv[2], a->argv[3]);
|
---|
[95140] | 551 | hrc = E_FAIL;
|
---|
[81287] | 552 | break;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | CHECK_ERROR_BREAK(sessionMachine, COMSETTER(ClipboardFileTransfersEnabled)(fEnabled));
|
---|
[93708] | 556 | fNeedsSaving = true;
|
---|
[41925] | 557 | }
|
---|
[81287] | 558 | # endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
|
---|
[81962] | 559 | else
|
---|
| 560 | {
|
---|
[93708] | 561 | errorArgument(ControlVM::tr("Invalid '%s' argument '%s'."), a->argv[1], a->argv[2]);
|
---|
[95140] | 562 | hrc = E_FAIL;
|
---|
[81962] | 563 | break;
|
---|
| 564 | }
|
---|
[41925] | 565 | }
|
---|
[81287] | 566 | #endif /* VBOX_WITH_SHARED_CLIPBOARD */
|
---|
[42261] | 567 | else if (!strcmp(a->argv[1], "draganddrop"))
|
---|
| 568 | {
|
---|
[93708] | 569 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_DRAGANDDROP);
|
---|
[42261] | 570 | if (a->argc <= 1 + 1)
|
---|
| 571 | {
|
---|
[93708] | 572 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 573 | hrc = E_FAIL;
|
---|
[42261] | 574 | break;
|
---|
| 575 | }
|
---|
| 576 |
|
---|
[63300] | 577 | DnDMode_T mode = DnDMode_Disabled; /* Shup up MSC. */
|
---|
[42261] | 578 | if (!strcmp(a->argv[2], "disabled"))
|
---|
[51476] | 579 | mode = DnDMode_Disabled;
|
---|
[42261] | 580 | else if (!strcmp(a->argv[2], "hosttoguest"))
|
---|
[51476] | 581 | mode = DnDMode_HostToGuest;
|
---|
[42261] | 582 | else if (!strcmp(a->argv[2], "guesttohost"))
|
---|
[51476] | 583 | mode = DnDMode_GuestToHost;
|
---|
[42261] | 584 | else if (!strcmp(a->argv[2], "bidirectional"))
|
---|
[51476] | 585 | mode = DnDMode_Bidirectional;
|
---|
[42261] | 586 | else
|
---|
| 587 | {
|
---|
[93708] | 588 | errorSyntax(ControlVM::tr("Invalid '%s' argument '%s'."), a->argv[1], a->argv[2]);
|
---|
[95140] | 589 | hrc = E_FAIL;
|
---|
[42261] | 590 | }
|
---|
[95140] | 591 | if (SUCCEEDED(hrc))
|
---|
[42261] | 592 | {
|
---|
[51476] | 593 | CHECK_ERROR_BREAK(sessionMachine, COMSETTER(DnDMode)(mode));
|
---|
[95140] | 594 | if (SUCCEEDED(hrc))
|
---|
[54525] | 595 | fNeedsSaving = true;
|
---|
[42261] | 596 | }
|
---|
| 597 | }
|
---|
[18782] | 598 | else if (!strcmp(a->argv[1], "poweroff"))
|
---|
[1] | 599 | {
|
---|
[93708] | 600 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_POWEROFF);
|
---|
[20928] | 601 | ComPtr<IProgress> progress;
|
---|
[23934] | 602 | CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam()));
|
---|
[20928] | 603 |
|
---|
[95140] | 604 | hrc = showProgress(progress);
|
---|
[93708] | 605 | CHECK_PROGRESS_ERROR(progress, (ControlVM::tr("Failed to power off machine.")));
|
---|
[1] | 606 | }
|
---|
[18782] | 607 | else if (!strcmp(a->argv[1], "savestate"))
|
---|
[1] | 608 | {
|
---|
[93708] | 609 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SAVESTATE);
|
---|
[29970] | 610 | /* first pause so we don't trigger a live save which needs more time/resources */
|
---|
[41096] | 611 | bool fPaused = false;
|
---|
[95140] | 612 | hrc = console->Pause();
|
---|
| 613 | if (FAILED(hrc))
|
---|
[35707] | 614 | {
|
---|
[41096] | 615 | bool fError = true;
|
---|
[95140] | 616 | if (hrc == VBOX_E_INVALID_VM_STATE)
|
---|
[35707] | 617 | {
|
---|
| 618 | /* check if we are already paused */
|
---|
| 619 | MachineState_T machineState;
|
---|
| 620 | CHECK_ERROR_BREAK(console, COMGETTER(State)(&machineState));
|
---|
[40673] | 621 | /* the error code was lost by the previous instruction */
|
---|
[95140] | 622 | hrc = VBOX_E_INVALID_VM_STATE;
|
---|
[35707] | 623 | if (machineState != MachineState_Paused)
|
---|
| 624 | {
|
---|
[93708] | 625 | RTMsgError(ControlVM::tr("Machine in invalid state %d -- %s."),
|
---|
[35907] | 626 | machineState, machineStateToName(machineState, false));
|
---|
[35707] | 627 | }
|
---|
[41096] | 628 | else
|
---|
| 629 | {
|
---|
| 630 | fError = false;
|
---|
| 631 | fPaused = true;
|
---|
| 632 | }
|
---|
[35707] | 633 | }
|
---|
[41096] | 634 | if (fError)
|
---|
| 635 | break;
|
---|
[35707] | 636 | }
|
---|
[29970] | 637 |
|
---|
[1] | 638 | ComPtr<IProgress> progress;
|
---|
[55214] | 639 | CHECK_ERROR(sessionMachine, SaveState(progress.asOutParam()));
|
---|
[95140] | 640 | if (FAILED(hrc))
|
---|
[29979] | 641 | {
|
---|
[41096] | 642 | if (!fPaused)
|
---|
| 643 | console->Resume();
|
---|
[29979] | 644 | break;
|
---|
| 645 | }
|
---|
[1] | 646 |
|
---|
[95140] | 647 | hrc = showProgress(progress);
|
---|
[93708] | 648 | CHECK_PROGRESS_ERROR(progress, (ControlVM::tr("Failed to save machine state.")));
|
---|
[95140] | 649 | if (FAILED(hrc))
|
---|
[41096] | 650 | {
|
---|
| 651 | if (!fPaused)
|
---|
| 652 | console->Resume();
|
---|
| 653 | }
|
---|
[1] | 654 | }
|
---|
[18782] | 655 | else if (!strcmp(a->argv[1], "acpipowerbutton"))
|
---|
[1] | 656 | {
|
---|
[93708] | 657 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_ACPIPOWERBUTTON);
|
---|
[23934] | 658 | CHECK_ERROR_BREAK(console, PowerButton());
|
---|
[1] | 659 | }
|
---|
[18782] | 660 | else if (!strcmp(a->argv[1], "acpisleepbutton"))
|
---|
[6156] | 661 | {
|
---|
[93708] | 662 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_ACPISLEEPBUTTON);
|
---|
[23934] | 663 | CHECK_ERROR_BREAK(console, SleepButton());
|
---|
[6156] | 664 | }
|
---|
[84576] | 665 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
[84575] | 666 | else if ( !strcmp(a->argv[1], "reboot")
|
---|
| 667 | || !strcmp(a->argv[1], "shutdown")) /* With shutdown we mean gracefully powering off the VM by letting the guest OS do its thing. */
|
---|
| 668 | {
|
---|
[93708] | 669 | const bool fReboot = !strcmp(a->argv[1], "reboot");
|
---|
| 670 | if (fReboot)
|
---|
| 671 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_REBOOT);
|
---|
| 672 | else
|
---|
| 673 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SHUTDOWN);
|
---|
| 674 |
|
---|
[84585] | 675 | ComPtr<IGuest> pGuest;
|
---|
| 676 | CHECK_ERROR_BREAK(console, COMGETTER(Guest)(pGuest.asOutParam()));
|
---|
| 677 | if (!pGuest)
|
---|
| 678 | {
|
---|
[93708] | 679 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 680 | hrc = E_FAIL;
|
---|
[84585] | 681 | break;
|
---|
| 682 | }
|
---|
[84575] | 683 |
|
---|
| 684 | com::SafeArray<GuestShutdownFlag_T> aShutdownFlags;
|
---|
| 685 | if (fReboot)
|
---|
| 686 | aShutdownFlags.push_back(GuestShutdownFlag_Reboot);
|
---|
| 687 | else
|
---|
| 688 | aShutdownFlags.push_back(GuestShutdownFlag_PowerOff);
|
---|
[84814] | 689 |
|
---|
| 690 | if ( a->argc >= 3
|
---|
| 691 | && !strcmp(a->argv[2], "--force"))
|
---|
| 692 | aShutdownFlags.push_back(GuestShutdownFlag_Force);
|
---|
| 693 |
|
---|
[84585] | 694 | CHECK_ERROR(pGuest, Shutdown(ComSafeArrayAsInParam(aShutdownFlags)));
|
---|
[95140] | 695 | if (FAILED(hrc))
|
---|
[84575] | 696 | {
|
---|
[95140] | 697 | if (hrc == VBOX_E_NOT_SUPPORTED)
|
---|
[93708] | 698 | {
|
---|
| 699 | if (fReboot)
|
---|
| 700 | RTMsgError(ControlVM::tr("Current installed Guest Additions don't support rebooting the guest."));
|
---|
| 701 | else
|
---|
| 702 | RTMsgError(ControlVM::tr("Current installed Guest Additions don't support shutting down the guest."));
|
---|
| 703 | }
|
---|
[84575] | 704 | }
|
---|
| 705 | }
|
---|
[84576] | 706 | #endif
|
---|
[18782] | 707 | else if (!strcmp(a->argv[1], "keyboardputscancode"))
|
---|
[8675] | 708 | {
|
---|
[93708] | 709 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_KEYBOARDPUTSCANCODE);
|
---|
[45190] | 710 | ComPtr<IKeyboard> pKeyboard;
|
---|
| 711 | CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(pKeyboard.asOutParam()));
|
---|
| 712 | if (!pKeyboard)
|
---|
| 713 | {
|
---|
[93708] | 714 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 715 | hrc = E_FAIL;
|
---|
[45190] | 716 | break;
|
---|
| 717 | }
|
---|
[8675] | 718 |
|
---|
[16052] | 719 | if (a->argc <= 1 + 1)
|
---|
[8675] | 720 | {
|
---|
[93708] | 721 | errorSyntax(ControlVM::tr("Missing argument to '%s'. Expected IBM PC AT set 2 keyboard scancode(s)."),
|
---|
[92372] | 722 | a->argv[1]);
|
---|
[95140] | 723 | hrc = E_FAIL;
|
---|
[8675] | 724 | break;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
[32701] | 727 | std::list<LONG> llScancodes;
|
---|
[8675] | 728 |
|
---|
| 729 | /* Process the command line. */
|
---|
| 730 | int i;
|
---|
[32701] | 731 | for (i = 1 + 1; i < a->argc; i++)
|
---|
[8675] | 732 | {
|
---|
[16052] | 733 | if ( RT_C_IS_XDIGIT (a->argv[i][0])
|
---|
| 734 | && RT_C_IS_XDIGIT (a->argv[i][1])
|
---|
| 735 | && a->argv[i][2] == 0)
|
---|
[8675] | 736 | {
|
---|
| 737 | uint8_t u8Scancode;
|
---|
[95140] | 738 | int vrc = RTStrToUInt8Ex(a->argv[i], NULL, 16, &u8Scancode);
|
---|
| 739 | if (RT_FAILURE (vrc))
|
---|
[8675] | 740 | {
|
---|
[95140] | 741 | RTMsgError(ControlVM::tr("Converting '%s' returned %Rrc!"), a->argv[i], vrc);
|
---|
| 742 | hrc = E_FAIL;
|
---|
[8675] | 743 | break;
|
---|
| 744 | }
|
---|
| 745 |
|
---|
[32701] | 746 | llScancodes.push_back(u8Scancode);
|
---|
[8675] | 747 | }
|
---|
| 748 | else
|
---|
| 749 | {
|
---|
[93708] | 750 | RTMsgError(ControlVM::tr("'%s' is not a hex byte!"), a->argv[i]);
|
---|
[95140] | 751 | hrc = E_FAIL;
|
---|
[8675] | 752 | break;
|
---|
| 753 | }
|
---|
| 754 | }
|
---|
| 755 |
|
---|
[95140] | 756 | if (FAILED(hrc))
|
---|
[8675] | 757 | break;
|
---|
| 758 |
|
---|
[95140] | 759 | hrc = keyboardPutScancodes(pKeyboard, llScancodes);
|
---|
[64906] | 760 | }
|
---|
| 761 | else if (!strcmp(a->argv[1], "keyboardputstring"))
|
---|
| 762 | {
|
---|
[93708] | 763 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_KEYBOARDPUTSTRING);
|
---|
[64906] | 764 | ComPtr<IKeyboard> pKeyboard;
|
---|
| 765 | CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(pKeyboard.asOutParam()));
|
---|
| 766 | if (!pKeyboard)
|
---|
[8675] | 767 | {
|
---|
[93708] | 768 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 769 | hrc = E_FAIL;
|
---|
[8675] | 770 | break;
|
---|
| 771 | }
|
---|
[64906] | 772 |
|
---|
| 773 | if (a->argc <= 1 + 1)
|
---|
| 774 | {
|
---|
[93708] | 775 | errorSyntax(ControlVM::tr("Missing argument to '%s'. Expected ASCII string(s)."), a->argv[1]);
|
---|
[95140] | 776 | hrc = E_FAIL;
|
---|
[64906] | 777 | break;
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[95140] | 780 | hrc = keyboardPutString(pKeyboard, a->argc, a->argv);
|
---|
[8675] | 781 | }
|
---|
[64906] | 782 | else if (!strcmp(a->argv[1], "keyboardputfile"))
|
---|
| 783 | {
|
---|
[93708] | 784 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_KEYBOARDPUTFILE);
|
---|
[64906] | 785 | ComPtr<IKeyboard> pKeyboard;
|
---|
| 786 | CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(pKeyboard.asOutParam()));
|
---|
| 787 | if (!pKeyboard)
|
---|
| 788 | {
|
---|
[93708] | 789 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 790 | hrc = E_FAIL;
|
---|
[64906] | 791 | break;
|
---|
| 792 | }
|
---|
| 793 |
|
---|
| 794 | if (a->argc <= 1 + 1)
|
---|
| 795 | {
|
---|
[93708] | 796 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 797 | hrc = E_FAIL;
|
---|
[64906] | 798 | break;
|
---|
| 799 | }
|
---|
| 800 |
|
---|
[95140] | 801 | hrc = keyboardPutFile(pKeyboard, a->argv[2]);
|
---|
[64906] | 802 | }
|
---|
[18782] | 803 | else if (!strncmp(a->argv[1], "setlinkstate", 12))
|
---|
[1] | 804 | {
|
---|
[93708] | 805 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SETLINKSTATE);
|
---|
[1] | 806 | /* Get the number of network adapters */
|
---|
[101035] | 807 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[16052] | 808 | unsigned n = parseNum(&a->argv[1][12], NetworkAdapterCount, "NIC");
|
---|
[1] | 809 | if (!n)
|
---|
| 810 | {
|
---|
[95140] | 811 | hrc = E_FAIL;
|
---|
[1] | 812 | break;
|
---|
| 813 | }
|
---|
[16052] | 814 | if (a->argc <= 1 + 1)
|
---|
[1] | 815 | {
|
---|
[93708] | 816 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 817 | hrc = E_FAIL;
|
---|
[1] | 818 | break;
|
---|
| 819 | }
|
---|
| 820 | /* get the corresponding network adapter */
|
---|
| 821 | ComPtr<INetworkAdapter> adapter;
|
---|
[23934] | 822 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
[1] | 823 | if (adapter)
|
---|
| 824 | {
|
---|
[93708] | 825 | bool fEnabled;
|
---|
[96907] | 826 | if (RT_FAILURE(parseBool(a->argv[2], &fEnabled)))
|
---|
[1] | 827 | {
|
---|
[93708] | 828 | errorSyntax(ControlVM::tr("Invalid link state '%s'."), a->argv[2]);
|
---|
[95140] | 829 | hrc = E_FAIL;
|
---|
[1] | 830 | break;
|
---|
| 831 | }
|
---|
[93708] | 832 | CHECK_ERROR_BREAK(adapter, COMSETTER(CableConnected)(fEnabled));
|
---|
| 833 | fNeedsSaving = true;
|
---|
[1] | 834 | }
|
---|
| 835 | }
|
---|
[23222] | 836 | /* here the order in which strncmp is called is important
|
---|
| 837 | * cause nictracefile can be very well compared with
|
---|
| 838 | * nictrace and nic and thus everything will always fail
|
---|
| 839 | * if the order is changed
|
---|
| 840 | */
|
---|
| 841 | else if (!strncmp(a->argv[1], "nictracefile", 12))
|
---|
| 842 | {
|
---|
[93708] | 843 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NICTRACEFILE);
|
---|
[23222] | 844 | /* Get the number of network adapters */
|
---|
[101035] | 845 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[23222] | 846 | unsigned n = parseNum(&a->argv[1][12], NetworkAdapterCount, "NIC");
|
---|
| 847 | if (!n)
|
---|
| 848 | {
|
---|
[95140] | 849 | hrc = E_FAIL;
|
---|
[23222] | 850 | break;
|
---|
| 851 | }
|
---|
| 852 | if (a->argc <= 2)
|
---|
| 853 | {
|
---|
[93708] | 854 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 855 | hrc = E_FAIL;
|
---|
[23222] | 856 | break;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | /* get the corresponding network adapter */
|
---|
| 860 | ComPtr<INetworkAdapter> adapter;
|
---|
[23934] | 861 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
[23222] | 862 | if (adapter)
|
---|
| 863 | {
|
---|
| 864 | BOOL fEnabled;
|
---|
| 865 | adapter->COMGETTER(Enabled)(&fEnabled);
|
---|
| 866 | if (fEnabled)
|
---|
| 867 | {
|
---|
| 868 | if (a->argv[2])
|
---|
| 869 | {
|
---|
[56118] | 870 | CHECK_ERROR_RET(adapter, COMSETTER(TraceFile)(Bstr(a->argv[2]).raw()), RTEXITCODE_FAILURE);
|
---|
[23222] | 871 | }
|
---|
| 872 | else
|
---|
| 873 | {
|
---|
[93708] | 874 | errorSyntax(ControlVM::tr("Filename not specified for NIC %lu."), n);
|
---|
[95140] | 875 | hrc = E_FAIL;
|
---|
[23222] | 876 | break;
|
---|
| 877 | }
|
---|
[95140] | 878 | if (SUCCEEDED(hrc))
|
---|
[54525] | 879 | fNeedsSaving = true;
|
---|
[23222] | 880 | }
|
---|
| 881 | else
|
---|
[93708] | 882 | RTMsgError(ControlVM::tr("The NIC %d is currently disabled and thus its tracefile can't be changed."), n);
|
---|
[23222] | 883 | }
|
---|
| 884 | }
|
---|
| 885 | else if (!strncmp(a->argv[1], "nictrace", 8))
|
---|
| 886 | {
|
---|
[93708] | 887 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NICTRACE);
|
---|
[23222] | 888 | /* Get the number of network adapters */
|
---|
[101035] | 889 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[23222] | 890 | unsigned n = parseNum(&a->argv[1][8], NetworkAdapterCount, "NIC");
|
---|
| 891 | if (!n)
|
---|
| 892 | {
|
---|
[95140] | 893 | hrc = E_FAIL;
|
---|
[23222] | 894 | break;
|
---|
| 895 | }
|
---|
| 896 | if (a->argc <= 2)
|
---|
| 897 | {
|
---|
[93708] | 898 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 899 | hrc = E_FAIL;
|
---|
[23222] | 900 | break;
|
---|
| 901 | }
|
---|
| 902 |
|
---|
| 903 | /* get the corresponding network adapter */
|
---|
| 904 | ComPtr<INetworkAdapter> adapter;
|
---|
[23934] | 905 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
[23222] | 906 | if (adapter)
|
---|
| 907 | {
|
---|
| 908 | BOOL fEnabled;
|
---|
| 909 | adapter->COMGETTER(Enabled)(&fEnabled);
|
---|
| 910 | if (fEnabled)
|
---|
| 911 | {
|
---|
[93708] | 912 | bool fTraceEnabled;
|
---|
[96907] | 913 | if (RT_FAILURE(parseBool(a->argv[2], &fTraceEnabled)))
|
---|
[23222] | 914 | {
|
---|
[93708] | 915 | errorSyntax(ControlVM::tr("Invalid nictrace%lu argument '%s'."), n, a->argv[2]);
|
---|
[95140] | 916 | hrc = E_FAIL;
|
---|
[23222] | 917 | break;
|
---|
| 918 | }
|
---|
[93708] | 919 | CHECK_ERROR_RET(adapter, COMSETTER(TraceEnabled)(fTraceEnabled), RTEXITCODE_FAILURE);
|
---|
| 920 | fNeedsSaving = true;
|
---|
[23222] | 921 | }
|
---|
| 922 | else
|
---|
[93708] | 923 | RTMsgError(ControlVM::tr("The NIC %d is currently disabled and thus its trace flag can't be changed."), n);
|
---|
[23222] | 924 | }
|
---|
| 925 | }
|
---|
[34014] | 926 | else if( a->argc > 2
|
---|
[33825] | 927 | && !strncmp(a->argv[1], "natpf", 5))
|
---|
| 928 | {
|
---|
| 929 | /* Get the number of network adapters */
|
---|
[101035] | 930 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[33825] | 931 | unsigned n = parseNum(&a->argv[1][5], NetworkAdapterCount, "NIC");
|
---|
| 932 | if (!n)
|
---|
| 933 | {
|
---|
[95140] | 934 | hrc = E_FAIL;
|
---|
[33825] | 935 | break;
|
---|
| 936 | }
|
---|
| 937 | if (a->argc <= 2)
|
---|
| 938 | {
|
---|
[93708] | 939 | errorArgument(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 940 | hrc = E_FAIL;
|
---|
[33825] | 941 | break;
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 | /* get the corresponding network adapter */
|
---|
| 945 | ComPtr<INetworkAdapter> adapter;
|
---|
| 946 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
| 947 | if (!adapter)
|
---|
| 948 | {
|
---|
[95140] | 949 | hrc = E_FAIL;
|
---|
[33825] | 950 | break;
|
---|
| 951 | }
|
---|
[54378] | 952 | ComPtr<INATEngine> engine;
|
---|
[42551] | 953 | CHECK_ERROR(adapter, COMGETTER(NATEngine)(engine.asOutParam()));
|
---|
[33825] | 954 | if (!engine)
|
---|
| 955 | {
|
---|
[95140] | 956 | hrc = E_FAIL;
|
---|
[33825] | 957 | break;
|
---|
| 958 | }
|
---|
| 959 |
|
---|
| 960 | if (!strcmp(a->argv[2], "delete"))
|
---|
[34014] | 961 | {
|
---|
[93708] | 962 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NATPF_DELETE);
|
---|
[33825] | 963 | if (a->argc >= 3)
|
---|
| 964 | CHECK_ERROR(engine, RemoveRedirect(Bstr(a->argv[3]).raw()));
|
---|
| 965 | }
|
---|
| 966 | else
|
---|
| 967 | {
|
---|
[93708] | 968 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NATPF);
|
---|
[92372] | 969 | #define ITERATE_TO_NEXT_TERM(ch) \
|
---|
| 970 | do { \
|
---|
| 971 | while (*ch != ',') \
|
---|
| 972 | { \
|
---|
| 973 | if (*ch == 0) \
|
---|
| 974 | { \
|
---|
[93708] | 975 | return errorSyntax(ControlVM::tr("Missing or invalid argument to '%s'."), \
|
---|
| 976 | a->argv[1]); \
|
---|
[92372] | 977 | } \
|
---|
| 978 | ch++; \
|
---|
| 979 | } \
|
---|
| 980 | *ch = '\0'; \
|
---|
| 981 | ch++; \
|
---|
[33825] | 982 | } while(0)
|
---|
| 983 |
|
---|
| 984 | char *strName;
|
---|
| 985 | char *strProto;
|
---|
| 986 | char *strHostIp;
|
---|
| 987 | char *strHostPort;
|
---|
| 988 | char *strGuestIp;
|
---|
| 989 | char *strGuestPort;
|
---|
| 990 | char *strRaw = RTStrDup(a->argv[2]);
|
---|
| 991 | char *ch = strRaw;
|
---|
| 992 | strName = RTStrStrip(ch);
|
---|
| 993 | ITERATE_TO_NEXT_TERM(ch);
|
---|
| 994 | strProto = RTStrStrip(ch);
|
---|
| 995 | ITERATE_TO_NEXT_TERM(ch);
|
---|
| 996 | strHostIp = RTStrStrip(ch);
|
---|
| 997 | ITERATE_TO_NEXT_TERM(ch);
|
---|
| 998 | strHostPort = RTStrStrip(ch);
|
---|
| 999 | ITERATE_TO_NEXT_TERM(ch);
|
---|
| 1000 | strGuestIp = RTStrStrip(ch);
|
---|
| 1001 | ITERATE_TO_NEXT_TERM(ch);
|
---|
| 1002 | strGuestPort = RTStrStrip(ch);
|
---|
| 1003 | NATProtocol_T proto;
|
---|
| 1004 | if (RTStrICmp(strProto, "udp") == 0)
|
---|
| 1005 | proto = NATProtocol_UDP;
|
---|
| 1006 | else if (RTStrICmp(strProto, "tcp") == 0)
|
---|
| 1007 | proto = NATProtocol_TCP;
|
---|
[33830] | 1008 | else
|
---|
| 1009 | {
|
---|
[93708] | 1010 | return errorSyntax(ControlVM::tr("Wrong rule proto '%s' specified -- only 'udp' and 'tcp' are allowed."),
|
---|
[33830] | 1011 | strProto);
|
---|
| 1012 | }
|
---|
[33825] | 1013 | CHECK_ERROR(engine, AddRedirect(Bstr(strName).raw(), proto, Bstr(strHostIp).raw(),
|
---|
| 1014 | RTStrToUInt16(strHostPort), Bstr(strGuestIp).raw(), RTStrToUInt16(strGuestPort)));
|
---|
| 1015 | #undef ITERATE_TO_NEXT_TERM
|
---|
| 1016 | }
|
---|
[95140] | 1017 | if (SUCCEEDED(hrc))
|
---|
[54523] | 1018 | fNeedsSaving = true;
|
---|
[33825] | 1019 | }
|
---|
[37200] | 1020 | else if (!strncmp(a->argv[1], "nicproperty", 11))
|
---|
| 1021 | {
|
---|
[93708] | 1022 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NICPROPERTY);
|
---|
[37200] | 1023 | /* Get the number of network adapters */
|
---|
[101035] | 1024 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[37200] | 1025 | unsigned n = parseNum(&a->argv[1][11], NetworkAdapterCount, "NIC");
|
---|
| 1026 | if (!n)
|
---|
| 1027 | {
|
---|
[95140] | 1028 | hrc = E_FAIL;
|
---|
[37200] | 1029 | break;
|
---|
| 1030 | }
|
---|
| 1031 | if (a->argc <= 2)
|
---|
| 1032 | {
|
---|
[93708] | 1033 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1034 | hrc = E_FAIL;
|
---|
[37200] | 1035 | break;
|
---|
| 1036 | }
|
---|
| 1037 |
|
---|
| 1038 | /* get the corresponding network adapter */
|
---|
| 1039 | ComPtr<INetworkAdapter> adapter;
|
---|
| 1040 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
| 1041 | if (adapter)
|
---|
| 1042 | {
|
---|
| 1043 | BOOL fEnabled;
|
---|
| 1044 | adapter->COMGETTER(Enabled)(&fEnabled);
|
---|
| 1045 | if (fEnabled)
|
---|
| 1046 | {
|
---|
| 1047 | /* Parse 'name=value' */
|
---|
| 1048 | char *pszProperty = RTStrDup(a->argv[2]);
|
---|
| 1049 | if (pszProperty)
|
---|
| 1050 | {
|
---|
| 1051 | char *pDelimiter = strchr(pszProperty, '=');
|
---|
| 1052 | if (pDelimiter)
|
---|
| 1053 | {
|
---|
| 1054 | *pDelimiter = '\0';
|
---|
| 1055 |
|
---|
| 1056 | Bstr bstrName = pszProperty;
|
---|
| 1057 | Bstr bstrValue = &pDelimiter[1];
|
---|
| 1058 | CHECK_ERROR(adapter, SetProperty(bstrName.raw(), bstrValue.raw()));
|
---|
[95140] | 1059 | if (SUCCEEDED(hrc))
|
---|
[54523] | 1060 | fNeedsSaving = true;
|
---|
[37200] | 1061 | }
|
---|
| 1062 | else
|
---|
| 1063 | {
|
---|
[93708] | 1064 | errorSyntax(ControlVM::tr("Invalid nicproperty%d argument '%s'."), n, a->argv[2]);
|
---|
[95140] | 1065 | hrc = E_FAIL;
|
---|
[37200] | 1066 | }
|
---|
| 1067 | RTStrFree(pszProperty);
|
---|
| 1068 | }
|
---|
| 1069 | else
|
---|
| 1070 | {
|
---|
[93708] | 1071 | RTMsgError(ControlVM::tr("Failed to allocate memory for nicproperty%d '%s'."),
|
---|
[92372] | 1072 | n, a->argv[2]);
|
---|
[95140] | 1073 | hrc = E_FAIL;
|
---|
[37200] | 1074 | }
|
---|
[95140] | 1075 | if (FAILED(hrc))
|
---|
[37200] | 1076 | break;
|
---|
| 1077 | }
|
---|
| 1078 | else
|
---|
[93708] | 1079 | RTMsgError(ControlVM::tr("The NIC %d is currently disabled and thus its properties can't be changed."), n);
|
---|
[37200] | 1080 | }
|
---|
| 1081 | }
|
---|
[45021] | 1082 | else if (!strncmp(a->argv[1], "nicpromisc", 10))
|
---|
| 1083 | {
|
---|
[93708] | 1084 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NICPROMISC);
|
---|
[45021] | 1085 | /* Get the number of network adapters */
|
---|
[101035] | 1086 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[45021] | 1087 | unsigned n = parseNum(&a->argv[1][10], NetworkAdapterCount, "NIC");
|
---|
| 1088 | if (!n)
|
---|
| 1089 | {
|
---|
[95140] | 1090 | hrc = E_FAIL;
|
---|
[45021] | 1091 | break;
|
---|
| 1092 | }
|
---|
| 1093 | if (a->argc <= 2)
|
---|
| 1094 | {
|
---|
[93708] | 1095 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1096 | hrc = E_FAIL;
|
---|
[45021] | 1097 | break;
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
| 1100 | /* get the corresponding network adapter */
|
---|
| 1101 | ComPtr<INetworkAdapter> adapter;
|
---|
| 1102 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
| 1103 | if (adapter)
|
---|
| 1104 | {
|
---|
| 1105 | BOOL fEnabled;
|
---|
| 1106 | adapter->COMGETTER(Enabled)(&fEnabled);
|
---|
| 1107 | if (fEnabled)
|
---|
| 1108 | {
|
---|
| 1109 | NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
|
---|
| 1110 | if (!strcmp(a->argv[2], "deny"))
|
---|
| 1111 | enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
|
---|
| 1112 | else if ( !strcmp(a->argv[2], "allow-vms")
|
---|
| 1113 | || !strcmp(a->argv[2], "allow-network"))
|
---|
| 1114 | enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
|
---|
| 1115 | else if (!strcmp(a->argv[2], "allow-all"))
|
---|
| 1116 | enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
|
---|
| 1117 | else
|
---|
| 1118 | {
|
---|
[93708] | 1119 | errorSyntax(ControlVM::tr("Unknown promiscuous mode policy '%s'."), a->argv[2]);
|
---|
[95140] | 1120 | hrc = E_INVALIDARG;
|
---|
[45021] | 1121 | break;
|
---|
| 1122 | }
|
---|
| 1123 |
|
---|
| 1124 | CHECK_ERROR(adapter, COMSETTER(PromiscModePolicy)(enmPromiscModePolicy));
|
---|
[95140] | 1125 | if (SUCCEEDED(hrc))
|
---|
[54523] | 1126 | fNeedsSaving = true;
|
---|
[45021] | 1127 | }
|
---|
| 1128 | else
|
---|
[93708] | 1129 | RTMsgError(ControlVM::tr("The NIC %d is currently disabled and thus its promiscuous mode can't be changed."), n);
|
---|
[45021] | 1130 | }
|
---|
| 1131 | }
|
---|
[20521] | 1132 | else if (!strncmp(a->argv[1], "nic", 3))
|
---|
| 1133 | {
|
---|
[93708] | 1134 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_NIC);
|
---|
[20521] | 1135 | /* Get the number of network adapters */
|
---|
[101035] | 1136 | ULONG NetworkAdapterCount = getMaxNics(sessionMachine);
|
---|
[20521] | 1137 | unsigned n = parseNum(&a->argv[1][3], NetworkAdapterCount, "NIC");
|
---|
| 1138 | if (!n)
|
---|
| 1139 | {
|
---|
[95140] | 1140 | hrc = E_FAIL;
|
---|
[20521] | 1141 | break;
|
---|
| 1142 | }
|
---|
[21729] | 1143 | if (a->argc <= 2)
|
---|
[20521] | 1144 | {
|
---|
[93708] | 1145 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1146 | hrc = E_FAIL;
|
---|
[20521] | 1147 | break;
|
---|
| 1148 | }
|
---|
| 1149 |
|
---|
| 1150 | /* get the corresponding network adapter */
|
---|
| 1151 | ComPtr<INetworkAdapter> adapter;
|
---|
[23934] | 1152 | CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
|
---|
[20521] | 1153 | if (adapter)
|
---|
| 1154 | {
|
---|
[21729] | 1155 | BOOL fEnabled;
|
---|
| 1156 | adapter->COMGETTER(Enabled)(&fEnabled);
|
---|
| 1157 | if (fEnabled)
|
---|
[20521] | 1158 | {
|
---|
[21729] | 1159 | if (!strcmp(a->argv[2], "null"))
|
---|
[20521] | 1160 | {
|
---|
[56118] | 1161 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Null), RTEXITCODE_FAILURE);
|
---|
[20521] | 1162 | }
|
---|
[21729] | 1163 | else if (!strcmp(a->argv[2], "nat"))
|
---|
[20521] | 1164 | {
|
---|
[21729] | 1165 | if (a->argc == 4)
|
---|
[56118] | 1166 | CHECK_ERROR_RET(adapter, COMSETTER(NATNetwork)(Bstr(a->argv[3]).raw()), RTEXITCODE_FAILURE);
|
---|
| 1167 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_NAT), RTEXITCODE_FAILURE);
|
---|
[20521] | 1168 | }
|
---|
[21729] | 1169 | else if ( !strcmp(a->argv[2], "bridged")
|
---|
| 1170 | || !strcmp(a->argv[2], "hostif")) /* backward compatibility */
|
---|
| 1171 | {
|
---|
| 1172 | if (a->argc <= 3)
|
---|
| 1173 | {
|
---|
[93708] | 1174 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[2]);
|
---|
[95140] | 1175 | hrc = E_FAIL;
|
---|
[21729] | 1176 | break;
|
---|
| 1177 | }
|
---|
[56118] | 1178 | CHECK_ERROR_RET(adapter, COMSETTER(BridgedInterface)(Bstr(a->argv[3]).raw()), RTEXITCODE_FAILURE);
|
---|
[88079] | 1179 | verifyHostNetworkInterfaceName(a->virtualBox, a->argv[3], HostNetworkInterfaceType_Bridged);
|
---|
[56118] | 1180 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged), RTEXITCODE_FAILURE);
|
---|
[21729] | 1181 | }
|
---|
| 1182 | else if (!strcmp(a->argv[2], "intnet"))
|
---|
| 1183 | {
|
---|
| 1184 | if (a->argc <= 3)
|
---|
| 1185 | {
|
---|
[93708] | 1186 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[2]);
|
---|
[95140] | 1187 | hrc = E_FAIL;
|
---|
[21729] | 1188 | break;
|
---|
| 1189 | }
|
---|
[56118] | 1190 | CHECK_ERROR_RET(adapter, COMSETTER(InternalNetwork)(Bstr(a->argv[3]).raw()), RTEXITCODE_FAILURE);
|
---|
| 1191 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Internal), RTEXITCODE_FAILURE);
|
---|
[21729] | 1192 | }
|
---|
[20521] | 1193 | #if defined(VBOX_WITH_NETFLT)
|
---|
[21729] | 1194 | else if (!strcmp(a->argv[2], "hostonly"))
|
---|
[20521] | 1195 | {
|
---|
[21729] | 1196 | if (a->argc <= 3)
|
---|
| 1197 | {
|
---|
[93708] | 1198 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[2]);
|
---|
[95140] | 1199 | hrc = E_FAIL;
|
---|
[21729] | 1200 | break;
|
---|
| 1201 | }
|
---|
[56118] | 1202 | CHECK_ERROR_RET(adapter, COMSETTER(HostOnlyInterface)(Bstr(a->argv[3]).raw()), RTEXITCODE_FAILURE);
|
---|
[88079] | 1203 | verifyHostNetworkInterfaceName(a->virtualBox, a->argv[3], HostNetworkInterfaceType_HostOnly);
|
---|
[56118] | 1204 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly), RTEXITCODE_FAILURE);
|
---|
[21729] | 1205 | }
|
---|
| 1206 | #endif
|
---|
[37200] | 1207 | else if (!strcmp(a->argv[2], "generic"))
|
---|
| 1208 | {
|
---|
| 1209 | if (a->argc <= 3)
|
---|
| 1210 | {
|
---|
[93708] | 1211 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[2]);
|
---|
[95140] | 1212 | hrc = E_FAIL;
|
---|
[37200] | 1213 | break;
|
---|
| 1214 | }
|
---|
[56118] | 1215 | CHECK_ERROR_RET(adapter, COMSETTER(GenericDriver)(Bstr(a->argv[3]).raw()), RTEXITCODE_FAILURE);
|
---|
| 1216 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic), RTEXITCODE_FAILURE);
|
---|
[37200] | 1217 | }
|
---|
[48538] | 1218 | else if (!strcmp(a->argv[2], "natnetwork"))
|
---|
| 1219 | {
|
---|
| 1220 | if (a->argc <= 3)
|
---|
| 1221 | {
|
---|
[93708] | 1222 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[2]);
|
---|
[95140] | 1223 | hrc = E_FAIL;
|
---|
[48538] | 1224 | break;
|
---|
| 1225 | }
|
---|
[56118] | 1226 | CHECK_ERROR_RET(adapter, COMSETTER(NATNetwork)(Bstr(a->argv[3]).raw()), RTEXITCODE_FAILURE);
|
---|
| 1227 | CHECK_ERROR_RET(adapter, COMSETTER(AttachmentType)(NetworkAttachmentType_NATNetwork), RTEXITCODE_FAILURE);
|
---|
[48538] | 1228 | }
|
---|
[21729] | 1229 | else
|
---|
| 1230 | {
|
---|
[93708] | 1231 | errorSyntax(ControlVM::tr("Invalid type '%s' specfied for NIC %lu."), a->argv[2], n);
|
---|
[95140] | 1232 | hrc = E_FAIL;
|
---|
[20521] | 1233 | break;
|
---|
| 1234 | }
|
---|
[95140] | 1235 | if (SUCCEEDED(hrc))
|
---|
[54525] | 1236 | fNeedsSaving = true;
|
---|
[20521] | 1237 | }
|
---|
| 1238 | else
|
---|
[93708] | 1239 | RTMsgError(ControlVM::tr("The NIC %d is currently disabled and thus its attachment type can't be changed."), n);
|
---|
[20521] | 1240 | }
|
---|
| 1241 | }
|
---|
[33386] | 1242 | else if ( !strcmp(a->argv[1], "vrde")
|
---|
| 1243 | || !strcmp(a->argv[1], "vrdp"))
|
---|
[15267] | 1244 | {
|
---|
[93708] | 1245 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_VRDE);
|
---|
[33386] | 1246 | if (!strcmp(a->argv[1], "vrdp"))
|
---|
[93708] | 1247 | RTMsgWarning(ControlVM::tr("'vrdp' is deprecated. Use 'vrde'."));
|
---|
[33386] | 1248 |
|
---|
[16052] | 1249 | if (a->argc <= 1 + 1)
|
---|
[15267] | 1250 | {
|
---|
[93708] | 1251 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1252 | hrc = E_FAIL;
|
---|
[15267] | 1253 | break;
|
---|
| 1254 | }
|
---|
[33386] | 1255 | ComPtr<IVRDEServer> vrdeServer;
|
---|
| 1256 | sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
|
---|
| 1257 | ASSERT(vrdeServer);
|
---|
| 1258 | if (vrdeServer)
|
---|
[15267] | 1259 | {
|
---|
[93708] | 1260 | bool fEnabled;
|
---|
| 1261 | if (RT_FAILURE(parseBool(a->argv[2], &fEnabled)))
|
---|
[15267] | 1262 | {
|
---|
[93708] | 1263 | errorSyntax(ControlVM::tr("Invalid remote desktop server state '%s'."), a->argv[2]);
|
---|
[95140] | 1264 | hrc = E_FAIL;
|
---|
[15267] | 1265 | break;
|
---|
| 1266 | }
|
---|
[93708] | 1267 | CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(fEnabled));
|
---|
| 1268 | fNeedsSaving = true;
|
---|
[15267] | 1269 | }
|
---|
| 1270 | }
|
---|
[35194] | 1271 | else if ( !strcmp(a->argv[1], "vrdeport")
|
---|
| 1272 | || !strcmp(a->argv[1], "vrdpport"))
|
---|
[23129] | 1273 | {
|
---|
[93708] | 1274 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_VRDEPORT);
|
---|
[35194] | 1275 | if (!strcmp(a->argv[1], "vrdpport"))
|
---|
[93708] | 1276 | RTMsgWarning(ControlVM::tr("'vrdpport' is deprecated. Use 'vrdeport'."));
|
---|
[35194] | 1277 |
|
---|
[23129] | 1278 | if (a->argc <= 1 + 1)
|
---|
| 1279 | {
|
---|
[93708] | 1280 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1281 | hrc = E_FAIL;
|
---|
[23129] | 1282 | break;
|
---|
| 1283 | }
|
---|
[35105] | 1284 |
|
---|
[33386] | 1285 | ComPtr<IVRDEServer> vrdeServer;
|
---|
| 1286 | sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
|
---|
| 1287 | ASSERT(vrdeServer);
|
---|
| 1288 | if (vrdeServer)
|
---|
[23129] | 1289 | {
|
---|
[33386] | 1290 | Bstr ports;
|
---|
[23129] | 1291 |
|
---|
| 1292 | if (!strcmp(a->argv[2], "default"))
|
---|
[33386] | 1293 | ports = "0";
|
---|
[23129] | 1294 | else
|
---|
[33386] | 1295 | ports = a->argv[2];
|
---|
[23129] | 1296 |
|
---|
[33386] | 1297 | CHECK_ERROR_BREAK(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), ports.raw()));
|
---|
[95140] | 1298 | if (SUCCEEDED(hrc))
|
---|
[54525] | 1299 | fNeedsSaving = true;
|
---|
[23129] | 1300 | }
|
---|
| 1301 | }
|
---|
[33386] | 1302 | else if ( !strcmp(a->argv[1], "vrdevideochannelquality")
|
---|
| 1303 | || !strcmp(a->argv[1], "vrdpvideochannelquality"))
|
---|
[29364] | 1304 | {
|
---|
[93708] | 1305 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_VRDEVIDEOCHANNELQUALITY);
|
---|
[33386] | 1306 | if (!strcmp(a->argv[1], "vrdpvideochannelquality"))
|
---|
[93708] | 1307 | RTMsgWarning(ControlVM::tr("'vrdpvideochannelquality' is deprecated. Use 'vrdevideochannelquality'."));
|
---|
[33386] | 1308 |
|
---|
[29364] | 1309 | if (a->argc <= 1 + 1)
|
---|
| 1310 | {
|
---|
[93708] | 1311 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1312 | hrc = E_FAIL;
|
---|
[29364] | 1313 | break;
|
---|
| 1314 | }
|
---|
[33386] | 1315 | ComPtr<IVRDEServer> vrdeServer;
|
---|
| 1316 | sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
|
---|
| 1317 | ASSERT(vrdeServer);
|
---|
| 1318 | if (vrdeServer)
|
---|
[29364] | 1319 | {
|
---|
[35146] | 1320 | Bstr value = a->argv[2];
|
---|
[29364] | 1321 |
|
---|
[35146] | 1322 | CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(), value.raw()));
|
---|
[95140] | 1323 | if (SUCCEEDED(hrc))
|
---|
[54525] | 1324 | fNeedsSaving = true;
|
---|
[29364] | 1325 | }
|
---|
| 1326 | }
|
---|
[33590] | 1327 | else if (!strcmp(a->argv[1], "vrdeproperty"))
|
---|
[33386] | 1328 | {
|
---|
[93708] | 1329 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_VRDEPROPERTY);
|
---|
[33386] | 1330 | if (a->argc <= 1 + 1)
|
---|
| 1331 | {
|
---|
[93708] | 1332 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 1333 | hrc = E_FAIL;
|
---|
[33386] | 1334 | break;
|
---|
| 1335 | }
|
---|
| 1336 | ComPtr<IVRDEServer> vrdeServer;
|
---|
| 1337 | sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
|
---|
| 1338 | ASSERT(vrdeServer);
|
---|
| 1339 | if (vrdeServer)
|
---|
| 1340 | {
|
---|
| 1341 | /* Parse 'name=value' */
|
---|
| 1342 | char *pszProperty = RTStrDup(a->argv[2]);
|
---|
| 1343 | if (pszProperty)
|
---|
| 1344 | {
|
---|
| 1345 | char *pDelimiter = strchr(pszProperty, '=');
|
---|
| 1346 | if (pDelimiter)
|
---|
| 1347 | {
|
---|
| 1348 | *pDelimiter = '\0';
|
---|
| 1349 |
|
---|
| 1350 | Bstr bstrName = pszProperty;
|
---|
| 1351 | Bstr bstrValue = &pDelimiter[1];
|
---|
| 1352 | CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
|
---|
[95140] | 1353 | if (SUCCEEDED(hrc))
|
---|
[54525] | 1354 | fNeedsSaving = true;
|
---|
[33386] | 1355 | }
|
---|
| 1356 | else
|
---|
| 1357 | {
|
---|
[93708] | 1358 | errorSyntax(ControlVM::tr("Invalid vrdeproperty argument '%s'."), a->argv[2]);
|
---|
[95140] | 1359 | hrc = E_FAIL;
|
---|
[33386] | 1360 | }
|
---|
| 1361 | RTStrFree(pszProperty);
|
---|
| 1362 | }
|
---|
| 1363 | else
|
---|
| 1364 | {
|
---|
[93708] | 1365 | RTMsgError(ControlVM::tr("Failed to allocate memory for VRDE property '%s'."),
|
---|
[92372] | 1366 | a->argv[2]);
|
---|
[95140] | 1367 | hrc = E_FAIL;
|
---|
[33386] | 1368 | }
|
---|
| 1369 | }
|
---|
[95140] | 1370 | if (FAILED(hrc))
|
---|
[33386] | 1371 | {
|
---|
| 1372 | break;
|
---|
| 1373 | }
|
---|
| 1374 | }
|
---|
[23934] | 1375 | else if ( !strcmp(a->argv[1], "usbattach")
|
---|
| 1376 | || !strcmp(a->argv[1], "usbdetach"))
|
---|
[1] | 1377 | {
|
---|
[93708] | 1378 | bool attach = !strcmp(a->argv[1], "usbattach");
|
---|
| 1379 | if (attach)
|
---|
| 1380 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_USBATTACH);
|
---|
| 1381 | else
|
---|
| 1382 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_USBDETACH);
|
---|
| 1383 |
|
---|
[16052] | 1384 | if (a->argc < 3)
|
---|
[1] | 1385 | {
|
---|
[93708] | 1386 | errorSyntax(ControlVM::tr("Not enough parameters."));
|
---|
[95140] | 1387 | hrc = E_FAIL;
|
---|
[1] | 1388 | break;
|
---|
| 1389 | }
|
---|
[53062] | 1390 | else if (a->argc == 4 || a->argc > 5)
|
---|
| 1391 | {
|
---|
[93708] | 1392 | errorSyntax(ControlVM::tr("Wrong number of arguments."));
|
---|
[95140] | 1393 | hrc = E_FAIL;
|
---|
[53062] | 1394 | break;
|
---|
| 1395 | }
|
---|
[1] | 1396 |
|
---|
[32718] | 1397 | Bstr usbId = a->argv[2];
|
---|
[53062] | 1398 | Bstr captureFilename;
|
---|
[44039] | 1399 |
|
---|
[53062] | 1400 | if (a->argc == 5)
|
---|
| 1401 | {
|
---|
| 1402 | if (!strcmp(a->argv[3], "--capturefile"))
|
---|
| 1403 | captureFilename = a->argv[4];
|
---|
| 1404 | else
|
---|
| 1405 | {
|
---|
[93708] | 1406 | errorSyntax(ControlVM::tr("Invalid parameter '%s'."), a->argv[3]);
|
---|
[95140] | 1407 | hrc = E_FAIL;
|
---|
[53062] | 1408 | break;
|
---|
| 1409 | }
|
---|
| 1410 | }
|
---|
| 1411 |
|
---|
[44039] | 1412 | Guid guid(usbId);
|
---|
| 1413 | if (!guid.isValid())
|
---|
[1] | 1414 | {
|
---|
| 1415 | // assume address
|
---|
| 1416 | if (attach)
|
---|
| 1417 | {
|
---|
[47908] | 1418 | ComPtr<IHost> host;
|
---|
[23934] | 1419 | CHECK_ERROR_BREAK(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
[17684] | 1420 | SafeIfaceArray <IHostUSBDevice> coll;
|
---|
[23934] | 1421 | CHECK_ERROR_BREAK(host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(coll)));
|
---|
[47908] | 1422 | ComPtr<IHostUSBDevice> dev;
|
---|
[32718] | 1423 | CHECK_ERROR_BREAK(host, FindUSBDeviceByAddress(Bstr(a->argv[2]).raw(),
|
---|
| 1424 | dev.asOutParam()));
|
---|
[23934] | 1425 | CHECK_ERROR_BREAK(dev, COMGETTER(Id)(usbId.asOutParam()));
|
---|
[1] | 1426 | }
|
---|
| 1427 | else
|
---|
| 1428 | {
|
---|
[17553] | 1429 | SafeIfaceArray <IUSBDevice> coll;
|
---|
[23934] | 1430 | CHECK_ERROR_BREAK(console, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(coll)));
|
---|
[47908] | 1431 | ComPtr<IUSBDevice> dev;
|
---|
[32718] | 1432 | CHECK_ERROR_BREAK(console, FindUSBDeviceByAddress(Bstr(a->argv[2]).raw(),
|
---|
| 1433 | dev.asOutParam()));
|
---|
[23934] | 1434 | CHECK_ERROR_BREAK(dev, COMGETTER(Id)(usbId.asOutParam()));
|
---|
[1] | 1435 | }
|
---|
| 1436 | }
|
---|
[44039] | 1437 | else if (guid.isZero())
|
---|
| 1438 | {
|
---|
[93708] | 1439 | errorSyntax(ControlVM::tr("Zero UUID argument '%s'."), a->argv[2]);
|
---|
[95140] | 1440 | hrc = E_FAIL;
|
---|
[44039] | 1441 | break;
|
---|
| 1442 | }
|
---|
[1] | 1443 |
|
---|
| 1444 | if (attach)
|
---|
[53062] | 1445 | CHECK_ERROR_BREAK(console, AttachUSBDevice(usbId.raw(), captureFilename.raw()));
|
---|
[1] | 1446 | else
|
---|
| 1447 | {
|
---|
[47908] | 1448 | ComPtr<IUSBDevice> dev;
|
---|
[32718] | 1449 | CHECK_ERROR_BREAK(console, DetachUSBDevice(usbId.raw(),
|
---|
| 1450 | dev.asOutParam()));
|
---|
[1] | 1451 | }
|
---|
| 1452 | }
|
---|
[18782] | 1453 | else if (!strcmp(a->argv[1], "setvideomodehint"))
|
---|
[1] | 1454 | {
|
---|
[93708] | 1455 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SETVIDEOMODEHINT);
|
---|
[42248] | 1456 | if (a->argc != 5 && a->argc != 6 && a->argc != 7 && a->argc != 9)
|
---|
[1] | 1457 | {
|
---|
[93708] | 1458 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1459 | hrc = E_FAIL;
|
---|
[1] | 1460 | break;
|
---|
| 1461 | }
|
---|
[42248] | 1462 | bool fEnabled = true;
|
---|
| 1463 | uint32_t uXRes = RTStrToUInt32(a->argv[2]);
|
---|
| 1464 | uint32_t uYRes = RTStrToUInt32(a->argv[3]);
|
---|
| 1465 | uint32_t uBpp = RTStrToUInt32(a->argv[4]);
|
---|
| 1466 | uint32_t uDisplayIdx = 0;
|
---|
| 1467 | bool fChangeOrigin = false;
|
---|
| 1468 | int32_t iOriginX = 0;
|
---|
| 1469 | int32_t iOriginY = 0;
|
---|
| 1470 | if (a->argc >= 6)
|
---|
| 1471 | uDisplayIdx = RTStrToUInt32(a->argv[5]);
|
---|
| 1472 | if (a->argc >= 7)
|
---|
| 1473 | {
|
---|
[93708] | 1474 | if (RT_FAILURE(parseBool(a->argv[6], &fEnabled)))
|
---|
[42248] | 1475 | {
|
---|
[93708] | 1476 | errorSyntax(ControlVM::tr("Either \"yes\" or \"no\" is expected."));
|
---|
[95140] | 1477 | hrc = E_FAIL;
|
---|
[42248] | 1478 | break;
|
---|
| 1479 | }
|
---|
| 1480 | }
|
---|
| 1481 | if (a->argc == 9)
|
---|
| 1482 | {
|
---|
| 1483 | iOriginX = RTStrToInt32(a->argv[7]);
|
---|
| 1484 | iOriginY = RTStrToInt32(a->argv[8]);
|
---|
| 1485 | fChangeOrigin = true;
|
---|
| 1486 | }
|
---|
[1] | 1487 |
|
---|
[44309] | 1488 | ComPtr<IDisplay> pDisplay;
|
---|
| 1489 | CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
|
---|
| 1490 | if (!pDisplay)
|
---|
| 1491 | {
|
---|
[93708] | 1492 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 1493 | hrc = E_FAIL;
|
---|
[44309] | 1494 | break;
|
---|
| 1495 | }
|
---|
| 1496 | CHECK_ERROR_BREAK(pDisplay, SetVideoModeHint(uDisplayIdx, fEnabled,
|
---|
| 1497 | fChangeOrigin, iOriginX, iOriginY,
|
---|
[78995] | 1498 | uXRes, uYRes, uBpp, true));
|
---|
[1] | 1499 | }
|
---|
[72352] | 1500 | else if (!strcmp(a->argv[1], "setscreenlayout"))
|
---|
| 1501 | {
|
---|
[93708] | 1502 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SETSCREENLAYOUT);
|
---|
[72352] | 1503 | if (a->argc < 4)
|
---|
| 1504 | {
|
---|
[93708] | 1505 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1506 | hrc = E_FAIL;
|
---|
[72352] | 1507 | break;
|
---|
| 1508 | }
|
---|
| 1509 |
|
---|
| 1510 | ComPtr<IDisplay> pDisplay;
|
---|
| 1511 | CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
|
---|
| 1512 | if (!pDisplay)
|
---|
| 1513 | {
|
---|
[93708] | 1514 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 1515 | hrc = E_FAIL;
|
---|
[72352] | 1516 | break;
|
---|
| 1517 | }
|
---|
| 1518 |
|
---|
| 1519 | com::SafeIfaceArray<IGuestScreenInfo> aGuestScreenInfos;
|
---|
| 1520 |
|
---|
| 1521 | /* Parse "<display> on|primary <xorigin> <yorigin> <xres> <yres> <bpp> | off" sequences. */
|
---|
| 1522 | int argc = a->argc - 2;
|
---|
| 1523 | char **argv = &a->argv[2];
|
---|
| 1524 | while (argc >= 2)
|
---|
| 1525 | {
|
---|
| 1526 | ULONG aDisplay = RTStrToUInt32(argv[0]);
|
---|
| 1527 | BOOL aPrimary = FALSE;
|
---|
| 1528 |
|
---|
| 1529 | GuestMonitorStatus_T aStatus;
|
---|
| 1530 | if (RTStrICmp(argv[1], "primary") == 0)
|
---|
| 1531 | {
|
---|
| 1532 | aStatus = GuestMonitorStatus_Enabled;
|
---|
| 1533 | aPrimary = TRUE;
|
---|
| 1534 | }
|
---|
| 1535 | else if (RTStrICmp(argv[1], "on") == 0)
|
---|
| 1536 | aStatus = GuestMonitorStatus_Enabled;
|
---|
| 1537 | else if (RTStrICmp(argv[1], "off") == 0)
|
---|
| 1538 | aStatus = GuestMonitorStatus_Disabled;
|
---|
| 1539 | else
|
---|
| 1540 | {
|
---|
[93708] | 1541 | errorSyntax(ControlVM::tr("Display status must be <on> or <off>."));
|
---|
[95140] | 1542 | hrc = E_FAIL;
|
---|
[72352] | 1543 | break;
|
---|
| 1544 | }
|
---|
| 1545 |
|
---|
| 1546 | BOOL aChangeOrigin = FALSE;
|
---|
| 1547 | LONG aOriginX = 0;
|
---|
| 1548 | LONG aOriginY = 0;
|
---|
| 1549 | ULONG aWidth = 0;
|
---|
| 1550 | ULONG aHeight = 0;
|
---|
| 1551 | ULONG aBitsPerPixel = 0;
|
---|
[72355] | 1552 | if (aStatus == GuestMonitorStatus_Enabled)
|
---|
[72352] | 1553 | {
|
---|
| 1554 | if (argc < 7)
|
---|
| 1555 | {
|
---|
[93708] | 1556 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1557 | hrc = E_FAIL;
|
---|
[72352] | 1558 | break;
|
---|
| 1559 | }
|
---|
| 1560 |
|
---|
| 1561 | aChangeOrigin = TRUE;
|
---|
| 1562 | aOriginX = RTStrToUInt32(argv[2]);
|
---|
| 1563 | aOriginY = RTStrToUInt32(argv[3]);
|
---|
| 1564 | aWidth = RTStrToUInt32(argv[4]);
|
---|
| 1565 | aHeight = RTStrToUInt32(argv[5]);
|
---|
| 1566 | aBitsPerPixel = RTStrToUInt32(argv[6]);
|
---|
| 1567 |
|
---|
| 1568 | argc -= 7;
|
---|
| 1569 | argv += 7;
|
---|
| 1570 | }
|
---|
| 1571 | else
|
---|
| 1572 | {
|
---|
| 1573 | argc -= 2;
|
---|
| 1574 | argv += 2;
|
---|
| 1575 | }
|
---|
| 1576 |
|
---|
| 1577 | ComPtr<IGuestScreenInfo> pInfo;
|
---|
| 1578 | CHECK_ERROR_BREAK(pDisplay, CreateGuestScreenInfo(aDisplay, aStatus, aPrimary, aChangeOrigin,
|
---|
| 1579 | aOriginX, aOriginY, aWidth, aHeight, aBitsPerPixel,
|
---|
| 1580 | pInfo.asOutParam()));
|
---|
| 1581 | aGuestScreenInfos.push_back(pInfo);
|
---|
| 1582 | }
|
---|
| 1583 |
|
---|
[95140] | 1584 | if (FAILED(hrc))
|
---|
[72352] | 1585 | break;
|
---|
| 1586 |
|
---|
| 1587 | CHECK_ERROR_BREAK(pDisplay, SetScreenLayout(ScreenLayoutMode_Apply, ComSafeArrayAsInParam(aGuestScreenInfos)));
|
---|
| 1588 | }
|
---|
[18782] | 1589 | else if (!strcmp(a->argv[1], "setcredentials"))
|
---|
[1] | 1590 | {
|
---|
[93708] | 1591 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SETCREDENTIALS);
|
---|
[1] | 1592 | bool fAllowLocalLogon = true;
|
---|
[42444] | 1593 | if ( a->argc == 7
|
---|
| 1594 | || ( a->argc == 8
|
---|
| 1595 | && ( !strcmp(a->argv[3], "-p")
|
---|
| 1596 | || !strcmp(a->argv[3], "--passwordfile"))))
|
---|
[1] | 1597 | {
|
---|
[42444] | 1598 | if ( strcmp(a->argv[5 + (a->argc - 7)], "--allowlocallogon")
|
---|
| 1599 | && strcmp(a->argv[5 + (a->argc - 7)], "-allowlocallogon"))
|
---|
[1] | 1600 | {
|
---|
[93708] | 1601 | errorSyntax(ControlVM::tr("Invalid parameter '%s'."), a->argv[5]);
|
---|
[95140] | 1602 | hrc = E_FAIL;
|
---|
[1] | 1603 | break;
|
---|
| 1604 | }
|
---|
[42444] | 1605 | if (!strcmp(a->argv[6 + (a->argc - 7)], "no"))
|
---|
[1] | 1606 | fAllowLocalLogon = false;
|
---|
| 1607 | }
|
---|
[42444] | 1608 | else if ( a->argc != 5
|
---|
| 1609 | && ( a->argc != 6
|
---|
| 1610 | || ( strcmp(a->argv[3], "-p")
|
---|
| 1611 | && strcmp(a->argv[3], "--passwordfile"))))
|
---|
[1] | 1612 | {
|
---|
[93708] | 1613 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1614 | hrc = E_FAIL;
|
---|
[1] | 1615 | break;
|
---|
| 1616 | }
|
---|
[42444] | 1617 | Utf8Str passwd, domain;
|
---|
| 1618 | if (a->argc == 5 || a->argc == 7)
|
---|
| 1619 | {
|
---|
| 1620 | passwd = a->argv[3];
|
---|
| 1621 | domain = a->argv[4];
|
---|
| 1622 | }
|
---|
| 1623 | else
|
---|
| 1624 | {
|
---|
| 1625 | RTEXITCODE rcExit = readPasswordFile(a->argv[4], &passwd);
|
---|
| 1626 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 1627 | {
|
---|
[95140] | 1628 | hrc = E_FAIL;
|
---|
[42444] | 1629 | break;
|
---|
| 1630 | }
|
---|
| 1631 | domain = a->argv[5];
|
---|
| 1632 | }
|
---|
[1] | 1633 |
|
---|
[44513] | 1634 | ComPtr<IGuest> pGuest;
|
---|
| 1635 | CHECK_ERROR_BREAK(console, COMGETTER(Guest)(pGuest.asOutParam()));
|
---|
| 1636 | if (!pGuest)
|
---|
| 1637 | {
|
---|
[93708] | 1638 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 1639 | hrc = E_FAIL;
|
---|
[44513] | 1640 | break;
|
---|
| 1641 | }
|
---|
| 1642 | CHECK_ERROR_BREAK(pGuest, SetCredentials(Bstr(a->argv[2]).raw(),
|
---|
| 1643 | Bstr(passwd).raw(),
|
---|
| 1644 | Bstr(domain).raw(),
|
---|
| 1645 | fAllowLocalLogon));
|
---|
[1] | 1646 | }
|
---|
[26941] | 1647 | else if (!strcmp(a->argv[1], "guestmemoryballoon"))
|
---|
[4659] | 1648 | {
|
---|
[93708] | 1649 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_GUESTMEMORYBALLOON);
|
---|
[16052] | 1650 | if (a->argc != 3)
|
---|
[4659] | 1651 | {
|
---|
[93708] | 1652 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1653 | hrc = E_FAIL;
|
---|
[4659] | 1654 | break;
|
---|
| 1655 | }
|
---|
| 1656 | uint32_t uVal;
|
---|
| 1657 | int vrc;
|
---|
[16052] | 1658 | vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
|
---|
[4659] | 1659 | if (vrc != VINF_SUCCESS)
|
---|
| 1660 | {
|
---|
[93708] | 1661 | errorSyntax(ControlVM::tr("Error parsing guest memory balloon size '%s'."), a->argv[2]);
|
---|
[95140] | 1662 | hrc = E_FAIL;
|
---|
[4659] | 1663 | break;
|
---|
| 1664 | }
|
---|
[28528] | 1665 | /* guest is running; update IGuest */
|
---|
[47908] | 1666 | ComPtr<IGuest> pGuest;
|
---|
[95140] | 1667 | hrc = console->COMGETTER(Guest)(pGuest.asOutParam());
|
---|
| 1668 | if (SUCCEEDED(hrc))
|
---|
[45158] | 1669 | {
|
---|
| 1670 | if (!pGuest)
|
---|
| 1671 | {
|
---|
[93708] | 1672 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 1673 | hrc = E_FAIL;
|
---|
[45158] | 1674 | break;
|
---|
| 1675 | }
|
---|
| 1676 | CHECK_ERROR(pGuest, COMSETTER(MemoryBalloonSize)(uVal));
|
---|
| 1677 | }
|
---|
[4659] | 1678 | }
|
---|
[23801] | 1679 | else if (!strcmp(a->argv[1], "teleport"))
|
---|
[23667] | 1680 | {
|
---|
| 1681 | Bstr bstrHostname;
|
---|
[24874] | 1682 | uint32_t uMaxDowntime = 250 /*ms*/;
|
---|
| 1683 | uint32_t uPort = UINT32_MAX;
|
---|
[24969] | 1684 | uint32_t cMsTimeout = 0;
|
---|
[42445] | 1685 | Utf8Str strPassword;
|
---|
[23801] | 1686 | static const RTGETOPTDEF s_aTeleportOptions[] =
|
---|
[23667] | 1687 | {
|
---|
[30396] | 1688 | { "--host", 'h', RTGETOPT_REQ_STRING }, /** @todo RTGETOPT_FLAG_MANDATORY */
|
---|
| 1689 | { "--maxdowntime", 'd', RTGETOPT_REQ_UINT32 },
|
---|
[42445] | 1690 | { "--port", 'P', RTGETOPT_REQ_UINT32 }, /** @todo RTGETOPT_FLAG_MANDATORY */
|
---|
| 1691 | { "--passwordfile", 'p', RTGETOPT_REQ_STRING },
|
---|
| 1692 | { "--password", 'W', RTGETOPT_REQ_STRING },
|
---|
[30396] | 1693 | { "--timeout", 't', RTGETOPT_REQ_UINT32 },
|
---|
| 1694 | { "--detailed-progress", 'D', RTGETOPT_REQ_NOTHING }
|
---|
[23667] | 1695 | };
|
---|
| 1696 | RTGETOPTSTATE GetOptState;
|
---|
[26517] | 1697 | RTGetOptInit(&GetOptState, a->argc, a->argv, s_aTeleportOptions, RT_ELEMENTS(s_aTeleportOptions), 2, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
|
---|
[93708] | 1698 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_TELEPORT);
|
---|
[23667] | 1699 | int ch;
|
---|
| 1700 | RTGETOPTUNION Value;
|
---|
[95140] | 1701 | while ( SUCCEEDED(hrc)
|
---|
[23667] | 1702 | && (ch = RTGetOpt(&GetOptState, &Value)))
|
---|
| 1703 | {
|
---|
| 1704 | switch (ch)
|
---|
| 1705 | {
|
---|
| 1706 | case 'h': bstrHostname = Value.psz; break;
|
---|
[24874] | 1707 | case 'd': uMaxDowntime = Value.u32; break;
|
---|
[30396] | 1708 | case 'D': g_fDetailedProgress = true; break;
|
---|
[42445] | 1709 | case 'P': uPort = Value.u32; break;
|
---|
| 1710 | case 'p':
|
---|
| 1711 | {
|
---|
| 1712 | RTEXITCODE rcExit = readPasswordFile(Value.psz, &strPassword);
|
---|
| 1713 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
[95140] | 1714 | hrc = E_FAIL;
|
---|
[42445] | 1715 | break;
|
---|
| 1716 | }
|
---|
| 1717 | case 'W': strPassword = Value.psz; break;
|
---|
[24969] | 1718 | case 't': cMsTimeout = Value.u32; break;
|
---|
[23667] | 1719 | default:
|
---|
[93708] | 1720 | errorGetOpt(ch, &Value);
|
---|
[95140] | 1721 | hrc = E_FAIL;
|
---|
[23667] | 1722 | break;
|
---|
| 1723 | }
|
---|
| 1724 | }
|
---|
[95140] | 1725 | if (FAILED(hrc))
|
---|
[23667] | 1726 | break;
|
---|
| 1727 |
|
---|
| 1728 | ComPtr<IProgress> progress;
|
---|
[32718] | 1729 | CHECK_ERROR_BREAK(console, Teleport(bstrHostname.raw(), uPort,
|
---|
[42445] | 1730 | Bstr(strPassword).raw(),
|
---|
[32718] | 1731 | uMaxDowntime,
|
---|
| 1732 | progress.asOutParam()));
|
---|
[24969] | 1733 |
|
---|
| 1734 | if (cMsTimeout)
|
---|
| 1735 | {
|
---|
[95140] | 1736 | hrc = progress->COMSETTER(Timeout)(cMsTimeout);
|
---|
| 1737 | if (FAILED(hrc) && hrc != VBOX_E_INVALID_OBJECT_STATE)
|
---|
[24969] | 1738 | CHECK_ERROR_BREAK(progress, COMSETTER(Timeout)(cMsTimeout)); /* lazyness */
|
---|
| 1739 | }
|
---|
| 1740 |
|
---|
[95140] | 1741 | hrc = showProgress(progress);
|
---|
[93708] | 1742 | CHECK_PROGRESS_ERROR(progress, (ControlVM::tr("Teleportation failed")));
|
---|
[23667] | 1743 | }
|
---|
[36720] | 1744 | else if (!strcmp(a->argv[1], "screenshotpng"))
|
---|
| 1745 | {
|
---|
[93708] | 1746 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_SCREENSHOTPNG);
|
---|
[36720] | 1747 | if (a->argc <= 2 || a->argc > 4)
|
---|
| 1748 | {
|
---|
[93708] | 1749 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1750 | hrc = E_FAIL;
|
---|
[36720] | 1751 | break;
|
---|
| 1752 | }
|
---|
| 1753 | int vrc;
|
---|
[46123] | 1754 | uint32_t iScreen = 0;
|
---|
[36720] | 1755 | if (a->argc == 4)
|
---|
| 1756 | {
|
---|
[46123] | 1757 | vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &iScreen);
|
---|
[36720] | 1758 | if (vrc != VINF_SUCCESS)
|
---|
| 1759 | {
|
---|
[93708] | 1760 | errorSyntax(ControlVM::tr("Error parsing display number '%s'."), a->argv[3]);
|
---|
[95140] | 1761 | hrc = E_FAIL;
|
---|
[36720] | 1762 | break;
|
---|
| 1763 | }
|
---|
| 1764 | }
|
---|
| 1765 | ComPtr<IDisplay> pDisplay;
|
---|
| 1766 | CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
|
---|
[44239] | 1767 | if (!pDisplay)
|
---|
| 1768 | {
|
---|
[93708] | 1769 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 1770 | hrc = E_FAIL;
|
---|
[44239] | 1771 | break;
|
---|
| 1772 | }
|
---|
[36720] | 1773 | ULONG width, height, bpp;
|
---|
[47774] | 1774 | LONG xOrigin, yOrigin;
|
---|
[52978] | 1775 | GuestMonitorStatus_T monitorStatus;
|
---|
| 1776 | CHECK_ERROR_BREAK(pDisplay, GetScreenResolution(iScreen, &width, &height, &bpp, &xOrigin, &yOrigin, &monitorStatus));
|
---|
[36720] | 1777 | com::SafeArray<BYTE> saScreenshot;
|
---|
[52200] | 1778 | CHECK_ERROR_BREAK(pDisplay, TakeScreenShotToArray(iScreen, width, height, BitmapFormat_PNG, ComSafeArrayAsOutParam(saScreenshot)));
|
---|
[36720] | 1779 | RTFILE pngFile = NIL_RTFILE;
|
---|
[41885] | 1780 | vrc = RTFileOpen(&pngFile, a->argv[2], RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_TRUNCATE | RTFILE_O_DENY_ALL);
|
---|
[36720] | 1781 | if (RT_FAILURE(vrc))
|
---|
| 1782 | {
|
---|
[93708] | 1783 | RTMsgError(ControlVM::tr("Failed to create file '%s' (%Rrc)."), a->argv[2], vrc);
|
---|
[95140] | 1784 | hrc = E_FAIL;
|
---|
[36720] | 1785 | break;
|
---|
| 1786 | }
|
---|
| 1787 | vrc = RTFileWrite(pngFile, saScreenshot.raw(), saScreenshot.size(), NULL);
|
---|
| 1788 | if (RT_FAILURE(vrc))
|
---|
| 1789 | {
|
---|
[93708] | 1790 | RTMsgError(ControlVM::tr("Failed to write screenshot to file '%s' (%Rrc)."), a->argv[2], vrc);
|
---|
[95140] | 1791 | hrc = E_FAIL;
|
---|
[36720] | 1792 | }
|
---|
| 1793 | RTFileClose(pngFile);
|
---|
| 1794 | }
|
---|
[75345] | 1795 | #ifdef VBOX_WITH_RECORDING
|
---|
[79363] | 1796 | else if ( !strcmp(a->argv[1], "recording")
|
---|
| 1797 | || !strcmp(a->argv[1], "videocap") /* legacy command */)
|
---|
[46123] | 1798 | {
|
---|
[105266] | 1799 | if (!strcmp(a->argv[1], "videocap"))
|
---|
| 1800 | RTMsgWarning(ControlVM::tr("Sub command 'videocap' is deprecated -- please use 'recording' instead ."));
|
---|
| 1801 |
|
---|
[75251] | 1802 | if (a->argc < 3)
|
---|
[46523] | 1803 | {
|
---|
[93708] | 1804 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1805 | hrc = E_FAIL;
|
---|
[46523] | 1806 | break;
|
---|
| 1807 | }
|
---|
[75251] | 1808 |
|
---|
[75361] | 1809 | ComPtr<IRecordingSettings> recordingSettings;
|
---|
[79363] | 1810 | CHECK_ERROR_BREAK(sessionMachine, COMGETTER(RecordingSettings)(recordingSettings.asOutParam()));
|
---|
[75251] | 1811 |
|
---|
[75361] | 1812 | SafeIfaceArray <IRecordingScreenSettings> saRecordingScreenScreens;
|
---|
| 1813 | CHECK_ERROR_BREAK(recordingSettings, COMGETTER(Screens)(ComSafeArrayAsOutParam(saRecordingScreenScreens)));
|
---|
[75251] | 1814 |
|
---|
[81964] | 1815 | ComPtr<IGraphicsAdapter> pGraphicsAdapter;
|
---|
| 1816 | CHECK_ERROR_BREAK(sessionMachine, COMGETTER(GraphicsAdapter)(pGraphicsAdapter.asOutParam()));
|
---|
| 1817 |
|
---|
[75251] | 1818 | /* Note: For now all screens have the same configuration. */
|
---|
| 1819 |
|
---|
[93708] | 1820 | bool fEnabled;
|
---|
| 1821 | if (RT_SUCCESS(parseBool(a->argv[2], &fEnabled)))
|
---|
[46523] | 1822 | {
|
---|
[105266] | 1823 | //setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING);
|
---|
[93708] | 1824 | CHECK_ERROR_RET(recordingSettings, COMSETTER(Enabled)(fEnabled), RTEXITCODE_FAILURE);
|
---|
[105266] | 1825 |
|
---|
| 1826 | if (fEnabled)
|
---|
| 1827 | RTPrintf(ControlVM::tr("Recording enabled. Use 'start' to start recording.\n"));
|
---|
[46523] | 1828 | }
|
---|
[105266] | 1829 | else if (!strcmp(a->argv[2], "start"))
|
---|
| 1830 | {
|
---|
| 1831 | //setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_START);
|
---|
| 1832 | bool fWait = false;
|
---|
| 1833 | if (a->argc >= 4 && !strcmp(a->argv[3], "--wait"))
|
---|
| 1834 | fWait = true;
|
---|
| 1835 |
|
---|
| 1836 | ComPtr<IProgress> progress;
|
---|
| 1837 | CHECK_ERROR_BREAK(recordingSettings, Start(progress.asOutParam()));
|
---|
| 1838 |
|
---|
| 1839 | if (fWait)
|
---|
| 1840 | {
|
---|
| 1841 | hrc = showProgress(progress, SHOW_PROGRESS_OPS);
|
---|
| 1842 | CHECK_PROGRESS_ERROR(progress, (ControlVM::tr("Recording failed.")));
|
---|
| 1843 | }
|
---|
| 1844 | else
|
---|
| 1845 | RTPrintf(ControlVM::tr("Recording started (detacted).\n"));
|
---|
| 1846 | }
|
---|
| 1847 | else if (!strcmp(a->argv[2], "stop"))
|
---|
| 1848 | {
|
---|
| 1849 | //setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_STOP);
|
---|
| 1850 | ComPtr<IProgress> progress;
|
---|
| 1851 | CHECK_ERROR_BREAK(recordingSettings, COMGETTER(Progress)(progress.asOutParam()));
|
---|
| 1852 | CHECK_ERROR_BREAK(progress, Cancel());
|
---|
| 1853 | }
|
---|
| 1854 | else if (!strcmp(a->argv[2], "attach"))
|
---|
| 1855 | {
|
---|
| 1856 | //setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_ATTACH);
|
---|
| 1857 | ComPtr<IProgress> progress;
|
---|
| 1858 | CHECK_ERROR_BREAK(recordingSettings, COMGETTER(Progress)(progress.asOutParam()));
|
---|
| 1859 | hrc = showProgress(progress, SHOW_PROGRESS_OPS);
|
---|
| 1860 | }
|
---|
[75251] | 1861 | else if (!strcmp(a->argv[2], "screens"))
|
---|
[46523] | 1862 | {
|
---|
[93708] | 1863 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_SCREENS);
|
---|
[75251] | 1864 | ULONG cMonitors = 64;
|
---|
[81964] | 1865 | CHECK_ERROR_BREAK(pGraphicsAdapter, COMGETTER(MonitorCount)(&cMonitors));
|
---|
[75251] | 1866 | com::SafeArray<BOOL> saScreens(cMonitors);
|
---|
[93708] | 1867 | if (a->argc != 4)
|
---|
[75251] | 1868 | {
|
---|
[93708] | 1869 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1870 | hrc = E_FAIL;
|
---|
[93708] | 1871 | break;
|
---|
[75251] | 1872 | }
|
---|
[93708] | 1873 | if (RT_FAILURE(parseScreens(a->argv[3], &saScreens)))
|
---|
[75251] | 1874 | {
|
---|
[93708] | 1875 | errorSyntax(ControlVM::tr("Error parsing list of screen IDs '%s'."), a->argv[3]);
|
---|
[95140] | 1876 | hrc = E_FAIL;
|
---|
[93708] | 1877 | break;
|
---|
[75251] | 1878 | }
|
---|
| 1879 |
|
---|
[75361] | 1880 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
| 1881 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(Enabled)(saScreens[i]));
|
---|
[46123] | 1882 | }
|
---|
[75251] | 1883 | else if (!strcmp(a->argv[2], "filename"))
|
---|
[54400] | 1884 | {
|
---|
[93708] | 1885 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_FILENAME);
|
---|
[75390] | 1886 | if (a->argc != 4)
|
---|
[75251] | 1887 | {
|
---|
[93708] | 1888 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1889 | hrc = E_FAIL;
|
---|
[75251] | 1890 | break;
|
---|
| 1891 | }
|
---|
[54400] | 1892 |
|
---|
[75361] | 1893 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
[75926] | 1894 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(Filename)(Bstr(a->argv[3]).raw()));
|
---|
[54400] | 1895 | }
|
---|
[75341] | 1896 | else if ( !strcmp(a->argv[2], "videores")
|
---|
| 1897 | || !strcmp(a->argv[2], "videoresolution"))
|
---|
[54400] | 1898 | {
|
---|
[93708] | 1899 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_VIDEORES);
|
---|
[75251] | 1900 | if (a->argc != 5)
|
---|
| 1901 | {
|
---|
[93708] | 1902 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1903 | hrc = E_FAIL;
|
---|
[75251] | 1904 | break;
|
---|
| 1905 | }
|
---|
[54400] | 1906 |
|
---|
[75390] | 1907 | uint32_t uWidth;
|
---|
| 1908 | int vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &uWidth);
|
---|
[75251] | 1909 | if (RT_FAILURE(vrc))
|
---|
| 1910 | {
|
---|
[93708] | 1911 | errorSyntax(ControlVM::tr("Error parsing video width '%s'."), a->argv[3]);
|
---|
[95140] | 1912 | hrc = E_FAIL;
|
---|
[75251] | 1913 | break;
|
---|
| 1914 | }
|
---|
| 1915 |
|
---|
[75390] | 1916 | uint32_t uHeight;
|
---|
| 1917 | vrc = RTStrToUInt32Ex(a->argv[4], NULL, 0, &uHeight);
|
---|
[75251] | 1918 | if (RT_FAILURE(vrc))
|
---|
| 1919 | {
|
---|
[93708] | 1920 | errorSyntax(ControlVM::tr("Error parsing video height '%s'."), a->argv[4]);
|
---|
[95140] | 1921 | hrc = E_FAIL;
|
---|
[75251] | 1922 | break;
|
---|
| 1923 | }
|
---|
| 1924 |
|
---|
[75361] | 1925 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
[75251] | 1926 | {
|
---|
[75390] | 1927 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(VideoWidth)(uWidth));
|
---|
| 1928 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(VideoHeight)(uHeight));
|
---|
[75251] | 1929 | }
|
---|
[54400] | 1930 | }
|
---|
[75251] | 1931 | else if (!strcmp(a->argv[2], "videorate"))
|
---|
[54421] | 1932 | {
|
---|
[93708] | 1933 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_VIDEORATE);
|
---|
[75251] | 1934 | if (a->argc != 4)
|
---|
| 1935 | {
|
---|
[93708] | 1936 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1937 | hrc = E_FAIL;
|
---|
[75251] | 1938 | break;
|
---|
| 1939 | }
|
---|
| 1940 |
|
---|
[75390] | 1941 | uint32_t uRate;
|
---|
| 1942 | int vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &uRate);
|
---|
[75251] | 1943 | if (RT_FAILURE(vrc))
|
---|
| 1944 | {
|
---|
[93708] | 1945 | errorSyntax(ControlVM::tr("Error parsing video rate '%s'."), a->argv[3]);
|
---|
[95140] | 1946 | hrc = E_FAIL;
|
---|
[75251] | 1947 | break;
|
---|
| 1948 | }
|
---|
| 1949 |
|
---|
[75361] | 1950 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
[75390] | 1951 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(VideoRate)(uRate));
|
---|
[54421] | 1952 | }
|
---|
[75251] | 1953 | else if (!strcmp(a->argv[2], "videofps"))
|
---|
[54421] | 1954 | {
|
---|
[93708] | 1955 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_VIDEOFPS);
|
---|
[75251] | 1956 | if (a->argc != 4)
|
---|
| 1957 | {
|
---|
[93708] | 1958 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1959 | hrc = E_FAIL;
|
---|
[75251] | 1960 | break;
|
---|
| 1961 | }
|
---|
[54400] | 1962 |
|
---|
[75390] | 1963 | uint32_t uFPS;
|
---|
| 1964 | int vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &uFPS);
|
---|
[75251] | 1965 | if (RT_FAILURE(vrc))
|
---|
| 1966 | {
|
---|
[93708] | 1967 | errorSyntax(ControlVM::tr("Error parsing video FPS '%s'."), a->argv[3]);
|
---|
[95140] | 1968 | hrc = E_FAIL;
|
---|
[75251] | 1969 | break;
|
---|
| 1970 | }
|
---|
| 1971 |
|
---|
[75361] | 1972 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
[75390] | 1973 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(VideoFPS)(uFPS));
|
---|
[54400] | 1974 | }
|
---|
[75251] | 1975 | else if (!strcmp(a->argv[2], "maxtime"))
|
---|
[54400] | 1976 | {
|
---|
[93708] | 1977 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_MAXTIME);
|
---|
[75251] | 1978 | if (a->argc != 4)
|
---|
| 1979 | {
|
---|
[93708] | 1980 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 1981 | hrc = E_FAIL;
|
---|
[75251] | 1982 | break;
|
---|
| 1983 | }
|
---|
[54400] | 1984 |
|
---|
[75390] | 1985 | uint32_t uMaxTime;
|
---|
| 1986 | int vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &uMaxTime);
|
---|
[75251] | 1987 | if (RT_FAILURE(vrc))
|
---|
| 1988 | {
|
---|
[93708] | 1989 | errorSyntax(ControlVM::tr("Error parsing maximum time '%s'."), a->argv[3]);
|
---|
[95140] | 1990 | hrc = E_FAIL;
|
---|
[75251] | 1991 | break;
|
---|
| 1992 | }
|
---|
| 1993 |
|
---|
[75361] | 1994 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
[75390] | 1995 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(MaxTime)(uMaxTime));
|
---|
[54400] | 1996 | }
|
---|
[75251] | 1997 | else if (!strcmp(a->argv[2], "maxfilesize"))
|
---|
[54400] | 1998 | {
|
---|
[93708] | 1999 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_MAXFILESIZE);
|
---|
[75251] | 2000 | if (a->argc != 4)
|
---|
| 2001 | {
|
---|
[93708] | 2002 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 2003 | hrc = E_FAIL;
|
---|
[75251] | 2004 | break;
|
---|
| 2005 | }
|
---|
[54400] | 2006 |
|
---|
[75390] | 2007 | uint32_t uMaxFileSize;
|
---|
| 2008 | int vrc = RTStrToUInt32Ex(a->argv[3], NULL, 0, &uMaxFileSize);
|
---|
[75251] | 2009 | if (RT_FAILURE(vrc))
|
---|
| 2010 | {
|
---|
[93708] | 2011 | errorSyntax(ControlVM::tr("Error parsing maximum file size '%s'."), a->argv[3]);
|
---|
[95140] | 2012 | hrc = E_FAIL;
|
---|
[75251] | 2013 | break;
|
---|
| 2014 | }
|
---|
| 2015 |
|
---|
[75361] | 2016 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
[75390] | 2017 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(MaxFileSize)(uMaxFileSize));
|
---|
[54400] | 2018 | }
|
---|
[75251] | 2019 | else if (!strcmp(a->argv[2], "opts"))
|
---|
[54400] | 2020 | {
|
---|
[93708] | 2021 | #if 0 /* Add when the corresponding documentation is enabled. */
|
---|
| 2022 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_RECORDING_OPTS);
|
---|
| 2023 | #endif
|
---|
[75251] | 2024 | if (a->argc != 4)
|
---|
| 2025 | {
|
---|
[93708] | 2026 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[95140] | 2027 | hrc = E_FAIL;
|
---|
[75251] | 2028 | break;
|
---|
| 2029 | }
|
---|
[54400] | 2030 |
|
---|
[75361] | 2031 | for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
|
---|
| 2032 | CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(Options)(Bstr(a->argv[3]).raw()));
|
---|
[54400] | 2033 | }
|
---|
| 2034 | }
|
---|
[75345] | 2035 | #endif /* VBOX_WITH_RECORDING */
|
---|
[48406] | 2036 | else if (!strcmp(a->argv[1], "webcam"))
|
---|
| 2037 | {
|
---|
| 2038 | if (a->argc < 3)
|
---|
| 2039 | {
|
---|
[93708] | 2040 | errorArgument(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 2041 | hrc = E_FAIL;
|
---|
[48406] | 2042 | break;
|
---|
| 2043 | }
|
---|
| 2044 |
|
---|
| 2045 | ComPtr<IEmulatedUSB> pEmulatedUSB;
|
---|
| 2046 | CHECK_ERROR_BREAK(console, COMGETTER(EmulatedUSB)(pEmulatedUSB.asOutParam()));
|
---|
| 2047 | if (!pEmulatedUSB)
|
---|
| 2048 | {
|
---|
[93708] | 2049 | RTMsgError(ControlVM::tr("Guest not running."));
|
---|
[95140] | 2050 | hrc = E_FAIL;
|
---|
[48406] | 2051 | break;
|
---|
| 2052 | }
|
---|
| 2053 |
|
---|
| 2054 | if (!strcmp(a->argv[2], "attach"))
|
---|
| 2055 | {
|
---|
[93708] | 2056 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_WEBCAM_ATTACH);
|
---|
[48406] | 2057 | Bstr path("");
|
---|
| 2058 | if (a->argc >= 4)
|
---|
| 2059 | path = a->argv[3];
|
---|
| 2060 | Bstr settings("");
|
---|
| 2061 | if (a->argc >= 5)
|
---|
| 2062 | settings = a->argv[4];
|
---|
| 2063 | CHECK_ERROR_BREAK(pEmulatedUSB, WebcamAttach(path.raw(), settings.raw()));
|
---|
| 2064 | }
|
---|
| 2065 | else if (!strcmp(a->argv[2], "detach"))
|
---|
| 2066 | {
|
---|
[93708] | 2067 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_WEBCAM_DETACH);
|
---|
[48406] | 2068 | Bstr path("");
|
---|
| 2069 | if (a->argc >= 4)
|
---|
| 2070 | path = a->argv[3];
|
---|
| 2071 | CHECK_ERROR_BREAK(pEmulatedUSB, WebcamDetach(path.raw()));
|
---|
| 2072 | }
|
---|
| 2073 | else if (!strcmp(a->argv[2], "list"))
|
---|
| 2074 | {
|
---|
[93708] | 2075 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_WEBCAM_LIST);
|
---|
[48406] | 2076 | com::SafeArray <BSTR> webcams;
|
---|
| 2077 | CHECK_ERROR_BREAK(pEmulatedUSB, COMGETTER(Webcams)(ComSafeArrayAsOutParam(webcams)));
|
---|
| 2078 | for (size_t i = 0; i < webcams.size(); ++i)
|
---|
| 2079 | {
|
---|
| 2080 | RTPrintf("%ls\n", webcams[i][0]? webcams[i]: Bstr("default").raw());
|
---|
| 2081 | }
|
---|
| 2082 | }
|
---|
| 2083 | else
|
---|
| 2084 | {
|
---|
[93708] | 2085 | errorArgument(ControlVM::tr("Invalid argument to '%s'."), a->argv[1]);
|
---|
[95140] | 2086 | hrc = E_FAIL;
|
---|
[48406] | 2087 | break;
|
---|
| 2088 | }
|
---|
[54591] | 2089 | }
|
---|
| 2090 | else if (!strcmp(a->argv[1], "addencpassword"))
|
---|
| 2091 | {
|
---|
[93708] | 2092 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_ADDENCPASSWORD);
|
---|
[54591] | 2093 | if ( a->argc != 4
|
---|
| 2094 | && a->argc != 6)
|
---|
| 2095 | {
|
---|
[93708] | 2096 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[54591] | 2097 | break;
|
---|
| 2098 | }
|
---|
[48538] | 2099 |
|
---|
[58434] | 2100 | BOOL fRemoveOnSuspend = FALSE;
|
---|
| 2101 | if (a->argc == 6)
|
---|
[54591] | 2102 | {
|
---|
[58434] | 2103 | if ( strcmp(a->argv[4], "--removeonsuspend")
|
---|
| 2104 | || ( strcmp(a->argv[5], "yes")
|
---|
| 2105 | && strcmp(a->argv[5], "no")))
|
---|
| 2106 | {
|
---|
[93708] | 2107 | errorSyntax(ControlVM::tr("Invalid parameters."));
|
---|
[58434] | 2108 | break;
|
---|
| 2109 | }
|
---|
| 2110 | if (!strcmp(a->argv[5], "yes"))
|
---|
| 2111 | fRemoveOnSuspend = TRUE;
|
---|
[54591] | 2112 | }
|
---|
| 2113 |
|
---|
| 2114 | Bstr bstrPwId(a->argv[2]);
|
---|
[55923] | 2115 | Utf8Str strPassword;
|
---|
| 2116 |
|
---|
| 2117 | if (!RTStrCmp(a->argv[3], "-"))
|
---|
| 2118 | {
|
---|
| 2119 | /* Get password from console. */
|
---|
[93708] | 2120 | RTEXITCODE rcExit = readPasswordFromConsole(&strPassword, ControlVM::tr("Enter password:"));
|
---|
[55923] | 2121 | if (rcExit == RTEXITCODE_FAILURE)
|
---|
| 2122 | break;
|
---|
| 2123 | }
|
---|
| 2124 | else
|
---|
| 2125 | {
|
---|
| 2126 | RTEXITCODE rcExit = readPasswordFile(a->argv[3], &strPassword);
|
---|
| 2127 | if (rcExit == RTEXITCODE_FAILURE)
|
---|
| 2128 | {
|
---|
[93708] | 2129 | RTMsgError(ControlVM::tr("Failed to read new password from file."));
|
---|
[55923] | 2130 | break;
|
---|
| 2131 | }
|
---|
| 2132 | }
|
---|
| 2133 |
|
---|
[94660] | 2134 | CHECK_ERROR_BREAK(console, AddEncryptionPassword(bstrPwId.raw(), Bstr(strPassword).raw(), fRemoveOnSuspend));
|
---|
[48406] | 2135 | }
|
---|
[54591] | 2136 | else if (!strcmp(a->argv[1], "removeencpassword"))
|
---|
| 2137 | {
|
---|
[93708] | 2138 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_REMOVEENCPASSWORD);
|
---|
[54591] | 2139 | if (a->argc != 3)
|
---|
| 2140 | {
|
---|
[93708] | 2141 | errorSyntax(ControlVM::tr("Incorrect number of parameters."));
|
---|
[54591] | 2142 | break;
|
---|
| 2143 | }
|
---|
| 2144 | Bstr bstrPwId(a->argv[2]);
|
---|
[94660] | 2145 | CHECK_ERROR_BREAK(console, RemoveEncryptionPassword(bstrPwId.raw()));
|
---|
[54591] | 2146 | }
|
---|
[99204] | 2147 | /** @todo r=bird: 'removeallencpasswords' is very much unreadable carp. Use
|
---|
| 2148 | * dashes as word separators to make it less fishy. */
|
---|
[54591] | 2149 | else if (!strcmp(a->argv[1], "removeallencpasswords"))
|
---|
| 2150 | {
|
---|
[93708] | 2151 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_REMOVEALLENCPASSWORDS);
|
---|
[94660] | 2152 | CHECK_ERROR_BREAK(console, ClearAllEncryptionPasswords());
|
---|
[54591] | 2153 | }
|
---|
[70766] | 2154 | else if (!strncmp(a->argv[1], "changeuartmode", 14))
|
---|
| 2155 | {
|
---|
[93708] | 2156 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_CHANGEUARTMODE);
|
---|
[70766] | 2157 | unsigned n = parseNum(&a->argv[1][14], 4, "UART");
|
---|
| 2158 | if (!n)
|
---|
| 2159 | {
|
---|
[95140] | 2160 | hrc = E_FAIL;
|
---|
[70766] | 2161 | break;
|
---|
| 2162 | }
|
---|
| 2163 | if (a->argc < 3)
|
---|
| 2164 | {
|
---|
[93708] | 2165 | errorSyntax(ControlVM::tr("Missing argument to '%s'."), a->argv[1]);
|
---|
[95140] | 2166 | hrc = E_FAIL;
|
---|
[70766] | 2167 | break;
|
---|
| 2168 | }
|
---|
| 2169 |
|
---|
| 2170 | ComPtr<ISerialPort> uart;
|
---|
| 2171 |
|
---|
| 2172 | CHECK_ERROR_BREAK(sessionMachine, GetSerialPort(n - 1, uart.asOutParam()));
|
---|
| 2173 | ASSERT(uart);
|
---|
| 2174 |
|
---|
| 2175 | if (!RTStrICmp(a->argv[2], "disconnected"))
|
---|
| 2176 | {
|
---|
| 2177 | if (a->argc != 3)
|
---|
| 2178 | {
|
---|
[93708] | 2179 | errorSyntax(ControlVM::tr("Incorrect arguments to '%s'."), a->argv[1]);
|
---|
[95140] | 2180 | hrc = E_FAIL;
|
---|
[70766] | 2181 | break;
|
---|
| 2182 | }
|
---|
| 2183 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
|
---|
| 2184 | }
|
---|
| 2185 | else if ( !RTStrICmp(a->argv[2], "server")
|
---|
| 2186 | || !RTStrICmp(a->argv[2], "client")
|
---|
| 2187 | || !RTStrICmp(a->argv[2], "tcpserver")
|
---|
| 2188 | || !RTStrICmp(a->argv[2], "tcpclient")
|
---|
| 2189 | || !RTStrICmp(a->argv[2], "file"))
|
---|
| 2190 | {
|
---|
| 2191 | const char *pszMode = a->argv[2];
|
---|
| 2192 | if (a->argc != 4)
|
---|
| 2193 | {
|
---|
[93708] | 2194 | errorSyntax(ControlVM::tr("Incorrect arguments to '%s'."), a->argv[1]);
|
---|
[95140] | 2195 | hrc = E_FAIL;
|
---|
[70766] | 2196 | break;
|
---|
| 2197 | }
|
---|
| 2198 |
|
---|
| 2199 | CHECK_ERROR(uart, COMSETTER(Path)(Bstr(a->argv[3]).raw()));
|
---|
| 2200 |
|
---|
| 2201 | /*
|
---|
| 2202 | * Change to disconnected first to get changes in just a parameter causing
|
---|
| 2203 | * the correct changes later on.
|
---|
| 2204 | */
|
---|
| 2205 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
|
---|
| 2206 | if (!RTStrICmp(pszMode, "server"))
|
---|
| 2207 | {
|
---|
| 2208 | CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
|
---|
| 2209 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
|
---|
| 2210 | }
|
---|
| 2211 | else if (!RTStrICmp(pszMode, "client"))
|
---|
| 2212 | {
|
---|
| 2213 | CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
|
---|
| 2214 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
|
---|
| 2215 | }
|
---|
| 2216 | else if (!RTStrICmp(pszMode, "tcpserver"))
|
---|
| 2217 | {
|
---|
| 2218 | CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
|
---|
| 2219 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_TCP));
|
---|
| 2220 | }
|
---|
| 2221 | else if (!RTStrICmp(pszMode, "tcpclient"))
|
---|
| 2222 | {
|
---|
| 2223 | CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
|
---|
| 2224 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_TCP));
|
---|
| 2225 | }
|
---|
| 2226 | else if (!RTStrICmp(pszMode, "file"))
|
---|
| 2227 | {
|
---|
| 2228 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
|
---|
| 2229 | }
|
---|
| 2230 | }
|
---|
| 2231 | else
|
---|
| 2232 | {
|
---|
| 2233 | if (a->argc != 3)
|
---|
| 2234 | {
|
---|
[93708] | 2235 | errorSyntax(ControlVM::tr("Incorrect arguments to '%s'."), a->argv[1]);
|
---|
[95140] | 2236 | hrc = E_FAIL;
|
---|
[70766] | 2237 | break;
|
---|
| 2238 | }
|
---|
| 2239 | CHECK_ERROR(uart, COMSETTER(Path)(Bstr(a->argv[2]).raw()));
|
---|
| 2240 | CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
|
---|
| 2241 | }
|
---|
| 2242 | }
|
---|
[77910] | 2243 | else if (!strncmp(a->argv[1], "vm-process-priority", 14))
|
---|
| 2244 | {
|
---|
[93708] | 2245 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_VM_PROCESS_PRIORITY);
|
---|
[77910] | 2246 | if (a->argc != 3)
|
---|
| 2247 | {
|
---|
[93708] | 2248 | errorSyntax(ControlVM::tr("Incorrect arguments to '%s'."), a->argv[1]);
|
---|
[95140] | 2249 | hrc = E_FAIL;
|
---|
[77910] | 2250 | break;
|
---|
| 2251 | }
|
---|
| 2252 | VMProcPriority_T enmPriority = nameToVMProcPriority(a->argv[2]);
|
---|
| 2253 | if (enmPriority == VMProcPriority_Invalid)
|
---|
| 2254 | {
|
---|
[93708] | 2255 | errorSyntax(ControlVM::tr("Invalid vm-process-priority '%s'."), a->argv[2]);
|
---|
[95140] | 2256 | hrc = E_FAIL;
|
---|
[77910] | 2257 | }
|
---|
| 2258 | else
|
---|
| 2259 | {
|
---|
| 2260 | CHECK_ERROR(sessionMachine, COMSETTER(VMProcessPriority)(enmPriority));
|
---|
| 2261 | }
|
---|
| 2262 | break;
|
---|
| 2263 | }
|
---|
[89597] | 2264 | else if (!strncmp(a->argv[1], "autostart-enabled", 17))
|
---|
| 2265 | {
|
---|
[93708] | 2266 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_AUTOSTART_ENABLED);
|
---|
[89597] | 2267 | if (a->argc != 3)
|
---|
| 2268 | {
|
---|
[93708] | 2269 | errorSyntax(ControlVM::tr("Incorrect arguments to '%s'."), a->argv[1]);
|
---|
[95140] | 2270 | hrc = E_FAIL;
|
---|
[89597] | 2271 | break;
|
---|
| 2272 | }
|
---|
[93708] | 2273 | bool fEnabled;
|
---|
| 2274 | if (RT_FAILURE(parseBool(a->argv[2], &fEnabled)))
|
---|
[89597] | 2275 | {
|
---|
[93708] | 2276 | errorSyntax(ControlVM::tr("Invalid value '%s'."), a->argv[2]);
|
---|
[95140] | 2277 | hrc = E_FAIL;
|
---|
[89597] | 2278 | break;
|
---|
| 2279 | }
|
---|
[93708] | 2280 | CHECK_ERROR(sessionMachine, COMSETTER(AutostartEnabled)(TRUE));
|
---|
| 2281 | fNeedsSaving = true;
|
---|
[89597] | 2282 | break;
|
---|
| 2283 | }
|
---|
| 2284 | else if (!strncmp(a->argv[1], "autostart-delay", 15))
|
---|
| 2285 | {
|
---|
[93708] | 2286 | setCurrentSubcommand(HELP_SCOPE_CONTROLVM_AUTOSTART_DELAY);
|
---|
[89597] | 2287 | if (a->argc != 3)
|
---|
| 2288 | {
|
---|
[93708] | 2289 | errorSyntax(ControlVM::tr("Incorrect arguments to '%s'."), a->argv[1]);
|
---|
[95140] | 2290 | hrc = E_FAIL;
|
---|
[89597] | 2291 | break;
|
---|
| 2292 | }
|
---|
| 2293 | uint32_t u32;
|
---|
| 2294 | char *pszNext;
|
---|
| 2295 | int vrc = RTStrToUInt32Ex(a->argv[2], &pszNext, 10, &u32);
|
---|
| 2296 | if (RT_FAILURE(vrc) || *pszNext != '\0')
|
---|
| 2297 | {
|
---|
[93708] | 2298 | errorSyntax(ControlVM::tr("Invalid autostart delay number '%s'."), a->argv[2]);
|
---|
[95140] | 2299 | hrc = E_FAIL;
|
---|
[89597] | 2300 | break;
|
---|
| 2301 | }
|
---|
| 2302 | CHECK_ERROR(sessionMachine, COMSETTER(AutostartDelay)(u32));
|
---|
[95140] | 2303 | if (SUCCEEDED(hrc))
|
---|
[89597] | 2304 | fNeedsSaving = true;
|
---|
| 2305 | break;
|
---|
| 2306 | }
|
---|
[1] | 2307 | else
|
---|
| 2308 | {
|
---|
[93708] | 2309 | errorSyntax(ControlVM::tr("Invalid parameter '%s'."), a->argv[1]);
|
---|
[95140] | 2310 | hrc = E_FAIL;
|
---|
[1] | 2311 | }
|
---|
[23934] | 2312 | } while (0);
|
---|
[1] | 2313 |
|
---|
[54523] | 2314 | /* The client has to trigger saving the state explicitely. */
|
---|
| 2315 | if (fNeedsSaving)
|
---|
| 2316 | CHECK_ERROR(sessionMachine, SaveSettings());
|
---|
| 2317 |
|
---|
[31070] | 2318 | a->session->UnlockMachine();
|
---|
[1] | 2319 |
|
---|
[95140] | 2320 | return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
|
---|
[1] | 2321 | }
|
---|