diff options
author | Michael Adam <obnox@samba.org> | 2008-04-13 01:40:45 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2008-04-13 01:43:42 +0200 |
commit | 227904434a1ce46a9d314c20c80fb82fafd4684a (patch) | |
tree | c1316d8e90e8d7490767be1ad6f854dca2fc299d /source3 | |
parent | bbca983507bf78f63713719e501ccad64f9a2573 (diff) | |
download | samba-227904434a1ce46a9d314c20c80fb82fafd4684a.tar.gz samba-227904434a1ce46a9d314c20c80fb82fafd4684a.tar.bz2 samba-227904434a1ce46a9d314c20c80fb82fafd4684a.zip |
registry cachehook: refactor normalization of keyname out.
Michael
(This used to be commit acb9c98dff7dac5e0688a04dbf6d63a7a7f67fd2)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/registry/reg_cachehook.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c index 19943d51fa..bb190411ee 100644 --- a/source3/registry/reg_cachehook.c +++ b/source3/registry/reg_cachehook.c @@ -28,6 +28,22 @@ static SORTED_TREE *cache_tree = NULL; extern REGISTRY_OPS regdb_ops; /* these are the default */ +static char *keyname_to_path(TALLOC_CTX *mem_ctx, const char *keyname) +{ + char *path = NULL; + + if ((keyname == NULL)) { + return NULL; + } + + path = talloc_asprintf(mem_ctx, "\\%s", keyname); + if (path == NULL) { + return NULL; + } + path = talloc_string_sub(mem_ctx, path, "\\", "/"); + return path; +} + /********************************************************************** Initialize the cache tree if it has not been initialized yet. *********************************************************************/ @@ -53,19 +69,11 @@ bool reghook_cache_init( void ) bool reghook_cache_add(const char *keyname, REGISTRY_OPS *ops) { - TALLOC_CTX *ctx = talloc_tos(); char *key = NULL; - if ((keyname == NULL) || (ops == NULL)) { - return false; - } + key = keyname_to_path(talloc_tos(), keyname); - key = talloc_asprintf(ctx, "\\%s", keyname); - if (!key) { - return false; - } - key = talloc_string_sub(ctx, key, "\\", "/"); - if (!key) { + if ((key == NULL) || (ops == NULL)) { return false; } @@ -82,28 +90,14 @@ bool reghook_cache_add(const char *keyname, REGISTRY_OPS *ops) REGISTRY_OPS *reghook_cache_find(const char *keyname) { char *key; - int len; REGISTRY_OPS *ops; - - if ( !keyname ) - return NULL; - - /* prepend the string with a '\' character */ - - len = strlen( keyname ); - if ( !(key = (char *)SMB_MALLOC( len + 2 )) ) { - DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n", - keyname)); + + key = keyname_to_path(talloc_tos(), keyname); + + if (key == NULL) { return NULL; } - *key = '\\'; - strncpy( key+1, keyname, len+1); - - /* swap to a form understood by the SORTED_TREE */ - - string_sub( key, "\\", "/", 0 ); - DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key)); ops = (REGISTRY_OPS *)pathtree_find(cache_tree, key); @@ -111,7 +105,7 @@ REGISTRY_OPS *reghook_cache_find(const char *keyname) DEBUG(10, ("reghook_cache_find: found ops %p for key [%s]\n", ops ? (void *)ops : 0, key)); - SAFE_FREE( key ); + TALLOC_FREE(key); return ops; } |