Apache HTTPD
Classes | Macros | Typedefs | Enumerations | Functions | Variables
mod_auth_digest.c File Reference
#include "apr_sha1.h"
#include "apr_base64.h"
#include "apr_lib.h"
#include "apr_time.h"
#include "apr_errno.h"
#include "apr_global_mutex.h"
#include "apr_strings.h"
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_log.h"
#include "http_protocol.h"
#include "apr_uri.h"
#include "util_md5.h"
#include "util_mutex.h"
#include "apr_shm.h"
#include "apr_rmm.h"
#include "ap_provider.h"
#include "mod_auth.h"

Go to the source code of this file.

Classes

struct  digest_config_struct
 
struct  hash_entry
 
struct  hash_table
 
struct  digest_header_struct
 
union  time_union
 

Macros

#define APR_WANT_STRFUNC
 
#define DFLT_ALGORITHM   "MD5"
 
#define DFLT_NONCE_LIFE   apr_time_from_sec(300)
 
#define NEXTNONCE_DELTA   apr_time_from_sec(30)
 
#define NONCE_TIME_LEN   (((sizeof(apr_time_t)+2)/3)*4)
 
#define NONCE_HASH_LEN   (2*APR_SHA1_DIGESTSIZE)
 
#define NONCE_LEN   (int )(NONCE_TIME_LEN + NONCE_HASH_LEN)
 
#define SECRET_LEN   20
 
#define RETAINED_DATA_ID   "mod_auth_digest"
 
#define DEF_SHMEM_SIZE   1000L /* ~ 12 entries */
 
#define DEF_NUM_BUCKETS   15L
 
#define HASH_DEPTH   5
 

Typedefs

typedef struct digest_config_struct digest_config_rec
 
typedef struct hash_entry client_entry
 
typedef struct digest_header_struct digest_header_rec
 
typedef union time_union time_rec
 

Enumerations

enum  hdr_sts { NO_HEADER , NOT_DIGEST , INVALID , VALID }
 

Functions

static apr_status_t cleanup_tables (void *not_used)
 
static void log_error_and_cleanup (char *msg, apr_status_t sts, server_rec *s)
 
static void * rmm_malloc (apr_rmm_t *rmm, apr_size_t size)
 
static apr_status_t rmm_free (apr_rmm_t *rmm, void *alloc)
 
