VirtualBox

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

Last change on this file since 59642 was 58437, checked in by vboxsync, 9 years ago

Main: Added paravirtdebug options.

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