1 | /* $Id: ApplianceImpl.h 93115 2022-01-01 11:31:46Z 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 |
|
---|
223 | HRESULT i_preCheckImageAvailability(ImportStack &stack);
|
---|
224 | bool i_importEnsureOvaLookAhead(ImportStack &stack);
|
---|
225 | RTVFSIOSTREAM i_importOpenSourceFile(ImportStack &stack, Utf8Str const &rstrSrcPath, const char *pszManifestEntry);
|
---|
226 | HRESULT i_importCreateAndWriteDestinationFile(Utf8Str const &rstrDstPath,
|
---|
227 | RTVFSIOSTREAM hVfsIosSrc, Utf8Str const &rstrSrcLogNm);
|
---|
228 |
|
---|
229 | void i_importCopyFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
|
---|
230 | const char *pszManifestEntry);
|
---|
231 | void i_importDecompressFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
|
---|
232 | const char *pszManifestEntry);
|
---|
233 | HRESULT i_importCloudImpl(TaskCloud *pTask);
|
---|
234 | /** @} */
|
---|
235 |
|
---|
236 | /** @name Write stuff
|
---|
237 | * @{
|
---|
238 | */
|
---|
239 | HRESULT i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
240 | HRESULT i_writeOPCImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
241 | HRESULT i_writeCloudImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
242 |
|
---|
243 | HRESULT i_writeFS(TaskOVF *pTask);
|
---|
244 | HRESULT i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
|
---|
245 | HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
|
---|
246 | HRESULT i_writeFSOPC(TaskOPC *pTask);
|
---|
247 | HRESULT i_exportCloudImpl(TaskCloud *pTask);
|
---|
248 | HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst);
|
---|
249 | HRESULT i_writeBufferToFile(RTVFSFSSTREAM hVfsFssDst, const char *pszFilename, const void *pvContent, size_t cbContent);
|
---|
250 |
|
---|
251 | struct XMLStack;
|
---|
252 |
|
---|
253 | void i_buildXML(AutoWriteLockBase& writeLock,
|
---|
254 | xml::Document &doc,
|
---|
255 | XMLStack &stack,
|
---|
256 | const Utf8Str &strPath,
|
---|
257 | ovf::OVFVersion_T enFormat);
|
---|
258 | void i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
|
---|
259 | xml::ElementNode &elmToAddVirtualSystemsTo,
|
---|
260 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
|
---|
261 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
262 | ovf::OVFVersion_T enFormat,
|
---|
263 | XMLStack &stack);
|
---|
264 | /** @} */
|
---|
265 |
|
---|
266 | friend class Machine;
|
---|
267 | friend class Certificate;
|
---|
268 | };
|
---|
269 |
|
---|
270 | void i_parseURI(Utf8Str strUri, LocationInfo &locInfo);
|
---|
271 |
|
---|
272 | struct VirtualSystemDescriptionEntry
|
---|
273 | {
|
---|
274 | uint32_t ulIndex; ///< zero-based index of this entry within array
|
---|
275 | VirtualSystemDescriptionType_T type; ///< type of this entry
|
---|
276 | Utf8Str strRef; ///< reference number (hard disk controllers only)
|
---|
277 | Utf8Str strOvf; ///< original OVF value (type-dependent)
|
---|
278 | Utf8Str strVBoxSuggested; ///< configuration value (type-dependent); original value suggested by interpret()
|
---|
279 | Utf8Str strVBoxCurrent; ///< configuration value (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
280 | Utf8Str strExtraConfigSuggested; ///< extra configuration key=value strings (type-dependent); original value suggested by interpret()
|
---|
281 | Utf8Str strExtraConfigCurrent; ///< extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
282 |
|
---|
283 | uint32_t ulSizeMB; ///< hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
|
---|
284 | bool skipIt; ///< used during export to skip some parts if it's needed
|
---|
285 | };
|
---|
286 |
|
---|
287 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
288 | public VirtualSystemDescriptionWrap
|
---|
289 | {
|
---|
290 | friend class Appliance;
|
---|
291 |
|
---|
292 | public:
|
---|
293 |
|
---|
294 | DECLARE_COMMON_CLASS_METHODS(VirtualSystemDescription)
|
---|
295 |
|
---|
296 | HRESULT FinalConstruct();
|
---|
297 | void FinalRelease();
|
---|
298 |
|
---|
299 | HRESULT init();
|
---|
300 | void uninit();
|
---|
301 |
|
---|
302 | /* public methods only for internal purposes */
|
---|
303 | void i_addEntry(VirtualSystemDescriptionType_T aType,
|
---|
304 | const Utf8Str &strRef,
|
---|
305 | const Utf8Str &aOvfValue,
|
---|
306 | const Utf8Str &aVBoxValue,
|
---|
307 | uint32_t ulSizeMB = 0,
|
---|
308 | const Utf8Str &strExtraConfig = "");
|
---|
309 |
|
---|
310 | std::list<VirtualSystemDescriptionEntry*> i_findByType(VirtualSystemDescriptionType_T aType);
|
---|
311 | const VirtualSystemDescriptionEntry* i_findControllerFromID(const Utf8Str &id);
|
---|
312 |
|
---|
313 | void i_importVBoxMachineXML(const xml::ElementNode &elmMachine);
|
---|
314 | const settings::MachineConfigFile* i_getMachineConfig() const;
|
---|
315 |
|
---|
316 | /* private instance data */
|
---|
317 | private:
|
---|
318 |
|
---|
319 | // wrapped IVirtualSystemDescription properties
|
---|
320 | HRESULT getCount(ULONG *aCount);
|
---|
321 |
|
---|
322 | // wrapped IVirtualSystemDescription methods
|
---|
323 | HRESULT getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
|
---|
324 | std::vector<com::Utf8Str> &aRefs,
|
---|
325 | std::vector<com::Utf8Str> &aOVFValues,
|
---|
326 | std::vector<com::Utf8Str> &aVBoxValues,
|
---|
327 | std::vector<com::Utf8Str> &aExtraConfigValues);
|
---|
328 | HRESULT getDescriptionByType(VirtualSystemDescriptionType_T aType,
|
---|
329 | std::vector<VirtualSystemDescriptionType_T> &aTypes,
|
---|
330 | std::vector<com::Utf8Str> &aRefs,
|
---|
331 | std::vector<com::Utf8Str> &aOVFValues,
|
---|
332 | std::vector<com::Utf8Str> &aVBoxValues,
|
---|
333 | std::vector<com::Utf8Str> &aExtraConfigValues);
|
---|
334 | HRESULT getValuesByType(VirtualSystemDescriptionType_T aType,
|
---|
335 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
336 | std::vector<com::Utf8Str> &aValues);
|
---|
337 | HRESULT setFinalValues(const std::vector<BOOL> &aEnabled,
|
---|
338 | const std::vector<com::Utf8Str> &aVBoxValues,
|
---|
339 | const std::vector<com::Utf8Str> &aExtraConfigValues);
|
---|
340 | HRESULT addDescription(VirtualSystemDescriptionType_T aType,
|
---|
341 | const com::Utf8Str &aVBoxValue,
|
---|
342 | const com::Utf8Str &aExtraConfigValue);
|
---|
343 | HRESULT removeDescriptionByType(VirtualSystemDescriptionType_T aType);
|
---|
344 | void i_removeByType(VirtualSystemDescriptionType_T aType);
|
---|
345 |
|
---|
346 | struct Data;
|
---|
347 | Data *m;
|
---|
348 |
|
---|
349 | friend class Machine;
|
---|
350 | };
|
---|
351 |
|
---|
352 | #endif /* !MAIN_INCLUDED_ApplianceImpl_h */
|
---|
353 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|