VirtualBox

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


Ignore:
Timestamp:
Mar 11, 2015 8:39:08 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
98893
Message:

FE/VBoxManage: Change the way passwords are provided when encrypting a medium. Instead of giving it directly on the command line read it from standard input or from a file

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

Legend:

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

    r54591 r54725  
    5252}
    5353
     54static int getPassword(const char *pszPrompt, Utf8Str *pPassword)
     55{
     56    char aszPwdInput[_1K] = { 0 };
     57
     58    int vrc = RTStrmPutStr(g_pStdOut, pszPrompt);
     59    if (RT_SUCCESS(vrc))
     60    {
     61        bool fEchoOld = false;
     62        vrc = RTStrmInputGetEchoChars(g_pStdIn, &fEchoOld);
     63        if (RT_SUCCESS(vrc))
     64        {
     65            vrc = RTStrmInputSetEchoChars(g_pStdIn, false);
     66            if (RT_SUCCESS(vrc))
     67            {
     68                vrc = RTStrmGetLine(g_pStdIn, &aszPwdInput[0], sizeof(aszPwdInput));
     69                if (RT_SUCCESS(vrc))
     70                    *pPassword = aszPwdInput;
     71
     72                int vrc2 = RTStrmInputSetEchoChars(g_pStdIn, fEchoOld);
     73                AssertRC(vrc2);
     74            }
     75        }
     76        RTStrmPutStr(g_pStdOut, "\n");
     77    }
     78
     79    return vrc;
     80}
    5481
    5582static int parseMediumVariant(const char *psz, MediumVariant_T *pMediumVariant)
     
    16571684    const char *pszFilenameOrUuid = NULL;
    16581685    const char *pszNewPasswordId = NULL;
     1686    Utf8Str strPasswordNew;
     1687    Utf8Str strPasswordOld;
    16591688
    16601689    int c;
     
    17181747        return errorSyntax(USAGE_ENCRYPTMEDIUM, "A new password must always have a valid identifier set at the same time");
    17191748
     1749    if (pszPasswordNew)
     1750    {
     1751        if (!RTStrCmp(pszPasswordNew, "-"))
     1752        {
     1753            /* Get password from console. */
     1754            vrc = getPassword("Enter new password:", &strPasswordNew);
     1755            if (RT_FAILURE(vrc))
     1756            {
     1757                RTMsgError("Failed to read new password from standard input");
     1758                return 1;
     1759            }
     1760        }
     1761        else
     1762        {
     1763            RTEXITCODE rcExit = readPasswordFile(pszPasswordNew, &strPasswordNew);
     1764            if (rcExit == RTEXITCODE_FAILURE)
     1765            {
     1766                RTMsgError("Failed to read new password from file");
     1767                return rcExit;
     1768            }
     1769        }
     1770    }
     1771
     1772    if (pszPasswordOld)
     1773    {
     1774        if (!RTStrCmp(pszPasswordOld, "-"))
     1775        {
     1776            /* Get password from console. */
     1777            vrc = getPassword("Enter old password:", &strPasswordOld);
     1778            if (RT_FAILURE(vrc))
     1779            {
     1780                RTMsgError("Failed to read old password from standard input");
     1781                return 1;
     1782            }
     1783        }
     1784        else
     1785        {
     1786            RTEXITCODE rcExit = readPasswordFile(pszPasswordOld, &strPasswordOld);
     1787            if (rcExit == RTEXITCODE_FAILURE)
     1788            {
     1789                RTMsgError("Failed to read old password from file");
     1790                return rcExit;
     1791            }
     1792        }
     1793    }
     1794
    17201795    /* Always open the medium if necessary, there is no other way. */
    17211796    rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk,
     
    17311806
    17321807    ComPtr<IProgress> progress;
    1733     CHECK_ERROR(hardDisk, ChangeEncryption(Bstr(pszPasswordNew).raw(), Bstr(pszPasswordOld).raw(),
     1808    CHECK_ERROR(hardDisk, ChangeEncryption(Bstr(strPasswordNew).raw(), Bstr(strPasswordOld).raw(),
    17341809                                           Bstr(pszCipher).raw(), Bstr(pszNewPasswordId).raw(),
    17351810                                           progress.asOutParam()));
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r54591 r54725  
    639639        RTStrmPrintf(pStrm,
    640640                           "%s encryptmedium %s   <uuid|filename>\n"
    641                      "                            [--newpassword <new password>]\n"
    642                      "                            [--oldpassword <old password>]\n"
     641                     "                            [--newpassword <file>|-]\n"
     642                     "                            [--oldpassword <file>|-]\n"
    643643                     "                            [--cipher <cipher identifier>]\n"
    644644                     "                            [--newpasswordid <password identifier>]\n"
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