]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
registry cachehook: change helper function keyname_to_path() to return WERROR.
authorMichael Adam <obnox@samba.org>
Sun, 13 Apr 2008 12:49:32 +0000 (14:49 +0200)
committerMichael Adam <obnox@samba.org>
Sun, 13 Apr 2008 13:33:47 +0000 (15:33 +0200)
Michael

source/registry/reg_cachehook.c

index f407f310f74b636bb295ea91af62fc6521622ef5..66b9ae6c4ea94c213b2bb4f5f3489b1164550e15 100644 (file)
 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)
+static WERROR keyname_to_path(TALLOC_CTX *mem_ctx, const char *keyname,
+                             char **path)
 {
-       char *path = NULL;
+       char *tmp_path = NULL;
 
-       if ((keyname == NULL)) {
-               return NULL;
+       if ((keyname == NULL) || (path == NULL)) {
+               return WERR_INVALID_PARAM;
        }
 
-       path = talloc_asprintf(mem_ctx, "\\%s", keyname);
-       if (path == NULL) {
+       tmp_path = talloc_asprintf(mem_ctx, "\\%s", keyname);
+       if (tmp_path == NULL) {
                DEBUG(0, ("talloc_asprintf failed!\n"));
-               return NULL;
+               return WERR_NOMEM;
        }
 
-       path = talloc_string_sub(mem_ctx, path, "\\", "/");
-       if (path == NULL) {
+       tmp_path = talloc_string_sub(mem_ctx, tmp_path, "\\", "/");
+       if (tmp_path == NULL) {
                DEBUG(0, ("talloc_string_sub_failed!\n"));
+               return WERR_NOMEM;
        }
 
-       return path;
+       *path = tmp_path;
+
+       return WERR_OK;
 }
 
 /**********************************************************************
@@ -80,16 +84,21 @@ bool reghook_cache_add(const char *keyname, REGISTRY_OPS *ops)
        WERROR werr;
        char *key = NULL;
 
-       key = keyname_to_path(talloc_tos(), keyname);
-
-       if ((key == NULL) || (ops == NULL)) {
+       if ((keyname == NULL) || (ops == NULL)) {
                return false;
        }
 
+       werr = keyname_to_path(talloc_tos(), keyname, &key);
+       if (!W_ERROR_IS_OK(werr)) {
+               goto done;
+       }
+
        DEBUG(10, ("reghook_cache_add: Adding ops %p for key [%s]\n",
                   (void *)ops, key));
 
        werr = pathtree_add(cache_tree, key, ops);
+
+done:
        TALLOC_FREE(key);
        return W_ERROR_IS_OK(werr);
 }
@@ -100,15 +109,19 @@ bool reghook_cache_add(const char *keyname, REGISTRY_OPS *ops)
 
 REGISTRY_OPS *reghook_cache_find(const char *keyname)
 {
-       char *key;
-       REGISTRY_OPS *ops;
-
-       key = keyname_to_path(talloc_tos(), keyname);
+       WERROR werr;
+       char *key = NULL;
+       REGISTRY_OPS *ops = NULL;
 
-       if (key == NULL) {
+       if (keyname == NULL) {
                return NULL;
        }
 
+       werr = keyname_to_path(talloc_tos(), keyname, &key);
+       if (!W_ERROR_IS_OK(werr)) {
+               goto done;
+       }
+
        DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key));
 
        ops = (REGISTRY_OPS *)pathtree_find(cache_tree, key);
@@ -116,6 +129,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));
 
+done:
        TALLOC_FREE(key);
 
        return ops;