summaryrefslogtreecommitdiff
path: root/source4/lib/registry
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2010-03-22 19:18:56 +0100
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2010-03-22 22:31:00 +0100
commit43170dafbcbe7464bce9b4c6d76532d7d0bf5b9a (patch)
treec10af94c0148af2ad934d1804c7a2beb406cc641 /source4/lib/registry
parent64f51380aad484d020093c926512ec79a35bcb93 (diff)
downloadsamba-43170dafbcbe7464bce9b4c6d76532d7d0bf5b9a.tar.gz
samba-43170dafbcbe7464bce9b4c6d76532d7d0bf5b9a.tar.bz2
samba-43170dafbcbe7464bce9b4c6d76532d7d0bf5b9a.zip
s4:registry - adaptions for "add memory contexts for delete value/key functions"
Diffstat (limited to 'source4/lib/registry')
-rw-r--r--source4/lib/registry/dir.c8
-rw-r--r--source4/lib/registry/hive.c10
-rw-r--r--source4/lib/registry/interface.c10
-rw-r--r--source4/lib/registry/ldb.c29
-rw-r--r--source4/lib/registry/local.c10
-rw-r--r--source4/lib/registry/patchfile.c4
-rw-r--r--source4/lib/registry/pyregistry.c6
-rw-r--r--source4/lib/registry/regf.c10
-rw-r--r--source4/lib/registry/rpc.c6
-rw-r--r--source4/lib/registry/tests/hive.c14
-rw-r--r--source4/lib/registry/tests/registry.c6
-rw-r--r--source4/lib/registry/tools/regshell.c4
-rw-r--r--source4/lib/registry/util.c2
13 files changed, 57 insertions, 62 deletions
diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c
index 4380dce74e..8fcf27b66e 100644
--- a/source4/lib/registry/dir.c
+++ b/source4/lib/registry/dir.c
@@ -108,7 +108,8 @@ static WERROR reg_dir_delete_recursive(const char *name)
return WERR_GENERAL_FAILURE;
}
-static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
+static WERROR reg_dir_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *k,
+ const char *name)
{
struct dir_key *dk = talloc_get_type(k, struct dir_key);
char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);
@@ -380,10 +381,11 @@ static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx,
}
-static WERROR reg_dir_del_value (struct hive_key *key, const char *name)
+static WERROR reg_dir_del_value(TALLOC_CTX *mem_ctx,
+ struct hive_key *key, const char *name)
{
const struct dir_key *dk = talloc_get_type(key, struct dir_key);
- char *path = talloc_asprintf(key, "%s/%s", dk->path, name);
+ char *path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name);
if (unlink(path) < 0) {
talloc_free(path);
if (errno == ENOENT)
diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c
index 8bf7c9f8d1..c9cb247071 100644
--- a/source4/lib/registry/hive.c
+++ b/source4/lib/registry/hive.c
@@ -91,9 +91,10 @@ _PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx,
desc, key);
}
-_PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name)
+_PUBLIC_ WERROR hive_key_del(TALLOC_CTX *mem_ctx, const struct hive_key *key,
+ const char *name)
{
- return key->ops->del_key(key, name);
+ return key->ops->del_key(mem_ctx, key, name);
}
_PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
@@ -163,12 +164,13 @@ WERROR hive_set_sec_desc(struct hive_key *key,
return key->ops->set_sec_desc(key, security);
}
-WERROR hive_key_del_value(struct hive_key *key, const char *name)
+WERROR hive_key_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
+ const char *name)
{
if (key->ops->delete_value == NULL)
return WERR_NOT_SUPPORTED;
- return key->ops->delete_value(key, name);
+ return key->ops->delete_value(mem_ctx, key, name);
}
WERROR hive_key_flush(struct hive_key *key)
diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c
index 5d24f6da74..c5d5ce8d5f 100644
--- a/source4/lib/registry/interface.c
+++ b/source4/lib/registry/interface.c
@@ -185,7 +185,8 @@ _PUBLIC_ WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
/**
* Delete a key.
*/
-_PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name)
+_PUBLIC_ WERROR reg_key_del(TALLOC_CTX *mem_ctx, struct registry_key *parent,
+ const char *name)
{
if (parent == NULL)
return WERR_INVALID_PARAM;
@@ -193,7 +194,7 @@ _PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name)
if (parent->context->ops->delete_key == NULL)
return WERR_NOT_SUPPORTED;
- return parent->context->ops->delete_key(parent, name);
+ return parent->context->ops->delete_key(mem_ctx, parent, name);
}
/**
@@ -257,7 +258,8 @@ _PUBLIC_ WERROR reg_get_sec_desc(TALLOC_CTX *ctx,
/**
* Delete a value.
*/
-_PUBLIC_ WERROR reg_del_value(struct registry_key *key, const char *valname)
+_PUBLIC_ WERROR reg_del_value(TALLOC_CTX *mem_ctx, struct registry_key *key,
+ const char *valname)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@@ -265,7 +267,7 @@ _PUBLIC_ WERROR reg_del_value(struct registry_key *key, const char *valname)
if (key->context->ops->delete_value == NULL)
return WERR_NOT_SUPPORTED;
- return key->context->ops->delete_value(key, valname);
+ return key->context->ops->delete_value(mem_ctx, key, valname);
}
/**
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 7ceaa5b6e5..8310b6fd85 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -712,18 +712,16 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
return WERR_OK;
}
-static WERROR ldb_del_value (struct hive_key *key, const char *child)
+static WERROR ldb_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
+ const char *child)
{
int ret;
struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data);
- TALLOC_CTX *mem_ctx;
struct ldb_message *msg;
struct ldb_dn *childdn;
if ((child == NULL) || (child[0] == '\0')) {
/* default value */
- mem_ctx = talloc_init("ldb_del_value");
-
msg = talloc_zero(mem_ctx, struct ldb_message);
W_ERROR_HAVE_NO_MEMORY(msg);
msg->dn = ldb_dn_copy(msg, kd->dn);
@@ -734,11 +732,8 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
ret = ldb_modify(kd->ldb, msg);
if (ret != LDB_SUCCESS) {
DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb)));
- talloc_free(mem_ctx);
return WERR_FOOBAR;
}
-
- talloc_free(mem_ctx);
} else {
/* normal value */
childdn = ldb_dn_copy(kd->ldb, kd->dn);
@@ -768,13 +763,13 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
return WERR_OK;
}
-static WERROR ldb_del_key(const struct hive_key *key, const char *name)
+static WERROR ldb_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *key,
+ const char *name)
{
unsigned int i;
int ret;
struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data);
struct ldb_dn *ldap_path;
- TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key");
struct ldb_context *c = parentkd->ldb;
struct ldb_result *res_keys;
struct ldb_result *res_vals;
@@ -784,7 +779,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
/* Verify key exists by opening it */
werr = ldb_open_key(mem_ctx, key, name, &hk);
if (!W_ERROR_IS_OK(werr)) {
- talloc_free(mem_ctx);
return werr;
}
@@ -798,7 +792,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting subkeys for '%s': %s\n",
ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
- talloc_free(mem_ctx);
return WERR_FOOBAR;
}
@@ -809,7 +802,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting values for '%s': %s\n",
ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
- talloc_free(mem_ctx);
return WERR_FOOBAR;
}
@@ -818,7 +810,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
if (ret != LDB_SUCCESS) {
DEBUG(0, ("ldb_transaction_start: %s\n", ldb_errstring(c)));
- talloc_free(mem_ctx);
return WERR_FOOBAR;
}
@@ -827,12 +818,12 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
/* Delete any subkeys */
for (i = 0; i < res_keys->count; i++)
{
- werr = ldb_del_key(hk, ldb_msg_find_attr_as_string(
+ werr = ldb_del_key(mem_ctx, hk,
+ ldb_msg_find_attr_as_string(
res_keys->msgs[i],
"key", NULL));
if (!W_ERROR_IS_OK(werr)) {
ret = ldb_transaction_cancel(c);
- talloc_free(mem_ctx);
return werr;
}
}
@@ -840,12 +831,12 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
/* Delete any values */
for (i = 0; i < res_vals->count; i++)
{
- werr = ldb_del_value(hk, ldb_msg_find_attr_as_string(
+ werr = ldb_del_value(mem_ctx, hk,
+ ldb_msg_find_attr_as_string(
res_vals->msgs[i],
"value", NULL));
if (!W_ERROR_IS_OK(werr)) {
ret = ldb_transaction_cancel(c);
- talloc_free(mem_ctx);
return werr;
}
}
@@ -858,7 +849,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
{
DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(c)));
ret = ldb_transaction_cancel(c);
- talloc_free(mem_ctx);
return WERR_FOOBAR;
}
@@ -869,12 +859,9 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name)
{
DEBUG(0, ("ldb_transaction_commit: %s\n", ldb_errstring(c)));
ret = ldb_transaction_cancel(c);
- talloc_free(mem_ctx);
return WERR_FOOBAR;
}
- talloc_free(mem_ctx);
-
/* reset cache */
talloc_free(parentkd->subkeys);
parentkd->subkeys = NULL;
diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c
index 458239b9e0..7ab35b0096 100644
--- a/source4/lib/registry/local.c
+++ b/source4/lib/registry/local.c
@@ -236,18 +236,20 @@ static WERROR local_enum_value(TALLOC_CTX *mem_ctx,
name, type, data);
}
-static WERROR local_delete_key(struct registry_key *key, const char *name)
+static WERROR local_delete_key(TALLOC_CTX *mem_ctx, struct registry_key *key,
+ const char *name)
{
const struct local_key *local = (const struct local_key *)key;
- return hive_key_del(local->hive_key, name);
+ return hive_key_del(mem_ctx, local->hive_key, name);
}
-static WERROR local_delete_value(struct registry_key *key, const char *name)
+static WERROR local_delete_value(TALLOC_CTX *mem_ctx, struct registry_key *key,
+ const char *name)
{
const struct local_key *local = (const struct local_key *)key;
- return hive_key_del_value(local->hive_key, name);
+ return hive_key_del_value(mem_ctx, local->hive_key, name);
}
static WERROR local_flush_key(struct registry_key *key)
diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c
index 2932910ea0..d91516cdc9 100644
--- a/source4/lib/registry/patchfile.c
+++ b/source4/lib/registry/patchfile.c
@@ -483,7 +483,7 @@ static WERROR reg_diff_apply_del_value(void *_ctx, const char *key_name,
return error;
}
- error = reg_del_value(tmp, value_name);
+ error = reg_del_value(ctx, tmp, value_name);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error deleting value '%s'\n", value_name));
return error;
@@ -513,7 +513,7 @@ static WERROR reg_diff_apply_del_all_values(void *_ctx, const char *key_name)
while (W_ERROR_IS_OK(reg_key_get_value_by_index(
ctx, key, 0, &value_name, NULL, NULL))) {
- error = reg_del_value(key, value_name);
+ error = reg_del_value(ctx, key, value_name);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error deleting value '%s'\n", value_name));
return error;
diff --git a/source4/lib/registry/pyregistry.c b/source4/lib/registry/pyregistry.c
index a2042f4d68..4c42dad6bf 100644
--- a/source4/lib/registry/pyregistry.c
+++ b/source4/lib/registry/pyregistry.c
@@ -172,7 +172,7 @@ static PyObject *py_hive_key_del(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
- result = hive_key_del(key, name);
+ result = hive_key_del(NULL, key, name);
PyErr_WERROR_IS_ERR_RAISE(result);
@@ -199,7 +199,7 @@ static PyObject *py_hive_key_del_value(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
- result = hive_key_del_value(key, name);
+ result = hive_key_del_value(NULL, key, name);
PyErr_WERROR_IS_ERR_RAISE(result);
@@ -220,7 +220,7 @@ static PyObject *py_hive_key_set_value(PyObject *self, PyObject *args)
if (value.data != NULL)
result = hive_key_set_value(key, name, type, value);
else
- result = hive_key_del_value(key, name);
+ result = hive_key_del_value(NULL, key, name);
PyErr_WERROR_IS_ERR_RAISE(result);
diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c
index ddb917d15a..52adb3ae98 100644
--- a/source4/lib/registry/regf.c
+++ b/source4/lib/registry/regf.c
@@ -1542,7 +1542,8 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
return WERR_OK;
}
-static WERROR regf_del_value (struct hive_key *key, const char *name)
+static WERROR regf_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
+ const char *name)
{
struct regf_key_data *private_data = (struct regf_key_data *)key;
struct regf_data *regf = private_data->hive;
@@ -1600,7 +1601,8 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
}
-static WERROR regf_del_key(const struct hive_key *parent, const char *name)
+static WERROR regf_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
+ const char *name)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)parent;
@@ -1639,7 +1641,7 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
}
/* Delete subkey. */
- error = regf_del_key(sk, sk_name);
+ error = regf_del_key(NULL, sk, sk_name);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Can't delete key '%s'.\n", sk_name));
return error;
@@ -1665,7 +1667,7 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
}
/* Delete value. */
- error = regf_del_value(sk, val_name);
+ error = regf_del_value(NULL, sk, val_name);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Can't delete value '%s'.\n", val_name));
return error;
diff --git a/source4/lib/registry/rpc.c b/source4/lib/registry/rpc.c
index ada9a55c9e..d7b853bb92 100644
--- a/source4/lib/registry/rpc.c
+++ b/source4/lib/registry/rpc.c
@@ -399,12 +399,12 @@ static WERROR rpc_query_key(TALLOC_CTX *mem_ctx, const struct registry_key *k)
return r.out.result;
}
-static WERROR rpc_del_key(struct registry_key *parent, const char *name)
+static WERROR rpc_del_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
+ const char *name)
{
NTSTATUS status;
struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
struct winreg_DeleteKey r;
- TALLOC_CTX *mem_ctx = talloc_init("del_key");
ZERO_STRUCT(r);
r.in.handle = &mykeydata->pol;
@@ -412,8 +412,6 @@ static WERROR rpc_del_key(struct registry_key *parent, const char *name)
status = dcerpc_winreg_DeleteKey_r(mykeydata->binding_handle, mem_ctx, &r);
- talloc_free(mem_ctx);
-
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("DeleteKey failed - %s\n", nt_errstr(status)));
return ntstatus_to_werror(status);
diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c
index edc97c2468..c09051d27a 100644
--- a/source4/lib/registry/tests/hive.c
+++ b/source4/lib/registry/tests/hive.c
@@ -32,7 +32,7 @@ static bool test_del_nonexistant_key(struct torture_context *tctx,
const void *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(tctx, root, "bla");
torture_assert_werr_equal(tctx, error, WERR_BADFILE,
"invalid return code");
@@ -107,7 +107,7 @@ static bool test_add_subkey(struct torture_context *tctx,
NULL, &subkey);
torture_assert_werr_ok(tctx, error, "hive_key_add_name");
- error = hive_key_del(root, "Nested Key");
+ error = hive_key_del(mem_ctx, root, "Nested Key");
torture_assert_werr_ok(tctx, error, "reg_key_del");
return true;
@@ -140,7 +140,7 @@ static bool test_del_recursive(struct torture_context *tctx,
torture_assert_werr_ok(tctx, error, "hive_key_set_value");
/* Deleting "Parent Key" will also delete "Child Key" and the value. */
- error = hive_key_del(root, "Parent Key");
+ error = hive_key_del(mem_ctx, root, "Parent Key");
torture_assert_werr_ok(tctx, error, "hive_key_del");
return true;
@@ -166,10 +166,10 @@ static bool test_del_key(struct torture_context *tctx, const void *test_data)
NULL, &subkey);
torture_assert_werr_ok(tctx, error, "hive_key_add_name");
- error = hive_key_del(root, "Nested Key");
+ error = hive_key_del(mem_ctx, root, "Nested Key");
torture_assert_werr_ok(tctx, error, "reg_key_del");
- error = hive_key_del(root, "Nested Key");
+ error = hive_key_del(mem_ctx, root, "Nested Key");
torture_assert_werr_equal(tctx, error, WERR_BADFILE, "reg_key_del");
return true;
@@ -252,13 +252,13 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data)
data_blob_talloc(mem_ctx, data, sizeof(data)));
torture_assert_werr_ok(tctx, error, "hive_key_set_value");
- error = hive_key_del_value(subkey, "Answer");
+ error = hive_key_del_value(mem_ctx, subkey, "Answer");
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_BADFILE, "getting value");
- error = hive_key_del_value(subkey, "Answer");
+ error = hive_key_del_value(mem_ctx, subkey, "Answer");
torture_assert_werr_equal(tctx, error, WERR_BADFILE,
"deleting value");
diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c
index 7274bf009d..1bb20399a2 100644
--- a/source4/lib/registry/tests/registry.c
+++ b/source4/lib/registry/tests/registry.c
@@ -200,10 +200,10 @@ static bool test_del_key(struct torture_context *tctx, void *_data)
torture_assert_werr_ok(tctx, error, "Creating key return code");
torture_assert(tctx, newkey != NULL, "Creating new key");
- error = reg_key_del(root, "Polen");
+ error = reg_key_del(tctx, root, "Polen");
torture_assert_werr_ok(tctx, error, "Delete key");
- error = reg_key_del(root, "Polen");
+ error = reg_key_del(tctx, root, "Polen");
torture_assert_werr_equal(tctx, error, WERR_BADFILE,
"Delete missing key");
@@ -464,7 +464,7 @@ static bool test_del_value(struct torture_context *tctx, void *_data)
data_blob_talloc(tctx, value, sizeof(value)));
torture_assert_werr_ok (tctx, error, "setting value");
- error = reg_del_value(subkey, __FUNCTION__);
+ error = reg_del_value(tctx, subkey, __FUNCTION__);
torture_assert_werr_ok (tctx, error, "unsetting value");
error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__,
diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c
index 558e26dcdf..b72b07574e 100644
--- a/source4/lib/registry/tools/regshell.c
+++ b/source4/lib/registry/tools/regshell.c
@@ -325,7 +325,7 @@ static WERROR cmd_rmkey(struct regshell_context *ctx,
return WERR_INVALID_PARAM;
}
- error = reg_key_del(ctx->current, argv[1]);
+ error = reg_key_del(ctx, ctx->current, argv[1]);
if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Error deleting '%s'\n", argv[1]);
return error;
@@ -345,7 +345,7 @@ static WERROR cmd_rmval(struct regshell_context *ctx, int argc, char **argv)
return WERR_INVALID_PARAM;
}
- error = reg_del_value(ctx->current, argv[1]);
+ error = reg_del_value(ctx, ctx->current, argv[1]);
if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Error deleting value '%s'\n", argv[1]);
return error;
diff --git a/source4/lib/registry/util.c b/source4/lib/registry/util.c
index b389ea4698..8aff578cd9 100644
--- a/source4/lib/registry/util.c
+++ b/source4/lib/registry/util.c
@@ -244,7 +244,7 @@ WERROR reg_key_del_abs(struct registry_context *ctx, const char *path)
error = get_abs_parent(mem_ctx, ctx, path, &parent, &n);
if (W_ERROR_IS_OK(error)) {
- error = reg_key_del(parent, n);
+ error = reg_key_del(mem_ctx, parent, n);
}
talloc_free(mem_ctx);