~ubuntu-branches/ubuntu/wily/virtualbox/wily

« back to all changes in this revision

Viewing changes to src/VBox/Main/src-server/ApplianceImplImport.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Felix Geyer, Gianfranco Costamagna
  • Date: 2013-07-21 23:25:44 UTC
  • mfrom: (3.3.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721232544-lwx39bot5tshhd3o
Tags: 4.2.16-dfsg-1
[ Felix Geyer ]
* New upstream release.
  - Fixes CVE-2013-3792: virtio-net host DoS vulnerability. (Closes: #715327)
* Drop 36-python-multiarch.patch and 37-wheezy-kernel-drm.patch,
  fixed upstream.
* Explicity load the vboxguest and vboxsf kernel modules in the
  virtualbox-guest-utils init script.
  This makes sure that shared folders can be mounted. (Closes: #712438)

[ Gianfranco Costamagna ]
* Patch refresh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <VBox/version.h>
48
48
#include <VBox/settings.h>
49
49
 
 
50
#include <set>
 
51
 
50
52
using namespace std;
51
53
 
52
54
////////////////////////////////////////////////////////////////////////////////
1246
1248
            throw setError(E_OUTOFMEMORY);
1247
1249
 
1248
1250
        Utf8Str strMfFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".mf");
 
1251
 
 
1252
        SHASTORAGE storage;
 
1253
        RT_ZERO(storage);
 
1254
 
 
1255
        int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile",
 
1256
                                 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
 
1257
                                 &storage.pVDImageIfaces);
 
1258
        if (RT_FAILURE(vrc))
 
1259
            throw setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc);
 
1260
 
1249
1261
        /* Create the import stack for the rollback on errors. */
1250
1262
        ImportStack stack(pTask->locInfo, m->pReader->m_mapDisks, pTask->pProgress);
1251
1263
 
1252
1264
        if (RTFileExists(strMfFile.c_str()))
1253
1265
        {
1254
 
            SHASTORAGE storage;
1255
 
            RT_ZERO(storage);
1256
 
 
1257
1266
            pShaIo = ShaCreateInterface();
1258
1267
            if (!pShaIo)
1259
1268
                throw setError(E_OUTOFMEMORY);
1260
1269
 
1261
 
            storage.fCreateDigest = true;
1262
 
            int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile",
1263
 
                                     VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
1264
 
                                     &storage.pVDImageIfaces);
1265
 
            if (RT_FAILURE(vrc))
1266
 
                throw setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc);
1267
 
 
1268
1270
            size_t cbMfSize = 0;
1269
1271
            storage.fCreateDigest = true;
1270
1272
            /* Now import the appliance. */
1278
1280
            if (FAILED(rc)) throw rc;
1279
1281
        }
1280
1282
        else
1281
 
            importMachines(stack, pFileIo, NULL);
 
1283
        {
 
1284
            storage.fCreateDigest = false;
 
1285
            importMachines(stack, pFileIo, &storage);
 
1286
        }
1282
1287
    }
1283
1288
    catch (HRESULT rc2)
