registry: Improve error codes and update tests.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 18 Jan 2008 01:45:00 +0000 (02:45 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 18 Jan 2008 02:41:59 +0000 (03:41 +0100)
Rather than map the error returned by the registry to the correct error,
return the correct error in the first place.

Also deal with the fact that the right error code is now returned in a
couple of places.
(This used to be commit 1e31fcb8a097810a97e2d4bb1f243f1b34cc2415)

source4/lib/registry/dir.c
source4/lib/registry/ldb.c
source4/lib/registry/patchfile.c
source4/lib/registry/regf.c
source4/lib/registry/tests/hive.c
source4/lib/registry/tests/registry.c
source4/rpc_server/winreg/rpc_winreg.c

index a13e3753b7f0bac4010c0f351d6b76efdccd7a83..87d76e5eb75c66e96c0d4213e9bf5eebbb3b8f4b 100644 (file)
@@ -282,7 +282,7 @@ static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx,
        contents = file_load(path, &size, mem_ctx);
        talloc_free(path);
        if (contents == NULL)
-               return WERR_NOT_FOUND;
+               return WERR_BADFILE;
 
        if (type != NULL)
                *type = 4; /* FIXME */
index 884aed15790c9a4ae2bab75c271e73486979ca5b..17fac4abb24b20f1f9b0a4c3b7dbc8384cfbf0b8 100644 (file)
@@ -111,7 +111,6 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
        return msg;
 }
 
-
 static char *reg_ldb_escape(TALLOC_CTX *mem_ctx, const char *value)
 {
        struct ldb_val val;
@@ -303,7 +302,7 @@ static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
        }
 
        if (res->count == 0)
-               return WERR_NOT_FOUND;
+               return WERR_BADFILE;
 
        reg_ldb_unpack_value(mem_ctx, res->msgs[0], NULL, data_type, data);
 
@@ -410,8 +409,12 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
                                   talloc_strdup(mem_ctx, classname));
 
        ret = ldb_add(parentkd->ldb, msg);
+       if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
+               return WERR_ALREADY_EXISTS;
+       }
+
        if (ret != LDB_SUCCESS) {
-               DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(parentkd->ldb)));
+               DEBUG(1, ("ldb_add: %s\n", ldb_errstring(parentkd->ldb)));
                return WERR_FOOBAR;
        }
 
index b6ad7dfb1099c72eed4ccdbcd20f8ee80547e7f4..d859bc31347611f4284d065d3f17be799e410ad5 100644 (file)
@@ -132,10 +132,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
                                continue;
                } else {
                        t1 = NULL;
-                       error2 = WERR_DEST_NOT_FOUND;
+                       error2 = WERR_NOT_FOUND;
                }
 
-               if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+               if (!W_ERROR_EQUAL(error2, WERR_NOT_FOUND)) {
                        DEBUG(0, ("Error occured while getting subkey by name: %s\n",
                                win_errstr(error2)));
                        talloc_free(mem_ctx);
@@ -174,10 +174,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
                                                           name, &type2,
                                                           &contents2);
                } else
-                       error2 = WERR_DEST_NOT_FOUND;
+                       error2 = WERR_BADFILE;
 
                if(!W_ERROR_IS_OK(error2) &&
-                  !W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+                  !W_ERROR_EQUAL(error2, WERR_BADFILE)) {
                        DEBUG(0, ("Error occured while getting value by name: %s\n",
                                win_errstr(error2)));
                        talloc_free(mem_ctx);
@@ -210,7 +210,7 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
                if (W_ERROR_IS_OK(error2))
                        continue;
 
-               if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+               if (!W_ERROR_EQUAL(error2, WERR_BADFILE)) {
                        DEBUG(0, ("Error occured while getting value by name: %s\n",
                                win_errstr(error2)));
                        return error2;
index 9b126cc8084fe4d08748c6ce000ee5138dd3e224..475ec7bb5d4edf91df6492840631c65a1201f127 100644 (file)
@@ -575,7 +575,7 @@ static WERROR regf_get_value_by_name(TALLOC_CTX *mem_ctx,
        }
 
        if (W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS))
-               return WERR_NOT_FOUND;
+               return WERR_BADFILE;
 
        return error;
 }
