43
42
struct rpc_registry_context {
44
43
struct registry_context context;
45
44
struct dcerpc_pipe *pipe;
45
struct dcerpc_binding_handle *binding_handle;
48
48
static struct registry_operations reg_backend_rpc;
51
51
* This is the RPC backend for the registry library.
54
#define openhive(u) static WERROR open_ ## u(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *hnd) \
54
#define openhive(u) static WERROR open_ ## u(struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, struct policy_handle *hnd) \
56
56
struct winreg_Open ## u r; \
61
61
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; \
62
62
r.out.handle = hnd;\
64
status = dcerpc_winreg_Open ## u(p, mem_ctx, &r); \
64
status = dcerpc_winreg_Open ## u ## _r(b, mem_ctx, &r); \
66
66
if (!NT_STATUS_IS_OK(status)) { \
67
67
DEBUG(1, ("OpenHive failed - %s\n", nt_errstr(status))); \
84
WERROR (*open) (struct dcerpc_pipe *p, TALLOC_CTX *,
84
WERROR (*open) (struct dcerpc_binding_handle *b, TALLOC_CTX *,
85
85
struct policy_handle *h);
86
86
} known_hives[] = {
87
87
{ HKEY_LOCAL_MACHINE, open_HKLM },
119
119
mykeydata = talloc_zero(ctx, struct rpc_key);
120
W_ERROR_HAVE_NO_MEMORY(mykeydata);
120
121
mykeydata->key.context = ctx;
121
mykeydata->pipe = talloc_reference(mykeydata, rctx->pipe);
122
mykeydata->binding_handle = rctx->binding_handle;
122
123
mykeydata->num_values = -1;
123
124
mykeydata->num_subkeys = -1;
124
125
*k = (struct registry_key *)mykeydata;
125
return known_hives[n].open(mykeydata->pipe, mykeydata, &(mykeydata->pol));
126
return known_hives[n].open(mykeydata->binding_handle, mykeydata, &mykeydata->pol);
162
163
mykeydata = talloc_zero(mem_ctx, struct rpc_key);
164
W_ERROR_HAVE_NO_MEMORY(mykeydata);
163
165
mykeydata->key.context = parentkeydata->key.context;
164
mykeydata->pipe = talloc_reference(mykeydata, parentkeydata->pipe);
166
mykeydata->binding_handle = parentkeydata->binding_handle;
165
167
mykeydata->num_values = -1;
166
168
mykeydata->num_subkeys = -1;
167
169
*key = (struct registry_key *)mykeydata;
171
173
r.in.parent_handle = &parentkeydata->pol;
172
174
r.in.keyname.name = name;
173
r.in.unknown = 0x00000000;
175
r.in.options = 0x00000000;
174
176
r.in.access_mask = 0x02000000;
175
177
r.out.handle = &mykeydata->pol;
177
status = dcerpc_winreg_OpenKey(mykeydata->pipe, mem_ctx, &r);
179
status = dcerpc_winreg_OpenKey_r(mykeydata->binding_handle, mem_ctx, &r);
179
181
if (!NT_STATUS_IS_OK(status)) {
180
182
DEBUG(1, ("OpenKey failed - %s\n", nt_errstr(status)));
212
214
r.in.handle = &mykeydata->pol;
213
215
r.in.enum_index = n;
214
216
r.in.name = &name;
217
r.in.type = (enum winreg_Type *) type;
216
218
r.in.value = &value;
217
219
r.in.size = &val_size;
218
220
r.in.length = &zero;
219
221
r.out.name = &name;
222
r.out.type = (enum winreg_Type *) type;
221
223
r.out.value = &value;
222
224
r.out.size = &val_size;
223
225
r.out.length = &zero;
225
status = dcerpc_winreg_EnumValue(mykeydata->pipe, mem_ctx, &r);
227
status = dcerpc_winreg_EnumValue_r(mykeydata->binding_handle, mem_ctx, &r);
227
229
if (!NT_STATUS_IS_OK(status)) {
228
230
DEBUG(1, ("EnumValue failed - %s\n", nt_errstr(status)));
229
231
return ntstatus_to_werror(status);
232
*value_name = talloc_reference(mem_ctx, r.out.name->name);
234
*value_name = talloc_steal(mem_ctx, r.out.name->name);
233
235
*type = *(r.out.type);
234
236
*data = data_blob_talloc(mem_ctx, r.out.value, *r.out.length);
262
264
r.in.handle = &mykeydata->pol;
263
265
r.in.value_name = &name;
266
r.in.type = (enum winreg_Type *) type;
265
267
r.in.data = &value;
266
268
r.in.data_size = &val_size;
267
269
r.in.data_length = &zero;
270
r.out.type = (enum winreg_Type *) type;
269
271
r.out.data = &value;
270
272
r.out.data_size = &val_size;
271
273
r.out.data_length = &zero;
273
status = dcerpc_winreg_QueryValue(mykeydata->pipe, mem_ctx, &r);
275
status = dcerpc_winreg_QueryValue_r(mykeydata->binding_handle, mem_ctx, &r);
275
277
if (!NT_STATUS_IS_OK(status)) {
276
278
DEBUG(1, ("QueryValue failed - %s\n", nt_errstr(status)));
311
313
r.out.keyclass = &classbuf;
312
314
r.out.last_changed_time = &change_time;
314
status = dcerpc_winreg_EnumKey(mykeydata->pipe, mem_ctx, &r);
316
status = dcerpc_winreg_EnumKey_r(mykeydata->binding_handle, mem_ctx, &r);
316
318
if (!NT_STATUS_IS_OK(status)) {
317
319
DEBUG(1, ("EnumKey failed - %s\n", nt_errstr(status)));
321
323
if (name != NULL)
322
*name = talloc_reference(mem_ctx, r.out.name->name);
324
*name = talloc_steal(mem_ctx, r.out.name->name);
323
325
if (keyclass != NULL)
324
*keyclass = talloc_reference(mem_ctx, r.out.keyclass->name);
326
*keyclass = talloc_steal(mem_ctx, r.out.keyclass->name);
325
327
if (last_changed_time != NULL)
326
328
*last_changed_time = *(r.out.last_changed_time);
331
333
static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
332
struct registry_key *parent, const char *name,
334
struct registry_key *parent, const char *path,
333
335
const char *key_class,
334
336
struct security_descriptor *sec,
335
337
struct registry_key **key)
351
353
r.out.new_handle = &rpck->pol;
352
354
r.out.action_taken = NULL;
354
status = dcerpc_winreg_CreateKey(parentkd->pipe, mem_ctx, &r);
356
status = dcerpc_winreg_CreateKey_r(parentkd->binding_handle, mem_ctx, &r);
356
358
if (!NT_STATUS_IS_OK(status)) {
357
359
talloc_free(rpck);
359
361
return ntstatus_to_werror(status);
362
rpck->pipe = talloc_reference(rpck, parentkd->pipe);
364
rpck->binding_handle = parentkd->binding_handle;
363
365
*key = (struct registry_key *)rpck;
365
367
return r.out.result;
387
389
r.out.secdescsize = &mykeydata->secdescsize;
388
390
r.out.last_changed_time = &mykeydata->last_changed_time;
390
status = dcerpc_winreg_QueryInfoKey(mykeydata->pipe, mem_ctx, &r);
392
status = dcerpc_winreg_QueryInfoKey_r(mykeydata->binding_handle, mem_ctx, &r);
392
394
if (!NT_STATUS_IS_OK(status)) {
393
395
DEBUG(1, ("QueryInfoKey failed - %s\n", nt_errstr(status)));
394
396
return ntstatus_to_werror(status);
397
mykeydata->classname = talloc_reference(mem_ctx, r.out.classname->name);
399
mykeydata->classname = talloc_steal(mem_ctx, r.out.classname->name);
399
401
return r.out.result;
402
static WERROR rpc_del_key(struct registry_key *parent, const char *name)
404
static WERROR rpc_del_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
405
408
struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
406
409
struct winreg_DeleteKey r;
407
TALLOC_CTX *mem_ctx = talloc_init("del_key");
410
412
r.in.handle = &mykeydata->pol;
411
413
r.in.key.name = name;
413
status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r);
415
talloc_free(mem_ctx);
415
status = dcerpc_winreg_DeleteKey_r(mykeydata->binding_handle, mem_ctx, &r);
417
417
if (!NT_STATUS_IS_OK(status)) {
418
418
DEBUG(1, ("DeleteKey failed - %s\n", nt_errstr(status)));
473
473
.create_key = rpc_add_key,
474
474
.delete_key = rpc_del_key,
475
475
.get_key_info = rpc_get_info,
476
.get_predefined_key = rpc_get_predefined_key,
479
478
_PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
498
498
status = dcerpc_pipe_connect(rctx /* TALLOC_CTX */,
501
501
credentials, ev, lp_ctx);
504
502
if(NT_STATUS_IS_ERR(status)) {
505
503
DEBUG(1, ("Unable to open '%s': %s\n", location,
506
504
nt_errstr(status)));