VirtualBox

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

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

*: scm cleanup run.

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