diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-01-18 02:45:00 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-01-18 03:41:59 +0100 |
commit | 85d60d2d091a2eb6bd4c73c87c94b10ee93167ee (patch) | |
tree | b0c1498f80bffbc7a7e0271f15a9847405ce2654 | |
parent | 4d8a60f617f941ff6481bcfbac73d7ed69e43daa (diff) | |
download | samba-85d60d2d091a2eb6bd4c73c87c94b10ee93167ee.tar.gz samba-85d60d2d091a2eb6bd4c73c87c94b10ee93167ee.tar.bz2 samba-85d60d2d091a2eb6bd4c73c87c94b10ee93167ee.zip |
registry: Improve error codes and update tests.
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)
-rw-r--r-- | source4/lib/registry/dir.c | 2 | ||||
-rw-r--r-- | source4/lib/registry/ldb.c | 9 | ||||
-rw-r--r-- | source4/lib/registry/patchfile.c | 10 | ||||
-rw-r--r-- | source4/lib/registry/regf.c | 2 | ||||
-rw-r--r-- | source4/lib/registry/tests/hive.c | 4 | ||||
-rw-r--r-- | source4/lib/registry/tests/registry.c | 16 | ||||
-rw-r--r-- | source4/rpc_server/winreg/rpc_winreg.c | 10 |
7 files changed, 24 insertions, 29 deletions
diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c index a13e3753b7..87d76e5eb7 100644 --- a/source4/lib/registry/dir.c +++ b/source4/lib/registry/dir.c @@ -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 */ diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 884aed1579..17fac4abb2 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -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; } diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c index b6ad7dfb10..d859bc3134 100644 --- a/source4/lib/registry/patchfile.c +++ b/source4/lib/registry/patchfile.c @@ -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; diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c index 9b126cc808..475ec7bb5d 100644 --- a/source4/lib/registry/regf.c +++ b/source4/lib/registry/regf.c @@ -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; } diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 22b4785222..f72b7d6bf3 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -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, diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 75fbe1cbea..59e31f55dc 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -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; diff --git a/source4/rpc_server/winreg/rpc_winreg.c b/source4/rpc_server/winreg/rpc_winreg.c index 7eba428aef..681e3b918f 100644 --- a/source4/rpc_server/winreg/rpc_winreg.c +++ b/source4/rpc_server/winreg/rpc_winreg.c @@ -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 */ |