# # This patch base on the source code downloaded from # http://httpd.apache.org/download.cgi (Version: 2.4.27) # # HOWTO apply this patch: # after extracting the source from tar.gz or zip go into the base dir: # > cd httpd-2.4.27 # > patch -p0 -b -i httpd-2.4.27.mod_ldap_ttl.patch # # --- modules/ldap/util_ldap_cache.h.orig 2011-09-23 20:08:42.000000000 +0200 +++ modules/ldap/util_ldap_cache.h 2017-12-11 14:44:41.932763422 +0100 @@ -46,6 +46,7 @@ unsigned long numentries; /* Current number of cache entries */ unsigned long fullmark; /* Used to keep track of when cache becomes 3/4 full */ apr_time_t marktime; /* Time that the cache became 3/4 full */ + unsigned long ttl; /* Time to live for items in cache */ unsigned long (*hash)(void *); /* Func to hash the payload */ int (*compare)(void *, void *); /* Func to compare two payloads */ void * (*copy)(util_ald_cache_t *cache, void *); /* Func to alloc mem and copy payload to new mem */ @@ -188,6 +189,7 @@ util_url_node_t *util_ald_create_caches(util_ldap_state_t *s, const char *url); util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st, long cache_size, + long cache_ttl, unsigned long (*hashfunc)(void *), int (*comparefunc)(void *, void *), void * (*copyfunc)(util_ald_cache_t *cache, void *), --- modules/ldap/util_ldap_cache.c.orig 2015-10-06 14:36:36.000000000 +0200 +++ modules/ldap/util_ldap_cache.c 2017-12-11 15:10:53.248643208 +0100 @@ -114,6 +114,7 @@ "%ld" "%ld" "%ld" + "%ld" "%s" "", node->url, @@ -121,6 +122,7 @@ cache_node->size, cache_node->maxentries, cache_node->numentries, + cache_node->ttl / APR_USEC_PER_SEC, cache_node->fullmark, date_str); } @@ -452,6 +454,7 @@ st->util_ldap_cache = util_ald_create_cache(st, st->search_cache_size, + st->search_cache_ttl, util_ldap_url_node_hash, util_ldap_url_node_compare, util_ldap_url_node_copy, --- modules/ldap/util_ldap_cache_mgr.c.orig 2016-08-25 14:48:18.000000000 +0200 +++ modules/ldap/util_ldap_cache_mgr.c 2017-12-11 15:17:19.571130430 +0100 @@ -241,6 +241,8 @@ cache->last_purge = apr_time_now(); cache->npurged = 0; cache->numpurges++; + if (cache->last_purge - cache->ttl > cache->marktime) + cache->marktime = cache->last_purge - cache->ttl; for (i=0; i < cache->size; ++i) { pp = cache->nodes + i; @@ -281,6 +283,7 @@ /* create the three caches */ search_cache = util_ald_create_cache(st, st->search_cache_size, + st->search_cache_ttl, util_ldap_search_node_hash, util_ldap_search_node_compare, util_ldap_search_node_copy, @@ -288,6 +291,7 @@ util_ldap_search_node_display); compare_cache = util_ald_create_cache(st, st->compare_cache_size, + st->compare_cache_ttl, util_ldap_compare_node_hash, util_ldap_compare_node_compare, util_ldap_compare_node_copy, @@ -295,6 +299,7 @@ util_ldap_compare_node_display); dn_compare_cache = util_ald_create_cache(st, st->compare_cache_size, + st->compare_cache_ttl, util_ldap_dn_compare_node_hash, util_ldap_dn_compare_node_compare, util_ldap_dn_compare_node_copy, @@ -323,6 +328,7 @@ util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st, long cache_size, + long cache_ttl, unsigned long (*hashfunc)(void *), int (*comparefunc)(void *, void *), void * (*copyfunc)(util_ald_cache_t *cache, void *), @@ -381,8 +387,10 @@ cache->free = freefunc; cache->display = displayfunc; + cache->fullmark = cache->maxentries / 4 * 3; cache->marktime = 0; + cache->ttl = cache_ttl; cache->avg_purgetime = 0.0; cache->numpurges = 0; cache->last_purge = 0; @@ -727,6 +735,10 @@ "%ld" "\n" "\n" + "TTL (sec):" + "%ld" + "\n" + "\n" "Full Mark:" "%ld" "\n" @@ -738,6 +750,7 @@ util_ldap_cache->size, util_ldap_cache->maxentries, util_ldap_cache->numentries, + util_ldap_cache->ttl / APR_USEC_PER_SEC, util_ldap_cache->fullmark, date_str); @@ -748,6 +761,7 @@ "Size" "Max Entries" "# Entries" + "TTL (sec)" "Full Mark" "Full Mark Time" "\n", r --- modules/ldap/util_ldap.c.orig 2015-09-08 13:10:16.000000000 +0200 +++ modules/ldap/util_ldap.c 2017-12-11 14:55:08.002210792 +0100 @@ -2244,7 +2244,7 @@ return err; } - st->compare_cache_ttl = atol(ttl) * 1000000; + st->compare_cache_ttl = atol(ttl) * APR_USEC_PER_SEC; ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01301) "ldap cache: Setting operation cache TTL to %ld microseconds.", @@ -2815,9 +2815,9 @@ #endif st->cache_bytes = 500000; - st->search_cache_ttl = 600000000; + st->search_cache_ttl = 600 * APR_USEC_PER_SEC; /* 10 minutes */ st->search_cache_size = 1024; - st->compare_cache_ttl = 600000000; + st->compare_cache_ttl = 600 * APR_USEC_PER_SEC; /* 10 minutes */ st->compare_cache_size = 1024; st->connections = NULL; st->ssl_supported = 0;