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 NTSTATUS dcerpc_winreg_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
33 struct registry_context *ctx;
36 dce_call->conn->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->conn->private;
46 struct dcesrv_handle *h;
49 h = dcesrv_handle_new(dce_call->conn, 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 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
85 DCESRV_CHECK_HANDLE(h);
87 dcesrv_handle_destroy(dce_call->conn, h);
96 static WERROR winreg_CreateKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
97 struct winreg_CreateKey *r)
99 struct dcesrv_handle *h, *newh;
102 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
103 DCESRV_CHECK_HANDLE(h);
105 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
107 error = reg_key_add_name(newh, (struct registry_key *)h->data, r->in.key.name,
109 r->in.sec_desc?r->in.sec_desc->sd:NULL,
110 (struct registry_key **)&newh->data);
112 if(W_ERROR_IS_OK(error)) {
113 r->out.handle = &newh->wire_handle;
115 dcesrv_handle_destroy(dce_call->conn, newh);
125 static WERROR winreg_DeleteKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
126 struct winreg_DeleteKey *r)
128 struct dcesrv_handle *h;
129 struct registry_key *key;
132 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
133 DCESRV_CHECK_HANDLE(h);
135 result = reg_open_key(mem_ctx, (struct registry_key *)h->data, r->in.key.name, &key);
137 if (W_ERROR_IS_OK(result)) {
138 return reg_key_del(key);
148 static WERROR winreg_DeleteValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
149 struct winreg_DeleteValue *r)
151 struct dcesrv_handle *h;
152 struct registry_value *value;
154 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGVAL);
155 DCESRV_CHECK_HANDLE(h);
161 return WERR_NOT_SUPPORTED;
168 static WERROR winreg_EnumKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
169 struct winreg_EnumKey *r)
171 struct dcesrv_handle *h;
172 struct registry_key *key;
174 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
175 DCESRV_CHECK_HANDLE(h);
177 r->out.result = reg_key_get_subkey_by_index(mem_ctx, (struct registry_key *)h->data, r->in.enum_index, &key);
179 if (W_ERROR_IS_OK(r->out.result)) {
180 r->out.key_name_len = strlen(key->name);
181 r->out.out_name = talloc_zero_p(mem_ctx, struct winreg_EnumKeyNameResponse);
182 r->out.out_name->name = key->name;
183 r->out.class = talloc_zero_p(mem_ctx, struct winreg_String);
184 r->out.last_changed_time = talloc_zero_p(mem_ctx, struct winreg_Time);
187 return r->out.result;
194 static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
195 struct winreg_EnumValue *r)
197 struct dcesrv_handle *h;
198 struct registry_key *key;
199 struct registry_value *value;
202 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
203 DCESRV_CHECK_HANDLE(h);
207 result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index, &value);
208 if (!W_ERROR_IS_OK(result)) {
212 r->out.type = talloc_p(mem_ctx, uint32_t);
213 *r->out.type = value->data_type;
214 r->out.name_out.name = value->name;
215 r->out.value = value->data_blk;
216 r->out.size = talloc_p(mem_ctx, uint32_t);
217 r->out.length = r->out.size;
218 *r->out.size = value->data_len;
227 static WERROR winreg_FlushKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
228 struct winreg_FlushKey *r)
230 struct dcesrv_handle *h;
232 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
233 DCESRV_CHECK_HANDLE(h);
235 return reg_key_flush(h->data);
240 winreg_GetKeySecurity
242 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
243 struct winreg_GetKeySecurity *r)
245 return WERR_NOT_SUPPORTED;
252 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
253 struct winreg_LoadKey *r)
255 return WERR_NOT_SUPPORTED;
260 winreg_NotifyChangeKeyValue
262 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
263 struct winreg_NotifyChangeKeyValue *r)
265 return WERR_NOT_SUPPORTED;
272 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
273 struct winreg_OpenKey *r)
275 struct dcesrv_handle *h, *newh;
278 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
279 DCESRV_CHECK_HANDLE(h);
281 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
283 result = reg_open_key(newh, (struct registry_key *)h->data,
284 r->in.keyname.name, (struct registry_key **)&newh->data);
286 if (W_ERROR_IS_OK(result)) {
287 r->out.handle = &newh->wire_handle;
289 dcesrv_handle_destroy(dce_call->conn, newh);
299 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
300 struct winreg_QueryInfoKey *r)
302 struct dcesrv_handle *h;
303 struct registry_key *k;
306 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
307 DCESRV_CHECK_HANDLE(h);
310 ret = reg_key_num_subkeys(k, &r->out.num_subkeys);
311 if (!W_ERROR_IS_OK(ret)) {
315 ret = reg_key_num_values(k, &r->out.num_values);
316 if (!W_ERROR_IS_OK(ret)) {
320 ret = reg_key_subkeysizes(k, &r->out.max_subkeysize, &r->out.max_subkeylen);
321 if (!W_ERROR_IS_OK(ret)) {
325 ret = reg_key_valuesizes(k, &r->out.max_valnamelen, &r->out.max_valbufsize);
326 if (!W_ERROR_IS_OK(ret)) {
330 r->out.secdescsize = 0; /* FIXME */
331 ZERO_STRUCT(r->out.last_changed_time); /* FIXME */ if (!W_ERROR_IS_OK(ret)) {
343 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
344 struct winreg_QueryValue *r)
346 return WERR_NOT_SUPPORTED;
353 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
354 struct winreg_ReplaceKey *r)
356 return WERR_NOT_SUPPORTED;
363 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
364 struct winreg_RestoreKey *r)
366 return WERR_NOT_SUPPORTED;
373 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
374 struct winreg_SaveKey *r)
376 return WERR_NOT_SUPPORTED;
381 winreg_SetKeySecurity
383 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
384 struct winreg_SetKeySecurity *r)
386 return WERR_NOT_SUPPORTED;
393 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
394 struct winreg_SetValue *r)
396 return WERR_NOT_SUPPORTED;
403 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
404 struct winreg_UnLoadKey *r)
406 return WERR_NOT_SUPPORTED;
411 winreg_InitiateSystemShutdown
413 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
414 struct winreg_InitiateSystemShutdown *r)
416 return WERR_NOT_SUPPORTED;
421 winreg_AbortSystemShutdown
423 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
424 struct winreg_AbortSystemShutdown *r)
426 return WERR_NOT_SUPPORTED;
433 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
434 struct winreg_GetVersion *r)
442 winreg_QueryMultipleValues
444 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
445 struct winreg_QueryMultipleValues *r)
447 return WERR_NOT_SUPPORTED;
452 winreg_InitiateSystemShutdownEx
454 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
455 struct winreg_InitiateSystemShutdownEx *r)
457 return WERR_NOT_SUPPORTED;
464 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
465 struct winreg_SaveKeyEx *r)
467 return WERR_NOT_SUPPORTED;
472 winreg_QueryMultipleValues2
474 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
475 struct winreg_QueryMultipleValues2 *r)
477 return WERR_NOT_SUPPORTED;
481 /* include the generated boilerplate */
482 #include "librpc/gen_ndr/ndr_winreg_s.c"