util_ldap_cache.h revision 8c5e6c7678471111589bc199bee1839f8176e8f1
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* Copyright 2001-2004 The Apache Software Foundation
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 * 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.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * This switches LDAP support on or off.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* this whole thing disappears if LDAP is not enabled */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * LDAP Cache Manager
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_cache_node_t {
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 unsigned long numpurges; /* No. of times the cache has been purged */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end double avg_purgetime; /* Average time to purge the cache */
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. */
d37a47f683d959ca24a0482b305b20582155da7ajim if (!st->util_ldap_cache_lock) apr_thread_rwlock_create(&st->util_ldap_cache_lock, st->pool)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * LDAP Cache
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.
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowentypedef struct util_url_node_t {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *url;
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.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_search_node_t {
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *bindpw; /* The most recently used bind password;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end NULL if the bind failed */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * We cache every successful compare operation, using the DN, attrib, and
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * value as the key.
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 * 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.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endtypedef struct util_dn_compare_node_t {
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end const char *reqdn; /* The DN in the require dn statement */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * Function prototypes for LDAP cache
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);
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);
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);
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/* 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);
65a611af7093423efb91e5794b8887a527d4cf63trawick/* Cache managing function */
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 (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *));
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#endif /* APR_HAS_LDAP */
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin#endif /* APU_LDAP_CACHE_H */