TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishPlatformCredentialLib.c
Go to the documentation of this file.
1
9#include <Uefi.h>
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
14#include <Library/UefiLib.h>
15
17
18#include <Guid/GlobalVariable.h>
20
21BOOLEAN mSecureBootDisabled = FALSE;
22BOOLEAN mStopRedfishService = FALSE;
23
25EFIAPI
29 );
30
45 OUT CHAR8 **UserId,
46 OUT CHAR8 **Password
47 )
48{
49 UINTN UserIdSize;
50 UINTN PasswordSize;
51
52 //
53 // AuthMethod set to HTTP Basic authentication.
54 //
55 *AuthMethod = AuthMethodHttpBasic;
56
57 //
58 // User ID and Password.
59 //
60 UserIdSize = AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdRedfishServiceUserId));
61 PasswordSize = AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdRedfishServicePassword));
62 if ((UserIdSize == 0) || (PasswordSize == 0)) {
63 DEBUG ((DEBUG_ERROR, "Incorrect string of UserID or Password for REdfish service.\n"));
64 return EFI_INVALID_PARAMETER;
65 }
66
67 *UserId = AllocateZeroPool (UserIdSize);
68 if (*UserId == NULL) {
69 return EFI_OUT_OF_RESOURCES;
70 }
71
72 CopyMem (*UserId, (CHAR8 *)PcdGetPtr (PcdRedfishServiceUserId), UserIdSize);
73
74 *Password = AllocateZeroPool (PasswordSize);
75 if (*Password == NULL) {
76 FreePool (*UserId);
77 return EFI_OUT_OF_RESOURCES;
78 }
79
80 CopyMem (*Password, (CHAR8 *)PcdGetPtr (PcdRedfishServicePassword), PasswordSize);
81 return EFI_SUCCESS;
82}
83
109EFIAPI
112 OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
113 OUT CHAR8 **UserId,
114 OUT CHAR8 **Password
115 )
116{
117 EFI_STATUS Status;
118
119 if ((This == NULL) || (AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
120 return EFI_INVALID_PARAMETER;
121 }
122
123 if (mStopRedfishService) {
124 return EFI_ACCESS_DENIED;
125 }
126
127 if (mSecureBootDisabled) {
129 if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
130 DEBUG ((DEBUG_ERROR, "SecureBoot has been disabled, but failed to stop RedfishService - %r\n", Status));
131 return Status;
132 }
133 }
134
135 Status = GetRedfishCredential (
136 AuthMethod,
137 UserId,
138 Password
139 );
140
141 return Status;
142}
143
162EFIAPI
166 )
167{
168 EFI_STATUS Status;
169 UINT8 *SecureBootVar;
170
171 if (ServiceStopType >= ServiceStopTypeMax) {
172 return EFI_INVALID_PARAMETER;
173 }
174
175 if (ServiceStopType == ServiceStopTypeSecureBootDisabled) {
176 //
177 // Check platform PCD to determine the action for stopping
178 // Redfish service due to secure boot is disabled.
179 //
180 if (!PcdGetBool (PcdRedfishServiceStopIfSecureBootDisabled)) {
181 return EFI_UNSUPPORTED;
182 } else {
183 //
184 // Check Secure Boot status and lock Redfish service if Secure Boot is disabled.
185 //
186 Status = GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID **)&SecureBootVar, NULL);
187 if (EFI_ERROR (Status) || (*SecureBootVar != SECURE_BOOT_MODE_ENABLE)) {
188 //
189 // Secure Boot is disabled
190 //
191 mSecureBootDisabled = TRUE;
192 mStopRedfishService = TRUE;
193 DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped due to SecureBoot is disabled!!\n"));
194 }
195 }
196 } else if (ServiceStopType == ServiceStopTypeExitBootService) {
197 //
198 // Check platform PCD to determine the action for stopping
199 // Redfish service due to exit boot service.
200 //
201 if (PcdGetBool (PcdRedfishServiceStopIfExitbootService)) {
202 return EFI_UNSUPPORTED;
203 } else {
204 mStopRedfishService = TRUE;
205 DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped due to Exit Boot Service!!\n"));
206 }
207 } else {
208 mStopRedfishService = TRUE;
209 DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped without Redfish service stop type!!\n"));
210 }
211
212 return EFI_SUCCESS;
213}
214
220VOID
221EFIAPI
224 )
225{
226}
227
233VOID
234EFIAPI
237 )
238{
239}
UINT64 UINTN
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE
@ ServiceStopTypeSecureBootDisabled
@ ServiceStopTypeExitBootService
EDKII_REDFISH_AUTH_METHOD
@ AuthMethodHttpBasic
Basic authentication is required.
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define EFI_SECURE_BOOT_MODE_NAME
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
EFI_STATUS EFIAPI LibStopRedfishService(IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType)
VOID EFIAPI LibCredentialExitBootServicesNotify(IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This)
EFI_STATUS EFIAPI LibCredentialGetAuthInfo(IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId, OUT CHAR8 **Password)
EFI_STATUS GetRedfishCredential(OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId, OUT CHAR8 **Password)
VOID EFIAPI LibCredentialEndOfDxeNotify(IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1317