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