VirtualBox

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

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

VBoxManage: adapted the video capture options in 'controlvm' to 'modifyvm'

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