1 | /* $Id: ApplianceImpl.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | #ifndef MAIN_INCLUDED_ApplianceImpl_h
|
---|
29 | #define MAIN_INCLUDED_ApplianceImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* VBox includes */
|
---|
35 | #include "VirtualSystemDescriptionWrap.h"
|
---|
36 | #include "ApplianceWrap.h"
|
---|
37 | #include "MediumFormatImpl.h"
|
---|
38 |
|
---|
39 | /** @todo This file needs massive cleanup. Split IAppliance in a public and
|
---|
40 | * private classes. */
|
---|
41 | #include "ovfreader.h"
|
---|
42 | #include <set>
|
---|
43 |
|
---|
44 | /* VBox forward declarations */
|
---|
45 | class Certificate;
|
---|
46 | class Progress;
|
---|
47 | class VirtualSystemDescription;
|
---|
48 | struct VirtualSystemDescriptionEntry;
|
---|
49 | struct LocationInfo;
|
---|
50 | typedef struct VDINTERFACE *PVDINTERFACE;
|
---|
51 | typedef struct VDINTERFACEIO *PVDINTERFACEIO;
|
---|
52 | typedef struct SHASTORAGE *PSHASTORAGE;
|
---|
53 |
|
---|
54 | namespace ovf
|
---|
55 | {
|
---|
56 | struct HardDiskController;
|
---|
57 | struct VirtualSystem;
|
---|
58 | class OVFReader;
|
---|
59 | struct DiskImage;
|
---|
60 | struct EnvelopeData;
|
---|
61 | }
|
---|
62 |
|
---|
63 | namespace xml
|
---|
64 | {
|
---|
65 | class Document;
|
---|
66 | class ElementNode;
|
---|
67 | }
|
---|
68 |
|
---|
69 | namespace settings
|
---|
70 | {
|
---|
71 | class MachineConfigFile;
|
---|
72 | }
|
---|
73 |
|
---|
74 | class ATL_NO_VTABLE Appliance :
|
---|
75 | public ApplianceWrap
|
---|
76 | {
|
---|
77 | public:
|
---|
78 |
|
---|
79 | DECLARE_COMMON_CLASS_METHODS(Appliance)
|
---|
80 |
|
---|
81 | HRESULT FinalConstruct();
|
---|
82 | void FinalRelease();
|
---|
83 |
|
---|
84 |
|
---|
85 | HRESULT init(VirtualBox *aVirtualBox);
|
---|
86 | void uninit();
|
---|
87 |
|
---|
88 | /* public methods only for internal purposes */
|
---|
89 |
|
---|
90 | static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *aText, ...)
|
---|
91 | {
|
---|
92 | va_list va;
|
---|
93 | va_start(va, aText);
|
---|
94 | HRESULT hrc = setErrorInternalV(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, va, false, true);
|
---|
95 | va_end(va);
|
---|
96 | return hrc;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* private instance data */
|
---|
100 | private:
|
---|
101 | // wrapped IAppliance properties
|
---|
102 | HRESULT getPath(com::Utf8Str &aPath);
|
---|
103 | HRESULT getDisks(std::vector<com::Utf8Str> &aDisks);
|
---|
104 | HRESULT getCertificate(ComPtr<ICertificate> &aCertificateInfo);
|
---|
105 | HRESULT getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions);
|
---|
106 | HRESULT getMachines(std::vector<com::Utf8Str> &aMachines);
|
---|
107 |
|
---|
108 | // wrapped IAppliance methods
|
---|
109 | HRESULT read(const com::Utf8Str &aFile,
|
---|
110 | ComPtr<IProgress> &aProgress);
|
---|
111 | HRESULT interpret();
|
---|
112 | HRESULT importMachines(const std::vector<ImportOptions_T> &aOptions,
|
---|
113 | ComPtr<IProgress> &aProgress);
|
---|
114 | HRESULT createVFSExplorer(const com::Utf8Str &aURI,
|
---|
115 | ComPtr<IVFSExplorer> &aExplorer);
|
---|
116 | HRESULT write(const com::Utf8Str &aFormat,
|
---|
117 | const std::vector<ExportOptions_T> &aOptions,
|
---|
118 | const com::Utf8Str &aPath,
|
---|
119 | ComPtr<IProgress> &aProgress);
|
---|
120 | HRESULT getWarnings(std::vector<com::Utf8Str> &aWarnings);
|
---|
121 | HRESULT getPasswordIds(std::vector<com::Utf8Str> &aIdentifiers);
|
---|
122 | HRESULT getMediumIdsForPasswordId(const com::Utf8Str &aPasswordId, std::vector<com::Guid> &aIdentifiers);
|
---|
123 | HRESULT addPasswords(const std::vector<com::Utf8Str> &aIdentifiers,
|
---|
124 | const std::vector<com::Utf8Str> &aPasswords);
|
---|
125 | HRESULT createVirtualSystemDescriptions(ULONG aRequested, ULONG *aCreated);
|
---|
126 | /** weak VirtualBox parent */
|
---|
127 | VirtualBox* const mVirtualBox;
|
---|
128 |
|
---|
129 | struct ImportStack;
|
---|
130 | class TaskOVF;
|
---|
131 | class TaskOPC;
|
---|
132 | class TaskCloud;
|
---|
133 |
|
---|
134 | struct Data; // opaque, defined in ApplianceImpl.cpp
|
---|
135 | Data *m;
|
---|
136 |
|
---|
137 | enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3, ExportCloud, ImportCloud };
|
---|
138 |
|
---|
139 | enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
|
---|
140 | void i_setApplianceState(const ApplianceState &state);
|
---|
141 | /** @name General stuff
|
---|
142 | * @{
|
---|
143 | */
|
---|
144 | bool i_isApplianceIdle();
|
---|
145 | HRESULT i_searchUniqueVMName(Utf8Str &aName) const;
|
---|
146 | HRESULT i_ensureUniqueImageFilePath(const Utf8Str &aMachineFolder,
|
---|
147 | DeviceType_T aDeviceType,
|
---|
148 | Utf8Str &aName) const;
|
---|
149 | HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress,
|
---|
150 | const Utf8Str &strDescription,
|
---|
151 | SetUpProgressMode mode);
|
---|
152 | void i_addWarning(const char* aWarning, ...);
|
---|
153 | void i_disksWeight();
|
---|
154 | void i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
|
---|
155 |
|
---|
156 | static void i_importOrExportThreadTask(TaskOVF *pTask);
|
---|
157 | static void i_exportOPCThreadTask(TaskOPC *pTask);
|
---|
158 | static void i_importOrExportCloudThreadTask(TaskCloud *pTask);
|
---|
159 |
|
---|
160 | HRESULT i_initBackendNames();
|
---|
161 |
|
---|
162 | Utf8Str i_typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
|
---|
163 |
|
---|
164 | #if 0 /* unused */
|
---|
165 | std::set<Utf8Str> i_URIFromTypeOfVirtualDiskFormat(Utf8Str type);
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | HRESULT i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
|
---|
169 |
|
---|
170 | RTVFSIOSTREAM i_manifestSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry,
|
---|
171 | bool fRead = true);
|
---|
172 | /** @} */
|
---|
173 |
|
---|
174 | /** @name Read stuff
|
---|
175 | * @{
|
---|
176 | */
|
---|
177 | HRESULT i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
178 |
|
---|
179 | HRESULT i_readFS(TaskOVF *pTask);
|
---|
180 | HRESULT i_readFSOVF(TaskOVF *pTask);
|
---|
181 | HRESULT i_readFSOVA(TaskOVF *pTask);
|
---|
182 | HRESULT i_readOVFFile(TaskOVF *pTask, RTVFSIOSTREAM hIosOvf, const char *pszManifestEntry);
|
---|
183 | HRESULT i_readManifestFile(TaskOVF *pTask, RTVFSIOSTREAM hIosMf, const char *pszSubFileNm);
|
---|
184 | HRESULT i_readSignatureFile(TaskOVF *pTask, RTVFSIOSTREAM hIosCert, const char *pszSubFileNm);
|
---|
185 | HRESULT i_readTailProcessing(TaskOVF *pTask);
|
---|
186 | HRESULT i_readTailProcessingGetManifestData(void **ppvData, size_t *pcbData);
|
---|
187 | HRESULT i_readTailProcessingSignedData(PRTERRINFOSTATIC pErrInfo);
|
---|
188 | HRESULT i_readTailProcessingVerifySelfSignedOvfCert(TaskOVF *pTask, RTCRSTORE hTrustedCerts, PRTERRINFOSTATIC pErrInfo);
|
---|
189 | HRESULT i_readTailProcessingVerifyIssuedOvfCert(TaskOVF *pTask, RTCRSTORE hTrustedStore, PRTERRINFOSTATIC pErrInfo);
|
---|
190 | HRESULT i_readTailProcessingVerifyContentInfoCerts(void const *pvData, size_t cbData,
|
---|
191 | RTCRSTORE hTrustedStore, PRTERRINFOSTATIC pErrInfo);
|
---|
192 | HRESULT i_readTailProcessingVerifyAnalyzeSignerInfo(void const *pvData, size_t cbData, RTCRSTORE hTrustedStore,
|
---|
193 | uint32_t iSigner, PRTTIMESPEC pNow, int vrc,
|
---|
194 | PRTERRINFOSTATIC pErrInfo, PRTCRSTORE phTrustedStore2);
|
---|
195 | HRESULT i_readTailProcessingVerifyContentInfoFailOne(const char *pszSignature, int vrc, PRTERRINFOSTATIC pErrInfo);
|
---|
196 |
|
---|
197 | HRESULT i_gettingCloudData(TaskCloud *pTask);
|
---|
198 | /** @} */
|
---|
199 |
|
---|
200 | /** @name Import stuff
|
---|
201 | * @{
|
---|
202 | */
|
---|
203 | HRESULT i_importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
204 |
|
---|
205 | HRESULT i_importFS(TaskOVF *pTask);
|
---|
206 | HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
|
---|
207 | HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
|
---|
208 | HRESULT i_importDoIt(TaskOVF *pTask, AutoWriteLockBase &rWriteLock, RTVFSFSSTREAM hVfsFssOva = NIL_RTVFSFSSTREAM);
|
---|
209 |
|
---|
210 | HRESULT i_verifyManifestFile(ImportStack &stack);
|
---|
211 |
|
---|
212 | void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
|
---|
213 | uint32_t ulAddressOnParent,
|
---|
214 | Utf8Str &controllerName,
|
---|
215 | int32_t &lControllerPort,
|
---|
216 | int32_t &lDevice);
|
---|
217 |
|
---|
218 | void i_importOneDiskImage(const ovf::DiskImage &di,
|
---|
219 | const Utf8Str &strDstPath,
|
---|
220 | ComObjPtr<Medium> &pTargetMedium,
|
---|
221 | ImportStack &stack);
|
---|
222 |
|
---|
223 | void i_importMachineGeneric(const ovf::VirtualSystem &vsysThis,
|
---|
224 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
225 | ComPtr<IMachine> &pNewMachineRet,
|
---|
226 | ImportStack &stack);
|
---|
227 | void i_importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
228 | ComPtr<IMachine> &pNewMachine,
|
---|
229 | ImportStack &stack);
|
---|
230 | void i_importMachines(ImportStack &stack);
|
---|
231 | HRESULT i_verifyStorageControllerPortValid(const StorageControllerType_T aStorageControllerType,
|
---|
232 | const uint32_t aControllerPort,
|
---|
233 | ULONG *ulMaxPorts);
|
---|
234 |
|
---|
235 | HRESULT i_preCheckImageAvailability(ImportStack &stack);
|
---|
236 | bool i_importEnsureOvaLookAhead(ImportStack &stack);
|
---|
237 | RTVFSIOSTREAM i_importOpenSourceFile(ImportStack &stack, Utf8Str const &rstrSrcPath, const char *pszManifestEntry);
|
---|
238 | HRESULT i_importCreateAndWriteDestinationFile(Utf8Str const &rstrDstPath,
|
---|
239 | RTVFSIOSTREAM hVfsIosSrc, Utf8Str const &rstrSrcLogNm);
|
---|
240 |
|
---|
241 | void i_importCopyFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
|
---|
242 | const char *pszManifestEntry);
|
---|
243 | void i_importDecompressFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
|
---|
244 | const char *pszManifestEntry);
|
---|
245 | HRESULT i_importCloudImpl(TaskCloud *pTask);
|
---|
246 | /** @} */
|
---|
247 |
|
---|
248 | /** @name Write stuff
|
---|
249 | * @{
|
---|
250 | */
|
---|
251 | HRESULT i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
252 | HRESULT i_writeOPCImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
253 | HRESULT i_writeCloudImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
254 |
|
---|
255 | HRESULT i_writeFS(TaskOVF *pTask);
|
---|
256 | HRESULT i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
|
---|
257 | HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
|
---|
258 | HRESULT i_writeFSOPC(TaskOPC *pTask);
|
---|
259 | HRESULT i_exportCloudImpl(TaskCloud *pTask);
|
---|
260 | HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst);
|
---|
261 | HRESULT i_writeBufferToFile(RTVFSFSSTREAM hVfsFssDst, const char *pszFilename, const void *pvContent, size_t cbContent);
|
---|
262 |
|
---|
263 | struct XMLStack;
|
---|
264 |
|
---|
265 | void i_buildXML(AutoWriteLockBase& writeLock,
|
---|
266 | xml::Document &doc,
|
---|
267 | XMLStack &stack,
|
---|
268 | const Utf8Str &strPath,
|
---|
269 | ovf::OVFVersion_T enFormat);
|
---|
270 | void i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
|
---|
271 | xml::ElementNode &elmToAddVirtualSystemsTo,
|
---|
272 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
|
---|
273 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
274 | ovf::OVFVersion_T enFormat,
|
---|
275 | XMLStack &stack);
|
---|
276 | /** @} */
|
---|
277 |
|
---|
278 | friend class Machine;
|
---|
279 | friend class Certificate;
|
---|
280 | };
|
---|
281 |
|
---|
282 | void i_parseURI(Utf8Str strUri, LocationInfo &locInfo);
|
---|
283 |
|
---|
284 | struct VirtualSystemDescriptionEntry
|
---|
285 | {
|
---|
286 | uint32_t ulIndex; ///< zero-based index of this entry within array
|
---|
287 | VirtualSystemDescriptionType_T type; ///< type of this entry
|
---|
288 | Utf8Str strRef; ///< reference number (hard disk controllers only)
|
---|
289 | Utf8Str strOvf; ///< original OVF value (type-dependent)
|
---|
290 | Utf8Str strVBoxSuggested; ///< configuration value (type-dependent); original value suggested by interpret()
|
---|
291 | Utf8Str strVBoxCurrent; ///< configuration value (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
292 | Utf8Str strExtraConfigSuggested; ///< extra configuration key=value strings (type-dependent); original value suggested by interpret()
|
---|
293 | Utf8Str strExtraConfigCurrent; ///< extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
294 |
|
---|
295 | uint32_t ulSizeMB; ///< hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
|
---|
296 | bool skipIt; ///< used during export to skip some parts if it's needed
|
---|
297 | };
|
---|
298 |
|
---|
299 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
300 | public VirtualSystemDescriptionWrap
|
---|
301 | {
|
---|
302 | friend class Appliance;
|
---|
303 |
|
---|
304 | public:
|
---|
305 |
|
---|
306 | DECLARE_COMMON_CLASS_METHODS(VirtualSystemDescription)
|
---|
307 |
|
---|
308 | HRESULT FinalConstruct();
|
---|
309 | void FinalRelease();
|
---|
310 |
|
---|
311 | HRESULT init();
|
---|
312 | void uninit();
|
---|
313 |
|
---|
314 | /* public methods only for internal purposes */
|
---|
315 | void i_addEntry(VirtualSystemDescriptionType_T aType,
|
---|
316 | const Utf8Str &strRef,
|
---|
317 | const Utf8Str &aOvfValue,
|
---|
318 | const Utf8Str &aVBoxValue,
|
---|
319 | uint32_t ulSizeMB = 0,
|
---|
320 | const Utf8Str &strExtraConfig = "");
|
---|
321 |
|
---|
322 | std::list<VirtualSystemDescriptionEntry*> i_findByType(VirtualSystemDescriptionType_T aType);
|
---|
323 | const VirtualSystemDescriptionEntry* i_findControllerFromID(const Utf8Str &id);
|
---|
324 | const VirtualSystemDescriptionEntry* i_findByIndex(const uint32_t aIndex);
|
---|
325 |
|
---|
326 | void i_importVBoxMachineXML(const xml::ElementNode &elmMachine);
|
---|
327 | const settings::MachineConfigFile* i_getMachineConfig() const;
|
---|
328 |
|
---|
329 | /* private instance data */
|
---|
330 | private:
|
---|
331 |
|
---|
332 | // wrapped IVirtualSystemDescription properties
|
---|
333 | HRESULT getCount(ULONG *aCount);
|
---|
334 |
|
---|
335 | // wrapped IVirtualSystemDescription methods
|
---|
336 | HRESULT getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
|
---|
337 | std::vector<com::Utf8Str> &aRefs,
|
---|
338 | std::vector<com::Utf8Str> &aOVFValues,
|
---|
339 | std::vector<com::Utf8Str> &aVBoxValues,
|
---|
340 | std::vector<com::Utf8Str> &aExtraConfigValues);
|
---|
341 | HRESULT getDescriptionByType(VirtualSystemDescriptionType_T aType,
|
---|
342 | std::vector<VirtualSystemDescriptionType_T> &aTypes,
|
---|
343 | std::vector<com::Utf8Str> &aRefs,
|
---|
344 | std::vector<com::Utf8Str> &aOVFValues,
|
---|
345 | std::vector<com::Utf8Str> &aVBoxValues,
|
---|
346 | std::vector<com::Utf8Str> &aExtraConfigValues);
|
---|
347 | HRESULT getValuesByType(VirtualSystemDescriptionType_T aType,
|
---|
348 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
349 | std::vector<com::Utf8Str> &aValues);
|
---|
350 | HRESULT setFinalValues(const std::vector<BOOL> &aEnabled,
|
---|
351 | const std::vector<com::Utf8Str> &aVBoxValues,
|
---|
352 | const std::vector<com::Utf8Str> &aExtraConfigValues);
|
---|
353 | HRESULT addDescription(VirtualSystemDescriptionType_T aType,
|
---|
354 | const com::Utf8Str &aVBoxValue,
|
---|
355 | const com::Utf8Str &aExtraConfigValue);
|
---|
356 | HRESULT removeDescriptionByType(VirtualSystemDescriptionType_T aType);
|
---|
357 | void i_removeByType(VirtualSystemDescriptionType_T aType);
|
---|
358 |
|
---|
359 | struct Data;
|
---|
360 | Data *m;
|
---|
361 |
|
---|
362 | friend class Machine;
|
---|
363 | };
|
---|
364 |
|
---|
365 | #endif /* !MAIN_INCLUDED_ApplianceImpl_h */
|
---|
366 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|