VirtualBox

Changeset 49047 in vbox for trunk/src


Ignore:
Timestamp:
Oct 11, 2013 6:23:11 AM (11 years ago)
Author:
vboxsync
Message:

pr6927. the state of CD/DVD image is checked, only ISO image is granted to export, host CD/DVD isn't exported now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp

    r49039 r49047  
    326326            if (FAILED(rc)) throw rc;
    327327
    328             Utf8Str strTargetVmdkName;
     328            Utf8Str strTargetImageName;
    329329            Utf8Str strLocation;
    330330            LONG64  llSize = 0;
     
    334334            {
    335335                Bstr bstrLocation;
     336
    336337                rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    337338                if (FAILED(rc)) throw rc;
     
    348349                if (FAILED(rc)) throw rc;
    349350
    350                 Bstr bstrBaseName;
    351                 rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam());
    352                 if (FAILED(rc)) throw rc;
    353 
    354                 Utf8Str strTargetName = Utf8Str(locInfo.strPath).stripPath().stripSuffix();
    355                 strTargetVmdkName = Utf8StrFmt("%s-disk%d.vmdk", strTargetName.c_str(), ++pAppliance->m->cDisks);
    356                 if (strTargetVmdkName.length() > RTTAR_NAME_MAX)
     351                Utf8Str strName = Utf8Str(locInfo.strPath).stripPath().stripSuffix();
     352                strTargetImageName = Utf8StrFmt("%s-disk%d.vmdk", strName.c_str(), ++pAppliance->m->cDisks);
     353                if (strTargetImageName.length() > RTTAR_NAME_MAX)
    357354                    throw setError(VBOX_E_NOT_SUPPORTED,
    358                                 tr("Cannot attach disk '%s' -- file name too long"), strTargetVmdkName.c_str());
     355                                tr("Cannot attach disk '%s' -- file name too long"), strTargetImageName.c_str());
    359356
    360357                // force reading state, or else size will be returned as 0
     
    369366                     && pMedium)
    370367            {
     368                /*
     369                 * check the minimal rules to grant access to export an image
     370                 * 1. no host drive CD/DVD image
     371                 * 2. the image must be accessible and readable
     372                 * 3. only ISO image is exported
     373                 */
     374
     375                //1. no host drive CD/DVD image
     376                BOOL fHostDrive = false;
     377                rc = pMedium->COMGETTER(HostDrive)(&fHostDrive);
     378                if (FAILED(rc)) throw rc;
     379
     380                if(fHostDrive)
     381                    continue;
     382
     383                //2. the image must be accessible and readable
     384                MediumState_T ms;
     385                rc = pMedium->RefreshState(&ms);
     386                if (FAILED(rc)) throw rc;
     387
     388                if (ms != MediumState_Created)
     389                    continue;
     390
     391                //3. only ISO image is exported
    371392                Bstr bstrLocation;
    372393                rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    373394                if (FAILED(rc)) throw rc;
     395
    374396                strLocation = bstrLocation;
    375397
    376                 // find the source's base medium for two things:
    377                 // 1) we'll use its name to determine the name of the target disk, which is readable,
    378                 //    as opposed to the UUID filename of a differencing image, if pMedium is one
    379                 // 2) we need the size of the base image so we can give it to addEntry(), and later
    380                 //    on export, the progress will be based on that (and not the diff image)
    381                 ComPtr<IMedium> pBaseMedium;
    382                 rc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam());
    383                         // returns pMedium if there are no diff images
    384                 if (FAILED(rc)) throw rc;
    385 
    386                 Bstr bstrBaseName;
    387                 rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam());
    388                 if (FAILED(rc)) throw rc;
    389 
    390                 Utf8Str strTargetName = Utf8Str(locInfo.strPath).stripPath().stripSuffix();
    391                 strTargetVmdkName = Utf8StrFmt("%s-disk%d.iso", strTargetName.c_str(), ++pAppliance->m->cDisks);
    392                 if (strTargetVmdkName.length() > RTTAR_NAME_MAX)
     398                Utf8Str ext = strLocation;
     399                ext.assignEx(RTPathSuffix(ext.c_str()));//returns extension with dot (".iso")
     400
     401                int eq = ext.compare(".iso", Utf8Str::CaseInsensitive);
     402                if (eq != 0)
     403                    continue;
     404
     405                Utf8Str strName = Utf8Str(locInfo.strPath).stripPath().stripSuffix();
     406                strTargetImageName = Utf8StrFmt("%s-disk%d.iso", strName.c_str(), ++pAppliance->m->cDisks);
     407                if (strTargetImageName.length() > RTTAR_NAME_MAX)
    393408                    throw setError(VBOX_E_NOT_SUPPORTED,
    394                                 tr("Cannot attach image '%s' -- file name too long"), strTargetVmdkName.c_str());
    395 
    396                 // force reading state, or else size will be returned as 0
    397                 MediumState_T ms;
    398                 rc = pBaseMedium->RefreshState(&ms);
    399                 if (FAILED(rc)) throw rc;
    400 
    401                 rc = pBaseMedium->COMGETTER(Size)(&llSize);
     409                                tr("Cannot attach image '%s' -- file name too long"), strTargetImageName.c_str());
     410
     411                rc = pMedium->COMGETTER(Size)(&llSize);
    402412                if (FAILED(rc)) throw rc;
    403413            }
     
    469479                    Log(("Adding VirtualSystemDescriptionType_HardDiskImage, disk size: %RI64\n", llSize));
    470480                    pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage,
    471                                        strTargetVmdkName,   // disk ID: let's use the name
    472                                        strTargetVmdkName,   // OVF value:
     481                                       strTargetImageName,   // disk ID: let's use the name
     482                                       strTargetImageName,   // OVF value:
    473483                                       strLocation, // vbox value: media path
    474484                                       (uint32_t)(llSize / _1M),
     
    477487
    478488                case DeviceType_DVD:
    479                 {
    480                     if (!pMedium)
    481                         break;
    482 
    483                     /* get info about whether medium is a real drive/device or not */
    484                     BOOL fHostDrive = false;
    485                     rc = pMedium->COMGETTER(HostDrive)(&fHostDrive);
    486 
    487                     /* Only virtual CD-ROM is exported, the real device/drive isn't exported */
    488                     if(!fHostDrive)
    489                         pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM,
    490                                            strTargetVmdkName,   // disk ID
    491                                            strTargetVmdkName,   // OVF value
    492                                            strLocation, // vbox value
    493                                            (uint32_t)(llSize / _1M),// ulSize
    494                                            strExtra);
    495                 }
     489                    Log(("Adding VirtualSystemDescriptionType_CDROM, disk size: %RI64\n", llSize));
     490                    pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM,
     491                                       strTargetImageName,   // disk ID
     492                                       strTargetImageName,   // OVF value
     493                                       strLocation, // vbox value
     494                                       (uint32_t)(llSize / _1M),// ulSize
     495                                       strExtra);
    496496                break;
    497497
     
    18131813        // fill the machine config
    18141814        vsdescThis->m->pMachine->copyMachineDataToSettings(*pConfig);
     1815
    18151816        // write the machine config to the vbox:Machine element
    18161817        pConfig->buildMachineXML(*pelmVBoxMachine,
     
    21312132                    waitForAsyncProgress(pTask->pProgress, pProgress3);
    21322133                }
    2133                 else
     2134                else//pDiskEntry->type == VirtualSystemDescriptionType_CDROM
    21342135                {
    21352136                    //copy/clone CD/DVD image
Note: See TracChangeset for help on using the changeset viewer.

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