VirtualBox

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

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

Main+Frontends/VBoxManage: implement saving the settings, and add the matching VBoxManage support

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