registry: remove the REGISTRY_HOOKS layer from the reghook cache.
authorMichael Adam <obnox@samba.org>
Sat, 12 Apr 2008 22:54:44 +0000 (00:54 +0200)
committerMichael Adam <obnox@samba.org>
Sat, 12 Apr 2008 23:43:42 +0000 (01:43 +0200)
There is no need to save the keyname again, we only need to
get the REGISTRY_OPS out of the pathtree.

Furthermore, this makes life easier, since we can now pass
in keynames as temporarily allocated strings.

Michael
(This used to be commit 2f9ee2f782c77ed99669af5ac2ba40cb0978f0da)

source3/include/reg_objects.h
source3/registry/reg_api.c
source3/registry/reg_cachehook.c
source3/registry/reg_dispatcher.c
source3/registry/reg_init_full.c
source3/registry/reg_init_smbconf.c
source3/script/mkproto.awk

index 1d0d0d4996f476aa98f02ddc8d7588e5b3cc84d9..d9159dd464ded4f62cf4a198ae1bd3536f3810a1 100644 (file)
@@ -159,7 +159,7 @@ typedef struct _RegistryKey {
        uint32          type;
        char            *name;          /* full name of registry key */
        uint32          access_granted;
-       REGISTRY_HOOK   *hook;  
+       REGISTRY_OPS    *ops;
 } REGISTRY_KEY;
 
 struct registry_key {
index 1a0bf2b16aae0b5fbaa83d7f41975c88f2716d29..cbbc7dd0ef6fa0c514b3cc909b8eb8022a9c7be7 100644 (file)
@@ -183,9 +183,9 @@ static WERROR regkey_open_onelevel(TALLOC_CTX *mem_ctx,
        
        /* Look up the table of registry I/O operations */
 
-       if ( !(key->hook = reghook_cache_find( key->name )) ) {
-               DEBUG(0,("reg_open_onelevel: Failed to assign "
-                        "REGISTRY_HOOK to [%s]\n", key->name ));
+       if ( !(key->ops = reghook_cache_find( key->name )) ) {
+               DEBUG(0,("reg_open_onelevel: Failed to assign "
+                        "REGISTRY_OPS to [%s]\n", key->name ));
                result = WERR_BADFILE;
                goto done;
        }
@@ -733,9 +733,9 @@ static WERROR reg_load_tree(REGF_FILE *regfile, const char *topkeypath,
 
        /* initialize the REGISTRY_KEY structure */
 
-       registry_key.hook = reghook_cache_find(topkeypath);
-       if (!registry_key.hook) {
-               DEBUG(0, ("reg_load_tree: Failed to assigned a REGISTRY_HOOK "
+       registry_key.ops = reghook_cache_find(topkeypath);
+       if (!registry_key.ops) {
+               DEBUG(0, ("reg_load_tree: Failed to assign  REGISTRY_OPS "
                          "to [%s]\n", topkeypath));
                return WERR_BADFILE;
        }
@@ -898,8 +898,8 @@ static WERROR reg_write_tree(REGF_FILE *regfile, const char *keypath,
                return WERR_NOMEM;
        }
 
-       registry_key.hook = reghook_cache_find(registry_key.name);
-       if (registry_key.hook == NULL) {
+       registry_key.ops = reghook_cache_find(registry_key.name);
+       if (registry_key.ops == NULL) {
                return WERR_BADFILE;
        }
 
index f9851c781012b92c3ede67272da398ba370727d1..7ce39aff25cba524ccdf89f97e8b446ed6090a54 100644 (file)
@@ -27,7 +27,6 @@
 
 static SORTED_TREE *cache_tree = NULL;
 extern REGISTRY_OPS regdb_ops;         /* these are the default */
-static REGISTRY_HOOK default_hook = { KEY_TREE_ROOT, &regdb_ops };
 
 /**********************************************************************
  Initialize the cache tree if it has not been initialized yet.
@@ -36,7 +35,7 @@ static REGISTRY_HOOK default_hook = { KEY_TREE_ROOT, &regdb_ops };
 bool reghook_cache_init( void )
 {
        if (cache_tree == NULL) {
-               cache_tree = pathtree_init(&default_hook, NULL);
+               cache_tree = pathtree_init(&regdb_ops, NULL);
                if (cache_tree !=0) {
                        DEBUG(10, ("reghook_cache_init: new tree with default "
                                   "ops %p for key [%s]\n", (void *)&regdb_ops,
@@ -48,20 +47,20 @@ bool reghook_cache_init( void )
 }
 
 /**********************************************************************
- Add a new REGISTRY_HOOK to the cache.  Note that the keyname
+ Add a new registry hook to the cache.  Note that the keyname
  is not in the exact format that a SORTED_TREE expects.
  *********************************************************************/
 
-bool reghook_cache_add( REGISTRY_HOOK *hook )
+bool reghook_cache_add(const char *keyname, REGISTRY_OPS *ops)
 {
        TALLOC_CTX *ctx = talloc_tos();
        char *key = NULL;
 
-       if (!hook) {
+       if ((keyname == NULL) || (ops == NULL)) {
                return false;
        }
 
-       key = talloc_asprintf(ctx, "\\%s", hook->keyname);
+       key = talloc_asprintf(ctx, "\\%s", keyname);
        if (!key) {
                return false;
        }
@@ -71,20 +70,20 @@ bool reghook_cache_add( REGISTRY_HOOK *hook )
        }
 
        DEBUG(10, ("reghook_cache_add: Adding ops %p for key [%s]\n",
-                  (void *)hook->ops, key));
+                  (void *)ops, key));
 
-       return pathtree_add( cache_tree, key, hook );
+       return pathtree_add(cache_tree, key, ops);
 }
 
 /**********************************************************************
  Initialize the cache tree
  *********************************************************************/
 
-REGISTRY_HOOK* reghook_cache_find( const char *keyname )
+REGISTRY_OPS *reghook_cache_find(const char *keyname)
 {
        char *key;
        int len;
-       REGISTRY_HOOK *hook;
+       REGISTRY_OPS *ops;
        
        if ( !keyname )
                return NULL;
@@ -107,14 +106,14 @@ REGISTRY_HOOK* reghook_cache_find( const char *keyname )
                
        DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key));
        
-       hook = (REGISTRY_HOOK *)pathtree_find( cache_tree, key ) ;
+       ops = (REGISTRY_OPS *)pathtree_find(cache_tree, key);
 
        DEBUG(10, ("reghook_cache_find: found ops %p for key [%s]\n",
-                  hook ? (void *)hook->ops : 0, key));
+                  ops ? (void *)ops : 0, key));
        
        SAFE_FREE( key );
        
-       return hook;
+       return ops;
 }
 
 /**********************************************************************
index cdcd045904d93f72f33f1bd8eae79d773f293cd6..c68ecdedebcd01014a32cd57505af0de5a5f91b8 100644 (file)
@@ -86,8 +86,8 @@ static WERROR construct_registry_sd(TALLOC_CTX *ctx, SEC_DESC **psd)
 
 bool store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys )
 {
-       if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys )
-               return key->hook->ops->store_subkeys( key->name, subkeys );
+       if (key->ops && key->ops->store_subkeys)
+               return key->ops->store_subkeys(key->name, subkeys);
 
        return false;
 }
@@ -98,8 +98,8 @@ bool store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys )
 
 bool store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
 {
-       if ( key->hook && key->hook->ops && key->hook->ops->store_values )
-               return key->hook->ops->store_values( key->name, val );
+       if (key->ops && key->ops->store_values)
+               return key->ops->store_values(key->name, val);
 
        return false;
 }
@@ -113,8 +113,8 @@ int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr )
 {
        int result = -1;
 
-       if ( key->hook && key->hook->ops && key->hook->ops->fetch_subkeys )
-               result = key->hook->ops->fetch_subkeys( key->name, subkey_ctr );
+       if (key->ops && key->ops->fetch_subkeys)
+               result = key->ops->fetch_subkeys(key->name, subkey_ctr);
 
        return result;
 }
@@ -128,10 +128,10 @@ int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
        int result = -1;
 
        DEBUG(10, ("fetch_reg_values called for key '%s' (ops %p)\n", key->name,
-                  (key->hook && key->hook->ops) ? (void *)key->hook->ops : NULL));
+                  (key->ops) ? (void *)key->ops : NULL));
 
-       if ( key->hook && key->hook->ops && key->hook->ops->fetch_values )
-               result = key->hook->ops->fetch_values( key->name, val );
+       if (key->ops && key->ops->fetch_values)
+               result = key->ops->fetch_values(key->name, val);
 
        return result;
 }
@@ -152,9 +152,9 @@ bool regkey_access_check( REGISTRY_KEY *key, uint32 requested, uint32 *granted,
        /* use the default security check if the backend has not defined its
         * own */
 
-       if (key->hook && key->hook->ops && key->hook->ops->reg_access_check) {
-               return key->hook->ops->reg_access_check( key->name, requested,
-                                                        granted, token );
+       if (key->ops && key->ops->reg_access_check) {
+               return key->ops->reg_access_check(key->name, requested,
+                                                 granted, token);
        }
 
        /*
@@ -189,9 +189,8 @@ WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key,
        struct security_descriptor *secdesc;
        WERROR werr;
 
-       if (key->hook && key->hook->ops && key->hook->ops->get_secdesc) {
-               werr = key->hook->ops->get_secdesc(mem_ctx, key->name,
-                                                  psecdesc);
+       if (key->ops && key->ops->get_secdesc) {
+               werr = key->ops->get_secdesc(mem_ctx, key->name, psecdesc);
                if (W_ERROR_IS_OK(werr)) {
                        return WERR_OK;
                }
@@ -209,8 +208,8 @@ WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key,
 WERROR regkey_set_secdesc(REGISTRY_KEY *key,
                          struct security_descriptor *psecdesc)
 {
-       if (key->hook && key->hook->ops && key->hook->ops->set_secdesc) {
-               return key->hook->ops->set_secdesc(key->name, psecdesc);
+       if (key->ops && key->ops->set_secdesc) {
+               return key->ops->set_secdesc(key->name, psecdesc);
        }
 
        return WERR_ACCESS_DENIED;
@@ -222,9 +221,9 @@ WERROR regkey_set_secdesc(REGISTRY_KEY *key,
  */
 bool reg_subkeys_need_update(REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys)
 {
-       if (key->hook && key->hook->ops && key->hook->ops->subkeys_need_update)
+       if (key->ops && key->ops->subkeys_need_update)
        {
-               return key->hook->ops->subkeys_need_update(subkeys);
+               return key->ops->subkeys_need_update(subkeys);
        }
 
        return false;
@@ -236,9 +235,9 @@ bool reg_subkeys_need_update(REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys)
  */
 bool reg_values_need_update(REGISTRY_KEY *key, REGVAL_CTR *values)
 {
-       if (key->hook && key->hook->ops && key->hook->ops->values_need_update)
+       if (key->ops && key->ops->values_need_update)
        {
-               return key->hook->ops->values_need_update(values);
+               return key->ops->values_need_update(values);
        }
 
        return false;
index ad245cb52e95bbb14d2bcf093e70b06fa8178f59..f171949e38df9492481357b70de85438c9dd7b5c 100644 (file)
@@ -86,7 +86,7 @@ bool init_registry( void )
        reghook_cache_init();
 
        for ( i=0; reg_hooks[i].keyname; i++ ) {
-               if ( !reghook_cache_add(&reg_hooks[i]) )
+               if (!reghook_cache_add(reg_hooks[i].keyname, reg_hooks[i].ops))
                        goto fail;
        }
 
index f76cc2f051f24be176e6d7b3e85ca334e3d25a4b..d1acd213c113ba0291751ffe3bfb644295fe3452 100644 (file)
@@ -71,7 +71,6 @@ bool registry_init_smbconf(void)
 {
        bool ret = false;
        int saved_errno = 0;
-       static REGISTRY_HOOK smbconf_reg_hook = {KEY_SMBCONF, &smbconf_reg_ops};
 
        DEBUG(10, ("registry_init_smbconf called\n"));
 
@@ -90,7 +89,7 @@ bool registry_init_smbconf(void)
                goto done;
        }
        reghook_cache_init();
-       if (!reghook_cache_add(&smbconf_reg_hook)) {
+       if (!reghook_cache_add(KEY_SMBCONF, &smbconf_reg_ops)) {
                DEBUG(1, ("Error adding smbconf reghooks to reghook cache.\n"));
                goto done;
        }
index e9839fe49894ed13c7af2650ce0db393f93b90a5..0fcfbb1e197608594076fc13a9216905dccafb30 100644 (file)
@@ -143,7 +143,7 @@ END {
     gotstart = 1;
   }
 
-  if( $0 ~ /^SAM_ACCT_INFO_NODE|^SMB_ACL_T|^ADS_MODLIST|^PyObject|^SORTED_TREE|^REGISTRY_HOOK|^REGISTRY_VALUE|^REGVAL_CTR|^DEVICEMODE|^PAC_DATA|^NET_USER_INFO_3|^smb_event_id_t/ ) {
+  if( $0 ~ /^SAM_ACCT_INFO_NODE|^SMB_ACL_T|^ADS_MODLIST|^PyObject|^SORTED_TREE|^REGISTRY_HOOK|^REGISTRY_OPS|^REGISTRY_VALUE|^REGVAL_CTR|^DEVICEMODE|^PAC_DATA|^NET_USER_INFO_3|^smb_event_id_t/ ) {
     gotstart = 1;
   }