VirtualBox

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

Last change on this file since 44028 was 44028, checked in by vboxsync, 12 years ago

Frontends/VBoxManage: improve snapshot information, unify wrappers for opening a medium object, cleanup

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