static int pre_init (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
 
static int initialize_module (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 
static void initialize_child (apr_pool_t *p, server_rec *s)
 
static void * create_digest_dir_config (apr_pool_t *p, char *dir)
 
static const charset_realm (cmd_parms *cmd, void *config, const char *realm)
 
static const charadd_authn_provider (cmd_parms *cmd, void *config, const char *arg)
 
static const charset_qop (cmd_parms *cmd, void *config, const char *op)
 
static const charset_nonce_lifetime (cmd_parms *cmd, void *config, const char *t)
 
static const charset_nonce_format (cmd_parms *cmd, void *config, const char *fmt)
 
static const charset_nc_check (cmd_parms *cmd, void *config, int flag)
 
static const charset_algorithm (cmd_parms *cmd, void *config, const char *alg)
 
static const charset_uri_list (cmd_parms *cmd, void *config, const char *uri)
 
static const charset_shmem_size (cmd_parms *cmd, void *config, const char *size_str)
 
static client_entryget_client (unsigned long key, const request_rec *r)
 
static long gc (server_rec *s)
 
static client_entryadd_client (unsigned long key, client_entry *info, server_rec *s)
 
static int get_digest_rec (request_rec *r, digest_header_rec *resp)
 
static int parse_hdr_and_update_nc (request_rec *r)
 
static void gen_nonce_hash (char *hash, const char *timestr, const char *opaque, const server_rec *server, const digest_config_rec *conf)
 
static const chargen_nonce (apr_pool_t *p, apr_time_t now, const char *opaque, const server_rec *server, const digest_config_rec *conf)
 
static client_entrygen_client (const request_rec *r)
 
static const charltox (apr_pool_t *p, unsigned long num)
 
static void note_digest_auth_failure (request_rec *r, const digest_config_rec *conf, digest_header_rec *resp, int stale)
 
static int hook_note_digest_auth_failure (request_rec *r, const char *auth_type)
 
static authn_status get_hash (request_rec *r, const char *user, digest_config_rec *conf, const char **rethash)
 
static int check_nc (const request_rec *r, const digest_header_rec *resp, const digest_config_rec *conf)
 
static int check_nonce (request_rec *r, digest_header_rec *resp, const digest_config_rec *conf)
 
static const charold_digest (const request_rec *r, const digest_header_rec *resp)
 
static const charnew_digest (const request_rec *r, digest_header_rec *resp)
 
static void copy_uri_components (apr_uri_t *dst, apr_uri_t *src, request_rec *r)
 
static int authenticate_digest_user (request_rec *r)
 
static int add_auth_info (request_rec *r)
 
static void register_hooks (apr_pool_t *p)
 

Variables

static struct hash_tableclient_list
 
static unsigned charsecret
 
static apr_shm_tclient_shm = NULL
 
static apr_rmm_tclient_rmm = NULL
 
static unsigned longopaque_cntr
 
static apr_time_totn_counter
 
static apr_global_mutex_tclient_lock = NULL
 
static apr_global_mutex_topaque_lock = NULL
 
static const charclient_mutex_type = "authdigest-client"
 
static const charopaque_mutex_type = "authdigest-opaque"
 
static const charclient_shm_filename
 
static apr_size_t shmem_size = 1000L
 
static unsigned long num_buckets = 15L
 
static const command_rec digest_cmds []
 
static int *const aplog_module_index = &( auth_digest_module.module_index)
 

Macro Definition Documentation

◆ APR_WANT_STRFUNC

#define APR_WANT_STRFUNC

Definition at line 60 of file mod_auth_digest.c.

◆ DEF_NUM_BUCKETS

#define DEF_NUM_BUCKETS   15L

Definition at line 182 of file mod_auth_digest.c.

◆ DEF_SHMEM_SIZE

#define DEF_SHMEM_SIZE   1000L /* ~ 12 entries */

Definition at line 181 of file mod_auth_digest.c.

◆ DFLT_ALGORITHM

#define DFLT_ALGORITHM   "MD5"

Definition at line 98 of file mod_auth_digest.c.

◆ DFLT_NONCE_LIFE

#define DFLT_NONCE_LIFE   apr_time_from_sec(300)

Definition at line 100 of file mod_auth_digest.c.

◆ HASH_DEPTH

#define HASH_DEPTH   5

Definition at line 183 of file mod_auth_digest.c.

◆ NEXTNONCE_DELTA

#define NEXTNONCE_DELTA   apr_time_from_sec(30)

Definition at line 101 of file mod_auth_digest.c.

◆ NONCE_HASH_LEN

#define NONCE_HASH_LEN   (2*APR_SHA1_DIGESTSIZE)

Definition at line 105 of file mod_auth_digest.c.

◆ NONCE_LEN

#define NONCE_LEN   (int )(NONCE_TIME_LEN + NONCE_HASH_LEN)

Definition at line 106 of file mod_auth_digest.c.

◆ NONCE_TIME_LEN

#define NONCE_TIME_LEN   (((sizeof(apr_time_t)+2)/3)*4)

Definition at line 104 of file mod_auth_digest.c.

◆ RETAINED_DATA_ID

#define RETAINED_DATA_ID   "mod_auth_digest"

Definition at line 109 of file mod_auth_digest.c.

◆ SECRET_LEN

#define SECRET_LEN   20

Definition at line 108 of file mod_auth_digest.c.

Typedef Documentation

◆ client_entry

◆ digest_config_rec

◆ digest_header_rec

◆ time_rec

Enumeration Type Documentation

◆ hdr_sts

Enumerator
NO_HEADER 
NOT_DIGEST 
INVALID 
VALID 

Definition at line 133 of file mod_auth_digest.c.

Function Documentation

◆ add_auth_info()

static int add_auth_info ( request_rec r)
static

< Module has handled this stage.

< Standard proxy

< Module has handled this stage.

Definition at line 1861 of file mod_auth_digest.c.

◆ add_authn_provider()

static const char * add_authn_provider ( cmd_parms cmd,
void *  config,
const char arg 
)
static

Definition at line 511 of file mod_auth_digest.c.

◆ add_client()

static client_entry * add_client ( unsigned long  key,
client_entry info,
server_rec s 
)
static

Definition at line 859 of file mod_auth_digest.c.

◆ authenticate_digest_user()

static int authenticate_digest_user ( request_rec r)
static

< Module declines to handle

< Module has handled this stage.

< Module has handled this stage.

Definition at line 1582 of file mod_auth_digest.c.

◆ check_nc()

static int check_nc ( const request_rec r,
const digest_header_rec resp,
const digest_config_rec conf 
)
static

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

Definition at line 1369 of file mod_auth_digest.c.

◆ check_nonce()

static int check_nonce ( request_rec r,
digest_header_rec resp,
const digest_config_rec conf 
)
static

< Module has handled this stage.

Definition at line 1422 of file mod_auth_digest.c.

◆ cleanup_tables()

static apr_status_t cleanup_tables ( void *  not_used)
static

Definition at line 195 of file mod_auth_digest.c.

◆ copy_uri_components()

static void copy_uri_components ( apr_uri_t dst,
apr_uri_t src,
request_rec r 
)
static

Definition at line 1525 of file mod_auth_digest.c.

◆ create_digest_dir_config()

static void * create_digest_dir_config ( apr_pool_t p,
char dir 
)
static

Definition at line 459 of file mod_auth_digest.c.

◆ gc()

static long gc ( server_rec s)
static

Definition at line 806 of file mod_auth_digest.c.

◆ gen_client()

static client_entry * gen_client ( const request_rec r)
static

Definition at line 1142 of file mod_auth_digest.c.

◆ gen_nonce()

static const char * gen_nonce ( apr_pool_t p,
apr_time_t  now,
const char opaque,
const server_rec server,
const digest_config_rec conf 
)
static

Definition at line 1107 of file mod_auth_digest.c.

◆ gen_nonce_hash()

static void gen_nonce_hash ( char hash,
const char timestr,
const char opaque,
const server_rec server,
const digest_config_rec conf 
)
static

Definition at line 1080 of file mod_auth_digest.c.

◆ get_client()

static client_entry * get_client ( unsigned long  key,
const request_rec r 
)
static

Definition at line 763 of file mod_auth_digest.c.

◆ get_digest_rec()

static int get_digest_rec ( request_rec r,
digest_header_rec resp 
)
static

< Standard proxy

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

Definition at line 917 of file mod_auth_digest.c.

◆ get_hash()

static authn_status get_hash ( request_rec r,
const char user,
digest_config_rec conf,
const char **  rethash 
)
static

Definition at line 1310 of file mod_auth_digest.c.

◆ hook_note_digest_auth_failure()

static int hook_note_digest_auth_failure ( request_rec r,
const char auth_type 
)
static

< Module declines to handle

< Module has handled this stage.

Definition at line 1272 of file mod_auth_digest.c.

◆ initialize_child()

static void initialize_child ( apr_pool_t p,
server_rec s 
)
static

Definition at line 421 of file mod_auth_digest.c.

◆ initialize_module()

static int initialize_module ( apr_pool_t p,
apr_pool_t plog,
apr_pool_t ptemp,
server_rec s 
)
static

< Module has handled this stage.

< Module has handled this stage.

Definition at line 394 of file mod_auth_digest.c.

◆ log_error_and_cleanup()

static void log_error_and_cleanup ( char msg,
apr_status_t  sts,
server_rec s 
)
static

Definition at line 225 of file mod_auth_digest.c.

◆ ltox()

static const char * ltox ( apr_pool_t p,
unsigned long  num 
)
static

Definition at line 1169 of file mod_auth_digest.c.

◆ new_digest()

static const char * new_digest ( const request_rec r,
digest_header_rec resp 
)
static

Definition at line 1507 of file mod_auth_digest.c.

◆ note_digest_auth_failure()

static void note_digest_auth_failure ( request_rec r,
const digest_config_rec conf,
digest_header_rec resp,
int  stale 
)
static

< Standard proxy

Definition at line 1179 of file mod_auth_digest.c.

◆ old_digest()

static const char * old_digest ( const request_rec r,
const digest_header_rec resp 
)
static

Definition at line 1494 of file mod_auth_digest.c.

◆ parse_hdr_and_update_nc()

static int parse_hdr_and_update_nc ( request_rec r)
static

< Module declines to handle

< Module has handled this stage.

< Module declines to handle

Definition at line 1047 of file mod_auth_digest.c.

◆ pre_init()

static int pre_init ( apr_pool_t pconf,
apr_pool_t plog,
apr_pool_t ptemp 
)
static

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

Definition at line 362 of file mod_auth_digest.c.

◆ register_hooks()

static void register_hooks ( apr_pool_t p)
static

< Run access control hooks only on internal requests with configurations distinct from that of initial request

Definition at line 1955 of file mod_auth_digest.c.

◆ rmm_free()

static apr_status_t rmm_free ( apr_rmm_t rmm,
void *  alloc 
)
static

Definition at line 247 of file mod_auth_digest.c.

◆ rmm_malloc()

static void * rmm_malloc ( apr_rmm_t rmm,
apr_size_t  size 
)
static

Definition at line 236 of file mod_auth_digest.c.

◆ set_algorithm()

static const char * set_algorithm ( cmd_parms cmd,
void *  config,
const char alg 
)
static

Definition at line 615 of file mod_auth_digest.c.

◆ set_nc_check()

static const char * set_nc_check ( cmd_parms cmd,
void *  config,
int  flag 
)
static

Definition at line 601 of file mod_auth_digest.c.

◆ set_nonce_format()

static const char * set_nonce_format ( cmd_parms cmd,
void *  config,
const char fmt 
)
static

Definition at line 595 of file mod_auth_digest.c.

◆ set_nonce_lifetime()

static const char * set_nonce_lifetime ( cmd_parms cmd,
void *  config,
const char t 
)
static

Definition at line 578 of file mod_auth_digest.c.

◆ set_qop()

static const char * set_qop ( cmd_parms cmd,
void *  config,
const char op 
)
static

Definition at line 556 of file mod_auth_digest.c.

◆ set_realm()

static const char * set_realm ( cmd_parms cmd,
void *  config,
const char realm 
)
static

Definition at line 478 of file mod_auth_digest.c.

◆ set_shmem_size()

static const char * set_shmem_size ( cmd_parms cmd,
void *  config,
const char size_str 
)
static

Definition at line 642 of file mod_auth_digest.c.

◆ set_uri_list()

static const char * set_uri_list ( cmd_parms cmd,
void *  config,
const char uri 
)
static

Definition at line 629 of file mod_auth_digest.c.

Variable Documentation

◆ aplog_module_index

int* const aplog_module_index = &( auth_digest_module.module_index)
static

Definition at line 1973 of file mod_auth_digest.c.

◆ client_list

struct hash_table * client_list
static

◆ client_lock

apr_global_mutex_t* client_lock = NULL
static

Definition at line 175 of file mod_auth_digest.c.

◆ client_mutex_type

const char* client_mutex_type = "authdigest-client"
static

Definition at line 177 of file mod_auth_digest.c.

◆ client_rmm

apr_rmm_t* client_rmm = NULL
static

Definition at line 172 of file mod_auth_digest.c.

◆ client_shm

apr_shm_t* client_shm = NULL
static

Definition at line 171 of file mod_auth_digest.c.

◆ client_shm_filename

const char* client_shm_filename
static

Definition at line 179 of file mod_auth_digest.c.

◆ digest_cmds

const command_rec digest_cmds[]
static
Initial value:
=
{
{ "AuthName" , set_realm , NULL , 8 , TAKE1, "The authentication realm (e.g. \"Members Only\")" },
{ "AuthDigestProvider" , add_authn_provider , NULL , 8 , ITERATE, "specify the auth providers for a directory or location" },
{ "AuthDigestQop" , set_qop , NULL , 8 , ITERATE, "A list of quality-of-protection options" },
{ "AuthDigestNonceLifetime" , set_nonce_lifetime , NULL , 8 , TAKE1, "Maximum lifetime of the server nonce (seconds)" },
{ "AuthDigestNonceFormat" , set_nonce_format , NULL , 8 , TAKE1, "The format to use when generating the server nonce" },
{ "AuthDigestNcCheck" , set_nc_check , NULL , 8 , FLAG, "Whether or not to check the nonce-count sent by the client" },
{ "AuthDigestAlgorithm" , set_algorithm , NULL , 8 , TAKE1, "The algorithm used for the hash calculation" },
{ "AuthDigestDomain" , set_uri_list , NULL , 8 , ITERATE, "A list of URI's which belong to the same protection space as the current URI" },
{ "AuthDigestShmemSize" , set_shmem_size , NULL , 128 , TAKE1, "The amount of shared memory to allocate for keeping track of clients" },
{NULL}
}
@ TAKE1
Definition http_config.h:51
@ FLAG
Definition http_config.h:59
@ ITERATE
Definition http_config.h:53
static const char * set_uri_list(cmd_parms *cmd, void *config, const char *uri)
static const char * add_authn_provider(cmd_parms *cmd, void *config, const char *arg)
static const char * set_shmem_size(cmd_parms *cmd, void *config, const char *size_str)
static const char * set_realm(cmd_parms *cmd, void *config, const char *realm)
static const char * set_nonce_format(cmd_parms *cmd, void *config, const char *fmt)
static const char * set_nonce_lifetime(cmd_parms *cmd, void *config, const char *t)
static const char * set_qop(cmd_parms *cmd, void *config, const char *op)
static const char * set_nc_check(cmd_parms *cmd, void *config, int flag)
static const char * set_algorithm(cmd_parms *cmd, void *config, const char *alg)
return NULL
Definition mod_so.c:359

Definition at line 683 of file mod_auth_digest.c.

◆ num_buckets

unsigned long num_buckets = 15L
static

Definition at line 186 of file mod_auth_digest.c.

◆ opaque_cntr

unsigned long* opaque_cntr
static

Definition at line 173 of file mod_auth_digest.c.

◆ opaque_lock

apr_global_mutex_t* opaque_lock = NULL
static

Definition at line 176 of file mod_auth_digest.c.

◆ opaque_mutex_type

const char* opaque_mutex_type = "authdigest-opaque"
static

Definition at line 178 of file mod_auth_digest.c.

◆ otn_counter

apr_time_t* otn_counter
static

Definition at line 174 of file mod_auth_digest.c.

◆ secret

unsigned char* secret
static

Definition at line 167 of file mod_auth_digest.c.

◆ shmem_size

apr_size_t shmem_size = 1000L
static

Definition at line 185 of file mod_auth_digest.c.