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