Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a VarCheckPolicyLib for RuntimeDxe
- Loading branch information
1 parent
70f0b41
commit 9807ab9
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibVariableDxe.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** @file -- VarCheckPolicyLib.c | ||
This is a NULL library instance that leverages the VarCheck interface | ||
and the business logic behind the VariablePolicy code to make its decisions. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Uefi.h> | ||
#include <Library/VarCheckLib.h> | ||
#include <Library/DebugLib.h> | ||
|
||
#include <Library/VariablePolicyLib.h> | ||
|
||
// ================================================ | ||
// As a VarCheck library, we're linked into the VariableServices | ||
// and may not be able to call them indirectly. To get around this, | ||
// use the internal GetVariable function to query the variable store. | ||
// ================================================ | ||
EFI_STATUS | ||
EFIAPI | ||
VariableServiceGetVariable ( | ||
IN CHAR16 *VariableName, | ||
IN EFI_GUID *VendorGuid, | ||
OUT UINT32 *Attributes OPTIONAL, | ||
IN OUT UINTN *DataSize, | ||
OUT VOID *Data | ||
); | ||
|
||
/** | ||
Simple constructor function of VarCheckPolicyLib | ||
@param[in] ImageHandle The firmware allocated handle for the EFI image. | ||
@param[in] SystemTable A pointer to the EFI System Table. | ||
@retval EFI_SUCCESS The constructor executed correctly. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
VarCheckPolicyLibConstructor ( | ||
IN EFI_HANDLE ImageHandle, | ||
IN EFI_SYSTEM_TABLE *SystemTable | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
|
||
// Initialize the business logic with the internal GetVariable handler. | ||
Status = InitVariablePolicyLib (VariableServiceGetVariable); | ||
|
||
// Only proceed with init if the business logic could be initialized. | ||
if (!EFI_ERROR (Status)) { | ||
// Register the VarCheck handler for SetVariable filtering. | ||
// Forward the check to the business logic of the library. | ||
VarCheckLibRegisterSetVariableCheckHandler (ValidateSetVariable); | ||
} | ||
// Otherwise, there's not much we can do. | ||
else { | ||
DEBUG ((DEBUG_ERROR, "%a - Cannot Initialize VariablePolicyLib! %r\n", __FUNCTION__, Status)); | ||
ASSERT_EFI_ERROR (Status); | ||
} | ||
|
||
return Status; | ||
} |
31 changes: 31 additions & 0 deletions
31
MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibVariableDxe.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## @file VarCheckPolicyLib.inf | ||
# This is an instance of a VarCheck lib that leverages the business logic behind | ||
# the VariablePolicy code to make its decisions. | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010005 | ||
BASE_NAME = VarCheckPolicyLibVariableDxe | ||
FILE_GUID = C17DF9DB-A744-4011-A796-4EDA2ED97C2F | ||
MODULE_TYPE = DXE_RUNTIME_DRIVER | ||
VERSION_STRING = 1.0 | ||
LIBRARY_CLASS = NULL|DXE_RUNTIME_DRIVER | ||
CONSTRUCTOR = VarCheckPolicyLibConstructor | ||
|
||
|
||
[Sources] | ||
VarCheckPolicyLibVariableDxe.c | ||
|
||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
|
||
|
||
[LibraryClasses] | ||
DebugLib | ||
VarCheckLib | ||
VariablePolicyLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters