Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
auth.c File Reference

Handling of HTTP AUTH takes place here. More...

#include <ctype.h>
#include "auth.h"
#include "msg.h"
#include "misc.h"
#include "dialog.hh"
#include "digest.h"
#include "../dlib/dlib.h"
Include dependency graph for auth.c:

Go to the source code of this file.

Typedefs

typedef int() Auth_parse_token_value_callback_t(AuthParse_t *auth_parse, char *token, const char *value)
 

Functions

void a_Auth_init (void)
 Initialize the auth module.
 
static AuthParse_t * Auth_parse_new (void)
 
static void Auth_parse_free (AuthParse_t *auth_parse)
 
static int Auth_path_is_inside (const char *path1, const char *path2, int len)
 
static int Auth_is_token_char (char c)
 Check valid chars.
 
static DstrAuth_unquote_value (char **valuep)
 Unquote the content of a (potentially) quoted string.
 
static int Auth_parse_token_value (AuthParse_t *auth_parse, char **auth, Auth_parse_token_value_callback_t *callback)
 Parse authentication challenge into token-value pairs and feed them into the callback function.
 
static int Auth_parse_basic_challenge_cb (AuthParse_t *auth_parse, char *token, const char *value)
 
static int Auth_parse_digest_challenge_cb (AuthParse_t *auth_parse, char *token, const char *value)
 
static void Auth_parse_challenge_args (AuthParse_t *auth_parse, char **challenge, Auth_parse_token_value_callback_t *cb)
 
static void Auth_parse_challenge (AuthParse_t *auth_parse, char *challenge)
 
static AuthHost_t * Auth_host_by_url (const DilloUrl *url)
 Return the host that contains a URL, or NULL if there is no such host.
 
static AuthRealm_tAuth_realm_by_name (const AuthHost_t *host, const char *name)
 Search all realms for the one with the given name.
 
static AuthRealm_tAuth_realm_by_path (const AuthHost_t *host, const char *path)
 Search all realms for the one with the best-matching path.
 
static void Auth_realm_delete (AuthRealm_t *realm)
 
static int Auth_realm_includes_path (const AuthRealm_t *realm, const char *path)
 
static void Auth_realm_add_path (AuthRealm_t *realm, const char *path)
 
char * a_Auth_get_auth_str (const DilloUrl *url, const char *request_uri)
 Return the authorization header for an HTTP query.
 
static int Auth_do_auth_required (const AuthParse_t *auth_parse, const DilloUrl *url)
 Determine whether the user needs to authenticate.
 
static void Auth_do_auth_dialog_cb (const char *user, const char *password, void *vData)
 
static int Auth_do_auth_dialog (const AuthParse_t *auth_parse, const DilloUrl *url)
 
static int Auth_do_auth (char *challenge, enum AuthParseHTTPAuthType_t type, const DilloUrl *url)
 Do authorization for an auth string.
 
int a_Auth_do_auth (Dlist *challenges, const DilloUrl *url)
 Given authentication challenge(s), prepare authorization.
 

Variables

static Dlistauth_hosts
 Local data.
 

Detailed Description

Handling of HTTP AUTH takes place here.

This implementation aims to follow RFC 2617: http://www.ietf.org/rfc/rfc2617.txt

Definition in file auth.c.

Typedef Documentation

◆ Auth_parse_token_value_callback_t

typedef int() Auth_parse_token_value_callback_t(AuthParse_t *auth_parse, char *token, const char *value)

Definition at line 151 of file auth.c.

Function Documentation

◆ a_Auth_do_auth()

int a_Auth_do_auth ( Dlist challenges,
const DilloUrl url 
)

Given authentication challenge(s), prepare authorization.

Return: 0 on failure nonzero on success. A new query will be sent to the server.

Definition at line 671 of file auth.c.

References Auth_do_auth(), BASIC, DIGEST, dList_nth_data(), and dStrnAsciiCasecmp().

Referenced by Cache_auth_callback().

◆ a_Auth_get_auth_str()

char * a_Auth_get_auth_str ( const DilloUrl url,
const char *  request_uri 
)

Return the authorization header for an HTTP query.

request_uri is a separate argument because we want it precisely as formatted in the request.

Definition at line 472 of file auth.c.

References a_Digest_authorization_hdr(), Auth_host_by_url(), Auth_realm_by_path(), AuthRealm_t::authorization, BASIC, DIGEST, dStrdup(), MSG, AuthRealm_t::type, and URL_PATH.

Referenced by Http_make_query_str().

◆ a_Auth_init()

void a_Auth_init ( void  )

Initialize the auth module.

Definition at line 59 of file auth.c.

References auth_hosts, and dList_new().

Referenced by main().

◆ Auth_do_auth()

static int Auth_do_auth ( char *  challenge,
enum AuthParseHTTPAuthType_t  type,
const DilloUrl url 
)
static

Do authorization for an auth string.

Definition at line 646 of file auth.c.

References _MSG, Auth_do_auth_dialog(), Auth_do_auth_required(), Auth_parse_challenge(), Auth_parse_free(), and Auth_parse_new().

Referenced by a_Auth_do_auth().

◆ Auth_do_auth_dialog()

static int Auth_do_auth_dialog ( const AuthParse_t *  auth_parse,
const DilloUrl url 
)
static

◆ Auth_do_auth_dialog_cb()

◆ Auth_do_auth_required()

static int Auth_do_auth_required ( const AuthParse_t *  auth_parse,
const DilloUrl url 
)
static

Determine whether the user needs to authenticate.

Definition at line 494 of file auth.c.

References _MSG, Auth_host_by_url(), Auth_realm_add_path(), Auth_realm_by_name(), Auth_realm_includes_path(), dFree(), DIGEST, dStrdup(), AuthRealm_t::nonce, URL_PATH, and URL_STR.

Referenced by Auth_do_auth().

◆ Auth_host_by_url()

static AuthHost_t * Auth_host_by_url ( const DilloUrl url)
static

Return the host that contains a URL, or NULL if there is no such host.

Definition at line 357 of file auth.c.

References auth_hosts, dList_nth_data(), dStrAsciiCasecmp(), URL_AUTHORITY, and URL_SCHEME.

Referenced by a_Auth_get_auth_str(), Auth_do_auth_dialog_cb(), and Auth_do_auth_required().

◆ Auth_is_token_char()

static int Auth_is_token_char ( char  c)
static

Check valid chars.

Return: 0 if invalid, 1 otherwise.

Definition at line 105 of file auth.c.

References d_isascii.

Referenced by Auth_parse_token_value(), and Auth_unquote_value().

◆ Auth_parse_basic_challenge_cb()

static int Auth_parse_basic_challenge_cb ( AuthParse_t *  auth_parse,
char *  token,
const char *  value 
)
static

Definition at line 229 of file auth.c.

References dStrAsciiCasecmp(), dStrdup(), and MSG.

Referenced by Auth_parse_challenge().

◆ Auth_parse_challenge()

static void Auth_parse_challenge ( AuthParse_t *  auth_parse,
char *  challenge 
)
static

◆ Auth_parse_challenge_args()

static void Auth_parse_challenge_args ( AuthParse_t *  auth_parse,
char **  challenge,
Auth_parse_token_value_callback_t cb 
)
static

Definition at line 305 of file auth.c.

References Auth_parse_token_value(), BASIC, DIGEST, and MSG.

Referenced by Auth_parse_challenge().

◆ Auth_parse_digest_challenge_cb()

static int Auth_parse_digest_challenge_cb ( AuthParse_t *  auth_parse,
char *  token,
const char *  value 
)
static

Definition at line 242 of file auth.c.

References AUTH, dStrAsciiCasecmp(), dStrdup(), MD5, and MSG.

Referenced by Auth_parse_challenge().

◆ Auth_parse_free()

static void Auth_parse_free ( AuthParse_t *  auth_parse)
static

Definition at line 79 of file auth.c.

References dFree().

Referenced by Auth_do_auth().

◆ Auth_parse_new()

static AuthParse_t * Auth_parse_new ( void  )
static

Definition at line 64 of file auth.c.

References ALGORITHMNOTSET, dNew, QOPNOTSET, and TYPENOTSET.

Referenced by Auth_do_auth().

◆ Auth_parse_token_value()

static int Auth_parse_token_value ( AuthParse_t *  auth_parse,
char **  auth,
Auth_parse_token_value_callback_t callback 
)
static

Parse authentication challenge into token-value pairs and feed them into the callback function.

The parsing is aborted should the callback function return 0.

Return: 1 if the parse succeeds, 0 otherwise.

Definition at line 164 of file auth.c.

References _MSG, Auth_is_token_char(), Auth_unquote_value(), dStr_free(), MSG, MSG_WARN, and Dstr::str.

Referenced by Auth_parse_challenge_args().

◆ Auth_path_is_inside()

static int Auth_path_is_inside ( const char *  path1,
const char *  path2,
int  len 
)
static

Definition at line 90 of file auth.c.

Referenced by Auth_realm_add_path(), Auth_realm_by_path(), and Auth_realm_includes_path().

◆ Auth_realm_add_path()

static void Auth_realm_add_path ( AuthRealm_t realm,
const char *  path 
)
static

◆ Auth_realm_by_name()

static AuthRealm_t * Auth_realm_by_name ( const AuthHost_t *  host,
const char *  name 
)
static

Search all realms for the one with the given name.

Definition at line 373 of file auth.c.

References dList_nth_data(), and AuthRealm_t::name.

Referenced by Auth_do_auth_dialog_cb(), and Auth_do_auth_required().

◆ Auth_realm_by_path()

static AuthRealm_t * Auth_realm_by_path ( const AuthHost_t *  host,
const char *  path 
)
static

Search all realms for the one with the best-matching path.

Definition at line 389 of file auth.c.

References Auth_path_is_inside(), dList_nth_data(), path(), and AuthRealm_t::paths.

Referenced by a_Auth_get_auth_str().

◆ Auth_realm_delete()

◆ Auth_realm_includes_path()

static int Auth_realm_includes_path ( const AuthRealm_t realm,
const char *  path 
)
static

Definition at line 431 of file auth.c.

References Auth_path_is_inside(), dList_nth_data(), path(), and AuthRealm_t::paths.

Referenced by Auth_do_auth_required().

◆ Auth_unquote_value()

static Dstr * Auth_unquote_value ( char **  valuep)
static

Unquote the content of a (potentially) quoted string.

Return: newly allocated unquoted content.

Arguments: valuep: pointer to a pointer to the first char.

Preconditions: *valuep points to a correctly quoted and escaped string.

Postconditions: *valuep points to the first not processed char.

Definition at line 125 of file auth.c.

References Auth_is_token_char(), dStr_append_c(), and dStr_new().

Referenced by Auth_parse_token_value().

Variable Documentation

◆ auth_hosts

Dlist* auth_hosts
static

Local data.

Definition at line 54 of file auth.c.

Referenced by a_Auth_init(), Auth_do_auth_dialog_cb(), and Auth_host_by_url().