VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp@ 42739

Last change on this file since 42739 was 42551, checked in by vboxsync, 12 years ago

Main: big API naming cleanup, use all caps acronyms everywhere, including SDK docs
Frontends/VBoxManage: implement guestcontrol execute for new API, disabled by default

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 100.5 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 42551 2012-08-02 16:44:39Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2012 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* Header Files *
20*******************************************************************************/
21#ifndef VBOX_ONLY_DOCS
22#include <VBox/com/com.h>
23#include <VBox/com/array.h>
24#include <VBox/com/ErrorInfo.h>
25#include <VBox/com/errorprint.h>
26#include <VBox/com/EventQueue.h>
27
28#include <VBox/com/VirtualBox.h>
29#endif /* !VBOX_ONLY_DOCS */
30
31#include <iprt/cidr.h>
32#include <iprt/ctype.h>
33#include <iprt/file.h>
34#include <iprt/param.h>
35#include <iprt/path.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/getopt.h>
39#include <VBox/log.h>
40
41#include "VBoxManage.h"
42
43#ifndef VBOX_ONLY_DOCS
44using namespace com;
45
46
47/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
48#if defined(_MSC_VER)
49# pragma optimize("g", off)
50#endif
51
52enum
53{
54 MODIFYVM_NAME = 1000,
55 MODIFYVM_GROUPS,
56 MODIFYVM_OSTYPE,
57 MODIFYVM_MEMORY,
58 MODIFYVM_PAGEFUSION,
59 MODIFYVM_VRAM,
60 MODIFYVM_FIRMWARE,
61 MODIFYVM_ACPI,
62 MODIFYVM_IOAPIC,
63 MODIFYVM_PAE,
64 MODIFYVM_SYNTHCPU,
65 MODIFYVM_HWVIRTEX,
66 MODIFYVM_HWVIRTEXEXCLUSIVE,
67 MODIFYVM_NESTEDPAGING,
68 MODIFYVM_LARGEPAGES,
69 MODIFYVM_VTXVPID,
70 MODIFYVM_CPUS,
71 MODIFYVM_CPUHOTPLUG,
72 MODIFYVM_PLUGCPU,
73 MODIFYVM_UNPLUGCPU,
74 MODIFYVM_SETCPUID,
75 MODIFYVM_DELCPUID,
76 MODIFYVM_DELALLCPUID,
77 MODIFYVM_MONITORCOUNT,
78 MODIFYVM_ACCELERATE3D,
79#ifdef VBOX_WITH_VIDEOHWACCEL
80 MODIFYVM_ACCELERATE2DVIDEO,
81#endif
82 MODIFYVM_BIOSLOGOFADEIN,
83 MODIFYVM_BIOSLOGOFADEOUT,
84 MODIFYVM_BIOSLOGODISPLAYTIME,
85 MODIFYVM_BIOSLOGOIMAGEPATH,
86 MODIFYVM_BIOSBOOTMENU,
87 MODIFYVM_BIOSSYSTEMTIMEOFFSET,
88 MODIFYVM_BIOSPXEDEBUG,
89 MODIFYVM_BOOT,
90 MODIFYVM_HDA, // deprecated
91 MODIFYVM_HDB, // deprecated
92 MODIFYVM_HDD, // deprecated
93 MODIFYVM_IDECONTROLLER, // deprecated
94 MODIFYVM_SATAIDEEMULATION, // deprecated
95 MODIFYVM_SATAPORTCOUNT, // deprecated
96 MODIFYVM_SATAPORT, // deprecated
97 MODIFYVM_SATA, // deprecated
98 MODIFYVM_SCSIPORT, // deprecated
99 MODIFYVM_SCSITYPE, // deprecated
100 MODIFYVM_SCSI, // deprecated
101 MODIFYVM_DVDPASSTHROUGH, // deprecated
102 MODIFYVM_DVD, // deprecated
103 MODIFYVM_FLOPPY, // deprecated
104 MODIFYVM_NICTRACEFILE,
105 MODIFYVM_NICTRACE,
106 MODIFYVM_NICPROPERTY,
107 MODIFYVM_NICTYPE,
108 MODIFYVM_NICSPEED,
109 MODIFYVM_NICBOOTPRIO,
110 MODIFYVM_NICPROMISC,
111 MODIFYVM_NICBWGROUP,
112 MODIFYVM_NIC,
113 MODIFYVM_CABLECONNECTED,
114 MODIFYVM_BRIDGEADAPTER,
115 MODIFYVM_HOSTONLYADAPTER,
116 MODIFYVM_INTNET,
117 MODIFYVM_NATNET,
118 MODIFYVM_GENERICDRV,
119 MODIFYVM_NATBINDIP,
120 MODIFYVM_NATSETTINGS,
121 MODIFYVM_NATPF,
122 MODIFYVM_NATALIASMODE,
123 MODIFYVM_NATTFTPPREFIX,
124 MODIFYVM_NATTFTPFILE,
125 MODIFYVM_NATTFTPSERVER,
126 MODIFYVM_NATDNSPASSDOMAIN,
127 MODIFYVM_NATDNSPROXY,
128 MODIFYVM_NATDNSHOSTRESOLVER,
129 MODIFYVM_MACADDRESS,
130 MODIFYVM_HIDPTR,
131 MODIFYVM_HIDKBD,
132 MODIFYVM_UARTMODE,
133 MODIFYVM_UART,
134#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
135 MODIFYVM_LPTMODE,
136 MODIFYVM_LPT,
137#endif
138 MODIFYVM_GUESTMEMORYBALLOON,
139 MODIFYVM_AUDIOCONTROLLER,
140 MODIFYVM_AUDIO,
141 MODIFYVM_CLIPBOARD,
142 MODIFYVM_DRAGANDDROP,
143 MODIFYVM_VRDPPORT, /* VRDE: deprecated */
144 MODIFYVM_VRDPADDRESS, /* VRDE: deprecated */
145 MODIFYVM_VRDPAUTHTYPE, /* VRDE: deprecated */
146 MODIFYVM_VRDPMULTICON, /* VRDE: deprecated */
147 MODIFYVM_VRDPREUSECON, /* VRDE: deprecated */
148 MODIFYVM_VRDPVIDEOCHANNEL, /* VRDE: deprecated */
149 MODIFYVM_VRDPVIDEOCHANNELQUALITY, /* VRDE: deprecated */
150 MODIFYVM_VRDP, /* VRDE: deprecated */
151 MODIFYVM_VRDEPROPERTY,
152 MODIFYVM_VRDEPORT,
153 MODIFYVM_VRDEADDRESS,
154 MODIFYVM_VRDEAUTHTYPE,
155 MODIFYVM_VRDEAUTHLIBRARY,
156 MODIFYVM_VRDEMULTICON,
157 MODIFYVM_VRDEREUSECON,
158 MODIFYVM_VRDEVIDEOCHANNEL,
159 MODIFYVM_VRDEVIDEOCHANNELQUALITY,
160 MODIFYVM_VRDE_EXTPACK,
161 MODIFYVM_VRDE,
162 MODIFYVM_RTCUSEUTC,
163 MODIFYVM_USBEHCI,
164 MODIFYVM_USB,
165 MODIFYVM_SNAPSHOTFOLDER,
166 MODIFYVM_TELEPORTER_ENABLED,
167 MODIFYVM_TELEPORTER_PORT,
168 MODIFYVM_TELEPORTER_ADDRESS,
169 MODIFYVM_TELEPORTER_PASSWORD,
170 MODIFYVM_TELEPORTER_PASSWORD_FILE,
171 MODIFYVM_TRACING_ENABLED,
172 MODIFYVM_TRACING_CONFIG,
173 MODIFYVM_TRACING_ALLOW_VM_ACCESS,
174 MODIFYVM_HARDWARE_UUID,
175 MODIFYVM_HPET,
176 MODIFYVM_IOCACHE,
177 MODIFYVM_IOCACHESIZE,
178 MODIFYVM_FAULT_TOLERANCE,
179 MODIFYVM_FAULT_TOLERANCE_ADDRESS,
180 MODIFYVM_FAULT_TOLERANCE_PORT,
181 MODIFYVM_FAULT_TOLERANCE_PASSWORD,
182 MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL,
183 MODIFYVM_CPU_EXECTUION_CAP,
184 MODIFYVM_AUTOSTART_ENABLED,
185 MODIFYVM_AUTOSTART_DELAY,
186 MODIFYVM_AUTOSTOP_TYPE,
187#ifdef VBOX_WITH_PCI_PASSTHROUGH
188 MODIFYVM_ATTACH_PCI,
189 MODIFYVM_DETACH_PCI,
190#endif
191#ifdef VBOX_WITH_USB_CARDREADER
192 MODIFYVM_USBCARDREADER,
193#endif
194 MODIFYVM_CHIPSET
195};
196
197static const RTGETOPTDEF g_aModifyVMOptions[] =
198{
199 { "--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING },
200 { "--groups", MODIFYVM_GROUPS, RTGETOPT_REQ_STRING },
201 { "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING },
202 { "--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32 },
203 { "--pagefusion", MODIFYVM_PAGEFUSION, RTGETOPT_REQ_BOOL_ONOFF },
204 { "--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32 },
205 { "--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING },
206 { "--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF },
207 { "--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF },
208 { "--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF },
209 { "--synthcpu", MODIFYVM_SYNTHCPU, RTGETOPT_REQ_BOOL_ONOFF },
210 { "--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF },
211 { "--hwvirtexexcl", MODIFYVM_HWVIRTEXEXCLUSIVE, RTGETOPT_REQ_BOOL_ONOFF },
212 { "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF },
213 { "--largepages", MODIFYVM_LARGEPAGES, RTGETOPT_REQ_BOOL_ONOFF },
214 { "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF },
215 { "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
216 { "--cpuidremove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
217 { "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING},
218 { "--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32 },
219 { "--cpuhotplug", MODIFYVM_CPUHOTPLUG, RTGETOPT_REQ_BOOL_ONOFF },
220 { "--plugcpu", MODIFYVM_PLUGCPU, RTGETOPT_REQ_UINT32 },
221 { "--unplugcpu", MODIFYVM_UNPLUGCPU, RTGETOPT_REQ_UINT32 },
222 { "--cpuexecutioncap", MODIFYVM_CPU_EXECTUION_CAP, RTGETOPT_REQ_UINT32 },
223 { "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF },
224 { "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32 },
225 { "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF },
226#ifdef VBOX_WITH_VIDEOHWACCEL
227 { "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF },
228#endif
229 { "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF },
230 { "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF },
231 { "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32 },
232 { "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING },
233 { "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING },
234 { "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64 },
235 { "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF },
236 { "--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
237 { "--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING },
238 { "--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING },
239 { "--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING },
240 { "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING },
241 { "--sataideemulation", MODIFYVM_SATAIDEEMULATION, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
242 { "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32 },
243 { "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
244 { "--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING },
245 { "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
246 { "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING },
247 { "--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING },
248 { "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING },
249 { "--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING },
250 { "--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING },
251 { "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
252 { "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
253 { "--nicproperty", MODIFYVM_NICPROPERTY, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
254 { "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
255 { "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
256 { "--nicbootprio", MODIFYVM_NICBOOTPRIO, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
257 { "--nicpromisc", MODIFYVM_NICPROMISC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
258 { "--nicbandwidthgroup", MODIFYVM_NICBWGROUP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
259 { "--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
260 { "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
261 { "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
262 { "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
263 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
264 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
265 { "--nicgenericdrv", MODIFYVM_GENERICDRV, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
266 { "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
267 { "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
268 { "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
269 { "--nataliasmode", MODIFYVM_NATALIASMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
270 { "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
271 { "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
272 { "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
273 { "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
274 { "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
275 { "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
276 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
277 { "--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING },
278 { "--keyboard", MODIFYVM_HIDKBD, RTGETOPT_REQ_STRING },
279 { "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
280 { "--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
281#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
282 { "--lptmode", MODIFYVM_LPTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
283 { "--lpt", MODIFYVM_LPT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
284#endif
285 { "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32 },
286 { "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING },
287 { "--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING },
288 { "--clipboard", MODIFYVM_CLIPBOARD, RTGETOPT_REQ_STRING },
289 { "--draganddrop", MODIFYVM_DRAGANDDROP, RTGETOPT_REQ_STRING },
290 { "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING }, /* deprecated */
291 { "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING }, /* deprecated */
292 { "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING }, /* deprecated */
293 { "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
294 { "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
295 { "--vrdpvideochannel", MODIFYVM_VRDPVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
296 { "--vrdpvideochannelquality", MODIFYVM_VRDPVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING }, /* deprecated */
297 { "--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
298 { "--vrdeproperty", MODIFYVM_VRDEPROPERTY, RTGETOPT_REQ_STRING },
299 { "--vrdeport", MODIFYVM_VRDEPORT, RTGETOPT_REQ_STRING },
300 { "--vrdeaddress", MODIFYVM_VRDEADDRESS, RTGETOPT_REQ_STRING },
301 { "--vrdeauthtype", MODIFYVM_VRDEAUTHTYPE, RTGETOPT_REQ_STRING },
302 { "--vrdeauthlibrary", MODIFYVM_VRDEAUTHLIBRARY, RTGETOPT_REQ_STRING },
303 { "--vrdemulticon", MODIFYVM_VRDEMULTICON, RTGETOPT_REQ_BOOL_ONOFF },
304 { "--vrdereusecon", MODIFYVM_VRDEREUSECON, RTGETOPT_REQ_BOOL_ONOFF },
305 { "--vrdevideochannel", MODIFYVM_VRDEVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF },
306 { "--vrdevideochannelquality", MODIFYVM_VRDEVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING },
307 { "--vrdeextpack", MODIFYVM_VRDE_EXTPACK, RTGETOPT_REQ_STRING },
308 { "--vrde", MODIFYVM_VRDE, RTGETOPT_REQ_BOOL_ONOFF },
309 { "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF },
310 { "--usb", MODIFYVM_USB, RTGETOPT_REQ_BOOL_ONOFF },
311 { "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING },
312 { "--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
313 { "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
314 { "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32 },
315 { "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING },
316 { "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING },
317 { "--teleporterpasswordfile", MODIFYVM_TELEPORTER_PASSWORD_FILE, RTGETOPT_REQ_STRING },
318 { "--tracing-enabled", MODIFYVM_TRACING_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
319 { "--tracing-config", MODIFYVM_TRACING_CONFIG, RTGETOPT_REQ_STRING },
320 { "--tracing-allow-vm-access", MODIFYVM_TRACING_ALLOW_VM_ACCESS, RTGETOPT_REQ_BOOL_ONOFF },
321 { "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING },
322 { "--hpet", MODIFYVM_HPET, RTGETOPT_REQ_BOOL_ONOFF },
323 { "--iocache", MODIFYVM_IOCACHE, RTGETOPT_REQ_BOOL_ONOFF },
324 { "--iocachesize", MODIFYVM_IOCACHESIZE, RTGETOPT_REQ_UINT32 },
325 { "--faulttolerance", MODIFYVM_FAULT_TOLERANCE, RTGETOPT_REQ_STRING },
326 { "--faulttoleranceaddress", MODIFYVM_FAULT_TOLERANCE_ADDRESS, RTGETOPT_REQ_STRING },
327 { "--faulttoleranceport", MODIFYVM_FAULT_TOLERANCE_PORT, RTGETOPT_REQ_UINT32 },
328 { "--faulttolerancepassword", MODIFYVM_FAULT_TOLERANCE_PASSWORD, RTGETOPT_REQ_STRING },
329 { "--faulttolerancesyncinterval", MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL, RTGETOPT_REQ_UINT32 },
330 { "--chipset", MODIFYVM_CHIPSET, RTGETOPT_REQ_STRING },
331 { "--autostart-enabled", MODIFYVM_AUTOSTART_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
332 { "--autostart-delay", MODIFYVM_AUTOSTART_DELAY, RTGETOPT_REQ_UINT32 },
333 { "--autostop-type", MODIFYVM_AUTOSTOP_TYPE, RTGETOPT_REQ_STRING },
334#ifdef VBOX_WITH_PCI_PASSTHROUGH
335 { "--pciattach", MODIFYVM_ATTACH_PCI, RTGETOPT_REQ_STRING },
336 { "--pcidetach", MODIFYVM_DETACH_PCI, RTGETOPT_REQ_STRING },
337#endif
338#ifdef VBOX_WITH_USB_CARDREADER
339 { "--usbcardreader", MODIFYVM_USBCARDREADER, RTGETOPT_REQ_BOOL_ONOFF },
340#endif
341};
342
343static void vrdeWarningDeprecatedOption(const char *pszOption)
344{
345 RTStrmPrintf(g_pStdErr, "Warning: '--vrdp%s' is deprecated. Use '--vrde%s'.\n", pszOption, pszOption);
346}
347
348/** Parse PCI address in format 01:02.03 and convert it to the numeric representation. */
349static int32_t parsePci(const char* szPciAddr)
350{
351 char* pszNext = (char*)szPciAddr;
352 int rc;
353 uint8_t aVals[3] = {0, 0, 0};
354
355 rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &aVals[0]);
356 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != ':')
357 return -1;
358
359 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[1]);
360 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != '.')
361 return -1;
362
363 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[2]);
364 if (RT_FAILURE(rc) || pszNext == NULL)
365 return -1;
366
367 return (aVals[0] << 8) | (aVals[1] << 3) | (aVals[2] << 0);
368}
369
370void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups)
371{
372 while (pcszGroups)
373 {
374 char *pComma = RTStrStr(pcszGroups, ",");
375 if (pComma)
376 {
377 Bstr(pcszGroups, pComma - pcszGroups).detachTo(pGroups->appendedRaw());
378 pcszGroups = pComma + 1;
379 }
380 else
381 {
382 Bstr(pcszGroups).detachTo(pGroups->appendedRaw());
383 pcszGroups = NULL;
384 }
385 }
386}
387
388int handleModifyVM(HandlerArg *a)
389{
390 int c;
391 HRESULT rc;
392 Bstr name;
393 RTGETOPTUNION ValueUnion;
394 RTGETOPTSTATE GetOptState;
395 ComPtr <IMachine> machine;
396 ComPtr <IBIOSSettings> biosSettings;
397
398 /* VM ID + at least one parameter. Parameter arguments are checked
399 * individually. */
400 if (a->argc < 2)
401 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
402
403 /* try to find the given machine */
404 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
405 machine.asOutParam()), 1);
406
407
408 /* Get the number of network adapters */
409 ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, machine);
410
411 /* open a session for the VM */
412 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), 1);
413
414 /* get the mutable session machine */
415 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
416 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
417
418 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
419 RT_ELEMENTS(g_aModifyVMOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
420
421 while ( SUCCEEDED (rc)
422 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
423 {
424 switch (c)
425 {
426 case MODIFYVM_NAME:
427 {
428 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
429 break;
430 }
431 case MODIFYVM_GROUPS:
432 {
433 com::SafeArray<BSTR> groups;
434 parseGroups(ValueUnion.psz, &groups);
435 CHECK_ERROR(machine, COMSETTER(Groups)(ComSafeArrayAsInParam(groups)));
436 break;
437 }
438 case MODIFYVM_OSTYPE:
439 {
440 ComPtr<IGuestOSType> guestOSType;
441 CHECK_ERROR(a->virtualBox, GetGuestOSType(Bstr(ValueUnion.psz).raw(),
442 guestOSType.asOutParam()));
443 if (SUCCEEDED(rc) && guestOSType)
444 {
445 CHECK_ERROR(machine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz).raw()));
446 }
447 else
448 {
449 errorArgument("Invalid guest OS type '%s'", Utf8Str(ValueUnion.psz).c_str());
450 rc = E_FAIL;
451 }
452 break;
453 }
454
455 case MODIFYVM_MEMORY:
456 {
457 CHECK_ERROR(machine, COMSETTER(MemorySize)(ValueUnion.u32));
458 break;
459 }
460
461 case MODIFYVM_PAGEFUSION:
462 {
463 CHECK_ERROR(machine, COMSETTER(PageFusionEnabled)(ValueUnion.f));
464 break;
465 }
466
467 case MODIFYVM_VRAM:
468 {
469 CHECK_ERROR(machine, COMSETTER(VRAMSize)(ValueUnion.u32));
470 break;
471 }
472
473 case MODIFYVM_FIRMWARE:
474 {
475 if (!strcmp(ValueUnion.psz, "efi"))
476 {
477 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI));
478 }
479 else if (!strcmp(ValueUnion.psz, "efi32"))
480 {
481 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
482 }
483 else if (!strcmp(ValueUnion.psz, "efi64"))
484 {
485 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
486 }
487 else if (!strcmp(ValueUnion.psz, "efidual"))
488 {
489 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
490 }
491 else if (!strcmp(ValueUnion.psz, "bios"))
492 {
493 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
494 }
495 else
496 {
497 errorArgument("Invalid --firmware argument '%s'", ValueUnion.psz);
498 rc = E_FAIL;
499 }
500 break;
501 }
502
503 case MODIFYVM_ACPI:
504 {
505 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
506 break;
507 }
508
509 case MODIFYVM_IOAPIC:
510 {
511 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
512 break;
513 }
514
515 case MODIFYVM_PAE:
516 {
517 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_PAE, ValueUnion.f));
518 break;
519 }
520
521 case MODIFYVM_SYNTHCPU:
522 {
523 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_Synthetic, ValueUnion.f));
524 break;
525 }
526
527 case MODIFYVM_HWVIRTEX:
528 {
529 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
530 break;
531 }
532
533 case MODIFYVM_HWVIRTEXEXCLUSIVE:
534 {
535 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Exclusive, ValueUnion.f));
536 break;
537 }
538
539 case MODIFYVM_SETCPUID:
540 {
541 uint32_t id = ValueUnion.u32;
542 uint32_t aValue[4];
543
544 for (unsigned i = 0 ; i < 4 ; i++)
545 {
546 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
547 if (RT_FAILURE(vrc))
548 return errorSyntax(USAGE_MODIFYVM,
549 "Missing or Invalid argument to '%s'",
550 GetOptState.pDef->pszLong);
551 aValue[i] = ValueUnion.u32;
552 }
553 CHECK_ERROR(machine, SetCPUIDLeaf(id, aValue[0], aValue[1], aValue[2], aValue[3]));
554 break;
555 }
556
557 case MODIFYVM_DELCPUID:
558 {
559 CHECK_ERROR(machine, RemoveCPUIDLeaf(ValueUnion.u32));
560 break;
561 }
562
563 case MODIFYVM_DELALLCPUID:
564 {
565 CHECK_ERROR(machine, RemoveAllCPUIDLeaves());
566 break;
567 }
568
569 case MODIFYVM_NESTEDPAGING:
570 {
571 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
572 break;
573 }
574
575 case MODIFYVM_LARGEPAGES:
576 {
577 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_LargePages, ValueUnion.f));
578 break;
579 }
580
581 case MODIFYVM_VTXVPID:
582 {
583 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
584 break;
585 }
586
587 case MODIFYVM_CPUS:
588 {
589 CHECK_ERROR(machine, COMSETTER(CPUCount)(ValueUnion.u32));
590 break;
591 }
592
593 case MODIFYVM_RTCUSEUTC:
594 {
595 CHECK_ERROR(machine, COMSETTER(RTCUseUTC)(ValueUnion.f));
596 break;
597 }
598
599 case MODIFYVM_CPUHOTPLUG:
600 {
601 CHECK_ERROR(machine, COMSETTER(CPUHotPlugEnabled)(ValueUnion.f));
602 break;
603 }
604
605 case MODIFYVM_PLUGCPU:
606 {
607 CHECK_ERROR(machine, HotPlugCPU(ValueUnion.u32));
608 break;
609 }
610
611 case MODIFYVM_UNPLUGCPU:
612 {
613 CHECK_ERROR(machine, HotUnplugCPU(ValueUnion.u32));
614 break;
615 }
616
617 case MODIFYVM_CPU_EXECTUION_CAP:
618 {
619 CHECK_ERROR(machine, COMSETTER(CPUExecutionCap)(ValueUnion.u32));
620 break;
621 }
622
623 case MODIFYVM_MONITORCOUNT:
624 {
625 CHECK_ERROR(machine, COMSETTER(MonitorCount)(ValueUnion.u32));
626 break;
627 }
628
629 case MODIFYVM_ACCELERATE3D:
630 {
631 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
632 break;
633 }
634
635#ifdef VBOX_WITH_VIDEOHWACCEL
636 case MODIFYVM_ACCELERATE2DVIDEO:
637 {
638 CHECK_ERROR(machine, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
639 break;
640 }
641#endif
642
643 case MODIFYVM_BIOSLOGOFADEIN:
644 {
645 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
646 break;
647 }
648
649 case MODIFYVM_BIOSLOGOFADEOUT:
650 {
651 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
652 break;
653 }
654
655 case MODIFYVM_BIOSLOGODISPLAYTIME:
656 {
657 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
658 break;
659 }
660
661 case MODIFYVM_BIOSLOGOIMAGEPATH:
662 {
663 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz).raw()));
664 break;
665 }
666
667 case MODIFYVM_BIOSBOOTMENU:
668 {
669 if (!strcmp(ValueUnion.psz, "disabled"))
670 {
671 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
672 }
673 else if (!strcmp(ValueUnion.psz, "menuonly"))
674 {
675 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
676 }
677 else if (!strcmp(ValueUnion.psz, "messageandmenu"))
678 {
679 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
680 }
681 else
682 {
683 errorArgument("Invalid --biosbootmenu argument '%s'", ValueUnion.psz);
684 rc = E_FAIL;
685 }
686 break;
687 }
688
689 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
690 {
691 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
692 break;
693 }
694
695 case MODIFYVM_BIOSPXEDEBUG:
696 {
697 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
698 break;
699 }
700
701 case MODIFYVM_BOOT:
702 {
703 if (!strcmp(ValueUnion.psz, "none"))
704 {
705 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
706 }
707 else if (!strcmp(ValueUnion.psz, "floppy"))
708 {
709 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
710 }
711 else if (!strcmp(ValueUnion.psz, "dvd"))
712 {
713 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
714 }
715 else if (!strcmp(ValueUnion.psz, "disk"))
716 {
717 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
718 }
719 else if (!strcmp(ValueUnion.psz, "net"))
720 {
721 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
722 }
723 else
724 return errorArgument("Invalid boot device '%s'", ValueUnion.psz);
725 break;
726 }
727
728 case MODIFYVM_HDA: // deprecated
729 case MODIFYVM_HDB: // deprecated
730 case MODIFYVM_HDD: // deprecated
731 case MODIFYVM_SATAPORT: // deprecated
732 {
733 uint32_t u1 = 0, u2 = 0;
734 Bstr bstrController = L"IDE Controller";
735
736 switch (c)
737 {
738 case MODIFYVM_HDA: // deprecated
739 u1 = 0;
740 break;
741
742 case MODIFYVM_HDB: // deprecated
743 u1 = 0;
744 u2 = 1;
745 break;
746
747 case MODIFYVM_HDD: // deprecated
748 u1 = 1;
749 u2 = 1;
750 break;
751
752 case MODIFYVM_SATAPORT: // deprecated
753 u1 = GetOptState.uIndex;
754 bstrController = L"SATA";
755 break;
756 }
757
758 if (!strcmp(ValueUnion.psz, "none"))
759 {
760 machine->DetachDevice(bstrController.raw(), u1, u2);
761 }
762 else
763 {
764 ComPtr<IMedium> hardDisk;
765 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk,
766 AccessMode_ReadWrite, hardDisk,
767 false /* fForceNewUuidOnOpen */, NULL);
768 if (FAILED(rc))
769 break;
770 if (hardDisk)
771 {
772 CHECK_ERROR(machine, AttachDevice(bstrController.raw(),
773 u1, u2,
774 DeviceType_HardDisk,
775 hardDisk));
776 }
777 else
778 rc = E_FAIL;
779 }
780 break;
781 }
782
783 case MODIFYVM_IDECONTROLLER: // deprecated
784 {
785 ComPtr<IStorageController> storageController;
786 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE Controller").raw(),
787 storageController.asOutParam()));
788
789 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
790 {
791 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
792 }
793 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
794 {
795 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
796 }
797 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
798 {
799 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
800 }
801 else
802 {
803 errorArgument("Invalid --idecontroller argument '%s'", ValueUnion.psz);
804 rc = E_FAIL;
805 }
806 break;
807 }
808
809 case MODIFYVM_SATAIDEEMULATION: // deprecated
810 {
811 ComPtr<IStorageController> SataCtl;
812 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA").raw(),
813 SataCtl.asOutParam()));
814
815 if (SUCCEEDED(rc))
816 CHECK_ERROR(SataCtl, SetIDEEmulationPort(GetOptState.uIndex, ValueUnion.u32));
817 break;
818 }
819
820 case MODIFYVM_SATAPORTCOUNT: // deprecated
821 {
822 ComPtr<IStorageController> SataCtl;
823 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA").raw(),
824 SataCtl.asOutParam()));
825
826 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
827 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
828 break;
829 }
830
831 case MODIFYVM_SATA: // deprecated
832 {
833 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
834 {
835 ComPtr<IStorageController> ctl;
836 CHECK_ERROR(machine, AddStorageController(Bstr("SATA").raw(),
837 StorageBus_SATA,
838 ctl.asOutParam()));
839 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
840 }
841 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
842 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA").raw()));
843 else
844 return errorArgument("Invalid --usb argument '%s'", ValueUnion.psz);
845 break;
846 }
847
848 case MODIFYVM_SCSIPORT: // deprecated
849 {
850 if (!strcmp(ValueUnion.psz, "none"))
851 {
852 rc = machine->DetachDevice(Bstr("LsiLogic").raw(),
853 GetOptState.uIndex, 0);
854 if (FAILED(rc))
855 CHECK_ERROR(machine, DetachDevice(Bstr("BusLogic").raw(),
856 GetOptState.uIndex, 0));
857 }
858 else
859 {
860 ComPtr<IMedium> hardDisk;
861 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk,
862 AccessMode_ReadWrite, hardDisk,
863 false /* fForceNewUuidOnOpen */, NULL);
864 if (FAILED(rc))
865 break;
866 if (hardDisk)
867 {
868 rc = machine->AttachDevice(Bstr("LsiLogic").raw(),
869 GetOptState.uIndex, 0,
870 DeviceType_HardDisk,
871 hardDisk);
872 if (FAILED(rc))
873 CHECK_ERROR(machine,
874 AttachDevice(Bstr("BusLogic").raw(),
875 GetOptState.uIndex, 0,
876 DeviceType_HardDisk,
877 hardDisk));
878 }
879 else
880 rc = E_FAIL;
881 }
882 break;
883 }
884
885 case MODIFYVM_SCSITYPE: // deprecated
886 {
887 ComPtr<IStorageController> ctl;
888
889 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
890 {
891 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
892 if (FAILED(rc))
893 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
894
895 CHECK_ERROR(machine,
896 AddStorageController(Bstr("LsiLogic").raw(),
897 StorageBus_SCSI,
898 ctl.asOutParam()));
899
900 if (SUCCEEDED(rc))
901 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
902 }
903 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
904 {
905 rc = machine->RemoveStorageController(Bstr("LsiLogic").raw());
906 if (FAILED(rc))
907 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic").raw()));
908
909 CHECK_ERROR(machine,
910 AddStorageController(Bstr("BusLogic").raw(),
911 StorageBus_SCSI,
912 ctl.asOutParam()));
913
914 if (SUCCEEDED(rc))
915 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
916 }
917 else
918 return errorArgument("Invalid --scsitype argument '%s'", ValueUnion.psz);
919 break;
920 }
921
922 case MODIFYVM_SCSI: // deprecated
923 {
924 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
925 {
926 ComPtr<IStorageController> ctl;
927
928 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic").raw(),
929 StorageBus_SCSI,
930 ctl.asOutParam()));
931 if (SUCCEEDED(rc))
932 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
933 }
934 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
935 {
936 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
937 if (FAILED(rc))
938 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
939 }
940 break;
941 }
942
943 case MODIFYVM_DVDPASSTHROUGH: // deprecated
944 {
945 CHECK_ERROR(machine, PassthroughDevice(Bstr("IDE Controller").raw(),
946 1, 0,
947 !strcmp(ValueUnion.psz, "on")));
948 break;
949 }
950
951 case MODIFYVM_DVD: // deprecated
952 {
953 ComPtr<IMedium> dvdMedium;
954
955 /* unmount? */
956 if (!strcmp(ValueUnion.psz, "none"))
957 {
958 /* nothing to do, NULL object will cause unmount */
959 }
960 /* host drive? */
961 else if (!strncmp(ValueUnion.psz, "host:", 5))
962 {
963 ComPtr<IHost> host;
964 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
965 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5).raw(),
966 dvdMedium.asOutParam());
967 if (!dvdMedium)
968 {
969 /* 2nd try: try with the real name, important on Linux+libhal */
970 char szPathReal[RTPATH_MAX];
971 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
972 {
973 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
974 rc = E_FAIL;
975 break;
976 }
977 rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
978 dvdMedium.asOutParam());
979 if (!dvdMedium)
980 {
981 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
982 rc = E_FAIL;
983 break;
984 }
985 }
986 }
987 else
988 {
989 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_DVD,
990 AccessMode_ReadOnly, dvdMedium,
991 false /* fForceNewUuidOnOpen */, NULL);
992 if (FAILED(rc))
993 break;
994 if (!dvdMedium)
995 {
996 rc = E_FAIL;
997 break;
998 }
999 }
1000
1001 CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller").raw(),
1002 1, 0,
1003 dvdMedium,
1004 FALSE /* aForce */));
1005 break;
1006 }
1007
1008 case MODIFYVM_FLOPPY: // deprecated
1009 {
1010 ComPtr<IMedium> floppyMedium;
1011 ComPtr<IMediumAttachment> floppyAttachment;
1012 machine->GetMediumAttachment(Bstr("Floppy Controller").raw(),
1013 0, 0, floppyAttachment.asOutParam());
1014
1015 /* disable? */
1016 if (!strcmp(ValueUnion.psz, "disabled"))
1017 {
1018 /* disable the controller */
1019 if (floppyAttachment)
1020 CHECK_ERROR(machine, DetachDevice(Bstr("Floppy Controller").raw(),
1021 0, 0));
1022 }
1023 else
1024 {
1025 /* enable the controller */
1026 if (!floppyAttachment)
1027 CHECK_ERROR(machine, AttachDeviceWithoutMedium(Bstr("Floppy Controller").raw(),
1028 0, 0,
1029 DeviceType_Floppy));
1030
1031 /* unmount? */
1032 if ( !strcmp(ValueUnion.psz, "none")
1033 || !strcmp(ValueUnion.psz, "empty")) // deprecated
1034 {
1035 /* nothing to do, NULL object will cause unmount */
1036 }
1037 /* host drive? */
1038 else if (!strncmp(ValueUnion.psz, "host:", 5))
1039 {
1040 ComPtr<IHost> host;
1041 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1042 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5).raw(),
1043 floppyMedium.asOutParam());
1044 if (!floppyMedium)
1045 {
1046 errorArgument("Invalid host floppy drive name \"%s\"", ValueUnion.psz + 5);
1047 rc = E_FAIL;
1048 break;
1049 }
1050 }
1051 else
1052 {
1053 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_Floppy,
1054 AccessMode_ReadWrite, floppyMedium,
1055 false /* fForceNewUuidOnOpen */, NULL);
1056 if (FAILED(rc))
1057 break;
1058 if (!floppyMedium)
1059 {
1060 rc = E_FAIL;
1061 break;
1062 }
1063 }
1064 CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller").raw(),
1065 0, 0,
1066 floppyMedium,
1067 FALSE /* aForce */));
1068 }
1069 break;
1070 }
1071
1072 case MODIFYVM_NICTRACEFILE:
1073 {
1074 ComPtr<INetworkAdapter> nic;
1075
1076 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1077 ASSERT(nic);
1078
1079 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz).raw()));
1080 break;
1081 }
1082
1083 case MODIFYVM_NICTRACE:
1084 {
1085 ComPtr<INetworkAdapter> nic;
1086
1087 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1088 ASSERT(nic);
1089
1090 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
1091 break;
1092 }
1093
1094 case MODIFYVM_NICPROPERTY:
1095 {
1096 ComPtr<INetworkAdapter> nic;
1097
1098 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1099 ASSERT(nic);
1100
1101 if (nic)
1102 {
1103 /* Parse 'name=value' */
1104 char *pszProperty = RTStrDup(ValueUnion.psz);
1105 if (pszProperty)
1106 {
1107 char *pDelimiter = strchr(pszProperty, '=');
1108 if (pDelimiter)
1109 {
1110 *pDelimiter = '\0';
1111
1112 Bstr bstrName = pszProperty;
1113 Bstr bstrValue = &pDelimiter[1];
1114 CHECK_ERROR(nic, SetProperty(bstrName.raw(), bstrValue.raw()));
1115 }
1116 else
1117 {
1118 errorArgument("Invalid --nicproperty%d argument '%s'", GetOptState.uIndex, ValueUnion.psz);
1119 rc = E_FAIL;
1120 }
1121 RTStrFree(pszProperty);
1122 }
1123 else
1124 {
1125 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for --nicproperty%d '%s'\n", GetOptState.uIndex, ValueUnion.psz);
1126 rc = E_FAIL;
1127 }
1128 }
1129 break;
1130 }
1131 case MODIFYVM_NICTYPE:
1132 {
1133 ComPtr<INetworkAdapter> nic;
1134
1135 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1136 ASSERT(nic);
1137
1138 if (!strcmp(ValueUnion.psz, "Am79C970A"))
1139 {
1140 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1141 }
1142 else if (!strcmp(ValueUnion.psz, "Am79C973"))
1143 {
1144 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1145 }
1146#ifdef VBOX_WITH_E1000
1147 else if (!strcmp(ValueUnion.psz, "82540EM"))
1148 {
1149 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1150 }
1151 else if (!strcmp(ValueUnion.psz, "82543GC"))
1152 {
1153 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1154 }
1155 else if (!strcmp(ValueUnion.psz, "82545EM"))
1156 {
1157 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1158 }
1159#endif
1160#ifdef VBOX_WITH_VIRTIO
1161 else if (!strcmp(ValueUnion.psz, "virtio"))
1162 {
1163 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1164 }
1165#endif /* VBOX_WITH_VIRTIO */
1166 else
1167 {
1168 errorArgument("Invalid NIC type '%s' specified for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1169 rc = E_FAIL;
1170 }
1171 break;
1172 }
1173
1174 case MODIFYVM_NICSPEED:
1175 {
1176 ComPtr<INetworkAdapter> nic;
1177
1178 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1179 ASSERT(nic);
1180
1181 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1182 break;
1183 }
1184
1185 case MODIFYVM_NICBOOTPRIO:
1186 {
1187 ComPtr<INetworkAdapter> nic;
1188
1189 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1190 ASSERT(nic);
1191
1192 /* Somewhat arbitrary limitation - we can pass a list of up to 4 PCI devices
1193 * to the PXE ROM, hence only boot priorities 1-4 are allowed (in addition to
1194 * 0 for the default lowest priority).
1195 */
1196 if (ValueUnion.u32 > 4)
1197 {
1198 errorArgument("Invalid boot priority '%u' specfied for NIC %u", ValueUnion.u32, GetOptState.uIndex);
1199 rc = E_FAIL;
1200 }
1201 else
1202 {
1203 CHECK_ERROR(nic, COMSETTER(BootPriority)(ValueUnion.u32));
1204 }
1205 break;
1206 }
1207
1208 case MODIFYVM_NICPROMISC:
1209 {
1210 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
1211 if (!strcmp(ValueUnion.psz, "deny"))
1212 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
1213 else if ( !strcmp(ValueUnion.psz, "allow-vms")
1214 || !strcmp(ValueUnion.psz, "allow-network"))
1215 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
1216 else if (!strcmp(ValueUnion.psz, "allow-all"))
1217 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
1218 else
1219 {
1220 errorArgument("Unknown promiscuous mode policy '%s'", ValueUnion.psz);
1221 rc = E_INVALIDARG;
1222 break;
1223 }
1224
1225 ComPtr<INetworkAdapter> nic;
1226 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1227 ASSERT(nic);
1228
1229 CHECK_ERROR(nic, COMSETTER(PromiscModePolicy)(enmPromiscModePolicy));
1230 break;
1231 }
1232
1233 case MODIFYVM_NICBWGROUP:
1234 {
1235 ComPtr<INetworkAdapter> nic;
1236 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1237 ASSERT(nic);
1238
1239 if (!RTStrICmp(ValueUnion.psz, "none"))
1240 {
1241 /* Just remove the bandwidth group. */
1242 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(NULL));
1243 }
1244 else
1245 {
1246 ComPtr<IBandwidthControl> bwCtrl;
1247 ComPtr<IBandwidthGroup> bwGroup;
1248
1249 CHECK_ERROR(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
1250
1251 if (SUCCEEDED(rc))
1252 {
1253 CHECK_ERROR(bwCtrl, GetBandwidthGroup(Bstr(ValueUnion.psz).raw(), bwGroup.asOutParam()));
1254 if (SUCCEEDED(rc))
1255 {
1256 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(bwGroup));
1257 }
1258 }
1259 }
1260 break;
1261 }
1262
1263 case MODIFYVM_NIC:
1264 {
1265 ComPtr<INetworkAdapter> nic;
1266
1267 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1268 ASSERT(nic);
1269
1270 if (!strcmp(ValueUnion.psz, "none"))
1271 {
1272 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1273 }
1274 else if (!strcmp(ValueUnion.psz, "null"))
1275 {
1276 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1277 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Null));
1278 }
1279 else if (!strcmp(ValueUnion.psz, "nat"))
1280 {
1281 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1282 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_NAT));
1283 }
1284 else if ( !strcmp(ValueUnion.psz, "bridged")
1285 || !strcmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1286 {
1287 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1288 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged));
1289 }
1290 else if (!strcmp(ValueUnion.psz, "intnet"))
1291 {
1292 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1293 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Internal));
1294 }
1295 else if (!strcmp(ValueUnion.psz, "hostonly"))
1296 {
1297
1298 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1299 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly));
1300 }
1301 else if (!strcmp(ValueUnion.psz, "generic"))
1302 {
1303
1304 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1305 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic));
1306 }
1307 else
1308 {
1309 errorArgument("Invalid type '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1310 rc = E_FAIL;
1311 }
1312 break;
1313 }
1314
1315 case MODIFYVM_CABLECONNECTED:
1316 {
1317 ComPtr<INetworkAdapter> nic;
1318
1319 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1320 ASSERT(nic);
1321
1322 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1323 break;
1324 }
1325
1326 case MODIFYVM_BRIDGEADAPTER:
1327 {
1328 ComPtr<INetworkAdapter> nic;
1329
1330 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1331 ASSERT(nic);
1332
1333 /* remove it? */
1334 if (!strcmp(ValueUnion.psz, "none"))
1335 {
1336 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr().raw()));
1337 }
1338 else
1339 {
1340 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr(ValueUnion.psz).raw()));
1341 }
1342 break;
1343 }
1344
1345 case MODIFYVM_HOSTONLYADAPTER:
1346 {
1347 ComPtr<INetworkAdapter> nic;
1348
1349 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1350 ASSERT(nic);
1351
1352 /* remove it? */
1353 if (!strcmp(ValueUnion.psz, "none"))
1354 {
1355 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr().raw()));
1356 }
1357 else
1358 {
1359 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr(ValueUnion.psz).raw()));
1360 }
1361 break;
1362 }
1363
1364 case MODIFYVM_INTNET:
1365 {
1366 ComPtr<INetworkAdapter> nic;
1367
1368 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1369 ASSERT(nic);
1370
1371 /* remove it? */
1372 if (!strcmp(ValueUnion.psz, "none"))
1373 {
1374 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr().raw()));
1375 }
1376 else
1377 {
1378 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz).raw()));
1379 }
1380 break;
1381 }
1382
1383 case MODIFYVM_GENERICDRV:
1384 {
1385 ComPtr<INetworkAdapter> nic;
1386
1387 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1388 ASSERT(nic);
1389
1390 CHECK_ERROR(nic, COMSETTER(GenericDriver)(Bstr(ValueUnion.psz).raw()));
1391 break;
1392 }
1393
1394 case MODIFYVM_NATNET:
1395 {
1396 ComPtr<INetworkAdapter> nic;
1397 ComPtr<INATEngine> engine;
1398
1399 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1400 ASSERT(nic);
1401
1402 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1403
1404 const char *psz = ValueUnion.psz;
1405 if (!strcmp("default", psz))
1406 psz = "";
1407
1408 CHECK_ERROR(engine, COMSETTER(Network)(Bstr(psz).raw()));
1409 break;
1410 }
1411
1412 case MODIFYVM_NATBINDIP:
1413 {
1414 ComPtr<INetworkAdapter> nic;
1415 ComPtr<INATEngine> engine;
1416
1417 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1418 ASSERT(nic);
1419
1420 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1421 CHECK_ERROR(engine, COMSETTER(HostIP)(Bstr(ValueUnion.psz).raw()));
1422 break;
1423 }
1424
1425#define ITERATE_TO_NEXT_TERM(ch) \
1426 do { \
1427 while (*ch != ',') \
1428 { \
1429 if (*ch == 0) \
1430 { \
1431 return errorSyntax(USAGE_MODIFYVM, \
1432 "Missing or Invalid argument to '%s'", \
1433 GetOptState.pDef->pszLong); \
1434 } \
1435 ch++; \
1436 } \
1437 *ch = '\0'; \
1438 ch++; \
1439 } while(0)
1440
1441 case MODIFYVM_NATSETTINGS:
1442 {
1443 ComPtr<INetworkAdapter> nic;
1444 ComPtr<INATEngine> engine;
1445 char *strMtu;
1446 char *strSockSnd;
1447 char *strSockRcv;
1448 char *strTcpSnd;
1449 char *strTcpRcv;
1450 char *strRaw = RTStrDup(ValueUnion.psz);
1451 char *ch = strRaw;
1452 strMtu = RTStrStrip(ch);
1453 ITERATE_TO_NEXT_TERM(ch);
1454 strSockSnd = RTStrStrip(ch);
1455 ITERATE_TO_NEXT_TERM(ch);
1456 strSockRcv = RTStrStrip(ch);
1457 ITERATE_TO_NEXT_TERM(ch);
1458 strTcpSnd = RTStrStrip(ch);
1459 ITERATE_TO_NEXT_TERM(ch);
1460 strTcpRcv = RTStrStrip(ch);
1461
1462 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1463 ASSERT(nic);
1464
1465 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1466 CHECK_ERROR(engine, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv),
1467 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv)));
1468 break;
1469 }
1470
1471
1472 case MODIFYVM_NATPF:
1473 {
1474 ComPtr<INetworkAdapter> nic;
1475 ComPtr<INATEngine> engine;
1476
1477 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1478 ASSERT(nic);
1479
1480 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1481 /* format name:proto:hostip:hostport:guestip:guestport*/
1482 if (RTStrCmp(ValueUnion.psz, "delete") != 0)
1483 {
1484 char *strName;
1485 char *strProto;
1486 char *strHostIp;
1487 char *strHostPort;
1488 char *strGuestIp;
1489 char *strGuestPort;
1490 char *strRaw = RTStrDup(ValueUnion.psz);
1491 char *ch = strRaw;
1492 strName = RTStrStrip(ch);
1493 ITERATE_TO_NEXT_TERM(ch);
1494 strProto = RTStrStrip(ch);
1495 ITERATE_TO_NEXT_TERM(ch);
1496 strHostIp = RTStrStrip(ch);
1497 ITERATE_TO_NEXT_TERM(ch);
1498 strHostPort = RTStrStrip(ch);
1499 ITERATE_TO_NEXT_TERM(ch);
1500 strGuestIp = RTStrStrip(ch);
1501 ITERATE_TO_NEXT_TERM(ch);
1502 strGuestPort = RTStrStrip(ch);
1503 NATProtocol_T proto;
1504 if (RTStrICmp(strProto, "udp") == 0)
1505 proto = NATProtocol_UDP;
1506 else if (RTStrICmp(strProto, "tcp") == 0)
1507 proto = NATProtocol_TCP;
1508 else
1509 {
1510 errorArgument("Invalid proto '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1511 rc = E_FAIL;
1512 break;
1513 }
1514 CHECK_ERROR(engine, AddRedirect(Bstr(strName).raw(), proto,
1515 Bstr(strHostIp).raw(),
1516 RTStrToUInt16(strHostPort),
1517 Bstr(strGuestIp).raw(),
1518 RTStrToUInt16(strGuestPort)));
1519 }
1520 else
1521 {
1522 /* delete NAT Rule operation */
1523 int vrc;
1524 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1525 if (RT_FAILURE(vrc))
1526 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
1527 CHECK_ERROR(engine, RemoveRedirect(Bstr(ValueUnion.psz).raw()));
1528 }
1529 break;
1530 }
1531 #undef ITERATE_TO_NEXT_TERM
1532 case MODIFYVM_NATALIASMODE:
1533 {
1534 ComPtr<INetworkAdapter> nic;
1535 ComPtr<INATEngine> engine;
1536 uint32_t aliasMode = 0;
1537
1538 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1539 ASSERT(nic);
1540
1541 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1542 if (RTStrCmp(ValueUnion.psz,"default") == 0)
1543 {
1544 aliasMode = 0;
1545 }
1546 else
1547 {
1548 char *token = (char *)ValueUnion.psz;
1549 while(token)
1550 {
1551 if (RTStrNCmp(token, "log", 3) == 0)
1552 aliasMode |= 0x1;
1553 else if (RTStrNCmp(token, "proxyonly", 9) == 0)
1554 aliasMode |= 0x2;
1555 else if (RTStrNCmp(token, "sameports", 9) == 0)
1556 aliasMode |= 0x4;
1557 token = RTStrStr(token, ",");
1558 if (token == NULL)
1559 break;
1560 token++;
1561 }
1562 }
1563 CHECK_ERROR(engine, COMSETTER(AliasMode)(aliasMode));
1564 break;
1565 }
1566
1567 case MODIFYVM_NATTFTPPREFIX:
1568 {
1569 ComPtr<INetworkAdapter> nic;
1570 ComPtr<INATEngine> engine;
1571
1572 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1573 ASSERT(nic);
1574
1575 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1576 CHECK_ERROR(engine, COMSETTER(TFTPPrefix)(Bstr(ValueUnion.psz).raw()));
1577 break;
1578 }
1579
1580 case MODIFYVM_NATTFTPFILE:
1581 {
1582 ComPtr<INetworkAdapter> nic;
1583 ComPtr<INATEngine> engine;
1584
1585 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1586 ASSERT(nic);
1587
1588 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1589 CHECK_ERROR(engine, COMSETTER(TFTPBootFile)(Bstr(ValueUnion.psz).raw()));
1590 break;
1591 }
1592
1593 case MODIFYVM_NATTFTPSERVER:
1594 {
1595 ComPtr<INetworkAdapter> nic;
1596 ComPtr<INATEngine> engine;
1597
1598 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1599 ASSERT(nic);
1600
1601 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1602 CHECK_ERROR(engine, COMSETTER(TFTPNextServer)(Bstr(ValueUnion.psz).raw()));
1603 break;
1604 }
1605 case MODIFYVM_NATDNSPASSDOMAIN:
1606 {
1607 ComPtr<INetworkAdapter> nic;
1608 ComPtr<INATEngine> engine;
1609
1610 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1611 ASSERT(nic);
1612
1613 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1614 CHECK_ERROR(engine, COMSETTER(DNSPassDomain)(ValueUnion.f));
1615 break;
1616 }
1617
1618 case MODIFYVM_NATDNSPROXY:
1619 {
1620 ComPtr<INetworkAdapter> nic;
1621 ComPtr<INATEngine> engine;
1622
1623 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1624 ASSERT(nic);
1625
1626 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1627 CHECK_ERROR(engine, COMSETTER(DNSProxy)(ValueUnion.f));
1628 break;
1629 }
1630
1631 case MODIFYVM_NATDNSHOSTRESOLVER:
1632 {
1633 ComPtr<INetworkAdapter> nic;
1634 ComPtr<INATEngine> engine;
1635
1636 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1637 ASSERT(nic);
1638
1639 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1640 CHECK_ERROR(engine, COMSETTER(DNSUseHostResolver)(ValueUnion.f));
1641 break;
1642 }
1643 case MODIFYVM_MACADDRESS:
1644 {
1645 ComPtr<INetworkAdapter> nic;
1646
1647 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1648 ASSERT(nic);
1649
1650 /* generate one? */
1651 if (!strcmp(ValueUnion.psz, "auto"))
1652 {
1653 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr().raw()));
1654 }
1655 else
1656 {
1657 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz).raw()));
1658 }
1659 break;
1660 }
1661
1662 case MODIFYVM_HIDPTR:
1663 {
1664 bool fEnableUsb = false;
1665 if (!strcmp(ValueUnion.psz, "ps2"))
1666 {
1667 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_PS2Mouse));
1668 }
1669 else if (!strcmp(ValueUnion.psz, "usb"))
1670 {
1671 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_USBMouse));
1672 if (SUCCEEDED(rc))
1673 fEnableUsb = true;
1674 }
1675 else if (!strcmp(ValueUnion.psz, "usbtablet"))
1676 {
1677 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_USBTablet));
1678 if (SUCCEEDED(rc))
1679 fEnableUsb = true;
1680 }
1681 else
1682 {
1683 errorArgument("Invalid type '%s' specfied for pointing device", ValueUnion.psz);
1684 rc = E_FAIL;
1685 }
1686 if (fEnableUsb)
1687 {
1688 /* Make sure the OHCI controller is enabled. */
1689 ComPtr<IUSBController> UsbCtl;
1690 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1691 if (SUCCEEDED(rc))
1692 {
1693 BOOL fEnabled;
1694 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1695 if (FAILED(rc))
1696 fEnabled = false;
1697 if (!fEnabled)
1698 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1699 }
1700 }
1701 break;
1702 }
1703
1704 case MODIFYVM_HIDKBD:
1705 {
1706 bool fEnableUsb = false;
1707 if (!strcmp(ValueUnion.psz, "ps2"))
1708 {
1709 CHECK_ERROR(machine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_PS2Keyboard));
1710 }
1711 else if (!strcmp(ValueUnion.psz, "usb"))
1712 {
1713 CHECK_ERROR(machine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_USBKeyboard));
1714 if (SUCCEEDED(rc))
1715 fEnableUsb = true;
1716 }
1717 else
1718 {
1719 errorArgument("Invalid type '%s' specfied for keyboard", ValueUnion.psz);
1720 rc = E_FAIL;
1721 }
1722 if (fEnableUsb)
1723 {
1724 /* Make sure the OHCI controller is enabled. */
1725 ComPtr<IUSBController> UsbCtl;
1726 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1727 if (SUCCEEDED(rc))
1728 {
1729 BOOL fEnabled;
1730 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1731 if (FAILED(rc))
1732 fEnabled = false;
1733 if (!fEnabled)
1734 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1735 }
1736 }
1737 break;
1738 }
1739
1740 case MODIFYVM_UARTMODE:
1741 {
1742 ComPtr<ISerialPort> uart;
1743 char *pszIRQ = NULL;
1744
1745 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1746 ASSERT(uart);
1747
1748 if (!strcmp(ValueUnion.psz, "disconnected"))
1749 {
1750 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
1751 }
1752 else if ( !strcmp(ValueUnion.psz, "server")
1753 || !strcmp(ValueUnion.psz, "client")
1754 || !strcmp(ValueUnion.psz, "file"))
1755 {
1756 const char *pszMode = ValueUnion.psz;
1757
1758 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1759 if (RT_FAILURE(vrc))
1760 return errorSyntax(USAGE_MODIFYVM,
1761 "Missing or Invalid argument to '%s'",
1762 GetOptState.pDef->pszLong);
1763
1764 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1765
1766 if (!strcmp(pszMode, "server"))
1767 {
1768 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1769 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
1770 }
1771 else if (!strcmp(pszMode, "client"))
1772 {
1773 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1774 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
1775 }
1776 else if (!strcmp(pszMode, "file"))
1777 {
1778 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
1779 }
1780 }
1781 else
1782 {
1783 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1784 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
1785 }
1786 break;
1787 }
1788
1789 case MODIFYVM_UART:
1790 {
1791 ComPtr<ISerialPort> uart;
1792
1793 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1794 ASSERT(uart);
1795
1796 if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
1797 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
1798 else
1799 {
1800 const char *pszIOBase = ValueUnion.psz;
1801 uint32_t uVal = 0;
1802
1803 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
1804 if (RT_FAILURE(vrc))
1805 return errorSyntax(USAGE_MODIFYVM,
1806 "Missing or Invalid argument to '%s'",
1807 GetOptState.pDef->pszLong);
1808
1809 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
1810
1811 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1812 if (vrc != VINF_SUCCESS || uVal == 0)
1813 return errorArgument("Error parsing UART I/O base '%s'", pszIOBase);
1814 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
1815
1816 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
1817 }
1818 break;
1819 }
1820
1821#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
1822 case MODIFYVM_LPTMODE:
1823 {
1824 ComPtr<IParallelPort> lpt;
1825 char *pszIRQ = NULL;
1826
1827 CHECK_ERROR_BREAK(machine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
1828 ASSERT(lpt);
1829
1830 CHECK_ERROR(lpt, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1831 break;
1832 }
1833
1834 case MODIFYVM_LPT:
1835 {
1836 ComPtr<IParallelPort> lpt;
1837
1838 CHECK_ERROR_BREAK(machine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
1839 ASSERT(lpt);
1840
1841 if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
1842 CHECK_ERROR(lpt, COMSETTER(Enabled)(FALSE));
1843 else
1844 {
1845 const char *pszIOBase = ValueUnion.psz;
1846 uint32_t uVal = 0;
1847
1848 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_LPT;
1849 if (RT_FAILURE(vrc))
1850 return errorSyntax(USAGE_MODIFYVM,
1851 "Missing or Invalid argument to '%s'",
1852 GetOptState.pDef->pszLong);
1853
1854 CHECK_ERROR(lpt, COMSETTER(IRQ)(ValueUnion.u32));
1855
1856 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1857 if (vrc != VINF_SUCCESS || uVal == 0)
1858 return errorArgument("Error parsing LPT I/O base '%s'", pszIOBase);
1859 CHECK_ERROR(lpt, COMSETTER(IOBase)(uVal));
1860
1861 CHECK_ERROR(lpt, COMSETTER(Enabled)(TRUE));
1862 }
1863 break;
1864 }
1865#endif
1866
1867 case MODIFYVM_GUESTMEMORYBALLOON:
1868 {
1869 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
1870 break;
1871 }
1872
1873 case MODIFYVM_AUDIOCONTROLLER:
1874 {
1875 ComPtr<IAudioAdapter> audioAdapter;
1876 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1877 ASSERT(audioAdapter);
1878
1879 if (!strcmp(ValueUnion.psz, "sb16"))
1880 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1881 else if (!strcmp(ValueUnion.psz, "ac97"))
1882 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1883 else if (!strcmp(ValueUnion.psz, "hda"))
1884 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_HDA));
1885 else
1886 {
1887 errorArgument("Invalid --audiocontroller argument '%s'", ValueUnion.psz);
1888 rc = E_FAIL;
1889 }
1890 break;
1891 }
1892
1893 case MODIFYVM_AUDIO:
1894 {
1895 ComPtr<IAudioAdapter> audioAdapter;
1896 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1897 ASSERT(audioAdapter);
1898
1899 /* disable? */
1900 if (!strcmp(ValueUnion.psz, "none"))
1901 {
1902 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1903 }
1904 else if (!strcmp(ValueUnion.psz, "null"))
1905 {
1906 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1907 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1908 }
1909#ifdef RT_OS_WINDOWS
1910#ifdef VBOX_WITH_WINMM
1911 else if (!strcmp(ValueUnion.psz, "winmm"))
1912 {
1913 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1914 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1915 }
1916#endif
1917 else if (!strcmp(ValueUnion.psz, "dsound"))
1918 {
1919 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1920 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1921 }
1922#endif /* RT_OS_WINDOWS */
1923#ifdef RT_OS_LINUX
1924# ifdef VBOX_WITH_ALSA
1925 else if (!strcmp(ValueUnion.psz, "alsa"))
1926 {
1927 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1928 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1929 }
1930# endif
1931# ifdef VBOX_WITH_PULSE
1932 else if (!strcmp(ValueUnion.psz, "pulse"))
1933 {
1934 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1935 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1936 }
1937# endif
1938#endif /* !RT_OS_LINUX */
1939#ifdef RT_OS_SOLARIS
1940 else if (!strcmp(ValueUnion.psz, "solaudio"))
1941 {
1942 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1943 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1944 }
1945#endif /* !RT_OS_SOLARIS */
1946#ifdef RT_OS_FREEBSD
1947 else if (!strcmp(ValueUnion.psz, "oss"))
1948 {
1949 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1950 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1951 }
1952# ifdef VBOX_WITH_PULSE
1953 else if (!strcmp(ValueUnion.psz, "pulse"))
1954 {
1955 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1956 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1957 }
1958# endif
1959#endif /* !RT_OS_FREEBSD */
1960#ifdef RT_OS_DARWIN
1961 else if (!strcmp(ValueUnion.psz, "coreaudio"))
1962 {
1963 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1964 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1965 }
1966
1967#endif /* !RT_OS_DARWIN */
1968# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
1969 else if (!strcmp(ValueUnion.psz, "oss"))
1970 {
1971 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1972 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1973 }
1974# endif
1975 else
1976 {
1977 errorArgument("Invalid --audio argument '%s'", ValueUnion.psz);
1978 rc = E_FAIL;
1979 }
1980 break;
1981 }
1982
1983 case MODIFYVM_CLIPBOARD:
1984 {
1985 ClipboardMode_T mode;
1986 if (!strcmp(ValueUnion.psz, "disabled"))
1987 mode = ClipboardMode_Disabled;
1988 else if (!strcmp(ValueUnion.psz, "hosttoguest"))
1989 mode = ClipboardMode_HostToGuest;
1990 else if (!strcmp(ValueUnion.psz, "guesttohost"))
1991 mode = ClipboardMode_GuestToHost;
1992 else if (!strcmp(ValueUnion.psz, "bidirectional"))
1993 mode = ClipboardMode_Bidirectional;
1994 else
1995 {
1996 errorArgument("Invalid --clipboard argument '%s'", ValueUnion.psz);
1997 rc = E_FAIL;
1998 }
1999 if (SUCCEEDED(rc))
2000 {
2001 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(mode));
2002 }
2003 break;
2004 }
2005
2006 case MODIFYVM_DRAGANDDROP:
2007 {
2008 DragAndDropMode_T mode;
2009 if (!strcmp(ValueUnion.psz, "disabled"))
2010 mode = DragAndDropMode_Disabled;
2011 else if (!strcmp(ValueUnion.psz, "hosttoguest"))
2012 mode = DragAndDropMode_HostToGuest;
2013 else if (!strcmp(ValueUnion.psz, "guesttohost"))
2014 mode = DragAndDropMode_GuestToHost;
2015 else if (!strcmp(ValueUnion.psz, "bidirectional"))
2016 mode = DragAndDropMode_Bidirectional;
2017 else
2018 {
2019 errorArgument("Invalid --draganddrop argument '%s'", ValueUnion.psz);
2020 rc = E_FAIL;
2021 }
2022 if (SUCCEEDED(rc))
2023 {
2024 CHECK_ERROR(machine, COMSETTER(DragAndDropMode)(mode));
2025 }
2026 break;
2027 }
2028
2029 case MODIFYVM_VRDE_EXTPACK:
2030 {
2031 ComPtr<IVRDEServer> vrdeServer;
2032 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2033 ASSERT(vrdeServer);
2034
2035 if (vrdeServer)
2036 {
2037 if (strcmp(ValueUnion.psz, "default") != 0)
2038 {
2039 Bstr bstr(ValueUnion.psz);
2040 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(bstr.raw()));
2041 }
2042 else
2043 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(Bstr().raw()));
2044 }
2045 break;
2046 }
2047
2048 case MODIFYVM_VRDEPROPERTY:
2049 {
2050 ComPtr<IVRDEServer> vrdeServer;
2051 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2052 ASSERT(vrdeServer);
2053
2054 if (vrdeServer)
2055 {
2056 /* Parse 'name=value' */
2057 char *pszProperty = RTStrDup(ValueUnion.psz);
2058 if (pszProperty)
2059 {
2060 char *pDelimiter = strchr(pszProperty, '=');
2061 if (pDelimiter)
2062 {
2063 *pDelimiter = '\0';
2064
2065 Bstr bstrName = pszProperty;
2066 Bstr bstrValue = &pDelimiter[1];
2067 CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
2068 }
2069 else
2070 {
2071 RTStrFree(pszProperty);
2072
2073 errorArgument("Invalid --vrdeproperty argument '%s'", ValueUnion.psz);
2074 rc = E_FAIL;
2075 break;
2076 }
2077 RTStrFree(pszProperty);
2078 }
2079 else
2080 {
2081 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for VRDE property '%s'\n", ValueUnion.psz);
2082 rc = E_FAIL;
2083 }
2084 }
2085 break;
2086 }
2087
2088 case MODIFYVM_VRDPPORT:
2089 vrdeWarningDeprecatedOption("port");
2090
2091 case MODIFYVM_VRDEPORT:
2092 {
2093 ComPtr<IVRDEServer> vrdeServer;
2094 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2095 ASSERT(vrdeServer);
2096
2097 if (!strcmp(ValueUnion.psz, "default"))
2098 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr("0").raw()));
2099 else
2100 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr(ValueUnion.psz).raw()));
2101 break;
2102 }
2103
2104 case MODIFYVM_VRDPADDRESS:
2105 vrdeWarningDeprecatedOption("address");
2106
2107 case MODIFYVM_VRDEADDRESS:
2108 {
2109 ComPtr<IVRDEServer> vrdeServer;
2110 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2111 ASSERT(vrdeServer);
2112
2113 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Address").raw(), Bstr(ValueUnion.psz).raw()));
2114 break;
2115 }
2116
2117 case MODIFYVM_VRDPAUTHTYPE:
2118 vrdeWarningDeprecatedOption("authtype");
2119 case MODIFYVM_VRDEAUTHTYPE:
2120 {
2121 ComPtr<IVRDEServer> vrdeServer;
2122 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2123 ASSERT(vrdeServer);
2124
2125 if (!strcmp(ValueUnion.psz, "null"))
2126 {
2127 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Null));
2128 }
2129 else if (!strcmp(ValueUnion.psz, "external"))
2130 {
2131 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_External));
2132 }
2133 else if (!strcmp(ValueUnion.psz, "guest"))
2134 {
2135 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Guest));
2136 }
2137 else
2138 {
2139 errorArgument("Invalid --vrdeauthtype argument '%s'", ValueUnion.psz);
2140 rc = E_FAIL;
2141 }
2142 break;
2143 }
2144
2145 case MODIFYVM_VRDEAUTHLIBRARY:
2146 {
2147 ComPtr<IVRDEServer> vrdeServer;
2148 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2149 ASSERT(vrdeServer);
2150
2151 if (vrdeServer)
2152 {
2153 if (strcmp(ValueUnion.psz, "default") != 0)
2154 {
2155 Bstr bstr(ValueUnion.psz);
2156 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(bstr.raw()));
2157 }
2158 else
2159 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(Bstr().raw()));
2160 }
2161 break;
2162 }
2163
2164 case MODIFYVM_VRDPMULTICON:
2165 vrdeWarningDeprecatedOption("multicon");
2166 case MODIFYVM_VRDEMULTICON:
2167 {
2168 ComPtr<IVRDEServer> vrdeServer;
2169 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2170 ASSERT(vrdeServer);
2171
2172 CHECK_ERROR(vrdeServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
2173 break;
2174 }
2175
2176 case MODIFYVM_VRDPREUSECON:
2177 vrdeWarningDeprecatedOption("reusecon");
2178 case MODIFYVM_VRDEREUSECON:
2179 {
2180 ComPtr<IVRDEServer> vrdeServer;
2181 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2182 ASSERT(vrdeServer);
2183
2184 CHECK_ERROR(vrdeServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
2185 break;
2186 }
2187
2188 case MODIFYVM_VRDPVIDEOCHANNEL:
2189 vrdeWarningDeprecatedOption("videochannel");
2190 case MODIFYVM_VRDEVIDEOCHANNEL:
2191 {
2192 ComPtr<IVRDEServer> vrdeServer;
2193 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2194 ASSERT(vrdeServer);
2195
2196 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
2197 ValueUnion.f? Bstr("true").raw(): Bstr("false").raw()));
2198 break;
2199 }
2200
2201 case MODIFYVM_VRDPVIDEOCHANNELQUALITY:
2202 vrdeWarningDeprecatedOption("videochannelquality");
2203 case MODIFYVM_VRDEVIDEOCHANNELQUALITY:
2204 {
2205 ComPtr<IVRDEServer> vrdeServer;
2206 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2207 ASSERT(vrdeServer);
2208
2209 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
2210 Bstr(ValueUnion.psz).raw()));
2211 break;
2212 }
2213
2214 case MODIFYVM_VRDP:
2215 vrdeWarningDeprecatedOption("");
2216 case MODIFYVM_VRDE:
2217 {
2218 ComPtr<IVRDEServer> vrdeServer;
2219 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2220 ASSERT(vrdeServer);
2221
2222 CHECK_ERROR(vrdeServer, COMSETTER(Enabled)(ValueUnion.f));
2223 break;
2224 }
2225
2226 case MODIFYVM_USBEHCI:
2227 {
2228 ComPtr<IUSBController> UsbCtl;
2229 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
2230 if (SUCCEEDED(rc))
2231 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEHCI)(ValueUnion.f));
2232 break;
2233 }
2234
2235 case MODIFYVM_USB:
2236 {
2237 ComPtr<IUSBController> UsbCtl;
2238 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
2239 if (SUCCEEDED(rc))
2240 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(ValueUnion.f));
2241 break;
2242 }
2243
2244 case MODIFYVM_SNAPSHOTFOLDER:
2245 {
2246 if (!strcmp(ValueUnion.psz, "default"))
2247 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr().raw()));
2248 else
2249 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz).raw()));
2250 break;
2251 }
2252
2253 case MODIFYVM_TELEPORTER_ENABLED:
2254 {
2255 CHECK_ERROR(machine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
2256 break;
2257 }
2258
2259 case MODIFYVM_TELEPORTER_PORT:
2260 {
2261 CHECK_ERROR(machine, COMSETTER(TeleporterPort)(ValueUnion.u32));
2262 break;
2263 }
2264
2265 case MODIFYVM_TELEPORTER_ADDRESS:
2266 {
2267 CHECK_ERROR(machine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz).raw()));
2268 break;
2269 }
2270
2271 case MODIFYVM_TELEPORTER_PASSWORD:
2272 {
2273 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz).raw()));
2274 break;
2275 }
2276
2277 case MODIFYVM_TELEPORTER_PASSWORD_FILE:
2278 {
2279 Utf8Str password;
2280 RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &password);
2281 if (rcExit != RTEXITCODE_SUCCESS)
2282 rc = E_FAIL;
2283 else
2284 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(password).raw()));
2285 break;
2286 }
2287
2288 case MODIFYVM_TRACING_ENABLED:
2289 {
2290 CHECK_ERROR(machine, COMSETTER(TracingEnabled)(ValueUnion.f));
2291 break;
2292 }
2293
2294 case MODIFYVM_TRACING_CONFIG:
2295 {
2296 CHECK_ERROR(machine, COMSETTER(TracingConfig)(Bstr(ValueUnion.psz).raw()));
2297 break;
2298 }
2299
2300 case MODIFYVM_TRACING_ALLOW_VM_ACCESS:
2301 {
2302 CHECK_ERROR(machine, COMSETTER(AllowTracingToAccessVM)(ValueUnion.f));
2303 break;
2304 }
2305
2306 case MODIFYVM_FAULT_TOLERANCE:
2307 {
2308 if (!strcmp(ValueUnion.psz, "master"))
2309 {
2310 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Master)));
2311 }
2312 else
2313 if (!strcmp(ValueUnion.psz, "standby"))
2314 {
2315 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Standby)));
2316 }
2317 else
2318 {
2319 errorArgument("Invalid --faulttolerance argument '%s'", ValueUnion.psz);
2320 rc = E_FAIL;
2321 }
2322 break;
2323 }
2324
2325 case MODIFYVM_FAULT_TOLERANCE_ADDRESS:
2326 {
2327 CHECK_ERROR(machine, COMSETTER(FaultToleranceAddress)(Bstr(ValueUnion.psz).raw()));
2328 break;
2329 }
2330
2331 case MODIFYVM_FAULT_TOLERANCE_PORT:
2332 {
2333 CHECK_ERROR(machine, COMSETTER(FaultTolerancePort)(ValueUnion.u32));
2334 break;
2335 }
2336
2337 case MODIFYVM_FAULT_TOLERANCE_PASSWORD:
2338 {
2339 CHECK_ERROR(machine, COMSETTER(FaultTolerancePassword)(Bstr(ValueUnion.psz).raw()));
2340 break;
2341 }
2342
2343 case MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL:
2344 {
2345 CHECK_ERROR(machine, COMSETTER(FaultToleranceSyncInterval)(ValueUnion.u32));
2346 break;
2347 }
2348
2349 case MODIFYVM_HARDWARE_UUID:
2350 {
2351 CHECK_ERROR(machine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz).raw()));
2352 break;
2353 }
2354
2355 case MODIFYVM_HPET:
2356 {
2357 CHECK_ERROR(machine, COMSETTER(HPETEnabled)(ValueUnion.f));
2358 break;
2359 }
2360
2361 case MODIFYVM_IOCACHE:
2362 {
2363 CHECK_ERROR(machine, COMSETTER(IOCacheEnabled)(ValueUnion.f));
2364 break;
2365 }
2366
2367 case MODIFYVM_IOCACHESIZE:
2368 {
2369 CHECK_ERROR(machine, COMSETTER(IOCacheSize)(ValueUnion.u32));
2370 break;
2371 }
2372
2373 case MODIFYVM_CHIPSET:
2374 {
2375 if (!strcmp(ValueUnion.psz, "piix3"))
2376 {
2377 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_PIIX3));
2378 }
2379 else if (!strcmp(ValueUnion.psz, "ich9"))
2380 {
2381 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_ICH9));
2382 BOOL fIoApic = FALSE;
2383 CHECK_ERROR(biosSettings, COMGETTER(IOAPICEnabled)(&fIoApic));
2384 if (!fIoApic)
2385 {
2386 RTStrmPrintf(g_pStdErr, "*** I/O APIC must be enabled for ICH9, enabling. ***\n");
2387 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(TRUE));
2388 }
2389 }
2390 else
2391 {
2392 errorArgument("Invalid --chipset argument '%s' (valid: piix3,ich9)", ValueUnion.psz);
2393 rc = E_FAIL;
2394 }
2395 break;
2396 }
2397 case MODIFYVM_AUTOSTART_ENABLED:
2398 {
2399 CHECK_ERROR(machine, COMSETTER(AutostartEnabled)(ValueUnion.f));
2400 break;
2401 }
2402
2403 case MODIFYVM_AUTOSTART_DELAY:
2404 {
2405 CHECK_ERROR(machine, COMSETTER(AutostartDelay)(ValueUnion.u32));
2406 break;
2407 }
2408
2409 case MODIFYVM_AUTOSTOP_TYPE:
2410 {
2411 AutostopType_T enmAutostopType = AutostopType_Disabled;
2412
2413 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2414 enmAutostopType = AutostopType_Disabled;
2415 else if (!RTStrICmp(ValueUnion.psz, "savestate"))
2416 enmAutostopType = AutostopType_SaveState;
2417 else if (!RTStrICmp(ValueUnion.psz, "poweroff"))
2418 enmAutostopType = AutostopType_PowerOff;
2419 else if (!RTStrICmp(ValueUnion.psz, "acpishutdown"))
2420 enmAutostopType = AutostopType_AcpiShutdown;
2421 else
2422 {
2423 errorArgument("Invalid --autostop-type argument '%s' (valid: disabled, savestate, poweroff, acpishutdown)", ValueUnion.psz);
2424 rc = E_FAIL;
2425 }
2426
2427 if (SUCCEEDED(rc))
2428 CHECK_ERROR(machine, COMSETTER(AutostopType)(enmAutostopType));
2429 break;
2430 }
2431#ifdef VBOX_WITH_PCI_PASSTHROUGH
2432 case MODIFYVM_ATTACH_PCI:
2433 {
2434 const char* pAt = strchr(ValueUnion.psz, '@');
2435 int32_t iHostAddr, iGuestAddr;
2436
2437 iHostAddr = parsePci(ValueUnion.psz);
2438 iGuestAddr = pAt != NULL ? parsePci(pAt + 1) : iHostAddr;
2439
2440 if (iHostAddr == -1 || iGuestAddr == -1)
2441 {
2442 errorArgument("Invalid --pciattach argument '%s' (valid: 'HB:HD.HF@GB:GD.GF' or just 'HB:HD.HF')", ValueUnion.psz);
2443 rc = E_FAIL;
2444 }
2445 else
2446 {
2447 CHECK_ERROR(machine, AttachHostPCIDevice(iHostAddr, iGuestAddr, TRUE));
2448 }
2449
2450 break;
2451 }
2452 case MODIFYVM_DETACH_PCI:
2453 {
2454 int32_t iHostAddr;
2455
2456 iHostAddr = parsePci(ValueUnion.psz);
2457 if (iHostAddr == -1)
2458 {
2459 errorArgument("Invalid --pcidetach argument '%s' (valid: 'HB:HD.HF')", ValueUnion.psz);
2460 rc = E_FAIL;
2461 }
2462 else
2463 {
2464 CHECK_ERROR(machine, DetachHostPCIDevice(iHostAddr));
2465 }
2466
2467 break;
2468 }
2469#endif
2470#ifdef VBOX_WITH_USB_CARDREADER
2471 case MODIFYVM_USBCARDREADER:
2472 {
2473 CHECK_ERROR(machine, COMSETTER(EmulatedUSBCardReaderEnabled)(ValueUnion.f));
2474 break;
2475 }
2476#endif /* VBOX_WITH_USB_CARDREADER */
2477
2478 default:
2479 {
2480 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
2481 rc = E_FAIL;
2482 break;
2483 }
2484 }
2485 }
2486
2487 /* commit changes */
2488 if (SUCCEEDED(rc))
2489 CHECK_ERROR(machine, SaveSettings());
2490
2491 /* it's important to always close sessions */
2492 a->session->UnlockMachine();
2493
2494 return SUCCEEDED(rc) ? 0 : 1;
2495}
2496
2497#endif /* !VBOX_ONLY_DOCS */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette