#include "includes.h"
#include "system/filesys.h"
#include "winbindd.h"
-#include "tdb_validate.h"
+//#include "tdb_validate.h"
#include "../libcli/auth/libcli_auth.h"
#include "../librpc/gen_ndr/ndr_wbint.h"
#include "ads.h"
#include "nss_info.h"
#include "../libcli/security/security.h"
#include "passdb/machine_sid.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
#include "util_tdb.h"
#undef DBGC_CLASS
static bool global_winbindd_offline_state;
struct winbind_cache {
- TDB_CONTEXT *tdb;
+ struct db_context *db;
};
struct cache_entry {
if (ret)
return ret;
- ret = SMB_XMALLOC_P(struct winbind_cache);
- ZERO_STRUCTP(ret);
-
- wcache = ret;
+ wcache = ret = talloc_zero(NULL, struct winbind_cache);
wcache_flush_cache();
return ret;
{
bool ret;
- if (!wcache->tdb)
+ if (!wcache->db)
return false;
ret = (domain->sequence_number == DOM_SEQUENCE_NONE);
char *key;
TDB_DATA data;
- if (wcache->tdb == NULL) {
- DEBUG(10,("wcache_fetch_seqnum: tdb == NULL\n"));
+ if (wcache->db == NULL) {
+ DEBUG(10,("wcache_fetch_seqnum: db == NULL\n"));
return false;
}
return false;
}
- data = tdb_fetch_bystring(wcache->tdb, key);
- TALLOC_FREE(key);
-
- if (data.dptr == NULL) {
+ if (!NT_STATUS_IS_OK(dbwrap_fetch_bystring(wcache->db, wcache,
+ key, &data))) {
+ TALLOC_FREE(key);
DEBUG(10, ("wcache_fetch_seqnum: %s not found\n",
domain_name));
return false;
}
+ TALLOC_FREE(key);
if (data.dsize != 8) {
DEBUG(10, ("wcache_fetch_seqnum: invalid data size %d\n",
(int)data.dsize));
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(data.dptr);
return false;
}
*seqnum = IVAL(data.dptr, 0);
*last_seq_check = IVAL(data.dptr, 4);
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(data.dptr);
return true;
}
{
char *key_str;
uint8_t buf[8];
- int ret;
+ NTSTATUS status;
- if (wcache->tdb == NULL) {
- DEBUG(10, ("wcache_store_seqnum: wcache->tdb == NULL\n"));
+ if (wcache->db == NULL) {
+ DEBUG(10, ("wcache_store_seqnum: wcache->db == NULL\n"));
return false;
}
SIVAL(buf, 0, seqnum);
SIVAL(buf, 4, last_seq_check);
- ret = tdb_store_bystring(wcache->tdb, key_str,
- make_tdb_data(buf, sizeof(buf)), TDB_REPLACE);
+ status = dbwrap_store_bystring(wcache->db, key_str,
+ make_tdb_data(buf, sizeof(buf)),
+ TDB_REPLACE);
TALLOC_FREE(key_str);
- if (ret != 0) {
- DEBUG(10, ("tdb_store_bystring failed: %s\n",
- tdb_errorstr_compat(wcache->tdb)));
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("dbwrap_store_bystring failed\n"));
TALLOC_FREE(key_str);
return false;
}
TDB_DATA key;
key = string_tdb_data(kstr);
- data = tdb_fetch_compat(wcache->tdb, key);
- if (!data.dptr) {
+ if (!NT_STATUS_IS_OK(dbwrap_fetch(wcache->db, wcache, key, &data))) {
/* a cache miss */
return NULL;
}
centry = SMB_XMALLOC_P(struct cache_entry);
- centry->data = (unsigned char *)data.dptr;
+ centry->data = (unsigned char *)memdup(data.dptr, data.dsize);
+ TALLOC_FREE(data.dptr);
+ if (!centry->data) {
+ DEBUG(0,("wcache_fetch_raw: alloc of %zu bytes failed\n",
+ data.dsize));
+ free(centry);
+ return NULL;
+ }
+
centry->len = data.dsize;
centry->ofs = 0;
key = string_tdb_data(kstr);
- tdb_delete(wcache->tdb, key);
+ dbwrap_delete(wcache->db, key);
free(kstr);
}
{
struct cache_entry *centry;
- if (!wcache->tdb)
+ if (!wcache->db)
return NULL;
centry = SMB_XMALLOC_P(struct cache_entry);
}
/*
- finish a centry and write it to the tdb
+ finish a centry and write it to the db
*/
static void centry_end(struct cache_entry *centry, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
static void centry_end(struct cache_entry *centry, const char *format, ...)
data.dptr = centry->data;
data.dsize = centry->ofs;
- tdb_store(wcache->tdb, key, data, TDB_REPLACE);
+ dbwrap_store(wcache->db, key, data, TDB_REPLACE);
free(kstr);
}
if ( domain->internal )
return NT_STATUS_NOT_SUPPORTED;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
if ( (upper_name = SMB_STRDUP(name)) == NULL )
if ( domain->internal )
return NT_STATUS_NOT_SUPPORTED;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
if ( (upper_name = SMB_STRDUP(alias)) == NULL )
TDB_DATA data;
fstring key_str, tmp;
uint32 rid;
+ NTSTATUS status;
- if (!cache->tdb) {
+ if (!cache->db) {
return NT_STATUS_INTERNAL_DB_ERROR;
}
fstr_sprintf(key_str, "CRED/%s", sid_to_fstring(tmp, sid));
- data = tdb_fetch_compat(cache->tdb, string_tdb_data(key_str));
- if (!data.dptr) {
- return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ status = dbwrap_fetch(cache->db, NULL, string_tdb_data(key_str), &data);
+ if (NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(data.dptr);
}
-
- SAFE_FREE(data.dptr);
- return NT_STATUS_OK;
+ return status;
}
/* Lookup creds for a SID - copes with old (unsalted) creds as well
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
- if (!cache->tdb) {
+ if (!cache->db) {
return NT_STATUS_INTERNAL_DB_ERROR;
}
unsigned int i, retry;
bool old_status = domain->online;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
centry = wcache_fetch(cache, domain, "UL/%s", domain->name);
* domain is offline now, and there is no user entries,
* try to fetch from cache again.
*/
- if (cache->tdb && !domain->online && !domain->internal && old_status) {
+ if (cache->db && !domain->online && !domain->internal && old_status) {
centry = wcache_fetch(cache, domain, "UL/%s", domain->name);
/* partial response... */
if (!centry) {
bool old_status;
old_status = domain->online;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
centry = wcache_fetch(cache, domain, "GL/%s/domain", domain->name);
if (!domain->internal && old_status) {
set_domain_offline(domain);
}
- if (cache->tdb &&
+ if (cache->db &&
!domain->online &&
!domain->internal &&
old_status) {
bool old_status;
old_status = domain->online;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
centry = wcache_fetch(cache, domain, "GL/%s/local", domain->name);
if (!domain->internal && old_status) {
set_domain_offline(domain);
}
- if (cache->tdb &&
+ if (cache->db &&
!domain->internal &&
!domain->online &&
old_status) {
NTSTATUS status;
char *uname;
- if (cache->tdb == NULL) {
+ if (cache->db == NULL) {
return NT_STATUS_NOT_FOUND;
}
char *sid_string;
NTSTATUS status;
- if (cache->tdb == NULL) {
+ if (cache->db == NULL) {
return NT_STATUS_NOT_FOUND;
}
*names = NULL;
*types = NULL;
- if (!cache->tdb) {
+ if (!cache->db) {
goto do_query;
}
if (!domain->internal && old_status) {
set_domain_offline(domain);
}
- if (cache->tdb &&
+ if (cache->db &&
!domain->internal &&
!domain->online &&
old_status) {
NTSTATUS status;
char *sid_string;
- if (cache->tdb == NULL) {
+ if (cache->db == NULL) {
return NT_STATUS_NOT_FOUND;
}
struct dom_sid *sids;
fstring sid_string;
- if (cache->tdb == NULL) {
+ if (cache->db == NULL) {
return NT_STATUS_NOT_FOUND;
}
char *sidlist;
int i;
- if (cache->tdb == NULL) {
+ if (cache->db == NULL) {
return NT_STATUS_NOT_FOUND;
}
unsigned int i;
char *sid_string;
- if (cache->tdb == NULL) {
+ if (cache->db == NULL) {
return NT_STATUS_NOT_FOUND;
}
trusts->array = NULL;
cache = get_cache(domain);
- if (!cache || !cache->tdb) {
+ if (!cache || !cache->db) {
goto do_query;
}
bool old_status;
old_status = domain->online;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
centry = wcache_fetch(cache, domain, "LOC_POL/%s", domain->name);
if (!domain->internal && old_status) {
set_domain_offline(domain);
}
- if (cache->tdb &&
+ if (cache->db &&
!domain->internal &&
!domain->online &&
old_status) {
bool old_status;
old_status = domain->online;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
centry = wcache_fetch(cache, domain, "PWD_POL/%s", domain->name);
if (!domain->internal && old_status) {
set_domain_offline(domain);
}
- if (cache->tdb &&
+ if (cache->db &&
!domain->internal &&
!domain->online &&
old_status) {
/* Invalidate cached user and group lists coherently */
-static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf,
- void *state)
+static int traverse_fn(struct db_record *rec, void *state)
{
+ TDB_DATA kbuf = dbwrap_record_get_key(rec);
+
if (strncmp((const char *)kbuf.dptr, "UL/", 3) == 0 ||
- strncmp((const char *)kbuf.dptr, "GL/", 3) == 0)
- tdb_delete(the_tdb, kbuf);
+ strncmp((const char *)kbuf.dptr, "GL/", 3) == 0) {
+ dbwrap_record_delete(rec);
+ }
return 0;
}
cache = get_cache(domain);
- if (!cache->tdb) {
+ if (!cache->db) {
return;
}
/* Clear U/SID cache entry */
fstr_sprintf(key_str, "U/%s", sid_to_fstring(sid_string, sid));
DEBUG(10, ("wcache_invalidate_samlogon: clearing %s\n", key_str));
- tdb_delete(cache->tdb, string_tdb_data(key_str));
+ dbwrap_delete(cache->db, string_tdb_data(key_str));
/* Clear UG/SID cache entry */
fstr_sprintf(key_str, "UG/%s", sid_to_fstring(sid_string, sid));
DEBUG(10, ("wcache_invalidate_samlogon: clearing %s\n", key_str));
- tdb_delete(cache->tdb, string_tdb_data(key_str));
+ dbwrap_delete(cache->db, string_tdb_data(key_str));
/* Samba/winbindd never needs this. */
netsamlogon_clear_cached_user(sid);
DEBUG(10, ("wcache_invalidate_cache: invalidating cache "
"entries for %s\n", domain->name));
if (cache) {
- if (cache->tdb) {
- tdb_traverse(cache->tdb, traverse_fn, NULL);
+ if (cache->db) {
+ dbwrap_traverse(cache->db, traverse_fn, NULL,
+ NULL);
} else {
return false;
}
DEBUG(10, ("wcache_invalidate_cache: invalidating cache "
"entries for %s\n", domain->name));
if (cache) {
- if (cache->tdb) {
- tdb_traverse(cache->tdb, traverse_fn, NULL);
+ if (cache->db) {
+ dbwrap_traverse(cache->db, traverse_fn, NULL,
+ NULL);
/*
* Flushing cache has nothing to with domains.
* return here if we successfully flushed once.
return true;
}
-bool init_wcache(void)
+static bool init_wcache(bool do_truncate)
{
+ int open_flags = O_RDWR|O_CREAT;
+
+ if (do_truncate) {
+ open_flags |= O_TRUNC;
+ }
+
if (wcache == NULL) {
- wcache = SMB_XMALLOC_P(struct winbind_cache);
- ZERO_STRUCTP(wcache);
+ wcache = talloc_zero(NULL, struct winbind_cache);
+ if (!wcache) {
+ smb_panic("Could not allocate wcache");
+ }
}
- if (wcache->tdb != NULL)
+ if (wcache->db != NULL)
return true;
/* when working offline we must not clear the cache on restart */
- wcache->tdb = tdb_open_log(state_path("winbindd_cache.tdb"),
- WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
- TDB_INCOMPATIBLE_HASH |
- (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
- O_RDWR|O_CREAT, 0600);
+ wcache->db = db_s3open(wcache, state_path("winbindd_cache.tdb"),
+ WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
+ TDB_INCOMPATIBLE_HASH |
+ (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
+ open_flags, 0600);
- if (wcache->tdb == NULL) {
+ if (wcache->db == NULL) {
DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
return false;
}
{
bool cache_bad = true;
uint32 vers;
+ NTSTATUS status;
- if (!init_wcache()) {
+ if (!init_wcache(false)) {
DEBUG(0,("initialize_winbindd_cache: init_wcache failed.\n"));
return false;
}
/* Check version number. */
- if (tdb_fetch_uint32(wcache->tdb, WINBINDD_CACHE_VERSION_KEYSTR, &vers) &&
- vers == WINBINDD_CACHE_VERSION) {
+ status = dbwrap_fetch_uint32(wcache->db, WINBINDD_CACHE_VERSION_KEYSTR,
+ &vers);
+ if (NT_STATUS_IS_OK(status) && vers == WINBINDD_CACHE_VERSION) {
cache_bad = false;
}
"and re-creating with version number %d\n",
WINBINDD_CACHE_VERSION ));
- tdb_close(wcache->tdb);
- wcache->tdb = NULL;
+ TALLOC_FREE(wcache->db);
- if (unlink(state_path("winbindd_cache.tdb")) == -1) {
- DEBUG(0,("initialize_winbindd_cache: unlink %s failed %s ",
- state_path("winbindd_cache.tdb"),
- strerror(errno) ));
- return false;
- }
- if (!init_wcache()) {
+ if (!init_wcache(true)) {
DEBUG(0,("initialize_winbindd_cache: re-initialization "
"init_wcache failed.\n"));
return false;
}
/* Write the version. */
- if (!tdb_store_uint32(wcache->tdb, WINBINDD_CACHE_VERSION_KEYSTR, WINBINDD_CACHE_VERSION)) {
- DEBUG(0,("initialize_winbindd_cache: version number store failed %s\n",
- tdb_errorstr_compat(wcache->tdb) ));
+ status = dbwrap_store_uint32(wcache->db,
+ WINBINDD_CACHE_VERSION_KEYSTR,
+ WINBINDD_CACHE_VERSION);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("initialize_winbindd_cache: version number store failed\n"));
return false;
}
}
- tdb_close(wcache->tdb);
- wcache->tdb = NULL;
+ TALLOC_FREE(wcache->db);
return true;
}
if (!wcache) {
return;
}
- if (wcache->tdb) {
- tdb_close(wcache->tdb);
- wcache->tdb = NULL;
- }
+ TALLOC_FREE(wcache->db);
}
bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
* ignore these things on cleanup.
*/
-static int traverse_fn_cleanup(TDB_CONTEXT *the_tdb, TDB_DATA kbuf,
- TDB_DATA dbuf, void *state)
+static int traverse_fn_cleanup(struct db_record *rec, void *state)
{
struct cache_entry *centry;
+ TDB_DATA kbuf = dbwrap_record_get_key(rec);
if (is_non_centry_key(kbuf)) {
return 0;
if (!NT_STATUS_IS_OK(centry->status)) {
DEBUG(10,("deleting centry %s\n", (const char *)kbuf.dptr));
- tdb_delete(the_tdb, kbuf);
+ dbwrap_record_delete(rec);
}
centry_free(centry);
{
if (!wcache)
return;
- if (wcache->tdb) {
- tdb_close(wcache->tdb);
- wcache->tdb = NULL;
- }
+ TALLOC_FREE(wcache->db);
if (!winbindd_use_cache()) {
return;
}
/* when working offline we must not clear the cache on restart */
- wcache->tdb = tdb_open_log(state_path("winbindd_cache.tdb"),
- WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
- TDB_INCOMPATIBLE_HASH |
- (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
- O_RDWR|O_CREAT, 0600);
-
- if (!wcache->tdb) {
+ wcache->db = db_s3open(wcache,
+ state_path("winbindd_cache.tdb"),
+ WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
+ TDB_INCOMPATIBLE_HASH |
+ (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
+ O_RDWR|O_CREAT, 0600);
+
+ if (!wcache->db) {
DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
return;
}
- tdb_traverse(wcache->tdb, traverse_fn_cleanup, NULL);
+ dbwrap_traverse(wcache->db, traverse_fn_cleanup, NULL, NULL);
DEBUG(10,("wcache_flush_cache success\n"));
}
/* Count cached creds */
-static int traverse_fn_cached_creds(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf,
- void *state)
+static int traverse_fn_cached_creds(struct db_record *rec, void *state)
{
int *cred_count = (int*)state;
-
+ TDB_DATA kbuf = dbwrap_record_get_key(rec);
+
if (strncmp((const char *)kbuf.dptr, "CRED/", 5) == 0) {
(*cred_count)++;
}
*count = 0;
- if (!cache->tdb) {
+ if (!cache->db) {
return NT_STATUS_INTERNAL_DB_ERROR;
}
- tdb_traverse(cache->tdb, traverse_fn_cached_creds, (void *)count);
+ dbwrap_traverse(cache->db, traverse_fn_cached_creds, (void *)count,
+ NULL);
return NT_STATUS_OK;
}
};
static struct cred_list *wcache_cred_list;
-static int traverse_fn_get_credlist(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf,
- void *state)
+static int traverse_fn_get_credlist(struct db_record *rec, void *state)
{
struct cred_list *cred;
+ TDB_DATA kbuf = dbwrap_record_get_key(rec);
if (strncmp((const char *)kbuf.dptr, "CRED/", 5) == 0) {
{
struct winbind_cache *cache = get_cache(domain);
NTSTATUS status;
- int ret;
+ int count;
struct cred_list *cred, *oldest = NULL;
- if (!cache->tdb) {
+ if (!cache->db) {
return NT_STATUS_INTERNAL_DB_ERROR;
}
fstr_sprintf(key_str, "CRED/%s", sid_to_fstring(tmp, sid));
- tdb_delete(cache->tdb, string_tdb_data(key_str));
+ dbwrap_delete(cache->db, string_tdb_data(key_str));
return NT_STATUS_OK;
}
- ret = tdb_traverse(cache->tdb, traverse_fn_get_credlist, NULL);
- if (ret == 0) {
+ status = dbwrap_traverse(cache->db, traverse_fn_get_credlist, NULL,
+ &count);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+ if (count == 0) {
return NT_STATUS_OK;
- } else if ((ret < 0) || (wcache_cred_list == NULL)) {
+ }
+ if (wcache_cred_list == NULL) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
TDB_DATA data;
time_t t;
- data = tdb_fetch_compat(cache->tdb, string_tdb_data(cred->name));
- if (!data.dptr) {
+ status = dbwrap_fetch(cache->db, NULL,
+ string_tdb_data(cred->name), &data);
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("wcache_remove_oldest_cached_creds: entry for [%s] not found\n",
cred->name));
- status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
goto done;
}
t = IVAL(data.dptr, 0);
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(data.dptr);
if (!oldest) {
oldest = SMB_MALLOC_P(struct cred_list);
}
}
- if (tdb_delete(cache->tdb, string_tdb_data(oldest->name)) == 0) {
- status = NT_STATUS_OK;
- } else {
- status = NT_STATUS_UNSUCCESSFUL;
- }
+ status = dbwrap_delete(cache->db, string_tdb_data(oldest->name));
done:
SAFE_FREE(wcache_cred_list);
SAFE_FREE(oldest);
bool set_global_winbindd_state_offline(void)
{
TDB_DATA data;
+ NTSTATUS status;
DEBUG(10,("set_global_winbindd_state_offline: offline requested.\n"));
/* Only go offline if someone has created
the key "WINBINDD_OFFLINE" in the cache tdb. */
- if (wcache == NULL || wcache->tdb == NULL) {
+ if (wcache == NULL || wcache->db == NULL) {
DEBUG(10,("set_global_winbindd_state_offline: wcache not open yet.\n"));
return false;
}
return true;
}
- data = tdb_fetch_bystring( wcache->tdb, "WINBINDD_OFFLINE" );
+ status = dbwrap_fetch_bystring(wcache->db, NULL,
+ "WINBINDD_OFFLINE", &data);
- if (!data.dptr || data.dsize != 4) {
+ if (!NT_STATUS_IS_OK(status) || data.dsize != 4) {
DEBUG(10,("set_global_winbindd_state_offline: offline state not set.\n"));
- SAFE_FREE(data.dptr);
+ if (NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(data.dptr);
+ }
return false;
} else {
DEBUG(10,("set_global_winbindd_state_offline: offline state set.\n"));
global_winbindd_offline_state = true;
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(data.dptr);
return true;
}
}
}
global_winbindd_offline_state = false;
- if (!wcache->tdb) {
+ if (!wcache->db) {
return;
}
/* Ensure there is no key "WINBINDD_OFFLINE" in the cache tdb. */
- tdb_delete_bystring(wcache->tdb, "WINBINDD_OFFLINE");
+ dbwrap_delete_bystring(wcache->db, "WINBINDD_OFFLINE");
}
bool get_global_winbindd_state_offline(void)
return global_winbindd_offline_state;
}
+#if 0
/***********************************************************************
- Validate functions for all possible cache tdb keys.
+ Validate functions for all possible cache db keys.
***********************************************************************/
static struct cache_entry *create_centry_validate(const char *kstr, TDB_DATA data,
possible.
***********************************************************************/
-static int cache_traverse_validate_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
+static int cache_traverse_validate_fn(struct db_record *rec, void *state)
{
int i;
unsigned int max_key_len = 1024;
+ TDB_DATA kbuf = dbwrap_record_get_key(rec);
+ TDB_DATA dbuf = dbwrap_record_get_value(rec);
struct tdb_validation_status *v_state = (struct tdb_validation_status *)state;
/* Paranoia check. */
v_state->success = false;
return 1; /* terminate. */
}
+#endif
static void validate_panic(const char *const why)
{
exit(47);
}
-static int wbcache_update_centry_fn(TDB_CONTEXT *tdb,
- TDB_DATA key,
- TDB_DATA data,
- void *state)
+static int wbcache_update_centry_fn(struct db_record *rec, void *state)
{
+ TDB_DATA key = dbwrap_record_get_key(rec);
+ TDB_DATA data = dbwrap_record_get_value(rec);
uint64_t ctimeout;
TDB_DATA blob;
}
if (data.dptr == NULL || data.dsize == 0) {
- if (tdb_delete(tdb, key) < 0) {
+ if (!NT_STATUS_IS_OK(dbwrap_record_delete(rec))) {
DEBUG(0, ("tdb_delete for [%s] failed!\n",
key.dptr));
return 1;
/* copy the rest */
memcpy(blob.dptr + 16, data.dptr + 8, data.dsize - 8);
- if (tdb_store(tdb, key, blob, TDB_REPLACE) < 0) {
- DEBUG(0, ("tdb_store to update [%s] failed!\n",
+ if (!NT_STATUS_IS_OK(dbwrap_record_store(rec, blob, TDB_REPLACE))) {
+ DEBUG(0, ("tdbwrap_store to update [%s] failed!\n",
key.dptr));
SAFE_FREE(blob.dptr);
return 1;
return 0;
}
-static bool wbcache_upgrade_v1_to_v2(TDB_CONTEXT *tdb)
+static bool wbcache_upgrade_v1_to_v2(struct db_context *db)
{
- int rc;
+ NTSTATUS status;
DEBUG(1, ("Upgrade to version 2 of the winbindd_cache.tdb\n"));
- rc = tdb_traverse(tdb, wbcache_update_centry_fn, NULL);
- if (rc < 0) {
+ status = dbwrap_traverse(db, wbcache_update_centry_fn, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
return false;
}
{
int ret = -1;
const char *tdb_path = state_path("winbindd_cache.tdb");
- TDB_CONTEXT *tdb = NULL;
+ struct db_context *db = NULL;
uint32_t vers_id;
+ NTSTATUS status;
bool ok;
DEBUG(10, ("winbindd_validate_cache: replacing panic function\n"));
smb_panic_fn = validate_panic;
- tdb = tdb_open_log(tdb_path,
- WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
- TDB_INCOMPATIBLE_HASH |
- ( lp_winbind_offline_logon()
- ? TDB_DEFAULT
- : TDB_DEFAULT | TDB_CLEAR_IF_FIRST ),
- O_RDWR|O_CREAT,
- 0600);
- if (!tdb) {
+ db = db_s3open(NULL, tdb_path,
+ WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
+ TDB_INCOMPATIBLE_HASH |
+ ( lp_winbind_offline_logon()
+ ? TDB_DEFAULT
+ : TDB_DEFAULT | TDB_CLEAR_IF_FIRST ),
+ O_RDWR|O_CREAT,
+ 0600);
+ if (!db) {
DEBUG(0, ("winbindd_validate_cache: "
"error opening/initializing tdb\n"));
goto done;
}
/* Version check and upgrade code. */
- if (!tdb_fetch_uint32(tdb, WINBINDD_CACHE_VERSION_KEYSTR, &vers_id)) {
+ status = dbwrap_fetch_uint32(db, WINBINDD_CACHE_VERSION_KEYSTR,
+ &vers_id);
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("Fresh database\n"));
- tdb_store_uint32(tdb, WINBINDD_CACHE_VERSION_KEYSTR, WINBINDD_CACHE_VERSION);
+ dbwrap_store_uint32(db, WINBINDD_CACHE_VERSION_KEYSTR,
+ WINBINDD_CACHE_VERSION);
vers_id = WINBINDD_CACHE_VERSION;
}
if (vers_id != WINBINDD_CACHE_VERSION) {
if (vers_id == WINBINDD_CACHE_VER1) {
- ok = wbcache_upgrade_v1_to_v2(tdb);
+ ok = wbcache_upgrade_v1_to_v2(db);
if (!ok) {
DEBUG(10, ("winbindd_validate_cache: upgrade to version 2 failed.\n"));
- unlink(tdb_path);
+ unlink(dbwrap_name(db));
goto done;
}
- tdb_store_uint32(tdb,
- WINBINDD_CACHE_VERSION_KEYSTR,
- WINBINDD_CACHE_VERSION);
+ dbwrap_store_uint32(db,
+ WINBINDD_CACHE_VERSION_KEYSTR,
+ WINBINDD_CACHE_VERSION);
vers_id = WINBINDD_CACHE_VER2;
}
}
- tdb_close(tdb);
+ TALLOC_FREE(db);
- ret = tdb_validate_and_backup(tdb_path, cache_traverse_validate_fn);
+#if 0
+ ret = db_validate_and_backup(tdb_path, cache_traverse_validate_fn);
if (ret != 0) {
+ const char *ntdb_path = state_path("winbindd_cache.ntdb");
DEBUG(10, ("winbindd_validate_cache: validation not successful.\n"));
DEBUGADD(10, ("removing tdb %s.\n", tdb_path));
+ /* Hard to know which was opened: delete both */
unlink(tdb_path);
+ unlink(ntdb_path);
}
+#endif
done:
DEBUG(10, ("winbindd_validate_cache: restoring panic function\n"));
DEBUG(10, ("winbindd_validate_cache: replacing panic function\n"));
smb_panic_fn = validate_panic;
-
- if (wcache == NULL || wcache->tdb == NULL) {
- ret = tdb_validate_open(tdb_path, cache_traverse_validate_fn);
+#if 0
+ if (wcache == NULL || wcache->db == NULL) {
+ ret = db_validate_open(tdb_path, cache_traverse_validate_fn);
} else {
- ret = tdb_validate(wcache->tdb, cache_traverse_validate_fn);
+ ret = db_validate(wcache->db, cache_traverse_validate_fn);
}
if (ret != 0) {
DEBUG(10, ("winbindd_validate_cache_nobackup: validation not "
"successful.\n"));
}
+#endif
DEBUG(10, ("winbindd_validate_cache_nobackup: restoring panic "
"function\n"));
{
TDB_DATA key = make_tdc_key( lp_workgroup() );
TDB_DATA data = { NULL, 0 };
- int ret;
+ NTSTATUS status;
if ( !key.dptr )
return false;
/* See if we were asked to delete the cache entry */
if ( !domains ) {
- ret = tdb_delete( wcache->tdb, key );
+ status = dbwrap_delete(wcache->db, key);
goto done;
}
data.dsize = pack_tdc_domains( domains, num_domains, &data.dptr );
if ( !data.dptr ) {
- ret = -1;
+ status = NT_STATUS_NO_MEMORY;
goto done;
}
- ret = tdb_store( wcache->tdb, key, data, 0 );
+ status = dbwrap_store(wcache->db, key, data, 0);
done:
SAFE_FREE( data.dptr );
SAFE_FREE( key.dptr );
- return ( ret == 0 );
+ return NT_STATUS_IS_OK(status);
}
/*********************************************************************
if ( !key.dptr )
return false;
- data = tdb_fetch_compat( wcache->tdb, key );
-
- SAFE_FREE( key.dptr );
-
- if ( !data.dptr )
+ if (!NT_STATUS_IS_OK(dbwrap_fetch(wcache->db, NULL, key, &data))) {
+ SAFE_FREE( key.dptr );
return false;
+ }
+ SAFE_FREE( key.dptr );
*num_domains = unpack_tdc_domains( data.dptr, data.dsize, domains );
- SAFE_FREE( data.dptr );
+ TALLOC_FREE( data.dptr );
if ( !*domains )
return false;
domain->domain_trust_attribs,
domain->domain_type));
- if ( !init_wcache() ) {
+ if ( !init_wcache(false) ) {
return false;
}
DEBUG(10,("wcache_tdc_fetch_domain: Searching for domain %s\n", name));
- if ( !init_wcache() ) {
+ if ( !init_wcache(false) ) {
return NULL;
}
DEBUG(10,("wcache_tdc_fetch_domainbysid: Searching for domain %s\n",
sid_string_dbg(sid)));
- if (!init_wcache()) {
+ if (!init_wcache(false)) {
return NULL;
}
void wcache_tdc_clear( void )
{
- if ( !init_wcache() )
+ if ( !init_wcache(false) )
return;
wcache_tdc_store_list( NULL, 0 );
NTSTATUS nt_status;
fstring tmp;
- if (!cache->tdb)
+ if (!cache->db)
goto do_query;
centry = wcache_fetch(cache, domain, "NSS/PWINFO/%s",
return false;
}
- if (wcache->tdb == NULL) {
+ if (wcache->db == NULL) {
return false;
}
if (!wcache_ndr_key(talloc_tos(), domain->name, opnum, req, &key)) {
return false;
}
- data = tdb_fetch_compat(wcache->tdb, key);
- TALLOC_FREE(key.dptr);
-
- if (data.dptr == NULL) {
+ if (!NT_STATUS_IS_OK(dbwrap_fetch(wcache->db, NULL, key, &data))) {
+ TALLOC_FREE(key.dptr);
return false;
}
+ TALLOC_FREE(key.dptr);
if (data.dsize < 12) {
goto fail;
}
ret = true;
fail:
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(data.dptr);
return ret;
}
return;
}
- if (wcache->tdb == NULL) {
+ if (wcache->db == NULL) {
return;
}
SBVAL(data.dptr, 4, timeout);
memcpy(data.dptr + 12, resp->data, resp->length);
- tdb_store(wcache->tdb, key, data, 0);
+ dbwrap_store(wcache->db, key, data, 0);
done:
TALLOC_FREE(key.dptr);