1 /*******************************************************************************
2 * *****************************************************************************
6 * * Description: Header file for cache.c
9 * * Copyright (C) 2003 Jeremy Rumpf
11 * * Redistribution and use in source and binary forms, with or without
12 * * modification, are permitted provided that the following conditions
15 * * 1. Redistributions of source code must retain the above copyright
16 * * notice, this list of conditions and the following disclaimer.
18 * * 2. Redistributions in binary form must reproduce the above copyright
19 * * notice, this list of conditions and the following disclaimer in the
20 * * documentation and/or other materials provided with the distribution.
22 * * THIS SOFTWARE IS PROVIDED ``AS IS''. ANY EXPRESS OR IMPLIED WARRANTIES,
23 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * * IN NO EVENT SHALL JEREMY RUMPF OR ANY CONTRIBUTER TO THIS SOFTWARE BE
25 * * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * * THE POSSIBILITY OF SUCH DAMAGE
34 * * jrumpf@heavyload.net
36 * ******************************************************************************
37 ********************************************************************************/
43 /* constant includes */
44 #include "saslauthd.h"
47 /****************************************************************
48 * * Plug in some autoconf magic to determine what implementation
49 * * to use for the table slot (row) locking.
50 ****************************************************************/
52 # define CACHE_USE_PTHREAD_RWLOCK
54 # define CACHE_USE_FCNTL
59 /************************************************/
60 #ifdef CACHE_USE_FCNTL
68 #endif /* CACHE_USE_FCNTL */
69 /************************************************/
73 /************************************************/
74 #ifdef CACHE_USE_PTHREAD_RWLOCK
80 pthread_rwlock_t *rwlock;
83 #endif /* CACHE_USE_PTHREAD_RWLOCK */
84 /************************************************/
89 #define CACHE_DEFAULT_TIMEOUT 28800
90 #define CACHE_DEFAULT_TABLE_SIZE 1711
91 #define CACHE_DEFAULT_FLAGS 0
92 #define CACHE_MAX_BUCKETS_PER 6
93 #define CACHE_MMAP_FILE "/cache.mmap" /* don't forget the "/" */
94 #define CACHE_FLOCK_FILE "/cache.flock" /* don't forget the "/" */
98 /* If debugging uncomment this for always verbose */
99 /* #define CACHE_DEFAULT_FLAGS CACHE_VERBOSE */
103 /* max length for cached credential values */
104 #define CACHE_MAX_CREDS_LENGTH 60
108 /* magic values (must be less than 63 chars!) */
109 #define CACHE_CACHE_MAGIC "SASLAUTHD_CACHE_MAGIC"
116 #define CACHE_TOO_BIG 2
120 /* cache_result status values */
121 #define CACHE_NO_FLUSH 0
122 #define CACHE_FLUSH 1
123 #define CACHE_FLUSH_WITH_RESCAN 2
129 char creds[CACHE_MAX_CREDS_LENGTH];
130 unsigned int user_offt;
131 unsigned int realm_offt;
132 unsigned int service_offt;
133 unsigned char pwd_digest[16];
138 volatile unsigned int hits;
139 volatile unsigned int misses;
140 volatile unsigned int lock_failures;
141 volatile unsigned int attempts;
142 unsigned int table_size;
143 unsigned int max_buckets_per;
144 unsigned int sizeof_bucket;
146 unsigned int timeout;
155 struct cache_result {
156 struct bucket bucket;
157 struct bucket *read_bucket;
158 unsigned int hash_offset;
164 extern int cache_init(void);
165 extern int cache_lookup(const char *, const char *, const char *, const char *, struct cache_result *);
166 extern void cache_commit(struct cache_result *);
167 extern int cache_pjwhash(char *);
168 extern void cache_set_table_size(const char *);
169 extern void cache_set_timeout(const char *);
170 extern unsigned int cache_get_next_prime(unsigned int);
171 extern void *cache_alloc_mm(unsigned int);
172 extern void cache_cleanup_mm(void);
173 extern void cache_cleanup_lock(void);
174 extern int cache_init_lock(void);
175 extern int cache_get_wlock(unsigned int);
176 extern int cache_get_rlock(unsigned int);
177 extern int cache_un_lock(unsigned int);
179 #endif /* _CACHE_H */