VirtualBox

Changeset 98035 in vbox for trunk/src/VBox/Storage


Ignore:
Timestamp:
Jan 10, 2023 6:35:56 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155131
Message:

reimplemented changes for bugref:10180 after seperating the changes from bugref:4787

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VISO.cpp

    r97367 r98035  
    107107};
    108108
     109/** NULL-terminated array of configuration option. */
     110static const VDCONFIGINFO s_aVisoConfigInfo[] =
     111{
     112    /* Options for VMDK raw disks */
     113    { "UnattendedInstall",     NULL,    VDCFGVALUETYPE_STRING,  VD_CFGKEY_EXPERT },
     114    /* End of options list */
     115    { NULL,                    NULL,    VDCFGVALUETYPE_INTEGER, 0 }
     116};
    109117
    110118/**
     
    515523}
    516524
     525/**
     526 * Scans the VISO file and removes all references to files
     527 * which are in the same folder as the VISO and
     528 * whose names begin with "Unattended-".
     529 *
     530 * @return VBox status code.
     531 *
     532 * @param pThis Pointer to VISO backend data.
     533 */
     534static int deleteReferences(PVISOIMAGE pThis)
     535{
     536    /*
     537     * Open the file and read it into memory.
     538     */
     539    PVDIOSTORAGE pStorage = NULL;
     540    int vrc = vdIfIoIntFileOpen(pThis->pIfIo, pThis->pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, &pStorage);
     541    if (RT_FAILURE(vrc))
     542    {
     543        LogRel(("VISO: Unable to open file '%s': %Rrc\n", pThis->pszFilename, vrc));
     544        return vrc;
     545    }
     546
     547    LogRel(("VISO: Handling file '%s' references\n", pThis->pszFilename));
     548
     549    /*
     550     * Read the file into memory.
     551     */
     552    uint64_t cbFile = 0;
     553    vrc = vdIfIoIntFileGetSize(pThis->pIfIo, pStorage, &cbFile);
     554    if (RT_SUCCESS(vrc))
     555    {
     556        if (cbFile <= VISO_MAX_FILE_SIZE)
     557        {
     558            char *pszContent = (char *)RTMemTmpAlloc(cbFile + 1);
     559            if (pszContent)
     560            {
     561                vrc = vdIfIoIntFileReadSync(pThis->pIfIo, pStorage, 0 /*off*/, pszContent, (size_t)cbFile);
     562                if (RT_SUCCESS(vrc))
     563                {
     564                    /*
     565                     * Check the file marker.
     566                     * Ignore leading blanks.
     567                     */
     568                    pszContent[(size_t)cbFile] = '\0';
     569
     570                    char *pszReadDst = pszContent;
     571                    while (RT_C_IS_SPACE(*pszReadDst))
     572                        pszReadDst++;
     573                    if (strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker")) == 0)
     574                    {
     575                        vrc = visoParseUuid(pszReadDst, &pThis->Uuid);
     576                        if (RT_SUCCESS(vrc))
     577                        {
     578                            /*
     579                             * Make sure it's valid UTF-8 before letting
     580                             */
     581                            vrc = RTStrValidateEncodingEx(pszContent, cbFile + 1,
     582                                                          RTSTR_VALIDATE_ENCODING_EXACT_LENGTH
     583                                                          | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
     584                            if (RT_SUCCESS(vrc))
     585                            {
     586                                /*
     587                                 * Convert it into an argument vector.
     588                                 * Free the content afterwards to reduce memory pressure.
     589                                 */
     590                                uint32_t fGetOpt = strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker-ms")) != 0
     591                                                 ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT;
     592                                fGetOpt |= RTGETOPTARGV_CNV_MODIFY_INPUT;
     593                                char **papszArgs;
     594                                int    cArgs;
     595                                vrc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL);
     596
     597                                if (RT_SUCCESS(vrc))
     598                                {
     599                                    for (int i = 0; i < cArgs; ++i)
     600                                    {
     601                                        char *pszArg = papszArgs[i];
     602                                        char *pszOffset = strrchr(pszArg, '=');
     603                                        if (pszOffset != NULL)
     604                                            pszArg = pszOffset + 1;
     605
     606                                        /* if it isn't option */
     607                                        if (pszArg[0] != '-')
     608                                        {
     609                                            char *pszPath = RTPathAbsExDup(pThis->pszCwd, pszArg, 0);
     610                                            if (RTStrStartsWith((const char *)pszPath, pThis->pszCwd))
     611                                            {
     612                                                char *pszFileName = RTPathFilename(pszPath);
     613                                                if (   pszFileName != NULL
     614                                                    && RTStrStartsWith((const char *)pszFileName, "Unattended-"))
     615                                                {
     616                                                    vrc = RTFileDelete(pszPath);
     617                                                    if (RT_SUCCESS(vrc))
     618                                                        LogRel(("VISO: file '%s' deleted\n", pszPath));
     619                                                    else
     620                                                        LogRel(("VISO: Failed to delete the file '%s' (%Rrc)\n", pszPath, vrc));
     621                                                    vrc = VINF_SUCCESS;
     622                                                }
     623                                            }
     624                                            RTStrFree(pszPath);
     625                                        }
     626                                    }
     627                                    RTGetOptArgvFreeEx(papszArgs, fGetOpt);
     628                                    papszArgs = NULL;
     629                                }
     630                                else
     631                                    vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: RTGetOptArgvFromString failed: %Rrc", vrc);
     632                            }
     633                            else
     634                                vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Invalid file encoding");
     635                        }
     636                        else
     637                            vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Parsing UUID failed: %Rrc", vrc);
     638                    }
     639                    else
     640                        vrc = VERR_VD_GEN_INVALID_HEADER;
     641                }
     642                else
     643                    vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Reading file failed: %Rrc", vrc);
     644
     645                RTMemTmpFree(pszContent);
     646            }
     647            else
     648                vrc = VERR_NO_TMP_MEMORY;
     649        }
     650        else
     651        {
     652            LogRel(("visoOpen: VERR_VD_INVALID_SIZE - cbFile=%#RX64 cbMaxFile=%#RX64\n",
     653                    cbFile, (uint64_t)VISO_MAX_FILE_SIZE));
     654            vrc = VERR_VD_INVALID_SIZE;
     655        }
     656    }
     657    if (RT_FAILURE(vrc))
     658        LogRel(("VISO: Handling of file '%s' failed with %Rrc\n", pThis->pszFilename, vrc));
     659
     660    vdIfIoIntFileClose(pThis->pIfIo, pStorage);
     661    return vrc;
     662}
    517663
    518664/**
     
    527673    {
    528674        if (fDelete)
     675        {
     676                PVDINTERFACECONFIG pImgCfg = VDIfConfigGet(&pThis->pIfIo->Core);
     677
     678                bool fUnattendedInstall = false;
     679                int vrc = VDCFGQueryBool(pImgCfg, "UnattendedInstall", &fUnattendedInstall);
     680
     681                /*
     682                * The VISO created by unattended installer, so delete all generated files
     683                * included in the VISO. the file is considered generated if it is located
     684                * in the same folder as VISO and its name begins with "Unattended-"
     685                */
     686                if (RT_SUCCESS(vrc) && fUnattendedInstall)
     687                    deleteReferences(pThis);
    529688            vdIfIoIntFileDelete(pThis->pIfIo, pThis->pszFilename);
     689        }
    530690
    531691        if (pThis->hIsoFile != NIL_RTVFSFILE)
     
    8691029    g_aVBoXIsoMakerFileExtensions,
    8701030    /* paConfigInfo */
    871     NULL,
     1031    s_aVisoConfigInfo,
    8721032    /* pfnProbe */
    8731033    visoProbe,
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