summaryrefslogtreecommitdiff
path: root/daemon/bd.h
blob: 20a74b910087f521e2d28bd1d7a35d1c805bb46b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright (c) 2004, Nate Nielsen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *     * Redistributions of source code must retain the above
 *       copyright notice, this list of conditions and the
 *       following disclaimer.
 *     * Redistributions in binary form must reproduce the
 *       above copyright notice, this list of conditions and
 *       the following disclaimer in the documentation and/or
 *       other materials provided with the distribution.
 *     * The names of contributors to this software may not be
 *       used to endorse or promote products derived from this
 *       software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 *
 * CONTRIBUTORS
 *  Nate Nielsen <nielsen@memberwebs.com>
 *
 */

#ifndef BD_H
#define BD_H

#include "hash.h"
#include "digest.h"
#include "httpauthd.h"

/* ----------------------------------------------------------------------------------
 *  Callbacks
 */

/*
 * A callback for completing a given user's digest ha1. In this function
 * you're required to fill in the digest ha1 hash for the user. ha1 will
 * always be an array of MD5_LEN bytes.
 *
 * Return Values
 * HA_OK: completed successfully
 * HA_FAILED: error retrieving hash (should have logged error)
 */
typedef int (*bd_validate_digest)(ha_request_t* rq,
                                  const char* user, digest_context_t* dg);

/*
 * A callback for validating a given user's password.
 *
 * Return Values
 * HA_OK: good password
 * HA_FALSE: invalid password
 * HA_FAILED: error validating (should have logged error)
 */
typedef int (*bd_validate_basic)(ha_request_t* rq,
                                 const char* user, const char* password);

/*
 * Escapes a value for sending to 'server'
 */
typedef void (*bd_escape_value)(const ha_request_t* rq, ha_buffer_t* buf,
                                const char* value);

/* ----------------------------------------------------------------------------------
 *  Base Context
 */
typedef struct bd_context
{
    /* Readonly ---------------------------------------------*/
    bd_validate_digest  f_validate_digest;
    bd_validate_basic   f_validate_basic;
    bd_escape_value     f_escape_value;

    /* Require locking --------------------------------------*/
    hsh_t* cache;            /* Some cached records or basic */
}
bd_context_t;

#define BD_CALLBACKS(a, b, c) {(a), (b), (c), NULL }
#define BD_DEFAULTS { NULL, NULL, NULL, NULL }

/* ----------------------------------------------------------------------------------
 *  Base Handler Functions
 */

/*
 * The base/digest initialize function. Call this from your
 * 'derived' handler initialize function.
 */
int bd_init(ha_context_t* context);

/*
 * The base/digest uninitialize function. Call this from your
 * 'derived' handler uninitialize function.
 */
void bd_destroy(ha_context_t* context);

/*
 * The base/digest processer for requests. Call this from your
 * 'derived' handler process function.
 */
int bd_process(ha_request_t* rq);

/* ----------------------------------------------------------------------------------
 *  Other helper functionts
 */

const char* bd_substitute(const ha_request_t* rq, const char* user, const char* str);

#endif /* BD_H */