summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/gencache.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index dc5f32d66e..95ec47b697 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -31,6 +31,7 @@
#define READ_CACHE_DATA_FMT_TEMPLATE "%%12u/%%%us"
static TDB_CONTEXT *cache;
+static BOOL cache_readonly;
/**
* @file gencache.c
@@ -66,6 +67,14 @@ BOOL gencache_init(void)
cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT,
O_RDWR|O_CREAT, 0644);
+ if (!cache && (errno == EACCES)) {
+ cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, O_RDONLY, 0644);
+ if (cache) {
+ cache_readonly = True;
+ DEBUG(5, ("gencache_init: Opening cache file %s read-only.\n", cache_fname));
+ }
+ }
+
SAFE_FREE(cache_fname);
if (!cache) {
DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
@@ -90,6 +99,7 @@ BOOL gencache_shutdown(void)
DEBUG(5, ("Closing cache file\n"));
ret = tdb_close(cache);
cache = NULL;
+ cache_readonly = False;
return ret != -1;
}
@@ -117,6 +127,10 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
if (!gencache_init()) return False;
+ if (cache_readonly) {
+ return False;
+ }
+
asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value);
if (!valstr)
return False;
@@ -155,6 +169,10 @@ BOOL gencache_del(const char *keystr)
if (!gencache_init()) return False;
+ if (cache_readonly) {
+ return False;
+ }
+
keybuf.dptr = CONST_DISCARD(char *, keystr);
keybuf.dsize = strlen(keystr)+1;
DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr));