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