1284
1289
    {
2395
2400
            if (FAILED(rc)) throw rc;
2396
2401
            stack.fSessionOpen = true;
2397
2402
 
2398
 
            /* Iterate over all given disk images */
2399
 
            list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2400
 
            for (itHD = avsdeHDs.begin();
2401
 
                 itHD != avsdeHDs.end();
2402
 
                 ++itHD)
 
2403
            ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin();
 
2404
            std::set<RTCString>  disksResolvedNames;
 
2405
 
 
2406
            while(oit != stack.mapDisks.end())
2403
2407
            {
2404
 
                VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2405
 
 
2406
 
                // vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
2407
 
                // in the virtual system's disks map under that ID and also in the global images map
2408
 
                ovf::VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef);
2409
 
                // and find the disk from the OVF's disk list
2410
 
                ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
2411
 
                if (    (itVirtualDisk == vsysThis.mapVirtualDisks.end())
2412
 
                     || (itDiskImage == stack.mapDisks.end())
2413
 
                   )
2414
 
                    throw setError(E_FAIL,
2415
 
                                   tr("Internal inconsistency looking up disk image '%s'"),
2416
 
                                   vsdeHD->strRef.c_str());
2417
 
 
2418
 
                const ovf::DiskImage &ovfDiskImage = itDiskImage->second;
2419
 
                const ovf::VirtualDisk &ovfVdisk = itVirtualDisk->second;
 
2408
                if (RTPathHaveExt(oit->second.strHref.c_str()))
 
2409
                {
 
2410
                    /* Figure out which format the user have. */
 
2411
                    char *pszExt = RTPathExt(oit->second.strHref.c_str());
 
2412
                    /* Get the system properties. */
 
2413
                    SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
 
2414
                    ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
 
2415
                    if (trgFormat.isNull())
 
2416
                    {
 
2417
                        ++oit;
 
2418
                        continue;
 
2419
                    }
 
2420
                }
 
2421
 
 
2422
                ovf::DiskImage diCurrent = oit->second;
 
2423
                ovf::VirtualDisksMap::const_iterator itVDisk = vsysThis.mapVirtualDisks.begin();
 
2424
 
 
2425
                VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
 
2426
 
 
2427
                /*
 
2428
                 *
 
2429
                 * Iterate over all given disk images of the virtual system
 
2430
                 * disks description. We need to find the target disk path,
 
2431
                 * which could be changed by the user.
 
2432
                 *
 
2433
                 */
 
2434
                {
 
2435
                    list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
 
2436
                    for (itHD = avsdeHDs.begin();
 
2437
                         itHD != avsdeHDs.end();
 
2438
                         ++itHD)
 
2439
                    {
 
2440
                        VirtualSystemDescriptionEntry *vsdeHD = *itHD;
 
2441
                        if (vsdeHD->strRef == diCurrent.strDiskId)
 
2442
                        {
 
2443
                            vsdeTargetHD = vsdeHD;
 
2444
                            break;
 
2445
                        }
 
2446
                    }
 
2447
                    if (!vsdeTargetHD)
 
2448
                        throw setError(E_FAIL,
 
2449
                                       tr("Internal inconsistency looking up disk image '%s'"),
 
2450
                                       diCurrent.strHref.c_str());
 
2451
 
 
2452
                    //diCurrent.strDiskId contains the disk identifier (e.g. "vmdisk1"), which should exist
 
2453
                    //in the virtual system's disks map under that ID and also in the global images map
 
2454
                    itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId);
 
2455
                    if (itVDisk == vsysThis.mapVirtualDisks.end())
 
2456
                        throw setError(E_FAIL,
 
2457
                                       tr("Internal inconsistency looking up disk image '%s'"),
 
2458
                                       diCurrent.strHref.c_str());
 
2459
                }
 
2460
 
 
2461
                if (strncmp(pStorage->pVDImageIfaces->pszInterfaceName, "Appliance::IOTar", strlen("Appliance::IOTar")) == 0)
 
