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/common/common.h"
26 enum handle_types { HTYPE_REGVAL, HTYPE_REGKEY };
28 static void winreg_destroy_hive(struct dcesrv_connection *c, struct dcesrv_handle *h)
30 /* FIXME: Free ((struct registry_key *)h->data)->root->hive->reg_ctx */
33 static WERROR winreg_openhive (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, const char *hivename, struct policy_handle **outh)
35 struct registry_context *ctx;
36 struct dcesrv_handle *h;
38 const char *conf = lp_parm_string(-1, "registry", hivename);
39 char *backend, *location;
42 return WERR_NOT_SUPPORTED;
45 backend = talloc_strdup(mem_ctx, conf);
46 location = strchr(backend, ':');
53 error = reg_open(&ctx, backend, location, NULL);
54 if(!W_ERROR_IS_OK(error)) return error;
56 h = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
57 h->data = ctx->hives[0]->root;
59 h->destroy = winreg_destroy_hive;
60 *outh = &h->wire_handle;
64 #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) \
66 return winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
69 func_winreg_OpenHive(HKCR,"HKEY_CLASSES_ROOT")
70 func_winreg_OpenHive(HKCU,"HKEY_CURRENT_USER")
71 func_winreg_OpenHive(HKLM,"HKEY_LOCAL_MACHINE")
72 func_winreg_OpenHive(HKPD,"HKEY_PERFORMANCE_DATA")
73 func_winreg_OpenHive(HKU,"HKEY_USERS")
74 func_winreg_OpenHive(HKCC,"HKEY_CC")
75 func_winreg_OpenHive(HKDD,"HKEY_DD")
76 func_winreg_OpenHive(HKPT,"HKEY_PT")
77 func_winreg_OpenHive(HKPN,"HKEY_PN")
82 static WERROR winreg_CloseKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
83 struct winreg_CloseKey *r)
85 struct dcesrv_handle *h;
87 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
88 DCESRV_CHECK_HANDLE(h);
90 dcesrv_handle_destroy(dce_call->conn, h);
99 static WERROR winreg_CreateKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
100 struct winreg_CreateKey *r)
102 struct dcesrv_handle *h, *newh;
105 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
106 DCESRV_CHECK_HANDLE(h);
108 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
110 error = reg_key_add_name(newh, (struct registry_key *)h->data, r->in.key.name,
112 r->in.sec_desc?r->in.sec_desc->sd:NULL,
113 (struct registry_key **)&newh->data);
115 if(W_ERROR_IS_OK(error)) {
116 r->out.handle = &newh->wire_handle;
118 dcesrv_handle_destroy(dce_call->conn, newh);
128 static WERROR winreg_DeleteKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
129 struct winreg_DeleteKey *r)
131 struct dcesrv_handle *h;
132 struct registry_key *key;
135 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
136 DCESRV_CHECK_HANDLE(h);
138 result = reg_open_key(mem_ctx, (struct registry_key *)h->data, r->in.key.name, &key);
140 if (W_ERROR_IS_OK(result)) {
141 return reg_key_del(key);
151 static WERROR winreg_DeleteValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
152 struct winreg_DeleteValue *r)
154 struct dcesrv_handle *h;
155 struct registry_value *value;
157 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGVAL);
158 DCESRV_CHECK_HANDLE(h);
164 return WERR_NOT_SUPPORTED;
171 static WERROR winreg_EnumKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
172 struct winreg_EnumKey *r)
174 struct dcesrv_handle *h;
175 struct registry_key *key;
177 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
178 DCESRV_CHECK_HANDLE(h);
180 r->out.result = reg_key_get_subkey_by_index(mem_ctx, (struct registry_key *)h->data, r->in.enum_index, &key);
182 if (W_ERROR_IS_OK(r->out.result)) {
183 r->out.key_name_len = strlen(key->name);
184 r->out.out_name = talloc_zero_p(mem_ctx, struct winreg_EnumKeyNameResponse);
185 r->out.out_name->name = key->name;
186 r->out.class = talloc_zero_p(mem_ctx, struct winreg_String);
187 r->out.last_changed_time = talloc_zero_p(mem_ctx, struct winreg_Time);
190 return r->out.result;
197 static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
198 struct winreg_EnumValue *r)
201 return WERR_NOT_SUPPORTED;
208 static WERROR winreg_FlushKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
209 struct winreg_FlushKey *r)
211 return WERR_NOT_SUPPORTED;
216 winreg_GetKeySecurity
218 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
219 struct winreg_GetKeySecurity *r)
221 return WERR_NOT_SUPPORTED;
228 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
229 struct winreg_LoadKey *r)
231 return WERR_NOT_SUPPORTED;
236 winreg_NotifyChangeKeyValue
238 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
239 struct winreg_NotifyChangeKeyValue *r)
241 return WERR_NOT_SUPPORTED;
248 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
249 struct winreg_OpenKey *r)
251 struct dcesrv_handle *h, *newh;
254 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
255 DCESRV_CHECK_HANDLE(h);
257 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
259 result = reg_open_key(newh, (struct registry_key *)h->data,
260 r->in.keyname.name, (struct registry_key **)&newh->data);
262 if (W_ERROR_IS_OK(result)) {
263 r->out.handle = &newh->wire_handle;
265 dcesrv_handle_destroy(dce_call->conn, newh);
275 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
276 struct winreg_QueryInfoKey *r)
278 return WERR_NOT_SUPPORTED;
285 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
286 struct winreg_QueryValue *r)
288 return WERR_NOT_SUPPORTED;
295 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
296 struct winreg_ReplaceKey *r)
298 return WERR_NOT_SUPPORTED;
305 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
306 struct winreg_RestoreKey *r)
308 return WERR_NOT_SUPPORTED;
315 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
316 struct winreg_SaveKey *r)
318 return WERR_NOT_SUPPORTED;
323 winreg_SetKeySecurity
325 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
326 struct winreg_SetKeySecurity *r)
328 return WERR_NOT_SUPPORTED;
335 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
336 struct winreg_SetValue *r)
338 return WERR_NOT_SUPPORTED;
345 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
346 struct winreg_UnLoadKey *r)
348 return WERR_NOT_SUPPORTED;
353 winreg_InitiateSystemShutdown
355 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
356 struct winreg_InitiateSystemShutdown *r)
358 return WERR_NOT_SUPPORTED;
363 winreg_AbortSystemShutdown
365 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
366 struct winreg_AbortSystemShutdown *r)
368 return WERR_NOT_SUPPORTED;
375 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
376 struct winreg_GetVersion *r)
378 return WERR_NOT_SUPPORTED;
383 winreg_QueryMultipleValues
385 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
386 struct winreg_QueryMultipleValues *r)
388 return WERR_NOT_SUPPORTED;
393 winreg_InitiateSystemShutdownEx
395 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
396 struct winreg_InitiateSystemShutdownEx *r)
398 return WERR_NOT_SUPPORTED;
405 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
406 struct winreg_SaveKeyEx *r)
408 return WERR_NOT_SUPPORTED;
413 winreg_QueryMultipleValues2
415 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
416 struct winreg_QueryMultipleValues2 *r)
418 return WERR_NOT_SUPPORTED;
422 /* include the generated boilerplate */
423 #include "librpc/gen_ndr/ndr_winreg_s.c"