VirtualBox

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

Last change on this file since 56160 was 56118, checked in by vboxsync, 10 years ago

VBoxManage: A quick command handler return-code cleanup that turned out to be rather tedious.

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

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