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