VirtualBox

Changeset 54978 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Mar 26, 2015 8:49:26 PM (10 years ago)
Author:
vboxsync
Message:

Main/Console: Fix automatic unpausing a VM which has several disks configured with the same password when all passwords are provided

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r54976 r54978  
    33793379    if (RT_SUCCESS(rc))
    33803380    {
     3381        unsigned cDisksConfigured = 0;
    33813382        memcpy(pbKey, aPassword.c_str(), cbKey);
    33823383
     
    33873388        /* Add the key to the map */
    33883389        m_mapSecretKeys.insert(std::make_pair(aId, pKey));
    3389         hrc = i_configureEncryptionForDisk(aId);
     3390        hrc = i_configureEncryptionForDisk(aId, &cDisksConfigured);
    33903391        if (SUCCEEDED(hrc))
    33913392        {
    3392             if (   m_mapSecretKeys.size() == m_cDisksEncrypted
     3393            pKey->m_cDisks = cDisksConfigured;
     3394            m_cDisksPwProvided += cDisksConfigured;
     3395
     3396            if (   m_cDisksPwProvided == m_cDisksEncrypted
    33933397                && mMachineState == MachineState_Paused)
    33943398            {
     
    34453449        if (RT_SUCCESS(rc))
    34463450        {
     3451            unsigned cDisksConfigured = 0;
    34473452            memcpy(pbKey, aPasswords[i].c_str(), cbKey);
    34483453
     
    34533458            /* Add the key to the map */
    34543459            m_mapSecretKeys.insert(std::make_pair(aIds[i], pKey));
    3455             hrc = i_configureEncryptionForDisk(aIds[i]);
     3460            hrc = i_configureEncryptionForDisk(aIds[i], &cDisksConfigured);
    34563461            if (FAILED(hrc))
    34573462                m_mapSecretKeys.erase(aIds[i]);
     3463            else
     3464                pKey->m_cDisks = cDisksConfigured;
    34583465        }
    34593466        else
     
    34673474             */
    34683475            for (unsigned ii = 0; ii < i; ii++)
     3476            {
     3477                i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(aIds[ii]);
    34693478                removeDiskEncryptionPassword(aIds[ii]);
     3479            }
    34703480
    34713481            break;
     
    34743484
    34753485    if (   SUCCEEDED(hrc)
    3476         && m_mapSecretKeys.size() == m_cDisksEncrypted
     3486        && m_cDisksPwProvided == m_cDisksEncrypted
    34773487        && mMachineState == MachineState_Paused)
    34783488    {
     
    35083518        return setError(VBOX_E_OBJECT_IN_USE, tr("The password is still in use by the VM"));
    35093519
     3520    m_cDisksPwProvided -= pKey->m_cDisks;
    35103521    m_mapSecretKeys.erase(it);
    35113522    delete pKey;
     
    35343545        delete it->second;
    35353546    m_mapSecretKeys.clear();
     3547    m_cDisksPwProvided = 0;
    35363548
    35373549    return S_OK;
     
    48504862 *
    48514863 * @returns COM status code.
    4852  * @param   strId    The ID of the password.
     4864 * @param   strId                The ID of the password.
     4865 * @param   pcDisksConfigured    Where to store the number of disks configured for the given ID.
    48534866 */
    4854 HRESULT Console::i_configureEncryptionForDisk(const com::Utf8Str &strId)
    4855 {
     4867HRESULT Console::i_configureEncryptionForDisk(const com::Utf8Str &strId, unsigned *pcDisksConfigured)
     4868{
     4869    unsigned cDisksConfigured = 0;
    48564870    HRESULT hrc = S_OK;
    48574871    SafeIfaceArray<IMediumAttachment> sfaAttachments;
     
    49594973                        rc = pIMedium->pfnSetSecKeyIf(pIMedium, mpIfSecKey, mpIfSecKeyHlp);
    49604974                        if (rc == VERR_VD_PASSWORD_INCORRECT)
    4961                             return setError(VBOX_E_PASSWORD_INCORRECT, tr("The provided password for ID \"%s\" is not correct for at least one disk using this ID"),
    4962                                             strId.c_str());
     4975                        {
     4976                            hrc = setError(VBOX_E_PASSWORD_INCORRECT, tr("The provided password for ID \"%s\" is not correct for at least one disk using this ID"),
     4977                                           strId.c_str());
     4978                            break;
     4979                        }
    49634980                        else if (RT_FAILURE(rc))
    4964                             return setError(E_FAIL, tr("Failed to set the encryption key (%Rrc)"), rc);
     4981                        {
     4982                            hrc = setError(E_FAIL, tr("Failed to set the encryption key (%Rrc)"), rc);
     4983                            break;
     4984                        }
     4985
     4986                        if (RT_SUCCESS(rc))
     4987                           cDisksConfigured++;
    49654988                    }
    49664989                }
     
    49694992            }
    49704993        }
     4994    }
     4995
     4996    if (   SUCCEEDED(hrc)
     4997        && pcDisksConfigured)
     4998        *pcDisksConfigured = cDisksConfigured;
     4999    else if (FAILED(hrc))
     5000    {
     5001        /* Clear disk encryption setup on successfully configured attachments. */
     5002        i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(strId);
    49715003    }
    49725004
     
    50455077                    /* Add the key to the map */
    50465078                    m_mapSecretKeys.insert(std::make_pair(Utf8Str(pszUuid), pKey));
    5047                     hrc = i_configureEncryptionForDisk(Utf8Str(pszUuid));
     5079                    hrc = i_configureEncryptionForDisk(Utf8Str(pszUuid), NULL);
    50485080                    if (FAILED(hrc))
    50495081                    {
     
    51125144
    51135145            AssertMsg(!pKey->m_cRefs, ("No one should access the stored key at this point anymore!\n"));
     5146            m_cDisksPwProvided -= pKey->m_cDisks;
    51145147            delete pKey;
    51155148            m_mapSecretKeys.erase(it++);
     
    65076540    else if (   aReason == Reason_HostSuspend
    65086541             || aReason == Reason_HostBatteryLow)
     6542    {
     6543        alock.acquire();
    65096544        i_removeSecretKeysOnSuspend();
     6545    }
    65106546
    65116547    LogFlowThisFunc(("hrc=%Rhrc\n", hrc));
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