bool UIWizardExportApp::exportVMs(CAppliance &appliance)
{
/* Get the map of the password IDs: */
EncryptedMediumMap encryptedMediums;
foreach (const QString &strPasswordId, appliance.GetPasswordIds())
foreach (const QString &strMediumId, appliance.GetMediumIdsForPasswordId(strPasswordId))
encryptedMediums.insert(strPasswordId, strMediumId);
/* Ask for the disk encryption passwords if necessary: */
if (!encryptedMediums.isEmpty())
{
/* Create corresponding dialog: */
QPointer<UIAddDiskEncryptionPasswordDialog> pDlg =
new UIAddDiskEncryptionPasswordDialog(this,
window()->windowTitle(),
encryptedMediums);
/* Execute the dialog: */
if (pDlg->exec() == QDialog::Accepted)
{
/* Acquire the passwords provided: */
const EncryptionPasswordMap encryptionPasswords = pDlg->encryptionPasswords();
/* Delete the dialog: */
delete pDlg;
/* Make sure the passwords were really provided: */
AssertReturn(!encryptionPasswords.isEmpty(), false);
/* Provide appliance with passwords if possible: */
appliance.AddPasswords(encryptionPasswords.keys().toVector(),
encryptionPasswords.values().toVector());
if (!appliance.isOk())
{
/* Warn the user about failure: */
msgCenter().cannotAddDiskEncryptionPassword(appliance);
return false;
}
}
else
{
/* Any modal dialog can be destroyed in own event-loop
* as a part of application termination procedure..
* We have to check if the dialog still valid. */
if (pDlg)
{
/* Delete the dialog: */
delete pDlg;
}
return false;
}
}
/* Write the appliance: */
QVector<KExportOptions> options;
if (field("manifestSelected").toBool())
options.append(KExportOptions_CreateManifest);
CProgress progress = appliance.Write(field("format").toString(), options, uri());
bool fResult = appliance.isOk();
if (fResult)
{
/* Show some progress, so the user know whats going on: */
msgCenter().showModalProgressDialog(progress, QApplication::translate("UIWizardExportApp", "Exporting Appliance ..."),
":/progress_export_90px.png", this);
if (progress.GetCanceled())
return false;
if (!progress.isOk() || progress.GetResultCode() != 0)
{
msgCenter().cannotExportAppliance(progress, appliance.GetPath(), this);
return false;
}
else
return true;
}
if (!fResult)
msgCenter().cannotExportAppliance(appliance, this);
return false;
}
/**
* Worker for RTSemEventWaitEx and RTSemEventWaitExDebug.
*
* @returns VBox status code.
* @param pThis The event semaphore.
* @param fFlags See RTSemEventWaitEx.
* @param uTimeout See RTSemEventWaitEx.
* @param pSrcPos The source code position of the wait.
*/
static int rtR0SemEventLnxWait(PRTSEMEVENTINTERNAL pThis, uint32_t fFlags, uint64_t uTimeout,
PCRTLOCKVALSRCPOS pSrcPos)
{
int rc;
/*
* Validate the input.
*/
AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
AssertReturn(RTSEMWAIT_FLAGS_ARE_VALID(fFlags), VERR_INVALID_PARAMETER);
rtR0SemEventLnxRetain(pThis);
/*
* Try grab the event without setting up the wait.
*/
if ( 1 /** @todo check if there are someone waiting already - waitqueue_active, but then what do we do below? */
&& ASMAtomicCmpXchgU32(&pThis->fState, 0, 1))
rc = VINF_SUCCESS;
else
{
/*
* We have to wait.
*/
IPRT_LINUX_SAVE_EFL_AC();
RTR0SEMLNXWAIT Wait;
rc = rtR0SemLnxWaitInit(&Wait, fFlags, uTimeout, &pThis->Head);
if (RT_SUCCESS(rc))
{
IPRT_DEBUG_SEMS_STATE(pThis, 'E');
for (;;)
{
/* The destruction test. */
if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENT_MAGIC))
rc = VERR_SEM_DESTROYED;
else
{
rtR0SemLnxWaitPrepare(&Wait);
/* Check the exit conditions. */
if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENT_MAGIC))
rc = VERR_SEM_DESTROYED;
else if (ASMAtomicCmpXchgU32(&pThis->fState, 0, 1))
rc = VINF_SUCCESS;
else if (rtR0SemLnxWaitHasTimedOut(&Wait))
rc = VERR_TIMEOUT;
else if (rtR0SemLnxWaitWasInterrupted(&Wait))
rc = VERR_INTERRUPTED;
else
{
/* Do the wait and then recheck the conditions. */
rtR0SemLnxWaitDoIt(&Wait);
continue;
}
}
break;
}
rtR0SemLnxWaitDelete(&Wait);
IPRT_DEBUG_SEMS_STATE_RC(pThis, 'E', rc);
}
IPRT_LINUX_RESTORE_EFL_AC();
}
rtR0SemEventLnxRelease(pThis);
return rc;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Reference register (unary).}
*/
DECLCALLBACK(int) dbgcOpRegister(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
LogFlow(("dbgcOpRegister: %s\n", pArg->u.pszString));
AssertReturn(pArg->enmType == DBGCVAR_TYPE_SYMBOL, VERR_DBGC_PARSE_BUG);
/* Detect references to hypervisor registers. */
const char *pszReg = pArg->u.pszString;
VMCPUID idCpu = pDbgc->idCpu;
if (pszReg[0] == '.')
{
pszReg++;
idCpu |= DBGFREG_HYPER_VMCPUID;
}
/*
* If the desired result is a symbol, pass the argument along unmodified.
* This is a great help for "r @eax" and such, since it will be translated to "r eax".
*/
if (enmCat == DBGCVAR_CAT_SYMBOL)
{
int rc = DBGFR3RegNmValidate(pDbgc->pUVM, idCpu, pszReg);
if (RT_SUCCESS(rc))
DBGCVAR_INIT_STRING(pResult, pArg->u.pszString);
return rc;
}
/*
* Get the register.
*/
DBGFREGVALTYPE enmType;
DBGFREGVAL Value;
int rc = DBGFR3RegNmQuery(pDbgc->pUVM, idCpu, pszReg, &Value, &enmType);
if (RT_SUCCESS(rc))
{
switch (enmType)
{
case DBGFREGVALTYPE_U8:
DBGCVAR_INIT_NUMBER(pResult, Value.u8);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U16:
DBGCVAR_INIT_NUMBER(pResult, Value.u16);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U32:
DBGCVAR_INIT_NUMBER(pResult, Value.u32);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U64:
DBGCVAR_INIT_NUMBER(pResult, Value.u64);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U128:
DBGCVAR_INIT_NUMBER(pResult, Value.u128.s.Lo);
return VINF_SUCCESS;
case DBGFREGVALTYPE_R80:
#ifdef RT_COMPILER_WITH_80BIT_LONG_DOUBLE
DBGCVAR_INIT_NUMBER(pResult, (uint64_t)Value.r80Ex.lrd);
#else
DBGCVAR_INIT_NUMBER(pResult, (uint64_t)Value.r80Ex.sj64.u63Fraction);
#endif
return VINF_SUCCESS;
case DBGFREGVALTYPE_DTR:
DBGCVAR_INIT_NUMBER(pResult, Value.dtr.u64Base);
return VINF_SUCCESS;
case DBGFREGVALTYPE_INVALID:
case DBGFREGVALTYPE_END:
case DBGFREGVALTYPE_32BIT_HACK:
break;
}
rc = VERR_INTERNAL_ERROR_5;
}
return rc;
}
/**
* Internal helper for rtZipGzip_Write, rtZipGzip_Flush and rtZipGzip_Close.
*
* @returns IPRT status code.
* @retval VINF_SUCCESS
* @retval VINF_TRY_AGAIN - the only informational status.
* @retval VERR_INTERRUPTED - call again.
*
* @param pThis The gzip I/O stream instance data.
* @param fBlocking Whether to block or not.
*/
static int rtZipGzip_WriteOutputBuffer(PRTZIPGZIPSTREAM pThis, bool fBlocking)
{
/*
* Anything to write? No, then just return immediately.
*/
size_t cbToWrite = sizeof(pThis->abBuffer) - pThis->Zlib.avail_out;
if (cbToWrite == 0)
{
Assert(pThis->Zlib.next_out == &pThis->abBuffer[0]);
return VINF_SUCCESS;
}
Assert(cbToWrite <= sizeof(pThis->abBuffer));
/*
* Loop write on VERR_INTERRUPTED.
*
* Note! Asserting a bit extra here to make sure the
* RTVfsIoStrmSgWrite works correctly.
*/
int rc;
size_t cbWrittenOut;
for (;;)
{
/* Set up the buffer. */
pThis->SgSeg.cbSeg = cbToWrite;
Assert(pThis->SgSeg.pvSeg == &pThis->abBuffer[0]);
RTSgBufReset(&pThis->SgBuf);
cbWrittenOut = ~(size_t)0;
rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, &pThis->SgBuf, fBlocking, &cbWrittenOut);
if (rc != VINF_SUCCESS)
{
AssertMsg(RT_FAILURE(rc) || rc == VINF_TRY_AGAIN, ("%Rrc\n", rc));
if (rc == VERR_INTERRUPTED)
{
Assert(cbWrittenOut == 0);
continue;
}
if (RT_FAILURE(rc) || rc == VINF_TRY_AGAIN || cbWrittenOut == 0)
{
AssertReturn(cbWrittenOut == 0, VERR_INTERNAL_ERROR_3);
AssertReturn(rc != VINF_SUCCESS, VERR_IPE_UNEXPECTED_INFO_STATUS);
return rc;
}
}
break;
}
AssertMsgReturn(cbWrittenOut > 0 && cbWrittenOut <= sizeof(pThis->abBuffer),
("%zu %Rrc\n", cbWrittenOut, rc),
VERR_INTERNAL_ERROR_4);
/*
* Adjust the Zlib output buffer members.
*/
if (cbWrittenOut == pThis->SgBuf.paSegs[0].cbSeg)
{
pThis->Zlib.avail_out = sizeof(pThis->abBuffer);
pThis->Zlib.next_out = &pThis->abBuffer[0];
}
else
{
Assert(cbWrittenOut <= pThis->SgBuf.paSegs[0].cbSeg);
size_t cbLeft = pThis->SgBuf.paSegs[0].cbSeg - cbWrittenOut;
memmove(&pThis->abBuffer[0], &pThis->abBuffer[cbWrittenOut], cbLeft);
pThis->Zlib.avail_out += (uInt)cbWrittenOut;
pThis->Zlib.next_out = &pThis->abBuffer[cbWrittenOut];
}
return VINF_SUCCESS;
}
开发者ID:mcenirm,项目名称:vbox,代码行数:81,代码来源:gzipvfs.cpp
示例8: RTDECL
RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs)
{
int rc = VINF_SUCCESS;
/*
* Parameter validation.
*/
PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
RTFILEAIOCTX_VALID_RETURN(pCtxInt);
AssertReturn(cReqs > 0, VERR_INVALID_PARAMETER);
AssertPtrReturn(pahReqs, VERR_INVALID_POINTER);
uint32_t i = cReqs;
PRTFILEAIOREQINTERNAL pReqInt = NULL;
/*
* Validate requests and associate with the context.
*/
while (i-- > 0)
{
pReqInt = pahReqs[i];
if (RTFILEAIOREQ_IS_NOT_VALID(pReqInt))
{
/* Undo everything and stop submitting. */
size_t iUndo = cReqs;
while (iUndo-- > i)
{
pReqInt = pahReqs[iUndo];
RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
pReqInt->pCtxInt = NULL;
}
return VERR_INVALID_HANDLE;
}
pReqInt->AioContext = pCtxInt->AioContext;
pReqInt->pCtxInt = pCtxInt;
RTFILEAIOREQ_SET_STATE(pReqInt, SUBMITTED);
}
do
{
/*
* We cast pahReqs to the Linux iocb structure to avoid copying the requests
* into a temporary array. This is possible because the iocb structure is
* the first element in the request structure (see PRTFILEAIOCTXINTERNAL).
*/
int cReqsSubmitted = 0;
rc = rtFileAsyncIoLinuxSubmit(pCtxInt->AioContext, cReqs,
(PLNXKAIOIOCB *)pahReqs,
&cReqsSubmitted);
if (RT_FAILURE(rc))
{
/*
* We encountered an error.
* This means that the first IoCB
* is not correctly initialized
* (invalid buffer alignment or bad file descriptor).
* Revert every request into the prepared state except
* the first one which will switch to completed.
* Another reason could be insufficient resources.
*/
i = cReqs;
while (i-- > 0)
{
/* Already validated. */
pReqInt = pahReqs[i];
pReqInt->pCtxInt = NULL;
pReqInt->AioContext = 0;
RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
}
if (rc == VERR_TRY_AGAIN)
return VERR_FILE_AIO_INSUFFICIENT_RESSOURCES;
else
{
/* The first request failed. */
pReqInt = pahReqs[0];
RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
pReqInt->Rc = rc;
pReqInt->cbTransfered = 0;
return rc;
}
}
/* Advance. */
cReqs -= cReqsSubmitted;
pahReqs += cReqsSubmitted;
ASMAtomicAddS32(&pCtxInt->cRequests, cReqsSubmitted);
} while (cReqs);
return rc;
}
/**
* Deals with authenticated attributes.
*
* When authenticated attributes are present (checked by caller) we must:
* - fish out the content type and check it against the content inof,
* - fish out the message digest among and check it against *phDigest,
* - compute the message digest of the authenticated attributes and
* replace *phDigest with this for the signature verification.
*
* @returns IPRT status code.
* @param pSignerInfo The signer info being verified.
* @param pSignedData The signed data.
* @param phDigest On input this is the digest of the content. On
* output it will (on success) be a reference to
* the message digest of the authenticated
* attributes. The input reference is consumed.
* The caller shall release the output reference.
* @param fFlags Flags.
* @param pErrInfo Extended error info, optional.
*/
static int rtCrPkcs7VerifySignerInfoAuthAttribs(PCRTCRPKCS7SIGNERINFO pSignerInfo, PCRTCRPKCS7SIGNEDDATA pSignedData,
PRTCRDIGEST phDigest, uint32_t fFlags, PRTERRINFO pErrInfo)
{
/*
* Scan the attributes and validate the two required attributes
* (RFC-2315, chapter 9.2, fourth bullet). Checking that we've got exactly
* one of each of them is checked by the santiy checker function, so we'll
* just assert that it did it's job here.
*/
uint32_t cContentTypes = 0;
uint32_t cMessageDigests = 0;
uint32_t i = pSignerInfo->AuthenticatedAttributes.cItems;
while (i-- > 0)
{
PCRTCRPKCS7ATTRIBUTE pAttrib = &pSignerInfo->AuthenticatedAttributes.paItems[i];
if (RTAsn1ObjId_CompareWithString(&pAttrib->Type, RTCR_PKCS9_ID_CONTENT_TYPE_OID) == 0)
{
AssertReturn(!cContentTypes, VERR_CR_PKCS7_INTERNAL_ERROR);
AssertReturn(pAttrib->enmType == RTCRPKCS7ATTRIBUTETYPE_OBJ_IDS, VERR_CR_PKCS7_INTERNAL_ERROR);
AssertReturn(pAttrib->uValues.pObjIds->cItems == 1, VERR_CR_PKCS7_INTERNAL_ERROR);
if ( !(fFlags & RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE) /* See note about microsoft below. */
&& RTAsn1ObjId_Compare(&pAttrib->uValues.pObjIds->paItems[0], &pSignedData->ContentInfo.ContentType) != 0)
return RTErrInfoSetF(pErrInfo, VERR_CR_PKCS7_CONTENT_TYPE_ATTRIB_MISMATCH,
"Expected content-type %s, found %s",
&pAttrib->uValues.pObjIds->paItems[0], pSignedData->ContentInfo.ContentType.szObjId);
cContentTypes++;
}
else if (RTAsn1ObjId_CompareWithString(&pAttrib->Type, RTCR_PKCS9_ID_MESSAGE_DIGEST_OID) == 0)
{
AssertReturn(!cMessageDigests, VERR_CR_PKCS7_INTERNAL_ERROR);
AssertReturn(pAttrib->enmType == RTCRPKCS7ATTRIBUTETYPE_OCTET_STRINGS, VERR_CR_PKCS7_INTERNAL_ERROR);
AssertReturn(pAttrib->uValues.pOctetStrings->cItems == 1, VERR_CR_PKCS7_INTERNAL_ERROR);
if (!RTCrDigestMatch(*phDigest,
pAttrib->uValues.pOctetStrings->paItems[0].Asn1Core.uData.pv,
pAttrib->uValues.pOctetStrings->paItems[0].Asn1Core.cb))
{
size_t cbHash = RTCrDigestGetHashSize(*phDigest);
if (cbHash != pAttrib->uValues.pOctetStrings->paItems[0].Asn1Core.cb)
return RTErrInfoSetF(pErrInfo, VERR_CR_PKCS7_MESSAGE_DIGEST_ATTRIB_MISMATCH,
"Authenticated message-digest attribute mismatch: cbHash=%#zx cbValue=%#x",
cbHash, pAttrib->uValues.pOctetStrings->paItems[0].Asn1Core.cb);
return RTErrInfoSetF(pErrInfo, VERR_CR_PKCS7_MESSAGE_DIGEST_ATTRIB_MISMATCH,
"Authenticated message-digest attribute mismatch (cbHash=%#zx):\n"
"signed: %.*Rhxs\n"
"our: %.*Rhxs\n",
cbHash,
cbHash, pAttrib->uValues.pOctetStrings->paItems[0].Asn1Core.uData.pv,
cbHash, RTCrDigestGetHash(*phDigest));
}
cMessageDigests++;
}
}
/*
* Full error reporting here as we don't currently extensively santiy check
* counter signatures.
* Note! Microsoft includes content info in their timestamp counter signatures,
* at least for vista, despite the RFC-3852 stating counter signatures
* "MUST NOT contain a content-type".
*/
if (RT_UNLIKELY( cContentTypes != 1
&& !(fFlags & RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE)))
return RTErrInfoSet(pErrInfo, VERR_CR_PKCS7_MISSING_CONTENT_TYPE_ATTRIB,
"Missing authenticated content-type attribute.");
if (RT_UNLIKELY(cMessageDigests != 1))
return RTErrInfoSet(pErrInfo, VERR_CR_PKCS7_MISSING_MESSAGE_DIGEST_ATTRIB,
"Missing authenticated message-digest attribute.");
/*
* Calculate the digest of the the authenticated attributes for use in the
* signature validation.
*/
if ( pSignerInfo->DigestAlgorithm.Parameters.enmType != RTASN1TYPE_NULL
&& pSignerInfo->DigestAlgorithm.Parameters.enmType != RTASN1TYPE_NOT_PRESENT)
return RTErrInfoSet(pErrInfo, VERR_CR_PKCS7_DIGEST_PARAMS_NOT_IMPL, "Digest algorithm has unsupported parameters");
RTCRDIGEST hDigest;
//.........这里部分代码省略.........
STDMETHODIMP Session::AssignRemoteMachine(IMachine *aMachine, IConsole *aConsole)
{
LogFlowThisFuncEnter();
LogFlowThisFunc(("aMachine=%p, aConsole=%p\n", aMachine, aConsole));
AssertReturn(aMachine && aConsole, E_INVALIDARG);
AutoCaller autoCaller(this);
AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
AssertReturn(mState == SessionState_Unlocked ||
mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
HRESULT rc = E_FAIL;
/* query IInternalMachineControl interface */
mControl = aMachine;
AssertReturn(!!mControl, E_FAIL);
/// @todo (dmik)
// currently, the remote session returns the same machine and
// console objects as the direct session, thus giving the
// (remote) client full control over the direct session. For the
// console, it is the desired behavior (the ability to control
// VM execution is a must for the remote session). What about
// the machine object, we may want to prevent the remote client
// from modifying machine data. In this case, we must:
// 1) assign the Machine object (instead of the SessionMachine
// object that is passed to this method) to mRemoteMachine;
// 2) remove GetMachine() property from the IConsole interface
// because it always returns the SessionMachine object
// (alternatively, we can supply a separate IConsole
// implementation that will return the Machine object in
// response to GetMachine()).
mRemoteMachine = aMachine;
mRemoteConsole = aConsole;
/*
* Reference the VirtualBox object to ensure the server is up
* until the session is closed
*/
rc = aMachine->COMGETTER(Parent)(mVirtualBox.asOutParam());
if (SUCCEEDED(rc))
{
/*
* RemoteSession type can be already set by AssignMachine() when its
* argument is NULL (a special case)
*/
if (mType != SessionType_Remote)
mType = SessionType_Shared;
else
Assert(mState == SessionState_Spawning);
mState = SessionState_Locked;
}
else
{
/* some cleanup */
mControl.setNull();
mRemoteMachine.setNull();
mRemoteConsole.setNull();
}
LogFlowThisFunc(("rc=%08X\n", rc));
LogFlowThisFuncLeave();
return rc;
}
请发表评论