1 | /* $Id: NvramStoreImpl.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM NVRAM store class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2021-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
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
|
---|
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"
|
---|
35 | #include "SecretKeyStore.h"
|
---|
36 | #include <VBox/vmm/pdmdrv.h>
|
---|
37 | #include <VBox/VBoxCryptoIf.h>
|
---|
38 |
|
---|
39 |
|
---|
40 | #ifdef VBOX_COM_INPROC
|
---|
41 | class Console;
|
---|
42 | #else
|
---|
43 | class GuestOSType;
|
---|
44 |
|
---|
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);
|
---|
83 | HRESULT i_applyDefaults(GuestOSType *aOSType);
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | com::Utf8Str i_getNonVolatileStorageFile();
|
---|
87 | void i_updateNonVolatileStorageFile(const com::Utf8Str &aNonVolatileStorageFile);
|
---|
88 |
|
---|
89 | int i_loadStore(const char *pszPath);
|
---|
90 | int i_saveStore(void);
|
---|
91 |
|
---|
92 | #ifndef VBOX_COM_INPROC
|
---|
93 | HRESULT i_retainUefiVarStore(PRTVFS phVfs, bool fReadonly);
|
---|
94 | HRESULT i_releaseUefiVarStore(RTVFS hVfs);
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | #ifdef VBOX_WITH_FULL_VM_ENCRYPTION
|
---|
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();
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | private:
|
---|
109 |
|
---|
110 | int initImpl(void);
|
---|
111 |
|
---|
112 | // Wrapped NVRAM store properties
|
---|
113 | HRESULT getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile);
|
---|
114 | HRESULT getUefiVariableStore(ComPtr<IUefiVariableStore> &aUefiVarStore);
|
---|
115 | HRESULT getKeyId(com::Utf8Str &aKeyId);
|
---|
116 | HRESULT getKeyStore(com::Utf8Str &aKeyStore);
|
---|
117 |
|
---|
118 | // Wrapped NVRAM store members
|
---|
119 | HRESULT initUefiVariableStore(ULONG aSize);
|
---|
120 |
|
---|
121 | int i_loadStoreFromTar(RTVFSFSSTREAM hVfsFssTar);
|
---|
122 | int i_saveStoreAsTar(const char *pszPath);
|
---|
123 |
|
---|
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 |
|
---|
135 | #ifdef VBOX_COM_INPROC
|
---|
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 |
|
---|
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);
|
---|
145 | static DECLCALLBACK(int) i_nvramStoreDelete(PPDMIVFSCONNECTOR pInterface, const char *pszNamespace, const char *pszPath);
|
---|
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: */
|
---|