2462
                {
 
2463
                    /* It means that we possibly have imported the storage earlier on the previous loop steps*/
 
2464
                    std::set<RTCString>::const_iterator h = disksResolvedNames.find(diCurrent.strHref);
 
2465
                    if (h != disksResolvedNames.end())
 
2466
                    {
 
2467
                        /* Yes, disk name was found, we can skip it*/
 
2468
                        ++oit;
 
2469
                        continue;
 
2470
                    }
 
2471
 
 
2472
                    RTCString availableImage(diCurrent.strHref);
 
2473
 
 
2474
                    /*
 
2475
                     *
 
2476
                     * The preliminary check availability of the image
 
2477
                     * This step is useful if image is placed in the OVA (TAR) package
 
2478
                     *
 
2479
                     */
 
2480
 
 
2481
                    RTTAR tar = (RTTAR)pStorage->pVDImageIfaces->pvUser;
 
2482
                    char *pszFilename = 0;
 
2483
 
 
2484
                    int vrc = RTTarCurrentFile(tar, &pszFilename);
 
2485
 
 
2486
                    if (RT_FAILURE(vrc))
 
2487
                    {
 
2488
                        throw setError(VBOX_E_FILE_ERROR,
 
2489
                               tr("Could not open the current file in the archive (%Rrc)"), vrc);
 
2490
                    }
 
2491
                    else
 
2492
                    {
 
2493
                        availableImage = pszFilename;
 
2494
 
 
2495
                        /* current opened file isn't the same as passed one */
 
2496
                        if(availableImage.compare(diCurrent.strHref, Utf8Str::CaseInsensitive) != 0)
 
2497
                        {
 
2498
                            /*
 
2499
                             *
 
2500
                             * availableImage contains the disk file reference (e.g. "disk1.vmdk"), which should exist
 
2501
                             * in the global images map.
 
2502
                             * And find the disk from the OVF's disk list
 
2503
                             *
 
2504
                             */
 
2505
                            {
 
2506
                                ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.begin();
 
2507
                                while (++itDiskImage != stack.mapDisks.end())
 
2508
                                {
 
2509
                                    if (itDiskImage->second.strHref.compare(availableImage, Utf8Str::CaseInsensitive) == 0)
 
2510
                                        break;
 
2511
                                }
 
2512
                                if (itDiskImage == stack.mapDisks.end())
 
2513
                                {
 
2514
                                    throw setError(E_FAIL,
 
2515
                                                   tr("Internal inconsistency looking up disk image '%s'"),
 
2516
                                                   availableImage.c_str());
 
2517
                                }
 
2518
 
 
2519
                                /* replace with a new found disk image */
 
2520
                                diCurrent = *(&itDiskImage->second);
 
2521
                            }
 
2522
 
 
2523
                            /*
 
2524
                             *
 
2525
                             * Again iterate over all given disk images of the virtual system
 
2526
                             * disks description using the found disk image
 
2527
                             *
 
2528
                             */
 
2529
                            {
 
2530
                                list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
 
2531
                                for (itHD = avsdeHDs.begin();
 
2532
                                     itHD != avsdeHDs.end();
 
2533
                                     ++itHD)
 
2534
                                {
 
2535
                                    VirtualSystemDescriptionEntry *vsdeHD = *itHD;
 
2536
                                    if (vsdeHD->strRef == diCurrent.strDiskId)
 
2537
                                    {
 
2538
                                        vsdeTargetHD = vsdeHD;
 
2539
                                        break;
 
2540
                                    }
 
2541
                                }
 
2542
                                if (!vsdeTargetHD)
 
2543
                                    throw setError(E_FAIL,
 
2544
                                                   tr("Internal inconsistency looking up disk image '%s'"),
 
2545
                                                   diCurrent.strHref.c_str());
 
2546
 
 
2547
                                itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId);
 
2548
                                if (itVDisk == vsysThis.mapVirtualDisks.end())
 
2549
                                    throw setError(E_FAIL,
 
2550
                                                   tr("Internal inconsistency looking up disk image '%s'"),
 
2551
                                                   diCurrent.strHref.c_str());
 
2552
                            }
 
2553
                        }
 
2554
                        else
 
2555
                        {
 
2556
                            ++oit;
 
2557
                        }
 
2558
                    }
 
2559
                }
 
2560
                else
 
2561
                {
 
2562
                    /* just continue with normal files*/
 
2563
                    ++oit;
 
2564
                }
 
2565
 
 
2566
                disksResolvedNames.insert(diCurrent.strHref);
 
2567
 
 
2568
                const ovf::VirtualDisk &ovfVdisk = itVDisk->second;
2420
2569
 
2421
2570
                ComObjPtr<Medium> pTargetHD;
