summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_db.c43
-rw-r--r--source3/registry/reg_objects.c65
2 files changed, 84 insertions, 24 deletions
diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c
index ce44e490ab..1ae1d6be54 100644
--- a/source3/registry/reg_db.c
+++ b/source3/registry/reg_db.c
@@ -163,16 +163,22 @@ BOOL init_registry_db( void )
return True;
}
+/**********************************************************************
+ The full path to the registry key is used as database after the
+ \'s are converted to /'s. Key string is also normalized to UPPER
+ case.
+**********************************************************************/
+static void normalize_reg_path( pstring keyname )
+{
+ pstring_sub( keyname, "\\", "/" );
+ strupper_m( keyname );
+}
/***********************************************************************
Add subkey strings to the registry tdb under a defined key
fmt is the same format as tdb_pack except this function only supports
fstrings
-
- The full path to the registry key is used as database after the
- \'s are converted to /'s. Key string is also normalized to UPPER
- case.
***********************************************************************/
static BOOL regdb_store_reg_keys_internal( char *key, REGSUBKEY_CTR *ctr )
@@ -189,12 +195,8 @@ static BOOL regdb_store_reg_keys_internal( char *key, REGSUBKEY_CTR *ctr )
return False;
pstrcpy( keyname, key );
-
- /* convert to key format */
-
- pstring_sub( keyname, "\\", "/" );
- strupper_m( keyname );
-
+ normalize_reg_path( keyname );
+
/* allocate some initial memory */
buffer = SMB_MALLOC(sizeof(pstring));
@@ -249,7 +251,13 @@ static BOOL regdb_store_reg_keys( char *key, REGSUBKEY_CTR *ctr )
{
int num_subkeys, i;
pstring path;
- REGSUBKEY_CTR subkeys;
+ REGSUBKEY_CTR subkeys, old_subkeys;
+ char *oldkeyname;
+
+ /* fetch a list of the old subkeys so we can difure out if any were deleted */
+
+ regsubkey_ctr_init( &old_subkeys );
+ regdb_fetch_reg_keys( key, &old_subkeys );
/* store the subkey list for the parent */
@@ -258,6 +266,18 @@ static BOOL regdb_store_reg_keys( char *key, REGSUBKEY_CTR *ctr )
return False;
}
+ /* now delete removed keys */
+
+ num_subkeys = regsubkey_ctr_numkeys( &old_subkeys );
+ for ( i=0; i<num_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 );
+ tdb_delete_bystring( tdb_reg, path );
+ }
+ }
+
/* now create records for any subkeys that don't already exist */
num_subkeys = regsubkey_ctr_numkeys( ctr );
@@ -268,6 +288,7 @@ static BOOL regdb_store_reg_keys( char *key, REGSUBKEY_CTR *ctr )
/* create a record with 0 subkeys */
if ( !regdb_store_reg_keys_internal( path, &subkeys ) ) {
DEBUG(0,("regdb_store_reg_keys: Failed to store new record for key [%s}\n", path ));
+ regsubkey_ctr_destroy( &subkeys );
return False;
}
}
diff --git a/source3/registry/reg_objects.c b/source3/registry/reg_objects.c
index 2dd61f515f..582a696529 100644
--- a/source3/registry/reg_objects.c
+++ b/source3/registry/reg_objects.c
@@ -43,22 +43,16 @@ void regsubkey_ctr_init( REGSUBKEY_CTR *ctr )
int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname )
{
- uint32 len;
char **pp;
- int i;
-
+
if ( !keyname )
return ctr->num_subkeys;
- len = strlen( keyname );
-
/* make sure the keyname is not already there */
- for ( i=0; i<ctr->num_subkeys; i++ ) {
- if ( strequal( ctr->subkeys[i], keyname ) )
- return ctr->num_subkeys;
- }
-
+ if ( regsubkey_ctr_key_exists( ctr, keyname ) )
+ return ctr->num_subkeys;
+
/* allocate a space for the char* in the array */
if ( ctr->subkeys == 0 )
@@ -71,13 +65,58 @@ int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname )
/* allocate the string and save it in the array */
- ctr->subkeys[ctr->num_subkeys] = TALLOC( ctr->ctx, len+1 );
- strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 );
+ ctr->subkeys[ctr->num_subkeys] = talloc_strdup( ctr->ctx, keyname );
ctr->num_subkeys++;
return ctr->num_subkeys;
}
+ /***********************************************************************
+ Add a new key to the array
+ **********************************************************************/
+
+int regsubkey_ctr_delkey( REGSUBKEY_CTR *ctr, const char *keyname )
+{
+ int i;
+
+ if ( !keyname )
+ return ctr->num_subkeys;
+
+ /* make sure the keyname is actually already there */
+
+ for ( i=0; i<ctr->num_subkeys; i++ ) {
+ if ( strequal( ctr->subkeys[i], keyname ) )
+ break;
+ }
+
+ if ( i == ctr->num_subkeys )
+ return ctr->num_subkeys;
+
+ /* update if we have any keys left */
+ ctr->num_subkeys--;
+ if ( ctr->num_subkeys )
+ memmove( &ctr->subkeys[i], &ctr->subkeys[i+1], sizeof(char*) * (ctr->num_subkeys-i) );
+
+ return ctr->num_subkeys;
+}
+
+/***********************************************************************
+ Check for the existance of a key
+ **********************************************************************/
+
+BOOL regsubkey_ctr_key_exists( REGSUBKEY_CTR *ctr, const char *keyname )
+{
+ int i;
+
+ for ( i=0; i<ctr->num_subkeys; i++ ) {
+ if ( strequal( ctr->subkeys[i],keyname ) )
+ return True;
+ }
+
+ return False;
+
+}
+
/***********************************************************************
How many keys does the container hold ?
**********************************************************************/
@@ -351,7 +390,7 @@ int regval_ctr_delvalue( REGVAL_CTR *ctr, const char *name )
}
/***********************************************************************
- Delete a single value from the registry container.
+ Retrieve single value from the registry container.
No need to free memory since it is talloc'd.
**********************************************************************/