VirtualBox

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

Last change on this file since 73536 was 72919, checked in by vboxsync, 7 years ago

Main/*: From now on any valid UTF8 string is considered a valid guest OS type. Of course not all of them are known, so the API clients must be prepared to deal with not having a matching IGuestOSType object.
Frontends/VBoxManage+VBoxShell: adjust to deal with the change

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette