summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-10-02 23:34:03 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:15:06 -0500
commitb96aae779bdbd96677aef58d205282605046a8a6 (patch)
tree4ec3eb61325578e8abe4af879881ea23a16abf86
parent8c15a6ff2e7d9341972fe0431655acd4416121f3 (diff)
downloadsamba-b96aae779bdbd96677aef58d205282605046a8a6.tar.gz
samba-b96aae779bdbd96677aef58d205282605046a8a6.tar.bz2
samba-b96aae779bdbd96677aef58d205282605046a8a6.zip
r19054: Callers of gencache may not have the rights to
open read/write. Allow them to fallback to read-only. Jeremy (This used to be commit ec526e1b882e3ade23f90c5e3d637c72b6839da5)
-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));