mirror of
https://github.com/samba-team/samba.git
synced 2024-12-31 17:18:04 +03:00
registry: Use correct return values.
This commit is contained in:
parent
434e4857ce
commit
98ebdbe52f
@ -64,7 +64,7 @@ static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
|
|||||||
if (rmdir(child) == 0)
|
if (rmdir(child) == 0)
|
||||||
ret = WERR_OK;
|
ret = WERR_OK;
|
||||||
else if (errno == ENOENT)
|
else if (errno == ENOENT)
|
||||||
ret = WERR_NOT_FOUND;
|
ret = WERR_BADFILE;
|
||||||
else
|
else
|
||||||
ret = WERR_GENERAL_FAILURE;
|
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) {
|
if (unlink(path) < 0) {
|
||||||
talloc_free(path);
|
talloc_free(path);
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
return WERR_GENERAL_FAILURE;
|
return WERR_GENERAL_FAILURE;
|
||||||
}
|
}
|
||||||
talloc_free(path);
|
talloc_free(path);
|
||||||
|
@ -41,7 +41,7 @@ _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
|
|||||||
fd = open(location, O_RDWR);
|
fd = open(location, O_RDWR);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
return WERR_BADFILE;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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",
|
DEBUG(3, ("Key '%s' not found\n",
|
||||||
ldb_dn_get_linearized(ldap_path)));
|
ldb_dn_get_linearized(ldap_path)));
|
||||||
talloc_free(res);
|
talloc_free(res);
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
newkd = talloc_zero(mem_ctx, struct ldb_key_data);
|
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 security_descriptor *sd,
|
||||||
struct hive_key **newkey)
|
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_message *msg;
|
||||||
struct ldb_key_data *newkd;
|
struct ldb_key_data *newkd;
|
||||||
int ret;
|
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;
|
*newkey = (struct hive_key *)newkd;
|
||||||
|
|
||||||
|
/* reset cache */
|
||||||
|
talloc_free(parentkd->subkeys);
|
||||||
|
parentkd->subkeys = NULL;
|
||||||
|
|
||||||
return WERR_OK;
|
return WERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,12 +454,16 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
|
|||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
|
|
||||||
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
|
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else if (ret != LDB_SUCCESS) {
|
} else if (ret != LDB_SUCCESS) {
|
||||||
DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(parentkd->ldb)));
|
DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(parentkd->ldb)));
|
||||||
return WERR_FOOBAR;
|
return WERR_FOOBAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset cache */
|
||||||
|
talloc_free(parentkd->subkeys);
|
||||||
|
parentkd->subkeys = NULL;
|
||||||
|
|
||||||
return WERR_OK;
|
return WERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,12 +486,16 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
|
|||||||
talloc_free(childdn);
|
talloc_free(childdn);
|
||||||
|
|
||||||
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
|
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else if (ret != LDB_SUCCESS) {
|
} else if (ret != LDB_SUCCESS) {
|
||||||
DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb)));
|
DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb)));
|
||||||
return WERR_FOOBAR;
|
return WERR_FOOBAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset cache */
|
||||||
|
talloc_free(kd->values);
|
||||||
|
kd->values = NULL;
|
||||||
|
|
||||||
return WERR_OK;
|
return WERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,6 +533,10 @@ static WERROR ldb_set_value(struct hive_key *parent,
|
|||||||
return WERR_FOOBAR;
|
return WERR_FOOBAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset cache */
|
||||||
|
talloc_free(kd->values);
|
||||||
|
kd->values = NULL;
|
||||||
|
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
return WERR_OK;
|
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);
|
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 */
|
/* FIXME */
|
||||||
if (classname != NULL)
|
if (classname != NULL)
|
||||||
*classname = NULL;
|
*classname = NULL;
|
||||||
|
|
||||||
if (num_subkeys != NULL) {
|
if (num_subkeys != NULL) {
|
||||||
W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
|
|
||||||
*num_subkeys = kd->subkey_count;
|
*num_subkeys = kd->subkey_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_values != NULL) {
|
if (num_values != NULL) {
|
||||||
W_ERROR_NOT_OK_RETURN(cache_values(kd));
|
|
||||||
*num_values = kd->value_count;
|
*num_values = kd->value_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +579,6 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
|
|||||||
if (max_subkeynamelen != NULL) {
|
if (max_subkeynamelen != NULL) {
|
||||||
int i;
|
int i;
|
||||||
struct ldb_message_element *el;
|
struct ldb_message_element *el;
|
||||||
W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
|
|
||||||
|
|
||||||
*max_subkeynamelen = 0;
|
*max_subkeynamelen = 0;
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
|
|||||||
if (W_ERROR_IS_OK(error2))
|
if (W_ERROR_IS_OK(error2))
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
error2 = WERR_DEST_NOT_FOUND;
|
error2 = WERR_BADFILE;
|
||||||
t2 = NULL;
|
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",
|
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
|
||||||
win_errstr(error2)));
|
win_errstr(error2)));
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
@ -132,10 +132,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
t1 = NULL;
|
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",
|
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
|
||||||
win_errstr(error2)));
|
win_errstr(error2)));
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
@ -238,14 +238,14 @@ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
|
|||||||
struct registry_key *r1 = NULL, *r2 = NULL;
|
struct registry_key *r1 = NULL, *r2 = NULL;
|
||||||
error = reg_get_predefined_key(ctx1, i, &r1);
|
error = reg_get_predefined_key(ctx1, i, &r1);
|
||||||
if (!W_ERROR_IS_OK(error) &&
|
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",
|
DEBUG(0, ("Unable to open hive %s for backend 1\n",
|
||||||
reg_get_predef_name(i)));
|
reg_get_predef_name(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
error = reg_get_predefined_key(ctx2, i, &r2);
|
error = reg_get_predefined_key(ctx2, i, &r2);
|
||||||
if (!W_ERROR_IS_OK(error) &&
|
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",
|
DEBUG(0, ("Unable to open hive %s for backend 2\n",
|
||||||
reg_get_predef_name(i)));
|
reg_get_predef_name(i)));
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ static WERROR reg_diff_apply_set_value(void *_ctx, const char *path,
|
|||||||
/* Open key */
|
/* Open key */
|
||||||
error = reg_open_key_abs(ctx, ctx, path, &tmp);
|
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));
|
DEBUG(0, ("Error opening key '%s'\n", path));
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -870,7 +870,7 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (key_off == 0)
|
if (key_off == 0)
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else if (!strncmp((char *)data.data, "lf", 2)) {
|
} else if (!strncmp((char *)data.data, "lf", 2)) {
|
||||||
struct lf_block lf;
|
struct lf_block lf;
|
||||||
struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if (key_off == 0)
|
if (key_off == 0)
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else if (!strncmp((char *)data.data, "lh", 2)) {
|
} else if (!strncmp((char *)data.data, "lh", 2)) {
|
||||||
struct lh_block lh;
|
struct lh_block lh;
|
||||||
struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if (key_off == 0)
|
if (key_off == 0)
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else if (!strncmp((char *)data.data, "ri", 2)) {
|
} else if (!strncmp((char *)data.data, "ri", 2)) {
|
||||||
struct ri_block ri;
|
struct ri_block ri;
|
||||||
struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience);
|
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);
|
talloc_free(pull);
|
||||||
if (!key_off)
|
if (!key_off)
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else {
|
} else {
|
||||||
DEBUG(0, ("Unknown subkey list type.\n"));
|
DEBUG(0, ("Unknown subkey list type.\n"));
|
||||||
return WERR_GENERAL_FAILURE;
|
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) {
|
if (!found_offset) {
|
||||||
DEBUG(2, ("Subkey not found\n"));
|
DEBUG(2, ("Subkey not found\n"));
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
li.key_count--;
|
li.key_count--;
|
||||||
|
|
||||||
@ -1464,7 +1464,7 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
|
|||||||
}
|
}
|
||||||
if (!found_offset) {
|
if (!found_offset) {
|
||||||
DEBUG(2, ("Subkey not found\n"));
|
DEBUG(2, ("Subkey not found\n"));
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
lf.key_count--;
|
lf.key_count--;
|
||||||
|
|
||||||
@ -1510,7 +1510,7 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
|
|||||||
}
|
}
|
||||||
if (!found_offset) {
|
if (!found_offset) {
|
||||||
DEBUG(0, ("Subkey not found\n"));
|
DEBUG(0, ("Subkey not found\n"));
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
lh.key_count--;
|
lh.key_count--;
|
||||||
|
|
||||||
@ -1548,7 +1548,7 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (nk->values_offset == -1) {
|
if (nk->values_offset == -1) {
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
values = hbin_get(regf, nk->values_offset);
|
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) {
|
if (!found_offset) {
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
} else {
|
} else {
|
||||||
nk->num_values--;
|
nk->num_values--;
|
||||||
values.length = (nk->num_values)*4;
|
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) {
|
if (parent_nk->subkeys_offset == -1) {
|
||||||
DEBUG(4, ("Subkey list is empty, this key cannot contain subkeys.\n"));
|
DEBUG(4, ("Subkey list is empty, this key cannot contain subkeys.\n"));
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the key */
|
/* Find the key */
|
||||||
if (!W_ERROR_IS_OK(regf_get_subkey_by_name(parent_nk, parent, name,
|
if (!W_ERROR_IS_OK(regf_get_subkey_by_name(parent_nk, parent, name,
|
||||||
(struct hive_key **)&key))) {
|
(struct hive_key **)&key))) {
|
||||||
DEBUG(2, ("Key '%s' not found\n", name));
|
DEBUG(2, ("Key '%s' not found\n", name));
|
||||||
return WERR_NOT_FOUND;
|
return WERR_BADFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key->nk->subkeys_offset != -1 ||
|
if (key->nk->subkeys_offset != -1 ||
|
||||||
|
@ -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;
|
const struct hive_key *root = (const struct hive_key *)test_data;
|
||||||
WERROR error = hive_key_del(root, "bla");
|
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");
|
"invalid return code");
|
||||||
|
|
||||||
return true;
|
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");
|
torture_assert_werr_ok(tctx, error, "reg_key_del");
|
||||||
|
|
||||||
error = hive_key_del(root, "Nested Key");
|
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;
|
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");
|
torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting value");
|
||||||
|
|
||||||
error = hive_key_del_value(subkey, "Answer");
|
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");
|
"deleting value");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -204,7 +204,7 @@ static bool test_del_key(struct torture_context *tctx, void *_data)
|
|||||||
torture_assert_werr_ok(tctx, error, "Delete key");
|
torture_assert_werr_ok(tctx, error, "Delete key");
|
||||||
|
|
||||||
error = reg_key_del(root, "Polen");
|
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");
|
"Delete missing key");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user