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"
28 #include "param/param.h"
30 enum handle_types { HTYPE_REGVAL, HTYPE_REGKEY };
32 static NTSTATUS dcerpc_winreg_bind(struct dcesrv_call_state *dce_call,
33 const struct dcesrv_interface *iface)
35 struct registry_context *ctx;
38 err = reg_open_samba(dce_call->context,
39 &ctx, dce_call->conn->dce_ctx->lp_ctx, dce_call->conn->auth_state.session_info,
42 if (!W_ERROR_IS_OK(err)) {
43 DEBUG(0, ("Error opening registry: %s\n", win_errstr(err)));
44 return NT_STATUS_UNSUCCESSFUL;
47 dce_call->context->private = ctx;
52 #define DCESRV_INTERFACE_WINREG_BIND dcerpc_winreg_bind
54 static WERROR dcesrv_winreg_openhive(struct dcesrv_call_state *dce_call,
55 TALLOC_CTX *mem_ctx, uint32_t hkey,
56 struct policy_handle **outh)
58 struct registry_context *ctx = dce_call->context->private;
59 struct dcesrv_handle *h;
62 h = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
64 error = reg_get_predefined_key(ctx, hkey,
65 (struct registry_key **)&h->data);
66 if (!W_ERROR_IS_OK(error)) {
70 *outh = &h->wire_handle;
75 #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) \
77 return dcesrv_winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
80 func_winreg_OpenHive(HKCR,HKEY_CLASSES_ROOT)
81 func_winreg_OpenHive(HKCU,HKEY_CURRENT_USER)
82 func_winreg_OpenHive(HKLM,HKEY_LOCAL_MACHINE)
83 func_winreg_OpenHive(HKPD,HKEY_PERFORMANCE_DATA)
84 func_winreg_OpenHive(HKU,HKEY_USERS)
85 func_winreg_OpenHive(HKCC,HKEY_CURRENT_CONFIG)
86 func_winreg_OpenHive(HKDD,HKEY_DYN_DATA)
87 func_winreg_OpenHive(HKPT,HKEY_PERFORMANCE_TEXT)
88 func_winreg_OpenHive(HKPN,HKEY_PERFORMANCE_NLSTEXT)
93 static WERROR dcesrv_winreg_CloseKey(struct dcesrv_call_state *dce_call,
95 struct winreg_CloseKey *r)
97 struct dcesrv_handle *h;
99 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
103 ZERO_STRUCTP(r->out.handle);
111 static WERROR dcesrv_winreg_CreateKey(struct dcesrv_call_state *dce_call,
113 struct winreg_CreateKey *r)
115 struct dcesrv_handle *h, *newh;
117 struct security_descriptor sd;
119 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
121 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
123 /* the security descriptor is optional */
124 if (r->in.secdesc != NULL) {
126 enum ndr_err_code ndr_err;
127 sdblob.data = r->in.secdesc->sd.data;
128 sdblob.length = r->in.secdesc->sd.len;
129 if (sdblob.data == NULL) {
130 return WERR_INVALID_PARAM;
132 ndr_err = ndr_pull_struct_blob_all(&sdblob, mem_ctx, NULL, &sd,
133 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
134 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
135 return WERR_INVALID_PARAM;
139 error = reg_key_add_name(newh, (struct registry_key *)h->data,
140 r->in.name.name, NULL, r->in.secdesc?&sd:NULL,
141 (struct registry_key **)&newh->data);
142 if (W_ERROR_IS_OK(error)) {
143 r->out.new_handle = &newh->wire_handle;
155 static WERROR dcesrv_winreg_DeleteKey(struct dcesrv_call_state *dce_call,
157 struct winreg_DeleteKey *r)
159 struct dcesrv_handle *h;
161 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
163 return reg_key_del((struct registry_key *)h->data, r->in.key.name);
170 static WERROR dcesrv_winreg_DeleteValue(struct dcesrv_call_state *dce_call,
172 struct winreg_DeleteValue *r)
174 struct dcesrv_handle *h;
175 struct registry_key *key;
177 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
181 return reg_del_value(key, r->in.value.name);
188 static WERROR dcesrv_winreg_EnumKey(struct dcesrv_call_state *dce_call,
190 struct winreg_EnumKey *r)
192 struct dcesrv_handle *h;
196 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
198 r->out.result = reg_key_get_subkey_by_index(mem_ctx,
199 (struct registry_key *)h->data,
201 &name, NULL, &last_mod);
203 if (W_ERROR_IS_OK(r->out.result)) {
204 if (2*strlen_m_term(name) > r->in.name->size) {
205 return WERR_MORE_DATA;
207 r->out.name->length = 2*strlen_m_term(name);
208 r->out.name->name = name;
209 r->out.keyclass = talloc_zero(mem_ctx, struct winreg_StringBuf);
210 if (r->in.last_changed_time) {
211 r->out.last_changed_time = &last_mod;
215 return r->out.result;
222 static WERROR dcesrv_winreg_EnumValue(struct dcesrv_call_state *dce_call,
224 struct winreg_EnumValue *r)
226 struct dcesrv_handle *h;
227 struct registry_key *key;
229 const char *data_name;
233 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
237 result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index,
240 if (!W_ERROR_IS_OK(result)) {
244 /* the client can optionally pass a NULL for type, meaning they don't
246 if (r->in.type != NULL) {
247 r->out.type = talloc(mem_ctx, enum winreg_Type);
248 *r->out.type = data_type;
251 /* check the client has enough room for the value */
252 if (r->in.value != NULL &&
253 r->in.size != NULL &&
254 data.length > *r->in.size) {
255 return WERR_MORE_DATA;
258 /* and enough room for the name */
259 if (r->in.name->size < 2*strlen_m_term(data_name)) {
260 return WERR_MORE_DATA;
263 r->out.name->name = data_name;
264 r->out.name->length = 2*strlen_m_term(data_name);
265 r->out.name->size = r->in.name->size;
268 r->out.value = data.data;
272 r->out.size = talloc(mem_ctx, uint32_t);
273 *r->out.size = data.length;
274 r->out.length = r->out.size;
284 static WERROR dcesrv_winreg_FlushKey(struct dcesrv_call_state *dce_call,
286 struct winreg_FlushKey *r)
288 struct dcesrv_handle *h;
290 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
292 return reg_key_flush(h->data);
297 winreg_GetKeySecurity
299 static WERROR dcesrv_winreg_GetKeySecurity(struct dcesrv_call_state *dce_call,
301 struct winreg_GetKeySecurity *r)
303 struct dcesrv_handle *h;
305 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
307 return WERR_NOT_SUPPORTED;
314 static WERROR dcesrv_winreg_LoadKey(struct dcesrv_call_state *dce_call,
316 struct winreg_LoadKey *r)
318 return WERR_NOT_SUPPORTED;
323 winreg_NotifyChangeKeyValue
325 static WERROR dcesrv_winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call,
327 struct winreg_NotifyChangeKeyValue *r)
329 return WERR_NOT_SUPPORTED;
336 static WERROR dcesrv_winreg_OpenKey(struct dcesrv_call_state *dce_call,
338 struct winreg_OpenKey *r)
340 struct dcesrv_handle *h, *newh;
343 DCESRV_PULL_HANDLE_FAULT(h, r->in.parent_handle, HTYPE_REGKEY);
345 if (r->in.keyname.name && strcmp(r->in.keyname.name, "") == 0) {
346 newh = talloc_reference(dce_call->context, h);
349 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
350 result = reg_open_key(newh, (struct registry_key *)h->data,
352 (struct registry_key **)&newh->data);
355 if (W_ERROR_IS_OK(result)) {
356 r->out.handle = &newh->wire_handle;
368 static WERROR dcesrv_winreg_QueryInfoKey(struct dcesrv_call_state *dce_call,
370 struct winreg_QueryInfoKey *r)
372 struct dcesrv_handle *h;
373 struct registry_key *k;
375 const char *classname = NULL;
377 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
381 ret = reg_key_get_info(mem_ctx, k, &classname, r->out.num_subkeys,
382 r->out.num_values, r->out.last_changed_time,
383 r->out.max_subkeylen, r->out.max_valnamelen,
384 r->out.max_valbufsize);
386 if (r->out.classname != NULL)
387 r->out.classname->name = classname;
396 static WERROR dcesrv_winreg_QueryValue(struct dcesrv_call_state *dce_call,
398 struct winreg_QueryValue *r)
400 struct dcesrv_handle *h;
401 struct registry_key *key;
403 DATA_BLOB value_data;
406 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
410 result = reg_key_get_value_by_name(mem_ctx, key, r->in.value_name.name,
411 &value_type, &value_data);
413 if (!W_ERROR_IS_OK(result)) {
417 /* Just asking for the size of the buffer */
418 r->out.type = talloc(mem_ctx, uint32_t);
422 *r->out.type = value_type;
423 r->out.length = talloc(mem_ctx, uint32_t);
424 if (!r->out.length) {
427 *r->out.length = value_data.length;
428 if (r->in.data == NULL) {
429 r->out.size = talloc(mem_ctx, uint32_t);
430 *r->out.size = value_data.length;
432 r->out.size = r->in.size;
433 r->out.data = value_data.data;
443 static WERROR dcesrv_winreg_ReplaceKey(struct dcesrv_call_state *dce_call,
445 struct winreg_ReplaceKey *r)
447 return WERR_NOT_SUPPORTED;
454 static WERROR dcesrv_winreg_RestoreKey(struct dcesrv_call_state *dce_call,
456 struct winreg_RestoreKey *r)
458 return WERR_NOT_SUPPORTED;
465 static WERROR dcesrv_winreg_SaveKey(struct dcesrv_call_state *dce_call,
467 struct winreg_SaveKey *r)
469 return WERR_NOT_SUPPORTED;
474 winreg_SetKeySecurity
476 static WERROR dcesrv_winreg_SetKeySecurity(struct dcesrv_call_state *dce_call,
478 struct winreg_SetKeySecurity *r)
480 return WERR_NOT_SUPPORTED;
487 static WERROR dcesrv_winreg_SetValue(struct dcesrv_call_state *dce_call,
489 struct winreg_SetValue *r)
491 struct dcesrv_handle *h;
492 struct registry_key *key;
496 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
500 data.data = r->in.data;
501 data.length = r->in.size;
502 result = reg_val_set(key, r->in.name.name, r->in.type, data);
511 static WERROR dcesrv_winreg_UnLoadKey(struct dcesrv_call_state *dce_call,
513 struct winreg_UnLoadKey *r)
515 return WERR_NOT_SUPPORTED;
520 winreg_InitiateSystemShutdown
522 static WERROR dcesrv_winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call,
524 struct winreg_InitiateSystemShutdown *r)
526 return WERR_NOT_SUPPORTED;
531 winreg_AbortSystemShutdown
533 static WERROR dcesrv_winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call,
535 struct winreg_AbortSystemShutdown *r)
537 return WERR_NOT_SUPPORTED;
544 static WERROR dcesrv_winreg_GetVersion(struct dcesrv_call_state *dce_call,
546 struct winreg_GetVersion *r)
548 struct dcesrv_handle *h;
550 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
552 r->out.version = talloc(mem_ctx, uint32_t);
553 W_ERROR_HAVE_NO_MEMORY(r->out.version);
562 winreg_QueryMultipleValues
564 static WERROR dcesrv_winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call,
566 struct winreg_QueryMultipleValues *r)
568 return WERR_NOT_SUPPORTED;
573 winreg_InitiateSystemShutdownEx
575 static WERROR dcesrv_winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call,
577 struct winreg_InitiateSystemShutdownEx *r)
579 return WERR_NOT_SUPPORTED;
586 static WERROR dcesrv_winreg_SaveKeyEx(struct dcesrv_call_state *dce_call,
588 struct winreg_SaveKeyEx *r)
590 return WERR_NOT_SUPPORTED;
595 winreg_QueryMultipleValues2
597 static WERROR dcesrv_winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call,
599 struct winreg_QueryMultipleValues2 *r)
601 return WERR_NOT_SUPPORTED;
605 /* include the generated boilerplate */
606 #include "librpc/gen_ndr/ndr_winreg_s.c"