VirtualBox

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


Ignore:
Timestamp:
Mar 20, 2015 5:38:27 PM (10 years ago)
Author:
vboxsync
Message:

Main: Add a method to check for the correct encryption password

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

Legend:

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

    r54487 r54885  
    492492            { "clonevdi",         USAGE_CLONEMEDIUM,       handleCloneMedium }, /* backward compatibility */
    493493            { "encryptmedium",    USAGE_ENCRYPTMEDIUM,     handleEncryptMedium},
     494            { "checkmediumpwd",   USAGE_MEDIUMENCCHKPWD,   handleCheckMediumPassword},
    494495            { "createvm",         USAGE_CREATEVM,          handleCreateVM },
    495496            { "modifyvm",         USAGE_MODIFYVM,          handleModifyVM },
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r54487 r54885  
    106106#define USAGE_MEDIUMPROPERTY        RT_BIT_64(60)
    107107#define USAGE_ENCRYPTMEDIUM         RT_BIT_64(61)
     108#define USAGE_MEDIUMENCCHKPWD       RT_BIT_64(62)
    108109#define USAGE_ALL                   (~(uint64_t)0)
    109110/** @} */
     
    264265int handleMediumProperty(HandlerArg *a);
    265266int handleEncryptMedium(HandlerArg *a);
     267int handleCheckMediumPassword(HandlerArg *a);
    266268RTEXITCODE handleConvertFromRaw(int argc, char *argv[]);
    267269HRESULT showMediumInfo(const ComPtr<IVirtualBox> &pVirtualBox,
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r54854 r54885  
    18411841}
    18421842
     1843int handleCheckMediumPassword(HandlerArg *a)
     1844{
     1845    HRESULT rc;
     1846    int vrc;
     1847    ComPtr<IMedium> hardDisk;
     1848    const char *pszFilenameOrUuid = NULL;
     1849    Utf8Str strPassword;
     1850
     1851    if (a->argc != 2)
     1852        return errorSyntax(USAGE_MEDIUMENCCHKPWD, "Invalid number of arguments: %d", a->argc);
     1853
     1854    pszFilenameOrUuid = a->argv[0];
     1855
     1856    if (!RTStrCmp(a->argv[1], "-"))
     1857    {
     1858        /* Get password from console. */
     1859        vrc = getPassword("Enter password:", &strPassword);
     1860        if (RT_FAILURE(vrc))
     1861        {
     1862            RTMsgError("Failed to read password from standard input");
     1863            return 1;
     1864        }
     1865    }
     1866    else
     1867    {
     1868        RTEXITCODE rcExit = readPasswordFile(a->argv[1], &strPassword);
     1869        if (rcExit == RTEXITCODE_FAILURE)
     1870        {
     1871            RTMsgError("Failed to read password from file");
     1872            return rcExit;
     1873        }
     1874    }
     1875
     1876    /* Always open the medium if necessary, there is no other way. */
     1877    rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk,
     1878                    AccessMode_ReadWrite, hardDisk,
     1879                    false /* fForceNewUuidOnOpen */, false /* fSilent */);
     1880    if (FAILED(rc))
     1881        return 1;
     1882    if (hardDisk.isNull())
     1883    {
     1884        RTMsgError("Invalid hard disk reference, avoiding crash");
     1885        return 1;
     1886    }
     1887
     1888    CHECK_ERROR(hardDisk, CheckEncryptionPassword(Bstr(strPassword).raw()));
     1889    if (SUCCEEDED(rc))
     1890        RTPrintf("The given password is correct\n");
     1891    return SUCCEEDED(rc) ? 0 : 1;
     1892}
     1893
    18431894#endif /* !VBOX_ONLY_DOCS */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r54725 r54885  
    645645                     "\n", SEP);
    646646
     647    if (fCategory & USAGE_MEDIUMENCCHKPWD)
     648        RTStrmPrintf(pStrm,
     649                           "%s checkmediumpwd %s  <uuid|filename>\n"
     650                     "                            <pwd file>|-\n"
     651                     "\n", SEP);
     652
    647653    if (fCategory & USAGE_CONVERTFROMRAW)
    648654        RTStrmPrintf(pStrm,
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