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,
41 if (!W_ERROR_IS_OK(err)) {
42 DEBUG(0, ("Error opening registry: %s\n", win_errstr(err)));
43 return NT_STATUS_UNSUCCESSFUL;
46 dce_call->context->private = ctx;
51 #define DCESRV_INTERFACE_WINREG_BIND dcerpc_winreg_bind
53 static WERROR dcesrv_winreg_openhive(struct dcesrv_call_state *dce_call,
54 TALLOC_CTX *mem_ctx, uint32_t hkey,
55 struct policy_handle **outh)
57 struct registry_context *ctx = dce_call->context->private;
58 struct dcesrv_handle *h;
61 h = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
63 error = reg_get_predefined_key(ctx, hkey,
64 (struct registry_key **)&h->data);
65 if (!W_ERROR_IS_OK(error)) {
69 *outh = &h->wire_handle;
74 #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) \
76 return dcesrv_winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
79 func_winreg_OpenHive(HKCR,HKEY_CLASSES_ROOT)
80 func_winreg_OpenHive(HKCU,HKEY_CURRENT_USER)
81 func_winreg_OpenHive(HKLM,HKEY_LOCAL_MACHINE)
82 func_winreg_OpenHive(HKPD,HKEY_PERFORMANCE_DATA)
83 func_winreg_OpenHive(HKU,HKEY_USERS)
84 func_winreg_OpenHive(HKCC,HKEY_CURRENT_CONFIG)
85 func_winreg_OpenHive(HKDD,HKEY_DYN_DATA)
86 func_winreg_OpenHive(HKPT,HKEY_PERFORMANCE_TEXT)
87 func_winreg_OpenHive(HKPN,HKEY_PERFORMANCE_NLSTEXT)
92 static WERROR dcesrv_winreg_CloseKey(struct dcesrv_call_state *dce_call,
94 struct winreg_CloseKey *r)
96 struct dcesrv_handle *h;
98 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
102 ZERO_STRUCTP(r->out.handle);
110 static WERROR dcesrv_winreg_CreateKey(struct dcesrv_call_state *dce_call,
112 struct winreg_CreateKey *r)
114 struct dcesrv_handle *h, *newh;
116 struct security_descriptor sd;
118 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
120 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
122 /* the security descriptor is optional */
123 if (r->in.secdesc != NULL) {
126 sdblob.data = r->in.secdesc->sd.data;
127 sdblob.length = r->in.secdesc->sd.len;
128 if (sdblob.data == NULL) {
129 return WERR_INVALID_PARAM;
131 status = ndr_pull_struct_blob_all(&sdblob, mem_ctx, &sd,
132 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
133 if (!NT_STATUS_IS_OK(status)) {
134 return WERR_INVALID_PARAM;
138 error = reg_key_add_name(newh, (struct registry_key *)h->data,
139 r->in.name.name, NULL, r->in.secdesc?&sd:NULL,
140 (struct registry_key **)&newh->data);
141 if (W_ERROR_IS_OK(error)) {
142 r->out.new_handle = &newh->wire_handle;
154 static WERROR dcesrv_winreg_DeleteKey(struct dcesrv_call_state *dce_call,
156 struct winreg_DeleteKey *r)
158 struct dcesrv_handle *h;
160 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
162 return reg_key_del((struct registry_key *)h->data, r->in.key.name);
169 static WERROR dcesrv_winreg_DeleteValue(struct dcesrv_call_state *dce_call,
171 struct winreg_DeleteValue *r)
173 struct dcesrv_handle *h;
174 struct registry_key *key;
176 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
180 return reg_del_value(key, r->in.value.name);
187 static WERROR dcesrv_winreg_EnumKey(struct dcesrv_call_state *dce_call,
189 struct winreg_EnumKey *r)
191 struct dcesrv_handle *h;
195 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
197 r->out.result = reg_key_get_subkey_by_index(mem_ctx,
198 (struct registry_key *)h->data,
200 &name, NULL, &last_mod);
202 if (W_ERROR_IS_OK(r->out.result)) {
203 if (2*strlen_m_term(name) > r->in.name->size) {
204 return WERR_MORE_DATA;
206 r->out.name->length = 2*strlen_m_term(name);
207 r->out.name->name = name;
208 r->out.keyclass = talloc_zero(mem_ctx, struct winreg_StringBuf);
209 if (r->in.last_changed_time) {
210 r->out.last_changed_time = &last_mod;
214 return r->out.result;
221 static WERROR dcesrv_winreg_EnumValue(struct dcesrv_call_state *dce_call,
223 struct winreg_EnumValue *r)
225 struct dcesrv_handle *h;
226 struct registry_key *key;
228 const char *data_name;
232 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
236 result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index,
239 if (!W_ERROR_IS_OK(result)) {
243 /* the client can optionally pass a NULL for type, meaning they don't
245 if (r->in.type != NULL) {
246 r->out.type = talloc(mem_ctx, enum winreg_Type);
247 *r->out.type = data_type;
250 /* check the client has enough room for the value */
251 if (r->in.value != NULL &&
252 r->in.size != NULL &&
253 data.length > *r->in.size) {
254 return WERR_MORE_DATA;
257 /* and enough room for the name */
258 if (r->in.name->size < 2*strlen_m_term(data_name)) {
259 return WERR_MORE_DATA;
262 r->out.name->name = data_name;
263 r->out.name->length = 2*strlen_m_term(data_name);
264 r->out.name->size = 2*strlen_m_term(data_name);
267 r->out.value = data.data;
271 r->out.size = talloc(mem_ctx, uint32_t);
272 *r->out.size = data.length;
273 r->out.length = r->out.size;
283 static WERROR dcesrv_winreg_FlushKey(struct dcesrv_call_state *dce_call,
285 struct winreg_FlushKey *r)
287 struct dcesrv_handle *h;
289 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
291 return reg_key_flush(h->data);
296 winreg_GetKeySecurity
298 static WERROR dcesrv_winreg_GetKeySecurity(struct dcesrv_call_state *dce_call,
300 struct winreg_GetKeySecurity *r)
302 struct dcesrv_handle *h;
304 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
306 return WERR_NOT_SUPPORTED;
313 static WERROR dcesrv_winreg_LoadKey(struct dcesrv_call_state *dce_call,
315 struct winreg_LoadKey *r)
317 return WERR_NOT_SUPPORTED;
322 winreg_NotifyChangeKeyValue
324 static WERROR dcesrv_winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call,
326 struct winreg_NotifyChangeKeyValue *r)
328 return WERR_NOT_SUPPORTED;
335 static WERROR dcesrv_winreg_OpenKey(struct dcesrv_call_state *dce_call,
337 struct winreg_OpenKey *r)
339 struct dcesrv_handle *h, *newh;
342 DCESRV_PULL_HANDLE_FAULT(h, r->in.parent_handle, HTYPE_REGKEY);
344 if (r->in.keyname.name && strcmp(r->in.keyname.name, "") == 0) {
345 newh = talloc_reference(dce_call->context, h);
348 newh = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
349 result = reg_open_key(newh, (struct registry_key *)h->data,
351 (struct registry_key **)&newh->data);
354 if (W_ERROR_IS_OK(result)) {
355 r->out.handle = &newh->wire_handle;
367 static WERROR dcesrv_winreg_QueryInfoKey(struct dcesrv_call_state *dce_call,
369 struct winreg_QueryInfoKey *r)
371 struct dcesrv_handle *h;
372 struct registry_key *k;
374 const char *classname = NULL;
376 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
380 ret = reg_key_get_info(mem_ctx, k, &classname, r->out.num_subkeys,
381 r->out.num_values, r->out.last_changed_time);
383 if (r->out.classname != NULL)
384 r->out.classname->name = classname;
393 static WERROR dcesrv_winreg_QueryValue(struct dcesrv_call_state *dce_call,
395 struct winreg_QueryValue *r)
397 struct dcesrv_handle *h;
398 struct registry_key *key;
400 DATA_BLOB value_data;
403 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
407 result = reg_key_get_value_by_name(mem_ctx, key, r->in.value_name.name,
408 &value_type, &value_data);
410 if (!W_ERROR_IS_OK(result)) {
414 /* Just asking for the size of the buffer */
415 r->out.type = talloc(mem_ctx, uint32_t);
419 *r->out.type = value_type;
420 r->out.length = talloc(mem_ctx, uint32_t);
421 if (!r->out.length) {
424 *r->out.length = value_data.length;
425 if (r->in.data == NULL) {
426 r->out.size = talloc(mem_ctx, uint32_t);
427 *r->out.size = value_data.length;
429 r->out.size = r->in.size;
430 r->out.data = value_data.data;
440 static WERROR dcesrv_winreg_ReplaceKey(struct dcesrv_call_state *dce_call,
442 struct winreg_ReplaceKey *r)
444 return WERR_NOT_SUPPORTED;
451 static WERROR dcesrv_winreg_RestoreKey(struct dcesrv_call_state *dce_call,
453 struct winreg_RestoreKey *r)
455 return WERR_NOT_SUPPORTED;
462 static WERROR dcesrv_winreg_SaveKey(struct dcesrv_call_state *dce_call,
464 struct winreg_SaveKey *r)
466 return WERR_NOT_SUPPORTED;
471 winreg_SetKeySecurity
473 static WERROR dcesrv_winreg_SetKeySecurity(struct dcesrv_call_state *dce_call,
475 struct winreg_SetKeySecurity *r)
477 return WERR_NOT_SUPPORTED;
484 static WERROR dcesrv_winreg_SetValue(struct dcesrv_call_state *dce_call,
486 struct winreg_SetValue *r)
488 struct dcesrv_handle *h;
489 struct registry_key *key;
493 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
497 data.data = r->in.data;
498 data.length = r->in.size;
499 result = reg_val_set(key, r->in.name.name, r->in.type, data);
508 static WERROR dcesrv_winreg_UnLoadKey(struct dcesrv_call_state *dce_call,
510 struct winreg_UnLoadKey *r)
512 return WERR_NOT_SUPPORTED;
517 winreg_InitiateSystemShutdown
519 static WERROR dcesrv_winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call,
521 struct winreg_InitiateSystemShutdown *r)
523 return WERR_NOT_SUPPORTED;
528 winreg_AbortSystemShutdown
530 static WERROR dcesrv_winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call,
532 struct winreg_AbortSystemShutdown *r)
534 return WERR_NOT_SUPPORTED;
541 static WERROR dcesrv_winreg_GetVersion(struct dcesrv_call_state *dce_call,
543 struct winreg_GetVersion *r)
545 struct dcesrv_handle *h;
547 DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
549 r->out.version = talloc(mem_ctx, uint32_t);
550 W_ERROR_HAVE_NO_MEMORY(r->out.version);
559 winreg_QueryMultipleValues
561 static WERROR dcesrv_winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call,
563 struct winreg_QueryMultipleValues *r)
565 return WERR_NOT_SUPPORTED;
570 winreg_InitiateSystemShutdownEx
572 static WERROR dcesrv_winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call,
574 struct winreg_InitiateSystemShutdownEx *r)
576 return WERR_NOT_SUPPORTED;
583 static WERROR dcesrv_winreg_SaveKeyEx(struct dcesrv_call_state *dce_call,
585 struct winreg_SaveKeyEx *r)
587 return WERR_NOT_SUPPORTED;
592 winreg_QueryMultipleValues2
594 static WERROR dcesrv_winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call,
596 struct winreg_QueryMultipleValues2 *r)
598 return WERR_NOT_SUPPORTED;
602 /* include the generated boilerplate */
603 #include "librpc/gen_ndr/ndr_winreg_s.c"