util_ldap_cache.h revision 3f5585f7f4a7d74f2f94ec729ea8c1879d419e35
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unless required by applicable law or agreed to in writing, software
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distributed under the License is distributed on an "AS IS" BASIS,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * See the License for the specific language governing permissions and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * limitations under the License.
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding * @brief This switches LDAP support on or off.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* this whole thing disappears if LDAP is not enabled */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * LDAP Cache Manager
5c0419d51818eb02045cf923a9fe456127a44c60wrowetypedef struct util_cache_node_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_time_t add_time; /* Time node was added to cache */
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton unsigned long maxentries; /* Maximum number of cache entries */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes unsigned long numentries; /* Current number of cache entries */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes unsigned long fullmark; /* Used to keep track of when cache becomes 3/4 full */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes apr_time_t marktime; /* Time that the cache became 3/4 full */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes unsigned long (*hash)(void *); /* Func to hash the payload */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes int (*compare)(void *, void *); /* Func to compare two payloads */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes void * (*copy)(util_ald_cache_t *cache, void *); /* Func to alloc mem and copy payload to new mem */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes void (*free)(util_ald_cache_t *cache, void *); /* Func to free mem used by the payload */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes void (*display)(request_rec *r, util_ald_cache_t *cache, void *); /* Func to display the payload contents */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes unsigned long numpurges; /* No. of times the cache has been purged */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes double avg_purgetime; /* Average time to purge the cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_time_t last_purge; /* Time of the last purge */
0568280364eb026393be492ebc732795c4934643jorton unsigned long npurged; /* Number of elements purged in last purge. This is not
0568280364eb026393be492ebc732795c4934643jorton obvious: it won't be 3/4 the size of the cache if
0568280364eb026393be492ebc732795c4934643jorton there were a lot of expired entries. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * LDAP Cache
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Maintain a cache of LDAP URLs that the server handles. Each node in
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the cache contains the search cache for that URL, and a compare cache
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * for the URL. The compare cash is populated when doing require group
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct util_url_node_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *url;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * When a group is found, subgroups are stored in the group's cache entry.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char **subgroupDNs;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * We cache every successful search and bind operation, using the username
a1790fb35c4b352dab721370985c623a9f8f5062rpluem * as the key. Each node in the cache contains the returned DN, plus the
713a2b68bac4aeb1e9c48785006c0732451039depquerna * password used to bind.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct util_search_node_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *bindpw; /* The most recently used bind password;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe NULL if the bind failed */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe apr_time_t lastbind; /* Time of last successful bind */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char **vals; /* Values of queried attributes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * We cache every successful compare operation, using the DN, attrib, and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * value as the key.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenertypedef struct util_compare_node_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *dn; /* DN, attrib and value combine to be the key */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *attrib;
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes const char *value;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe int sgl_processed; /* 0 if no sgl processing yet. 1 if sgl has been processed (even if SGL is NULL). Saves repeat work on leaves. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * We cache every successful compare dn operation, using the dn in the require
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * statement and the dn fetched based on the client-provided username.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *reqdn; /* The DN in the require dn statement */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * Function prototypes for LDAP cache
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesunsigned long util_ldap_url_node_hash(void *n);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerint util_ldap_url_node_compare(void *a, void *b);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid *util_ldap_url_node_copy(util_ald_cache_t *cache, void *c);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenervoid util_ldap_url_node_free(util_ald_cache_t *cache, void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ldap_url_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesunsigned long util_ldap_search_node_hash(void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesint util_ldap_search_node_compare(void *a, void *b);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ldap_search_node_free(util_ald_cache_t *cache, void *n);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenervoid util_ldap_search_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
8113dac419143273351446c3ad653f3fe5ba5cfdwroweunsigned long util_ldap_compare_node_hash(void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesint util_ldap_compare_node_compare(void *a, void *b);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid *util_ldap_compare_node_copy(util_ald_cache_t *cache, void *c);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ldap_compare_node_free(util_ald_cache_t *cache, void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ldap_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesunsigned long util_ldap_dn_compare_node_hash(void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesint util_ldap_dn_compare_node_compare(void *a, void *b);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid *util_ldap_dn_compare_node_copy(util_ald_cache_t *cache, void *c);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ldap_dn_compare_node_free(util_ald_cache_t *cache, void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ldap_dn_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Cache alloc and free function, dealing or not with shm */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ald_free(util_ald_cache_t *cache, const void *ptr);
1f299703465bd9975d94e9f229f76af807442de2covenervoid *util_ald_alloc(util_ald_cache_t *cache, unsigned long size);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerconst char *util_ald_strdup(util_ald_cache_t *cache, const char *s);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerutil_compare_subgroup_t *util_ald_sgl_dup(util_ald_cache_t *cache, util_compare_subgroup_t *sgl);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenervoid util_ald_sgl_free(util_ald_cache_t *cache, util_compare_subgroup_t **sgl);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe/* Cache managing function */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ald_cache_purge(util_ald_cache_t *cache);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesutil_url_node_t *util_ald_create_caches(util_ldap_state_t *s, const char *url);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesutil_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
9ad7b260be233be7d7b5576979825cac72e15498rederpj unsigned long (*hashfunc)(void *),
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int (*comparefunc)(void *, void *),
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes void * (*copyfunc)(util_ald_cache_t *cache, void *),
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes void (*freefunc)(util_ald_cache_t *cache, void *),
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes void (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ald_destroy_cache(util_ald_cache_t *cache);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid *util_ald_cache_insert(util_ald_cache_t *cache, void *payload);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid util_ald_cache_remove(util_ald_cache_t *cache, void *payload);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholeschar *util_ald_cache_display_stats(request_rec *r, util_ald_cache_t *cache, char *name, char *id);
3e6d7277b90d3011db832139afc20efb5f17e203rederpj#endif /* APR_HAS_LDAP */
3e6d7277b90d3011db832139afc20efb5f17e203rederpj#endif /* APU_LDAP_CACHE_H */