r3367: More registry updates.
[kai/samba.git] / source4 / rpc_server / winreg / rpc_winreg.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    endpoint server for the winreg pipe
5
6    Copyright (C) Jelmer Vernooij 2004
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "rpc_server/common/common.h"
25
26 enum handle_types { HTYPE_REGVAL, HTYPE_REGKEY };
27
28 static void winreg_destroy_hive(struct dcesrv_connection *c, struct dcesrv_handle *h)
29 {
30         reg_close(((struct registry_key *)h->data)->hive->reg_ctx);
31 }
32
33 static WERROR winreg_openhive (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, const char *hivename, struct policy_handle **outh)
34 {
35         struct registry_context *ctx;
36         struct dcesrv_handle *h; 
37         WERROR error;
38         const char *conf = lp_parm_string(-1, "registry", hivename);
39         char *backend, *location;
40         
41         if (!conf) {
42                 return WERR_NOT_SUPPORTED;
43         }
44
45         backend = talloc_strdup(mem_ctx, conf);
46         location = strchr(backend, ':');
47
48         if (location) {
49                 *location = '\0';
50                 location++;
51         }
52
53         error = reg_open(&ctx, backend, location, NULL); 
54         if(!W_ERROR_IS_OK(error)) return error; 
55         
56         h = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY); 
57         h->data = ctx->hives[0]->root; 
58         SMB_ASSERT(h->data);
59         h->destroy = winreg_destroy_hive;
60         *outh = &h->wire_handle; 
61         return WERR_OK; 
62 }
63
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) \
65 { \
66         return winreg_openhive (dce_call, mem_ctx, n, &r->out.handle);\
67 }
68
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")
78
79 /* 
80   winreg_CloseKey 
81 */
82 static WERROR winreg_CloseKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
83                        struct winreg_CloseKey *r)
84 {
85         struct dcesrv_handle *h; 
86
87         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
88         DCESRV_CHECK_HANDLE(h);
89
90         dcesrv_handle_destroy(dce_call->conn, h);
91
92         return WERR_OK;
93 }
94
95
96 /* 
97   winreg_CreateKey 
98 */
99 static WERROR winreg_CreateKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
100                        struct winreg_CreateKey *r)
101 {
102         struct dcesrv_handle *h, *newh;
103         WERROR error;
104
105         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
106         DCESRV_CHECK_HANDLE(h);
107         
108         newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
109
110         error = reg_key_add_name(newh, (struct registry_key *)h->data, r->in.key.name, 
111                                                          r->in.access_mask, 
112                                                          r->in.sec_desc?r->in.sec_desc->sd:NULL, 
113                                                          (struct registry_key **)&newh->data);
114
115         if(W_ERROR_IS_OK(error)) {
116                 r->out.handle = &newh->wire_handle;
117         } else {
118                 dcesrv_handle_destroy(dce_call->conn, newh);
119         }
120
121         return error;
122 }
123
124
125 /* 
126   winreg_DeleteKey 
127 */
128 static WERROR winreg_DeleteKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
129                        struct winreg_DeleteKey *r)
130 {
131         struct dcesrv_handle *h;
132         struct registry_key *key;
133         WERROR result;
134
135         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
136         DCESRV_CHECK_HANDLE(h);
137
138         result = reg_open_key(mem_ctx, (struct registry_key *)h->data, r->in.key.name, &key);
139
140         if (W_ERROR_IS_OK(result)) {
141                 return reg_key_del(key);
142         }
143
144         return result;
145 }
146
147
148 /* 
149   winreg_DeleteValue 
150 */
151 static WERROR winreg_DeleteValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
152                        struct winreg_DeleteValue *r)
153 {
154         struct dcesrv_handle *h;
155         struct registry_value *value;
156
157         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGVAL);
158         DCESRV_CHECK_HANDLE(h);
159
160         value = h->data;
161         
162         /* FIXME */
163
164         return WERR_NOT_SUPPORTED;
165 }
166
167
168 /* 
169   winreg_EnumKey 
170 */
171 static WERROR winreg_EnumKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
172                        struct winreg_EnumKey *r)
173 {
174         struct dcesrv_handle *h;
175         struct registry_key *key;
176
177         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
178         DCESRV_CHECK_HANDLE(h);
179
180         r->out.result = reg_key_get_subkey_by_index(mem_ctx, (struct registry_key *)h->data, r->in.enum_index, &key);
181
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);
188         }
189         
190         return r->out.result;
191 }
192
193
194 /* 
195   winreg_EnumValue 
196 */
197 static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
198                        struct winreg_EnumValue *r)
199 {
200
201         return WERR_NOT_SUPPORTED;
202 }
203
204
205 /* 
206   winreg_FlushKey 
207 */
208 static WERROR winreg_FlushKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
209                        struct winreg_FlushKey *r)
210 {
211         struct dcesrv_handle *h;
212
213         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
214         DCESRV_CHECK_HANDLE(h);
215
216         return reg_key_flush(h->data);
217 }
218
219
220 /* 
221   winreg_GetKeySecurity 
222 */
223 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
224                        struct winreg_GetKeySecurity *r)
225 {
226         return WERR_NOT_SUPPORTED;
227 }
228
229
230 /* 
231   winreg_LoadKey 
232 */
233 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
234                        struct winreg_LoadKey *r)
235 {
236         return WERR_NOT_SUPPORTED;
237 }
238
239
240 /* 
241   winreg_NotifyChangeKeyValue 
242 */
243 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
244                        struct winreg_NotifyChangeKeyValue *r)
245 {
246         return WERR_NOT_SUPPORTED;
247 }
248
249
250 /* 
251   winreg_OpenKey 
252 */
253 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
254                        struct winreg_OpenKey *r)
255 {
256         struct dcesrv_handle *h, *newh;
257         WERROR result;
258
259         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
260         DCESRV_CHECK_HANDLE(h);
261
262         newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
263
264         result = reg_open_key(newh, (struct registry_key *)h->data, 
265                                 r->in.keyname.name, (struct registry_key **)&newh->data);
266
267         if (W_ERROR_IS_OK(result)) {
268                 r->out.handle = &newh->wire_handle; 
269         } else {
270                 dcesrv_handle_destroy(dce_call->conn, newh);
271         }
272         
273         return result;
274 }
275
276
277 /* 
278   winreg_QueryInfoKey 
279 */
280 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
281                        struct winreg_QueryInfoKey *r)
282 {
283         return WERR_NOT_SUPPORTED;
284 }
285
286
287 /* 
288   winreg_QueryValue 
289 */
290 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
291                        struct winreg_QueryValue *r)
292 {
293         return WERR_NOT_SUPPORTED;
294 }
295
296
297 /* 
298   winreg_ReplaceKey 
299 */
300 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
301                        struct winreg_ReplaceKey *r)
302 {
303         return WERR_NOT_SUPPORTED;
304 }
305
306
307 /* 
308   winreg_RestoreKey 
309 */
310 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
311                        struct winreg_RestoreKey *r)
312 {
313         return WERR_NOT_SUPPORTED;
314 }
315
316
317 /* 
318   winreg_SaveKey 
319 */
320 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
321                        struct winreg_SaveKey *r)
322 {
323         return WERR_NOT_SUPPORTED;
324 }
325
326
327 /* 
328   winreg_SetKeySecurity 
329 */
330 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
331                        struct winreg_SetKeySecurity *r)
332 {
333         return WERR_NOT_SUPPORTED;
334 }
335
336
337 /* 
338   winreg_SetValue 
339 */
340 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
341                        struct winreg_SetValue *r)
342 {
343         return WERR_NOT_SUPPORTED;
344 }
345
346
347 /* 
348   winreg_UnLoadKey 
349 */
350 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
351                        struct winreg_UnLoadKey *r)
352 {
353         return WERR_NOT_SUPPORTED;
354 }
355
356
357 /* 
358   winreg_InitiateSystemShutdown 
359 */
360 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
361                        struct winreg_InitiateSystemShutdown *r)
362 {
363         return WERR_NOT_SUPPORTED;
364 }
365
366
367 /* 
368   winreg_AbortSystemShutdown 
369 */
370 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
371                        struct winreg_AbortSystemShutdown *r)
372 {
373         return WERR_NOT_SUPPORTED;
374 }
375
376
377 /* 
378   winreg_GetVersion 
379 */
380 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
381                        struct winreg_GetVersion *r)
382 {
383         return WERR_NOT_SUPPORTED;
384 }
385
386
387 /* 
388   winreg_QueryMultipleValues 
389 */
390 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
391                        struct winreg_QueryMultipleValues *r)
392 {
393         return WERR_NOT_SUPPORTED;
394 }
395
396
397 /* 
398   winreg_InitiateSystemShutdownEx 
399 */
400 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
401                        struct winreg_InitiateSystemShutdownEx *r)
402 {
403         return WERR_NOT_SUPPORTED;
404 }
405
406
407 /* 
408   winreg_SaveKeyEx 
409 */
410 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
411                        struct winreg_SaveKeyEx *r)
412 {
413         return WERR_NOT_SUPPORTED;
414 }
415
416
417 /* 
418   winreg_QueryMultipleValues2 
419 */
420 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
421                        struct winreg_QueryMultipleValues2 *r)
422 {
423         return WERR_NOT_SUPPORTED;
424 }
425
426
427 /* include the generated boilerplate */
428 #include "librpc/gen_ndr/ndr_winreg_s.c"