From 44707ad2e00a91f459e80efbe8f362b5853b0a62 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 14:55:40 +0000 Subject: r9739: conver the reg_objects (REGSUBKEY_CTR & REGVAL_CTR) to use the new talloc() features: Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d since the methods use the object pointer as the talloc context for internal private data. There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy() pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the object. Also had to convert the printer_info_2->NT_PRINTER_DATA field to be talloc()'d as well. This is just a stop on the road to cleaning up the printer memory management. (This used to be commit ef721333ab9639cb5346067497e99fbd0d4425dd) --- source3/registry/reg_db.c | 78 +++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 27 deletions(-) (limited to 'source3/registry/reg_db.c') diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index 64a863ceac..19f9abd80d 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -31,7 +31,7 @@ static TDB_CONTEXT *tdb_reg; /* List the deepest path into the registry. All part components will be created.*/ -/* If you want to have a part of the path controlled by the tdb abd part by +/* If you want to have a part of the path controlled by the tdb and part by a virtual registry db (e.g. printing), then you have to list the deepest path. For example,"HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Print" allows the reg_db backend to handle everything up to @@ -89,12 +89,20 @@ static BOOL init_registry_data( void ) { pstring path, base, remaining; fstring keyname, subkeyname; - REGSUBKEY_CTR subkeys; - REGVAL_CTR values; + REGSUBKEY_CTR *subkeys; + REGVAL_CTR *values; + uint32 *ctx; int i; const char *p, *p2; UNISTR2 data; + /* create a new top level talloc ctx */ + + if ( !(ctx = TALLOC_P( NULL, uint32 )) ) { + DEBUG(0,("init_registry_data: top level talloc() failure!\n")); + return False; + } + /* loop over all of the predefined paths and add each component */ for ( i=0; builtin_registry_paths[i] != NULL; i++ ) { @@ -131,27 +139,33 @@ static BOOL init_registry_data( void ) we are about to update the record. We just want any subkeys already present */ - regsubkey_ctr_init( &subkeys ); - - regdb_fetch_keys( base, &subkeys ); + if ( !(subkeys = TALLOC_ZERO_P( ctx, REGSUBKEY_CTR )) ) { + DEBUG(0,("talloc() failure!\n")); + return False; + } + + regdb_fetch_keys( base, subkeys ); if ( *subkeyname ) - regsubkey_ctr_addkey( &subkeys, subkeyname ); - if ( !regdb_store_keys( base, &subkeys )) + regsubkey_ctr_addkey( subkeys, subkeyname ); + if ( !regdb_store_keys( base, subkeys )) return False; - regsubkey_ctr_destroy( &subkeys ); + TALLOC_FREE( subkeys ); } } /* loop over all of the predefined values and add each component */ for ( i=0; builtin_registry_values[i].path != NULL; i++ ) { - regval_ctr_init( &values ); - - regdb_fetch_values( builtin_registry_values[i].path, &values ); + if ( !(values = TALLOC_ZERO_P( ctx, REGVAL_CTR )) ) { + DEBUG(0,("talloc() failure!\n")); + return False; + } + + regdb_fetch_values( builtin_registry_values[i].path, values ); switch( builtin_registry_values[i].type ) { case REG_DWORD: - regval_ctr_addvalue( &values, + regval_ctr_addvalue( values, builtin_registry_values[i].valuename, REG_DWORD, (char*)&builtin_registry_values[i].data.dw_value, @@ -160,7 +174,7 @@ static BOOL init_registry_data( void ) case REG_SZ: init_unistr2( &data, builtin_registry_values[i].data.string, UNI_STR_TERMINATE); - regval_ctr_addvalue( &values, + regval_ctr_addvalue( values, builtin_registry_values[i].valuename, REG_SZ, (char*)data.buffer, @@ -171,9 +185,9 @@ static BOOL init_registry_data( void ) DEBUG(0,("init_registry_data: invalid value type in builtin_registry_values [%d]\n", builtin_registry_values[i].type)); } - regdb_store_values( builtin_registry_values[i].path, &values ); + regdb_store_values( builtin_registry_values[i].path, values ); - regval_ctr_destroy( &values ); + TALLOC_FREE( values ); } return True; @@ -297,13 +311,17 @@ BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr ) { int num_subkeys, i; pstring path; - REGSUBKEY_CTR subkeys, old_subkeys; + REGSUBKEY_CTR *subkeys, *old_subkeys; char *oldkeyname; /* fetch a list of the old subkeys so we can determine if any were deleted */ - regsubkey_ctr_init( &old_subkeys ); - regdb_fetch_keys( key, &old_subkeys ); + if ( !(old_subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) { + DEBUG(0,("regdb_store_keys: talloc() failure!\n")); + return False; + } + + regdb_fetch_keys( key, old_subkeys ); /* store the subkey list for the parent */ @@ -314,9 +332,9 @@ BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr ) /* now delete removed keys */ - num_subkeys = regsubkey_ctr_numkeys( &old_subkeys ); + num_subkeys = regsubkey_ctr_numkeys( old_subkeys ); for ( i=0; i