summaryrefslogtreecommitdiff
path: root/source4/lib/gencache/gencache.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/gencache/gencache.c')
-rw-r--r--source4/lib/gencache/gencache.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c
index a30f09fefa..949b16cb3b 100644
--- a/source4/lib/gencache/gencache.c
+++ b/source4/lib/gencache/gencache.c
@@ -47,30 +47,31 @@ static struct tdb_wrap *cache;
* false on failure
**/
-BOOL gencache_init(void)
+bool gencache_init(void)
{
char* cache_fname = NULL;
+ TALLOC_CTX *mem_ctx = talloc_autofree_context();
/* skip file open if it's already opened */
- if (cache) return True;
+ if (cache) return true;
- asprintf(&cache_fname, "%s/%s", lp_lockdir(), "gencache.tdb");
- if (cache_fname)
+ cache_fname = lock_path(mem_ctx, global_loadparm, "gencache.tdb");
+ if (cache_fname != NULL) {
DEBUG(5, ("Opening cache file at %s\n", cache_fname));
- else {
+ } else {
DEBUG(0, ("Filename allocation failed.\n"));
- return False;
+ return false;
}
- cache = tdb_wrap_open(NULL, cache_fname, 0, TDB_DEFAULT,
+ cache = tdb_wrap_open(mem_ctx, cache_fname, 0, TDB_DEFAULT,
O_RDWR|O_CREAT, 0644);
- SAFE_FREE(cache_fname);
+ talloc_free(cache_fname);
if (!cache) {
DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
- return False;
+ return false;
}
- return True;
+ return true;
}
@@ -81,12 +82,12 @@ BOOL gencache_init(void)
* false on failure during cache shutdown
**/
-BOOL gencache_shutdown(void)
+bool gencache_shutdown(void)
{
- if (!cache) return False;
+ if (!cache) return false;
DEBUG(5, ("Closing cache file\n"));
talloc_free(cache);
- return True;
+ return true;
}
@@ -102,7 +103,7 @@ BOOL gencache_shutdown(void)
* @retval false on failure
**/
-BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
+bool gencache_set(const char *keystr, const char *value, time_t timeout)
{
int ret;
TDB_DATA keybuf, databuf;
@@ -111,11 +112,11 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
/* fail completely if get null pointers passed */
SMB_ASSERT(keystr && value);
- if (!gencache_init()) return False;
+ if (!gencache_init()) return false;
asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value);
if (!valstr)
- return False;
+ return false;
keybuf.dptr = (uint8_t *)strdup(keystr);
keybuf.dsize = strlen(keystr)+1;
@@ -145,7 +146,7 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
* @retval false on failure
**/
-BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout)
+bool gencache_set_only(const char *keystr, const char *valstr, time_t timeout)
{
int ret = -1;
TDB_DATA keybuf, databuf;
@@ -155,7 +156,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout)
/* fail completely if get null pointers passed */
SMB_ASSERT(keystr && valstr);
- if (!gencache_init()) return False;
+ if (!gencache_init()) return false;
/*
* Check whether entry exists in the cache
@@ -163,7 +164,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout)
*/
gencache_get(keystr, &old_valstr, &old_timeout);
- if (!(old_valstr && old_timeout)) return False;
+ if (!(old_valstr && old_timeout)) return false;
DEBUG(10, ("Setting cache entry with key = %s; old value = %s and old timeout \
= %s\n", keystr, old_valstr, ctime(&old_timeout)));
@@ -198,7 +199,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout)
* @retval false in case of failure
**/
-BOOL gencache_del(const char *keystr)
+bool gencache_del(const char *keystr)
{
int ret;
TDB_DATA keybuf;
@@ -206,7 +207,7 @@ BOOL gencache_del(const char *keystr)
/* fail completely if get null pointers passed */
SMB_ASSERT(keystr);
- if (!gencache_init()) return False;
+ if (!gencache_init()) return false;
keybuf.dptr = (uint8_t *)strdup(keystr);
keybuf.dsize = strlen(keystr)+1;
@@ -228,10 +229,10 @@ BOOL gencache_del(const char *keystr)
* timeout
*
* @retval true when entry is successfuly fetched
- * @retval False for failure
+ * @retval false for failure
**/
-BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
+bool gencache_get(const char *keystr, char **valstr, time_t *timeout)
{
TDB_DATA keybuf, databuf;
@@ -239,7 +240,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
SMB_ASSERT(keystr);
if (!gencache_init())
- return False;
+ return false;
keybuf.dptr = (uint8_t *)strdup(keystr);
keybuf.dsize = strlen(keystr)+1;
@@ -285,7 +286,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
DEBUG(10, ("Cache entry with key = %s couldn't be found\n",
keystr));
- return False;
+ return false;
}
}