VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/ApplianceImpl.cpp@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 73.5 KB
Line 
1/* $Id: ApplianceImpl.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IAppliance and IVirtualSystem COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_MAIN_APPLIANCE
33#include <iprt/path.h>
34#include <iprt/cpp/path.h>
35#include <iprt/cpp/utils.h>
36#include <VBox/com/array.h>
37#include <map>
38
39#include "ApplianceImpl.h"
40#include "VFSExplorerImpl.h"
41#include "VirtualBoxImpl.h"
42#include "GuestOSTypeImpl.h"
43#include "Global.h"
44#include "ProgressImpl.h"
45#include "MachineImpl.h"
46#include "SystemPropertiesImpl.h"
47#include "AutoCaller.h"
48#include "LoggingNew.h"
49#include "CertificateImpl.h"
50
51#include "ApplianceImplPrivate.h"
52
53using namespace std;
54
55
56/*********************************************************************************************************************************
57* Global Variables *
58*********************************************************************************************************************************/
59static const char * const g_pszISOURI = "http://www.ecma-international.org/publications/standards/Ecma-119.htm";
60static const char * const g_pszVMDKStreamURI = "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized";
61static const char * const g_pszVMDKSparseURI = "http://www.vmware.com/specifications/vmdk.html#sparse";
62static const char * const g_pszVMDKCompressedURI = "http://www.vmware.com/specifications/vmdk.html#compressed";
63static const char * const g_pszVMDKCompressedURI2 = "http://www.vmware.com/interfaces/specifications/vmdk.html#compressed";
64static const char * const g_pszrVHDURI = "http://go.microsoft.com/fwlink/?LinkId=137171";
65static char g_szIsoBackend[128];
66static char g_szVmdkBackend[128];
67static char g_szVhdBackend[128];
68/** Set after the g_szXxxxBackend variables has been initialized. */
69static bool volatile g_fInitializedBackendNames = false;
70
71static struct
72{
73 const char *pszUri, *pszBackend;
74} const g_aUriToBackend[] =
75{
76 { g_pszISOURI, g_szIsoBackend },
77 { g_pszVMDKStreamURI, g_szVmdkBackend },
78 { g_pszVMDKSparseURI, g_szVmdkBackend },
79 { g_pszVMDKCompressedURI, g_szVmdkBackend },
80 { g_pszVMDKCompressedURI2, g_szVmdkBackend },
81 { g_pszrVHDURI, g_szVhdBackend },
82};
83
84static std::map<Utf8Str, Utf8Str> supportedStandardsURI;
85
86static struct
87{
88 ovf::CIMOSType_T cim;
89 VBOXOSTYPE osType;
90} const g_aOsTypes[] =
91{
92 { ovf::CIMOSType_CIMOS_Unknown, VBOXOSTYPE_Unknown },
93 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2 },
94 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp3 },
95 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp4 },
96 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp45 },
97 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS21x },
98 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_ECS },
99 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_ArcaOS },
100 { ovf::CIMOSType_CIMOS_MSDOS, VBOXOSTYPE_DOS },
101 { ovf::CIMOSType_CIMOS_WIN3x, VBOXOSTYPE_Win31 },
102 { ovf::CIMOSType_CIMOS_WIN95, VBOXOSTYPE_Win95 },
103 { ovf::CIMOSType_CIMOS_WIN98, VBOXOSTYPE_Win98 },
104 { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT },
105 { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT4 },
106 { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT3x },
107 { ovf::CIMOSType_CIMOS_NetWare, VBOXOSTYPE_Netware },
108 { ovf::CIMOSType_CIMOS_NovellOES, VBOXOSTYPE_Netware },
109 { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_Solaris },
110 { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_Solaris_x64 },
111 { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_Solaris10U8_or_later },
112 { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_Solaris10U8_or_later_x64 },
113 { ovf::CIMOSType_CIMOS_SunOS, VBOXOSTYPE_Solaris },
114 { ovf::CIMOSType_CIMOS_FreeBSD, VBOXOSTYPE_FreeBSD },
115 { ovf::CIMOSType_CIMOS_NetBSD, VBOXOSTYPE_NetBSD },
116 { ovf::CIMOSType_CIMOS_QNX, VBOXOSTYPE_QNX },
117 { ovf::CIMOSType_CIMOS_Windows2000, VBOXOSTYPE_Win2k },
118 { ovf::CIMOSType_CIMOS_WindowsMe, VBOXOSTYPE_WinMe },
119 { ovf::CIMOSType_CIMOS_OpenBSD, VBOXOSTYPE_OpenBSD },
120 { ovf::CIMOSType_CIMOS_WindowsXP, VBOXOSTYPE_WinXP },
121 { ovf::CIMOSType_CIMOS_WindowsXPEmbedded, VBOXOSTYPE_WinXP },
122 { ovf::CIMOSType_CIMOS_WindowsEmbeddedforPointofService, VBOXOSTYPE_WinXP },
123 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2003, VBOXOSTYPE_Win2k3 },
124 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2003_64, VBOXOSTYPE_Win2k3_x64 },
125 { ovf::CIMOSType_CIMOS_WindowsXP_64, VBOXOSTYPE_WinXP_x64 },
126 { ovf::CIMOSType_CIMOS_WindowsVista, VBOXOSTYPE_WinVista },
127 { ovf::CIMOSType_CIMOS_WindowsVista_64, VBOXOSTYPE_WinVista_x64 },
128 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008, VBOXOSTYPE_Win2k8 },
129 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008_64, VBOXOSTYPE_Win2k8_x64 },
130 { ovf::CIMOSType_CIMOS_FreeBSD_64, VBOXOSTYPE_FreeBSD_x64 },
131 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS },
132 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS_x64 }, // there is no CIM 64-bit type for this
133 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106 },
134 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106_x64 },
135 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS107_x64 },
136 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS108_x64 },
137 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS109_x64 },
138 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1010_x64 },
139 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1011_x64 },
140 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1012_x64 },
141 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1013_x64 },
142
143 // Linuxes
144 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat },
145 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat_x64 },
146 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat3 },
147 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat3_x64 },
148 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat4 },
149 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat4_x64 },
150 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat5 },
151 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat5_x64 },
152 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat6 },
153 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat6_x64 },
154 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat7_x64 }, // 64-bit only
155 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat8_x64 }, // 64-bit only
156 { ovf::CIMOSType_CIMOS_SUSE, VBOXOSTYPE_OpenSUSE },
157 { ovf::CIMOSType_CIMOS_SLES, VBOXOSTYPE_SUSE_LE },
158 { ovf::CIMOSType_CIMOS_NovellLinuxDesktop, VBOXOSTYPE_OpenSUSE },
159 { ovf::CIMOSType_CIMOS_SUSE_64, VBOXOSTYPE_OpenSUSE_x64 },
160 { ovf::CIMOSType_CIMOS_SLES_64, VBOXOSTYPE_SUSE_LE_x64 },
161 { ovf::CIMOSType_CIMOS_SUSE_64, VBOXOSTYPE_OpenSUSE_Leap_x64 }, // 64-bit only
162 { ovf::CIMOSType_CIMOS_SUSE, VBOXOSTYPE_OpenSUSE_Tumbleweed },
163 { ovf::CIMOSType_CIMOS_SUSE_64, VBOXOSTYPE_OpenSUSE_Tumbleweed_x64 },
164 { ovf::CIMOSType_CIMOS_LINUX, VBOXOSTYPE_Linux },
165 { ovf::CIMOSType_CIMOS_LINUX, VBOXOSTYPE_Linux22 },
166 { ovf::CIMOSType_CIMOS_SunJavaDesktopSystem, VBOXOSTYPE_Linux },
167 { ovf::CIMOSType_CIMOS_TurboLinux, VBOXOSTYPE_Turbolinux },
168 { ovf::CIMOSType_CIMOS_TurboLinux_64, VBOXOSTYPE_Turbolinux_x64 },
169 { ovf::CIMOSType_CIMOS_Mandriva, VBOXOSTYPE_Mandriva },
170 { ovf::CIMOSType_CIMOS_Mandriva_64, VBOXOSTYPE_Mandriva_x64 },
171 { ovf::CIMOSType_CIMOS_Mandriva, VBOXOSTYPE_OpenMandriva_Lx },
172 { ovf::CIMOSType_CIMOS_Mandriva_64, VBOXOSTYPE_OpenMandriva_Lx_x64 },
173 { ovf::CIMOSType_CIMOS_Mandriva, VBOXOSTYPE_PCLinuxOS },
174 { ovf::CIMOSType_CIMOS_Mandriva_64, VBOXOSTYPE_PCLinuxOS_x64 },
175 { ovf::CIMOSType_CIMOS_Mandriva, VBOXOSTYPE_Mageia },
176 { ovf::CIMOSType_CIMOS_Mandriva_64, VBOXOSTYPE_Mageia_x64 },
177 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu },
178 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu_x64 },
179 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu10_LTS },
180 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu10_LTS_x64 },
181 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu10 },
182 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu10_x64 },
183 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu11 },
184 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu11_x64 },
185 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu12_LTS },
186 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu12_LTS_x64 },
187 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu12 },
188 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu12_x64 },
189 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu13 },
190 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu13_x64 },
191 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu14_LTS },
192 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu14_LTS_x64 },
193 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu14 },
194 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu14_x64 },
195 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu15 },
196 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu15_x64 },
197 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu16_LTS },
198 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu16_LTS_x64 },
199 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu16 },
200 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu16_x64 },
201 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu17 },
202 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu17_x64 },
203 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu18_LTS },
204 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu18_LTS_x64 },
205 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu18 },
206 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu18_x64 },
207 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu19 },
208 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu19_x64 },
209 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu20_LTS_x64 },
210 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu20_x64 },
211 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu21_x64 },
212 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu22_LTS_x64 },
213 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu22_x64 },
214 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Lubuntu },
215 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Lubuntu_x64 },
216 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Xubuntu },
217 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Xubuntu_x64 },
218 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian },
219 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian_x64 },
220 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian31 },
221 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian4 },
222 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian4_x64 },
223 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian5 },
224 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian5_x64 },
225 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian6 },
226 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian6_x64 },
227 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian7 },
228 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian7_x64 },
229 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian8 },
230 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian8_x64 },
231 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian9 },
232 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian9_x64 },
233 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian10 },
234 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian10_x64 },
235 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian11 },
236 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian11_x64 },
237 { ovf::CIMOSType_CIMOS_Linux_2_4_x, VBOXOSTYPE_Linux24 },
238 { ovf::CIMOSType_CIMOS_Linux_2_4_x_64, VBOXOSTYPE_Linux24_x64 },
239 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Linux26 },
240 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Linux26_x64 },
241 { ovf::CIMOSType_CIMOS_Linux_64, VBOXOSTYPE_Linux26_x64 },
242
243 // types that we have support for but CIM doesn't
244 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_ArchLinux },
245 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_ArchLinux_x64 },
246 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_FedoraCore },
247 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_FedoraCore_x64 },
248 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Gentoo },
249 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Gentoo_x64 },
250 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Xandros },
251 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Xandros_x64 },
252 { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_OpenSolaris },
253 { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_OpenSolaris_x64 },
254
255 // types added with CIM 2.25.0 follow:
256 { ovf::CIMOSType_CIMOS_WindowsServer2008R2, VBOXOSTYPE_Win2k8 }, // duplicate, see above
257// { ovf::CIMOSType_CIMOS_VMwareESXi = 104, // we can't run ESX in a VM
258 { ovf::CIMOSType_CIMOS_Windows7, VBOXOSTYPE_Win7 },
259 { ovf::CIMOSType_CIMOS_Windows7, VBOXOSTYPE_Win7_x64 }, // there is no
260 // CIM 64-bit type for this
261 { ovf::CIMOSType_CIMOS_CentOS, VBOXOSTYPE_RedHat },
262 { ovf::CIMOSType_CIMOS_CentOS_64, VBOXOSTYPE_RedHat_x64 },
263 { ovf::CIMOSType_CIMOS_OracleLinux, VBOXOSTYPE_Oracle },
264 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle_x64 },
265 { ovf::CIMOSType_CIMOS_OracleLinux, VBOXOSTYPE_Oracle4 },
266 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle4_x64 },
267 { ovf::CIMOSType_CIMOS_OracleLinux, VBOXOSTYPE_Oracle5 },
268 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle5_x64 },
269 { ovf::CIMOSType_CIMOS_OracleLinux, VBOXOSTYPE_Oracle6 },
270 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle6_x64 },
271 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle7_x64 }, // 64-bit only
272 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle8_x64 }, // 64-bit only
273 { ovf::CIMOSType_CIMOS_eComStation, VBOXOSTYPE_ECS },
274
275 { ovf::CIMOSType_CIMOS_WindowsServer2011, VBOXOSTYPE_Win2k8_x64 }, // no 1:1 match on the VBox side
276 { ovf::CIMOSType_CIMOS_WindowsServer2012, VBOXOSTYPE_Win2k12_x64 },
277 { ovf::CIMOSType_CIMOS_Windows8, VBOXOSTYPE_Win8 },
278 { ovf::CIMOSType_CIMOS_Windows8_64, VBOXOSTYPE_Win8_x64 },
279 { ovf::CIMOSType_CIMOS_WindowsServer2012R2, VBOXOSTYPE_Win2k12_x64 },
280 { ovf::CIMOSType_CIMOS_Windows8_1, VBOXOSTYPE_Win81 },
281 { ovf::CIMOSType_CIMOS_Windows8_1_64, VBOXOSTYPE_Win81_x64 },
282 { ovf::CIMOSType_CIMOS_WindowsServer2016, VBOXOSTYPE_Win2k16_x64 },
283 { ovf::CIMOSType_CIMOS_Windows10, VBOXOSTYPE_Win10 },
284 { ovf::CIMOSType_CIMOS_Windows10_64, VBOXOSTYPE_Win10_x64 },
285 { ovf::CIMOSType_CIMOS_Windows10_64, VBOXOSTYPE_Win10_x64 },
286 { ovf::CIMOSType_CIMOS_WindowsServer2016, VBOXOSTYPE_Win2k19_x64 }, // no CIM type for this yet
287
288 // there are no CIM types for these, so these turn to "other" on export:
289 // VBOXOSTYPE_OpenBSD
290 // VBOXOSTYPE_OpenBSD_x64
291 // VBOXOSTYPE_NetBSD
292 // VBOXOSTYPE_NetBSD_x64
293
294};
295
296/* Pattern structure for matching the OS type description field */
297struct osTypePattern
298{
299 const char *pcszPattern;
300 VBOXOSTYPE osType;
301};
302
303/* These are the 32-Bit ones. They are sorted by priority. */
304static const osTypePattern g_aOsTypesPattern[] =
305{
306 {"Windows NT", VBOXOSTYPE_WinNT4},
307 {"Windows XP", VBOXOSTYPE_WinXP},
308 {"Windows 2000", VBOXOSTYPE_Win2k},
309 {"Windows 2003", VBOXOSTYPE_Win2k3},
310 {"Windows Vista", VBOXOSTYPE_WinVista},
311 {"Windows 2008", VBOXOSTYPE_Win2k8},
312 {"Windows 7", VBOXOSTYPE_Win7},
313 {"Windows 8.1", VBOXOSTYPE_Win81},
314 {"Windows 8", VBOXOSTYPE_Win8},
315 {"Windows 10", VBOXOSTYPE_Win10},
316 {"SUSE", VBOXOSTYPE_OpenSUSE},
317 {"Novell", VBOXOSTYPE_OpenSUSE},
318 {"Red Hat", VBOXOSTYPE_RedHat},
319 {"Mandriva", VBOXOSTYPE_Mandriva},
320 {"Ubuntu", VBOXOSTYPE_Ubuntu},
321 {"Debian", VBOXOSTYPE_Debian},
322 {"QNX", VBOXOSTYPE_QNX},
323 {"Linux 2.4", VBOXOSTYPE_Linux24},
324 {"Linux 2.6", VBOXOSTYPE_Linux26},
325 {"Linux", VBOXOSTYPE_Linux},
326 {"OpenSolaris", VBOXOSTYPE_OpenSolaris},
327 {"Solaris", VBOXOSTYPE_OpenSolaris},
328 {"FreeBSD", VBOXOSTYPE_FreeBSD},
329 {"NetBSD", VBOXOSTYPE_NetBSD},
330 {"Windows 95", VBOXOSTYPE_Win95},
331 {"Windows 98", VBOXOSTYPE_Win98},
332 {"Windows Me", VBOXOSTYPE_WinMe},
333 {"Windows 3.", VBOXOSTYPE_Win31},
334 {"DOS", VBOXOSTYPE_DOS},
335 {"OS2", VBOXOSTYPE_OS2}
336};
337
338/* These are the 64-Bit ones. They are sorted by priority. */
339static const osTypePattern g_aOsTypesPattern64[] =
340{
341 {"Windows XP", VBOXOSTYPE_WinXP_x64},
342 {"Windows 2003", VBOXOSTYPE_Win2k3_x64},
343 {"Windows Vista", VBOXOSTYPE_WinVista_x64},
344 {"Windows 2008", VBOXOSTYPE_Win2k8_x64},
345 {"Windows 7", VBOXOSTYPE_Win7_x64},
346 {"Windows 8.1", VBOXOSTYPE_Win81_x64},
347 {"Windows 8", VBOXOSTYPE_Win8_x64},
348 {"Windows 2012", VBOXOSTYPE_Win2k12_x64},
349 {"Windows 10", VBOXOSTYPE_Win10_x64},
350 {"Windows 2016", VBOXOSTYPE_Win2k16_x64},
351 {"Windows 2019", VBOXOSTYPE_Win2k19_x64},
352 {"SUSE", VBOXOSTYPE_OpenSUSE_x64},
353 {"Novell", VBOXOSTYPE_OpenSUSE_x64},
354 {"Red Hat", VBOXOSTYPE_RedHat_x64},
355 {"Mandriva", VBOXOSTYPE_Mandriva_x64},
356 {"Ubuntu", VBOXOSTYPE_Ubuntu_x64},
357 {"Debian", VBOXOSTYPE_Debian_x64},
358 {"Linux 2.4", VBOXOSTYPE_Linux24_x64},
359 {"Linux 2.6", VBOXOSTYPE_Linux26_x64},
360 {"Linux", VBOXOSTYPE_Linux26_x64},
361 {"OpenSolaris", VBOXOSTYPE_OpenSolaris_x64},
362 {"Solaris", VBOXOSTYPE_OpenSolaris_x64},
363 {"FreeBSD", VBOXOSTYPE_FreeBSD_x64},
364};
365
366/**
367 * Private helper func that suggests a VirtualBox guest OS type
368 * for the given OVF operating system type.
369 */
370void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr)
371{
372 /* First check if the type is other/other_64 */
373 if (c == ovf::CIMOSType_CIMOS_Other)
374 {
375 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypesPattern); ++i)
376 if (cStr.contains(g_aOsTypesPattern[i].pcszPattern, Utf8Str::CaseInsensitive))
377 {
378 strType = Global::OSTypeId(g_aOsTypesPattern[i].osType);
379 return;
380 }
381 }
382 else if (c == ovf::CIMOSType_CIMOS_Other_64)
383 {
384 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypesPattern64); ++i)
385 if (cStr.contains(g_aOsTypesPattern64[i].pcszPattern, Utf8Str::CaseInsensitive))
386 {
387 strType = Global::OSTypeId(g_aOsTypesPattern64[i].osType);
388 return;
389 }
390 }
391
392 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypes); ++i)
393 {
394 if (c == g_aOsTypes[i].cim)
395 {
396 strType = Global::OSTypeId(g_aOsTypes[i].osType);
397 return;
398 }
399 }
400
401 if (c == ovf::CIMOSType_CIMOS_Other_64)
402 strType = Global::OSTypeId(VBOXOSTYPE_Unknown_x64);
403 else
404 strType = Global::OSTypeId(VBOXOSTYPE_Unknown);
405}
406
407/**
408 * Private helper func that suggests a VirtualBox guest OS type
409 * for the given OVF operating system type.
410 * @returns CIM OS type.
411 * @param pcszVBox Our guest OS type identifier string.
412 * @param fLongMode Whether long mode is enabled and a 64-bit CIM type is
413 * preferred even if the VBox guest type isn't 64-bit.
414 */
415ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode)
416{
417 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypes); ++i)
418 {
419 if (!RTStrICmp(pcszVBox, Global::OSTypeId(g_aOsTypes[i].osType)))
420 {
421 if (fLongMode && !(g_aOsTypes[i].osType & VBOXOSTYPE_x64))
422 {
423 VBOXOSTYPE enmDesiredOsType = (VBOXOSTYPE)((int)g_aOsTypes[i].osType | (int)VBOXOSTYPE_x64);
424 for (size_t j = i+1; j < RT_ELEMENTS(g_aOsTypes); j++)
425 if (g_aOsTypes[j].osType == enmDesiredOsType)
426 return g_aOsTypes[j].cim;
427 if (i > 0)
428 {
429 for (size_t j = i-1; j > 0; j++)
430 if (g_aOsTypes[j].osType == enmDesiredOsType)
431 return g_aOsTypes[j].cim;
432 }
433 /* Not all OSes have 64-bit versions, so just return the 32-bit variant. */
434 }
435 return g_aOsTypes[i].cim;
436 }
437 }
438
439 return fLongMode ? ovf::CIMOSType_CIMOS_Other_64 : ovf::CIMOSType_CIMOS_Other;
440}
441
442Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type)
443{
444 Utf8Str strType;
445 switch (type)
446 {
447 case NetworkAttachmentType_NAT: strType = "NAT"; break;
448 case NetworkAttachmentType_Bridged: strType = "Bridged"; break;
449 case NetworkAttachmentType_Internal: strType = "Internal"; break;
450 case NetworkAttachmentType_HostOnly: strType = "HostOnly"; break;
451 case NetworkAttachmentType_HostOnlyNetwork: strType = "HostOnlyNetwork"; break;
452 case NetworkAttachmentType_Generic: strType = "Generic"; break;
453 case NetworkAttachmentType_NATNetwork: strType = "NATNetwork"; break;
454 case NetworkAttachmentType_Null: strType = "Null"; break;
455 case NetworkAttachmentType_Cloud: strType = "Cloud"; break;
456#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
457 case NetworkAttachmentType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
458#endif
459 }
460 return strType;
461}
462
463
464////////////////////////////////////////////////////////////////////////////////
465//
466// Appliance constructor / destructor
467//
468// ////////////////////////////////////////////////////////////////////////////////
469
470DEFINE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
471
472HRESULT VirtualSystemDescription::FinalConstruct()
473{
474 return BaseFinalConstruct();
475}
476
477void VirtualSystemDescription::FinalRelease()
478{
479 uninit();
480
481 BaseFinalRelease();
482}
483
484Appliance::Appliance()
485 : mVirtualBox(NULL)
486{
487}
488
489Appliance::~Appliance()
490{
491}
492
493
494HRESULT Appliance::FinalConstruct()
495{
496 return BaseFinalConstruct();
497}
498
499void Appliance::FinalRelease()
500{
501 uninit();
502
503 BaseFinalRelease();
504}
505
506
507////////////////////////////////////////////////////////////////////////////////
508//
509// Internal helpers
510//
511////////////////////////////////////////////////////////////////////////////////
512
513
514////////////////////////////////////////////////////////////////////////////////
515//
516// IVirtualBox public methods
517//
518////////////////////////////////////////////////////////////////////////////////
519
520// This code is here so we won't have to include the appliance headers in the
521// IVirtualBox implementation.
522
523/**
524 * Implementation for IVirtualBox::createAppliance.
525 *
526 * @param aAppliance IAppliance object created if S_OK is returned.
527 * @return S_OK or error.
528 */
529HRESULT VirtualBox::createAppliance(ComPtr<IAppliance> &aAppliance)
530{
531 ComObjPtr<Appliance> appliance;
532 HRESULT hrc = appliance.createObject();
533 if (SUCCEEDED(hrc))
534 {
535 hrc = appliance->init(this);
536 if (SUCCEEDED(hrc))
537 hrc = appliance.queryInterfaceTo(aAppliance.asOutParam());
538 }
539 return hrc;
540}
541
542/**
543 * Appliance COM initializer.
544 * @param aVirtualBox The VirtualBox object.
545 */
546HRESULT Appliance::init(VirtualBox *aVirtualBox)
547{
548 HRESULT rc = S_OK;
549 /* Enclose the state transition NotReady->InInit->Ready */
550 AutoInitSpan autoInitSpan(this);
551 AssertReturn(autoInitSpan.isOk(), E_FAIL);
552
553 /* Weak reference to a VirtualBox object */
554 unconst(mVirtualBox) = aVirtualBox;
555
556 // initialize data
557 m = new Data;
558 m->m_pSecretKeyStore = new SecretKeyStore(false /* fRequireNonPageable*/);
559 AssertReturn(m->m_pSecretKeyStore, E_FAIL);
560
561 rc = i_initBackendNames();
562
563 /* Confirm a successful initialization */
564 autoInitSpan.setSucceeded();
565
566 return rc;
567}
568
569/**
570 * Appliance COM uninitializer.
571 */
572void Appliance::uninit()
573{
574 /* Enclose the state transition Ready->InUninit->NotReady */
575 AutoUninitSpan autoUninitSpan(this);
576 if (autoUninitSpan.uninitDone())
577 return;
578
579 if (m->m_pSecretKeyStore)
580 delete m->m_pSecretKeyStore;
581
582 delete m;
583 m = NULL;
584}
585
586////////////////////////////////////////////////////////////////////////////////
587//
588// IAppliance public methods
589//
590////////////////////////////////////////////////////////////////////////////////
591
592/**
593 * Public method implementation.
594 */
595HRESULT Appliance::getPath(com::Utf8Str &aPath)
596{
597 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
598
599 aPath = m->locInfo.strPath;
600
601 return S_OK;
602}
603
604/**
605 * Public method implementation.
606 */
607HRESULT Appliance::getDisks(std::vector<com::Utf8Str> &aDisks)
608{
609 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
610
611 aDisks.resize(0);
612
613 if (m->pReader) // OVFReader instantiated?
614 {
615 aDisks.resize(m->pReader->m_mapDisks.size());
616
617 ovf::DiskImagesMap::const_iterator it;
618 size_t i = 0;
619 for (it = m->pReader->m_mapDisks.begin();
620 it != m->pReader->m_mapDisks.end();
621 ++it, ++i)
622 {
623 // create a string representing this disk
624 const ovf::DiskImage &d = it->second;
625 char *psz = NULL;
626 RTStrAPrintf(&psz,
627 "%s\t"
628 "%RI64\t"
629 "%RI64\t"
630 "%s\t"
631 "%s\t"
632 "%RI64\t"
633 "%RI64\t"
634 "%s",
635 d.strDiskId.c_str(),
636 d.iCapacity,
637 d.iPopulatedSize,
638 d.strFormat.c_str(),
639 d.strHref.c_str(),
640 d.iSize,
641 d.iChunkSize,
642 d.strCompression.c_str());
643 Utf8Str utf(psz);
644 aDisks[i] = utf;
645 RTStrFree(psz);
646 }
647 }
648
649 return S_OK;
650}
651
652/**
653 * Public method implementation.
654 */
655HRESULT Appliance::getCertificate(ComPtr<ICertificate> &aCertificateInfo)
656{
657 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
658
659 /* Can be NULL at this point, queryInterfaceto handles that. */
660 m->ptrCertificateInfo.queryInterfaceTo(aCertificateInfo.asOutParam());
661 return S_OK;
662}
663
664/**
665 * Public method implementation.
666 */
667HRESULT Appliance::getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions)
668{
669 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
670
671 aVirtualSystemDescriptions.resize(m->virtualSystemDescriptions.size());
672 std::list< ComObjPtr<VirtualSystemDescription> > vsds(m->virtualSystemDescriptions);
673 size_t i = 0;
674 for (std::list< ComObjPtr<VirtualSystemDescription> >::iterator it = vsds.begin(); it != vsds.end(); ++it, ++i)
675 {
676 (*it).queryInterfaceTo(aVirtualSystemDescriptions[i].asOutParam());
677 }
678 return S_OK;
679}
680
681/**
682 * Public method implementation.
683 */
684HRESULT Appliance::getMachines(std::vector<com::Utf8Str> &aMachines)
685{
686 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
687
688 aMachines.resize(m->llGuidsMachinesCreated.size());
689 size_t i = 0;
690 for (std::list<Guid>::const_iterator it = m->llGuidsMachinesCreated.begin();
691 it != m->llGuidsMachinesCreated.end();
692 ++it, ++i)
693 {
694 const Guid &uuid = *it;
695 aMachines[i] = uuid.toUtf16();
696 }
697 return S_OK;
698}
699
700HRESULT Appliance::createVFSExplorer(const com::Utf8Str &aURI, ComPtr<IVFSExplorer> &aExplorer)
701{
702 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
703
704 ComObjPtr<VFSExplorer> explorer;
705 HRESULT rc = S_OK;
706 try
707 {
708 Utf8Str uri(aURI);
709 /* Check which kind of export the user has requested */
710 LocationInfo li;
711 i_parseURI(aURI, li);
712 /* Create the explorer object */
713 explorer.createObject();
714 rc = explorer->init(li.storageType, li.strPath, li.strHostname, li.strUsername, li.strPassword, mVirtualBox);
715 }
716 catch (HRESULT aRC)
717 {
718 rc = aRC;
719 }
720
721 if (SUCCEEDED(rc))
722 /* Return explorer to the caller */
723 explorer.queryInterfaceTo(aExplorer.asOutParam());
724
725 return rc;
726}
727
728
729/**
730 * Public method implementation.
731 * Add the "aRequested" numbers of new empty objects of VSD into the list
732 * "virtualSystemDescriptions".
733 * The parameter "aCreated" keeps the actual number of the added objects.
734 * In case of exception all added objects are removed from the list.
735 */
736HRESULT Appliance::createVirtualSystemDescriptions(ULONG aRequested, ULONG *aCreated)
737{
738 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
739
740 HRESULT rc = S_OK;
741 uint32_t lQuantity = aRequested;
742 uint32_t i=0;
743
744 if (lQuantity < 1)
745 return setError(E_FAIL, tr("The number of VirtualSystemDescription objects must be at least 1 or more."));
746 try
747 {
748 for (; i<lQuantity; ++i)
749 {
750 ComObjPtr<VirtualSystemDescription> opVSD;
751 rc = opVSD.createObject();
752 if (SUCCEEDED(rc))
753 {
754 rc = opVSD->init();
755 if (SUCCEEDED(rc))
756 m->virtualSystemDescriptions.push_back(opVSD);
757 else
758 break;
759 }
760 else
761 break;
762 }
763
764 if (i<lQuantity)
765 LogRel(("Number of created VirtualSystemDescription objects is less than requested"
766 "(Requested %d, Created %d)",lQuantity, i));
767
768 *aCreated = i;
769 }
770 catch (HRESULT aRC)
771 {
772 for (; i>0; --i)
773 {
774 if (!m->virtualSystemDescriptions.empty())
775 m->virtualSystemDescriptions.pop_back();
776 else
777 break;
778 }
779 rc = aRC;
780 }
781
782 return rc;
783}
784
785/**
786 * Public method implementation.
787 */
788HRESULT Appliance::getWarnings(std::vector<com::Utf8Str> &aWarnings)
789{
790 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
791
792 aWarnings.resize(m->llWarnings.size());
793
794 list<Utf8Str>::const_iterator it;
795 size_t i = 0;
796 for (it = m->llWarnings.begin();
797 it != m->llWarnings.end();
798 ++it, ++i)
799 {
800 aWarnings[i] = *it;
801 }
802
803 return S_OK;
804}
805
806HRESULT Appliance::getPasswordIds(std::vector<com::Utf8Str> &aIdentifiers)
807{
808 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
809
810 aIdentifiers = m->m_vecPasswordIdentifiers;
811 return S_OK;
812}
813
814HRESULT Appliance::getMediumIdsForPasswordId(const com::Utf8Str &aPasswordId, std::vector<com::Guid> &aIdentifiers)
815{
816 HRESULT hrc = S_OK;
817 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
818
819 std::map<com::Utf8Str, GUIDVEC>::const_iterator it = m->m_mapPwIdToMediumIds.find(aPasswordId);
820 if (it != m->m_mapPwIdToMediumIds.end())
821 aIdentifiers = it->second;
822 else
823 hrc = setError(E_FAIL, tr("The given password identifier is not associated with any medium"));
824
825 return hrc;
826}
827
828HRESULT Appliance::addPasswords(const std::vector<com::Utf8Str> &aIdentifiers,
829 const std::vector<com::Utf8Str> &aPasswords)
830{
831 HRESULT hrc = S_OK;
832
833 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
834
835 /* Check that the IDs do not exist already before changing anything. */
836 for (unsigned i = 0; i < aIdentifiers.size(); i++)
837 {
838 SecretKey *pKey = NULL;
839 int rc = m->m_pSecretKeyStore->retainSecretKey(aIdentifiers[i], &pKey);
840 if (rc != VERR_NOT_FOUND)
841 {
842 AssertPtr(pKey);
843 if (pKey)
844 pKey->release();
845 return setError(VBOX_E_OBJECT_IN_USE, tr("A password with the given ID already exists"));
846 }
847 }
848
849 for (unsigned i = 0; i < aIdentifiers.size() && SUCCEEDED(hrc); i++)
850 {
851 size_t cbKey = aPasswords[i].length() + 1; /* Include terminator */
852 const uint8_t *pbKey = (const uint8_t *)aPasswords[i].c_str();
853
854 int rc = m->m_pSecretKeyStore->addSecretKey(aIdentifiers[i], pbKey, cbKey);
855 if (RT_SUCCESS(rc))
856 m->m_cPwProvided++;
857 else if (rc == VERR_NO_MEMORY)
858 hrc = setError(E_OUTOFMEMORY, tr("Failed to allocate enough secure memory for the key"));
859 else
860 hrc = setError(E_FAIL, tr("Unknown error happened while adding a password (%Rrc)"), rc);
861 }
862
863 return hrc;
864}
865
866////////////////////////////////////////////////////////////////////////////////
867//
868// Appliance private methods
869//
870////////////////////////////////////////////////////////////////////////////////
871
872HRESULT Appliance::i_initBackendNames()
873{
874 HRESULT hrc = S_OK;
875 if (!g_fInitializedBackendNames)
876 {
877 /*
878 * Use the system properties to translate file extensions into
879 * storage backend names.
880 */
881 static struct
882 {
883 const char *pszExt; /**< extension */
884 char *pszBackendName;
885 size_t cbBackendName;
886 } const s_aFormats[] =
887 {
888 { "iso", g_szIsoBackend, sizeof(g_szIsoBackend) },
889 { "vmdk", g_szVmdkBackend, sizeof(g_szVmdkBackend) },
890 { "vhd", g_szVhdBackend, sizeof(g_szVhdBackend) },
891 };
892 SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
893 for (unsigned i = 0; i < RT_ELEMENTS(s_aFormats); i++)
894 {
895 ComObjPtr<MediumFormat> trgFormat = pSysProps->i_mediumFormatFromExtension(s_aFormats[i].pszExt);
896 if (trgFormat.isNotNull())
897 {
898 const char *pszName = trgFormat->i_getName().c_str();
899 int vrc = RTStrCopy(s_aFormats[i].pszBackendName, s_aFormats[i].cbBackendName, pszName);
900 AssertRCStmt(vrc, hrc = setError(E_FAIL, "Unexpected storage backend name copy error %Rrc for %s.", vrc, pszName));
901 }
902 else
903 hrc = setError(E_FAIL, tr("Can't find appropriate medium format for ISO type of a virtual disk."));
904 }
905
906 if (SUCCEEDED(hrc))
907 g_fInitializedBackendNames = true;
908 }
909
910 return hrc;
911}
912
913Utf8Str Appliance::i_typeOfVirtualDiskFormatFromURI(Utf8Str uri) const
914{
915 Assert(g_fInitializedBackendNames);
916
917 unsigned i = RT_ELEMENTS(g_aUriToBackend);
918 while (i-- > 0)
919 if (RTStrICmp(g_aUriToBackend[i].pszUri, uri.c_str()) == 0)
920 return Utf8Str(g_aUriToBackend[i].pszBackend);
921 return Utf8Str();
922}
923
924#if 0 /* unused */
925std::set<Utf8Str> Appliance::i_URIFromTypeOfVirtualDiskFormat(Utf8Str type)
926{
927 Assert(g_fInitializedBackendNames);
928
929 std::set<Utf8Str> UriSet;
930 unsigned i = RT_ELEMENTS(g_aUriToBackend);
931 while (i-- > 0)
932 if (RTStrICmp(g_aUriToBackend[i].pszBackend, type.c_str()) == 0)
933 UriSet.insert(g_aUriToBackend[i].pszUri);
934 return UriSet;
935}
936#endif
937
938/**
939 * Returns a medium format object corresponding to the given
940 * disk image or null if no such format.
941 *
942 * @param di Disk Image
943 * @param mf Medium Format
944 *
945 * @return ComObjPtr<MediumFormat>
946 */
947HRESULT Appliance::i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf)
948{
949 HRESULT rc = S_OK;
950
951 /* Get the system properties. */
952 SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
953
954 /* We need a proper source format description */
955 /* Which format to use? */
956 Utf8Str strSrcFormat = i_typeOfVirtualDiskFormatFromURI(di.strFormat);
957
958 /*
959 * fallback, if we can't determine virtual disk format using URI from the attribute ovf:format
960 * in the corresponding section <Disk> in the OVF file.
961 */
962 if (strSrcFormat.isEmpty())
963 {
964 strSrcFormat = di.strHref;
965
966 /* check either file gzipped or not
967 * if "yes" then remove last extension,
968 * i.e. "image.vmdk.gz"->"image.vmdk"
969 */
970 if (di.strCompression == "gzip")
971 {
972 if (RTPathHasSuffix(strSrcFormat.c_str()))
973 {
974 strSrcFormat.stripSuffix();
975 }
976 else
977 {
978 mf.setNull();
979 rc = setError(E_FAIL,
980 tr("Internal inconsistency looking up medium format for the disk image '%s'"),
981 di.strHref.c_str());
982 return rc;
983 }
984 }
985 /* Figure out from extension which format the image of disk has. */
986 if (RTPathHasSuffix(strSrcFormat.c_str()))
987 {
988 const char *pszExt = RTPathSuffix(strSrcFormat.c_str());
989 if (pszExt)
990 pszExt++;
991 mf = pSysProps->i_mediumFormatFromExtension(pszExt);
992 }
993 else
994 mf.setNull();
995 }
996 else
997 mf = pSysProps->i_mediumFormat(strSrcFormat);
998
999 if (mf.isNull())
1000 rc = setError(E_FAIL, tr("Internal inconsistency looking up medium format for the disk image '%s'"),
1001 di.strHref.c_str());
1002
1003 return rc;
1004}
1005
1006/**
1007 * Setup automatic I/O stream digest calculation, adding it to hOurManifest.
1008 *
1009 * @returns Passthru I/O stream, of @a hVfsIos if no digest calc needed.
1010 * @param hVfsIos The stream to wrap. Always consumed.
1011 * @param pszManifestEntry The manifest entry.
1012 * @param fRead Set if read stream, clear if write.
1013 * @throws Nothing.
1014 */
1015RTVFSIOSTREAM Appliance::i_manifestSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry,
1016 bool fRead /*= true */)
1017{
1018 int vrc;
1019 Assert(!RTManifestPtIosIsInstanceOf(hVfsIos));
1020
1021 if (m->fDigestTypes == 0)
1022 return hVfsIos;
1023
1024 /* Create the manifest if necessary. */
1025 if (m->hOurManifest == NIL_RTMANIFEST)
1026 {
1027 vrc = RTManifestCreate(0 /*fFlags*/, &m->hOurManifest);
1028 AssertRCReturnStmt(vrc, RTVfsIoStrmRelease(hVfsIos), NIL_RTVFSIOSTREAM);
1029 }
1030
1031 /* Setup the stream. */
1032 RTVFSIOSTREAM hVfsIosPt;
1033 vrc = RTManifestEntryAddPassthruIoStream(m->hOurManifest, hVfsIos, pszManifestEntry, m->fDigestTypes, fRead, &hVfsIosPt);
1034
1035 RTVfsIoStrmRelease(hVfsIos); /* always consumed! */
1036 if (RT_SUCCESS(vrc))
1037 return hVfsIosPt;
1038
1039 setErrorVrc(vrc, tr("RTManifestEntryAddPassthruIoStream failed with rc=%Rrc"), vrc);
1040 return NIL_RTVFSIOSTREAM;
1041}
1042
1043/**
1044 * Returns true if the appliance is in "idle" state. This should always be the
1045 * case unless an import or export is currently in progress. Similar to machine
1046 * states, this permits the Appliance implementation code to let go of the
1047 * Appliance object lock while a time-consuming disk conversion is in progress
1048 * without exposing the appliance to conflicting calls.
1049 *
1050 * This sets an error on "this" (the appliance) and returns false if the appliance
1051 * is busy. The caller should then return E_ACCESSDENIED.
1052 *
1053 * Must be called from under the object lock!
1054 */
1055bool Appliance::i_isApplianceIdle()
1056{
1057 if (m->state == ApplianceImporting)
1058 setError(VBOX_E_INVALID_OBJECT_STATE, tr("The appliance is busy importing files"));
1059 else if (m->state == ApplianceExporting)
1060 setError(VBOX_E_INVALID_OBJECT_STATE, tr("The appliance is busy exporting files"));
1061 else
1062 return true;
1063
1064 return false;
1065}
1066
1067HRESULT Appliance::i_searchUniqueVMName(Utf8Str &aName) const
1068{
1069 ComPtr<IMachine> ptrMachine;
1070 char *tmpName = RTStrDup(aName.c_str());
1071 int i = 1;
1072 while (mVirtualBox->FindMachine(Bstr(tmpName).raw(), ptrMachine.asOutParam()) != VBOX_E_OBJECT_NOT_FOUND)
1073 {
1074 RTStrFree(tmpName);
1075 RTStrAPrintf(&tmpName, "%s %d", aName.c_str(), i);
1076 ++i;
1077 }
1078 aName = tmpName;
1079 RTStrFree(tmpName);
1080
1081 return S_OK;
1082}
1083
1084HRESULT Appliance::i_ensureUniqueImageFilePath(const Utf8Str &aMachineFolder, DeviceType_T aDeviceType, Utf8Str &aName) const
1085{
1086 /*
1087 * Check if the file exists or if a medium with this path is registered already
1088 */
1089 Utf8Str strAbsName;
1090 size_t offDashNum = ~(size_t)0;
1091 size_t cchDashNum = 0;
1092 for (unsigned i = 1;; i++)
1093 {
1094 /* Complete the path (could be relative to machine folder). */
1095 int rc = RTPathAbsExCxx(strAbsName, aMachineFolder, aName);
1096 AssertRCReturn(rc, Global::vboxStatusCodeToCOM(rc)); /** @todo stupid caller ignores this */
1097
1098 /* Check that the file does not exist and that there is no media somehow matching the name. */
1099 if (!RTPathExists(strAbsName.c_str()))
1100 {
1101 ComPtr<IMedium> ptrMedium;
1102 HRESULT hrc = mVirtualBox->OpenMedium(Bstr(strAbsName).raw(), aDeviceType, AccessMode_ReadWrite,
1103 FALSE /* fForceNewUuid */, ptrMedium.asOutParam());
1104 if (hrc == VBOX_E_OBJECT_NOT_FOUND)
1105 return S_OK;
1106 }
1107
1108 /* Insert '_%i' before the suffix and try again. */
1109 if (offDashNum == ~(size_t)0)
1110 {
1111 const char *pszSuffix = RTPathSuffix(aName.c_str());
1112 offDashNum = pszSuffix ? (size_t)(pszSuffix - aName.c_str()) : aName.length();
1113 }
1114 char szTmp[32];
1115 size_t cchTmp = RTStrPrintf(szTmp, sizeof(szTmp), "_%u", i);
1116 aName.replace(offDashNum, cchDashNum, szTmp, cchTmp);
1117 cchDashNum = cchTmp;
1118 }
1119}
1120
1121/**
1122 * Called from Appliance::importImpl() and Appliance::writeImpl() to set up a
1123 * progress object with the proper weights and maximum progress values.
1124 */
1125HRESULT Appliance::i_setUpProgress(ComObjPtr<Progress> &pProgress,
1126 const Utf8Str &strDescription,
1127 SetUpProgressMode mode)
1128{
1129 HRESULT rc;
1130
1131 /* Create the progress object */
1132 try
1133 {
1134 rc = pProgress.createObject();
1135 if (FAILED(rc))
1136 return rc;
1137 }
1138 catch (std::bad_alloc &)
1139 {
1140 return E_OUTOFMEMORY;
1141 }
1142
1143 // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
1144 i_disksWeight();
1145
1146 m->ulWeightForManifestOperation = 0;
1147
1148 ULONG cOperations = 1 // one for XML setup
1149 + m->cDisks; // plus one per disk
1150 ULONG ulTotalOperationsWeight;
1151 if (m->ulTotalDisksMB)
1152 {
1153 m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100); // use 1% of the progress for the XML
1154 ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
1155 }
1156 else
1157 {
1158 // no disks to export:
1159 m->ulWeightForXmlOperation = 1;
1160 ulTotalOperationsWeight = 1;
1161 }
1162
1163 switch (mode)
1164 {
1165 case ImportFile:
1166 {
1167 break;
1168 }
1169 case WriteFile:
1170 {
1171 // assume that creating the manifest will take .1% of the time it takes to export the disks
1172 if (m->fManifest)
1173 {
1174 ++cOperations; // another one for creating the manifest
1175
1176 m->ulWeightForManifestOperation = (ULONG)((double)m->ulTotalDisksMB * .1 / 100); // use .5% of the
1177 // progress for the manifest
1178 ulTotalOperationsWeight += m->ulWeightForManifestOperation;
1179 }
1180 break;
1181 }
1182 case ImportS3:
1183 {
1184 cOperations += 1 + 1; // another one for the manifest file & another one for the import
1185 ulTotalOperationsWeight = m->ulTotalDisksMB;
1186 if (!m->ulTotalDisksMB)
1187 // no disks to export:
1188 ulTotalOperationsWeight = 1;
1189
1190 ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50 / 100); // use 50% for import
1191 ulTotalOperationsWeight += ulImportWeight;
1192
1193 m->ulWeightForXmlOperation = ulImportWeight; /* save for using later */
1194
1195 ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1 / 100); // use 0.1% for init
1196 ulTotalOperationsWeight += ulInitWeight;
1197 break;
1198 }
1199 case WriteS3:
1200 {
1201 cOperations += 1 + 1; // another one for the mf & another one for temporary creation
1202
1203 if (m->ulTotalDisksMB)
1204 {
1205 m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100); // use 1% of the progress
1206 // for OVF file upload
1207 // (we didn't know the
1208 // size at this point)
1209 ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
1210 }
1211 else
1212 {
1213 // no disks to export:
1214 ulTotalOperationsWeight = 1;
1215 m->ulWeightForXmlOperation = 1;
1216 }
1217 ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the
1218 creation of the OVF
1219 & the disks */
1220 ulTotalOperationsWeight += ulOVFCreationWeight;
1221 break;
1222 }
1223 case ExportCloud:
1224 case ImportCloud:
1225 break;
1226 }
1227 Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightForXmlOperation = %d\n",
1228 m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
1229
1230 return pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
1231 strDescription,
1232 TRUE /* aCancelable */,
1233 cOperations, // ULONG cOperations,
1234 ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
1235 strDescription, // CBSTR bstrFirstOperationDescription,
1236 m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
1237}
1238
1239void Appliance::i_addWarning(const char* aWarning, ...)
1240{
1241 try
1242 {
1243 va_list args;
1244 va_start(args, aWarning);
1245 Utf8Str str(aWarning, args);
1246 va_end(args);
1247 m->llWarnings.push_back(str);
1248 }
1249 catch (...)
1250 {
1251 AssertFailed();
1252 }
1253}
1254
1255/**
1256 * Refreshes the cDisks and ulTotalDisksMB members in the instance data.
1257 * Requires that virtual system descriptions are present.
1258 */
1259void Appliance::i_disksWeight()
1260{
1261 m->ulTotalDisksMB = 0;
1262 m->cDisks = 0;
1263 // weigh the disk images according to their sizes
1264 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
1265 for (it = m->virtualSystemDescriptions.begin();
1266 it != m->virtualSystemDescriptions.end();
1267 ++it)
1268 {
1269 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
1270 /* One for every medium of the Virtual System */
1271 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
1272 std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
1273 for (itH = avsdeHDs.begin();
1274 itH != avsdeHDs.end();
1275 ++itH)
1276 {
1277 const VirtualSystemDescriptionEntry *pHD = *itH;
1278 m->ulTotalDisksMB += pHD->ulSizeMB;
1279 ++m->cDisks;
1280 }
1281
1282 avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_CDROM);
1283 for (itH = avsdeHDs.begin();
1284 itH != avsdeHDs.end();
1285 ++itH)
1286 {
1287 const VirtualSystemDescriptionEntry *pHD = *itH;
1288 m->ulTotalDisksMB += pHD->ulSizeMB;
1289 ++m->cDisks;
1290 }
1291 }
1292
1293}
1294
1295void Appliance::i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket)
1296{
1297 /* Buckets are S3 specific. So parse the bucket out of the file path */
1298 if (!aPath.startsWith("/"))
1299 throw setError(E_INVALIDARG,
1300 tr("The path '%s' must start with /"), aPath.c_str());
1301 size_t bpos = aPath.find("/", 1);
1302 if (bpos != Utf8Str::npos)
1303 {
1304 aBucket = aPath.substr(1, bpos - 1); /* The bucket without any slashes */
1305 aPath = aPath.substr(bpos); /* The rest of the file path */
1306 }
1307 /* If there is no bucket name provided reject it */
1308 if (aBucket.isEmpty())
1309 throw setError(E_INVALIDARG,
1310 tr("You doesn't provide a bucket name in the URI '%s'"), aPath.c_str());
1311}
1312
1313/**
1314 * Worker for TaskOVF::handler.
1315 *
1316 * The TaskOVF is started in Appliance::readImpl() and Appliance::importImpl()
1317 * and Appliance::writeImpl().
1318 *
1319 * This will in turn call Appliance::readFS() or Appliance::importFS() or
1320 * Appliance::writeFS().
1321 *
1322 * @thread pTask The task.
1323 */
1324/* static */ void Appliance::i_importOrExportThreadTask(TaskOVF *pTask)
1325{
1326 LogFlowFuncEnter();
1327 AssertReturnVoid(pTask);
1328
1329 Appliance *pAppliance = pTask->pAppliance;
1330 LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
1331
1332 switch (pTask->taskType)
1333 {
1334 case TaskOVF::Read:
1335 pAppliance->m->resetReadData();
1336 if (pTask->locInfo.storageType == VFSType_File)
1337 pTask->rc = pAppliance->i_readFS(pTask);
1338 else
1339 pTask->rc = E_NOTIMPL;
1340 break;
1341
1342 case TaskOVF::Import:
1343 /** @todo allow overriding these? */
1344 if (!pAppliance->m->fSignatureValid && pAppliance->m->pbSignedDigest)
1345 pTask->rc = pAppliance->setError(E_FAIL, tr("The manifest signature for '%s' is not valid"),
1346 pTask->locInfo.strPath.c_str());
1347 else if (!pAppliance->m->fCertificateValid && pAppliance->m->pbSignedDigest)
1348 {
1349 if (pAppliance->m->strCertError.isNotEmpty())
1350 pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is not valid: %s"),
1351 pTask->locInfo.strPath.c_str(), pAppliance->m->strCertError.c_str());
1352 else
1353 pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is not valid"),
1354 pTask->locInfo.strPath.c_str());
1355 }
1356 // fusion does not consider this a show stopper (we've filed a warning during read).
1357 //else if (pAppliance->m->fCertificateMissingPath && pAppliance->m->pbSignedDigest)
1358 // pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is does not have a valid CA path"),
1359 // pTask->locInfo.strPath.c_str());
1360 else
1361 {
1362 if (pTask->locInfo.storageType == VFSType_File)
1363 pTask->rc = pAppliance->i_importFS(pTask);
1364 else
1365 pTask->rc = E_NOTIMPL;
1366 }
1367 break;
1368
1369 case TaskOVF::Write:
1370 if (pTask->locInfo.storageType == VFSType_File)
1371 pTask->rc = pAppliance->i_writeFS(pTask);
1372 else
1373 pTask->rc = E_NOTIMPL;
1374 break;
1375
1376 default:
1377 AssertFailed();
1378 pTask->rc = E_FAIL;
1379 break;
1380 }
1381
1382 if (!pTask->pProgress.isNull())
1383 pTask->pProgress->i_notifyComplete(pTask->rc);
1384
1385 LogFlowFuncLeave();
1386}
1387
1388/* static */ DECLCALLBACK(int) Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser)
1389{
1390 Appliance::TaskOVF* pTask = *(Appliance::TaskOVF**)pvUser;
1391
1392 if ( pTask
1393 && !pTask->pProgress.isNull())
1394 {
1395 BOOL fCanceled;
1396 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
1397 if (fCanceled)
1398 return -1;
1399 pTask->pProgress->SetCurrentOperationProgress(uPercent);
1400 }
1401 return VINF_SUCCESS;
1402}
1403
1404/**
1405 * Worker for TaskOPC::handler.
1406 * @thread pTask The task.
1407 */
1408/* static */
1409void Appliance::i_exportOPCThreadTask(TaskOPC *pTask)
1410{
1411 LogFlowFuncEnter();
1412 AssertReturnVoid(pTask);
1413
1414 Appliance *pAppliance = pTask->pAppliance;
1415 LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
1416
1417 switch (pTask->taskType)
1418 {
1419 case TaskOPC::Export:
1420 pTask->rc = pAppliance->i_writeFSOPC(pTask);
1421 break;
1422
1423 default:
1424 AssertFailed();
1425 pTask->rc = E_FAIL;
1426 break;
1427 }
1428
1429 if (!pTask->pProgress.isNull())
1430 pTask->pProgress->i_notifyComplete(pTask->rc);
1431
1432 LogFlowFuncLeave();
1433}
1434
1435/* static */
1436DECLCALLBACK(int) Appliance::TaskOPC::updateProgress(unsigned uPercent, void *pvUser)
1437{
1438 Appliance::TaskOPC* pTask = *(Appliance::TaskOPC**)pvUser;
1439
1440 if ( pTask
1441 && !pTask->pProgress.isNull())
1442 {
1443 BOOL fCanceled;
1444 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
1445 if (fCanceled)
1446 return -1;
1447 pTask->pProgress->SetCurrentOperationProgress(uPercent);
1448 }
1449 return VINF_SUCCESS;
1450}
1451
1452/**
1453 * Worker for TaskCloud::handler.
1454 * @thread pTask The task.
1455 */
1456/* static */
1457void Appliance::i_importOrExportCloudThreadTask(TaskCloud *pTask)
1458{
1459 LogFlowFuncEnter();
1460 AssertReturnVoid(pTask);
1461
1462 Appliance *pAppliance = pTask->pAppliance;
1463 LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
1464
1465 switch (pTask->taskType)
1466 {
1467 case TaskCloud::Export:
1468 pAppliance->i_setApplianceState(ApplianceExporting);
1469 pTask->rc = pAppliance->i_exportCloudImpl(pTask);
1470 break;
1471 case TaskCloud::Import:
1472 pAppliance->i_setApplianceState(ApplianceImporting);
1473 pTask->rc = pAppliance->i_importCloudImpl(pTask);
1474 break;
1475 case TaskCloud::ReadData:
1476 pAppliance->i_setApplianceState(ApplianceImporting);
1477 pTask->rc = pAppliance->i_gettingCloudData(pTask);
1478 break;
1479 default:
1480 AssertFailed();
1481 pTask->rc = E_FAIL;
1482 break;
1483 }
1484
1485 pAppliance->i_setApplianceState(ApplianceIdle);
1486
1487 if (!pTask->pProgress.isNull())
1488 pTask->pProgress->i_notifyComplete(pTask->rc);
1489
1490 LogFlowFuncLeave();
1491}
1492
1493/* static */
1494DECLCALLBACK(int) Appliance::TaskCloud::updateProgress(unsigned uPercent, void *pvUser)
1495{
1496 Appliance::TaskCloud* pTask = *(Appliance::TaskCloud**)pvUser;
1497
1498 if ( pTask
1499 && !pTask->pProgress.isNull())
1500 {
1501 BOOL fCanceled;
1502 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
1503 if (fCanceled)
1504 return -1;
1505 pTask->pProgress->SetCurrentOperationProgress(uPercent);
1506 }
1507 return VINF_SUCCESS;
1508}
1509
1510void i_parseURI(Utf8Str strUri, LocationInfo &locInfo)
1511{
1512 /* Check the URI for the protocol */
1513 if (strUri.startsWith("file://", Utf8Str::CaseInsensitive)) /* File based */
1514 {
1515 locInfo.storageType = VFSType_File;
1516 strUri = strUri.substr(sizeof("file://") - 1);
1517 }
1518 else if (strUri.startsWith("SunCloud://", Utf8Str::CaseInsensitive)) /* Sun Cloud service */
1519 {
1520 locInfo.storageType = VFSType_S3;
1521 strUri = strUri.substr(sizeof("SunCloud://") - 1);
1522 }
1523 else if (strUri.startsWith("S3://", Utf8Str::CaseInsensitive)) /* S3 service */
1524 {
1525 locInfo.storageType = VFSType_S3;
1526 strUri = strUri.substr(sizeof("S3://") - 1);
1527 }
1528 else if (strUri.startsWith("OCI://", Utf8Str::CaseInsensitive)) /* OCI service (storage or compute) */
1529 {
1530 locInfo.storageType = VFSType_Cloud;
1531 locInfo.strProvider = "OCI";
1532 strUri = strUri.substr(sizeof("OCI://") - 1);
1533 }
1534 else if (strUri.startsWith("webdav://", Utf8Str::CaseInsensitive)) /* webdav service */
1535 throw E_NOTIMPL;
1536
1537 /* Not necessary on a file based URI */
1538// if (locInfo.storageType != VFSType_File)
1539// {
1540// size_t uppos = strUri.find("@"); /* username:password combo */
1541// if (uppos != Utf8Str::npos)
1542// {
1543// locInfo.strUsername = strUri.substr(0, uppos);
1544// strUri = strUri.substr(uppos + 1);
1545// size_t upos = locInfo.strUsername.find(":");
1546// if (upos != Utf8Str::npos)
1547// {
1548// locInfo.strPassword = locInfo.strUsername.substr(upos + 1);
1549// locInfo.strUsername = locInfo.strUsername.substr(0, upos);
1550// }
1551// }
1552// size_t hpos = strUri.find("/"); /* hostname part */
1553// if (hpos != Utf8Str::npos)
1554// {
1555// locInfo.strHostname = strUri.substr(0, hpos);
1556// strUri = strUri.substr(hpos);
1557// }
1558// }
1559
1560 locInfo.strPath = strUri;
1561}
1562
1563
1564////////////////////////////////////////////////////////////////////////////////
1565//
1566// IVirtualSystemDescription constructor / destructor
1567//
1568////////////////////////////////////////////////////////////////////////////////
1569
1570/**
1571 * COM initializer.
1572 * @return
1573 */
1574HRESULT VirtualSystemDescription::init()
1575{
1576 /* Enclose the state transition NotReady->InInit->Ready */
1577 AutoInitSpan autoInitSpan(this);
1578 AssertReturn(autoInitSpan.isOk(), E_FAIL);
1579
1580 /* Initialize data */
1581 m = new Data();
1582 m->pConfig = NULL;
1583
1584 /* Confirm a successful initialization */
1585 autoInitSpan.setSucceeded();
1586 return S_OK;
1587}
1588
1589/**
1590* COM uninitializer.
1591*/
1592
1593void VirtualSystemDescription::uninit()
1594{
1595 if (m->pConfig)
1596 delete m->pConfig;
1597 delete m;
1598 m = NULL;
1599}
1600
1601
1602////////////////////////////////////////////////////////////////////////////////
1603//
1604// IVirtualSystemDescription public methods
1605//
1606////////////////////////////////////////////////////////////////////////////////
1607
1608/**
1609 * Public method implementation.
1610 */
1611HRESULT VirtualSystemDescription::getCount(ULONG *aCount)
1612{
1613 if (!aCount)
1614 return E_POINTER;
1615
1616 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1617
1618 *aCount = (ULONG)m->maDescriptions.size();
1619 return S_OK;
1620}
1621
1622/**
1623 * Public method implementation.
1624 */
1625HRESULT VirtualSystemDescription::getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
1626 std::vector<com::Utf8Str> &aRefs,
1627 std::vector<com::Utf8Str> &aOVFValues,
1628 std::vector<com::Utf8Str> &aVBoxValues,
1629 std::vector<com::Utf8Str> &aExtraConfigValues)
1630
1631{
1632 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1633 size_t c = m->maDescriptions.size();
1634 aTypes.resize(c);
1635 aRefs.resize(c);
1636 aOVFValues.resize(c);
1637 aVBoxValues.resize(c);
1638 aExtraConfigValues.resize(c);
1639
1640 for (size_t i = 0; i < c; i++)
1641 {
1642 const VirtualSystemDescriptionEntry &vsde = m->maDescriptions[i];
1643 aTypes[i] = vsde.type;
1644 aRefs[i] = vsde.strRef;
1645 aOVFValues[i] = vsde.strOvf;
1646 aVBoxValues[i] = vsde.strVBoxCurrent;
1647 aExtraConfigValues[i] = vsde.strExtraConfigCurrent;
1648 }
1649 return S_OK;
1650}
1651
1652/**
1653 * Public method implementation.
1654 */
1655HRESULT VirtualSystemDescription::getDescriptionByType(VirtualSystemDescriptionType_T aType,
1656 std::vector<VirtualSystemDescriptionType_T> &aTypes,
1657 std::vector<com::Utf8Str> &aRefs,
1658 std::vector<com::Utf8Str> &aOVFValues,
1659 std::vector<com::Utf8Str> &aVBoxValues,
1660 std::vector<com::Utf8Str> &aExtraConfigValues)
1661{
1662 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1663 std::list<VirtualSystemDescriptionEntry*> vsd = i_findByType(aType);
1664
1665 size_t c = vsd.size();
1666 aTypes.resize(c);
1667 aRefs.resize(c);
1668 aOVFValues.resize(c);
1669 aVBoxValues.resize(c);
1670 aExtraConfigValues.resize(c);
1671
1672 size_t i = 0;
1673 for (list<VirtualSystemDescriptionEntry*>::const_iterator it = vsd.begin(); it != vsd.end(); ++it, ++i)
1674 {
1675 const VirtualSystemDescriptionEntry *vsde = (*it);
1676 aTypes[i] = vsde->type;
1677 aRefs[i] = vsde->strRef;
1678 aOVFValues[i] = vsde->strOvf;
1679 aVBoxValues[i] = vsde->strVBoxCurrent;
1680 aExtraConfigValues[i] = vsde->strExtraConfigCurrent;
1681 }
1682
1683 return S_OK;
1684}
1685
1686/**
1687 * Public method implementation.
1688 */
1689HRESULT VirtualSystemDescription::getValuesByType(VirtualSystemDescriptionType_T aType,
1690 VirtualSystemDescriptionValueType_T aWhich,
1691 std::vector<com::Utf8Str> &aValues)
1692{
1693 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1694
1695 std::list<VirtualSystemDescriptionEntry*> vsd = i_findByType (aType);
1696 aValues.resize((ULONG)vsd.size());
1697
1698 list<VirtualSystemDescriptionEntry*>::const_iterator it;
1699 size_t i = 0;
1700 for (it = vsd.begin();
1701 it != vsd.end();
1702 ++it, ++i)
1703 {
1704 const VirtualSystemDescriptionEntry *vsde = (*it);
1705
1706 Bstr bstr;
1707 switch (aWhich)
1708 {
1709 case VirtualSystemDescriptionValueType_Reference: aValues[i] = vsde->strRef; break;
1710 case VirtualSystemDescriptionValueType_Original: aValues[i] = vsde->strOvf; break;
1711 case VirtualSystemDescriptionValueType_Auto: aValues[i] = vsde->strVBoxCurrent; break;
1712 case VirtualSystemDescriptionValueType_ExtraConfig: aValues[i] = vsde->strExtraConfigCurrent; break;
1713#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
1714 case VirtualSystemDescriptionValueType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
1715#endif
1716 }
1717 }
1718
1719 return S_OK;
1720}
1721
1722/**
1723 * Public method implementation.
1724 */
1725HRESULT VirtualSystemDescription::setFinalValues(const std::vector<BOOL> &aEnabled,
1726 const std::vector<com::Utf8Str> &aVBoxValues,
1727 const std::vector<com::Utf8Str> &aExtraConfigValues)
1728{
1729#ifndef RT_OS_WINDOWS
1730 // NOREF(aEnabledSize);
1731#endif /* RT_OS_WINDOWS */
1732 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1733
1734 if ( (aEnabled.size() != m->maDescriptions.size())
1735 || (aVBoxValues.size() != m->maDescriptions.size())
1736 || (aExtraConfigValues.size() != m->maDescriptions.size())
1737 )
1738 return E_INVALIDARG;
1739
1740 size_t i = 0;
1741 for (vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1742 it != m->maDescriptions.end();
1743 ++it, ++i)
1744 {
1745 VirtualSystemDescriptionEntry& vsde = *it;
1746
1747 if (aEnabled[i])
1748 {
1749 vsde.strVBoxCurrent = aVBoxValues[i];
1750 vsde.strExtraConfigCurrent = aExtraConfigValues[i];
1751 }
1752 else
1753 vsde.type = VirtualSystemDescriptionType_Ignore;
1754 }
1755
1756 return S_OK;
1757}
1758
1759/**
1760 * Public method implementation.
1761 */
1762HRESULT VirtualSystemDescription::addDescription(VirtualSystemDescriptionType_T aType,
1763 const com::Utf8Str &aVBoxValue,
1764 const com::Utf8Str &aExtraConfigValue)
1765
1766{
1767 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1768 i_addEntry(aType, "", aVBoxValue, aVBoxValue, 0, aExtraConfigValue);
1769 return S_OK;
1770}
1771
1772/**
1773 * Internal method; adds a new description item to the member list.
1774 * @param aType Type of description for the new item.
1775 * @param strRef Reference item; only used with storage controllers.
1776 * @param aOvfValue Corresponding original value from OVF.
1777 * @param aVBoxValue Initial configuration value (can be overridden by caller with setFinalValues).
1778 * @param ulSizeMB Weight for IProgress
1779 * @param strExtraConfig Extra configuration; meaning dependent on type.
1780 */
1781void VirtualSystemDescription::i_addEntry(VirtualSystemDescriptionType_T aType,
1782 const Utf8Str &strRef,
1783 const Utf8Str &aOvfValue,
1784 const Utf8Str &aVBoxValue,
1785 uint32_t ulSizeMB,
1786 const Utf8Str &strExtraConfig /*= ""*/)
1787{
1788 VirtualSystemDescriptionEntry vsde;
1789 vsde.ulIndex = (uint32_t)m->maDescriptions.size(); // each entry gets an index so the client side can reference them
1790 vsde.type = aType;
1791 vsde.strRef = strRef;
1792 vsde.strOvf = aOvfValue;
1793 vsde.strVBoxSuggested /* remember original value */
1794 = vsde.strVBoxCurrent /* and set current value which can be overridden by setFinalValues() */
1795 = aVBoxValue;
1796 vsde.strExtraConfigSuggested
1797 = vsde.strExtraConfigCurrent
1798 = strExtraConfig;
1799 vsde.ulSizeMB = ulSizeMB;
1800
1801 vsde.skipIt = false;
1802
1803 m->maDescriptions.push_back(vsde);
1804}
1805
1806/**
1807 * Private method; returns a list of description items containing all the items from the member
1808 * description items of this virtual system that match the given type.
1809 */
1810std::list<VirtualSystemDescriptionEntry*> VirtualSystemDescription::i_findByType(VirtualSystemDescriptionType_T aType)
1811{
1812 std::list<VirtualSystemDescriptionEntry*> vsd;
1813 for (vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1814 it != m->maDescriptions.end();
1815 ++it)
1816 {
1817 if (it->type == aType)
1818 vsd.push_back(&(*it));
1819 }
1820
1821 return vsd;
1822}
1823
1824HRESULT VirtualSystemDescription::removeDescriptionByType(VirtualSystemDescriptionType_T aType)
1825{
1826 std::vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1827 while (it != m->maDescriptions.end())
1828 {
1829 if (it->type == aType)
1830 it = m->maDescriptions.erase(it);
1831 else
1832 ++it;
1833 }
1834
1835 return S_OK;
1836}
1837
1838/* Private method; delete all records from the list
1839 * m->llDescriptions that match the given type.
1840 */
1841void VirtualSystemDescription::i_removeByType(VirtualSystemDescriptionType_T aType)
1842{
1843 std::vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1844 while (it != m->maDescriptions.end())
1845 {
1846 if (it->type == aType)
1847 it = m->maDescriptions.erase(it);
1848 else
1849 ++it;
1850 }
1851}
1852
1853/**
1854 * Private method; looks thru the member hardware items for the IDE, SATA, or SCSI controller with
1855 * the given reference ID. Useful when needing the controller for a particular
1856 * virtual disk.
1857 */
1858const VirtualSystemDescriptionEntry* VirtualSystemDescription::i_findControllerFromID(const Utf8Str &id)
1859{
1860 vector<VirtualSystemDescriptionEntry>::const_iterator it;
1861 for (it = m->maDescriptions.begin();
1862 it != m->maDescriptions.end();
1863 ++it)
1864 {
1865 const VirtualSystemDescriptionEntry &d = *it;
1866 switch (d.type)
1867 {
1868 case VirtualSystemDescriptionType_HardDiskControllerIDE:
1869 case VirtualSystemDescriptionType_HardDiskControllerSATA:
1870 case VirtualSystemDescriptionType_HardDiskControllerSCSI:
1871 case VirtualSystemDescriptionType_HardDiskControllerVirtioSCSI:
1872 case VirtualSystemDescriptionType_HardDiskControllerSAS:
1873 if (d.strRef == id)
1874 return &d;
1875 break;
1876 default: break; /* Shut up MSC. */
1877 }
1878 }
1879
1880 return NULL;
1881}
1882
1883/**
1884 * Method called from Appliance::Interpret() if the source OVF for a virtual system
1885 * contains a <vbox:Machine> element. This method then attempts to parse that and
1886 * create a MachineConfigFile instance from it which is stored in this instance data
1887 * and can then be used to create a machine.
1888 *
1889 * This must only be called once per instance.
1890 *
1891 * This rethrows all XML and logic errors from MachineConfigFile.
1892 *
1893 * @param elmMachine <vbox:Machine> element with attributes and subelements from some
1894 * DOM tree.
1895 */
1896void VirtualSystemDescription::i_importVBoxMachineXML(const xml::ElementNode &elmMachine)
1897{
1898 settings::MachineConfigFile *pConfig = NULL;
1899
1900 Assert(m->pConfig == NULL);
1901
1902 try
1903 {
1904 pConfig = new settings::MachineConfigFile(NULL);
1905 pConfig->importMachineXML(elmMachine);
1906
1907 m->pConfig = pConfig;
1908 }
1909 catch (...)
1910 {
1911 if (pConfig)
1912 delete pConfig;
1913 throw;
1914 }
1915}
1916
1917/**
1918 * Returns the machine config created by importVBoxMachineXML() or NULL if there's none.
1919 */
1920const settings::MachineConfigFile* VirtualSystemDescription::i_getMachineConfig() const
1921{
1922 return m->pConfig;
1923}
1924
1925/**
1926 * Private method; walks through the array of VirtualSystemDescriptionEntry entries
1927 * and returns the one matching the given index.
1928 */
1929const VirtualSystemDescriptionEntry* VirtualSystemDescription::i_findByIndex(const uint32_t aIndex)
1930{
1931 vector<VirtualSystemDescriptionEntry>::const_iterator it;
1932 for (it = m->maDescriptions.begin();
1933 it != m->maDescriptions.end();
1934 ++it)
1935 {
1936 const VirtualSystemDescriptionEntry &d = *it;
1937 if (d.ulIndex == aIndex)
1938 return &d;
1939 }
1940
1941 return NULL;
1942}
1943
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