VirtualBox

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

Last change on this file since 74526 was 73929, checked in by vboxsync, 6 years ago

OCI: commit OCI code as-is. Doesn't yet compile in extpack but should
not break the normal build.

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