VirtualBox

Changeset 59621 in vbox for trunk/src/VBox/Main/include


Ignore:
Timestamp:
Feb 10, 2016 12:51:35 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105460
Message:

ApplianceImplImport.cpp,++: Pushed the IPRT VFS stuff futher down, only going to the VD I/O wrappers when start getting down into the media code during import. Reworked the OVA releated import code to skip files it doesn't care about (like message resource xml files which we don't implement) and not be picky about which order files the OVF, MF and CERT files come in (todo: make sure it isn't picky about the order of disks either). Read the manifest and certificate file during the read() method.

Location:
trunk/src/VBox/Main/include
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r59586 r59621  
    157157    HRESULT i_readFSOVF(TaskOVF *pTask);
    158158    HRESULT i_readFSOVA(TaskOVF *pTask);
    159     HRESULT i_readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
     159    HRESULT i_readOVFFile(TaskOVF *pTask, RTVFSIOSTREAM hIosOvf, const char *pszManifestEntry);
     160    HRESULT i_readManifestFile(TaskOVF *pTask, RTVFSIOSTREAM hIosMf, const char *pszSubFileNm);
     161    HRESULT i_readSignatureFile(TaskOVF *pTask, RTVFSIOSTREAM hIosCert, const char *pszSubFileNm);
     162    HRESULT i_readTailProcessing(TaskOVF *pTask);
    160163    /** @}  */
    161164
     
    166169
    167170    HRESULT i_importFS(TaskOVF *pTask);
    168     HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
    169     HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
    170 
    171     HRESULT i_readFileToBuf(const Utf8Str &strFile,
    172                             void **ppvBuf,
    173                             size_t *pcbSize,
    174                             bool fCreateDigest,
    175                             PVDINTERFACEIO pCallbacks,
    176                             PSHASTORAGE pStorage);
    177     HRESULT i_readTarFileToBuf(struct FSSRDONLYINTERFACEIO *pTarIo,
    178                                const Utf8Str &strFile,
    179                                void **ppvBuf,
    180                                size_t *pcbSize,
    181                                bool fCreateDigest,
    182                                PVDINTERFACEIO pCallbacks,
    183                                PSHASTORAGE pStorage);
    184     HRESULT i_verifyManifestFile(const Utf8Str &strFile, ImportStack &stack,
    185                                  RTVFSFILE hManifestVfsFile, const char *pszOvfEntry);
    186 
    187     HRESULT i_verifyCertificateFile(void *pvBuf, size_t cbSize, PSHASTORAGE pStorage);
     171    HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
     172    HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
     173    HRESULT i_importDoIt(TaskOVF *pTask, AutoWriteLockBase &rWriteLock, RTVFSFSSTREAM hVfsFssOva = NIL_RTVFSFSSTREAM);
     174
     175    HRESULT i_verifyManifestFile(ImportStack &stack);
    188176
    189177    void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
     
    196184                              Utf8Str *strTargetPath,
    197185                              ComObjPtr<Medium> &pTargetHD,
    198                               ImportStack &stack,
    199                               PVDINTERFACEIO pCallbacks,
    200                               PSHASTORAGE pStorage);
     186                              ImportStack &stack);
    201187
    202188    void i_importMachineGeneric(const ovf::VirtualSystem &vsysThis,
    203189                                ComObjPtr<VirtualSystemDescription> &vsdescThis,
    204190                                ComPtr<IMachine> &pNewMachine,
    205                                 ImportStack &stack,
    206                                 PVDINTERFACEIO pCallbacks,
    207                                 PSHASTORAGE pStorage);
     191                                ImportStack &stack);
    208192    void i_importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
    209193                             ComPtr<IMachine> &pNewMachine,
    210                              ImportStack &stack,
    211                              PVDINTERFACEIO pCallbacks,
    212                              PSHASTORAGE pStorage);
    213     void i_importMachines(ImportStack &stack,
    214                           PVDINTERFACEIO pCallbacks,
    215                           PSHASTORAGE pStorage);
    216 
    217     HRESULT i_preCheckImageAvailability(PSHASTORAGE pSHAStorage,
    218                                         RTCString &availableImage);
     194                             ImportStack &stack);
     195    void i_importMachines(ImportStack &stack);
     196
     197    HRESULT i_preCheckImageAvailability(ImportStack &stack);
     198    bool    i_importEnsureOvaLookAhead(ImportStack &stack);
     199    RTVFSIOSTREAM i_importSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry);
     200    RTVFSIOSTREAM i_importOpenSourceFile(ImportStack &stack, Utf8Str const &rstrSrcPath, const char *pszManifestEntry);
     201    HRESULT i_importCreateAndWriteDestinationFile(Utf8Str const &rstrDstPath,
     202                                                  RTVFSIOSTREAM hVfsIosSrc, Utf8Str const &rstrSrcLogNm);
     203
     204    void    i_importCopyFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
     205                             const char *pszManifestEntry);
     206    void    i_importDecompressFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
     207                                   const char *pszManifestEntry);
    219208    /** @} */
    220209
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r59555 r59621  
    2828#include <iprt/manifest.h>
    2929#include <iprt/vfs.h>
     30#include <iprt/crypto/x509.h>
    3031
    3132////////////////////////////////////////////////////////////////////////////////
     
    6061    Data()
    6162      : state(ApplianceIdle)
     63      , fDigestTypes(0)
     64      , hOurManifest(NIL_RTMANIFEST)
    6265      , fManifest(true)
    6366      , fSha256(false)
     67      , fDeterminedDigestTypes(false)
     68      , hTheirManifest(NIL_RTMANIFEST)
     69      , hMemFileTheirManifest(NIL_RTVFSFILE)
     70      , fSignerCertLoaded(false)
     71      , fSignatureValid(false)
     72      , pbSignedDigest(NULL)
     73      , cbSignedDigest(0)
     74      , enmSignedDigestType(RTDIGESTTYPE_INVALID)
    6475      , fExportISOImages(false)
    6576      , pReader(NULL)
     
    7990            pReader = NULL;
    8091        }
     92        resetReadData();
     93    }
     94
     95    /**
     96     * Resets data used by read.
     97     */
     98    void resetReadData(void)
     99    {
     100        strOvfManifestEntry.setNull();
     101        if (hOurManifest != NIL_RTMANIFEST)
     102        {
     103            RTManifestRelease(hOurManifest);
     104            hOurManifest = NIL_RTMANIFEST;
     105        }
     106        if (hTheirManifest != NIL_RTMANIFEST)
     107        {
     108            RTManifestRelease(hTheirManifest);
     109            hTheirManifest = NIL_RTMANIFEST;
     110        }
     111        if (hMemFileTheirManifest)
     112        {
     113            RTVfsFileRelease(hMemFileTheirManifest);
     114            hMemFileTheirManifest = NIL_RTVFSFILE;
     115        }
     116        if (pbSignedDigest)
     117        {
     118            RTMemFree(pbSignedDigest);
     119            pbSignedDigest = NULL;
     120            cbSignedDigest = 0;
     121        }
     122        if (fSignerCertLoaded)
     123        {
     124            RTCrX509Certificate_Delete(&SignerCert);
     125            fSignerCertLoaded = false;
     126        }
     127        enmSignedDigestType    = RTDIGESTTYPE_INVALID;
     128        fSignatureValid        = false;
     129        fDeterminedDigestTypes = false;
     130        fDigestTypes           = RTMANIFEST_ATTR_SHA1 | RTMANIFEST_ATTR_SHA256;
    81131    }
    82132
     
    84134
    85135    LocationInfo        locInfo;        // location info for the currently processed OVF
     136    /** The digests types to calculate (RTMANIFEST_ATTR_XXX) for the manifest.
     137     * This will be a single value when exporting.  Zero, one or two.  */
     138    uint32_t            fDigestTypes;
     139    /** Manifest created while importing or exporting. */
     140    RTMANIFEST          hOurManifest;
     141
     142    /** @name Write data
     143     * @{ */
    86144    bool                fManifest;      // Create a manifest file on export
    87145    bool                fSha256;        // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)
    88     Utf8Str             strOVFSHADigest;//SHA digest of OVf file. It is stored here after reading OVF file (before import)
     146    /** @} */
     147
     148    /** @name Read data
     149     *  @{ */
     150    /** The manifest entry name of the OVF-file. */
     151    Utf8Str             strOvfManifestEntry;
     152
     153    /** Set if we've parsed the manifest and determined the digest types. */
     154    bool                fDeterminedDigestTypes;
     155
     156    /** Manifest read in during read() and kept around for later verification. */
     157    RTMANIFEST          hTheirManifest;
     158    /** Memorized copy of the manifest file for signature checking purposes. */
     159    RTVFSFILE           hMemFileTheirManifest;
     160
     161    /** The signer certificate from the signature fiel (.cert).
     162     * This will be used in the future provide information about the signer via
     163     * the API. */
     164    RTCRX509CERTIFICATE SignerCert;
     165    /** Set if the SignerCert member contains usable data. */
     166    bool                fSignerCertLoaded;
     167    /** Set by read() if it found a certificate and the signature is fine. */
     168    bool                fSignatureValid;
     169    /** The signed digest of the manifest. */
     170    uint8_t            *pbSignedDigest;
     171    /** The size of the signed digest. */
     172    size_t              cbSignedDigest;
     173    /** The digest type used to sign the manifest. */
     174    RTDIGESTTYPE        enmSignedDigestType;
     175    /** @} */
    89176
    90177    bool                fExportISOImages;// when 1 the ISO images are exported
    91     bool                fX509;// wether X509 is used or not
    92178
    93179    RTCList<ImportOptions_T> optListImport;
     
    211297    bool                            fSessionOpen;       // true if the pSession is currently open and needs closing
    212298
     299    /** @name File access related stuff (TAR stream)
     300     *  @{  */
     301    /** OVA file system stream handle. NIL if not OVA.  */
     302    RTVFSFSSTREAM                   hVfsFssOva;
     303    /** OVA lookahead I/O stream object. */
     304    RTVFSIOSTREAM                   hVfsIosOvaLookAhead;
     305    /** OVA lookahead I/O stream object name. */
     306    char                           *pszOvaLookAheadName;
     307    /** @} */
     308
    213309    // a list of images that we created/imported; this is initially empty
    214310    // and will be cleaned up on errors
    215311    std::list<MyHardDiskAttachment> llHardDiskAttachments;      // disks that were attached
    216     RTMANIFEST                      hSrcDisksManifest;  /**< Manifest we build while processing/reading the source disks. */
    217     std::map<Utf8Str , Utf8Str> mapNewUUIDsToOriginalUUIDs;
     312    std::map<Utf8Str , Utf8Str>     mapNewUUIDsToOriginalUUIDs;
    218313
    219314    ImportStack(const LocationInfo &aLocInfo,
    220315                const ovf::DiskImagesMap &aMapDisks,
    221                 ComObjPtr<Progress> &aProgress)
     316                ComObjPtr<Progress> &aProgress,
     317                RTVFSFSSTREAM aVfsFssOva)
    222318        : locInfo(aLocInfo),
    223319          mapDisks(aMapDisks),
     
    228324          ulMemorySizeMB(0),
    229325          fSessionOpen(false),
    230           hSrcDisksManifest(NIL_RTMANIFEST)
    231     {
     326          hVfsFssOva(aVfsFssOva),
     327          hVfsIosOvaLookAhead(NIL_RTVFSIOSTREAM),
     328          pszOvaLookAheadName(NULL)
     329    {
     330        if (hVfsFssOva != NIL_RTVFSFSSTREAM)
     331            RTVfsFsStrmRetain(hVfsFssOva);
     332
    232333        // disk images have to be on the same place as the OVF file. So
    233334        // strip the filename out of the full file path
     
    238339    ~ImportStack()
    239340    {
    240         if (hSrcDisksManifest != NIL_RTMANIFEST)
    241         {
    242             RTManifestRelease(hSrcDisksManifest);
    243             hSrcDisksManifest = NIL_RTMANIFEST;
     341        if (hVfsFssOva != NIL_RTVFSFSSTREAM)
     342        {
     343            RTVfsFsStrmRelease(hVfsFssOva);
     344            hVfsFssOva = NIL_RTVFSFSSTREAM;
     345        }
     346        if (hVfsIosOvaLookAhead != NIL_RTVFSIOSTREAM)
     347        {
     348            RTVfsIoStrmRelease(hVfsIosOvaLookAhead);
     349            hVfsIosOvaLookAhead = NIL_RTVFSIOSTREAM;
     350        }
     351        if (pszOvaLookAheadName)
     352        {
     353            RTStrFree(pszOvaLookAheadName);
     354            pszOvaLookAheadName = NULL;
    244355        }
    245356    }
     
    248359    HRESULT saveOriginalUUIDOfAttachedDevice(settings::AttachedDevice &device,
    249360                                                  const Utf8Str &newlyUuid);
     361    RTVFSIOSTREAM claimOvaLookAHead(void);
     362
    250363};
    251364
     
    292405PVDINTERFACEIO tarWriterCreateInterface(void);
    293406
    294 /** Pointer to the instance data for the fssRdOnly_ methods. */
    295 typedef struct FSSRDONLYINTERFACEIO *PFSSRDONLYINTERFACEIO;
    296 
    297 int  fssRdOnlyCreateInterfaceForTarFile(const char *pszFilename, PFSSRDONLYINTERFACEIO *pTarIo);
    298 void fssRdOnlyDestroyInterface(PFSSRDONLYINTERFACEIO pFssIo);
    299 int  fssRdOnlyGetCurrentName(PFSSRDONLYINTERFACEIO pFssIo, const char **ppszName);
    300 bool fssRdOnlyEqualsCurrentFilename(PFSSRDONLYINTERFACEIO pFssIo, com::Utf8Str const &rstrFilename);
    301 int  fssRdOnlyMemorizeCurrentAsFile(PFSSRDONLYINTERFACEIO pFssIo, PRTVFSFILE phVfsFile);
    302 int  fssRdOnlySkipCurrent(PFSSRDONLYINTERFACEIO pFssIo);
    303 bool fssRdOnlyIsCurrentDirectory(PFSSRDONLYINTERFACEIO pFssIo);
    304 
    305 int readFileIntoBuffer(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser);
    306407int writeBufferToFile(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
    307 int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser);
    308 int copyFileAndCalcShaDigest(const char *pcszSourceFilename, const char *pcszTargetFilename, PVDINTERFACEIO pIfIo, void *pvUser);
     408
    309409#endif // !____H_APPLIANCEIMPLPRIVATE
    310410
  • trunk/src/VBox/Main/include/MediumImpl.h

    r58484 r59621  
    212212                        const ComObjPtr<MediumFormat> &aFormat,
    213213                        MediumVariant_T aVariant,
    214                         PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
     214                        RTVFSIOSTREAM hVfsIosSrc,
    215215                        const ComObjPtr<Medium> &aParent,
    216216                        const ComObjPtr<Progress> &aProgress);
Note: See TracChangeset for help on using the changeset viewer.

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