VirtualBox

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

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

Main/SystemProperties+Machine: new config setting for default VM frontend.
Frontend/VirtualBox+VBoxManage: changes to use the default VM frontend when starting a VM, other minor cleanups
Main/xml/*.xsd: attempt to bring the XML schema close to reality
doc/manual: document the new possibilities, and fix a few long standing inaccuracies

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