summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-04-04 18:32:17 +0000
committerJeremy Allison <jra@samba.org>2002-04-04 18:32:17 +0000
commitff30ca35726c42b76a02ae6797ce22914235b4a3 (patch)
tree6aeecbde4a6fe1a24c9cf89e171b5ce6e6ac3eb8
parentdd1e52dff415e24584d502060fafc96153429d45 (diff)
downloadsamba-ff30ca35726c42b76a02ae6797ce22914235b4a3.tar.gz
samba-ff30ca35726c42b76a02ae6797ce22914235b4a3.tar.xz
samba-ff30ca35726c42b76a02ae6797ce22914235b4a3.zip
Fix for CR#465. Enlarge hash table massively to enable winbindd to quickly
find records. Add cache file trimmer to delete and re-create cache at 50mb. Jeremy.
-rw-r--r--source/nsswitch/winbindd.c3
-rw-r--r--source/nsswitch/winbindd.h1
-rw-r--r--source/nsswitch/winbindd_cache.c31
3 files changed, 34 insertions, 1 deletions
diff --git a/source/nsswitch/winbindd.c b/source/nsswitch/winbindd.c
index c8a11186f01..f39bcd1ee4a 100644
--- a/source/nsswitch/winbindd.c
+++ b/source/nsswitch/winbindd.c
@@ -580,6 +580,9 @@ static void process_loop(int accept_sock)
state = state->next;
}
+ /* Check cache size */
+ winbindd_check_cache_size(time(NULL));
+
/* Check signal handling things */
if (do_sigterm)
diff --git a/source/nsswitch/winbindd.h b/source/nsswitch/winbindd.h
index cc86d703447..fddcb572e9d 100644
--- a/source/nsswitch/winbindd.h
+++ b/source/nsswitch/winbindd.h
@@ -117,6 +117,7 @@ extern struct winbindd_domain *domain_list; /* List of domains we know */
#define WINBINDD_ESTABLISH_LOOP 30
#define DOM_SEQUENCE_NONE ((uint32)-1)
+#define WINBINDD_MAX_CACHE_SIZE (50*1024*1024) /* 50 Mb max cache size */
/* SETENV */
#if HAVE_SETENV
diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c
index baa9acf1439..34c6e384175 100644
--- a/source/nsswitch/winbindd_cache.c
+++ b/source/nsswitch/winbindd_cache.c
@@ -41,7 +41,7 @@ void winbindd_cache_init(void)
{
/* Open tdb cache */
- if (!(cache_tdb = tdb_open(lock_path("winbindd_cache.tdb"), 0,
+ if (!(cache_tdb = tdb_open(lock_path("winbindd_cache.tdb"), 133403,
TDB_NOLOCK|TDB_NOMMAP, O_RDWR | O_CREAT | O_TRUNC,
0600))) {
DEBUG(0, ("Unable to open tdb cache - user and group caching "
@@ -49,6 +49,35 @@ void winbindd_cache_init(void)
}
}
+void winbindd_check_cache_size(time_t t)
+{
+ static 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 (cache_tdb == NULL) {
+ DEBUG(0, ("Unable to check size of tdb cache - cache not open !\n"));
+ return;
+ }
+
+ if (fstat(cache_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));
+ winbindd_flush_cache();
+ }
+}
+
/* get the domain sequence number, possibly re-fetching */
static uint32 cached_sequence_number(char *domain_name)
{