VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c@ 101291

最後變更 在這個檔案從101291是 99404,由 vboxsync 提交於 2 年 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 6.3 KB
 
1/** @file
2 Internal Functions for RedfishLib.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include "RedfishMisc.h"
12
13EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
14
15/**
16 This function returns the string of Redfish service version.
17
18 @param[in] RedfishService Redfish service instance.
19 @param[out] ServiceVersionStr Redfish service string.
20
21 @return EFI_STATUS
22
23**/
24EFI_STATUS
25RedfishGetServiceVersion (
26 IN REDFISH_SERVICE RedfishService,
27 OUT CHAR8 **ServiceVersionStr
28 )
29{
30 redfishService *Redfish;
31 CHAR8 **KeysArray;
32 UINTN KeysNum;
33
34 if ((RedfishService == NULL) || (ServiceVersionStr == NULL)) {
35 return EFI_INVALID_PARAMETER;
36 }
37
38 Redfish = (redfishService *)RedfishService;
39 if (Redfish->versions == NULL) {
40 return EFI_INVALID_PARAMETER;
41 }
42
43 KeysArray = JsonObjectGetKeys (Redfish->versions, &KeysNum);
44 if ((KeysNum == 0) || (KeysArray == NULL)) {
45 return EFI_NOT_FOUND;
46 }
47
48 *ServiceVersionStr = *KeysArray;
49 return EFI_SUCCESS;
50}
51
52/**
53 Creates a REDFISH_SERVICE which can be later used to access the Redfish resources.
54
55 This function will configure REST EX child according to parameters described in
56 Redfish network host interface in SMBIOS type 42 record. The service enumerator will also
57 handle the authentication flow automatically if HTTP basic auth or Redfish session
58 login is configured to use.
59
60 @param[in] RedfishConfigServiceInfo Redfish service information the EFI Redfish
61 feature driver communicates with.
62 @param[in] AuthMethod None, HTTP basic auth, or Redfish session login.
63 @param[in] UserId User Name used for authentication.
64 @param[in] Password Password used for authentication.
65
66 @return New created Redfish service, or NULL if error happens.
67
68**/
69REDFISH_SERVICE
70RedfishCreateLibredfishService (
71 IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
72 IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
73 IN CHAR8 *UserId,
74 IN CHAR8 *Password
75 )
76{
77 UINTN Flags;
78 enumeratorAuthentication Auth;
79 redfishService *Redfish;
80
81 Redfish = NULL;
82
83 ZeroMem (&Auth, sizeof (Auth));
84 if (AuthMethod == AuthMethodHttpBasic) {
85 Auth.authType = REDFISH_AUTH_BASIC;
86 } else if (AuthMethod == AuthMethodRedfishSession) {
87 Auth.authType = REDFISH_AUTH_SESSION;
88 }
89
90 Auth.authCodes.userPass.username = UserId;
91 Auth.authCodes.userPass.password = Password;
92
93 Flags = REDFISH_FLAG_SERVICE_NO_VERSION_DOC;
94
95 if (AuthMethod != AuthMethodNone) {
96 Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, &Auth, (unsigned int)Flags);
97 } else {
98 Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, NULL, (unsigned int)Flags);
99 }
100
101 //
102 // Zero the Password after use.
103 //
104 if (Password != NULL) {
105 ZeroMem (Password, AsciiStrLen (Password));
106 }
107
108 return (REDFISH_SERVICE)Redfish;
109}
110
111/**
112 Retrieve platform's Redfish authentication information.
113
114 This functions returns the Redfish authentication method together with the user
115 Id and password.
116 For AuthMethodNone, UserId and Password will point to NULL which means authentication
117 is not required to access the Redfish service.
118 For AuthMethodHttpBasic, the UserId and Password could be used for
119 HTTP header authentication as defined by RFC7235. For AuthMethodRedfishSession,
120 the UserId and Password could be used for Redfish session login as defined by
121 Redfish API specification (DSP0266).
122
123 Callers are responsible for freeing the returned string storage pointed by UserId
124 and Password.
125
126 @param[out] AuthMethod Type of Redfish authentication method.
127 @param[out] UserId The pointer to store the returned UserId string.
128 @param[out] Password The pointer to store the returned Password string.
129
130 @retval EFI_SUCCESS Get the authentication information successfully.
131 @retval EFI_INVALID_PARAMETER AuthMethod or UserId or Password is NULL.
132 @retval EFI_UNSUPPORTED Unsupported authentication method is found.
133**/
134EFI_STATUS
135RedfishGetAuthInfo (
136 OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
137 OUT CHAR8 **UserId,
138 OUT CHAR8 **Password
139 )
140{
141 EFI_STATUS Status;
142
143 if ((AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
144 return EFI_INVALID_PARAMETER;
145 }
146
147 //
148 // Locate Redfish Credential Protocol.
149 //
150 if (mCredentialProtocol == NULL) {
151 Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&mCredentialProtocol);
152 if (EFI_ERROR (Status)) {
153 return EFI_UNSUPPORTED;
154 }
155 }
156
157 ASSERT (mCredentialProtocol != NULL);
158
159 Status = mCredentialProtocol->GetAuthInfo (mCredentialProtocol, AuthMethod, UserId, Password);
160 if (EFI_ERROR (Status)) {
161 DEBUG ((DEBUG_ERROR, "RedfishGetAuthInfo: failed to retrieve Redfish credential - %r\n", Status));
162 return Status;
163 }
164
165 return Status;
166}
167
168/**
169 This function returns the string of Redfish service version.
170
171 @param[in] ServiceVerisonStr The string of Redfish service version.
172 @param[in] Url The URL to build Redpath with ID.
173 Start with "/", for example "/Registries"
174 @param[in] Id ID string
175 @param[out] Redpath Pointer to retrive Redpath, caller has to free
176 the memory allocated for this string.
177 @return EFI_STATUS
178
179**/
180EFI_STATUS
181RedfishBuildRedpathUseId (
182 IN CHAR8 *ServiceVerisonStr,
183 IN CHAR8 *Url,
184 IN CHAR8 *Id,
185 OUT CHAR8 **Redpath
186 )
187{
188 UINTN RedpathSize;
189
190 if ((Redpath == NULL) || (ServiceVerisonStr == NULL) || (Url == NULL) || (Id == NULL)) {
191 return EFI_INVALID_PARAMETER;
192 }
193
194 RedpathSize = AsciiStrLen ("/") +
195 AsciiStrLen (ServiceVerisonStr) +
196 AsciiStrLen (Url) +
197 AsciiStrLen ("[Id=]") +
198 AsciiStrLen (Id) + 1;
199 *Redpath = AllocatePool (RedpathSize);
200 if (*Redpath == NULL) {
201 return EFI_OUT_OF_RESOURCES;
202 }
203
204 AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVerisonStr, Url, Id);
205 return EFI_SUCCESS;
206}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette