From 10ab4d91c219c887b2e56e318605f671768e1a68 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Thu, 2 Mar 2023 13:37:58 +0800 Subject: [PATCH 01/11] Refactor ProviderValueAsAscii() --- .../SettingsManager/SettingsManagerProvider.c | 102 ++++++++++-------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index 8f0248b8..553fb3ce 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -332,11 +332,6 @@ SetProviderValueFromAscii ( return Status; } -#define ENABLED_STRING_SIZE (13) -#define SECURE_BOOT_ENUM_STRING_SIZE (20) -#define SYSTEM_PASSWORD_STATE_STRING_SIZE (30) -#define USB_PORT_STATE_STRING_SIZE (21) - /** Helper function to Print out the Value as Ascii text. NOTE: -- This must match the XML format @@ -355,7 +350,8 @@ ProviderValueAsAscii ( ) { EFI_STATUS Status; - CHAR8 *Value = NULL; + CHAR8 *Value = NULL; + CHAR8 *AsciiString = NULL; UINTN AsciiSize; UINT8 *Buffer; BOOLEAN v = FALSE; // Boolean Types @@ -376,19 +372,23 @@ ProviderValueAsAscii ( break; } - Value = AllocateZeroPool (ENABLED_STRING_SIZE); + if (v == ENABLE_INCONSISTENT) { + AsciiString = "Inconsistent"; + } else if (v) { + AsciiString = "Enabled"; + } else { + AsciiString = "Disabled"; + } + + ValueSize = AsciiStrLen (AsciiString) + 1; + + Value = AllocateZeroPool (ValueSize); if (Value == NULL) { DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); break; } - if (v == ENABLE_INCONSISTENT) { - AsciiStrCpyS (Value, ENABLED_STRING_SIZE, "Inconsistent"); - } else if (v) { - AsciiStrCpyS (Value, ENABLED_STRING_SIZE, "Enabled"); - } else { - AsciiStrCpyS (Value, ENABLED_STRING_SIZE, "Disabled"); - } + AsciiStrCpyS (Value, ValueSize, AsciiString); break; @@ -405,23 +405,27 @@ ProviderValueAsAscii ( break; } - Value = AllocateZeroPool (SECURE_BOOT_ENUM_STRING_SIZE); - if (Value == NULL) { - DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); - break; - } - if (b == 0) { - AsciiStrCpyS (Value, SECURE_BOOT_ENUM_STRING_SIZE, "MsOnly"); + AsciiString = "MsOnly"; } else if (b == 1) { - AsciiStrCpyS (Value, SECURE_BOOT_ENUM_STRING_SIZE, "MsPlus3rdParty"); + AsciiString = "MsPlus3rdParty"; } else if (b == 3) { // This is a special case. Only supported as output. - AsciiStrCpyS (Value, SECURE_BOOT_ENUM_STRING_SIZE, "Custom"); + AsciiString = "Custom"; } else { - AsciiStrCpyS (Value, SECURE_BOOT_ENUM_STRING_SIZE, "None"); + AsciiString = "None"; + } + + ValueSize = AsciiStrLen (AsciiString) + 1; + + Value = AllocateZeroPool (ValueSize); + if (Value == NULL) { + DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); + break; } + AsciiStrCpyS (Value, ValueSize, AsciiString); + break; case DFCI_SETTING_TYPE_PASSWORD: @@ -437,17 +441,21 @@ ProviderValueAsAscii ( break; } - Value = AllocateZeroPool (SYSTEM_PASSWORD_STATE_STRING_SIZE); + if (v) { + AsciiString = "System Password Set"; + } else { + AsciiString = "No System Password"; + } + + ValueSize = AsciiStrLen (AsciiString) + 1; + + Value = AllocateZeroPool (ValueSize); if (Value == NULL) { DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); break; } - if (v) { - AsciiStrCpyS (Value, SYSTEM_PASSWORD_STATE_STRING_SIZE, "System Password Set"); - } else { - AsciiStrCpyS (Value, SYSTEM_PASSWORD_STATE_STRING_SIZE, "No System Password"); - } + AsciiStrCpyS (Value, ValueSize, AsciiString); break; @@ -464,26 +472,30 @@ ProviderValueAsAscii ( break; } - Value = AllocateZeroPool (USB_PORT_STATE_STRING_SIZE); - if (Value == NULL) { - DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); - break; - } - if (b == DfciUsbPortHwDisabled) { - AsciiStrCpyS (Value, USB_PORT_STATE_STRING_SIZE, "UsbPortHwDisabled"); + AsciiString = "UsbPortHwDisabled"; } else if (b == DfciUsbPortEnabled) { - AsciiStrCpyS (Value, USB_PORT_STATE_STRING_SIZE, "UsbPortEnabled"); + AsciiString = "UsbPortEnabled"; } else if (b == DfciUsbPortDataDisabled) { - AsciiStrCpyS (Value, USB_PORT_STATE_STRING_SIZE, "UsbPortDataDisabled"); + AsciiString = "UsbPortDataDisabled"; } else if (b == DfciUsbPortAuthenticated) { - AsciiStrCpyS (Value, USB_PORT_STATE_STRING_SIZE, "UsbPortAuthenticated"); + AsciiString = "UsbPortAuthenticated"; } else if (b == ENABLE_INCONSISTENT) { - AsciiStrCpyS (Value, USB_PORT_STATE_STRING_SIZE, "Inconsistent"); + AsciiString = "Inconsistent"; } else { - AsciiStrCpyS (Value, USB_PORT_STATE_STRING_SIZE, "UnsupportedValue"); + AsciiString = "UnsupportedValue"; + } + + ValueSize = AsciiStrLen (AsciiString) + 1; + + Value = AllocateZeroPool (ValueSize); + if (Value == NULL) { + DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); + break; } + AsciiStrCpyS (Value, ValueSize, AsciiString); + break; case DFCI_SETTING_TYPE_STRING: @@ -501,7 +513,7 @@ ProviderValueAsAscii ( break; } - if (0 == ValueSize ) { + if (0 == ValueSize) { break; // Return NULL for Value silently } @@ -555,7 +567,7 @@ ProviderValueAsAscii ( break; } - if (0 == ValueSize ) { + if (0 == ValueSize) { ValueSize = sizeof (""); Value = AllocatePool (ValueSize); if (NULL != Value) { @@ -643,7 +655,7 @@ ProviderValueAsAscii ( break; } - if (0 == ValueSize ) { + if (0 == ValueSize) { break; // Return NULL for Value silently } From 19e319e97ee4746631674eab7e1abddcea2f7f36 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 20:30:37 +0800 Subject: [PATCH 02/11] Update DfciPkg/SettingsManager/SettingsManagerProvider.c Co-authored-by: Aaron <105021049+apop5@users.noreply.github.com> --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index 553fb3ce..22739fe1 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -380,7 +380,8 @@ ProviderValueAsAscii ( AsciiString = "Disabled"; } - ValueSize = AsciiStrLen (AsciiString) + 1; + ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); + Value = AllocateZeroPool (ValueSize); if (Value == NULL) { From 5e95fd5b67f1ec41fa560cbccda8a612e9809827 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 20:30:52 +0800 Subject: [PATCH 03/11] Update DfciPkg/SettingsManager/SettingsManagerProvider.c Co-authored-by: Aaron <105021049+apop5@users.noreply.github.com> --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index 22739fe1..5ea5960f 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -417,7 +417,7 @@ ProviderValueAsAscii ( AsciiString = "None"; } - ValueSize = AsciiStrLen (AsciiString) + 1; + ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); Value = AllocateZeroPool (ValueSize); if (Value == NULL) { From d4877bfa31b93b07db00a70e02e31b0b76698973 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 20:31:03 +0800 Subject: [PATCH 04/11] Update DfciPkg/SettingsManager/SettingsManagerProvider.c Co-authored-by: Aaron <105021049+apop5@users.noreply.github.com> --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index 5ea5960f..a60b1d5e 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -448,7 +448,7 @@ ProviderValueAsAscii ( AsciiString = "No System Password"; } - ValueSize = AsciiStrLen (AsciiString) + 1; + ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); Value = AllocateZeroPool (ValueSize); if (Value == NULL) { From 6675ed6c39f676008b969418996d2670159f6e34 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 20:31:14 +0800 Subject: [PATCH 05/11] Update DfciPkg/SettingsManager/SettingsManagerProvider.c Co-authored-by: Aaron <105021049+apop5@users.noreply.github.com> --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index a60b1d5e..c10c3edc 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -487,7 +487,7 @@ ProviderValueAsAscii ( AsciiString = "UnsupportedValue"; } - ValueSize = AsciiStrLen (AsciiString) + 1; + ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); Value = AllocateZeroPool (ValueSize); if (Value == NULL) { From 92acf08f4ef2300cdbae0350205314b9ffb2f21a Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 22:19:19 +0800 Subject: [PATCH 06/11] Add DfciSystemSettingStrings.h and replace strings with macros. --- DfciPkg/Include/DfciSystemSettingStrings.h | 61 +++++++++++++ DfciPkg/SettingsManager/SettingsManager.h | 1 + .../SettingsManagerCurrentSettingXml.c | 22 ++--- .../SettingsManager/SettingsManagerProvider.c | 90 +++++++++---------- 4 files changed, 117 insertions(+), 57 deletions(-) create mode 100644 DfciPkg/Include/DfciSystemSettingStrings.h diff --git a/DfciPkg/Include/DfciSystemSettingStrings.h b/DfciPkg/Include/DfciSystemSettingStrings.h new file mode 100644 index 00000000..6c1a0c45 --- /dev/null +++ b/DfciPkg/Include/DfciSystemSettingStrings.h @@ -0,0 +1,61 @@ +/** @file +DfciSystemSettingStrings.h + +These are the setting strings. + +Copyright (C) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __DFCI_SETTING_STRINGS_H__ +#define __DFCI_SETTING_STRINGS_H__ + +// +// DFCI Setting Type +// +#define DFCI_STR_SETTING_TYPE_ENABLE "ENABLE/DISABLE TYPE" +#define DFCI_STR_SETTING_TYPE_SECUREBOOTKEYENUM "SECURE BOOT KEY ENUM TYPE" +#define DFCI_STR_SETTING_TYPE_PASSWORD "PASSWORD TYPE" +#define DFCI_STR_SETTING_TYPE_USBPORTENUM "USB PORT STATE TYPE" +#define DFCI_STR_SETTING_TYPE_STRING "STRING TYPE" +#define DFCI_STR_SETTING_TYPE_BINARY "BINARY TYPE" +#define DFCI_STR_SETTING_TYPE_CERT "CERT TYPE" + +// +// Enable/Disable +// +#define DFCI_STR_ENABLED "Enabled" +#define DFCI_STR_DISABLED "Disabled" + +// +// Secure Boot Key +// +#define DFCI_STR_SECURE_BOOT_KEY_MS_ONLY "MsOnly" +#define DFCI_STR_SECURE_BOOT_KEY_MS_3RD_PARTY "MsPlus3rdParty" +#define DFCI_STR_SECURE_BOOT_KEY_NONE "None" +#define DFCI_STR_SECURE_BOOT_KEY_CUSTOM "Custom" + +// +// System Password +// +#define DFCI_STR_SYSTEM_PASSWORD_SET "System Password Set" +#define DFCI_STR_SYSTEM_PASSWORD_NOT_SET "No System Password" + +// +// USB Port State +// +#define DFCI_STR_USB_PORT_ENABLED "UsbPortEnabled" +#define DFCI_STR_USB_PORT_HW_DISABLED "UsbPortHwDisabled" +#define DFCI_STR_USB_PORT_DATA_DISABLED "UsbPortDataDisabled" +#define DFCI_STR_USB_PORT_AUTHENTICATED "UsbPortAuthenticated" + +// +// Misc +// +#define DFCI_STR_INCONSISTENT "Inconsistent" +#define DFCI_STR_UNKNOWN "Unknown" +#define DFCI_STR_UNSUPPORTED_VALUE "UnsupportedValue" +#define DRCI_STR_CERT_NOT_AVAILABLE "No Cert information available" + +#endif // __DFCI_SETTING_STRINGS_H__ diff --git a/DfciPkg/SettingsManager/SettingsManager.h b/DfciPkg/SettingsManager/SettingsManager.h index e8161f22..f7479d09 100644 --- a/DfciPkg/SettingsManager/SettingsManager.h +++ b/DfciPkg/SettingsManager/SettingsManager.h @@ -15,6 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include diff --git a/DfciPkg/SettingsManager/SettingsManagerCurrentSettingXml.c b/DfciPkg/SettingsManager/SettingsManagerCurrentSettingXml.c index 1f811523..fac41c8e 100644 --- a/DfciPkg/SettingsManager/SettingsManagerCurrentSettingXml.c +++ b/DfciPkg/SettingsManager/SettingsManagerCurrentSettingXml.c @@ -175,19 +175,19 @@ CreateXmlStringFromCurrentSettings ( case DFCI_SETTING_TYPE_ENABLE: switch (Value) { case ENABLE_FALSE: - ReturnValue = "Disabled"; + ReturnValue = DFCI_STR_DISABLED; break; case ENABLE_TRUE: - ReturnValue = "Enabled"; + ReturnValue = DFCI_STR_ENABLED; break; case ENABLE_INCONSISTENT: - ReturnValue = "Inconsistent"; + ReturnValue = DFCI_STR_INCONSISTENT; break; default: - ReturnValue = "Unknown"; + ReturnValue = DFCI_STR_UNKNOWN; break; } @@ -196,27 +196,27 @@ CreateXmlStringFromCurrentSettings ( case DFCI_SETTING_TYPE_USBPORTENUM: switch (Value) { case DfciUsbPortHwDisabled: - ReturnValue = "UsbPortHwDisabled"; + ReturnValue = DFCI_STR_USB_PORT_HW_DISABLED; break; case DfciUsbPortEnabled: - ReturnValue = "UsbPortEnabled"; + ReturnValue = DFCI_STR_USB_PORT_ENABLED; break; case DfciUsbPortDataDisabled: - ReturnValue = "UsbPortDataDisabled"; + ReturnValue = DFCI_STR_USB_PORT_DATA_DISABLED; break; case DfciUsbPortAuthenticated: - ReturnValue = "UsbPortAuthenticated"; + ReturnValue = DFCI_STR_USB_PORT_AUTHENTICATED; break; case ENABLE_INCONSISTENT: - ReturnValue = "Inconsistent"; + ReturnValue = DFCI_STR_INCONSISTENT; break; default: - ReturnValue = "UnsupportedValue"; + ReturnValue = DFCI_STR_UNSUPPORTED_VALUE; break; } @@ -224,7 +224,7 @@ CreateXmlStringFromCurrentSettings ( default: DEBUG ((DEBUG_ERROR, "%a: Group entries for type(%d) not supported\n", __FUNCTION__, GroupType)); - ReturnValue = "UnsupportedValue"; + ReturnValue = DFCI_STR_UNSUPPORTED_VALUE; break; } } diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index c10c3edc..8351b0a7 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -14,8 +14,7 @@ LIST_ENTRY mProviderList = INITIALIZE_LIST_HEAD_VARIABLE (mProviderList); // li static DFCI_AUTHENTICATION_PROTOCOL *mAuthenticationProtocol = NULL; -#define CERT_STRING_SIZE (200) -#define CERT_NOT_AVAILABLE "No Cert information available" +#define CERT_STRING_SIZE (200) /** Helper function to return the string describing the type enum @@ -27,28 +26,28 @@ ProviderTypeAsAscii ( { switch (Type) { case DFCI_SETTING_TYPE_ENABLE: - return "ENABLE/DISABLE TYPE"; + return DFCI_STR_SETTING_TYPE_ENABLE; case DFCI_SETTING_TYPE_SECUREBOOTKEYENUM: - return "SECURE BOOT KEY ENUM TYPE"; + return DFCI_STR_SETTING_TYPE_SECUREBOOTKEYENUM; case DFCI_SETTING_TYPE_PASSWORD: - return "PASSWORD TYPE"; + return DFCI_STR_SETTING_TYPE_PASSWORD; case DFCI_SETTING_TYPE_USBPORTENUM: - return "USB PORT STATE TYPE"; + return DFCI_STR_SETTING_TYPE_USBPORTENUM; case DFCI_SETTING_TYPE_STRING: - return "STRING TYPE"; + return DFCI_STR_SETTING_TYPE_STRING; case DFCI_SETTING_TYPE_BINARY: - return "BINARY TYPE"; + return DFCI_STR_SETTING_TYPE_BINARY; case DFCI_SETTING_TYPE_CERT: - return "CERT TYPE"; + return DFCI_STR_SETTING_TYPE_CERT; default: - return "Unknown"; + return DFCI_STR_UNKNOWN; break; } } @@ -173,12 +172,12 @@ SetProviderValueFromAscii ( case DFCI_SETTING_TYPE_ENABLE: // convert to BOOLEAN - if (AsciiStrCmp (Value, "Enabled") == 0) { + if (AsciiStrCmp (Value, DFCI_STR_ENABLED) == 0) { v = TRUE; - DEBUG ((DEBUG_INFO, "Setting to Enabled\n")); - } else if (AsciiStrCmp (Value, "Disabled") == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); + } else if (AsciiStrCmp (Value, DFCI_STR_DISABLED) == 0) { v = FALSE; - DEBUG ((DEBUG_INFO, "Setting to Disabled\n")); + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); } else { DEBUG ((DEBUG_ERROR, "Invalid Settings Ascii Value for Type Enable (%a)\n", Value)); return EFI_INVALID_PARAMETER; @@ -189,14 +188,14 @@ SetProviderValueFromAscii ( break; case DFCI_SETTING_TYPE_SECUREBOOTKEYENUM: - if (AsciiStrCmp (Value, "MsOnly") == 0) { - DEBUG ((DEBUG_INFO, "Setting to MsOnly\n")); + if (AsciiStrCmp (Value, DFCI_STR_SECURE_BOOT_KEY_MS_ONLY) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); b = 0; - } else if (AsciiStrCmp (Value, "MsPlus3rdParty") == 0) { - DEBUG ((DEBUG_INFO, "Setting to MsPlus3rdParty\n")); + } else if (AsciiStrCmp (Value, DFCI_STR_SECURE_BOOT_KEY_MS_3RD_PARTY) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); b = 1; - } else if (AsciiStrCmp (Value, "None") == 0) { - DEBUG ((DEBUG_INFO, "Setting to None\n")); + } else if (AsciiStrCmp (Value, DFCI_STR_SECURE_BOOT_KEY_NONE) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); b = 2; } else { DEBUG ((DEBUG_INFO, "Invalid Secure Boot Key Enum Setting. %a\n", Value)); @@ -251,17 +250,17 @@ SetProviderValueFromAscii ( break; case DFCI_SETTING_TYPE_USBPORTENUM: - if (AsciiStrCmp (Value, "UsbPortEnabled") == 0) { - DEBUG ((DEBUG_INFO, "Setting to Usb Port Enabled\n")); + if (AsciiStrCmp (Value, DFCI_STR_USB_PORT_ENABLED) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); UsbPortState = DfciUsbPortEnabled; - } else if (AsciiStrCmp (Value, "UsbPortHwDisabled") == 0) { - DEBUG ((DEBUG_INFO, "Setting to Usb Port HW Disabled\n")); + } else if (AsciiStrCmp (Value, DFCI_STR_USB_PORT_HW_DISABLED) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); UsbPortState = DfciUsbPortHwDisabled; - } else if (AsciiStrCmp (Value, "UsbPortDataDisabled") == 0) { - DEBUG ((DEBUG_INFO, "Setting to Usb Data Disabled\n")); + } else if (AsciiStrCmp (Value, DFCI_STR_USB_PORT_DATA_DISABLED) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); UsbPortState = DfciUsbPortDataDisabled; - } else if (AsciiStrCmp (Value, "UsbPortAuthenticated") == 0) { - DEBUG ((DEBUG_INFO, "Setting to Usb Authenticated\n")); + } else if (AsciiStrCmp (Value, DFCI_STR_USB_PORT_AUTHENTICATED) == 0) { + DEBUG ((DEBUG_INFO, "Setting to %a\n", Value)); UsbPortState = DfciUsbPortAuthenticated; } else { DEBUG ((DEBUG_INFO, "Invalid or unsupported Usb Port Setting. %a\n", Value)); @@ -373,16 +372,15 @@ ProviderValueAsAscii ( } if (v == ENABLE_INCONSISTENT) { - AsciiString = "Inconsistent"; + AsciiString = DFCI_STR_INCONSISTENT; } else if (v) { - AsciiString = "Enabled"; + AsciiString = DFCI_STR_ENABLED; } else { - AsciiString = "Disabled"; + AsciiString = DFCI_STR_DISABLED; } ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); - Value = AllocateZeroPool (ValueSize); if (Value == NULL) { DEBUG ((DEBUG_ERROR, "Failed - Couldn't allocate for string. \n")); @@ -407,14 +405,14 @@ ProviderValueAsAscii ( } if (b == 0) { - AsciiString = "MsOnly"; + AsciiString = DFCI_STR_SECURE_BOOT_KEY_MS_ONLY; } else if (b == 1) { - AsciiString = "MsPlus3rdParty"; + AsciiString = DFCI_STR_SECURE_BOOT_KEY_MS_3RD_PARTY; } else if (b == 3) { // This is a special case. Only supported as output. - AsciiString = "Custom"; + AsciiString = DFCI_STR_SECURE_BOOT_KEY_CUSTOM; } else { - AsciiString = "None"; + AsciiString = DFCI_STR_SECURE_BOOT_KEY_NONE; } ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); @@ -443,9 +441,9 @@ ProviderValueAsAscii ( } if (v) { - AsciiString = "System Password Set"; + AsciiString = DFCI_STR_SYSTEM_PASSWORD_SET; } else { - AsciiString = "No System Password"; + AsciiString = DFCI_STR_SYSTEM_PASSWORD_NOT_SET; } ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); @@ -474,17 +472,17 @@ ProviderValueAsAscii ( } if (b == DfciUsbPortHwDisabled) { - AsciiString = "UsbPortHwDisabled"; + AsciiString = DFCI_STR_USB_PORT_HW_DISABLED; } else if (b == DfciUsbPortEnabled) { - AsciiString = "UsbPortEnabled"; + AsciiString = DFCI_STR_USB_PORT_ENABLED; } else if (b == DfciUsbPortDataDisabled) { - AsciiString = "UsbPortDataDisabled"; + AsciiString = DFCI_STR_USB_PORT_DATA_DISABLED; } else if (b == DfciUsbPortAuthenticated) { - AsciiString = "UsbPortAuthenticated"; + AsciiString = DFCI_STR_USB_PORT_AUTHENTICATED; } else if (b == ENABLE_INCONSISTENT) { - AsciiString = "Inconsistent"; + AsciiString = DFCI_STR_INCONSISTENT; } else { - AsciiString = "UnsupportedValue"; + AsciiString = DFCI_STR_UNSUPPORTED_VALUE; } ValueSize = AsciiStrnSizeS (AsciiString, DFCI_MAX_ID_LEN); @@ -631,10 +629,10 @@ ProviderValueAsAscii ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Unable to get strings from the certificate\n")); - ValueSize = sizeof (CERT_NOT_AVAILABLE); + ValueSize = sizeof (DRCI_STR_CERT_NOT_AVAILABLE); Value = AllocatePool (ValueSize); if (NULL != Value) { - AsciiStrnCpyS (Value, ValueSize, CERT_NOT_AVAILABLE, ValueSize-sizeof (CHAR8)); + AsciiStrnCpyS (Value, ValueSize, DRCI_STR_CERT_NOT_AVAILABLE, ValueSize-sizeof (CHAR8)); } } From 19d12f02dc156bed9e0df729486e86f8e0124c1f Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 22:33:26 +0800 Subject: [PATCH 07/11] Update DfciPkg/Include/DfciSystemSettingStrings.h Co-authored-by: Michael Kubacki --- DfciPkg/Include/DfciSystemSettingStrings.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DfciPkg/Include/DfciSystemSettingStrings.h b/DfciPkg/Include/DfciSystemSettingStrings.h index 6c1a0c45..eb36c451 100644 --- a/DfciPkg/Include/DfciSystemSettingStrings.h +++ b/DfciPkg/Include/DfciSystemSettingStrings.h @@ -56,6 +56,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define DFCI_STR_INCONSISTENT "Inconsistent" #define DFCI_STR_UNKNOWN "Unknown" #define DFCI_STR_UNSUPPORTED_VALUE "UnsupportedValue" -#define DRCI_STR_CERT_NOT_AVAILABLE "No Cert information available" +#define DFCI_STR_CERT_NOT_AVAILABLE "No Cert information available" + #endif // __DFCI_SETTING_STRINGS_H__ From 80d8b090417998dd451596265d267dbad312e864 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 22:33:38 +0800 Subject: [PATCH 08/11] Update DfciPkg/SettingsManager/SettingsManagerProvider.c Co-authored-by: Michael Kubacki --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index 8351b0a7..4e436cb6 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -632,7 +632,8 @@ ProviderValueAsAscii ( ValueSize = sizeof (DRCI_STR_CERT_NOT_AVAILABLE); Value = AllocatePool (ValueSize); if (NULL != Value) { - AsciiStrnCpyS (Value, ValueSize, DRCI_STR_CERT_NOT_AVAILABLE, ValueSize-sizeof (CHAR8)); + AsciiStrnCpyS (Value, ValueSize, DFCI_STR_CERT_NOT_AVAILABLE, ValueSize-sizeof (CHAR8)); + } } From 00e46b59d858a413e59aa16e7994f0cace9a0bfe Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 22:33:51 +0800 Subject: [PATCH 09/11] Update DfciPkg/SettingsManager/SettingsManagerProvider.c Co-authored-by: Michael Kubacki --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index 4e436cb6..b31b3969 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -629,7 +629,8 @@ ProviderValueAsAscii ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Unable to get strings from the certificate\n")); - ValueSize = sizeof (DRCI_STR_CERT_NOT_AVAILABLE); + ValueSize = sizeof (DFCI_STR_CERT_NOT_AVAILABLE); + Value = AllocatePool (ValueSize); if (NULL != Value) { AsciiStrnCpyS (Value, ValueSize, DFCI_STR_CERT_NOT_AVAILABLE, ValueSize-sizeof (CHAR8)); From 84b319a1b6b16c99f1a5eb98186874ef261af180 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 22:36:56 +0800 Subject: [PATCH 10/11] Remove empty line --- DfciPkg/Include/DfciSystemSettingStrings.h | 1 - 1 file changed, 1 deletion(-) diff --git a/DfciPkg/Include/DfciSystemSettingStrings.h b/DfciPkg/Include/DfciSystemSettingStrings.h index eb36c451..eecf4f99 100644 --- a/DfciPkg/Include/DfciSystemSettingStrings.h +++ b/DfciPkg/Include/DfciSystemSettingStrings.h @@ -58,5 +58,4 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define DFCI_STR_UNSUPPORTED_VALUE "UnsupportedValue" #define DFCI_STR_CERT_NOT_AVAILABLE "No Cert information available" - #endif // __DFCI_SETTING_STRINGS_H__ From eb51f4d8a105a367ad92fd4ec29dbcfe2d5ef629 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Fri, 10 Mar 2023 23:25:01 +0800 Subject: [PATCH 11/11] Format code --- DfciPkg/SettingsManager/SettingsManagerProvider.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DfciPkg/SettingsManager/SettingsManagerProvider.c b/DfciPkg/SettingsManager/SettingsManagerProvider.c index b31b3969..b848fbba 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvider.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvider.c @@ -631,10 +631,9 @@ ProviderValueAsAscii ( DEBUG ((DEBUG_ERROR, "Unable to get strings from the certificate\n")); ValueSize = sizeof (DFCI_STR_CERT_NOT_AVAILABLE); - Value = AllocatePool (ValueSize); + Value = AllocatePool (ValueSize); if (NULL != Value) { AsciiStrnCpyS (Value, ValueSize, DFCI_STR_CERT_NOT_AVAILABLE, ValueSize-sizeof (CHAR8)); - } }