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