2422
 
                importOneDiskImage(ovfDiskImage,
2423
 
                                   vsdeHD->strVboxCurrent,
 
2571
                importOneDiskImage(diCurrent,
 
2572
                                   vsdeTargetHD->strVboxCurrent,
2424
2573
                                   pTargetHD,
2425
2574
                                   stack,
2426
2575
                                   pCallbacks,
2444
2593
                                            mhda.lControllerPort,
2445
2594
                                            mhda.lDevice);
2446
2595
 
2447
 
                Log(("Attaching disk %s to port %d on device %d\n", vsdeHD->strVboxCurrent.c_str(), mhda.lControllerPort, mhda.lDevice));
 
2596
                Log(("Attaching disk %s to port %d on device %d\n",
 
2597
                        vsdeTargetHD->strVboxCurrent.c_str(),
 
2598
                        mhda.lControllerPort,
 
2599
                        mhda.lDevice));
2448
2600
 
2449
2601
                rc = sMachine->AttachDevice(mhda.controllerType.raw(),    // wstring name
2450
2602
                                            mhda.lControllerPort,          // long controllerPort
2457
2609
 
2458
2610
                rc = sMachine->SaveSettings();
2459
2611
                if (FAILED(rc)) throw rc;
2460
 
            } // end for (itHD = avsdeHDs.begin();
 
2612
            } // end while(oit != stack.mapDisks.end())
2461
2613
 
2462
2614
            // only now that we're done with all disks, close the session
2463
2615
            rc = stack.pSession->UnlockMachine();
2672
2824
    if (cHardDisks != avsdeHDs.size())
2673
2825
        fRepairDuplicate = false;
2674
2826
 
2675
 
    // for each storage controller...
2676
 
    for (settings::StorageControllersList::iterator sit = config.storageMachine.llStorageControllers.begin();
2677
 
         sit != config.storageMachine.llStorageControllers.end();
2678
 
         ++sit)
 
2827
 
 
2828
    ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin();
 
2829
    std::set<RTCString>  disksResolvedNames;
 
2830
 
 
2831
    while(oit != stack.mapDisks.end())
2679
2832
    {
2680
 
        settings::StorageController &sc = *sit;
2681
 
 
2682
 
        // find the OVF virtual system description entry for this storage controller
2683
 
        switch (sc.storageBus)
2684
 
        {
2685
 
            case StorageBus_SATA:
2686
 
                break;
2687
 
            case StorageBus_SCSI:
2688
 
                break;
2689
 
            case StorageBus_IDE:
2690
 
                break;
2691
 
            case StorageBus_SAS:
2692
 
                break;
2693
 
        }
2694
 
 
2695
 
        // for each medium attachment to this controller...
2696
 
        for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin();
2697
 
             dit != sc.llAttachedDevices.end();
2698
 
             ++dit)
