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"
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 void winreg_destroy_hive(struct dcesrv_connection *c, struct dcesrv_handle *h)
33 reg_close(((struct registry_key *)h->data)->hive->reg_ctx);
36 static WERROR winreg_openhive (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, const char *hivename, struct policy_handle **outh)
38 struct registry_context *ctx;
39 struct dcesrv_handle *h;
41 const char *conf = lp_parm_string(-1, "registry", hivename);
42 char *backend, *location;
45 return WERR_NOT_SUPPORTED;
48 backend = talloc_strdup(mem_ctx, conf);
49 location = strchr(backend, ':');
56 error = reg_open(&ctx, backend, location, NULL);
57 if(!W_ERROR_IS_OK(error)) return error;
59 h = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
60 h->data = ctx->hives[0]->root;
62 h->destroy = winreg_destroy_hive;
63 *outh = &h->wire_handle;
67 #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) \
69 return winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
72 func_winreg_OpenHive(HKCR,"HKEY_CLASSES_ROOT")
73 func_winreg_OpenHive(HKCU,"HKEY_CURRENT_USER")
74 func_winreg_OpenHive(HKLM,"HKEY_LOCAL_MACHINE")
75 func_winreg_OpenHive(HKPD,"HKEY_PERFORMANCE_DATA")
76 func_winreg_OpenHive(HKU,"HKEY_USERS")
77 func_winreg_OpenHive(HKCC,"HKEY_CURRENT_CONFIG")
78 func_winreg_OpenHive(HKDD,"HKEY_DYN_DATA")
79 func_winreg_OpenHive(HKPT,"HKEY_PT")
80 func_winreg_OpenHive(HKPN,"HKEY_PN")
85 static WERROR winreg_CloseKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
86 struct winreg_CloseKey *r)
88 struct dcesrv_handle *h;
90 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
91 DCESRV_CHECK_HANDLE(h);
93 dcesrv_handle_destroy(dce_call->conn, h);
102 static WERROR winreg_CreateKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
103 struct winreg_CreateKey *r)
105 struct dcesrv_handle *h, *newh;
108 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
109 DCESRV_CHECK_HANDLE(h);
111 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
113 error = reg_key_add_name(newh, (struct registry_key *)h->data, r->in.key.name,
115 r->in.sec_desc?r->in.sec_desc->sd:NULL,
116 (struct registry_key **)&newh->data);
118 if(W_ERROR_IS_OK(error)) {
119 r->out.handle = &newh->wire_handle;
121 dcesrv_handle_destroy(dce_call->conn, newh);
131 static WERROR winreg_DeleteKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
132 struct winreg_DeleteKey *r)
134 struct dcesrv_handle *h;
135 struct registry_key *key;
138 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
139 DCESRV_CHECK_HANDLE(h);
141 result = reg_open_key(mem_ctx, (struct registry_key *)h->data, r->in.key.name, &key);
143 if (W_ERROR_IS_OK(result)) {
144 return reg_key_del(key);
154 static WERROR winreg_DeleteValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
155 struct winreg_DeleteValue *r)
157 struct dcesrv_handle *h;
158 struct registry_value *value;
160 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGVAL);
161 DCESRV_CHECK_HANDLE(h);
167 return WERR_NOT_SUPPORTED;
174 static WERROR winreg_EnumKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
175 struct winreg_EnumKey *r)
177 struct dcesrv_handle *h;
178 struct registry_key *key;
180 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
181 DCESRV_CHECK_HANDLE(h);
183 r->out.result = reg_key_get_subkey_by_index(mem_ctx, (struct registry_key *)h->data, r->in.enum_index, &key);
185 if (W_ERROR_IS_OK(r->out.result)) {
186 r->out.key_name_len = strlen(key->name);
187 r->out.out_name = talloc_zero_p(mem_ctx, struct winreg_EnumKeyNameResponse);
188 r->out.out_name->name = key->name;
189 r->out.class = talloc_zero_p(mem_ctx, struct winreg_String);
190 r->out.last_changed_time = talloc_zero_p(mem_ctx, struct winreg_Time);
193 return r->out.result;
200 static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
201 struct winreg_EnumValue *r)
203 struct dcesrv_handle *h;
204 struct registry_key *key;
205 struct registry_value *value;
208 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
209 DCESRV_CHECK_HANDLE(h);
213 result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index, &value);
214 if (!W_ERROR_IS_OK(result)) {
218 r->out.type = &value->data_type;
219 r->out.name_out.name = value->name;
220 r->out.value_out = talloc_p(mem_ctx, struct EnumValueOut);
221 r->out.value_out->offset = 0;
222 r->out.value_out->buffer = data_blob_talloc(mem_ctx, value->data_blk, value->data_len);
223 r->out.value_len1 = r->in.value_len1;
224 r->out.value_len2 = r->in.value_len2;
234 static WERROR winreg_FlushKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
235 struct winreg_FlushKey *r)
237 struct dcesrv_handle *h;
239 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
240 DCESRV_CHECK_HANDLE(h);
242 return reg_key_flush(h->data);
247 winreg_GetKeySecurity
249 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
250 struct winreg_GetKeySecurity *r)
252 return WERR_NOT_SUPPORTED;
259 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
260 struct winreg_LoadKey *r)
262 return WERR_NOT_SUPPORTED;
267 winreg_NotifyChangeKeyValue
269 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
270 struct winreg_NotifyChangeKeyValue *r)
272 return WERR_NOT_SUPPORTED;
279 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
280 struct winreg_OpenKey *r)
282 struct dcesrv_handle *h, *newh;
285 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
286 DCESRV_CHECK_HANDLE(h);
288 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
290 result = reg_open_key(newh, (struct registry_key *)h->data,
291 r->in.keyname.name, (struct registry_key **)&newh->data);
293 if (W_ERROR_IS_OK(result)) {
294 r->out.handle = &newh->wire_handle;
296 dcesrv_handle_destroy(dce_call->conn, newh);
306 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
307 struct winreg_QueryInfoKey *r)
309 struct dcesrv_handle *h;
310 struct registry_key *k;
313 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
314 DCESRV_CHECK_HANDLE(h);
317 ret = reg_key_num_subkeys(k, &r->out.num_subkeys);
318 if (!W_ERROR_IS_OK(ret)) {
322 ret = reg_key_num_values(k, &r->out.num_values);
323 if (!W_ERROR_IS_OK(ret)) {
327 ret = reg_key_subkeysizes(k, &r->out.max_subkeysize, &r->out.max_subkeylen);
328 if (!W_ERROR_IS_OK(ret)) {
332 ret = reg_key_valuesizes(k, &r->out.max_valnamelen, &r->out.max_valbufsize);
333 if (!W_ERROR_IS_OK(ret)) {
337 r->out.secdescsize = 0; /* FIXME */
338 ZERO_STRUCT(r->out.last_changed_time); /* FIXME */ if (!W_ERROR_IS_OK(ret)) {
350 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
351 struct winreg_QueryValue *r)
353 return WERR_NOT_SUPPORTED;
360 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
361 struct winreg_ReplaceKey *r)
363 return WERR_NOT_SUPPORTED;
370 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
371 struct winreg_RestoreKey *r)
373 return WERR_NOT_SUPPORTED;
380 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
381 struct winreg_SaveKey *r)
383 return WERR_NOT_SUPPORTED;
388 winreg_SetKeySecurity
390 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
391 struct winreg_SetKeySecurity *r)
393 return WERR_NOT_SUPPORTED;
400 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
401 struct winreg_SetValue *r)
403 return WERR_NOT_SUPPORTED;
410 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
411 struct winreg_UnLoadKey *r)
413 return WERR_NOT_SUPPORTED;
418 winreg_InitiateSystemShutdown
420 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
421 struct winreg_InitiateSystemShutdown *r)
423 return WERR_NOT_SUPPORTED;
428 winreg_AbortSystemShutdown
430 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
431 struct winreg_AbortSystemShutdown *r)
433 return WERR_NOT_SUPPORTED;
440 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
441 struct winreg_GetVersion *r)
449 winreg_QueryMultipleValues
451 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
452 struct winreg_QueryMultipleValues *r)
454 return WERR_NOT_SUPPORTED;
459 winreg_InitiateSystemShutdownEx
461 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
462 struct winreg_InitiateSystemShutdownEx *r)
464 return WERR_NOT_SUPPORTED;
471 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
472 struct winreg_SaveKeyEx *r)
474 return WERR_NOT_SUPPORTED;
479 winreg_QueryMultipleValues2
481 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
482 struct winreg_QueryMultipleValues2 *r)
484 return WERR_NOT_SUPPORTED;
488 /* include the generated boilerplate */
489 #include "librpc/gen_ndr/ndr_winreg_s.c"