r183: More bugfixes
authorJelmer Vernooij <jelmer@samba.org>
Mon, 12 Apr 2004 18:46:48 +0000 (18:46 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:51:15 +0000 (12:51 -0500)
(This used to be commit 88911bbcca574adbf6ea4f0759a68f2961b05d6b)

source4/lib/registry/common/reg_interface.c
source4/lib/registry/tools/regshell.c

index 696a504d878c13489002bd1b4f2a8e8750d0d682..5753de1bcae591986210dfc434742a2b27e29486 100644 (file)
@@ -124,8 +124,7 @@ WERROR reg_open(const char *backend, const char *location, const char *credentia
 WERROR reg_open_key(REG_KEY *parent, const char *name, REG_KEY **result)
 {
        char *fullname;
-       WERROR status;
-       REG_KEY *ret = NULL;
+       WERROR error;
        TALLOC_CTX *mem_ctx;
 
        if(!parent) {
@@ -143,10 +142,10 @@ WERROR reg_open_key(REG_KEY *parent, const char *name, REG_KEY **result)
 
                while(curbegin && *curbegin) {
                        if(curend)*curend = '\0';
-                       status = reg_key_get_subkey_by_name(curkey, curbegin, result);
-                       if(!NT_STATUS_IS_OK(status)) {
+                       error = reg_key_get_subkey_by_name(curkey, curbegin, result);
+                       if(!W_ERROR_IS_OK(error)) {
                                SAFE_FREE(orig);
-                               return status;
+                               return error;
                        }
                        if(!curend) break;
                        curbegin = curend + 1;
@@ -168,21 +167,19 @@ WERROR reg_open_key(REG_KEY *parent, const char *name, REG_KEY **result)
                return WERR_NOT_SUPPORTED;
        }
 
-       status = parent->handle->functions->open_key(parent->handle, fullname, result);
+       error = parent->handle->functions->open_key(parent->handle, fullname, result);
 
-       if(!NT_STATUS_IS_OK(status)) {
+       if(!W_ERROR_IS_OK(error)) {
                talloc_destroy(mem_ctx);
-               return status;
+               return error;
        }
                
-       ret->handle = parent->handle;
-       ret->path = fullname;
-       talloc_steal(mem_ctx, ret->mem_ctx, fullname);
+       (*result)->handle = parent->handle;
+       (*result)->path = fullname;
+       talloc_steal(mem_ctx, (*result)->mem_ctx, fullname);
 
        talloc_destroy(mem_ctx);
 
-       *result = ret;
-
        return WERR_OK;
 }
 
@@ -294,32 +291,29 @@ WERROR reg_key_get_subkey_by_index(REG_KEY *key, int idx, REG_KEY **subkey)
 WERROR reg_key_get_subkey_by_name(REG_KEY *key, const char *name, REG_KEY **subkey)
 {
        int i;
-       REG_KEY *ret = NULL;
        WERROR error = WERR_OK;
 
        if(!key) return WERR_INVALID_PARAM;
 
        if(key->handle->functions->get_subkey_by_name) {
                error = key->handle->functions->get_subkey_by_name(key,name,subkey);
-       } else {
+       } else if(key->handle->functions->get_subkey_by_index || key->handle->functions->fetch_subkeys) {
                for(i = 0; W_ERROR_IS_OK(error); i++) {
                        error = reg_key_get_subkey_by_index(key, i, subkey);
                        if(W_ERROR_IS_OK(error) && !strcmp((*subkey)->name, name)) {
-                               break;
+                               return error;
                        }
                        reg_key_free(*subkey);
                }
-
+       } else {
+               return WERR_NOT_SUPPORTED;
        }
 
-       if(!W_ERROR_IS_OK(error) && W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS))
-               return error;
+       if(!W_ERROR_IS_OK(error)) return error;
 
-       ret->path = talloc_asprintf(ret->mem_ctx, "%s%s%s", key->path, key->path[strlen(key->path)-1] == '\\'?"":"\\", ret->name);
-       ret->handle = key->handle;
+       (*subkey)->path = talloc_asprintf((*subkey)->mem_ctx, "%s%s%s", key->path, key->path[strlen(key->path)-1] == '\\'?"":"\\", (*subkey)->name);
+       (*subkey)->handle = key->handle;
 
-       *subkey = ret;
-               
        return WERR_OK; 
 }
 
index d60ca1ff46a24067011a9919bfba381e9ae097db..18399b5bda5fea64276e9ff84ce298f6833383e4 100644 (file)
@@ -39,18 +39,17 @@ static REG_KEY *cmd_set(REG_KEY *cur, int argc, char **argv)
 
 static REG_KEY *cmd_ck(REG_KEY *cur, int argc, char **argv)
 { 
-       REG_KEY *new;
+       REG_KEY *new = NULL;
        WERROR error;
        if(argc < 2) {
                new = cur;
        } else {
                error = reg_open_key(cur, argv[1], &new);
                if(!W_ERROR_IS_OK(error)) {
-                       DEBUG(0, ("Error opening specified key\n"));
+                       DEBUG(0, ("Error opening specified key: %s\n", win_errstr(error)));
+                       return NULL;
                }
-       }
-       
-       if(!new) new = cur;
+       } 
 
        printf("Current path is: %s\n", reg_key_get_path(new));