2699
 
        {
2700
 
            settings::AttachedDevice &d = *dit;
2701
 
 
2702
 
            if (d.uuid.isEmpty())
2703
 
                // empty DVD and floppy media
2704
 
                continue;
2705
 
 
2706
 
            // When repairing a broken VirtualBox xml config section (written
2707
 
            // by VirtualBox versions earlier than 3.2.10) assume the disks
2708
 
            // show up in the same order as in the OVF description.
2709
 
            if (fRepairDuplicate)
2710
 
            {
2711
 
                VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt;
2712
 
                ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
2713
 
                if (itDiskImage != stack.mapDisks.end())
2714
 
                {
2715
 
                    const ovf::DiskImage &di = itDiskImage->second;
2716
 
                    d.uuid = Guid(di.uuidVbox);
2717
 
                }
2718
 
                ++avsdeHDsIt;
2719
 
            }
2720
 
 
2721
 
            // convert the Guid to string
2722
 
            Utf8Str strUuid = d.uuid.toString();
2723
 
 
2724
 
            // there must be an image in the OVF disk structs with the same UUID
2725
 
            bool fFound = false;
2726
 
            for (ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin();
2727
 
                 oit != stack.mapDisks.end();
2728
 
                 ++oit)
2729
 
            {
2730
 
                const ovf::DiskImage &di = oit->second;
2731
 
 
2732
 
                if (di.uuidVbox == strUuid)
2733
 
                {
2734
 
                    VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
2735
 
 
2736
 
                    /* Iterate over all given disk images of the virtual system
2737
 
                     * disks description. We need to find the target disk path,
2738
 
                     * which could be changed by the user. */
2739
 
                    list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2740
 
                    for (itHD = avsdeHDs.begin();
2741
 
                         itHD != avsdeHDs.end();
2742
 
                         ++itHD)
2743
 
                    {
2744
 
                        VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2745
 
                        if (vsdeHD->strRef == oit->first)
2746
 
                        {
2747
 
                            vsdeTargetHD = vsdeHD;
2748
 
                            break;
2749
 
                        }
2750
 
                    }
2751
 
                    if (!vsdeTargetHD)
2752
 
                        throw setError(E_FAIL,
2753
 
                                       tr("Internal inconsistency looking up disk image '%s'"),
2754
 
                                       oit->first.c_str());
2755
 
 
2756
 
                    /*
2757
 
                     *
2758
 
                     * step 3: import disk
2759
 
                     *
2760
 
                     */
2761
 
                    ComObjPtr<Medium> pTargetHD;
2762
 
                    importOneDiskImage(di,
2763
 
                                       vsdeTargetHD->strVboxCurrent,
2764
 
                                       pTargetHD,
2765
 
                                       stack,
2766
 
                                       pCallbacks,
2767
 
                                       pStorage);
2768
 
 
2769
 
                    // ... and replace the old UUID in the machine config with the one of
2770
 
                    // the imported disk that was just created
2771
 
                    Bstr hdId;
2772
 
                    rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam());
2773
 
                    if (FAILED(rc)) throw rc;
2774
 
 
2775
 
                    d.uuid = hdId;
2776
 
 
2777
 
                    fFound = true;
 
2833
        ovf::DiskImage diCurrent = oit->second;
 
2834
 
 
2835
        VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
 
2836
 
 
2837
        {
 
2838
            /* Iterate over all given disk images of the virtual system
 
2839
             * disks description. We need to find the target disk path,
 
2840
             * which could be changed by the user. */
 
2841
            list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
 
2842
            for (itHD = avsdeHDs.begin();
 
2843
                 itHD != avsdeHDs.end();
 
2844
                 ++itHD)
 
2845
            {
 
2846
                VirtualSystemDescriptionEntry *vsdeHD = *itHD;
 
2847
                if (vsdeHD->strRef == oit->first)
 
2848
                {
 
2849
                    vsdeTargetHD = vsdeHD;
2778
2850
                    break;
2779
2851
                }
2780
2852
            }
2781
 
 
2782
 
            // no disk with such a UUID found:
2783
 
            if (!fFound)
 
2853
            if (!vsdeTargetHD)
2784
2854
                throw setError(E_FAIL,
2785
 
                               tr("<vbox:Machine> element in OVF contains a medium attachment for the disk image %s but the OVF describes no such image"),
2786
 
                               strUuid.c_str());
2787
 
        } // for (settings::AttachedDevicesList::const_iterator dit = sc.llAttachedDevices.begin();
2788
 
    } // for (settings::StorageControllersList::const_iterator sit = config.storageMachine.llStorageControllers.begin();
2789
 
 
 
2855
                               tr("Internal inconsistency looking up disk image '%s'"),
 
2856
                               oit->first.c_str());
 
2857
        }
 
2858
 
 
2859
        /*
 
2860
         *
 
2861
         * The preliminary check availability of the image
 
2862
         * This step is useful if image is placed in the OVA (TAR) package
 
2863
         *
 
2864
         */
 
2865
 
 
2866
        if (strncmp(pStorage->pVDImageIfaces->pszInterfaceName, "Appliance::IOTar", strlen("Appliance::IOTar")) == 0)
 
