VirtualBox

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

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

Main/Machine+Console+Display+VRDEServer,VBoxManage: allow VMs without graphics controller, eliminate annoying spurious error messages about Console not yet powered up when taking screenshots, getting/setting guest properties and updating metrics, make as many parameters to modifyvm as possible case insensitive

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