VirtualBox

Changeset 54487 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 25, 2015 12:50:45 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
98595
Message:

FE/VBoxManage: Add support for medium encryption

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r54438 r54487  
    491491            { "clonehd",          USAGE_CLONEMEDIUM,       handleCloneMedium }, /* backward compatibility */
    492492            { "clonevdi",         USAGE_CLONEMEDIUM,       handleCloneMedium }, /* backward compatibility */
     493            { "encryptmedium",    USAGE_ENCRYPTMEDIUM,     handleEncryptMedium},
    493494            { "createvm",         USAGE_CREATEVM,          handleCreateVM },
    494495            { "modifyvm",         USAGE_MODIFYVM,          handleModifyVM },
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r54438 r54487  
    105105#define USAGE_NATNETWORK            RT_BIT_64(59)
    106106#define USAGE_MEDIUMPROPERTY        RT_BIT_64(60)
     107#define USAGE_ENCRYPTMEDIUM         RT_BIT_64(61)
    107108#define USAGE_ALL                   (~(uint64_t)0)
    108109/** @} */
     
    262263int handleCloneMedium(HandlerArg *a);
    263264int handleMediumProperty(HandlerArg *a);
     265int handleEncryptMedium(HandlerArg *a);
    264266RTEXITCODE handleConvertFromRaw(int argc, char *argv[]);
    265267HRESULT showMediumInfo(const ComPtr<IVirtualBox> &pVirtualBox,
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r54443 r54487  
    16331633}
    16341634
     1635static const RTGETOPTDEF g_aEncryptMediumOptions[] =
     1636{
     1637    { "--newpassword",  'n', RTGETOPT_REQ_STRING },
     1638    { "--oldpassword",  'o', RTGETOPT_REQ_STRING },
     1639    { "--cipher",       'c', RTGETOPT_REQ_STRING }
     1640};
     1641
     1642int handleEncryptMedium(HandlerArg *a)
     1643{
     1644    HRESULT rc;
     1645    int vrc;
     1646    ComPtr<IMedium> hardDisk;
     1647    const char *pszPasswordNew = NULL;
     1648    const char *pszPasswordOld = NULL;
     1649    const char *pszCipher = NULL;
     1650    const char *pszFilenameOrUuid = NULL;
     1651
     1652    int c;
     1653    RTGETOPTUNION ValueUnion;
     1654    RTGETOPTSTATE GetState;
     1655    // start at 0 because main() has hacked both the argc and argv given to us
     1656    RTGetOptInit(&GetState, a->argc, a->argv, g_aEncryptMediumOptions, RT_ELEMENTS(g_aEncryptMediumOptions),
     1657                 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
     1658    while ((c = RTGetOpt(&GetState, &ValueUnion)))
     1659    {
     1660        switch (c)
     1661        {
     1662            case 'n':   // --newpassword
     1663                pszPasswordNew = ValueUnion.psz;
     1664                break;
     1665
     1666            case 'o':   // --oldpassword
     1667                pszPasswordOld = ValueUnion.psz;
     1668                break;
     1669
     1670            case 'c':   // --cipher
     1671                pszCipher = ValueUnion.psz;
     1672                break;
     1673
     1674            case VINF_GETOPT_NOT_OPTION:
     1675                if (!pszFilenameOrUuid)
     1676                    pszFilenameOrUuid = ValueUnion.psz;
     1677                else
     1678                    return errorSyntax(USAGE_ENCRYPTMEDIUM, "Invalid parameter '%s'", ValueUnion.psz);
     1679                break;
     1680
     1681            default:
     1682                if (c > 0)
     1683                {
     1684                    if (RT_C_IS_PRINT(c))
     1685                        return errorSyntax(USAGE_ENCRYPTMEDIUM, "Invalid option -%c", c);
     1686                    else
     1687                        return errorSyntax(USAGE_ENCRYPTMEDIUM, "Invalid option case %i", c);
     1688                }
     1689                else if (c == VERR_GETOPT_UNKNOWN_OPTION)
     1690                    return errorSyntax(USAGE_ENCRYPTMEDIUM, "unknown option: %s\n", ValueUnion.psz);
     1691                else if (ValueUnion.pDef)
     1692                    return errorSyntax(USAGE_ENCRYPTMEDIUM, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
     1693                else
     1694                    return errorSyntax(USAGE_ENCRYPTMEDIUM, "error: %Rrs", c);
     1695        }
     1696    }
     1697
     1698    if (!pszFilenameOrUuid)
     1699        return errorSyntax(USAGE_ENCRYPTMEDIUM, "Disk name or UUID required");
     1700
     1701    if (!pszPasswordNew && !pszPasswordOld)
     1702        return errorSyntax(USAGE_ENCRYPTMEDIUM, "No password specified");
     1703
     1704    /* Always open the medium if necessary, there is no other way. */
     1705    rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk,
     1706                    AccessMode_ReadWrite, hardDisk,
     1707                    false /* fForceNewUuidOnOpen */, false /* fSilent */);
     1708    if (FAILED(rc))
     1709        return 1;
     1710    if (hardDisk.isNull())
     1711    {
     1712        RTMsgError("Invalid hard disk reference, avoiding crash");
     1713        return 1;
     1714    }
     1715
     1716    ComPtr<IProgress> progress;
     1717    CHECK_ERROR(hardDisk, ChangeEncryption(Bstr(pszPasswordNew).raw(), Bstr(pszPasswordOld).raw(),
     1718                                           Bstr(pszCipher).raw(), progress.asOutParam()));
     1719    if (SUCCEEDED(rc))
     1720        rc = showProgress(progress);
     1721    if (FAILED(rc))
     1722    {
     1723        if (rc == E_NOTIMPL)
     1724            RTMsgError("Encrypt hard disk operation is not implemented!");
     1725        else if (rc == VBOX_E_NOT_SUPPORTED)
     1726            RTMsgError("Encrypt hard disk operation for this cipher is not implemented yet!");
     1727        else if (!progress.isNull())
     1728            CHECK_PROGRESS_ERROR(progress, ("Failed to encrypt hard disk"));
     1729        else
     1730            RTMsgError("Failed to encrypt hard disk!");
     1731    }
     1732
     1733    return SUCCEEDED(rc) ? 0 : 1;
     1734}
     1735
    16351736#endif /* !VBOX_ONLY_DOCS */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r54438 r54487  
    631631                     "\n", SEP);
    632632
     633    if (fCategory & USAGE_ENCRYPTMEDIUM)
     634        RTStrmPrintf(pStrm,
     635                           "%s encryptmedium %s   <uuid|filename>\n"
     636                     "                            [--newpassword <new password>]\n"
     637                     "                            [--oldpassword <old password>]\n"
     638                     "                            [--cipher <cipher identifier>]\n"
     639                     "\n", SEP);
     640
    633641    if (fCategory & USAGE_CONVERTFROMRAW)
    634642        RTStrmPrintf(pStrm,
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette