VirtualBox

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

Last change on this file since 56937 was 56843, checked in by vboxsync, 9 years ago

Frontends/VBoxManage: Add a modifyvm option to rename USB controllers, use "xHCI" as the default xHCI controller name, and remove USB controllers by type, not by hardcoded name.
Frontends/VirtualBox: Use "xHCI" as the default xHCI controller name, and remove USB controllers by type, not by hardcoded name.

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