summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/memcache.h2
-rw-r--r--source3/lib/memcache.c36
-rw-r--r--source3/smbd/server.c6
3 files changed, 44 insertions, 0 deletions
diff --git a/source3/include/memcache.h b/source3/include/memcache.h
index f849f8ad3b..0ba3bdbb00 100644
--- a/source3/include/memcache.h
+++ b/source3/include/memcache.h
@@ -37,6 +37,8 @@ enum memcache_number {
struct memcache *memcache_init(TALLOC_CTX *mem_ctx, size_t max_size);
+void memcache_set_global(struct memcache *cache);
+
void memcache_add(struct memcache *cache, enum memcache_number n,
DATA_BLOB key, DATA_BLOB value);
diff --git a/source3/lib/memcache.c b/source3/lib/memcache.c
index 17630066ae..38bbd66085 100644
--- a/source3/lib/memcache.c
+++ b/source3/lib/memcache.c
@@ -20,6 +20,8 @@
#include "memcache.h"
#include "rbtree.h"
+static struct memcache *global_cache;
+
struct memcache_element {
struct rb_node rb_node;
struct memcache_element *prev, *next;
@@ -58,6 +60,12 @@ struct memcache *memcache_init(TALLOC_CTX *mem_ctx, size_t max_size)
return result;
}
+void memcache_set_global(struct memcache *cache)
+{
+ TALLOC_FREE(global_cache);
+ global_cache = cache;
+}
+
static struct memcache_element *memcache_node2elem(struct rb_node *node)
{
return (struct memcache_element *)
@@ -119,6 +127,13 @@ bool memcache_lookup(struct memcache *cache, enum memcache_number n,
{
struct memcache_element *e;
+ if (cache == NULL) {
+ cache = global_cache;
+ }
+ if (cache == NULL) {
+ return false;
+ }
+
e = memcache_find(cache, n, key);
if (e == NULL) {
return false;
@@ -172,6 +187,13 @@ void memcache_delete(struct memcache *cache, enum memcache_number n,
{
struct memcache_element *e;
+ if (cache == NULL) {
+ cache = global_cache;
+ }
+ if (cache == NULL) {
+ return;
+ }
+
e = memcache_find(cache, n, key);
if (e == NULL) {
return;
@@ -189,6 +211,13 @@ void memcache_add(struct memcache *cache, enum memcache_number n,
DATA_BLOB cache_key, cache_value;
size_t element_size;
+ if (cache == NULL) {
+ cache = global_cache;
+ }
+ if (cache == NULL) {
+ return;
+ }
+
if (key.length == 0) {
return;
}
@@ -258,6 +287,13 @@ void memcache_flush(struct memcache *cache, enum memcache_number n)
{
struct rb_node *node;
+ if (cache == NULL) {
+ cache = global_cache;
+ }
+ if (cache == NULL) {
+ return;
+ }
+
/*
* Find the smallest element of number n
*/
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 40037074f6..43a6d62a28 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1191,6 +1191,12 @@ extern void build_options(bool screen);
if (smbd_messaging_context() == NULL)
exit(1);
+ if (smbd_memcache() == NULL) {
+ exit(1);
+ }
+
+ memcache_set_global(smbd_memcache());
+
/* Initialise the password backed before the global_sam_sid
to ensure that we fetch from ldap before we make a domain sid up */