VirtualBox

Ignore:
Timestamp:
Feb 22, 2024 2:05:31 PM (15 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
161878
Message:

VBoxManage: Add subcommand for enabling UEFI secure boot (and show the status in the VM infos).
Main/NVRAMStore+UefiVariableStore: Tweaks to allow reading the UEFI secure boot state when the VM isn't mutable.
doc/manual: Update VBoxManage manpage.

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

Legend:

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

    r101125 r103532  
    14141414    if (bstrNVRAMFile.isNotEmpty())
    14151415        SHOW_BSTR_STRING("BIOS NVRAM File", Info::tr("BIOS NVRAM File:"), bstrNVRAMFile);
     1416    if (   firmwareType == FirmwareType_EFI || firmwareType == FirmwareType_EFI32
     1417        || firmwareType == FirmwareType_EFI64 || firmwareType == FirmwareType_EFIDUAL)
     1418    {
     1419        ComPtr<IUefiVariableStore> uefiVarStore;
     1420        CHECK_ERROR_RET(nvramStore, COMGETTER(UefiVariableStore)(uefiVarStore.asOutParam()), hrc);
     1421        SHOW_BOOLEAN_PROP(uefiVarStore, SecureBootEnabled, "SecureBoot", Info::tr("UEFI Secure Boot:"));
     1422    }
    14161423    SHOW_BOOLEAN_PROP_EX(platform,   RTCUseUTC, "rtcuseutc", Info::tr("RTC:"), "UTC", Info::tr("local time"));
    14171424
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyNvram.cpp

    r98988 r103532  
    6464static RTEXITCODE handleModifyNvramInitUefiVarStore(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    6565{
    66     RT_NOREF(a);
     66    if (a->argc != 2)
     67        return errorTooManyParameters(&a->argv[1]);
    6768
    6869    CHECK_ERROR2I_RET(nvramStore, InitUefiVariableStore(0 /*aSize*/), RTEXITCODE_FAILURE);
     
    7980static RTEXITCODE handleModifyNvramEnrollMsSignatures(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    8081{
    81     RT_NOREF(a);
     82    if (a->argc != 2)
     83        return errorTooManyParameters(&a->argv[1]);
    8284
    8385    ComPtr<IUefiVariableStore> uefiVarStore;
     
    252254static RTEXITCODE handleModifyNvramEnrollOraclePlatformKey(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    253255{
    254     RT_NOREF(a);
     256    if (a->argc != 2)
     257        return errorTooManyParameters(&a->argv[1]);
    255258
    256259    ComPtr<IUefiVariableStore> uefiVarStore;
     
    263266
    264267/**
     268 * Handles the 'modifynvram myvm secureboot' sub-command.
     269 * @returns Exit code.
     270 * @param   a               The handler argument package.
     271 * @param   nvram           Reference to the NVRAM store interface.
     272 */
     273static RTEXITCODE handleModifyNvramSecureBoot(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
     274{
     275    static const RTGETOPTDEF s_aOptions[] =
     276    {
     277        /* common options */
     278        { "--enable",       'e', RTGETOPT_REQ_NOTHING },
     279        { "--disable",      'd', RTGETOPT_REQ_NOTHING }
     280    };
     281
     282    int enable = -1;
     283
     284    RTGETOPTSTATE GetState;
     285    int vrc = RTGetOptInit(&GetState, a->argc - 2, &a->argv[2], s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0);
     286    AssertRCReturn(vrc, RTEXITCODE_FAILURE);
     287
     288    int c;
     289    RTGETOPTUNION ValueUnion;
     290    while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
     291    {
     292        switch (c)
     293        {
     294            case 'e':   // --enable
     295                if (enable >= 0)
     296                    return errorSyntax(Nvram::tr("You can specify either --enable or --disable once."));
     297                enable = 1;
     298                break;
     299
     300            case 'd':   // --disable
     301                if (enable >= 0)
     302                    return errorSyntax(Nvram::tr("You can specify either --enable or --disable once."));
     303                enable = 0;
     304                break;
     305
     306            default:
     307                return errorGetOpt(c, &ValueUnion);
     308        }
     309    }
     310
     311    if (enable < 0)
     312        return errorSyntax(Nvram::tr("You have to specify either --enable or --disable."));
     313
     314    ComPtr<IUefiVariableStore> uefiVarStore;
     315    CHECK_ERROR2I_RET(nvramStore, COMGETTER(UefiVariableStore)(uefiVarStore.asOutParam()), RTEXITCODE_FAILURE);
     316
     317    CHECK_ERROR2I_RET(uefiVarStore, COMSETTER(SecureBootEnabled((BOOL)enable)), RTEXITCODE_FAILURE);
     318    return RTEXITCODE_SUCCESS;
     319}
     320
     321
     322/**
    265323 * Handles the 'modifynvram myvm listvars' sub-command.
    266324 * @returns Exit code.
     
    270328static RTEXITCODE handleModifyNvramListUefiVars(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    271329{
    272     RT_NOREF(a);
     330    if (a->argc != 2)
     331        return errorTooManyParameters(&a->argv[1]);
    273332
    274333    ComPtr<IUefiVariableStore> uefiVarStore;
     
    362421        }
    363422        else
    364            rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
     423            rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
    365424    }
    366425
     
    491550    }
    492551    else
    493        rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
     552        rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
    494553
    495554    return rcExit;
     
    548607        hrc = handleModifyNvramEnrollOraclePlatformKey(a, nvramStore) == RTEXITCODE_SUCCESS ? S_OK : E_FAIL;
    549608    }
     609    else if (!strcmp(a->argv[1], "secureboot"))
     610    {
     611        setCurrentSubcommand(HELP_SCOPE_MODIFYNVRAM_SECUREBOOT);
     612        hrc = handleModifyNvramSecureBoot(a, nvramStore) == RTEXITCODE_SUCCESS ? S_OK : E_FAIL;
     613    }
    550614    else if (!strcmp(a->argv[1], "listvars"))
    551615    {
     
    569633    }
    570634    else
    571         return errorUnknownSubcommand(a->argv[0]);
     635        return errorUnknownSubcommand(a->argv[1]);
    572636
    573637    /* commit changes */
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