registry: Use correct return values.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 18 Jan 2008 02:37:06 +0000 (03:37 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 18 Jan 2008 02:42:00 +0000 (03:42 +0100)
source/lib/registry/dir.c
source/lib/registry/hive.c
source/lib/registry/ldb.c
source/lib/registry/patchfile.c
source/lib/registry/regf.c
source/lib/registry/tests/hive.c
source/lib/registry/tests/registry.c

index 87d76e5eb75c66e96c0d4213e9bf5eebbb3b8f4b..27cae8c49062ed9ba1ba670f47f3bc594b422763 100644 (file)
@@ -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);
index bbe510772cc9a714e90b631ef81229f261fc5ce7..5d56a30b3e14edaacfcaf4c80801cae9adaca9df 100644 (file)
@@ -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;
        }
 
index edfb1f2e593aa6759bd443a6165f91c761444b52..262859f64b4302395d04cf41f0d0e47b27a4cde1 100644 (file)
@@ -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;
 
index d859bc31347611f4284d065d3f17be799e410ad5..fa1367bbd2cd38f37a8c359e254ec6e84d747269 100644 (file)
@@ -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;
        }
index 475ec7bb5d4edf91df6492840631c65a1201f127..15b60745f05612dea2b5d9ebdd06b6d161743d03 100644 (file)
@@ -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 ||
index f72b7d6bf3c8c5b4fab056a8966878ccf8a7e15b..4d27e83a74747375a245906f48b7e369318f5ad4 100644 (file)
@@ -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;
index 06783e6a75676afec31bdac0ce0fcacaf769c01f..7d14b3a4121d4c5d5246ed98daf094d537960d2b 100644 (file)
@@ -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;