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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "rpc_server/dcerpc_server.h"
24 #include "lib/registry/registry.h"
25 #include "librpc/gen_ndr/ndr_winreg.h"
26 #include "rpc_server/common/common.h"
27 #include "librpc/gen_ndr/ndr_security.h"
29 enum handle_types { HTYPE_REGVAL, HTYPE_REGKEY };
31 static NTSTATUS dcerpc_winreg_bind(struct dcesrv_call_state *dce_call,
32 const struct dcesrv_interface *iface)
34 struct registry_context *ctx;
37 err = reg_open_samba(dce_call->context,
38 &ctx, dce_call->conn->auth_state.session_info, NULL);
40 if (!W_ERROR_IS_OK(err)) {
41 DEBUG(0, ("Error opening registry: %s\n", win_errstr(err)));
42 return NT_STATUS_UNSUCCESSFUL;
45 dce_call->context->private = ctx;
50 #define DCESRV_INTERFACE_WINREG_BIND dcerpc_winreg_bind
52 static WERROR dcesrv_winreg_openhive(struct dcesrv_call_state *dce_call,
53 TALLOC_CTX *mem_ctx, uint32_t hkey,
54 struct policy_handle **outh)
56 struct registry_context *ctx = dce_call->context->private;
57 struct dcesrv_handle *h;
60 h = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
62 error = reg_get_predefined_key(ctx, hkey, (struct registry_key **)&h->data);
63 if (!W_ERROR_IS_OK(error)) {
67 *outh = &h->wire_handle;
72 #define func_winreg_OpenHive(k,n) static WERROR dcesrv_winreg_Open ## k (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct winreg_Open ## k *r) \
74 return dcesrv_winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
77 func_winreg_OpenHive(HKCR,HKEY_CLASSES_ROOT)
78 func_winreg_OpenHive(HKCU,HKEY_CURRENT_USER)
79 func_winreg_OpenHive(HKLM,HKEY_LOCAL_MACHINE)
80 func_winreg_OpenHive(HKPD,HKEY_PERFORMANCE_DATA)
81 func_winreg_OpenHive(HKU,HKEY_USERS)
82 func_winreg_OpenHive(HKCC,HKEY_CURRENT_CONFIG)
83 func_winreg_OpenHive(HKDD,HKEY_DYN_DATA)
84 func_winreg_OpenHive(HKPT,HKEY_PERFORMANCE_TEXT)
85 func_winreg_OpenHive(HKPN,HKEY_PERFORMANCE_NLSTEXT)
90 static WERROR dcesrv_winreg_CloseKey(struct dcesrv_call_state *dce_call,
92 struct winreg_CloseKey *r)
94 struct dcesrv_handle *h;
96 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
100 ZERO_STRUCTP(r->out.handle);
108 static WERROR dcesrv_winreg_CreateKey(struct dcesrv_call_state *dce_call,
110 struct winreg_CreateKey *r)
112 struct dcesrv_handle *h, *newh;
114 struct security_descriptor sd;
116 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
118 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
120 /* the security descriptor is optional */
121 if (r->in.secdesc != NULL) {
124 sdblob.data = r->in.secdesc->sd.data;
125 sdblob.length = r->in.secdesc->sd.len;
126 if (sdblob.data == NULL) {
127 return WERR_INVALID_PARAM;
129 status = ndr_pull_struct_blob_all(&sdblob, mem_ctx, &sd,
130 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
131 if (!NT_STATUS_IS_OK(status)) {
132 return WERR_INVALID_PARAM;
136 error = reg_key_add_name(newh, (struct registry_key *)h->data,
137 r->in.name.name, NULL, r->in.secdesc?&sd:NULL,
138 (struct registry_key **)&newh->data);
139 if (W_ERROR_IS_OK(error)) {
140 r->out.new_handle = &newh->wire_handle;
152 static WERROR dcesrv_winreg_DeleteKey(struct dcesrv_call_state *dce_call,
154 struct winreg_DeleteKey *r)
156 struct dcesrv_handle *h;
158 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
160 return reg_key_del((struct registry_key *)h->data, r->in.key.name);
167 static WERROR dcesrv_winreg_DeleteValue(struct dcesrv_call_state *dce_call,
169 struct winreg_DeleteValue *r)
171 struct dcesrv_handle *h;
172 struct registry_key *key;
174 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
178 return reg_del_value(key, r->in.value.name);
185 static WERROR dcesrv_winreg_EnumKey(struct dcesrv_call_state *dce_call,
187 struct winreg_EnumKey *r)
189 struct dcesrv_handle *h;
193 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
195 r->out.result = reg_key_get_subkey_by_index(mem_ctx,
196 (struct registry_key *)h->data, r->in.enum_index,
197 &name, NULL, &last_mod);
199 if (W_ERROR_IS_OK(r->out.result)) {
200 if (2*strlen_m_term(name) > r->in.name->size) {
201 return WERR_MORE_DATA;
203 r->out.name->length = 2*strlen_m_term(name);
204 r->out.name->name = name;
205 r->out.keyclass = talloc_zero(mem_ctx, struct winreg_StringBuf);
206 if (r->in.last_changed_time) {
207 r->out.last_changed_time = &last_mod;
211 return r->out.result;
218 static WERROR dcesrv_winreg_EnumValue(struct dcesrv_call_state *dce_call,
220 struct winreg_EnumValue *r)
222 struct dcesrv_handle *h;
223 struct registry_key *key;
225 const char *data_name;
229 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
233 result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index,
236 if (!W_ERROR_IS_OK(result)) {
240 /* the client can optionally pass a NULL for type, meaning they don't
242 if (r->in.type != NULL) {
243 r->out.type = talloc(mem_ctx, enum winreg_Type);
244 *r->out.type = data_type;
247 /* check the client has enough room for the value */
248 if (r->in.value != NULL &&
249 r->in.size != NULL &&
250 data.length > *r->in.size) {
251 return WERR_MORE_DATA;
254 /* and enough room for the name */
255 if (r->in.name->size < 2*strlen_m_term(data_name)) {
256 return WERR_MORE_DATA;
259 r->out.name->name = data_name;
260 r->out.name->length = 2*strlen_m_term(data_name);
261 r->out.name->size = 2*strlen_m_term(data_name);
264 r->out.value = data.data;
268 r->out.size = talloc(mem_ctx, uint32_t);
269 *r->out.size = data.length;
270 r->out.length = r->out.size;
280 static WERROR dcesrv_winreg_FlushKey(struct dcesrv_call_state *dce_call,
282 struct winreg_FlushKey *r)
284 struct dcesrv_handle *h;
286 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
288 return reg_key_flush(h->data);
293 winreg_GetKeySecurity
295 static WERROR dcesrv_winreg_GetKeySecurity(struct dcesrv_call_state *dce_call,
297 struct winreg_GetKeySecurity *r)
299 struct dcesrv_handle *h;
301 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
303 return WERR_NOT_SUPPORTED;
310 static WERROR dcesrv_winreg_LoadKey(struct dcesrv_call_state *dce_call,
312 struct winreg_LoadKey *r)
314 return WERR_NOT_SUPPORTED;
319 winreg_NotifyChangeKeyValue
321 static WERROR dcesrv_winreg_NotifyChangeKeyValue(
322 struct dcesrv_call_state *dce_call,
323 TALLOC_CTX *mem_ctx, struct winreg_NotifyChangeKeyValue *r)
325 return WERR_NOT_SUPPORTED;
332 static WERROR dcesrv_winreg_OpenKey(struct dcesrv_call_state *dce_call,
334 struct winreg_OpenKey *r)
336 struct dcesrv_handle *h, *newh;
339 DCESRV_PULL_HANDLE_FAULT(h, r->in.parent_handle, HTYPE_REGKEY);
341 if (r->in.keyname.name && strcmp(r->in.keyname.name, "") == 0) {
342 newh = talloc_reference(dce_call->context, h);
345 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
346 result = reg_open_key(newh, (struct registry_key *)h->data,
347 r->in.keyname.name, (struct registry_key **)&newh->data);
350 if (W_ERROR_IS_OK(result)) {
351 r->out.handle = &newh->wire_handle;
363 static WERROR dcesrv_winreg_QueryInfoKey(struct dcesrv_call_state *dce_call,
365 struct winreg_QueryInfoKey *r)
367 struct dcesrv_handle *h;
368 struct registry_key *k;
370 const char *classname = NULL;
372 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
376 ret = reg_key_get_info(mem_ctx, k, &classname, r->out.num_subkeys,
377 r->out.num_values, r->out.last_changed_time);
379 if (r->out.classname != NULL)
380 r->out.classname->name = classname;
389 static WERROR dcesrv_winreg_QueryValue(struct dcesrv_call_state *dce_call,
391 struct winreg_QueryValue *r)
393 struct dcesrv_handle *h;
394 struct registry_key *key;
396 DATA_BLOB value_data;
399 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
403 result = reg_key_get_value_by_name(mem_ctx, key, r->in.value_name.name,
404 &value_type, &value_data);
406 if (!W_ERROR_IS_OK(result)) {
410 /* Just asking for the size of the buffer */
411 r->out.type = &value_type;
412 r->out.length = talloc(mem_ctx, uint32_t);
413 if (!r->out.length) {
416 *r->out.length = value_data.length;
417 if (r->in.data == NULL) {
418 r->out.size = talloc(mem_ctx, uint32_t);
419 *r->out.size = value_data.length;
421 r->out.size = r->in.size;
422 r->out.data = value_data.data;
432 static WERROR dcesrv_winreg_ReplaceKey(struct dcesrv_call_state *dce_call,
434 struct winreg_ReplaceKey *r)
436 return WERR_NOT_SUPPORTED;
443 static WERROR dcesrv_winreg_RestoreKey(struct dcesrv_call_state *dce_call,
445 struct winreg_RestoreKey *r)
447 return WERR_NOT_SUPPORTED;
454 static WERROR dcesrv_winreg_SaveKey(struct dcesrv_call_state *dce_call,
456 struct winreg_SaveKey *r)
458 return WERR_NOT_SUPPORTED;
463 winreg_SetKeySecurity
465 static WERROR dcesrv_winreg_SetKeySecurity(struct dcesrv_call_state *dce_call,
467 struct winreg_SetKeySecurity *r)
469 return WERR_NOT_SUPPORTED;
476 static WERROR dcesrv_winreg_SetValue(struct dcesrv_call_state *dce_call,
478 struct winreg_SetValue *r)
480 struct dcesrv_handle *h;
481 struct registry_key *key;
485 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
489 data.data = r->in.data;
490 data.length = r->in.size;
491 result = reg_val_set(key, r->in.name.name, r->in.type, data);
500 static WERROR dcesrv_winreg_UnLoadKey(struct dcesrv_call_state *dce_call,
502 struct winreg_UnLoadKey *r)
504 return WERR_NOT_SUPPORTED;
509 winreg_InitiateSystemShutdown
511 static WERROR dcesrv_winreg_InitiateSystemShutdown(
512 struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
513 struct winreg_InitiateSystemShutdown *r)
515 return WERR_NOT_SUPPORTED;
520 winreg_AbortSystemShutdown
522 static WERROR dcesrv_winreg_AbortSystemShutdown(
523 struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
524 struct winreg_AbortSystemShutdown *r)
526 return WERR_NOT_SUPPORTED;
533 static WERROR dcesrv_winreg_GetVersion(struct dcesrv_call_state *dce_call,
535 struct winreg_GetVersion *r)
537 struct dcesrv_handle *h;
539 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
541 r->out.version = talloc(mem_ctx, uint32_t);
542 W_ERROR_HAVE_NO_MEMORY(r->out.version);
551 winreg_QueryMultipleValues
553 static WERROR dcesrv_winreg_QueryMultipleValues(
554 struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
555 struct winreg_QueryMultipleValues *r)
557 return WERR_NOT_SUPPORTED;
562 winreg_InitiateSystemShutdownEx
564 static WERROR dcesrv_winreg_InitiateSystemShutdownEx(
565 struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
566 struct winreg_InitiateSystemShutdownEx *r)
568 return WERR_NOT_SUPPORTED;
575 static WERROR dcesrv_winreg_SaveKeyEx(struct dcesrv_call_state *dce_call,
577 struct winreg_SaveKeyEx *r)
579 return WERR_NOT_SUPPORTED;
584 winreg_QueryMultipleValues2
586 static WERROR dcesrv_winreg_QueryMultipleValues2(
587 struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
588 struct winreg_QueryMultipleValues2 *r)
590 return WERR_NOT_SUPPORTED;
594 /* include the generated boilerplate */
595 #include "librpc/gen_ndr/ndr_winreg_s.c"