index 22b4785222567f0b71238e32a4204f12e4930bfb..f72b7d6bf3c8c5b4fab056a8966878ccf8a7e15b 100644 (file)
@@ -174,7 +174,7 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data)
        torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
        error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value);
-       torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
+       torture_assert_werr_equal(tctx, error, WERR_BADFILE,
                                  "getting missing value");
 
        error = hive_key_set_value(subkey, "Answer", REG_DWORD,
@@ -215,7 +215,7 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data)
        torture_assert_werr_ok(tctx, error, "deleting value");
 
        error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value);
-       torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "getting value");
+       torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting value");
 
        error = hive_key_del_value(subkey, "Answer");
        torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
index 75fbe1cbea8bca48d2815d97b84e5387d132ac17..59e31f55dc15415b13c6d681080abe59b7ae1421 100644 (file)
@@ -195,15 +195,15 @@ static bool test_del_key(struct torture_context *tctx, void *_data)
        torture_assert_werr_ok(tctx, error,
                               "getting predefined key failed");
 
-       error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, &newkey);
+       error = reg_key_add_name(rctx, root, "Polen", NULL, NULL, &newkey);
 
        torture_assert_werr_ok(tctx, error, "Creating key return code");
        torture_assert(tctx, newkey != NULL, "Creating new key");
 
-       error = reg_key_del(root, "Hamburg");
+       error = reg_key_del(root, "Polen");
        torture_assert_werr_ok(tctx, error, "Delete key");
 
-       error = reg_key_del(root, "Hamburg");
+       error = reg_key_del(root, "Polen");
        torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
                                  "Delete missing key");
 
@@ -239,7 +239,7 @@ static bool test_flush_key(struct torture_context *tctx, void *_data)
        struct registry_key *root, *subkey;
        WERROR error;
 
-       if (!create_test_key(tctx, rctx, "Munchen", &root, &subkey))
+       if (!create_test_key(tctx, rctx, "Bremen", &root, &subkey))
                return false;
 
        error = reg_key_flush(subkey);
@@ -416,7 +416,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data)
 
        error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type,
                                          &data);
-       torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
+       torture_assert_werr_equal(tctx, error, WERR_BADFILE,
                                  "getting missing value");
 
        error = reg_val_set(subkey, __FUNCTION__, REG_DWORD,
@@ -447,12 +447,12 @@ static bool test_del_value(struct torture_context *tctx, void *_data)
        uint32_t value = 42;
        uint32_t type;
 
-       if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey))
+       if (!create_test_key(tctx, rctx, "Warschau", &root, &subkey))
                return false;
 
        error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type,
                                          &data);
-       torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
+       torture_assert_werr_equal(tctx, error, WERR_BADFILE,
                                  "getting missing value");
 
        error = reg_val_set(subkey, __FUNCTION__, REG_DWORD,
@@ -464,7 +464,7 @@ static bool test_del_value(struct torture_context *tctx, void *_data)
 
        error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__,
                                          &type, &data);
-       torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
+       torture_assert_werr_equal(tctx, error, WERR_BADFILE,
                                  "getting missing value");
 
        return true;
index 7eba428aef3360b5d78b3ac552b27d3e1392c280..681e3b918f870afc11f38ce47c81539fbd3ee8c0 100644 (file)
@@ -411,15 +411,7 @@ static WERROR dcesrv_winreg_QueryValue(struct dcesrv_call_state *dce_call,
                                           &value_type, &value_data);
 
        if (!W_ERROR_IS_OK(result)) {
-               /*
-                * Windows expects WERR_BADFILE when a particular value
-                * is not found.  If we receive WERR_NOT_FOUND from the lower
-                * layer calls, translate it here to return what is expected.
-                */
-               if (W_ERROR_EQUAL(result, WERR_NOT_FOUND))
-                       return WERR_BADFILE;
-               else
-                       return result;
+               return result;
        }
 
        /* Just asking for the size of the buffer */