VirtualBox

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

Last change on this file since 107526 was 107516, checked in by vboxsync, 4 weeks ago

src/VBox/Main/src-server/ApplianceImpl.cpp: Fixed warning found by Parfait (uninitialized attributes). jiraref:VBP-1424

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