iPXE
Functions | Variables
httpauth.c File Reference

Hyper Text Transfer Protocol (HTTP) authentication. More...

#include <stdio.h>
#include <strings.h>
#include <errno.h>
#include <ipxe/http.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static struct http_authenticationhttp_authentication (const char *name)
 Identify authentication scheme. More...
 
static int http_parse_www_authenticate (struct http_transaction *http, char *line)
 Parse HTTP "WWW-Authenticate" header. More...
 
static int http_format_authorization (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Authorization" header. More...
 

Variables

struct http_response_header http_response_www_authenticate __http_response_header
 HTTP "WWW-Authenticate" header. More...
 
struct http_request_header http_request_authorization __http_request_header
 HTTP "Authorization" header. More...
 

Detailed Description

Hyper Text Transfer Protocol (HTTP) authentication.

Definition in file httpauth.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ http_authentication()

static struct http_authentication* http_authentication ( const char *  name)
static

Identify authentication scheme.

Parameters
httpHTTP transaction
nameScheme name
Return values
authAuthentication scheme, or NULL

Definition at line 46 of file httpauth.c.

46  {
47  struct http_authentication *auth;
48 
49  /* Identify authentication scheme */
51  if ( strcasecmp ( name, auth->name ) == 0 )
52  return auth;
53  }
54 
55  return NULL;
56 }
const char * name
Definition: ath9k_hw.c:1986
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:209
An HTTP authentication scheme.
Definition: http.h:519
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:386
const char * name
Name (e.g.
Definition: http.h:521
#define HTTP_AUTHENTICATIONS
HTTP authentication scheme table.
Definition: http.h:547
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References for_each_table_entry, HTTP_AUTHENTICATIONS, http_authentication::name, name, NULL, and strcasecmp().

Referenced by http_parse_www_authenticate().

◆ http_parse_www_authenticate()

static int http_parse_www_authenticate ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "WWW-Authenticate" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 65 of file httpauth.c.

66  {
67  struct http_authentication *auth;
68  char *name;
69  int rc;
70 
71  /* Get scheme name */
72  name = http_token ( &line, NULL );
73  if ( ! name ) {
74  DBGC ( http, "HTTP %p malformed WWW-Authenticate \"%s\"\n",
75  http, line );
76  return -EPROTO;
77  }
78 
79  /* Identify scheme */
80  auth = http_authentication ( name );
81  if ( ! auth ) {
82  DBGC ( http, "HTTP %p unrecognised authentication scheme "
83  "\"%s\"\n", http, name );
84  /* Ignore; the server may offer other schemes */
85  return 0;
86  }
87 
88  /* Use first supported scheme */
89  if ( http->response.auth.auth )
90  return 0;
91  http->response.auth.auth = auth;
92 
93  /* Parse remaining header line */
94  if ( ( rc = auth->parse ( http, line ) ) != 0 ) {
95  DBGC ( http, "HTTP %p could not parse %s WWW-Authenticate "
96  "\"%s\": %s\n", http, name, line, strerror ( rc ) );
97  return rc;
98  }
99 
100  return 0;
101 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
#define DBGC(...)
Definition: compiler.h:505
An HTTP authentication scheme.
Definition: http.h:519
struct http_response_auth auth
Authorization descriptor.
Definition: http.h:347
struct http_response response
Response.
Definition: http.h:439
#define EPROTO
Protocol error.
Definition: errno.h:625
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
char * http_token(char **line, char **value)
Get HTTP response token.
Definition: httpcore.c:196
struct http_authentication * auth
Authentication scheme (if any)
Definition: http.h:298
int(* parse)(struct http_transaction *http, char *line)
Parse remaining "WWW-Authenticate" header line.
Definition: http.h:528
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
static struct http_authentication * http_authentication(const char *name)
Identify authentication scheme.
Definition: httpauth.c:46

References http_response_auth::auth, http_response::auth, DBGC, EPROTO, http_authentication(), http_token(), name, NULL, http_authentication::parse, rc, http_transaction::response, and strerror().

◆ http_format_authorization()

static int http_format_authorization ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP "Authorization" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 118 of file httpauth.c.

119  {
120  struct http_authentication *auth = http->request.auth.auth;
121  size_t used;
122  int auth_len;
123  int rc;
124 
125  /* Do nothing unless we have an authentication scheme */
126  if ( ! auth )
127  return 0;
128 
129  /* Construct header */
130  used = snprintf ( buf, len, "%s ", auth->name );
131  auth_len = auth->format ( http, ( buf + used ),
132  ( ( used < len ) ? ( len - used ) : 0 ) );
133  if ( auth_len < 0 ) {
134  rc = auth_len;
135  return rc;
136  }
137  used += auth_len;
138 
139  return used;
140 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* format)(struct http_transaction *http, char *buf, size_t len)
Construct remaining "Authorization" header line.
Definition: http.h:542
An HTTP authentication scheme.
Definition: http.h:519
struct http_request request
Request.
Definition: http.h:437
struct http_request_auth auth
Authentication descriptor.
Definition: http.h:223
ring len
Length.
Definition: dwmac.h:231
struct http_authentication * auth
Authentication scheme (if any)
Definition: http.h:190
const char * name
Name (e.g.
Definition: http.h:521
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383

References http_request_auth::auth, http_request::auth, http_authentication::format, len, http_authentication::name, rc, http_transaction::request, and snprintf().

Variable Documentation

◆ __http_response_header

struct http_response_header http_response_www_authenticate __http_response_header
Initial value:
= {
.name = "WWW-Authenticate",
}
static int http_parse_www_authenticate(struct http_transaction *http, char *line)
Parse HTTP "WWW-Authenticate" header.
Definition: httpauth.c:65

HTTP "WWW-Authenticate" header.

Definition at line 105 of file httpauth.c.

◆ __http_request_header

struct http_request_header http_request_authorization __http_request_header
Initial value:
= {
.name = "Authorization",
}
static int http_format_authorization(struct http_transaction *http, char *buf, size_t len)
Construct HTTP "Authorization" header.
Definition: httpauth.c:118

HTTP "Authorization" header.

Definition at line 143 of file httpauth.c.