VirtualBox

Changeset 34442 in vbox


Ignore:
Timestamp:
Nov 29, 2010 12:25:17 AM (14 years ago)
Author:
vboxsync
Message:

bugfixing

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/VBoxExtPackHelperApp.cpp

    r34437 r34442  
    8686                      "Usage: %s <command> [options]\n"
    8787                      "Commands:\n"
    88                       "    install --base-dir <dir> --certificate-dir <dir> --name <name> \\\n"
     88                      "    install --base-dir <dir> --cert-dir <dir> --name <name> \\\n"
    8989                      "        --tarball <tarball> --tarball-fd <fd>\n"
    9090                      "    uninstall --base-dir <dir> --name <name>\n"
     
    231231static RTEXITCODE SetExtPackPermissions(const char *pszDir)
    232232{
     233    RTMsgInfo("Setting permissions...");
    233234#if !defined(RT_OS_WINDOWS)
    234235     int rc = RTPathSetMode(pszDir, 0755);
     
    239240#endif
    240241
     242    return RTEXITCODE_SUCCESS;
     243}
     244
     245
     246/**
     247 * Verifies the manifest and its signature.
     248 *
     249 * @returns Program exit code, failure with message.
     250 * @param   hManifestFile   The xml from the extension pack.
     251 * @param   pszExtPackName  The expected extension pack name.
     252 */
     253static RTEXITCODE VerifyXml(RTVFSFILE hXmlFile, const char *pszExtPackName)
     254{
     255    /** @todo implement XML verification. */
    241256    return RTEXITCODE_SUCCESS;
    242257}
     
    294309    }
    295310    else
    296         RTMsgError("Error parsing '%s': %Rrc", VBOX_EXTPACK_MANIFEST_NAME);
     311        RTMsgError("Error parsing '%s': %Rrc", VBOX_EXTPACK_MANIFEST_NAME, rc);
    297312
    298313    RTManifestRelease(hTheirManifest);
     
    356371            break;
    357372        }
     373
     374        /* advance */
     375        psz++;
    358376    }
    359377
     
    450468 * Operations performed:
    451469 *      - Hardening checks.
    452  *      - XML validity check.
    453  *      - Name check (against XML).
    454470 *
    455471 * @returns The program exit code.
    456472 * @param   pszDir              The directory where the extension pack has been
    457473 *                              unpacked.
    458  * @param   pszName             The expected extension pack name.
     474 * @param   pszExtPackName      The expected extension pack name.
    459475 * @param   pszTarball          The name of the tarball in case we have to
    460476 *                              complain about something.
    461477 */
    462 static RTEXITCODE ValidateUnpackedExtPack(const char *pszDir, const char *pszTarball, const char *pszName)
    463 {
    464     /** @todo  */
     478static RTEXITCODE ValidateUnpackedExtPack(const char *pszDir, const char *pszTarball, const char *pszExtPackName)
     479{
     480    RTMsgInfo("Validating unpacked extension pack...");
     481
     482    char szErr[4096+1024];
     483    int rc = SUPR3HardenedVerifyDir(pszDir, true /*fRecursive*/, true /*fCheckFiles*/, szErr, sizeof(szErr));
     484    if (RT_FAILURE(rc))
     485        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Hardening check failed with %Rrc: %s", rc, szErr);
     486    return RTEXITCODE_SUCCESS;
     487}
     488
     489
     490/**
     491 * Unpacks a directory from an extension pack tarball.
     492 *
     493 * @returns Program exit code, failure with message.
     494 * @param   pszDstDirName   The name of the unpacked directory.
     495 * @param   hVfsObj         The source object for the directory.
     496 */
     497static RTEXITCODE UnpackExtPackDir(const char *pszDstDirName, RTVFSOBJ hVfsObj)
     498{
     499    int rc = RTDirCreate(pszDstDirName, 0755);
     500    if (RT_FAILURE(rc))
     501        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create directory '%s': %Rrc", pszDstDirName, rc);
     502    /** @todo Ownership tricks on windows? */
    465503    return RTEXITCODE_SUCCESS;
    466504}
     
    564602 * @param   hTarballFile        The tarball to unpack.
    565603 * @param   pszDirDst           Where to unpack it.
     604 * @param   hValidManifest      The manifest we've validated.
    566605 * @param   pszTarball          The name of the tarball in case we have to
    567606 *                              complain about something.
    568  * @todo    Needs to take the previous verified manifest as input.
    569  */
    570 static RTEXITCODE UnpackExtPack(RTFILE hTarballFile, const char *pszDirDst, const char *pszTarball)
    571 {
     607 */
     608static RTEXITCODE UnpackExtPack(RTFILE hTarballFile, const char *pszDirDst, RTMANIFEST hValidManifest,
     609                                const char *pszTarball)
     610{
     611    RTMsgInfo("Unpacking extension pack into '%s'...", pszDirDst);
     612
    572613    /*
    573614     * Set up the destination path and directory.
     
    634675                    }
    635676                    else
    636                     {
    637                         rc = RTDirCreate(szDstPath, 0755);
    638                         if (RT_FAILURE(rc))
    639                             rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create directory '%s': %Rrc", pszName, rc);
    640                     }
     677                        rcExit = UnpackExtPackDir(szDstPath, hVfsObj);
    641678                }
    642679                else
     
    657694         * manifest.
    658695         */
    659         //if (rcExit == RTEXITCODE_SUCCESS)
    660         /// @todo
     696        if (rcExit == RTEXITCODE_SUCCESS)
     697        {
     698            char szEntry[RTPATH_MAX];
     699            rc = RTManifestEqualsEx(hUnpackManifest, hValidManifest, NULL /*papszIgnoreEntries*/, NULL /*papszIgnoreAttr*/,
     700                                    szEntry, sizeof(szEntry));
     701            if (RT_SUCCESS(rc))
     702                rc = RTEXITCODE_SUCCESS;
     703            else if (rc == VERR_NOT_EQUAL && szEntry[0])
     704                RTMsgError("Manifest mismatch: '%s'", szEntry);
     705            else
     706                RTMsgError("RTManifestEqualsEx failed: %Rrc", rc);
     707        }
    661708
    662709        RTManifestRelease(hUnpackManifest);
     
    668715
    669716
     717
    670718/**
    671719 * Validates the extension pack tarball prior to unpacking.
    672720 *
    673721 * Operations performed:
     722 *      - Mandatory files.
    674723 *      - Manifest check.
    675724 *      - Manifest seal check.
    676  *      - Mandatory files.
     725 *      - XML check, match name.
    677726 *
    678727 * @returns The program exit code.
    679728 * @param   hTarballFile        The handle to open the @a pszTarball file.
     729 * @param   pszExtPackName      The name of the extension pack name.
    680730 * @param   pszTarball          The name of the tarball in case we have to
    681731 *                              complain about something.
    682  *
    683  * @todo    Should validate the XML and name.
    684  * @todo    Needs to return a manifest.
    685  */
    686 static RTEXITCODE ValidateExtPackTarball(RTFILE hTarballFile, const char *pszTarball)
    687 {
     732 * @param   phValidManifest     Where to return the handle to fully validated
     733 *                              the manifest for the extension pack.  This
     734 *                              includes all files.
     735 *
     736 * @todo    This function is a bit too long and should be split up if possible.
     737 */
     738static RTEXITCODE ValidateExtPackTarball(RTFILE hTarballFile, const char *pszExtPackName, const char *pszTarball,
     739                                         PRTMANIFEST phValidManifest)
     740{
     741    *phValidManifest = NIL_RTMANIFEST;
     742    RTMsgInfo("Validating extension pack '%s' ('%s')...", pszTarball, pszExtPackName);
     743
    688744    /*
    689745     * Open the tar.gz filesystem stream and set up an manifest in-memory file.
     
    831887            rcExit = VerifyManifestAndSignature(hOurManifest, hManifestFile, hSignatureFile);
    832888
    833         RTManifestRelease(hOurManifest);   /** @todo return this and use it during unpacking */
     889        /*
     890         * Check the XML.
     891         */
     892        if (rcExit == RTEXITCODE_SUCCESS)
     893            rcExit = VerifyXml(hXmlFile, pszExtPackName);
     894
     895        /*
     896         * Release objects and stuff.
     897         */
     898        if (rcExit == RTEXITCODE_SUCCESS)
     899            *phValidManifest = hOurManifest;
     900        else
     901            RTManifestRelease(hOurManifest);
    834902
    835903        RTVfsFileRelease(hXmlFile);
     
    923991        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create temporary directory: %Rrc ('%s')", rc, szTmpPath);
    924992
    925     RTEXITCODE rcExit = ValidateExtPackTarball(hTarballFile, pszTarball);
     993    RTMANIFEST hValidManifest = NIL_RTMANIFEST;
     994    RTEXITCODE rcExit = ValidateExtPackTarball(hTarballFile, pszName, pszTarball, &hValidManifest);
    926995    if (rcExit == RTEXITCODE_SUCCESS)
    927         rcExit = UnpackExtPack(hTarballFile, szTmpPath, pszTarball);
     996        rcExit = UnpackExtPack(hTarballFile, szTmpPath, hValidManifest, pszTarball);
    928997    if (rcExit == RTEXITCODE_SUCCESS)
    929998        rcExit = ValidateUnpackedExtPack(szTmpPath, pszTarball, pszName);
    930999    if (rcExit == RTEXITCODE_SUCCESS)
    9311000        rcExit = SetExtPackPermissions(szTmpPath);
     1001    RTManifestRelease(hValidManifest);
     1002
    9321003    if (rcExit == RTEXITCODE_SUCCESS)
    9331004    {
  • trunk/src/VBox/Runtime/common/checksum/manifest2.cpp

    r34418 r34442  
    676676
    677677
     678#if 0
     679static int rtManifestReadLine(RTVFSIOSTREAM hVfsIos, char *pszLine, size_t cbLine)
     680{
     681    /* This is horribly slow right now, but it's not a biggy as the input is
     682       usually cached in memory somewhere... */
     683    *pszLine = '\0';
     684    while (cbLine > 1)
     685    {
     686        int rc = RTVfsIoStrmRead(hVfsIos, pszLine, 1, true /*fBLocking*/, NULL);
     687        if (RT_FAILURE(rc))
     688        {
     689            *pszLine = '\0';
     690            return rc == VERR_EOF ? VINF_EOF : rc;
     691        }
     692    }
     693    return rc;
     694}
     695#endif
     696
     697
    678698/**
    679699 * Reads in a "standard" manifest.
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