mirror of
https://github.com/ipxe/ipxe
synced 2025-12-21 04:20:17 +03:00
[http] Handle parsing of WWW-Authenticate header within authentication scheme
Allow individual authentication schemes to parse WWW-Authenticate headers that do not comply with RFC2617. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -42,6 +42,25 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
__einfo_uniqify ( EINFO_EACCES, 0x01, \
|
||||
"No username available for Basic authentication" )
|
||||
|
||||
/**
|
||||
* Parse HTTP "WWW-Authenticate" header for Basic authentication
|
||||
*
|
||||
* @v http HTTP transaction
|
||||
* @v line Remaining header line
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int http_parse_basic_auth ( struct http_transaction *http,
|
||||
char *line __unused ) {
|
||||
|
||||
/* Allow HTTP request to be retried if the request had not
|
||||
* already tried authentication.
|
||||
*/
|
||||
if ( ! http->request.auth.auth )
|
||||
http->response.flags |= HTTP_RESPONSE_RETRY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform HTTP Basic authentication
|
||||
*
|
||||
@@ -49,7 +68,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int http_basic_authenticate ( struct http_transaction *http ) {
|
||||
struct http_request_auth *req = &http->request.auth;
|
||||
struct http_request_auth_basic *req = &http->request.auth.basic;
|
||||
|
||||
/* Record username and password */
|
||||
if ( ! http->uri->user ) {
|
||||
@@ -73,7 +92,7 @@ static int http_basic_authenticate ( struct http_transaction *http ) {
|
||||
*/
|
||||
static int http_format_basic_auth ( struct http_transaction *http,
|
||||
char *buf, size_t len ) {
|
||||
struct http_request_auth *req = &http->request.auth;
|
||||
struct http_request_auth_basic *req = &http->request.auth.basic;
|
||||
size_t user_pw_len = ( strlen ( req->username ) + 1 /* ":" */ +
|
||||
strlen ( req->password ) );
|
||||
char user_pw[ user_pw_len + 1 /* NUL */ ];
|
||||
@@ -93,6 +112,7 @@ static int http_format_basic_auth ( struct http_transaction *http,
|
||||
/** HTTP Basic authentication scheme */
|
||||
struct http_authentication http_basic_auth __http_authentication = {
|
||||
.name = "Basic",
|
||||
.parse = http_parse_basic_auth,
|
||||
.authenticate = http_basic_authenticate,
|
||||
.format = http_format_basic_auth,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user