util_ldap_cache.h revision 8c5e6c7678471111589bc199bee1839f8176e8f1
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* Copyright 2001-2004 The Apache Software Foundation
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end *
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Licensed under the Apache License, Version 2.0 (the "License");
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * you may not use this file except in compliance with the License.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * You may obtain a copy of the License at
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end *
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * http://www.apache.org/licenses/LICENSE-2.0
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end *
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * Unless required by applicable law or agreed to in writing, software
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * distributed under the License is distributed on an "AS IS" BASIS,
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
2e545ce2450a9953665f701bb05350f0d3f26275nd */
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen#ifndef APU_LDAP_CACHE_H
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define APU_LDAP_CACHE_H
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * This switches LDAP support on or off.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* this whole thing disappears if LDAP is not enabled */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#if APR_HAS_LDAP
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * LDAP Cache Manager
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun#if APR_HAS_SHARED_MEMORY
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#include <apr_shm.h>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#include <apr_rmm.h> /* EDD */
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen#endif
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_cache_node_t {
e34c72770fb8ee6b2903f29a0c86c0d0509eefa8igalic void *payload; /* Pointer to the payload */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_time_t add_time; /* Time node was added to cache */
3f08db06526d6901aa08c110b5bc7dde6bc39905nd struct util_cache_node_t *next;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} util_cache_node_t;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_ald_cache util_ald_cache_t;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endstruct util_ald_cache {
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long size; /* Size of cache array */
d37a47f683d959ca24a0482b305b20582155da7ajim unsigned long maxentries; /* Maximum number of cache entries */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long numentries; /* Current number of cache entries */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long fullmark; /* Used to keep track of when cache becomes 3/4 full */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_time_t marktime; /* Time that the cache became 3/4 full */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long (*hash)(void *); /* Func to hash the payload */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end int (*compare)(void *, void *); /* Func to compare two payloads */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end void * (*copy)(util_ald_cache_t *cache, void *); /* Func to alloc mem and copy payload to new mem */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end void (*free)(util_ald_cache_t *cache, void *); /* Func to free mem used by the payload */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end void (*display)(request_rec *r, util_ald_cache_t *cache, void *); /* Func to display the payload contents */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end util_cache_node_t **nodes;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long numpurges; /* No. of times the cache has been purged */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end double avg_purgetime; /* Average time to purge the cache */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_time_t last_purge; /* Time of the last purge */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long npurged; /* Number of elements purged in last purge. This is not
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end obvious: it won't be 3/4 the size of the cache if
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end there were a lot of expired entries. */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long fetches; /* Number of fetches */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long hits; /* Number of cache hits */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long inserts; /* Number of inserts */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long removes; /* Number of removes */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#if APR_HAS_SHARED_MEMORY
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_shm_t *shm_addr;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_rmm_t *rmm_addr;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#endif
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end};
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#if APR_HAS_THREADS
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define LDAP_CACHE_LOCK_CREATE(p) \
d37a47f683d959ca24a0482b305b20582155da7ajim if (!st->util_ldap_cache_lock) apr_thread_rwlock_create(&st->util_ldap_cache_lock, st->pool)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define LDAP_CACHE_WRLOCK() \
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_thread_rwlock_wrlock(st->util_ldap_cache_lock)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define LDAP_CACHE_UNLOCK() \
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_thread_rwlock_unlock(st->util_ldap_cache_lock)
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define LDAP_CACHE_RDLOCK() \
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_thread_rwlock_rdlock(st->util_ldap_cache_lock)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#else
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define LDAP_CACHE_LOCK_CREATE(p)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define LDAP_CACHE_WRLOCK()
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define LDAP_CACHE_UNLOCK()
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define LDAP_CACHE_RDLOCK()
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#endif
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#ifndef WIN32
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define ALD_MM_FILE_MODE ( S_IRUSR|S_IWUSR )
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#else
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define ALD_MM_FILE_MODE ( _S_IREAD|_S_IWRITE )
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#endif
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * LDAP Cache
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
d37a47f683d959ca24a0482b305b20582155da7ajim/*
d37a47f683d959ca24a0482b305b20582155da7ajim * Maintain a cache of LDAP URLs that the server handles. Each node in
d37a47f683d959ca24a0482b305b20582155da7ajim * the cache contains the search cache for that URL, and a compare cache
1093a264c81aa1041581ab059905fb8f7cdfc5e2rbowen * for the URL. The compare cash is populated when doing require group
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen * compares.
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen */
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowentypedef struct util_url_node_t {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *url;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen util_ald_cache_t *search_cache;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end util_ald_cache_t *compare_cache;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end util_ald_cache_t *dn_compare_cache;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} util_url_node_t;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * We cache every successful search and bind operation, using the username
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * as the key. Each node in the cache contains the returned DN, plus the
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * password used to bind.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_search_node_t {
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *username; /* Cache key */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *dn; /* DN returned from search */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *bindpw; /* The most recently used bind password;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end NULL if the bind failed */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_time_t lastbind; /* Time of last successful bind */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char **vals; /* Values of queried attributes */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} util_search_node_t;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * We cache every successful compare operation, using the DN, attrib, and
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * value as the key.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_compare_node_t {
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *dn; /* DN, attrib and value combine to be the key */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *attrib;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *value;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end apr_time_t lastcompare;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end int result;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} util_compare_node_t;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * We cache every successful compare dn operation, using the dn in the require
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * statement and the dn fetched based on the client-provided username.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_dn_compare_node_t {
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *reqdn; /* The DN in the require dn statement */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *dn; /* The DN found in the search */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} util_dn_compare_node_t;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/*
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * Function prototypes for LDAP cache
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* util_ldap_cache.c */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endunsigned long util_ldap_url_node_hash(void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endint util_ldap_url_node_compare(void *a, void *b);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid *util_ldap_url_node_copy(util_ald_cache_t *cache, void *c);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_url_node_free(util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_url_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endunsigned long util_ldap_search_node_hash(void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endint util_ldap_search_node_compare(void *a, void *b);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_search_node_free(util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_search_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endunsigned long util_ldap_compare_node_hash(void *n);
316f02e3836836c82e19019ff23f90a7ebc65289nilgunint util_ldap_compare_node_compare(void *a, void *b);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid *util_ldap_compare_node_copy(util_ald_cache_t *cache, void *c);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_compare_node_free(util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endunsigned long util_ldap_dn_compare_node_hash(void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endint util_ldap_dn_compare_node_compare(void *a, void *b);
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asfvoid *util_ldap_dn_compare_node_copy(util_ald_cache_t *cache, void *c);
50c04f297d76a57ead2fa6b73845f7563b1fc788sfvoid util_ldap_dn_compare_node_free(util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ldap_dn_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
623eebe956d9c2d6d073ed3eae855b56030b40e9noodl/* util_ldap_cache_mgr.c */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* Cache alloc and free function, dealing or not with shm */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ald_free(util_ald_cache_t *cache, const void *ptr);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid *util_ald_alloc(util_ald_cache_t *cache, unsigned long size);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endconst char *util_ald_strdup(util_ald_cache_t *cache, const char *s);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
65a611af7093423efb91e5794b8887a527d4cf63trawick/* Cache managing function */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endunsigned long util_ald_hash_string(int nstr, ...);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ald_cache_purge(util_ald_cache_t *cache);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endutil_url_node_t *util_ald_create_caches(util_ldap_state_t *s, const char *url);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endutil_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned long (*hashfunc)(void *),
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end int (*comparefunc)(void *, void *),
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end void * (*copyfunc)(util_ald_cache_t *cache, void *),
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end void (*freefunc)(util_ald_cache_t *cache, void *),
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end void (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *));
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ald_destroy_cache(util_ald_cache_t *cache);
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrinvoid *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload);
f5a398cc8880978754903f9ece8e4beb63a81cedrbowenvoid util_ald_cache_insert(util_ald_cache_t *cache, void *payload);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endvoid util_ald_cache_remove(util_ald_cache_t *cache, void *payload);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endchar *util_ald_cache_display_stats(request_rec *r, util_ald_cache_t *cache, char *name, char *id);
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#endif /* APR_HAS_LDAP */
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin#endif /* APU_LDAP_CACHE_H */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end