diff options
author | Gerald Carter <jerry@samba.org> | 2005-06-17 18:57:37 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:57:19 -0500 |
commit | c25b67b24d3c7ec04a58410aaa05c1aae9688e32 (patch) | |
tree | 4c58725f37a14273333371b15a96dc02fa2a70ae /source3/registry/reg_db.c | |
parent | 5c9963c287e20a4a4b8bbaa088328438eb4f942c (diff) | |
download | samba-c25b67b24d3c7ec04a58410aaa05c1aae9688e32.tar.gz samba-c25b67b24d3c7ec04a58410aaa05c1aae9688e32.tar.bz2 samba-c25b67b24d3c7ec04a58410aaa05c1aae9688e32.zip |
r7698: * clean upserver frontend for RegDeleteKey()
* implement RegDeleteKey() for reg_db backend
(This used to be commit 91b81a23b8e2a096747e02fd9392ef590e7f0d61)
Diffstat (limited to 'source3/registry/reg_db.c')
-rw-r--r-- | source3/registry/reg_db.c | 43 |
1 files changed, 32 insertions, 11 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; } } |