VirtualBox

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

Last change on this file since 80074 was 80074, checked in by vboxsync, 5 years ago

VMM,Main,++: Retired the unfinished FTM component.

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