2867
        {
 
2868
            std::set<RTCString>::const_iterator h = disksResolvedNames.find(diCurrent.strHref);
 
2869
            if (h != disksResolvedNames.end())
 
2870
            {
 
2871
                /* Yes, disk name was found, we can skip it*/
 
2872
                ++oit;
 
2873
                continue;
 
2874
            }
 
2875
 
 
2876
            RTCString availableImage(diCurrent.strHref);
 
2877
 
 
2878
            RTTAR tar = (RTTAR)pStorage->pVDImageIfaces->pvUser;
 
2879
            char *pszFilename = 0;
 
2880
 
 
2881
            int vrc = RTTarCurrentFile(tar, &pszFilename);
 
2882
 
 
2883
            if (RT_FAILURE(vrc))
 
2884
            {
 
2885
                throw setError(VBOX_E_FILE_ERROR,
 
2886
                       tr("Could not open the current file in the archive (%Rrc)"), vrc);
 
2887
            }
 
2888
            else
 
2889
            {
 
2890
                availableImage = pszFilename;
 
2891
 
 
2892
                /* current opened file isn't the same as passed one */
 
2893
                if(availableImage.compare(diCurrent.strHref, Utf8Str::CaseInsensitive) != 0)
 
2894
                {
 
2895
                    // availableImage contains the disk identifier (e.g. "vmdisk1"), which should exist
 
2896
                    // in the virtual system's disks map under that ID and also in the global images map
 
2897
                    // and find the disk from the OVF's disk list
 
2898
                    ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.begin();
 
2899
                    while (++itDiskImage != stack.mapDisks.end())
 
2900
                    {
 
2901
                        if(itDiskImage->second.strHref.compare(availableImage, Utf8Str::CaseInsensitive) == 0 )
 
2902
                            break;
 
2903
                    }
 
2904
                    if (itDiskImage == stack.mapDisks.end())
 
2905
                    {
 
2906
                        throw setError(E_FAIL,
 
2907
                                       tr("Internal inconsistency looking up disk image '%s'"),
 
2908
                                       availableImage.c_str());
 
2909
                    }
 
2910
 
 
2911
                    /* replace with a new found disk image */
 
2912
                    diCurrent = *(&itDiskImage->second);
 
2913
 
 
2914
                    /* Again iterate over all given disk images of the virtual system
 
2915
                     * disks description using the found disk image
 
2916
                     */
 
2917
                    list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
 
2918
                    for (itHD = avsdeHDs.begin();
 
2919
                         itHD != avsdeHDs.end();
 
2920
                         ++itHD)
 
2921
                    {
 
2922
                        VirtualSystemDescriptionEntry *vsdeHD = *itHD;
 
2923
                        if (vsdeHD->strRef == diCurrent.strDiskId)
 
2924
                        {
 
2925
                            vsdeTargetHD = vsdeHD;
 
2926
                            break;
 
2927
                        }
 
2928
                    }
 
2929
                    if (!vsdeTargetHD)
 
2930
                        throw setError(E_FAIL,
 
2931
                                       tr("Internal inconsistency looking up disk image '%s'"),
 
2932
                                       diCurrent.strHref.c_str());
 
2933
                }
 
2934
                else
 
2935
                {
 
2936
                    ++oit;
 
2937
                }
 
2938
            }
 
2939
        }
 
2940
        else
 
2941
        {
 
2942
            /* just continue with normal files*/
 
2943
            ++oit;
 
2944
        }
 
2945
 
 
2946
        /* Important! to store disk name for the next checks */
 
2947
        disksResolvedNames.insert(diCurrent.strHref);
 
2948
 
 
2949
        // there must be an image in the OVF disk structs with the same UUID
 
2950
        bool fFound = false;
 
2951
        Utf8Str strUuid;
 
2952
 
 
2953
        // for each storage controller...
 
2954
        for (settings::StorageControllersList::iterator sit = config.storageMachine.llStorageControllers.begin();
 
2955
             sit != config.storageMachine.llStorageControllers.end();
 
2956
             ++sit)
 
