summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c44
-rw-r--r--source4/librpc/idl/winreg.idl8
-rw-r--r--source4/torture/rpc/winreg.c55
3 files changed, 82 insertions, 25 deletions
diff --git a/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c b/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c
index 796d957076..84c3cb8aee 100644
--- a/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c
+++ b/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c
@@ -39,7 +39,6 @@ static void init_winreg_String(struct winreg_String *name, const char *s)
struct winreg_Open ## u r; \
struct winreg_OpenUnknown unknown; \
struct policy_handle *hnd = malloc(sizeof(struct policy_handle)); \
- TALLOC_CTX *mem_ctx = talloc_init("openhive"); \
\
unknown.unknown0 = 0x84e0; \
unknown.unknown1 = 0x0000; \
@@ -47,13 +46,11 @@ static void init_winreg_String(struct winreg_String *name, const char *s)
r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED; \
r.out.handle = hnd;\
\
- if (!NT_STATUS_IS_OK(dcerpc_winreg_Open ## u(p, mem_ctx, &r))) {\
+ if (!NT_STATUS_IS_OK(dcerpc_winreg_Open ## u(p, h->mem_ctx, &r))) {\
printf("Error executing open\n");\
return NULL;\
}\
\
- talloc_destroy(mem_ctx);\
-\
return hnd;\
}
@@ -83,7 +80,7 @@ struct {
static BOOL rpc_open_registry(REG_HANDLE *h, const char *location, BOOL try_full)
{
BOOL res = True;
- struct rpc_data *mydata = malloc(sizeof(struct rpc_data));
+ struct rpc_data *mydata = talloc(h->mem_ctx, sizeof(struct rpc_data));
char *binding = strdup(location);
NTSTATUS status;
@@ -124,7 +121,7 @@ static struct policy_handle *rpc_get_key_handle(REG_HANDLE *h, const char *path)
char *end = strchr(path+1, '\\');
NTSTATUS status;
struct winreg_OpenKey r;
- struct policy_handle *key_handle = malloc(sizeof(struct policy_handle));
+ struct policy_handle *key_handle = talloc(h->mem_ctx, sizeof(struct policy_handle));
TALLOC_CTX *mem_ctx;
if(end) hivename = strndup(path+1, end-path-1);
@@ -177,17 +174,16 @@ static BOOL rpc_fetch_subkeys(REG_KEY *parent, int *count, REG_KEY ***subkeys)
struct winreg_Time tm;
struct rpc_data *mydata = parent->handle->backend_data;
int i;
- REG_KEY **ar = malloc(sizeof(REG_KEY *));
+ REG_KEY **ar = talloc(parent->mem_ctx, sizeof(REG_KEY *));
NTSTATUS status = NT_STATUS_OK;
TALLOC_CTX *mem_ctx;
/* List the hives */
if(parent->backend_data == parent->handle->backend_data) {
- REG_KEY **ar = malloc(sizeof(REG_KEY *));
for(i = 0; known_hives[i].name; i++) {
ar[i] = reg_key_new_rel(known_hives[i].name, parent, NULL);
(*count)++;
- ar = realloc(ar, sizeof(REG_KEY *) * ((*count)+1));
+ ar = talloc_realloc(parent->mem_ctx, ar, sizeof(REG_KEY *) * ((*count)+1));
}
*subkeys = ar;
@@ -199,7 +195,6 @@ static BOOL rpc_fetch_subkeys(REG_KEY *parent, int *count, REG_KEY ***subkeys)
if(!parent->backend_data) return False;
- mem_ctx = talloc_init("enumkey");
(*count) = 0;
r.in.handle = parent->backend_data;
keyname.unknown = 0x0000020a;
@@ -215,11 +210,11 @@ static BOOL rpc_fetch_subkeys(REG_KEY *parent, int *count, REG_KEY ***subkeys)
r.in.enum_index = i;
r.in.unknown = r.out.unknown = 0x0414;
r.in.key_name_len = r.out.key_name_len = 0;
- status = dcerpc_winreg_EnumKey(mydata->pipe, mem_ctx, &r);
+ status = dcerpc_winreg_EnumKey(mydata->pipe, parent->mem_ctx, &r);
if(NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
ar[(*count)] = reg_key_new_rel(r.out.out_name->name, parent, NULL);
(*count)++;
- ar = realloc(ar, ((*count)+1) * sizeof(REG_KEY *));
+ ar = talloc_realloc(parent->mem_ctx, ar, ((*count)+1) * sizeof(REG_KEY *));
}
}
@@ -271,29 +266,38 @@ static BOOL rpc_fetch_values(REG_KEY *parent, int *count, REG_VAL ***values)
r.in.returned_len = &returned_len;
r.out.result.v = 0;
- mem_ctx = talloc_init("fetchvalues");
while(1) {
- status = dcerpc_winreg_EnumValue(mydata->pipe, mem_ctx, &r);
+ status = dcerpc_winreg_EnumValue(mydata->pipe, parent->mem_ctx, &r);
if(NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
r.in.enum_index++;
ar[(*count)] = reg_val_new(parent, NULL);
- ar[(*count)]->name = strdup(r.out.name->name);
+ ar[(*count)]->name = talloc_strdup(ar[*count]->mem_ctx, r.out.name->name);
ar[(*count)]->data_type = *r.out.type;
ar[(*count)]->data_len = value.len;
- ar[(*count)]->data_blk = malloc(value.len);
+ ar[(*count)]->data_blk = talloc(ar[*count]->mem_ctx, value.len);
memcpy(ar[(*count)]->data_blk, value.buffer, value.len);
(*count)++;
- ar = realloc(ar, ((*count)+1) * sizeof(REG_VAL *));
+ ar = talloc_realloc(parent->mem_ctx, ar, ((*count)+1) * sizeof(REG_VAL *));
} else break;
}
- talloc_destroy(mem_ctx);
-
*values = ar;
return True;
}
+static BOOL rpc_add_key(REG_KEY *parent, const char *name)
+{
+ /* FIXME */
+ return False;
+}
+
+static BOOL rpc_del_key(REG_KEY *k)
+{
+ /* FIXME */
+ return False;
+}
+
static REG_OPS reg_backend_rpc = {
.name = "rpc",
.open_registry = rpc_open_registry,
@@ -302,6 +306,8 @@ static REG_OPS reg_backend_rpc = {
.open_key = rpc_open_key,
.fetch_subkeys = rpc_fetch_subkeys,
.fetch_values = rpc_fetch_values,
+ .add_key = rpc_add_key,
+ .del_key = rpc_del_key,
};
NTSTATUS reg_rpc_init(void)
diff --git a/source4/librpc/idl/winreg.idl b/source4/librpc/idl/winreg.idl
index 14f2bcfd5d..e522d839ef 100644
--- a/source4/librpc/idl/winreg.idl
+++ b/source4/librpc/idl/winreg.idl
@@ -69,6 +69,14 @@
/******************/
/* Function: 0x06 */
WERROR winreg_CreateKey(
+ [in,out,ref] policy_handle *handle,
+ [in] winreg_String key,
+ [in] winreg_String class,
+ [in,out] uint32 reserved,
+ [in] uint32 access_mask,
+ [in] uint32 sec_info,
+ [in] sec_desc_buf data,
+ [in] uint32 reserved2
);
/******************/
diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c
index 9b90d30d5c..23e3d2e779 100644
--- a/source4/torture/rpc/winreg.c
+++ b/source4/torture/rpc/winreg.c
@@ -53,6 +53,36 @@ static BOOL test_GetVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
return True;
}
+static BOOL test_CreateKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle, const char *name, const char *class)
+{
+ struct winreg_CreateKey r;
+ struct policy_handle newhandle;
+ NTSTATUS status;
+
+ printf("\ntesting CreateKey\n");
+
+ r.in.handle = handle;
+ r.out.handle = &newhandle;
+ init_winreg_String(&r.in.key, name);
+ init_winreg_String(&r.in.class, class);
+ r.in.reserved = 0x0;
+ r.in.reserved2 = 0x0;
+ r.in.access_mask = 0x02000000;
+ r.out.reserved = 0x0;
+ r.in.sec_info = 0x0;
+ r.in.data = 0;
+
+ status = dcerpc_winreg_CreateKey(p, mem_ctx, &r);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("CreateKey failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ return True;
+}
+
static BOOL test_CloseKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
struct policy_handle *handle)
{
@@ -384,6 +414,7 @@ typedef BOOL winreg_open_fn(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
{
struct policy_handle handle;
+ BOOL ret = True;
winreg_open_fn *open_fn = (winreg_open_fn *)fn;
if (!open_fn(p, mem_ctx, &handle))
@@ -391,25 +422,37 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
if (!test_GetVersion(p, mem_ctx, &handle)) {
printf("GetVersion failed\n");
- return False;
+ ret = False;
}
if (!test_FlushKey(p, mem_ctx, &handle)) {
printf("FlushKey failed\n");
- return False;
+ ret = False;
+ }
+
+ if (!test_CreateKey(p, mem_ctx, &handle, "spottyfoot", "foo")) {
+ printf("CreateKey failed\n");
+ ret = False;
}
if (!test_DeleteKey(p, mem_ctx, &handle, "spottyfoot")) {
printf("DeleteKey failed\n");
- return False;
+ ret = False;
}
/* The HKCR hive has a very large fanout */
- if (open_fn == test_OpenHKCR)
- return test_key(p, mem_ctx, &handle, MAX_DEPTH - 1);
+ if (open_fn == test_OpenHKCR) {
+ if(!test_key(p, mem_ctx, &handle, MAX_DEPTH - 1)) {
+ ret = False;
+ }
+ }
- return test_key(p, mem_ctx, &handle, 0);
+ if(!test_key(p, mem_ctx, &handle, 0)) {
+ ret = False;
+ }
+
+ return ret;
}
BOOL torture_rpc_winreg(int dummy)