mod_auth_digest.c revision 821ccfb63cb6392604cdfe9a5eea6ed1df441783
750f77ade4110c6b2315d6b9e9c22f643914d87drbb/* ====================================================================
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * The Apache Software License, Version 1.1
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * reserved.
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * Redistribution and use in source and binary forms, with or without
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * modification, are permitted provided that the following conditions
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * are met:
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * 1. Redistributions of source code must retain the above copyright
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * notice, this list of conditions and the following disclaimer.
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * 2. Redistributions in binary form must reproduce the above copyright
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * notice, this list of conditions and the following disclaimer in
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * the documentation and/or other materials provided with the
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * distribution.
3e5667f3bea0b417d0133534d960c5b86c63cf5cgstein * 3. The end-user documentation included with the redistribution,
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * if any, must include the following acknowledgment:
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * "This product includes software developed by the
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * Apache Software Foundation (http://www.apache.org/)."
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * Alternately, this acknowledgment may appear in the software itself,
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * if and wherever such third-party acknowledgments normally appear.
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * 4. The names "Apache" and "Apache Software Foundation" must
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * not be used to endorse or promote products derived from this
3e5667f3bea0b417d0133534d960c5b86c63cf5cgstein * software without prior written permission. For written
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * permission, please contact apache@apache.org.
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * 5. Products derived from this software may not be called "Apache",
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * nor may "Apache" appear in their name, without prior written
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * permission of the Apache Software Foundation.
105475009f541187ba7a14a367547d9404c578befielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
750f77ade4110c6b2315d6b9e9c22f643914d87drbb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7a6c08288f79ab1734b98afc114e52cd71f898c0jwoolley * SUCH DAMAGE.
3e5667f3bea0b417d0133534d960c5b86c63cf5cgstein * ====================================================================
* This module an updated version of modules/standard/mod_digest.c
#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"
#define APR_WANT_STRFUNC
#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 "apr_shm.h"
#include "apr_rmm.h"
#include "ap_provider.h"
#include "mod_auth.h"
#define APR_HAS_SHARED_MEMORY 0
typedef struct digest_config_struct {
const char *dir_name;
const char *realm;
char **qop_list;
const char *nonce_format;
int check_nc;
const char *algorithm;
char *uri_list;
const char *ha1;
typedef struct hash_entry {
} client_entry;
static struct hash_table {
unsigned long tbl_len;
unsigned long num_entries;
unsigned long num_created;
unsigned long num_removed;
unsigned long num_renewed;
} *client_list;
typedef struct digest_header_struct {
const char *scheme;
const char *realm;
const char *username;
char *nonce;
const char *uri;
const char *digest;
const char *algorithm;
const char *cnonce;
const char *opaque;
unsigned long opaque_num;
const char *message_qop;
const char *nonce_count;
const char *raw_request_uri;
int needed_auth;
typedef union time_union {
} time_rec;
static unsigned long *opaque_cntr;
if (client_shm) {
if (client_lock) {
if (opaque_lock) {
return APR_SUCCESS;
#if APR_HAS_RANDOM
return status;
return APR_SUCCESS;
unsigned long idx;
if (!client_list) {
*otn_counter = 0;
void *data;
if (!data) {
return OK;
return !OK;
initialize_tables(s, p);
return OK;
if (!client_shm) {
return NULL;
if (conf) {
return conf;
return DECLINE_CMD;
const char *arg)
const char *provider_name;
return NULL;
return NULL;
char **tmp;
int cnt;
return NULL;
return NULL;
char *endptr;
long lifetime;
t, NULL);
return NULL;
const char *fmt)
return NULL;
if (!client_shm) {
return NULL;
if (c->uri_list) {
return NULL;
const char *size_str)
char *endptr;
if (num_buckets == 0) {
return NULL;
{NULL}
int bucket;
if (entry) {
return entry;
static long gc(void)
if (prev) {
num_removed++;
return num_removed;
server_rec *s)
int bucket;
return NULL;
if (!entry) {
if (!entry) {
return entry;
const char *auth_line;
apr_size_t l;
if (!auth_line) {
return !OK;
return !OK;
auth_line++;
vk = 0;
auth_line++;
auth_line++;
auth_line++;
vv = 0;
auth_line++;
auth_line++;
auth_line++;
auth_line++;
return !OK;
return OK;
int res;
if (!ap_is_initial_req(r)) {
return DECLINED;
return DECLINED;
int idx;
if (opaque) {
int len;
time_rec t;
else if (otn_counter) {
return nonce;
unsigned long op;
if (!opaque_cntr) {
return NULL;
return NULL;
return entry;
* people need not modify mod_auth_digest.c each time they install a new
int generate)
else if (!generate) {
return NULL;
if (ha1) {
return ha1;
return dir;
return "http://0.0.0.0/";
return dir;
return tmp;
if (num != 0) {
int cnt;
if (opaque[0]) {
if (r->proxyreq) {
char *password;
if (!current_provider) {
&password);
} while (current_provider);
return NULL;
return password;
unsigned long nc;
char *endptr;
return OK;
return !OK;
return !OK;
return !OK;
return OK;
int len;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return OK;
const char *ha2;
if (!ha1) {
return NULL;
NULL));
int res;
return DECLINED;
if (!ap_auth_name(r)) {
return HTTP_INTERNAL_SERVER_ERROR;
mainreq = r;
r->uri);
return HTTP_UNAUTHORIZED;
return HTTP_BAD_REQUEST;
return HTTP_BAD_REQUEST;
return HTTP_BAD_REQUEST;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
r->uri);
return HTTP_UNAUTHORIZED;
const char *exp_digest;
if (!match
return HTTP_UNAUTHORIZED;
if (!exp_digest) {
return HTTP_INTERNAL_SERVER_ERROR;
r->uri);
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
return res;
return OK;
#ifdef SEND_DIGEST
if (val) {
return val;
return OK;
#ifdef SEND_DIGEST
char *entity_info =
date :
NULL));
digest =
NULL));
conf);
if (digest) {
if (!ha1) {
return !OK;
NULL);
ai);
return OK;