r3348: More registry fixes and additions. The following functions work right now...
[kai/samba-autobuild/.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         /* FIXME: Free ((struct registry_key *)h->data)->root->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         return WERR_NOT_SUPPORTED;
212 }
213
214
215 /* 
216   winreg_GetKeySecurity 
217 */
218 static WERROR winreg_GetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
219                        struct winreg_GetKeySecurity *r)
220 {
221         return WERR_NOT_SUPPORTED;
222 }
223
224
225 /* 
226   winreg_LoadKey 
227 */
228 static WERROR winreg_LoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
229                        struct winreg_LoadKey *r)
230 {
231         return WERR_NOT_SUPPORTED;
232 }
233
234
235 /* 
236   winreg_NotifyChangeKeyValue 
237 */
238 static WERROR winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
239                        struct winreg_NotifyChangeKeyValue *r)
240 {
241         return WERR_NOT_SUPPORTED;
242 }
243
244
245 /* 
246   winreg_OpenKey 
247 */
248 static WERROR winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
249                        struct winreg_OpenKey *r)
250 {
251         struct dcesrv_handle *h, *newh;
252         WERROR result;
253
254         h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
255         DCESRV_CHECK_HANDLE(h);
256
257         newh = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
258
259         result = reg_open_key(newh, (struct registry_key *)h->data, 
260                                 r->in.keyname.name, (struct registry_key **)&newh->data);
261
262         if (W_ERROR_IS_OK(result)) {
263                 r->out.handle = &newh->wire_handle; 
264         } else {
265                 dcesrv_handle_destroy(dce_call->conn, newh);
266         }
267         
268         return result;
269 }
270
271
272 /* 
273   winreg_QueryInfoKey 
274 */
275 static WERROR winreg_QueryInfoKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
276                        struct winreg_QueryInfoKey *r)
277 {
278         return WERR_NOT_SUPPORTED;
279 }
280
281
282 /* 
283   winreg_QueryValue 
284 */
285 static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
286                        struct winreg_QueryValue *r)
287 {
288         return WERR_NOT_SUPPORTED;
289 }
290
291
292 /* 
293   winreg_ReplaceKey 
294 */
295 static WERROR winreg_ReplaceKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
296                        struct winreg_ReplaceKey *r)
297 {
298         return WERR_NOT_SUPPORTED;
299 }
300
301
302 /* 
303   winreg_RestoreKey 
304 */
305 static WERROR winreg_RestoreKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
306                        struct winreg_RestoreKey *r)
307 {
308         return WERR_NOT_SUPPORTED;
309 }
310
311
312 /* 
313   winreg_SaveKey 
314 */
315 static WERROR winreg_SaveKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
316                        struct winreg_SaveKey *r)
317 {
318         return WERR_NOT_SUPPORTED;
319 }
320
321
322 /* 
323   winreg_SetKeySecurity 
324 */
325 static WERROR winreg_SetKeySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
326                        struct winreg_SetKeySecurity *r)
327 {
328         return WERR_NOT_SUPPORTED;
329 }
330
331
332 /* 
333   winreg_SetValue 
334 */
335 static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
336                        struct winreg_SetValue *r)
337 {
338         return WERR_NOT_SUPPORTED;
339 }
340
341
342 /* 
343   winreg_UnLoadKey 
344 */
345 static WERROR winreg_UnLoadKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
346                        struct winreg_UnLoadKey *r)
347 {
348         return WERR_NOT_SUPPORTED;
349 }
350
351
352 /* 
353   winreg_InitiateSystemShutdown 
354 */
355 static WERROR winreg_InitiateSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
356                        struct winreg_InitiateSystemShutdown *r)
357 {
358         return WERR_NOT_SUPPORTED;
359 }
360
361
362 /* 
363   winreg_AbortSystemShutdown 
364 */
365 static WERROR winreg_AbortSystemShutdown(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
366                        struct winreg_AbortSystemShutdown *r)
367 {
368         return WERR_NOT_SUPPORTED;
369 }
370
371
372 /* 
373   winreg_GetVersion 
374 */
375 static WERROR winreg_GetVersion(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
376                        struct winreg_GetVersion *r)
377 {
378         return WERR_NOT_SUPPORTED;
379 }
380
381
382 /* 
383   winreg_QueryMultipleValues 
384 */
385 static WERROR winreg_QueryMultipleValues(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
386                        struct winreg_QueryMultipleValues *r)
387 {
388         return WERR_NOT_SUPPORTED;
389 }
390
391
392 /* 
393   winreg_InitiateSystemShutdownEx 
394 */
395 static WERROR winreg_InitiateSystemShutdownEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
396                        struct winreg_InitiateSystemShutdownEx *r)
397 {
398         return WERR_NOT_SUPPORTED;
399 }
400
401
402 /* 
403   winreg_SaveKeyEx 
404 */
405 static WERROR winreg_SaveKeyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
406                        struct winreg_SaveKeyEx *r)
407 {
408         return WERR_NOT_SUPPORTED;
409 }
410
411
412 /* 
413   winreg_QueryMultipleValues2 
414 */
415 static WERROR winreg_QueryMultipleValues2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
416                        struct winreg_QueryMultipleValues2 *r)
417 {
418         return WERR_NOT_SUPPORTED;
419 }
420
421
422 /* include the generated boilerplate */
423 #include "librpc/gen_ndr/ndr_winreg_s.c"