VirtualBox

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

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

Main, VMM: Added an API seting to disable VT-x unrestricted execution.

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