VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImplPrivate.h@ 78402

Last change on this file since 78402 was 76562, checked in by vboxsync, 6 years ago

Main: Use MAIN_INCLUDED_ and MAIN_INCLUDED_SRC_ as header guard prefixes with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.6 KB
Line 
1/* $Id: ApplianceImplPrivate.h 76562 2019-01-01 03:22:50Z vboxsync $ */
2/** @file
3 * VirtualBox Appliance private data definitions
4 */
5
6/*
7 * Copyright (C) 2006-2019 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_ApplianceImplPrivate_h
19#define MAIN_INCLUDED_ApplianceImplPrivate_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24
25class VirtualSystemDescription;
26
27#include "ovfreader.h"
28#include "SecretKeyStore.h"
29#include "ThreadTask.h"
30#include "CertificateImpl.h"
31#include <map>
32#include <vector>
33#include <iprt/manifest.h>
34#include <iprt/vfs.h>
35#include <iprt/crypto/x509.h>
36
37////////////////////////////////////////////////////////////////////////////////
38//
39// Appliance data definition
40//
41////////////////////////////////////////////////////////////////////////////////
42
43namespace settings
44{
45 struct AttachedDevice;
46}
47
48typedef std::pair<Utf8Str, Utf8Str> STRPAIR;
49
50typedef std::vector<com::Guid> GUIDVEC;
51
52/* Describe a location for the import/export. The location could be a file on a
53 * local hard disk or a remote target based on the supported inet protocols. */
54struct LocationInfo
55{
56 LocationInfo()
57 : storageType(VFSType_File) {}
58 VFSType_T storageType; /* Which type of storage should be handled */
59 Utf8Str strProvider; /* cloud provider name in case of export/import to Cloud */
60 Utf8Str strPath; /* File path for the import/export */
61 Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
62 Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
63 Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
64};
65
66// opaque private instance data of Appliance class
67struct Appliance::Data
68{
69 enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
70 enum digest_T {SHA1, SHA256};
71
72 Data()
73 : state(ApplianceIdle)
74 , fDigestTypes(0)
75 , hOurManifest(NIL_RTMANIFEST)
76 , fManifest(true)
77 , fDeterminedDigestTypes(false)
78 , hTheirManifest(NIL_RTMANIFEST)
79 , hMemFileTheirManifest(NIL_RTVFSFILE)
80 , fSignerCertLoaded(false)
81 , fCertificateIsSelfSigned(false)
82 , fSignatureValid(false)
83 , fCertificateValid(false)
84 , fCertificateMissingPath(true)
85 , fCertificateValidTime(false)
86 , pbSignedDigest(NULL)
87 , cbSignedDigest(0)
88 , enmSignedDigestType(RTDIGESTTYPE_INVALID)
89 , fExportISOImages(false)
90 , pReader(NULL)
91 , ulWeightForXmlOperation(0)
92 , ulWeightForManifestOperation(0)
93 , ulTotalDisksMB(0)
94 , cDisks(0)
95 , m_cPwProvided(0)
96 {
97 }
98
99 ~Data()
100 {
101 if (pReader)
102 {
103 delete pReader;
104 pReader = NULL;
105 }
106 resetReadData();
107 }
108
109 /**
110 * Resets data used by read.
111 */
112 void resetReadData(void)
113 {
114 strOvfManifestEntry.setNull();
115 if (hOurManifest != NIL_RTMANIFEST)
116 {
117 RTManifestRelease(hOurManifest);
118 hOurManifest = NIL_RTMANIFEST;
119 }
120 if (hTheirManifest != NIL_RTMANIFEST)
121 {
122 RTManifestRelease(hTheirManifest);
123 hTheirManifest = NIL_RTMANIFEST;
124 }
125 if (hMemFileTheirManifest)
126 {
127 RTVfsFileRelease(hMemFileTheirManifest);
128 hMemFileTheirManifest = NIL_RTVFSFILE;
129 }
130 if (pbSignedDigest)
131 {
132 RTMemFree(pbSignedDigest);
133 pbSignedDigest = NULL;
134 cbSignedDigest = 0;
135 }
136 if (fSignerCertLoaded)
137 {
138 RTCrX509Certificate_Delete(&SignerCert);
139 fSignerCertLoaded = false;
140 }
141 enmSignedDigestType = RTDIGESTTYPE_INVALID;
142 fCertificateIsSelfSigned = false;
143 fSignatureValid = false;
144 fCertificateValid = false;
145 fCertificateMissingPath = true;
146 fCertificateValidTime = false;
147 fDeterminedDigestTypes = false;
148 fDigestTypes = RTMANIFEST_ATTR_SHA1 | RTMANIFEST_ATTR_SHA256 | RTMANIFEST_ATTR_SHA512;
149 ptrCertificateInfo.setNull();
150 strCertError.setNull();
151 }
152
153 ApplianceState state;
154
155 LocationInfo locInfo; // location info for the currently processed OVF
156 /** The digests types to calculate (RTMANIFEST_ATTR_XXX) for the manifest.
157 * This will be a single value when exporting. Zero, one or two. */
158 uint32_t fDigestTypes;
159 /** Manifest created while importing or exporting. */
160 RTMANIFEST hOurManifest;
161
162 /** @name Write data
163 * @{ */
164 bool fManifest; // Create a manifest file on export
165 /** @} */
166
167 /** @name Read data
168 * @{ */
169 /** The manifest entry name of the OVF-file. */
170 Utf8Str strOvfManifestEntry;
171
172 /** Set if we've parsed the manifest and determined the digest types. */
173 bool fDeterminedDigestTypes;
174
175 /** Manifest read in during read() and kept around for later verification. */
176 RTMANIFEST hTheirManifest;
177 /** Memorized copy of the manifest file for signature checking purposes. */
178 RTVFSFILE hMemFileTheirManifest;
179
180 /** The signer certificate from the signature file (.cert).
181 * This will be used in the future provide information about the signer via
182 * the API. */
183 RTCRX509CERTIFICATE SignerCert;
184 /** Set if the SignerCert member contains usable data. */
185 bool fSignerCertLoaded;
186 /** Cached RTCrX509Validity_IsValidAtTimeSpec result set by read(). */
187 bool fCertificateIsSelfSigned;
188 /** Set by read() if pbSignedDigest verified correctly against SignerCert. */
189 bool fSignatureValid;
190 /** Set by read() when the SignerCert checked out fine. */
191 bool fCertificateValid;
192 /** Set by read() when the SignerCert certificate path couldn't be built. */
193 bool fCertificateMissingPath;
194 /** Set by read() when the SignerCert (+path) is valid in the temporal sense. */
195 bool fCertificateValidTime;
196 /** For keeping certificate error messages we delay from read() to import(). */
197 Utf8Str strCertError;
198 /** The signed digest of the manifest. */
199 uint8_t *pbSignedDigest;
200 /** The size of the signed digest. */
201 size_t cbSignedDigest;
202 /** The digest type used to sign the manifest. */
203 RTDIGESTTYPE enmSignedDigestType;
204 /** The certificate info object. This is NULL if no signature and
205 * successfully loaded certificate. */
206 ComObjPtr<Certificate> ptrCertificateInfo;
207 /** @} */
208
209 bool fExportISOImages;// when 1 the ISO images are exported
210
211 RTCList<ImportOptions_T> optListImport;
212 RTCList<ExportOptions_T> optListExport;
213
214 ovf::OVFReader *pReader;
215
216 std::list< ComObjPtr<VirtualSystemDescription> >
217 virtualSystemDescriptions;
218
219 std::list<Utf8Str> llWarnings;
220
221 ULONG ulWeightForXmlOperation;
222 ULONG ulWeightForManifestOperation;
223 ULONG ulTotalDisksMB;
224 ULONG cDisks;
225
226 std::list<Guid> llGuidsMachinesCreated;
227
228 /** Sequence of password identifiers to encrypt disk images during export. */
229 std::vector<com::Utf8Str> m_vecPasswordIdentifiers;
230 /** Map to get all medium identifiers assoicated with a given password identifier. */
231 std::map<com::Utf8Str, GUIDVEC> m_mapPwIdToMediumIds;
232 /** Secret key store used to hold the passwords during export. */
233 SecretKeyStore *m_pSecretKeyStore;
234 /** Number of passwords provided. */
235 uint32_t m_cPwProvided;
236};
237
238struct Appliance::XMLStack
239{
240 std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
241 std::list<Utf8Str> mapDiskSequence;
242 std::list<Utf8Str> mapDiskSequenceForOneVM;//temporary keeps all disks attached to one exported VM
243 std::map<Utf8Str, bool> mapNetworks;
244};
245
246class Appliance::TaskOVF : public ThreadTask
247{
248public:
249 enum TaskType
250 {
251 Read,
252 Import,
253 Write
254 };
255
256 TaskOVF(Appliance *aThat,
257 TaskType aType,
258 LocationInfo aLocInfo,
259 ComObjPtr<Progress> &aProgress)
260 : ThreadTask("TaskOVF"),
261 pAppliance(aThat),
262 taskType(aType),
263 locInfo(aLocInfo),
264 pProgress(aProgress),
265 enFormat(ovf::OVFVersion_unknown),
266 rc(S_OK)
267 {
268 switch (taskType)
269 {
270 case TaskOVF::Read: m_strTaskName = "ApplRead"; break;
271 case TaskOVF::Import: m_strTaskName = "ApplImp"; break;
272 case TaskOVF::Write: m_strTaskName = "ApplWrit"; break;
273 default: m_strTaskName = "ApplTask"; break;
274 }
275 }
276
277 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
278
279 Appliance *pAppliance;
280 TaskType taskType;
281 const LocationInfo locInfo;
282 ComObjPtr<Progress> pProgress;
283
284 ovf::OVFVersion_T enFormat;
285
286 HRESULT rc;
287
288 void handler()
289 {
290 Appliance::i_importOrExportThreadTask(this);
291 }
292};
293
294class Appliance::TaskOPC : public ThreadTask
295{
296public:
297 enum TaskType
298 {
299 Export
300 };
301
302 TaskOPC(Appliance *aThat,
303 TaskType aType,
304 LocationInfo aLocInfo,
305 ComObjPtr<Progress> &aProgress)
306 : ThreadTask("TaskOPC"),
307 pAppliance(aThat),
308 taskType(aType),
309 locInfo(aLocInfo),
310 pProgress(aProgress),
311 rc(S_OK)
312 {
313 m_strTaskName = "OPCExpt";
314 }
315
316 ~TaskOPC()
317 {
318 }
319
320 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
321
322 Appliance *pAppliance;
323 TaskType taskType;
324 const LocationInfo locInfo;
325 ComObjPtr<Progress> pProgress;
326
327 HRESULT rc;
328
329 void handler()
330 {
331 Appliance::i_exportOPCThreadTask(this);
332 }
333};
334
335
336class Appliance::TaskCloud : public ThreadTask
337{
338public:
339 enum TaskType
340 {
341 Export
342 };
343
344 TaskCloud(Appliance *aThat,
345 TaskType aType,
346 LocationInfo aLocInfo,
347 ComObjPtr<Progress> &aProgress)
348 : ThreadTask("TaskCloud"),
349 pAppliance(aThat),
350 taskType(aType),
351 locInfo(aLocInfo),
352 pProgress(aProgress),
353 rc(S_OK)
354 {
355 m_strTaskName = "CloudExpt";
356 }
357
358 ~TaskCloud()
359 {
360 }
361
362 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
363
364 Appliance *pAppliance;
365 TaskType taskType;
366 const LocationInfo locInfo;
367 ComObjPtr<Progress> pProgress;
368
369 HRESULT rc;
370
371 void handler()
372 {
373 Appliance::i_exportCloudThreadTask(this);
374 }
375};
376
377struct MyHardDiskAttachment
378{
379 ComPtr<IMachine> pMachine;
380 Utf8Str controllerName;
381 int32_t lControllerPort; // 0-29 for SATA
382 int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
383};
384
385/**
386 * Used by Appliance::importMachineGeneric() to store
387 * input parameters and rollback information.
388 */
389struct Appliance::ImportStack
390{
391 // input pointers
392 const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
393 Utf8Str strSourceDir; // directory where source files reside
394 const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
395 ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
396
397 // input parameters from VirtualSystemDescriptions
398 Utf8Str strNameVBox; // VM name
399 Utf8Str strSettingsFilename; // Absolute path to VM config file
400 Utf8Str strMachineFolder; // Absolute path to VM folder (derived from strSettingsFilename)
401 Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
402 Utf8Str strPrimaryGroup; // VM primary group as string
403 Utf8Str strDescription;
404 uint32_t cCPUs; // CPU count
405 bool fForceHWVirt; // if true, we force enabling hardware virtualization
406 bool fForceIOAPIC; // if true, we force enabling the IOAPIC
407 uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
408#ifdef VBOX_WITH_USB
409 bool fUSBEnabled;
410#endif
411 Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
412 // representation of the audio adapter (should always be "0" for AC97 presently)
413
414 // session (not initially created)
415 ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
416 bool fSessionOpen; // true if the pSession is currently open and needs closing
417
418 /** @name File access related stuff (TAR stream)
419 * @{ */
420 /** OVA file system stream handle. NIL if not OVA. */
421 RTVFSFSSTREAM hVfsFssOva;
422 /** OVA lookahead I/O stream object. */
423 RTVFSIOSTREAM hVfsIosOvaLookAhead;
424 /** OVA lookahead I/O stream object name. */
425 char *pszOvaLookAheadName;
426 /** @} */
427
428 // a list of images that we created/imported; this is initially empty
429 // and will be cleaned up on errors
430 std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
431 std::map<Utf8Str , Utf8Str> mapNewUUIDsToOriginalUUIDs;
432
433 ImportStack(const LocationInfo &aLocInfo,
434 const ovf::DiskImagesMap &aMapDisks,
435 ComObjPtr<Progress> &aProgress,
436 RTVFSFSSTREAM aVfsFssOva)
437 : locInfo(aLocInfo),
438 mapDisks(aMapDisks),
439 pProgress(aProgress),
440 cCPUs(1),
441 fForceHWVirt(false),
442 fForceIOAPIC(false),
443 ulMemorySizeMB(0),
444 fSessionOpen(false),
445 hVfsFssOva(aVfsFssOva),
446 hVfsIosOvaLookAhead(NIL_RTVFSIOSTREAM),
447 pszOvaLookAheadName(NULL)
448 {
449 if (hVfsFssOva != NIL_RTVFSFSSTREAM)
450 RTVfsFsStrmRetain(hVfsFssOva);
451
452 // disk images have to be on the same place as the OVF file. So
453 // strip the filename out of the full file path
454 strSourceDir = aLocInfo.strPath;
455 strSourceDir.stripFilename();
456 }
457
458 ~ImportStack()
459 {
460 if (hVfsFssOva != NIL_RTVFSFSSTREAM)
461 {
462 RTVfsFsStrmRelease(hVfsFssOva);
463 hVfsFssOva = NIL_RTVFSFSSTREAM;
464 }
465 if (hVfsIosOvaLookAhead != NIL_RTVFSIOSTREAM)
466 {
467 RTVfsIoStrmRelease(hVfsIosOvaLookAhead);
468 hVfsIosOvaLookAhead = NIL_RTVFSIOSTREAM;
469 }
470 if (pszOvaLookAheadName)
471 {
472 RTStrFree(pszOvaLookAheadName);
473 pszOvaLookAheadName = NULL;
474 }
475 }
476
477 HRESULT restoreOriginalUUIDOfAttachedDevice(settings::MachineConfigFile *config);
478 HRESULT saveOriginalUUIDOfAttachedDevice(settings::AttachedDevice &device,
479 const Utf8Str &newlyUuid);
480 RTVFSIOSTREAM claimOvaLookAHead(void);
481
482};
483
484////////////////////////////////////////////////////////////////////////////////
485//
486// VirtualSystemDescription data definition
487//
488////////////////////////////////////////////////////////////////////////////////
489
490struct VirtualSystemDescription::Data
491{
492 std::vector<VirtualSystemDescriptionEntry>
493 maDescriptions; // item descriptions
494
495 ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
496
497 settings::MachineConfigFile
498 *pConfig; // machine config created from <vbox:Machine> element if found (import only)
499};
500
501////////////////////////////////////////////////////////////////////////////////
502//
503// Internal helpers
504//
505////////////////////////////////////////////////////////////////////////////////
506
507void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
508
509ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode);
510
511Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
512
513
514#endif /* !MAIN_INCLUDED_ApplianceImplPrivate_h */
515
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette