[91326] | 1 | /* $Id: NvramStoreImpl.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VirtualBox COM NVRAM store class implementation
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[96407] | 7 | * Copyright (C) 2021-2022 Oracle and/or its affiliates.
|
---|
[91326] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[91326] | 26 | */
|
---|
| 27 |
|
---|
| 28 | #ifndef MAIN_INCLUDED_NvramStoreImpl_h
|
---|
| 29 | #define MAIN_INCLUDED_NvramStoreImpl_h
|
---|
| 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | #include "NvramStoreWrap.h"
|
---|
[94743] | 35 | #include "SecretKeyStore.h"
|
---|
[91326] | 36 | #include <VBox/vmm/pdmdrv.h>
|
---|
[94743] | 37 | #include <VBox/VBoxCryptoIf.h>
|
---|
[91326] | 38 |
|
---|
[94743] | 39 |
|
---|
[91326] | 40 | #ifdef VBOX_COM_INPROC
|
---|
| 41 | class Console;
|
---|
| 42 | #else
|
---|
[91614] | 43 | class GuestOSType;
|
---|
| 44 |
|
---|
[91326] | 45 | namespace settings
|
---|
| 46 | {
|
---|
| 47 | struct NvramSettings;
|
---|
| 48 | }
|
---|
| 49 | #endif
|
---|
| 50 |
|
---|
| 51 | class ATL_NO_VTABLE NvramStore :
|
---|
| 52 | public NvramStoreWrap
|
---|
| 53 | {
|
---|
| 54 | public:
|
---|
| 55 |
|
---|
| 56 | DECLARE_COMMON_CLASS_METHODS(NvramStore)
|
---|
| 57 |
|
---|
| 58 | HRESULT FinalConstruct();
|
---|
| 59 | void FinalRelease();
|
---|
| 60 |
|
---|
| 61 | // public initializer/uninitializer for internal purposes only
|
---|
| 62 | #ifdef VBOX_COM_INPROC
|
---|
| 63 | HRESULT init(Console *aParent, const com::Utf8Str &strNonVolatileStorageFile);
|
---|
| 64 | #else
|
---|
| 65 | HRESULT init(Machine *parent);
|
---|
| 66 | HRESULT init(Machine *parent, NvramStore *that);
|
---|
| 67 | HRESULT initCopy(Machine *parent, NvramStore *that);
|
---|
| 68 | #endif
|
---|
| 69 | void uninit();
|
---|
| 70 |
|
---|
| 71 | // public methods for internal purposes only
|
---|
| 72 | #ifndef VBOX_COM_INPROC
|
---|
| 73 | HRESULT i_loadSettings(const settings::NvramSettings &data);
|
---|
| 74 | HRESULT i_saveSettings(settings::NvramSettings &data);
|
---|
| 75 | #endif
|
---|
| 76 |
|
---|
| 77 | #ifdef VBOX_COM_INPROC
|
---|
| 78 | static const PDMDRVREG DrvReg;
|
---|
| 79 | #else
|
---|
| 80 | void i_rollback();
|
---|
| 81 | void i_commit();
|
---|
| 82 | void i_copyFrom(NvramStore *aThat);
|
---|
[91614] | 83 | HRESULT i_applyDefaults(GuestOSType *aOSType);
|
---|
[91326] | 84 | #endif
|
---|
| 85 |
|
---|
| 86 | com::Utf8Str i_getNonVolatileStorageFile();
|
---|
| 87 | void i_updateNonVolatileStorageFile(const com::Utf8Str &aNonVolatileStorageFile);
|
---|
| 88 |
|
---|
[91434] | 89 | int i_loadStore(const char *pszPath);
|
---|
[91326] | 90 | int i_saveStore(void);
|
---|
| 91 |
|
---|
[91535] | 92 | #ifndef VBOX_COM_INPROC
|
---|
| 93 | HRESULT i_retainUefiVarStore(PRTVFS phVfs, bool fReadonly);
|
---|
| 94 | HRESULT i_releaseUefiVarStore(RTVFS hVfs);
|
---|
| 95 | #endif
|
---|
| 96 |
|
---|
[94743] | 97 | #ifdef VBOX_WITH_FULL_VM_ENCRYPTION
|
---|
[94660] | 98 | HRESULT i_updateEncryptionSettings(const com::Utf8Str &strKeyId,
|
---|
| 99 | const com::Utf8Str &strKeyStore);
|
---|
| 100 | HRESULT i_getEncryptionSettings(com::Utf8Str &strKeyId,
|
---|
| 101 | com::Utf8Str &strKeyStore);
|
---|
| 102 |
|
---|
| 103 | int i_addPassword(const Utf8Str &strKeyId, const Utf8Str &strPassword);
|
---|
| 104 | int i_removePassword(const Utf8Str &strKeyId);
|
---|
| 105 | int i_removeAllPasswords();
|
---|
[94743] | 106 | #endif
|
---|
[94660] | 107 |
|
---|
[91326] | 108 | private:
|
---|
| 109 |
|
---|
[94743] | 110 | int initImpl(void);
|
---|
| 111 |
|
---|
[91326] | 112 | // Wrapped NVRAM store properties
|
---|
| 113 | HRESULT getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile);
|
---|
[91396] | 114 | HRESULT getUefiVariableStore(ComPtr<IUefiVariableStore> &aUefiVarStore);
|
---|
[94660] | 115 | HRESULT getKeyId(com::Utf8Str &aKeyId);
|
---|
| 116 | HRESULT getKeyStore(com::Utf8Str &aKeyStore);
|
---|
[91326] | 117 |
|
---|
| 118 | // Wrapped NVRAM store members
|
---|
[91396] | 119 | HRESULT initUefiVariableStore(ULONG aSize);
|
---|
[91326] | 120 |
|
---|
[91535] | 121 | int i_loadStoreFromTar(RTVFSFSSTREAM hVfsFssTar);
|
---|
[91536] | 122 | int i_saveStoreAsTar(const char *pszPath);
|
---|
[91535] | 123 |
|
---|
[94743] | 124 | int i_retainCryptoIf(PCVBOXCRYPTOIF *ppCryptoIf);
|
---|
| 125 | int i_releaseCryptoIf(PCVBOXCRYPTOIF pCryptoIf);
|
---|
| 126 |
|
---|
| 127 | #ifdef VBOX_WITH_FULL_VM_ENCRYPTION
|
---|
| 128 | int i_setupEncryptionOrDecryption(RTVFSIOSTREAM hVfsIosInOut, bool fEncrypt,
|
---|
| 129 | PCVBOXCRYPTOIF *ppCryptoIf, SecretKey **ppKey,
|
---|
| 130 | PRTVFSIOSTREAM phVfsIos);
|
---|
| 131 | void i_releaseEncryptionOrDecryptionResources(RTVFSIOSTREAM hVfsIos, PCVBOXCRYPTOIF pCryptoIf,
|
---|
| 132 | SecretKey *pKey);
|
---|
| 133 | #endif
|
---|
| 134 |
|
---|
[91326] | 135 | #ifdef VBOX_COM_INPROC
|
---|
[94514] | 136 | static DECLCALLBACK(int) i_SsmSaveExec(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM);
|
---|
| 137 | static DECLCALLBACK(int) i_SsmLoadExec(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
|
---|
| 138 |
|
---|
[91326] | 139 | static DECLCALLBACK(int) i_nvramStoreQuerySize(PPDMIVFSCONNECTOR pInterface, const char *pszNamespace, const char *pszPath,
|
---|
| 140 | uint64_t *pcb);
|
---|
| 141 | static DECLCALLBACK(int) i_nvramStoreReadAll(PPDMIVFSCONNECTOR pInterface, const char *pszNamespace, const char *pszPath,
|
---|
| 142 | void *pvBuf, size_t cbRead);
|
---|
| 143 | static DECLCALLBACK(int) i_nvramStoreWriteAll(PPDMIVFSCONNECTOR pInterface, const char *pszNamespace, const char *pszPath,
|
---|
| 144 | const void *pvBuf, size_t cbWrite);
|
---|
[91346] | 145 | static DECLCALLBACK(int) i_nvramStoreDelete(PPDMIVFSCONNECTOR pInterface, const char *pszNamespace, const char *pszPath);
|
---|
[91326] | 146 | static DECLCALLBACK(void *) i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
|
---|
| 147 | static DECLCALLBACK(int) i_drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
|
---|
| 148 | static DECLCALLBACK(void) i_drvDestruct(PPDMDRVINS pDrvIns);
|
---|
| 149 | #endif
|
---|
| 150 |
|
---|
| 151 | struct Data; // opaque data struct, defined in NvramStoreImpl.cpp
|
---|
| 152 | Data *m;
|
---|
| 153 | };
|
---|
| 154 |
|
---|
| 155 | #endif /* !MAIN_INCLUDED_NvramStoreImpl_h */
|
---|
| 156 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|