VirtualBox

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

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

IMachine: Added CPUProfile attribute (read/write string). Added a modifyvm option for setting it. Show non-default values in showvminfo, but always show it starting with 6.0.

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