Changeset 34954 in vbox
- Timestamp:
- Dec 10, 2010 2:43:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ExtPackManagerImpl.cpp
r34948 r34954 462 462 463 463 /* 464 * Effectuate the query. 464 * Lock the extension pack. We need a write lock here as there must not be 465 * concurrent accesses to the tar file handle. 465 466 */ 466 467 AutoCaller autoCaller(this); … … 471 472 472 473 /* 473 * Look it up in the manifest before scanning the tarball for it 474 * Do not permit this query on a pack that isn't considered usable (could 475 * be marked so because of bad license files). 474 476 */ 475 if (RTManifestEntryExists(m->hOurManifest, szName)) 476 { 477 RTVFSFSSTREAM hTarFss; 478 char szError[8192]; 479 int vrc = VBoxExtPackOpenTarFss(m->hExtPackFile, szError, sizeof(szError), &hTarFss); 480 if (RT_SUCCESS(vrc)) 477 if (!m->fUsable) 478 hrc = setError(E_FAIL, tr("%s"), m->strWhyUnusable.c_str()); 479 else 480 { 481 /* 482 * Look it up in the manifest before scanning the tarball for it 483 */ 484 if (RTManifestEntryExists(m->hOurManifest, szName)) 481 485 { 482 for (;;) 486 RTVFSFSSTREAM hTarFss; 487 char szError[8192]; 488 int vrc = VBoxExtPackOpenTarFss(m->hExtPackFile, szError, sizeof(szError), &hTarFss); 489 if (RT_SUCCESS(vrc)) 483 490 { 484 /* Get the first/next. */ 485 char *pszName; 486 RTVFSOBJ hVfsObj; 487 RTVFSOBJTYPE enmType; 488 vrc = RTVfsFsStrmNext(hTarFss, &pszName, &enmType, &hVfsObj); 489 if (RT_FAILURE(vrc)) 491 for (;;) 490 492 { 491 if (vrc != VERR_EOF) 492 hrc = setError(VBOX_E_IPRT_ERROR, tr("RTVfsFsStrmNext failed: %Rrc"), vrc); 493 else 494 hrc = setError(E_UNEXPECTED, tr("'%s' was found in the manifest but not in the tarball"), szName); 495 break; 496 } 497 498 /* Is this it? */ 499 const char *pszAdjName = pszName[0] == '.' && pszName[1] == '/' ? &pszName[2] : pszName; 500 if ( !strcmp(pszAdjName, szName) 501 && ( enmType == RTVFSOBJTYPE_IO_STREAM 502 || enmType == RTVFSOBJTYPE_FILE)) 503 { 504 RTVFSIOSTREAM hVfsIos = RTVfsObjToIoStream(hVfsObj); 493 /* Get the first/next. */ 494 char *pszName; 495 RTVFSOBJ hVfsObj; 496 RTVFSOBJTYPE enmType; 497 vrc = RTVfsFsStrmNext(hTarFss, &pszName, &enmType, &hVfsObj); 498 if (RT_FAILURE(vrc)) 499 { 500 if (vrc != VERR_EOF) 501 hrc = setError(VBOX_E_IPRT_ERROR, tr("RTVfsFsStrmNext failed: %Rrc"), vrc); 502 else 503 hrc = setError(E_UNEXPECTED, tr("'%s' was found in the manifest but not in the tarball"), szName); 504 break; 505 } 506 507 /* Is this it? */ 508 const char *pszAdjName = pszName[0] == '.' && pszName[1] == '/' ? &pszName[2] : pszName; 509 if ( !strcmp(pszAdjName, szName) 510 && ( enmType == RTVFSOBJTYPE_IO_STREAM 511 || enmType == RTVFSOBJTYPE_FILE)) 512 { 513 RTVFSIOSTREAM hVfsIos = RTVfsObjToIoStream(hVfsObj); 514 RTVfsObjRelease(hVfsObj); 515 RTStrFree(pszName); 516 517 /* Load the file into memory. */ 518 RTFSOBJINFO ObjInfo; 519 vrc = RTVfsIoStrmQueryInfo(hVfsIos, &ObjInfo, RTFSOBJATTRADD_NOTHING); 520 if (RT_SUCCESS(vrc)) 521 { 522 size_t cbFile = (size_t)ObjInfo.cbObject; 523 void *pvFile = RTMemAllocZ(cbFile + 1); 524 if (pvFile) 525 { 526 vrc = RTVfsIoStrmRead(hVfsIos, pvFile, cbFile, true /*fBlocking*/, NULL); 527 if (RT_SUCCESS(vrc)) 528 { 529 /* try translate it into a string we can return. */ 530 Bstr bstrLicense((const char *)pvFile, cbFile); 531 if (bstrLicense.isNotEmpty()) 532 { 533 bstrLicense.detachTo(a_pbstrLicense); 534 hrc = S_OK; 535 } 536 else 537 hrc = setError(VBOX_E_IPRT_ERROR, 538 tr("The license file '%s' is empty or contains invalid UTF-8 encoding"), 539 szName); 540 } 541 else 542 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to read '%s': %Rrc"), szName, vrc); 543 RTMemFree(pvFile); 544 } 545 else 546 hrc = setError(E_OUTOFMEMORY, tr("Failed to allocate %zu bytes for '%s'"), cbFile, szName); 547 } 548 else 549 hrc = setError(VBOX_E_IPRT_ERROR, tr("RTVfsIoStrmQueryInfo on '%s': %Rrc"), szName, vrc); 550 RTVfsIoStrmRelease(hVfsIos); 551 break; 552 } 553 554 /* Release current. */ 505 555 RTVfsObjRelease(hVfsObj); 506 556 RTStrFree(pszName); 507 508 /* Load the file into memory. */509 RTFSOBJINFO ObjInfo;510 vrc = RTVfsIoStrmQueryInfo(hVfsIos, &ObjInfo, RTFSOBJATTRADD_NOTHING);511 if (RT_SUCCESS(vrc))512 {513 size_t cbFile = (size_t)ObjInfo.cbObject;514 void *pvFile = RTMemAllocZ(cbFile + 1);515 if (pvFile)516 {517 vrc = RTVfsIoStrmRead(hVfsIos, pvFile, cbFile, true /*fBlocking*/, NULL);518 if (RT_SUCCESS(vrc))519 {520 /* try translate it into a string we can return. */521 Bstr bstrLicense((const char *)pvFile, cbFile);522 if (bstrLicense.isNotEmpty())523 {524 bstrLicense.detachTo(a_pbstrLicense);525 hrc = S_OK;526 }527 else528 hrc = setError(VBOX_E_IPRT_ERROR,529 tr("The license file '%s' is empty or contains invalid UTF-8 encoding"),530 szName);531 }532 else533 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to read '%s': %Rrc"), szName, vrc);534 RTMemFree(pvFile);535 }536 else537 hrc = setError(E_OUTOFMEMORY, tr("Failed to allocate %zu bytes for '%s'"), cbFile, szName);538 }539 else540 hrc = setError(VBOX_E_IPRT_ERROR, tr("RTVfsIoStrmQueryInfo on '%s': %Rrc"), szName, vrc);541 RTVfsIoStrmRelease(hVfsIos);542 break;543 557 } 544 545 /* Release current. */ 546 RTVfsObjRelease(hVfsObj); 547 RTStrFree(pszName); 558 RTVfsFsStrmRelease(hTarFss); 548 559 } 549 RTVfsFsStrmRelease(hTarFss); 560 else 561 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("%s"), szError); 550 562 } 551 563 else 552 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("%s"), szError); 553 } 554 else 555 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The license file '%s' was not found in '%s'"), 556 szName, m->strExtPackFile.c_str()); 564 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The license file '%s' was not found in '%s'"), 565 szName, m->strExtPackFile.c_str()); 566 } 557 567 } 558 568 return hrc; … … 1627 1637 AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS); /* paranoia */ 1628 1638 1629 char szPath[RTPATH_MAX]; 1630 int vrc = RTPathJoin(szPath, sizeof(szPath), m->strExtPackPath.c_str(), szName); 1631 if (RT_SUCCESS(vrc)) 1632 { 1633 void *pvFile; 1634 size_t cbFile; 1635 vrc = RTFileReadAllEx(szPath, 0, RTFOFF_MAX, RTFILE_RDALL_O_DENY_READ, &pvFile, &cbFile); 1639 if (!m->fUsable) 1640 hrc = setError(E_FAIL, tr("%s"), m->strWhyUnusable.c_str()); 1641 else 1642 { 1643 char szPath[RTPATH_MAX]; 1644 int vrc = RTPathJoin(szPath, sizeof(szPath), m->strExtPackPath.c_str(), szName); 1636 1645 if (RT_SUCCESS(vrc)) 1637 1646 { 1638 Bstr bstrLicense((const char *)pvFile, cbFile); 1639 if (bstrLicense.isNotEmpty()) 1647 void *pvFile; 1648 size_t cbFile; 1649 vrc = RTFileReadAllEx(szPath, 0, RTFOFF_MAX, RTFILE_RDALL_O_DENY_READ, &pvFile, &cbFile); 1650 if (RT_SUCCESS(vrc)) 1640 1651 { 1641 bstrLicense.detachTo(a_pbstrLicense); 1642 hrc = S_OK; 1652 Bstr bstrLicense((const char *)pvFile, cbFile); 1653 if (bstrLicense.isNotEmpty()) 1654 { 1655 bstrLicense.detachTo(a_pbstrLicense); 1656 hrc = S_OK; 1657 } 1658 else 1659 hrc = setError(VBOX_E_IPRT_ERROR, tr("The license file '%s' is empty or contains invalid UTF-8 encoding"), 1660 szPath); 1661 RTFileReadAllFree(pvFile, cbFile); 1643 1662 } 1663 else if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND) 1664 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The license file '%s' was not found in extension pack '%s'"), 1665 szName, m->Desc.strName.c_str()); 1644 1666 else 1645 hrc = setError(VBOX_E_IPRT_ERROR, tr("The license file '%s' is empty or contains invalid UTF-8 encoding"), 1646 szPath); 1647 RTFileReadAllFree(pvFile, cbFile); 1667 hrc = setError(VBOX_E_FILE_ERROR, tr("Failed to open the license file '%s': %Rrc"), szPath, vrc); 1648 1668 } 1649 else if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND)1650 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The license file '%s' was not found in extension pack '%s'"),1651 szName, m->Desc.strName.c_str());1652 1669 else 1653 hrc = setError(VBOX_E_FILE_ERROR, tr("Failed to open the license file '%s': %Rrc"), szPath, vrc); 1654 } 1655 else 1656 hrc = setError(VBOX_E_IPRT_ERROR, tr("RTPathJoin failed: %Rrc"), vrc); 1670 hrc = setError(VBOX_E_IPRT_ERROR, tr("RTPathJoin failed: %Rrc"), vrc); 1671 } 1657 1672 } 1658 1673 return hrc;
Note:
See TracChangeset
for help on using the changeset viewer.