summaryrefslogtreecommitdiff
path: root/source3/registry/reg_db.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-08-29 14:55:40 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:03:25 -0500
commit44707ad2e00a91f459e80efbe8f362b5853b0a62 (patch)
tree438124f4550315df722d959891b66e669222f8e8 /source3/registry/reg_db.c
parent77670a2ec33275ae08a37606ee15bf0170b7fcb3 (diff)
downloadsamba-44707ad2e00a91f459e80efbe8f362b5853b0a62.tar.gz
samba-44707ad2e00a91f459e80efbe8f362b5853b0a62.tar.bz2
samba-44707ad2e00a91f459e80efbe8f362b5853b0a62.zip
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)
Diffstat (limited to 'source3/registry/reg_db.c')
-rw-r--r--source3/registry/reg_db.c78
1 files changed, 51 insertions, 27 deletions
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<num_subkeys; i++ ) {
- oldkeyname = regsubkey_ctr_specific_key( &old_subkeys, i );
+ oldkeyname = regsubkey_ctr_specific_key( old_subkeys, i );
if ( !regsubkey_ctr_key_exists( ctr, oldkeyname ) ) {
pstr_sprintf( path, "%s%c%s", key, '/', oldkeyname );
normalize_reg_path( path );
@@ -324,23 +342,29 @@ BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr )
}
}
- regsubkey_ctr_destroy( &old_subkeys );
+ TALLOC_FREE( old_subkeys );
/* now create records for any subkeys that don't already exist */
num_subkeys = regsubkey_ctr_numkeys( ctr );
for ( i=0; i<num_subkeys; i++ ) {
pstr_sprintf( path, "%s%c%s", key, '/', regsubkey_ctr_specific_key( ctr, i ) );
- regsubkey_ctr_init( &subkeys );
- if ( regdb_fetch_keys( path, &subkeys ) == -1 ) {
+
+ if ( !(subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {
+ DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
+ return False;
+ }
+
+ if ( regdb_fetch_keys( path, subkeys ) == -1 ) {
/* create a record with 0 subkeys */
- if ( !regdb_store_keys_internal( path, &subkeys ) ) {
+ if ( !regdb_store_keys_internal( path, subkeys ) ) {
DEBUG(0,("regdb_store_keys: Failed to store new record for key [%s}\n", path ));
- regsubkey_ctr_destroy( &subkeys );
+ TALLOC_FREE( subkeys );
return False;
}
}
- regsubkey_ctr_destroy( &subkeys );
+
+ TALLOC_FREE( subkeys );
}
return True;