From 464c1201978a2cd5abed8ea0d7bcb9486b1c92d8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Apr 2002 03:03:39 +0000 Subject: Fix up conversion code from old winbindd versions (some testing needed). Added time based cache size check (#ifdef'ed out by default, just didn't want to lose the code). Jeremy. (This used to be commit b2350ed36c42827c417ea4a3dd0668a4a631a090) --- source3/nsswitch/winbindd_cache.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/nsswitch/winbindd_cache.c') diff --git a/source3/nsswitch/winbindd_cache.c b/source3/nsswitch/winbindd_cache.c index 230d2b88b8..9bd95fdd86 100644 --- a/source3/nsswitch/winbindd_cache.c +++ b/source3/nsswitch/winbindd_cache.c @@ -34,6 +34,8 @@ struct cache_entry { uint32 len, ofs; }; +#define WINBINDD_MAX_CACHE_SIZE (50*1024*1024) + static struct winbind_cache *wcache; /* flush the cache */ @@ -56,6 +58,35 @@ void wcache_flush_cache(void) } } +void winbindd_check_cache_size(time_t t) +{ + static time_t last_check_time; + struct stat st; + + if (last_check_time == (time_t)0) + last_check_time = t; + + if (t - last_check_time < 60 && t - last_check_time > 0) + return; + + if (wcache == NULL || wcache->tdb == NULL) { + DEBUG(0, ("Unable to check size of tdb cache - cache not open !\n")); + return; + } + + if (fstat(wcache->tdb->fd, &st) == -1) { + DEBUG(0, ("Unable to check size of tdb cache %s!\n", strerror(errno) )); + return; + } + + if (st.st_size > WINBINDD_MAX_CACHE_SIZE) { + DEBUG(10,("flushing cache due to size (%lu) > (%lu)\n", + (unsigned long)st.st_size, + (unsigned long)WINBINDD_MAX_CACHE_SIZE)); + wcache_flush_cache(); + } +} + /* get the winbind_cache structure */ static struct winbind_cache *get_cache(struct winbindd_domain *domain) { -- cgit