summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-03-16 23:03:34 +0100
committerMichael Adam <obnox@samba.org>2008-03-17 08:22:32 +0100
commit178f3afe414760d8b8082ba411a971d70b8c5321 (patch)
treeff10e52ea679883cfd150c894b6ca221443b37cd /source3/registry
parenta5e1910f82228bc779508e3977a05ec553d99a01 (diff)
downloadsamba-178f3afe414760d8b8082ba411a971d70b8c5321.tar.gz
samba-178f3afe414760d8b8082ba411a971d70b8c5321.tar.bz2
samba-178f3afe414760d8b8082ba411a971d70b8c5321.zip
registry: migrate tdb registry backend to dbwrap.
Michael (This used to be commit 3c42d8ee16a4b143c6658fe26030569658eaef66)
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_backend_db.c101
1 files changed, 52 insertions, 49 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index 518078a062..7690ca2a05 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -24,7 +24,7 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_REGISTRY
-static struct tdb_wrap *tdb_reg = NULL;
+static struct db_context *tdb_reg = NULL;
static int tdb_refcount;
/* List the deepest path into the registry. All part components will be created.*/
@@ -105,7 +105,7 @@ static bool init_registry_data( void )
* transaction behaviour.
*/
- if ( tdb_transaction_start( tdb_reg->tdb ) == -1 ) {
+ if ( tdb_reg->transaction_start( tdb_reg ) == -1 ) {
DEBUG(0, ("init_registry_data: tdb_transaction_start "
"failed\n"));
return false;
@@ -229,7 +229,7 @@ static bool init_registry_data( void )
TALLOC_FREE(frame);
- if (tdb_transaction_commit( tdb_reg->tdb ) == -1) {
+ if (tdb_reg->transaction_commit(tdb_reg) == -1) {
DEBUG(0, ("init_registry_data: Could not commit "
"transaction\n"));
return false;
@@ -241,7 +241,7 @@ static bool init_registry_data( void )
TALLOC_FREE(frame);
- if (tdb_transaction_cancel( tdb_reg->tdb ) == -1) {
+ if (tdb_reg->transaction_cancel(tdb_reg) == -1) {
smb_panic("init_registry_data: tdb_transaction_cancel "
"failed\n");
}
@@ -264,9 +264,9 @@ bool regdb_init( void )
return true;
}
- if ( !(tdb_reg = tdb_wrap_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600)) )
+ if ( !(tdb_reg = db_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600)) )
{
- tdb_reg = tdb_wrap_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600);
+ tdb_reg = db_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600);
if ( !tdb_reg ) {
DEBUG(0,("regdb_init: Failed to open registry %s (%s)\n",
state_path("registry.tdb"), strerror(errno) ));
@@ -278,7 +278,7 @@ bool regdb_init( void )
tdb_refcount = 1;
- vers_id = tdb_fetch_int32(tdb_reg->tdb, vstring);
+ vers_id = dbwrap_fetch_int32(tdb_reg, vstring);
if ( vers_id != REGVER_V1 ) {
/* any upgrade code here if needed */
@@ -312,7 +312,7 @@ WERROR regdb_open( void )
become_root();
- tdb_reg = tdb_wrap_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600);
+ tdb_reg = db_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600);
if ( !tdb_reg ) {
result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
@@ -356,7 +356,7 @@ int regdb_close( void )
***********************************************************************/
int regdb_get_seqnum(void)
{
- return tdb_get_seqnum(tdb_reg->tdb);
+ return tdb_reg->get_seqnum(tdb_reg);
}
/***********************************************************************
@@ -375,6 +375,7 @@ static bool regdb_store_keys_internal(const char *key, REGSUBKEY_CTR *ctr)
uint32 num_subkeys = regsubkey_ctr_numkeys(ctr);
char *keyname = NULL;
TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status;
if (!key) {
return false;
@@ -419,7 +420,8 @@ static bool regdb_store_keys_internal(const char *key, REGSUBKEY_CTR *ctr)
dbuf.dptr = buffer;
dbuf.dsize = len;
- if ( tdb_store_bystring( tdb_reg->tdb, keyname, dbuf, TDB_REPLACE ) == -1) {
+ status = dbwrap_store_bystring(tdb_reg, keyname, dbuf, TDB_REPLACE);
+ if (!NT_STATUS_IS_OK(status)) {
ret = false;
goto done;
}
@@ -441,6 +443,7 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
REGSUBKEY_CTR *subkeys = NULL, *old_subkeys = NULL;
char *oldkeyname = NULL;
TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status;
/*
* fetch a list of the old subkeys so we can determine if anything has
@@ -473,8 +476,8 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
}
}
- if (tdb_transaction_start( tdb_reg->tdb ) == -1) {
- DEBUG(0, ("regdb_store_keys: tdb_transaction_start failed\n"));
+ if (tdb_reg->transaction_start(tdb_reg) == -1) {
+ DEBUG(0, ("regdb_store_keys: transaction_start failed\n"));
return false;
}
@@ -521,7 +524,8 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
if (!path) {
goto fail;
}
- if (tdb_delete_bystring(tdb_reg->tdb, path) == -1) {
+ status = dbwrap_delete_bystring(tdb_reg, path);
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Deleting %s failed\n", path));
goto fail;
}
@@ -542,7 +546,7 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
/*
* Ignore errors here, we might have no values around
*/
- tdb_delete_bystring( tdb_reg->tdb, path );
+ dbwrap_delete_bystring(tdb_reg, path);
TALLOC_FREE(path);
}
@@ -592,7 +596,7 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
TALLOC_FREE(path);
}
- if (tdb_transaction_commit( tdb_reg->tdb ) == -1) {
+ if (tdb_reg->transaction_commit(tdb_reg) == -1) {
DEBUG(0, ("regdb_store_keys: Could not commit transaction\n"));
return false;
}
@@ -603,8 +607,8 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
TALLOC_FREE(old_subkeys);
TALLOC_FREE(subkeys);
- if (tdb_transaction_cancel(tdb_reg->tdb) == -1) {
- smb_panic("regdb_store_keys: tdb_transaction_cancel failed\n");
+ if (tdb_reg->transaction_cancel(tdb_reg) == -1) {
+ smb_panic("regdb_store_keys: transaction_cancel failed\n");
}
return false;
@@ -620,13 +624,13 @@ int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
{
char *path = NULL;
uint32 num_items;
- TDB_DATA dbuf;
uint8 *buf;
uint32 buflen, len;
int i;
fstring subkeyname;
int ret = -1;
TALLOC_CTX *frame = talloc_stackframe();
+ struct db_record *rec;
DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));
@@ -642,18 +646,15 @@ int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
}
strupper_m(path);
- if (tdb_read_lock_bystring_with_timeout(tdb_reg->tdb, path, 10) == -1) {
+ rec = tdb_reg->fetch_locked(tdb_reg, frame, string_term_tdb_data(path));
+ if (rec == NULL) {
return 0;
}
- dbuf = tdb_fetch_bystring(tdb_reg->tdb, path);
ctr->seqnum = regdb_get_seqnum();
- tdb_read_unlock_bystring(tdb_reg->tdb, path);
-
-
- buf = dbuf.dptr;
- buflen = dbuf.dsize;
+ buf = rec->value.dptr;
+ buflen = rec->value.dsize;
if ( !buf ) {
DEBUG(5,("regdb_fetch_keys: tdb lookup failed to locate key [%s]\n", key));
@@ -667,8 +668,6 @@ int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
regsubkey_ctr_addkey(ctr, subkeyname);
}
- SAFE_FREE(dbuf.dptr);
-
DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items));
ret = num_items;
@@ -763,9 +762,10 @@ static int regdb_pack_values(REGVAL_CTR *values, uint8 *buf, int buflen)
int regdb_fetch_values( const char* key, REGVAL_CTR *values )
{
- TDB_DATA data;
char *keystr = NULL;
- TALLOC_CTX *ctx = talloc_tos();
+ TALLOC_CTX *ctx = talloc_stackframe();
+ struct db_record *rec;
+ int ret = 0;
DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key));
@@ -775,27 +775,27 @@ int regdb_fetch_values( const char* key, REGVAL_CTR *values )
}
keystr = normalize_reg_path(ctx, keystr);
if (!keystr) {
- return 0;
+ goto done;
}
- if (tdb_read_lock_bystring_with_timeout(tdb_reg->tdb, keystr, 10) == -1) {
- return 0;
+ rec = tdb_reg->fetch_locked(tdb_reg, ctx, string_term_tdb_data(keystr));
+ if (rec == NULL) {
+ goto done;
}
- data = tdb_fetch_bystring(tdb_reg->tdb, keystr);
values->seqnum = regdb_get_seqnum();
- tdb_read_unlock_bystring(tdb_reg->tdb, keystr);
-
- if (!data.dptr) {
+ if (!rec->value.dptr) {
/* all keys have zero values by default */
- return 0;
+ goto done;
}
- regdb_unpack_values(values, data.dptr, data.dsize);
+ regdb_unpack_values(values, rec->value.dptr, rec->value.dsize);
+ ret = regval_ctr_numvals(values);
- SAFE_FREE(data.dptr);
- return regval_ctr_numvals(values);
+done:
+ TALLOC_FREE(ctx);
+ return ret;
}
bool regdb_store_values( const char *key, REGVAL_CTR *values )
@@ -833,19 +833,20 @@ bool regdb_store_values( const char *key, REGVAL_CTR *values )
return false;
}
- old_data = tdb_fetch_bystring(tdb_reg->tdb, keystr);
+ old_data = dbwrap_fetch_bystring(tdb_reg, ctx, keystr);
if ((old_data.dptr != NULL)
&& (old_data.dsize == data.dsize)
&& (memcmp(old_data.dptr, data.dptr, data.dsize) == 0)) {
- SAFE_FREE(old_data.dptr);
+ TALLOC_FREE(old_data.dptr);
SAFE_FREE(data.dptr);
return true;
}
- ret = tdb_trans_store_bystring(tdb_reg->tdb, keystr, data, TDB_REPLACE);
+ ret = dbwrap_trans_store(tdb_reg, string_term_tdb_data(keystr), data,
+ TDB_REPLACE);
- SAFE_FREE( old_data.dptr );
+ TALLOC_FREE( old_data.dptr );
SAFE_FREE( data.dptr );
return ret != -1 ;
@@ -857,6 +858,7 @@ static WERROR regdb_get_secdesc(TALLOC_CTX *mem_ctx, const char *key,
char *tdbkey;
TDB_DATA data;
NTSTATUS status;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
DEBUG(10, ("regdb_get_secdesc: Getting secdesc of key [%s]\n", key));
@@ -865,7 +867,7 @@ static WERROR regdb_get_secdesc(TALLOC_CTX *mem_ctx, const char *key,
}
normalize_dbkey(tdbkey);
- data = tdb_fetch_bystring(tdb_reg->tdb, tdbkey);
+ data = dbwrap_fetch_bystring(tdb_reg, tmp_ctx, tdbkey);
SAFE_FREE(tdbkey);
if (data.dptr == NULL) {
@@ -875,7 +877,7 @@ static WERROR regdb_get_secdesc(TALLOC_CTX *mem_ctx, const char *key,
status = unmarshall_sec_desc(mem_ctx, (uint8 *)data.dptr, data.dsize,
psecdesc);
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(tmp_ctx);
if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MEMORY)) {
return WERR_NOMEM;
@@ -913,8 +915,8 @@ static WERROR regdb_set_secdesc(const char *key,
/* assuming a delete */
int tdb_ret;
- tdb_ret = tdb_trans_delete(tdb_reg->tdb,
- string_term_tdb_data(tdbkey));
+ tdb_ret = dbwrap_trans_delete(tdb_reg,
+ string_term_tdb_data(tdbkey));
if (tdb_ret == -1) {
err = ntstatus_to_werror(map_nt_error_from_unix(errno));
} else {
@@ -931,7 +933,8 @@ static WERROR regdb_set_secdesc(const char *key,
goto done;
}
- if (tdb_trans_store_bystring(tdb_reg->tdb, tdbkey, tdbdata, 0) == -1) {
+ if (dbwrap_trans_store(tdb_reg, string_term_tdb_data(tdbkey),
+ tdbdata, 0) == -1) {
err = ntstatus_to_werror(map_nt_error_from_unix(errno));
goto done;
}