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 reg_close(((struct registry_key *)h->data)->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 struct dcesrv_handle *h;
213 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
214 DCESRV_CHECK_HANDLE(h);
216 return reg_key_flush(h->data);
221 winreg_GetKeySecurity
223 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
224 struct winreg_GetKeySecurity *r)
226 return WERR_NOT_SUPPORTED;
233 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
234 struct winreg_LoadKey *r)
236 return WERR_NOT_SUPPORTED;
241 winreg_NotifyChangeKeyValue
243 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
244 struct winreg_NotifyChangeKeyValue *r)
246 return WERR_NOT_SUPPORTED;
253 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
254 struct winreg_OpenKey *r)
256 struct dcesrv_handle *h, *newh;
259 h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
260 DCESRV_CHECK_HANDLE(h);
262 newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
264 result = reg_open_key(newh, (struct registry_key *)h->data,
265 r->in.keyname.name, (struct registry_key **)&newh->data);
267 if (W_ERROR_IS_OK(result)) {
268 r->out.handle = &newh->wire_handle;
270 dcesrv_handle_destroy(dce_call->conn, newh);
280 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
281 struct winreg_QueryInfoKey *r)
283 return WERR_NOT_SUPPORTED;
290 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
291 struct winreg_QueryValue *r)
293 return WERR_NOT_SUPPORTED;
300 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
301 struct winreg_ReplaceKey *r)
303 return WERR_NOT_SUPPORTED;
310 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
311 struct winreg_RestoreKey *r)
313 return WERR_NOT_SUPPORTED;
320 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
321 struct winreg_SaveKey *r)
323 return WERR_NOT_SUPPORTED;
328 winreg_SetKeySecurity
330 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
331 struct winreg_SetKeySecurity *r)
333 return WERR_NOT_SUPPORTED;
340 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
341 struct winreg_SetValue *r)
343 return WERR_NOT_SUPPORTED;
350 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
351 struct winreg_UnLoadKey *r)
353 return WERR_NOT_SUPPORTED;
358 winreg_InitiateSystemShutdown
360 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
361 struct winreg_InitiateSystemShutdown *r)
363 return WERR_NOT_SUPPORTED;
368 winreg_AbortSystemShutdown
370 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
371 struct winreg_AbortSystemShutdown *r)
373 return WERR_NOT_SUPPORTED;
380 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
381 struct winreg_GetVersion *r)
383 return WERR_NOT_SUPPORTED;
388 winreg_QueryMultipleValues
390 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
391 struct winreg_QueryMultipleValues *r)
393 return WERR_NOT_SUPPORTED;
398 winreg_InitiateSystemShutdownEx
400 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
401 struct winreg_InitiateSystemShutdownEx *r)
403 return WERR_NOT_SUPPORTED;
410 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
411 struct winreg_SaveKeyEx *r)
413 return WERR_NOT_SUPPORTED;
418 winreg_QueryMultipleValues2
420 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
421 struct winreg_QueryMultipleValues2 *r)
423 return WERR_NOT_SUPPORTED;
427 /* include the generated boilerplate */
428 #include "librpc/gen_ndr/ndr_winreg_s.c"