From 7a192590514fe8adebf4cdf51dc96c48d5225329 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 22 Nov 2006 16:53:28 +0000 Subject: r19841: Wrap regdb_store_keys and regdb_store_values in tdb transactions (This used to be commit 5ec737922041b723b9e60c08049ace5fa2fa5dec) --- source3/lib/util_tdb.c | 8 ++++++ source3/registry/reg_db.c | 70 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 18 deletions(-) (limited to 'source3') diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c index e847c79369..4db39095a6 100644 --- a/source3/lib/util_tdb.c +++ b/source3/lib/util_tdb.c @@ -302,6 +302,14 @@ int tdb_store_bystring(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int return tdb_store(tdb, key, data, flags); } +int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr, + TDB_DATA data, int flags) +{ + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + + return tdb_trans_store(tdb, key, data, flags); +} + /**************************************************************************** Fetch a buffer using a null terminated string key. Don't forget to call free() on the result dptr. diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index df0664a304..2afecffec7 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -366,15 +366,20 @@ BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr ) { int num_subkeys, i; pstring path; - REGSUBKEY_CTR *subkeys, *old_subkeys; + REGSUBKEY_CTR *subkeys = NULL, *old_subkeys = NULL; char *oldkeyname; + if ( tdb_transaction_start( tdb_reg ) == -1 ) { + DEBUG(0, ("regdb_store_keys: tdb_transaction_start failed\n")); + return False; + } + /* fetch a list of the old subkeys so we can determine if any were * deleted */ if ( !(old_subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) { DEBUG(0,("regdb_store_keys: talloc() failure!\n")); - return False; + goto fail; } regdb_fetch_keys( key, old_subkeys ); @@ -383,8 +388,8 @@ BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr ) if ( !regdb_store_keys_internal( key, ctr ) ) { DEBUG(0,("regdb_store_keys: Failed to store new subkey list " - "for parent [%s}\n", key )); - return False; + "for parent [%s]\n", key )); + goto fail; } /* now delete removed keys */ @@ -392,15 +397,30 @@ BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr ) num_subkeys = regsubkey_ctr_numkeys( old_subkeys ); for ( i=0; i