VirtualBox

Changeset 91457 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Sep 29, 2021 2:08:32 PM (3 years ago)
Author:
vboxsync
Message:

Main,FE/VBoxManage: Implement functionality to list and query UEFI variables, bugref:9580

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r91416 r91457  
    60166016  </enum>
    60176017
     6018  <enum
     6019    name="UefiVariableAttributes"
     6020    uuid="cda505ec-b444-4aef-b55c-b687717bdac5"
     6021    >
     6022    <desc>
     6023      Possible variable attributes. More than one flag may be set.
     6024      <see><link to="IUefiVariableStore"/></see>
     6025    </desc>
     6026
     6027    <const name="None"                      value="0">
     6028      <desc>No attributes set.</desc>
     6029    </const>
     6030    <const name="NonVolatile"               value="0x01">
     6031      <desc>Variable is stored in non volatile storage.</desc>
     6032    </const>
     6033    <const name="BootServiceAccess"         value="0x02">
     6034      <desc>Variable can be accessed from the boot services.</desc>
     6035    </const>
     6036    <const name="RuntimeAccess"             value="0x04">
     6037      <desc>Variable can be accessed from the runtime.</desc>
     6038    </const>
     6039    <const name="HwErrorRecord"             value="0x08">
     6040      <desc>Variable contains a hardware error record.</desc>
     6041    </const>
     6042    <const name="AuthWriteAccess"           value="0x100">
     6043      <desc>Writing to this variable requires an authenticated source.</desc>
     6044    </const>
     6045    <const name="AuthTimeBasedWriteAccess"  value="0x200">
     6046      <desc>Variable was written with a time based authentication.</desc>
     6047    </const>
     6048    <const name="AuthAppendWrite"           value="0x400">
     6049      <desc>The variable can be appended only.</desc>
     6050    </const>
     6051  </enum>
     6052
    60186053  <interface
    60196054    name="IUefiVariableStore" extends="$unknown"
    6020     uuid="f39d5888-9009-4e77-94b5-9cdcfc1859c3"
     6055    uuid="d134c6b6-4479-430d-bb73-68a452ba3e67"
    60216056    wsmap="managed"
    60226057    reservedMethods="10" reservedAttributes="5"
     
    60286063    </desc>
    60296064
     6065    <attribute name="secureBootEnabled" type="boolean">
     6066      <desc>Flag whether secure boot is currently enabled for the VM.</desc>
     6067    </attribute>
     6068
    60306069    <method name="addVariable">
    60316070      <desc>Adds a new variable to the non volatile storage area.</desc>
     
    60366075        <desc>UUID of the variable owner.</desc>
    60376076      </param>
     6077      <param name="attributes" type="UefiVariableAttributes" safearray="yes" dir="in">
     6078        <desc>Attributes of the variable.</desc>
     6079      </param>
    60386080      <param name="data" type="octet" dir="in" safearray="yes">
    60396081        <desc>The variable data.</desc>
     
    60566098        <desc>Name of the variable.</desc>
    60576099      </param>
    6058       <param name="owner" type="uuid" mod="string" dir="in">
    6059         <desc>UUID of the variable owner.</desc>
    6060       </param>
    60616100      <param name="data" type="octet" dir="in" safearray="yes">
    60626101        <desc>The new variable data.</desc>
     
    60726111        <desc>UUID of the variable owner returned on success.</desc>
    60736112      </param>
     6113      <param name="attributes" type="UefiVariableAttributes" safearray="yes" dir="out">
     6114        <desc>Attributes of the variable.</desc>
     6115      </param>
    60746116      <param name="data" type="octet" dir="out" safearray="yes">
    60756117        <desc>The variable data returned on success.</desc>
     
    60876129        <desc>UUID of the variable owners returned on success.</desc>
    60886130      </param>
     6131    </method>
     6132
     6133    <method name="enrollOraclePlatformKey">
     6134      <desc>
     6135        Enroll the default platform key from Oracle for enabling Secure Boot.
     6136      </desc>
    60896137    </method>
    60906138
  • trunk/src/VBox/Main/include/UefiVariableStoreImpl.h

    r91396 r91457  
    4949
    5050    // Wrapped NVRAM store properties
     51    HRESULT getSecureBootEnabled(BOOL *pfEnabled);
     52    HRESULT setSecureBootEnabled(BOOL fEnabled);
    5153
    5254    // Wrapped NVRAM store members
    53     HRESULT addVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid, const std::vector<BYTE> &aData);
     55    HRESULT addVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid, const std::vector<UefiVariableAttributes_T> &aAttributes,
     56                        const std::vector<BYTE> &aData);
    5457    HRESULT deleteVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid);
    55     HRESULT changeVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid, const std::vector<BYTE> &aData);
    56     HRESULT queryVariableByName(const com::Utf8Str &aName, com::Guid &aOwnerUuid, std::vector<BYTE> &aData);
     58    HRESULT changeVariable(const com::Utf8Str &aName, const std::vector<BYTE> &aData);
     59    HRESULT queryVariableByName(const com::Utf8Str &aName, com::Guid &aOwnerUuid, std::vector<UefiVariableAttributes_T> &aAttributes,
     60                                std::vector<BYTE> &aData);
    5761    HRESULT queryVariables(std::vector<com::Utf8Str> &aNames, std::vector<com::Guid> &aOwnerUuids);
     62    HRESULT enrollOraclePlatformKey(void);
    5863    HRESULT enrollPlatformKey(const std::vector<BYTE> &aData, const com::Guid &aOwnerUuid);
    5964    HRESULT addKek(const std::vector<BYTE> &aData, const com::Guid &aOwnerUuid, SignatureType_T enmSignatureType);
     
    6368
    6469    int i_uefiVarStoreSetVarAttr(const char *pszVar, uint32_t fAttr);
     70    int i_uefiVarStoreQueryVarAttr(const char *pszVar, uint32_t *pfAttr);
     71    int i_uefiVarStoreQueryVarSz(const char *pszVar, uint64_t *pcbVar);
     72    int i_uefiVarStoreQueryVarOwnerUuid(const char *pszVar, PRTUUID pUuid);
     73    uint32_t i_uefiVarAttrToMask(const std::vector<UefiVariableAttributes_T> &aAttributes);
     74    void i_uefiAttrMaskToVec(uint32_t fAttr, std::vector<UefiVariableAttributes_T> &aAttributes);
    6575
    6676    HRESULT i_uefiVarStoreAddVar(PCEFI_GUID pGuid, const char *pszVar, uint32_t fAttr, PRTVFSFILE phVfsFile);
     77    HRESULT i_uefiVarStoreSetVar(PCEFI_GUID pGuid, const char *pszVar, uint32_t fAttr, const void *pvData, size_t cbData);
     78    HRESULT i_uefiVarStoreQueryVar(const char *pszVar, void *pvData, size_t cbData);
    6779    HRESULT i_uefiSigDbAddSig(RTEFISIGDB hEfiSigDb, const void *pvData, size_t cbData, const com::Guid &aOwnerUuid, SignatureType_T enmSignatureType);
    6880    HRESULT i_uefiVarStoreAddSignatureToDbVec(PCEFI_GUID pGuid, const char *pszDb, const std::vector<BYTE> &aData,
  • trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp

    r91434 r91457  
    386386
    387387    /* We need a write lock because of the lazy initialization. */
     388    AutoReadLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
    388389    AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
     390
     391    if (m->pParent->i_getFirmwareType() == FirmwareType_BIOS)
     392        return setError(VBOX_E_NOT_SUPPORTED, tr("The selected firmware type doesn't support a UEFI variable store"));
    389393
    390394    /* Load the NVRAM file first if it isn't already. */
  • trunk/src/VBox/Main/src-server/UefiVariableStoreImpl.cpp

    r91409 r91457  
    141141
    142142
    143 HRESULT UefiVariableStore::addVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid, const std::vector<BYTE> &aData)
    144 {
    145     RT_NOREF(aName, aOwnerUuid, aData);
    146     return E_NOTIMPL;
     143HRESULT UefiVariableStore::getSecureBootEnabled(BOOL *pfEnabled)
     144{
     145    /* the machine needs to be mutable */
     146    AutoMutableStateDependency adep(m->pMachine);
     147    if (FAILED(adep.rc())) return adep.rc();
     148
     149    AutoReadLock rlock(this COMMA_LOCKVAL_SRC_POS);
     150
     151    HRESULT hrc = S_OK;
     152    uint64_t cbVar = 0;
     153    int vrc = i_uefiVarStoreQueryVarSz("PK", &cbVar);
     154    if (RT_SUCCESS(vrc))
     155    {
     156        *pfEnabled = TRUE;
     157
     158        /* Check the SecureBootEnable variable for the override. */
     159        vrc = i_uefiVarStoreQueryVarSz("SecureBootEnable", &cbVar);
     160        if (RT_SUCCESS(vrc))
     161        {
     162            if (cbVar == sizeof(uint8_t))
     163            {
     164                uint8_t bVar = 0;
     165                hrc = i_uefiVarStoreQueryVar("SecureBootEnable", &bVar, sizeof(bVar));
     166                if (SUCCEEDED(hrc))
     167                    *pfEnabled = bVar == 0x0 ? FALSE : TRUE;
     168            }
     169            else
     170                hrc = setError(E_FAIL, tr("The 'SecureBootEnable' variable size is bogus (expected 1, got %llu)"), cbVar);
     171        }
     172        else if (vrc != VERR_FILE_NOT_FOUND)
     173            hrc = setError(E_FAIL, tr("Failed to query the 'SecureBootEnable' variable size: %Rrc"), vrc);
     174    }
     175    else if (vrc == VERR_FILE_NOT_FOUND) /* No platform key means no secure boot. */
     176        *pfEnabled = FALSE;
     177    else
     178        hrc = setError(E_FAIL, tr("Failed to query the platform key variable size: %Rrc"), vrc);
     179
     180    return hrc;
     181}
     182
     183
     184HRESULT UefiVariableStore::setSecureBootEnabled(BOOL fEnabled)
     185{
     186    /* the machine needs to be mutable */
     187    AutoMutableStateDependency adep(m->pMachine);
     188    if (FAILED(adep.rc())) return adep.rc();
     189
     190    AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
     191
     192    EFI_GUID GuidSecureBootEnable = EFI_SECURE_BOOT_ENABLE_DISABLE_GUID;
     193    uint64_t cbVar = 0;
     194    int vrc = i_uefiVarStoreQueryVarSz("PK", &cbVar);
     195    if (RT_SUCCESS(vrc))
     196    {
     197        uint8_t bVar = fEnabled ? 0x1 : 0x0;
     198        return i_uefiVarStoreSetVar(&GuidSecureBootEnable, "SecureBootEnable",
     199                                      EFI_VAR_HEADER_ATTR_NON_VOLATILE
     200                                    | EFI_VAR_HEADER_ATTR_BOOTSERVICE_ACCESS
     201                                    | EFI_VAR_HEADER_ATTR_RUNTIME_ACCESS,
     202                                    &bVar, sizeof(bVar));
     203    }
     204    else if (vrc == VERR_FILE_NOT_FOUND) /* No platform key means no secure boot support. */
     205        return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Secure boot is not available because the platform key (PK) is not enrolled"));
     206
     207    return setError(E_FAIL, tr("Failed to query the platform key variable size: %Rrc"), vrc);
     208}
     209
     210
     211HRESULT UefiVariableStore::addVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid,
     212                                       const std::vector<UefiVariableAttributes_T> &aAttributes,
     213                                       const std::vector<BYTE> &aData)
     214{
     215    /* the machine needs to be mutable */
     216    AutoMutableStateDependency adep(m->pMachine);
     217    if (FAILED(adep.rc())) return adep.rc();
     218
     219    AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
     220
     221    uint32_t fAttr = i_uefiVarAttrToMask(aAttributes);
     222    EFI_GUID OwnerGuid;
     223    RTEfiGuidFromUuid(&OwnerGuid, aOwnerUuid.raw());
     224    return i_uefiVarStoreSetVar(&OwnerGuid, aName.c_str(), fAttr, &aData.front(), aData.size());
    147225}
    148226
     
    155233
    156234
    157 HRESULT UefiVariableStore::changeVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid, const std::vector<BYTE> &aData)
    158 {
    159     RT_NOREF(aName, aOwnerUuid, aData);
     235HRESULT UefiVariableStore::changeVariable(const com::Utf8Str &aName, const std::vector<BYTE> &aData)
     236{
     237    RT_NOREF(aName, aData);
    160238    return E_NOTIMPL;
    161239}
    162240
    163241
    164 HRESULT UefiVariableStore::queryVariableByName(const com::Utf8Str &aName, com::Guid &aOwnerUuid, std::vector<BYTE> &aData)
    165 {
    166     RT_NOREF(aName, aOwnerUuid, aData);
    167     return E_NOTIMPL;
    168 }
    169 
    170 
    171 HRESULT UefiVariableStore::queryVariables(std::vector<com::Utf8Str> &aNames, std::vector<com::Guid> &aOwnerUuids)
    172 {
    173     RT_NOREF(aNames, aOwnerUuids);
     242HRESULT UefiVariableStore::queryVariableByName(const com::Utf8Str &aName, com::Guid &aOwnerUuid,
     243                                               std::vector<UefiVariableAttributes_T> &aAttributes,
     244                                               std::vector<BYTE> &aData)
     245{
     246    RT_NOREF(aName, aOwnerUuid, aAttributes, aData);
     247
     248    HRESULT hrc = S_OK;
     249    uint32_t fAttr;
     250    int vrc = i_uefiVarStoreQueryVarAttr(aName.c_str(), &fAttr);
     251    if (RT_SUCCESS(vrc))
     252    {
     253        RTUUID OwnerUuid;
     254        vrc = i_uefiVarStoreQueryVarOwnerUuid(aName.c_str(), &OwnerUuid);
     255        if (RT_SUCCESS(vrc))
     256        {
     257            uint64_t cbVar = 0;
     258            vrc = i_uefiVarStoreQueryVarSz(aName.c_str(), &cbVar);
     259            if (RT_SUCCESS(vrc))
     260            {
     261                aData.resize(cbVar);
     262                hrc = i_uefiVarStoreQueryVar(aName.c_str(), &aData.front(), aData.size());
     263                if (SUCCEEDED(hrc))
     264                {
     265                    aOwnerUuid = com::Guid(OwnerUuid);
     266                    i_uefiAttrMaskToVec(fAttr, aAttributes);
     267                }
     268            }
     269            else
     270                hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to query the size of variable '%s': %Rrc"), aName.c_str(), vrc);
     271        }
     272        else
     273            hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to query the owner UUID of variable '%s': %Rrc"), aName.c_str(), vrc);
     274    }
     275    else
     276        hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to query the attributes of variable '%s': %Rrc"), aName.c_str(), vrc);
     277
     278    return hrc;
     279}
     280
     281
     282HRESULT UefiVariableStore::queryVariables(std::vector<com::Utf8Str> &aNames,
     283                                          std::vector<com::Guid> &aOwnerUuids)
     284{
     285    /* the machine needs to be mutable */
     286    AutoMutableStateDependency adep(m->pMachine);
     287    if (FAILED(adep.rc())) return adep.rc();
     288
     289    AutoReadLock rlock(this COMMA_LOCKVAL_SRC_POS);
     290
     291    RTVFSDIR hVfsDir = NIL_RTVFSDIR;
     292    int vrc = RTVfsDirOpen(m->hVfsUefiVarStore, "by-name", 0 /*fFlags*/, &hVfsDir);
     293    if (RT_SUCCESS(vrc))
     294    {
     295        RTDIRENTRYEX DirEntry;
     296
     297        vrc = RTVfsDirReadEx(hVfsDir, &DirEntry, NULL, RTFSOBJATTRADD_NOTHING);
     298        for (;;)
     299        {
     300            RTUUID OwnerUuid;
     301            vrc = i_uefiVarStoreQueryVarOwnerUuid(DirEntry.szName, &OwnerUuid);
     302            if (RT_FAILURE(vrc))
     303                break;
     304
     305            aNames.push_back(Utf8Str(DirEntry.szName));
     306            aOwnerUuids.push_back(com::Guid(OwnerUuid));
     307
     308            vrc = RTVfsDirReadEx(hVfsDir, &DirEntry, NULL, RTFSOBJATTRADD_NOTHING);
     309            if (RT_FAILURE(vrc))
     310                break;
     311        }
     312
     313        if (vrc == VERR_NO_MORE_FILES)
     314            vrc = VINF_SUCCESS;
     315
     316        RTVfsDirRelease(hVfsDir);
     317    }
     318
     319    if (RT_FAILURE(vrc))
     320        return setError(VBOX_E_IPRT_ERROR, tr("Failed to query the variables: %Rrc"), vrc);
     321
     322    return S_OK;
     323}
     324
     325
     326HRESULT UefiVariableStore::enrollOraclePlatformKey(void)
     327{
    174328    return E_NOTIMPL;
    175329}
     
    285439
    286440    return vrc;
     441}
     442
     443
     444/**
     445 * Queries the attributes for the given EFI variable store variable.
     446 *
     447 * @returns IPRT status code.
     448 * @param   pszVar              The variable to query the attributes for.
     449 * @param   pfAttr              Where to store the attributes on success.
     450 */
     451int UefiVariableStore::i_uefiVarStoreQueryVarAttr(const char *pszVar, uint32_t *pfAttr)
     452{
     453    char szVarPath[_1K];
     454    ssize_t cch = RTStrPrintf2(szVarPath, sizeof(szVarPath), "/raw/%s/attr", pszVar);
     455    Assert(cch > 0); RT_NOREF(cch);
     456
     457    RTVFSFILE hVfsFileAttr = NIL_RTVFSFILE;
     458    int vrc = RTVfsFileOpen(m->hVfsUefiVarStore, szVarPath,
     459                           RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN,
     460                           &hVfsFileAttr);
     461    if (RT_SUCCESS(vrc))
     462    {
     463        uint32_t fAttrLe = 0;
     464        vrc = RTVfsFileRead(hVfsFileAttr, &fAttrLe, sizeof(fAttrLe), NULL /*pcbRead*/);
     465        RTVfsFileRelease(hVfsFileAttr);
     466        if (RT_SUCCESS(vrc))
     467            *pfAttr = RT_LE2H_U32(fAttrLe);
     468    }
     469
     470    return vrc;
     471}
     472
     473
     474/**
     475 * Queries the data size for the given variable.
     476 *
     477 * @returns IPRT status code.
     478 * @param   pszVar              The variable to query the size for.
     479 * @param   pcbVar              Where to store the size of the variable data on success.
     480 */
     481int UefiVariableStore::i_uefiVarStoreQueryVarSz(const char *pszVar, uint64_t *pcbVar)
     482{
     483    char szVarPath[_1K];
     484    ssize_t cch = RTStrPrintf2(szVarPath, sizeof(szVarPath), "/by-name/%s", pszVar);
     485    Assert(cch > 0); RT_NOREF(cch);
     486
     487    RTVFSFILE hVfsFile = NIL_RTVFSFILE;
     488    int vrc = RTVfsFileOpen(m->hVfsUefiVarStore, szVarPath,
     489                            RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN,
     490                            &hVfsFile);
     491    if (RT_SUCCESS(vrc))
     492    {
     493        vrc = RTVfsFileQuerySize(hVfsFile, pcbVar);
     494        RTVfsFileRelease(hVfsFile);
     495    }
     496    else if (vrc == VERR_PATH_NOT_FOUND)
     497        vrc = VERR_FILE_NOT_FOUND;
     498
     499    return vrc;
     500}
     501
     502
     503/**
     504 * Returns the owner UUID of the given variable.
     505 *
     506 * @returns IPRT status code.
     507 * @param   pszVar              The variable to query the owner UUID for.
     508 * @param   pUuid               Where to store the owner UUID on success.
     509 */
     510int UefiVariableStore::i_uefiVarStoreQueryVarOwnerUuid(const char *pszVar, PRTUUID pUuid)
     511{
     512    char szVarPath[_1K];
     513    ssize_t cch = RTStrPrintf2(szVarPath, sizeof(szVarPath), "/raw/%s/uuid", pszVar);
     514    Assert(cch > 0); RT_NOREF(cch);
     515
     516    RTVFSFILE hVfsFileAttr = NIL_RTVFSFILE;
     517    int vrc = RTVfsFileOpen(m->hVfsUefiVarStore, szVarPath,
     518                           RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN,
     519                           &hVfsFileAttr);
     520    if (RT_SUCCESS(vrc))
     521    {
     522        EFI_GUID OwnerGuid;
     523        vrc = RTVfsFileRead(hVfsFileAttr, &OwnerGuid, sizeof(OwnerGuid), NULL /*pcbRead*/);
     524        RTVfsFileRelease(hVfsFileAttr);
     525        if (RT_SUCCESS(vrc))
     526            RTEfiGuidToUuid(pUuid, &OwnerGuid);
     527    }
     528
     529    return vrc;
     530}
     531
     532
     533/**
     534 * Converts the given vector of variables attributes to a bitmask used internally.
     535 *
     536 * @returns Mask of UEFI variable attributes.
     537 * @param   vectAttributes      Vector of variable atttributes.
     538 */
     539uint32_t UefiVariableStore::i_uefiVarAttrToMask(const std::vector<UefiVariableAttributes_T> &vecAttributes)
     540{
     541    uint32_t fAttr = 0;
     542
     543    for (size_t i = 0; i < vecAttributes.size(); i++)
     544        fAttr |= (ULONG)vecAttributes[i];
     545
     546    return fAttr;
     547}
     548
     549
     550/**
     551 * Converts the given aatribute mask to the attribute vector used externally.
     552 *
     553 * @returns nothing.
     554 * @param   fAttr               The attribute mask.
     555 * @param   aAttributes         The vector to store the attibutes in.
     556 */
     557void UefiVariableStore::i_uefiAttrMaskToVec(uint32_t fAttr, std::vector<UefiVariableAttributes_T> &aAttributes)
     558{
     559    if (fAttr & EFI_VAR_HEADER_ATTR_NON_VOLATILE)
     560        aAttributes.push_back(UefiVariableAttributes_NonVolatile);
     561    if (fAttr & EFI_VAR_HEADER_ATTR_BOOTSERVICE_ACCESS)
     562        aAttributes.push_back(UefiVariableAttributes_BootServiceAccess);
     563    if (fAttr & EFI_VAR_HEADER_ATTR_RUNTIME_ACCESS)
     564        aAttributes.push_back(UefiVariableAttributes_RuntimeAccess);
     565    if (fAttr & EFI_VAR_HEADER_ATTR_HW_ERROR_RECORD)
     566        aAttributes.push_back(UefiVariableAttributes_HwErrorRecord);
     567    if (fAttr & EFI_AUTH_VAR_HEADER_ATTR_AUTH_WRITE_ACCESS)
     568        aAttributes.push_back(UefiVariableAttributes_AuthWriteAccess);
     569    if (fAttr & EFI_AUTH_VAR_HEADER_ATTR_TIME_BASED_AUTH_WRITE_ACCESS)
     570        aAttributes.push_back(UefiVariableAttributes_AuthTimeBasedWriteAccess);
     571    if (fAttr & EFI_AUTH_VAR_HEADER_ATTR_APPEND_WRITE)
     572        aAttributes.push_back(UefiVariableAttributes_AuthAppendWrite);
    287573}
    288574
     
    354640
    355641
     642HRESULT UefiVariableStore::i_uefiVarStoreSetVar(PCEFI_GUID pGuid, const char *pszVar, uint32_t fAttr, const void *pvData, size_t cbData)
     643{
     644    RTVFSFILE hVfsFileVar = NIL_RTVFSFILE;
     645
     646    HRESULT hrc = i_uefiVarStoreAddVar(pGuid, pszVar, fAttr, &hVfsFileVar);
     647    if (SUCCEEDED(hrc))
     648    {
     649        int vrc = RTVfsFileWrite(hVfsFileVar, pvData, cbData, NULL /*pcbWritten*/);
     650        if (RT_FAILURE(vrc))
     651            hrc = setError(E_FAIL, tr("Setting the variable '%s' failed: %Rrc"), pszVar, vrc);
     652
     653        RTVfsFileRelease(hVfsFileVar);
     654    }
     655
     656    return hrc;
     657}
     658
     659
     660HRESULT UefiVariableStore::i_uefiVarStoreQueryVar(const char *pszVar, void *pvData, size_t cbData)
     661{
     662    HRESULT hrc = S_OK;
     663
     664    char szVarPath[_1K];
     665    ssize_t cch = RTStrPrintf2(szVarPath, sizeof(szVarPath), "/by-name/%s", pszVar);
     666    Assert(cch > 0); RT_NOREF(cch);
     667
     668    RTVFSFILE hVfsFile = NIL_RTVFSFILE;
     669    int vrc = RTVfsFileOpen(m->hVfsUefiVarStore, szVarPath,
     670                            RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN,
     671                            &hVfsFile);
     672    if (RT_SUCCESS(vrc))
     673    {
     674        vrc = RTVfsFileRead(hVfsFile, pvData, cbData, NULL /*pcbRead*/);
     675        if (RT_FAILURE(vrc))
     676            hrc = setError(E_FAIL, tr("Failed to read data of variable '%s': %Rrc"), pszVar, vrc);
     677
     678        RTVfsFileRelease(hVfsFile);
     679    }
     680    else
     681        hrc = setError(E_FAIL, tr("Failed to open variable '%s' for reading: %Rrc"), pszVar, vrc);
     682
     683    return hrc;
     684}
     685
    356686HRESULT UefiVariableStore::i_uefiSigDbAddSig(RTEFISIGDB hEfiSigDb, const void *pvData, size_t cbData,
    357687                                             const com::Guid &aOwnerUuid, SignatureType_T enmSignatureType)
     
    385715
    386716    HRESULT hrc = i_uefiVarStoreAddVar(pGuid, pszDb,
    387                                      EFI_VAR_HEADER_ATTR_NON_VOLATILE
    388                                    | EFI_VAR_HEADER_ATTR_BOOTSERVICE_ACCESS
    389                                    | EFI_VAR_HEADER_ATTR_RUNTIME_ACCESS
    390                                    | EFI_AUTH_VAR_HEADER_ATTR_TIME_BASED_AUTH_WRITE_ACCESS,
    391                                    &hVfsFileSigDb);
     717                                         EFI_VAR_HEADER_ATTR_NON_VOLATILE
     718                                       | EFI_VAR_HEADER_ATTR_BOOTSERVICE_ACCESS
     719                                       | EFI_VAR_HEADER_ATTR_RUNTIME_ACCESS
     720                                       | EFI_AUTH_VAR_HEADER_ATTR_TIME_BASED_AUTH_WRITE_ACCESS,
     721                                       &hVfsFileSigDb);
    392722    if (SUCCEEDED(hrc))
    393723    {
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