summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-18 03:37:06 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-01-18 03:42:00 +0100
commit55ad09a01b31f2d2c9503f744b519e089f9f936b (patch)
treec2e97bda845c555b382c5c0bd2671601faf28dc0 /source4
parentb5ba4910120e5350e48927cc0f5f06742ee02eb8 (diff)
downloadsamba-55ad09a01b31f2d2c9503f744b519e089f9f936b.tar.gz
samba-55ad09a01b31f2d2c9503f744b519e089f9f936b.tar.bz2
samba-55ad09a01b31f2d2c9503f744b519e089f9f936b.zip
registry: Use correct return values.
(This used to be commit 98ebdbe52fd615ea62a3caa17acfe8bb31b8f85d)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/registry/dir.c4
-rw-r--r--source4/lib/registry/hive.c2
-rw-r--r--source4/lib/registry/ldb.c35
-rw-r--r--source4/lib/registry/patchfile.c14
-rw-r--r--source4/lib/registry/regf.c22
-rw-r--r--source4/lib/registry/tests/hive.c6
-rw-r--r--source4/lib/registry/tests/registry.c2
7 files changed, 53 insertions, 32 deletions
diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c
index 87d76e5eb7..27cae8c490 100644
--- a/source4/lib/registry/dir.c
+++ b/source4/lib/registry/dir.c
@@ -64,7 +64,7 @@ static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
if (rmdir(child) == 0)
ret = WERR_OK;
else if (errno == ENOENT)
- ret = WERR_NOT_FOUND;
+ ret = WERR_BADFILE;
else
ret = WERR_GENERAL_FAILURE;
@@ -339,7 +339,7 @@ static WERROR reg_dir_del_value (struct hive_key *key, const char *name)
if (unlink(path) < 0) {
talloc_free(path);
if (errno == ENOENT)
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
return WERR_GENERAL_FAILURE;
}
talloc_free(path);
diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c
index bbe510772c..5d56a30b3e 100644
--- a/source4/lib/registry/hive.c
+++ b/source4/lib/registry/hive.c
@@ -41,7 +41,7 @@ _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
fd = open(location, O_RDWR);
if (fd == -1) {
if (errno == ENOENT)
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
return WERR_BADFILE;
}
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index edfb1f2e59..262859f64b 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -337,7 +337,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
DEBUG(3, ("Key '%s' not found\n",
ldb_dn_get_linearized(ldap_path)));
talloc_free(res);
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
newkd = talloc_zero(mem_ctx, struct ldb_key_data);
@@ -400,7 +400,7 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
struct security_descriptor *sd,
struct hive_key **newkey)
{
- const struct ldb_key_data *parentkd = (const struct ldb_key_data *)parent;
+ struct ldb_key_data *parentkd = (const struct ldb_key_data *)parent;
struct ldb_message *msg;
struct ldb_key_data *newkd;
int ret;
@@ -433,6 +433,10 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
*newkey = (struct hive_key *)newkd;
+ /* reset cache */
+ talloc_free(parentkd->subkeys);
+ parentkd->subkeys = NULL;
+
return WERR_OK;
}
@@ -450,12 +454,16 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
talloc_free(mem_ctx);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else if (ret != LDB_SUCCESS) {
DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(parentkd->ldb)));
return WERR_FOOBAR;
}
+ /* reset cache */
+ talloc_free(parentkd->subkeys);
+ parentkd->subkeys = NULL;
+
return WERR_OK;
}
@@ -478,12 +486,16 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
talloc_free(childdn);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else if (ret != LDB_SUCCESS) {
DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb)));
return WERR_FOOBAR;
}
+ /* reset cache */
+ talloc_free(kd->values);
+ kd->values = NULL;
+
return WERR_OK;
}
@@ -521,6 +533,10 @@ static WERROR ldb_set_value(struct hive_key *parent,
return WERR_FOOBAR;
}
+ /* reset cache */
+ talloc_free(kd->values);
+ kd->values = NULL;
+
talloc_free(mem_ctx);
return WERR_OK;
}
@@ -537,17 +553,23 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
{
struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data);
+ if (kd->subkeys == NULL) {
+ W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
+ }
+
+ if (kd->values == NULL) {
+ W_ERROR_NOT_OK_RETURN(cache_values(kd));
+ }
+
/* FIXME */
if (classname != NULL)
*classname = NULL;
if (num_subkeys != NULL) {
- W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
*num_subkeys = kd->subkey_count;
}
if (num_values != NULL) {
- W_ERROR_NOT_OK_RETURN(cache_values(kd));
*num_values = kd->value_count;
}
@@ -557,7 +579,6 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
if (max_subkeynamelen != NULL) {
int i;
struct ldb_message_element *el;
- W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
*max_subkeynamelen = 0;
diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c
index d859bc3134..fa1367bbd2 100644
--- a/source4/lib/registry/patchfile.c
+++ b/source4/lib/registry/patchfile.c
@@ -82,11 +82,11 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
if (W_ERROR_IS_OK(error2))
continue;
} else {
- error2 = WERR_DEST_NOT_FOUND;
+ error2 = WERR_BADFILE;
t2 = NULL;
}
- if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+ if (!W_ERROR_EQUAL(error2, WERR_BADFILE)) {
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
win_errstr(error2)));
talloc_free(mem_ctx);
@@ -132,10 +132,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
continue;
} else {
t1 = NULL;
- error2 = WERR_NOT_FOUND;
+ error2 = WERR_BADFILE;
}
- if (!W_ERROR_EQUAL(error2, WERR_NOT_FOUND)) {
+ if (!W_ERROR_EQUAL(error2, WERR_BADFILE)) {
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
win_errstr(error2)));
talloc_free(mem_ctx);
@@ -238,14 +238,14 @@ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
struct registry_key *r1 = NULL, *r2 = NULL;
error = reg_get_predefined_key(ctx1, i, &r1);
if (!W_ERROR_IS_OK(error) &&
- !W_ERROR_EQUAL(error, WERR_NOT_FOUND)) {
+ !W_ERROR_EQUAL(error, WERR_BADFILE)) {
DEBUG(0, ("Unable to open hive %s for backend 1\n",
reg_get_predef_name(i)));
}
error = reg_get_predefined_key(ctx2, i, &r2);
if (!W_ERROR_IS_OK(error) &&
- !W_ERROR_EQUAL(error, WERR_NOT_FOUND)) {
+ !W_ERROR_EQUAL(error, WERR_BADFILE)) {
DEBUG(0, ("Unable to open hive %s for backend 2\n",
reg_get_predef_name(i)));
}
@@ -356,7 +356,7 @@ static WERROR reg_diff_apply_set_value(void *_ctx, const char *path,
/* Open key */
error = reg_open_key_abs(ctx, ctx, path, &tmp);
- if (W_ERROR_EQUAL(error, WERR_DEST_NOT_FOUND)) {
+ if (W_ERROR_EQUAL(error, WERR_BADFILE)) {
DEBUG(0, ("Error opening key '%s'\n", path));
return error;
}
diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c
index 475ec7bb5d..15b60745f0 100644
--- a/source4/lib/registry/regf.c
+++ b/source4/lib/registry/regf.c
@@ -870,7 +870,7 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
break;
}
if (key_off == 0)
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else if (!strncmp((char *)data.data, "lf", 2)) {
struct lf_block lf;
struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience);
@@ -905,7 +905,7 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
break;
}
if (key_off == 0)
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else if (!strncmp((char *)data.data, "lh", 2)) {
struct lh_block lh;
struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience);
@@ -942,7 +942,7 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
break;
}
if (key_off == 0)
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else if (!strncmp((char *)data.data, "ri", 2)) {
struct ri_block ri;
struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience);
@@ -1022,7 +1022,7 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
}
talloc_free(pull);
if (!key_off)
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else {
DEBUG(0, ("Unknown subkey list type.\n"));
return WERR_GENERAL_FAILURE;
@@ -1419,7 +1419,7 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
}
if (!found_offset) {
DEBUG(2, ("Subkey not found\n"));
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
li.key_count--;
@@ -1464,7 +1464,7 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
}
if (!found_offset) {
DEBUG(2, ("Subkey not found\n"));
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
lf.key_count--;
@@ -1510,7 +1510,7 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
}
if (!found_offset) {
DEBUG(0, ("Subkey not found\n"));
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
lh.key_count--;
@@ -1548,7 +1548,7 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
uint32_t i;
if (nk->values_offset == -1) {
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
values = hbin_get(regf, nk->values_offset);
@@ -1572,7 +1572,7 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
}
}
if (!found_offset) {
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
} else {
nk->num_values--;
values.length = (nk->num_values)*4;
@@ -1608,14 +1608,14 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
if (parent_nk->subkeys_offset == -1) {
DEBUG(4, ("Subkey list is empty, this key cannot contain subkeys.\n"));
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
/* Find the key */
if (!W_ERROR_IS_OK(regf_get_subkey_by_name(parent_nk, parent, name,
(struct hive_key **)&key))) {
DEBUG(2, ("Key '%s' not found\n", name));
- return WERR_NOT_FOUND;
+ return WERR_BADFILE;
}
if (key->nk->subkeys_offset != -1 ||
diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c
index f72b7d6bf3..4d27e83a74 100644
--- a/source4/lib/registry/tests/hive.c
+++ b/source4/lib/registry/tests/hive.c
@@ -31,7 +31,7 @@ static bool test_del_nonexistant_key(struct torture_context *tctx,
{
const struct hive_key *root = (const struct hive_key *)test_data;
WERROR error = hive_key_del(root, "bla");
- torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
+ torture_assert_werr_equal(tctx, error, WERR_BADFILE,
"invalid return code");
return true;
@@ -134,7 +134,7 @@ static bool test_del_key(struct torture_context *tctx, const void *test_data)
torture_assert_werr_ok(tctx, error, "reg_key_del");
error = hive_key_del(root, "Nested Key");
- torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "reg_key_del");
+ torture_assert_werr_equal(tctx, error, WERR_BADFILE, "reg_key_del");
return true;
}
@@ -218,7 +218,7 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data)
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,
+ torture_assert_werr_equal(tctx, error, WERR_BADFILE,
"deleting value");
return true;
diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c
index 06783e6a75..7d14b3a412 100644
--- a/source4/lib/registry/tests/registry.c
+++ b/source4/lib/registry/tests/registry.c
@@ -204,7 +204,7 @@ static bool test_del_key(struct torture_context *tctx, void *_data)
torture_assert_werr_ok(tctx, error, "Delete key");
error = reg_key_del(root, "Polen");
- torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
+ torture_assert_werr_equal(tctx, error, WERR_BADFILE,
"Delete missing key");
return true;