2 Unix SMB/CIFS implementation.
4 endpoint server for the winreg pipe
6 Copyright (C) Jelmer Vernooij 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rpc_server/dcerpc_server.h"
25 #include "lib/registry/registry.h"
26 #include "librpc/gen_ndr/ndr_winreg.h"
27 #include "rpc_server/common/common.h"
29 enum handle_types { HTYPE_REGVAL, HTYPE_REGKEY };
31 static NTSTATUS dcerpc_winreg_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
33 struct registry_context *ctx;
36 dce_call->context->private = ctx;
41 #define DCESRV_INTERFACE_WINREG_BIND dcerpc_winreg_bind
43 static WERROR winreg_openhive (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, uint32_t hkey, struct policy_handle **outh)
45 struct registry_context *ctx = dce_call->context->private;
46 struct dcesrv_handle *h;
49 h = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
51 error = reg_get_predefined_key(ctx, hkey, (struct registry_key **)&h->data);
52 if (!W_ERROR_IS_OK(error)) {
56 *outh = &h->wire_handle;
61 #define func_winreg_OpenHive(k,n) static WERROR winreg_Open ## k (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct winreg_Open ## k *r) \
63 return winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
66 func_winreg_OpenHive(HKCR,HKEY_CLASSES_ROOT)
67 func_winreg_OpenHive(HKCU,HKEY_CURRENT_USER)
68 func_winreg_OpenHive(HKLM,HKEY_LOCAL_MACHINE)
69 func_winreg_OpenHive(HKPD,HKEY_PERFORMANCE_DATA)
70 func_winreg_OpenHive(HKU,HKEY_USERS)
71 func_winreg_OpenHive(HKCC,HKEY_CURRENT_CONFIG)
72 func_winreg_OpenHive(HKDD,HKEY_DYN_DATA)
73 func_winreg_OpenHive(HKPT,HKEY_PERFORMANCE_TEXT)
74 func_winreg_OpenHive(HKPN,HKEY_PERFORMANCE_NLSTEXT)
79 static WERROR winreg_CloseKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
80 struct winreg_CloseKey *r)
82 struct dcesrv_handle *h;
84 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
88 ZERO_STRUCTP(r->out.handle);
97 static WERROR winreg_CreateKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
98 struct winreg_CreateKey *r)
100 struct dcesrv_handle *h, *newh;
102 struct security_descriptor sd;
104 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
106 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
108 /* the security descriptor is optional */
109 if (r->in.secdesc != NULL) {
112 sdblob.data = r->in.secdesc->sd.data;
113 sdblob.length = r->in.secdesc->sd.len;
114 if (sdblob.data == NULL) {
115 return WERR_INVALID_PARAM;
117 status = ndr_pull_struct_blob_all(&sdblob, mem_ctx, &sd,
118 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
119 if (!NT_STATUS_IS_OK(status)) {
120 return WERR_INVALID_PARAM;
124 error = reg_key_add_name(newh, (struct registry_key *)h->data, r->in.name.name,
126 r->in.secdesc?&sd:NULL,
127 (struct registry_key **)&newh->data);
128 if (W_ERROR_IS_OK(error)) {
129 r->out.new_handle = &newh->wire_handle;
141 static WERROR winreg_DeleteKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
142 struct winreg_DeleteKey *r)
144 struct dcesrv_handle *h;
146 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
148 return reg_key_del((struct registry_key *)h->data, r->in.key.name);
155 static WERROR winreg_DeleteValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
156 struct winreg_DeleteValue *r)
158 struct dcesrv_handle *h;
159 struct registry_key *key;
161 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
165 return reg_del_value(key, r->in.value.name);
172 static WERROR winreg_EnumKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
173 struct winreg_EnumKey *r)
175 struct dcesrv_handle *h;
176 struct registry_key *key;
178 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
180 r->out.result = reg_key_get_subkey_by_index(mem_ctx, (struct registry_key *)h->data, r->in.enum_index, &key);
182 if (W_ERROR_IS_OK(r->out.result)) {
183 if (2*strlen_m_term(key->name) > r->in.name->size) {
184 return WERR_MORE_DATA;
186 r->out.name->length = 2*strlen_m_term(key->name);
187 r->out.name->name = key->name;
188 r->out.class = talloc_zero(mem_ctx, struct winreg_StringBuf);
189 if (r->in.last_changed_time) {
190 r->out.last_changed_time = &key->last_mod;
194 return r->out.result;
201 static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
202 struct winreg_EnumValue *r)
204 struct dcesrv_handle *h;
205 struct registry_key *key;
206 struct registry_value *value;
209 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
213 result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index, &value);
214 if (!W_ERROR_IS_OK(result)) {
218 /* the client can optionally pass a NULL for type, meaning they don't
220 if (r->in.type != NULL) {
221 r->out.type = talloc(mem_ctx, uint32_t);
222 *r->out.type = value->data_type;
225 /* check the client has enough room for the value */
226 if (r->in.value != NULL &&
227 r->in.size != NULL &&
228 value->data.length > *r->in.size) {
229 return WERR_MORE_DATA;
232 /* and enough room for the name */
233 if (r->in.name->size < 2*strlen_m_term(value->name)) {
234 return WERR_MORE_DATA;
237 r->out.name->name = value->name;
238 r->out.name->length = 2*strlen_m_term(value->name);
239 r->out.name->size = 2*strlen_m_term(value->name);
242 r->out.value = value->data.data;
246 r->out.size = talloc(mem_ctx, uint32_t);
247 *r->out.size = value->data.length;
248 r->out.length = r->out.size;
258 static WERROR winreg_FlushKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
259 struct winreg_FlushKey *r)
261 struct dcesrv_handle *h;
263 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
265 return reg_key_flush(h->data);
270 winreg_GetKeySecurity
272 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
273 struct winreg_GetKeySecurity *r)
275 struct dcesrv_handle *h;
277 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
279 return WERR_NOT_SUPPORTED;
286 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
287 struct winreg_LoadKey *r)
289 return WERR_NOT_SUPPORTED;
294 winreg_NotifyChangeKeyValue
296 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
297 struct winreg_NotifyChangeKeyValue *r)
299 return WERR_NOT_SUPPORTED;
306 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
307 struct winreg_OpenKey *r)
309 struct dcesrv_handle *h, *newh;
312 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
314 if (r->in.keyname.name && strcmp(r->in.keyname.name, "") == 0) {
315 newh = talloc_reference(dce_call->context, h);
318 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
319 result = reg_open_key(newh, (struct registry_key *)h->data,
320 r->in.keyname.name, (struct registry_key **)&newh->data);
323 if (W_ERROR_IS_OK(result)) {
324 r->out.handle = &newh->wire_handle;
336 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
337 struct winreg_QueryInfoKey *r)
339 struct dcesrv_handle *h;
340 struct registry_key *k;
343 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
347 ret = reg_key_num_subkeys(k, &r->out.num_subkeys);
348 if (!W_ERROR_IS_OK(ret)) {
352 ret = reg_key_num_values(k, &r->out.num_values);
353 if (!W_ERROR_IS_OK(ret)) {
357 ret = reg_key_subkeysizes(k, &r->out.max_subkeysize, &r->out.max_subkeylen);
358 if (!W_ERROR_IS_OK(ret)) {
362 ret = reg_key_valuesizes(k, &r->out.max_valnamelen, &r->out.max_valbufsize);
363 if (!W_ERROR_IS_OK(ret)) {
367 r->out.secdescsize = 0; /* FIXME */
368 ZERO_STRUCT(r->out.last_changed_time); /* FIXME */
369 if (!W_ERROR_IS_OK(ret)) {
381 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
382 struct winreg_QueryValue *r)
384 struct dcesrv_handle *h;
385 struct registry_key *key;
386 struct registry_value *val;
389 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
393 result = reg_key_get_value_by_name(mem_ctx, key, r->in.value_name.name, &val);
395 if (!W_ERROR_IS_OK(result)) {
399 /* Just asking for the size of the buffer */
400 r->out.type = &val->data_type;
401 r->out.length = &val->data.length;
403 r->out.size = talloc(mem_ctx, uint32_t);
404 *r->out.size = val->data.length;
406 r->out.size = r->in.size;
407 r->out.data = val->data.data;
417 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
418 struct winreg_ReplaceKey *r)
420 return WERR_NOT_SUPPORTED;
427 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
428 struct winreg_RestoreKey *r)
430 return WERR_NOT_SUPPORTED;
437 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
438 struct winreg_SaveKey *r)
440 return WERR_NOT_SUPPORTED;
445 winreg_SetKeySecurity
447 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
448 struct winreg_SetKeySecurity *r)
450 return WERR_NOT_SUPPORTED;
457 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
458 struct winreg_SetValue *r)
460 struct dcesrv_handle *h;
461 struct registry_key *key;
465 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
469 data.data = r->in.data;
470 data.length = r->in.size;
471 result = reg_val_set(key, r->in.name.name, r->in.type, data);
473 if (!W_ERROR_IS_OK(result)) {
484 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
485 struct winreg_UnLoadKey *r)
487 return WERR_NOT_SUPPORTED;
492 winreg_InitiateSystemShutdown
494 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
495 struct winreg_InitiateSystemShutdown *r)
497 return WERR_NOT_SUPPORTED;
502 winreg_AbortSystemShutdown
504 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
505 struct winreg_AbortSystemShutdown *r)
507 return WERR_NOT_SUPPORTED;
514 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
515 struct winreg_GetVersion *r)
517 struct dcesrv_handle *h;
519 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
527 winreg_QueryMultipleValues
529 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
530 struct winreg_QueryMultipleValues *r)
532 return WERR_NOT_SUPPORTED;
537 winreg_InitiateSystemShutdownEx
539 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
540 struct winreg_InitiateSystemShutdownEx *r)
542 return WERR_NOT_SUPPORTED;
549 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
550 struct winreg_SaveKeyEx *r)
552 return WERR_NOT_SUPPORTED;
557 winreg_QueryMultipleValues2
559 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
560 struct winreg_QueryMultipleValues2 *r)
562 return WERR_NOT_SUPPORTED;
566 /* include the generated boilerplate */
567 #include "librpc/gen_ndr/ndr_winreg_s.c"