summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2004-10-29 01:10:40 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:04:58 -0500
commit7ce7137ad4edb03acf6189568d4c3c4f6d8798fe (patch)
treec4df8f4525c7cfc671e336bed7ede0bbc7704808
parent10ae6167651bc4fe3169c6c4086eef4920b0d739 (diff)
downloadsamba-7ce7137ad4edb03acf6189568d4c3c4f6d8798fe.tar.gz
samba-7ce7137ad4edb03acf6189568d4c3c4f6d8798fe.tar.bz2
samba-7ce7137ad4edb03acf6189568d4c3c4f6d8798fe.zip
r3348: More registry fixes and additions. The following functions work right now against samba 4, at least with a ldb backend:
winreg_Open* winreg_OpenKey winreg_EnumKey winreg_DeleteKey winreg_CreateKey (This used to be commit a71d51dd3b136a1bcde1704fe9830985e06bb01b)
-rw-r--r--source4/lib/registry/common/reg_interface.c1
-rw-r--r--source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c10
-rw-r--r--source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c46
-rw-r--r--source4/rpc_server/winreg/rpc_winreg.c2
-rw-r--r--source4/torture/rpc/winreg.c22
5 files changed, 67 insertions, 14 deletions
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c
index 6237a788b7..a9f7bf1d5f 100644
--- a/source4/lib/registry/common/reg_interface.c
+++ b/source4/lib/registry/common/reg_interface.c
@@ -367,6 +367,7 @@ WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx, struct registry_key *key,
if(key->hive->functions->get_subkey_by_name) {
error = key->hive->functions->get_subkey_by_name(mem_ctx, key,name,subkey);
+ /* FIXME: Fall back to reg_open_key rather then get_subkey_by_index */
} else if(key->hive->functions->get_subkey_by_index) {
for(i = 0; W_ERROR_IS_OK(error); i++) {
error = reg_key_get_subkey_by_index(mem_ctx, key, i, subkey);
diff --git a/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c b/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c
index d8c8d951c1..4f8cc5466e 100644
--- a/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c
+++ b/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c
@@ -35,8 +35,8 @@ static WERROR reg_open_gconf_hive(TALLOC_CTX *mem_ctx, struct registry_hive *h,
if(!h->backend_data) return WERR_FOOBAR;
*k = talloc_p(mem_ctx, struct registry_key);
- (*k)->name = "";
- (*k)->path = "";
+ (*k)->name = talloc_strdup(mem_ctx, "");
+ (*k)->path = talloc_strdup(mem_ctx, "");
(*k)->backend_data = talloc_strdup(mem_ctx, "/");
return WERR_OK;
}
@@ -46,17 +46,15 @@ static WERROR gconf_open_key (TALLOC_CTX *mem_ctx, struct registry_hive *h, cons
struct registry_key *ret;
char *fullpath;
- fullpath = reg_path_win2unix(strdup(name));
+ fullpath = talloc_asprintf(mem_ctx, "/%s", reg_path_win2unix(talloc_strdup(mem_ctx, name)));
/* Check if key exists */
if(!gconf_client_dir_exists((GConfClient *)h->backend_data, fullpath, NULL)) {
- SAFE_FREE(fullpath);
return WERR_DEST_NOT_FOUND;
}
ret = talloc_p(mem_ctx, struct registry_key);
- ret->backend_data = talloc_strdup(mem_ctx, fullpath);
- SAFE_FREE(fullpath);
+ ret->backend_data = fullpath;
*key = ret;
return WERR_OK;
diff --git a/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c b/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c
index b26ee6ec60..a18bed5591 100644
--- a/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c
+++ b/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c
@@ -142,7 +142,10 @@ static WERROR ldb_open_hive(TALLOC_CTX *mem_ctx, struct registry_hive *hive, str
if (!hive->location) return WERR_INVALID_PARAM;
c = ldb_connect(hive->location, 0, NULL);
- if(!c) return WERR_FOOBAR;
+ if(!c) {
+ DEBUG(1, ("ldb_open_hive: %s\n", ldb_errstring(hive->backend_data)));
+ return WERR_FOOBAR;
+ }
ldb_set_debug_stderr(c);
hive->backend_data = c;
@@ -152,8 +155,49 @@ static WERROR ldb_open_hive(TALLOC_CTX *mem_ctx, struct registry_hive *hive, str
return WERR_OK;
}
+static WERROR ldb_add_key (TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, uint32_t access_mask, SEC_DESC *sd, struct registry_key **newkey)
+{
+ struct ldb_context *ctx = parent->hive->backend_data;
+ struct ldb_message msg;
+ int ret;
+
+ ZERO_STRUCT(msg);
+
+ msg.dn = reg_path_to_ldb(mem_ctx, parent->path, talloc_asprintf(mem_ctx, "key=%s,", name));
+
+ ldb_msg_add_string(ctx, &msg, "key", talloc_strdup(mem_ctx, name));
+
+ ret = ldb_add(ctx, &msg);
+ if (ret < 0) {
+ DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(parent->hive->backend_data)));
+ return WERR_FOOBAR;
+ }
+
+ *newkey = talloc_zero_p(mem_ctx, struct registry_key);
+ (*newkey)->backend_data = msg.dn;
+ (*newkey)->name = talloc_strdup(mem_ctx, name);
+
+ return WERR_OK;
+}
+
+static WERROR ldb_del_key (struct registry_key *key)
+{
+ int ret;
+
+ ret = ldb_delete(key->hive->backend_data, key->backend_data);
+
+ if (ret < 0) {
+ DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(key->hive->backend_data)));
+ return WERR_FOOBAR;
+ }
+
+ return WERR_OK;
+}
+
static struct registry_operations reg_backend_ldb = {
.name = "ldb",
+ .add_key = ldb_add_key,
+ .del_key = ldb_del_key,
.open_hive = ldb_open_hive,
.open_key = ldb_open_key,
.get_value_by_index = ldb_get_value_by_id,
diff --git a/source4/rpc_server/winreg/rpc_winreg.c b/source4/rpc_server/winreg/rpc_winreg.c
index 6fa42d2bcd..9ef696d6aa 100644
--- a/source4/rpc_server/winreg/rpc_winreg.c
+++ b/source4/rpc_server/winreg/rpc_winreg.c
@@ -187,7 +187,7 @@ static WERROR winreg_EnumKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem
r->out.last_changed_time = talloc_zero_p(mem_ctx, struct winreg_Time);
}
- return WERR_NOT_SUPPORTED;
+ return r->out.result;
}
diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c
index 1ca5768622..fa08d1a69e 100644
--- a/source4/torture/rpc/winreg.c
+++ b/source4/torture/rpc/winreg.c
@@ -167,7 +167,6 @@ static BOOL test_OpenKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
}
if (!W_ERROR_IS_OK(r.out.result)) {
- printf("OpenKey failed - %s\n", win_errstr(r.out.result));
return False;
}
@@ -258,24 +257,35 @@ static BOOL test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
struct policy_handle key_handle;
+ printf("EnumKey: %d: %s\n", r.in.enum_index, r.out.out_name->name);
+
if (!test_OpenKey(
p, mem_ctx, handle, r.out.out_name->name,
&key_handle)) {
printf("OpenKey(%s) failed - %s\n",
r.out.out_name->name,
win_errstr(r.out.result));
- goto next_key;
+ } else {
+ test_key(p, mem_ctx, &key_handle, depth + 1);
}
-
- test_key(p, mem_ctx, &key_handle, depth + 1);
}
- next_key:
-
r.in.enum_index++;
} while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result));
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("EnumKey failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ if (!W_ERROR_IS_OK(r.out.result) && !W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
+ printf("EnumKey failed - %s\n", win_errstr(r.out.result));
+ return False;
+ }
+
+
+
return True;
}