summaryrefslogtreecommitdiffstats
path: root/src/net/tcp/httpbasic.c
diff options
context:
space:
mode:
authorMichael Brown2017-11-11 23:05:53 +0100
committerMichael Brown2017-11-12 19:52:04 +0100
commit96bd872c0342fcc290e9162154d07371405cf384 (patch)
treedcae7f76bfc6a5d86f839d545c85849367fd7b5d /src/net/tcp/httpbasic.c
parent[http] Gracefully handle offers of multiple authentication schemes (diff)
downloadipxe-96bd872c0342fcc290e9162154d07371405cf384.tar.gz
ipxe-96bd872c0342fcc290e9162154d07371405cf384.tar.xz
ipxe-96bd872c0342fcc290e9162154d07371405cf384.zip
[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>
Diffstat (limited to 'src/net/tcp/httpbasic.c')
-rw-r--r--src/net/tcp/httpbasic.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/net/tcp/httpbasic.c b/src/net/tcp/httpbasic.c
index 7ed7de9e..52a67063 100644
--- a/src/net/tcp/httpbasic.c
+++ b/src/net/tcp/httpbasic.c
@@ -43,13 +43,32 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
"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
*
* @v http HTTP transaction
* @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,
};