VirtualBox

Changeset 34418 in vbox


Ignore:
Timestamp:
Nov 26, 2010 5:25:58 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
68189
Message:

VBoxExtPAckHelperApp.cpp: More code.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/err.h

    r34380 r34418  
    457457#define VERR_NOT_IMPLEMENTED                (-12)
    458458
     459/** Not equal. */
     460#define VERR_NOT_EQUAL                      (-18)
    459461/** The specified path does not point at a symbolic link. */
    460462#define VERR_NOT_SYMLINK                    (-19)
  • trunk/include/iprt/manifest.h

    r34391 r34418  
    9696 * Compares two manifests for equality.
    9797 *
    98  * @returns true if equals, false if not.
     98 * @returns IPRT status code.
     99 * @retval  VINF_SUCCESS if equal.
     100 * @retval  VERR_NOT_EQUAL if not equal.
     101 *
    99102 * @param   hManifest1          The first manifest.
    100103 * @param   hManifest2          The second manifest.
    101104 * @param   papszIgnoreEntries  Entries to ignore.  Ends with a NULL entry.
    102105 * @param   papszIgnoreAttrs    Attributes to ignore.  Ends with a NULL entry.
     106 * @param   pszEntry            Where to store the name of the mismatching
     107 *                              entry, or as much of the name as there is room
     108 *                              for.  This is always set.  Optional.
     109 * @param   cbEntry             The size of the buffer pointed to by @a
     110 *                              pszEntry.
    103111 */
    104112RTDECL(int) RTManifestEqualsEx(RTMANIFEST hManifest1, RTMANIFEST hManifest2, const char * const *papszIgnoreEntries,
    105                                const char * const *papszIgnoreAttr);
     113                               const char * const *papszIgnoreAttr, char *pszEntry, size_t cbEntry);
    106114
    107115/**
    108116 * Compares two manifests for equality.
    109117 *
    110  * @returns true if equals, false if not.
     118 * @returns IPRT status code.
     119 * @retval  VINF_SUCCESS if equal.
     120 * @retval  VERR_NOT_EQUAL if not equal.
     121 *
    111122 * @param   hManifest1          The first manifest.
    112123 * @param   hManifest2          The second manifest.
  • trunk/src/VBox/Main/VBoxExtPackHelperApp.cpp

    r34391 r34418  
    236236
    237237/**
     238 * Verifies the manifest and its signature.
     239 *
     240 * @returns Program exit code, failure with message.
     241 * @param   hOurManifest    The manifest we compiled.
     242 * @param   hManifestFile   The manifest file in the extension pack.
     243 * @param   hSignatureFile  The manifest signature file.
     244 */
     245static RTEXITCODE VerifyManifestAndSignature(RTMANIFEST hOurManifest, RTVFSFILE hManifestFile, RTVFSFILE hSignatureFile)
     246{
     247    /*
     248     * Read the manifest from the extension pack.
     249     */
     250    RTMANIFEST hTheirManifest;
     251    int rc = RTManifestCreate(0 /*fFlags*/, &hTheirManifest);
     252    if (RT_FAILURE(rc))
     253        return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTManifestCreate failed: %Rrc", rc);
     254
     255    RTEXITCODE    rcExit;
     256    RTVFSIOSTREAM hVfsIos = RTVfsFileToIoStream(hManifestFile);
     257    rc = RTManifestReadStandard(hTheirManifest, hVfsIos);
     258    RTVfsIoStrmRelease(hVfsIos);
     259    if (RT_SUCCESS(rc))
     260    {
     261        /*
     262         * Compare the manifests.
     263         */
     264        static const char *s_apszIgnoreEntries[] =
     265        {
     266            VBOX_EXTPACK_MANIFEST_NAME,
     267            VBOX_EXTPACK_SIGNATURE_NAME,
     268            "./" VBOX_EXTPACK_MANIFEST_NAME,
     269            "./" VBOX_EXTPACK_SIGNATURE_NAME,
     270            NULL
     271        };
     272        char szEntry[RTPATH_MAX];
     273        rc = RTManifestEqualsEx(hOurManifest, hTheirManifest, &s_apszIgnoreEntries[0], NULL, szEntry, sizeof(szEntry));
     274        if (RT_SUCCESS(rc))
     275        {
     276            /*
     277             * Validate the manifest file signature.
     278             */
     279            /** @todo implement signature stuff */
     280
     281        }
     282        else if (rc == VERR_NOT_EQUAL && szEntry[0])
     283            RTMsgError("Manifest mismatch: '%s'", szEntry);
     284        else
     285            RTMsgError("RTManifestEqualsEx failed: %Rrc", rc);
     286    }
     287    else
     288        RTMsgError("Error parsing '%s': %Rrc", VBOX_EXTPACK_MANIFEST_NAME);
     289
     290    RTManifestRelease(hTheirManifest);
     291    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     292}
     293
     294
     295/**
    238296 * Validates a name in an extension pack.
    239297 *
     
    440498        return rcExit;
    441499
    442     RTMANIFEST hManifest;
    443     int rc = RTManifestCreate(0 /*fFlags*/, &hManifest);
     500    RTMANIFEST hOurManifest;
     501    int rc = RTManifestCreate(0 /*fFlags*/, &hOurManifest);
    444502    if (RT_SUCCESS(rc))
    445503    {
    446504        /*
    447          * Process the tarball.
     505         * Process the tarball (would be nice to move this to a function).
    448506         */
    449507        RTVFSFILE hXmlFile      = NIL_RTVFSFILE;
    450508        RTVFSFILE hManifestFile = NIL_RTVFSFILE;
    451         RTVFSFILE hSignFile     = NIL_RTVFSFILE;
     509        RTVFSFILE hSignatureFile= NIL_RTVFSFILE;
    452510        for (;;)
    453511        {
     
    482540                    phVfsFile = &hManifestFile;
    483541                else if (!strcmp(pszAdjName, VBOX_EXTPACK_SIGNATURE_NAME))
    484                     phVfsFile = &hSignFile;
     542                    phVfsFile = &hSignatureFile;
    485543                else
    486544                    phVfsFile = NULL;
     
    542600            {
    543601                RTVFSIOSTREAM hVfsIos = RTVfsObjToIoStream(hVfsObj);
    544                 rc = RTManifestEntryAddIoStream(hManifest, hVfsIos, pszName, RTMANIFEST_ATTR_SIZE | RTMANIFEST_ATTR_SHA256);
     602                rc = RTManifestEntryAddIoStream(hOurManifest, hVfsIos, pszName, RTMANIFEST_ATTR_SIZE | RTMANIFEST_ATTR_SHA256);
    545603                if (RT_FAILURE(rc))
    546604                    rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTManifestEntryAddIoStream failed on '%s': %Rrc", pszName, rc);
     
    567625            if (hManifestFile == NIL_RTVFSFILE)
    568626                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Mandator file '%s' is missing", VBOX_EXTPACK_MANIFEST_NAME);
    569             if (hSignFile == NIL_RTVFSFILE)
     627            if (hSignatureFile == NIL_RTVFSFILE)
    570628                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Mandator file '%s' is missing", VBOX_EXTPACK_SIGNATURE_NAME);
    571629        }
    572630
    573 
    574 
    575         RTManifestRelease(hManifest);   /** @todo return this and use it during unpacking */
     631        /*
     632         * Check the manifest and it's signature.
     633         */
     634        if (rcExit == RTEXITCODE_SUCCESS)
     635            rcExit = VerifyManifestAndSignature(hOurManifest, hManifestFile, hSignatureFile);
     636
     637        RTManifestRelease(hOurManifest);   /** @todo return this and use it during unpacking */
     638
     639        RTVfsFileRelease(hXmlFile);
     640        RTVfsFileRelease(hManifestFile);
     641        RTVfsFileRelease(hSignatureFile);
    576642    }
    577643    RTVfsFsStrmRelease(hTarFss);
  • trunk/src/VBox/Runtime/common/checksum/manifest2.cpp

    r34385 r34418  
    222222
    223223
    224 /**
    225  * Compares two manifests for equality.
    226  *
    227  * @returns true if equals, false if not.
    228  * @param   hManifest1          The first manifest.
    229  * @param   hManifest2          The second manifest.
    230  * @param   papszIgnoreEntries  Entries to ignore.  Ends with a NULL entry.
    231  * @param   papszIgnoreAttrs    Attributes to ignore.  Ends with a NULL entry.
    232  */
    233224RTDECL(int) RTManifestEqualsEx(RTMANIFEST hManifest1, RTMANIFEST hManifest2, const char * const *papszIgnoreEntries,
    234                                const char * const *papszIgnoreAttr)
    235 {
     225                               const char * const *papszIgnoreAttr, char *pszEntry, size_t cbEntry)
     226{
     227    /*
     228     * Validate input.
     229     */
     230    AssertPtrNullReturn(pszEntry, VERR_INVALID_POINTER);
     231    if (pszEntry && cbEntry)
     232        *pszEntry = '\0';
    236233    RTMANIFESTINT *pThis1 = hManifest1;
    237234    RTMANIFESTINT *pThis2 = hManifest1;
    238235    if (pThis1 != NIL_RTMANIFEST)
    239236    {
    240         AssertPtrReturn(pThis1, false);
    241         AssertReturn(pThis1->u32Magic == RTMANIFEST_MAGIC, false);
     237        AssertPtrReturn(pThis1, VERR_INVALID_HANDLE);
     238        AssertReturn(pThis1->u32Magic == RTMANIFEST_MAGIC, VERR_INVALID_HANDLE);
    242239    }
    243240    if (pThis2 != NIL_RTMANIFEST)
    244241    {
    245         AssertPtrReturn(pThis2, false);
    246         AssertReturn(pThis2->u32Magic == RTMANIFEST_MAGIC, false);
     242        AssertPtrReturn(pThis2, VERR_INVALID_HANDLE);
     243        AssertReturn(pThis2->u32Magic == RTMANIFEST_MAGIC, VERR_INVALID_HANDLE);
    247244    }
    248245
     
    251248     */
    252249    if (pThis1 == pThis2)
    253         return true;
     250        return VINF_SUCCESS;
    254251    if (pThis1 == NIL_RTMANIFEST || pThis2 == NIL_RTMANIFEST)
    255         return false;
     252        return VERR_NOT_EQUAL;
    256253
    257254    /*
     
    266263
    267264
    268 /**
    269  * Compares two manifests for equality.
    270  *
    271  * @returns true if equals, false if not.
    272  * @param   hManifest1          The first manifest.
    273  * @param   hManifest2          The second manifest.
    274  */
    275265RTDECL(int) RTManifestEquals(RTMANIFEST hManifest1, RTMANIFEST hManifest2)
    276266{
    277     return RTManifestEqualsEx(hManifest1, hManifest2, NULL /*papszIgnoreEntries*/, NULL /*papszIgnoreAttrs*/);
     267    return RTManifestEqualsEx(hManifest1, hManifest2, NULL /*papszIgnoreEntries*/, NULL /*papszIgnoreAttrs*/, NULL, 0);
    278268}
    279269
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