2957
        {
 
2958
            settings::StorageController &sc = *sit;
 
2959
 
 
2960
            // find the OVF virtual system description entry for this storage controller
 
2961
            switch (sc.storageBus)
 
2962
            {
 
2963
                case StorageBus_SATA:
 
2964
                    break;
 
2965
                case StorageBus_SCSI:
 
2966
                    break;
 
2967
                case StorageBus_IDE:
 
2968
                    break;
 
2969
                case StorageBus_SAS:
 
2970
                    break;
 
2971
            }
 
2972
 
 
2973
            // for each medium attachment to this controller...
 
2974
            for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin();
 
2975
                 dit != sc.llAttachedDevices.end();
 
2976
                 ++dit)
 
2977
            {
 
2978
                settings::AttachedDevice &d = *dit;
 
2979
 
 
2980
                if (d.uuid.isEmpty())
 
2981
                    // empty DVD and floppy media
 
2982
                    continue;
 
2983
 
 
2984
                // When repairing a broken VirtualBox xml config section (written
 
2985
                // by VirtualBox versions earlier than 3.2.10) assume the disks
 
2986
                // show up in the same order as in the OVF description.
 
2987
                if (fRepairDuplicate)
 
2988
                {
 
2989
                    VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt;
 
2990
                    ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
 
2991
                    if (itDiskImage != stack.mapDisks.end())
 
2992
                    {
 
2993
                        const ovf::DiskImage &di = itDiskImage->second;
 
2994
                        d.uuid = Guid(di.uuidVbox);
 
2995
                    }
 
2996
                    ++avsdeHDsIt;
 
2997
                }
 
2998
 
 
2999
                // convert the Guid to string
 
3000
                strUuid = d.uuid.toString();
 
3001
                if (diCurrent.uuidVbox != strUuid)
 
3002
                {
 
3003
                    continue;
 
3004
                }
 
3005
                /*
 
3006
                 *
 
3007
                 * step 3: import disk
 
3008
                 *
 
3009
                 */
 
3010
                ComObjPtr<Medium> pTargetHD;
 
3011
                importOneDiskImage(diCurrent,
 
3012
                                   vsdeTargetHD->strVboxCurrent,
 
3013
                                   pTargetHD,
 
3014
                                   stack,
 
3015
                                   pCallbacks,
 
3016
                                   pStorage);
 
3017
 
 
3018
                // ... and replace the old UUID in the machine config with the one of
 
3019
                // the imported disk that was just created
 
3020
                Bstr hdId;
 
3021
                rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam());
 
3022
                if (FAILED(rc)) throw rc;
 
3023
 
 
3024
                d.uuid = hdId;
 
3025
 
 
3026
                fFound = true;
 
3027
                break;
 
3028
            } // for (settings::AttachedDevicesList::const_iterator dit = sc.llAttachedDevices.begin();
 
3029
        } // for (settings::StorageControllersList::const_iterator sit = config.storageMachine.llStorageControllers.begin();
 
3030
        // no disk with such a UUID found:
 
3031
        if (!fFound)
 
3032
            throw setError(E_FAIL,
 
3033
                           tr("<vbox:Machine> element in OVF contains a medium attachment for the disk image %s but the OVF describes no such image"),
 
3034
                           strUuid.c_str());
 
3035
    }// while(oit != stack.mapDisks.end())
2790
3036
    /*
2791
3037
     *
2792
3038
     * step 4): create the machine and have it import the config
2837
3083
    size_t i = 0;
2838
3084
    for (it = reader.m_llVirtualSystems.begin(),
2839
3085
         it1 = m->virtualSystemDescriptions.begin();
2840
 
         it != reader.m_llVirtualSystems.end();
 
3086
         it != reader.m_llVirtualSystems.end(),
 
3087
         it1 != m->virtualSystemDescriptions.end();
2841
3088
         ++it, ++it1, ++i)
2842
3089
    {
2843
3090
        const ovf::VirtualSystem &vsysThis = *it;