r5037: got rid of all of the TALLOC_DEPRECATED stuff. My apologies for the
[bbaumbach/samba-autobuild/.git] / source4 / torture / rpc / winreg.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for winreg rpc operations
4
5    Copyright (C) Tim Potter 2003
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 "librpc/gen_ndr/ndr_winreg.h"
25
26 static void init_winreg_String(struct winreg_String *name, const char *s)
27 {
28         name->name = s;
29         if (s) {
30                 name->name_len = 2 * (strlen_m(s) + 1);
31                 name->name_size = name->name_len;
32         } else {
33                 name->name_len = 0;
34                 name->name_size = 0;
35         }
36 }
37
38 static BOOL test_GetVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
39                             struct policy_handle *handle)
40 {
41         NTSTATUS status;
42         struct winreg_GetVersion r;
43
44         printf("\ntesting GetVersion\n");
45
46         r.in.handle = handle;
47
48         status = dcerpc_winreg_GetVersion(p, mem_ctx, &r);
49
50         if (!NT_STATUS_IS_OK(status)) {
51                 printf("GetVersion failed - %s\n", nt_errstr(status));
52                 return False;
53         }
54
55         if (!W_ERROR_IS_OK(r.out.result)) {
56                 printf("GetVersion failed - %s\n", win_errstr(r.out.result));
57                 return False;
58         }
59
60         return True;
61 }
62
63 static BOOL test_NotifyChangeKeyValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
64                                                                           struct policy_handle *handle)
65 {
66         struct winreg_NotifyChangeKeyValue r;
67         NTSTATUS status;
68
69         printf("\ntesting NotifyChangeKeyValue\n");
70
71         r.in.handle = handle;
72         r.in.watch_subtree = 1;
73         r.in.notify_filter = 0;
74         r.in.unknown = r.in.unknown2 = 0;
75         init_winreg_String(&r.in.string1, NULL);
76         init_winreg_String(&r.in.string2, NULL);
77
78         status = dcerpc_winreg_NotifyChangeKeyValue(p, mem_ctx, &r);
79         
80         if (!NT_STATUS_IS_OK(status)) {
81                 printf("NotifyChangeKeyValue failed - %s\n", nt_errstr(status));
82                 return False;
83         }
84
85         if (!W_ERROR_IS_OK(r.out.result)) {
86                 printf("NotifyChangeKeyValue failed - %s\n", win_errstr(r.out.result));
87                 return False;
88         }
89
90         return True;
91 }
92
93 static BOOL test_CreateKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
94                           struct policy_handle *handle, const char *name, 
95                            const char *class)
96 {
97         struct winreg_CreateKey r;
98         struct policy_handle newhandle;
99         NTSTATUS status;
100         uint32_t action_taken = 0;
101
102         printf("\ntesting CreateKey\n");
103
104         r.in.handle = handle;
105         r.out.handle = &newhandle;
106         init_winreg_String(&r.in.key, name);    
107         init_winreg_String(&r.in.class, class);
108         r.in.options = 0x0;
109         r.in.access_mask = 0x02000000;
110         r.in.action_taken = r.out.action_taken = &action_taken;
111         r.in.sec_desc = NULL;
112
113         status = dcerpc_winreg_CreateKey(p, mem_ctx, &r);
114
115         if (!NT_STATUS_IS_OK(status)) {
116                 printf("CreateKey failed - %s\n", nt_errstr(status));
117                 return False;
118         }
119
120         if (!W_ERROR_IS_OK(r.out.result)) {
121                 printf("CreateKey failed - %s\n", win_errstr(r.out.result));
122                 return False;
123         }
124
125         return True;
126 }
127
128 static BOOL test_GetKeySecurity(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
129                           struct policy_handle *handle)
130 {
131         NTSTATUS status;
132         struct winreg_GetKeySecurity r;
133
134         printf("\ntesting GetKeySecurity\n");
135
136         ZERO_STRUCT(r);
137
138         r.in.handle = handle;
139         r.in.data = r.out.data =  talloc_zero(mem_ctx, struct KeySecurityData);
140         r.in.data->size = 0xffff;
141         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
142
143         status = dcerpc_winreg_GetKeySecurity(p, mem_ctx, &r);
144
145         if (!NT_STATUS_IS_OK(status)) {
146                 printf("GetKeySecurity failed - %s\n", nt_errstr(status));
147                 return False;
148         }
149
150         if (!W_ERROR_IS_OK(r.out.result)) {
151                 printf("GetKeySecurity failed - %s\n", win_errstr(r.out.result));
152                 return False;
153         }
154
155         return False;
156 }
157
158 static BOOL test_CloseKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
159                           struct policy_handle *handle)
160 {
161         NTSTATUS status;
162         struct winreg_CloseKey r;
163
164         printf("\ntesting CloseKey\n");
165
166         r.in.handle = r.out.handle = handle;
167
168         status = dcerpc_winreg_CloseKey(p, mem_ctx, &r);
169
170         if (!NT_STATUS_IS_OK(status)) {
171                 printf("CloseKey failed - %s\n", nt_errstr(status));
172                 return False;
173         }
174
175         if (!W_ERROR_IS_OK(r.out.result)) {
176                 printf("CloseKey failed - %s\n", win_errstr(r.out.result));
177                 return False;
178         }
179
180         return True;
181 }
182
183 static BOOL test_FlushKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
184                           struct policy_handle *handle)
185 {
186         NTSTATUS status;
187         struct winreg_FlushKey r;
188
189         printf("\ntesting FlushKey\n");
190
191         r.in.handle = handle;
192
193         status = dcerpc_winreg_FlushKey(p, mem_ctx, &r);
194
195         if (!NT_STATUS_IS_OK(status)) {
196                 printf("FlushKey failed - %s\n", nt_errstr(status));
197                 return False;
198         }
199
200         if (!W_ERROR_IS_OK(r.out.result)) {
201                 printf("FlushKey failed - %s\n", win_errstr(r.out.result));
202                 return False;
203         }
204
205         return True;
206 }
207
208 static BOOL test_OpenKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
209                          struct policy_handle *hive_handle,
210                          const char *keyname, struct policy_handle *key_handle)
211 {
212         NTSTATUS status;
213         struct winreg_OpenKey r;
214
215         printf("\ntesting OpenKey\n");
216
217         r.in.handle = hive_handle;
218         init_winreg_String(&r.in.keyname, keyname);
219         r.in.unknown = 0x00000000;
220         r.in.access_mask = 0x02000000;
221         r.out.handle = key_handle;
222
223         status = dcerpc_winreg_OpenKey(p, mem_ctx, &r);
224
225         if (!NT_STATUS_IS_OK(status)) {
226                 printf("OpenKey failed - %s\n", nt_errstr(status));
227                 return False;
228         }
229
230         if (!W_ERROR_IS_OK(r.out.result)) {
231                 printf("OpenKey failed - %s\n", win_errstr(r.out.result));
232
233                 return False;
234         }
235
236         return True;
237 }
238
239 static BOOL test_DeleteKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
240                            struct policy_handle *handle, const char *key)
241 {
242         NTSTATUS status;
243         struct winreg_DeleteKey r;
244
245         printf("\ntesting DeleteKey\n");
246
247         r.in.handle = handle;
248         init_winreg_String(&r.in.key, key);     
249
250         status = dcerpc_winreg_DeleteKey(p, mem_ctx, &r);
251
252         if (!NT_STATUS_IS_OK(status)) {
253                 printf("DeleteKey failed - %s\n", nt_errstr(status));
254                 return False;
255         }
256
257         if (!W_ERROR_IS_OK(r.out.result)) {
258                 printf("DeleteKey failed - %s\n", win_errstr(r.out.result));
259                 return False;
260         }
261
262         return True;
263 }
264
265 static BOOL test_QueryInfoKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
266                               struct policy_handle *handle, char *class)
267 {
268         NTSTATUS status;
269         struct winreg_QueryInfoKey r;
270
271         printf("\ntesting QueryInfoKey\n");
272
273         r.in.handle = handle;
274         init_winreg_String(&r.in.class, class);
275         
276         status = dcerpc_winreg_QueryInfoKey(p, mem_ctx, &r);
277
278         if (!NT_STATUS_IS_OK(status)) {
279                 printf("QueryInfoKey failed - %s\n", nt_errstr(status));
280                 return False;
281         }
282
283         if (!W_ERROR_IS_OK(r.out.result)) {
284                 printf("QueryInfoKey failed - %s\n", win_errstr(r.out.result));
285                 return False;
286         }
287
288         return True;
289 }
290
291 static BOOL test_key(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
292                      struct policy_handle *handle, int depth);
293
294 static BOOL test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
295                          struct policy_handle *handle, int depth)
296 {
297         struct winreg_EnumKey r;
298         struct winreg_EnumKeyNameRequest keyname;
299         struct winreg_String classname;
300         struct winreg_Time tm;
301         NTSTATUS status;
302
303         printf("Testing EnumKey\n\n");
304
305         r.in.handle = handle;
306         r.in.enum_index = 0;
307         r.in.key_name_len = r.out.key_name_len = 0;
308         r.in.unknown = r.out.unknown = 0x0414;
309         keyname.unknown = 0x0000020a;
310         init_winreg_String(&keyname.key_name, NULL);
311         init_winreg_String(&classname, NULL);
312         r.in.in_name = &keyname;
313         r.in.class = &classname;
314         tm.low = tm.high = 0x7fffffff;
315         r.in.last_changed_time = &tm;
316
317         do {
318                 status = dcerpc_winreg_EnumKey(p, mem_ctx, &r);
319
320                 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
321                         struct policy_handle key_handle;
322
323                         printf("EnumKey: %d: %s\n", r.in.enum_index, r.out.out_name->name);
324
325                         if (!test_OpenKey(
326                                     p, mem_ctx, handle, r.out.out_name->name,
327                                     &key_handle)) {
328                         } else {
329                                 test_key(p, mem_ctx, &key_handle, depth + 1);
330                         }
331                 }
332
333                 r.in.enum_index++;
334
335         } while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result));
336
337         if (!NT_STATUS_IS_OK(status)) {
338                 printf("EnumKey failed - %s\n", nt_errstr(status));
339                 return False;
340         }
341
342         if (!W_ERROR_IS_OK(r.out.result) && !W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
343                 printf("EnumKey failed - %s\n", win_errstr(r.out.result));
344                 return False;
345         }
346
347
348
349         return True;
350 }
351
352 static BOOL test_QueryMultipleValues(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *valuename)
353 {
354         struct winreg_QueryMultipleValues r;
355         NTSTATUS status;
356
357         printf("Testing QueryMultipleValues\n");
358
359         r.in.key_handle = handle;
360         r.in.values = r.out.values = talloc_array(mem_ctx, struct QueryMultipleValue, 1);
361         r.in.values[0].name = talloc(mem_ctx, struct winreg_String);
362         r.in.values[0].name->name = valuename;
363         r.in.values[0].offset = 0;
364         r.in.values[0].length = 0;
365         r.in.values[0].type = 0;
366
367         r.in.num_values = 1;
368         r.in.buffer_size = r.out.buffer_size = talloc(mem_ctx, uint32);
369         *r.in.buffer_size = 0x20;
370         r.in.buffer = r.out.buffer = talloc_zero_array(mem_ctx, uint8, *r.in.buffer_size);
371
372         status = dcerpc_winreg_QueryMultipleValues(p, mem_ctx, &r);
373         if(NT_STATUS_IS_ERR(status)) {
374                 printf("QueryMultipleValues failed - %s\n", nt_errstr(status));
375                 return False;
376         }
377
378         if (!W_ERROR_IS_OK(r.out.result)) {
379                 printf("QueryMultipleValues failed - %s\n", win_errstr(r.out.result));
380                 return False;
381         }
382
383         return True;
384 }
385
386 static BOOL test_QueryValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *valuename)
387 {
388         struct winreg_QueryValue r;
389         NTSTATUS status;
390         uint32 zero = 0;
391         uint32 offered = 0xfff;
392
393         printf("Testing QueryValue\n");
394
395         r.in.handle = handle;
396         r.in.data = NULL;
397         r.in.value_name.name = valuename;
398         r.in.type = &zero;
399         r.in.size = &offered;
400         r.in.length = &zero;
401
402         status = dcerpc_winreg_QueryValue(p, mem_ctx, &r);
403         if(NT_STATUS_IS_ERR(status)) {
404                 printf("QueryValue failed - %s\n", nt_errstr(status));
405                 return False;
406         }
407
408         if (!W_ERROR_IS_OK(r.out.result)) {
409                 printf("QueryValue failed - %s\n", win_errstr(r.out.result));
410                 return False;
411         }
412
413         return True;
414 }
415
416 static BOOL test_EnumValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
417                            struct policy_handle *handle, int max_valnamelen, int max_valbufsize)
418 {
419         struct winreg_EnumValue r;
420         uint32 type = 0;
421         uint32 size = max_valbufsize, zero = 0;
422         BOOL ret = True;
423         uint8_t buf8;
424         uint16_t buf16;
425
426         printf("testing EnumValue\n");
427
428         r.in.handle = handle;
429         r.in.enum_index = 0;
430         r.in.name_in.length = 0;
431         r.in.name_in.size = 0x200;
432         r.in.name_in.name = &buf16;
433         r.in.type = &type;
434         r.in.value = &buf8;
435         r.in.length = &zero;
436         r.in.size = &size;
437         
438         do {
439                 NTSTATUS status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
440                 if(NT_STATUS_IS_ERR(status)) {
441                         printf("EnumValue failed - %s\n", nt_errstr(status));
442                         return False;
443                 }
444
445                 if (W_ERROR_IS_OK(r.out.result)) {
446                         ret &= test_QueryValue(p, mem_ctx, handle, r.out.name_out.name);
447                         ret &= test_QueryMultipleValues(p, mem_ctx, handle, r.out.name_out.name);
448                 }
449
450                 r.in.enum_index++;
451         } while (W_ERROR_IS_OK(r.out.result));
452
453         if(!W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
454                 printf("EnumValue failed - %s\n", win_errstr(r.out.result));
455                 return False;
456         }
457
458         return ret;
459 }
460
461 static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
462                           struct policy_handle *handle)
463 {
464         NTSTATUS status;
465         struct winreg_OpenHKLM r;
466         struct winreg_OpenUnknown unknown;
467         BOOL ret = True;
468
469         printf("\ntesting OpenHKLM\n");
470
471         unknown.unknown0 = 0x84e0;
472         unknown.unknown1 = 0x0000;
473         r.in.unknown = &unknown;
474         r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
475         r.out.handle = handle;
476
477         status = dcerpc_winreg_OpenHKLM(p, mem_ctx, &r);
478
479         if (!NT_STATUS_IS_OK(status)) {
480                 printf("OpenHKLM failed - %s\n", nt_errstr(status));
481                 return False;
482         }
483
484         if (!W_ERROR_IS_OK(r.out.result)) {
485                 printf("OpenHKLM failed - %s\n", win_errstr(r.out.result));
486                 return False;
487         }
488
489         return ret;
490 }
491
492 static BOOL test_OpenHKU(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
493                          struct policy_handle *handle)
494 {
495         NTSTATUS status;
496         struct winreg_OpenHKU r;
497         struct winreg_OpenUnknown unknown;
498         BOOL ret = True;
499
500         printf("\ntesting OpenHKU\n");
501
502         unknown.unknown0 = 0x84e0;
503         unknown.unknown1 = 0x0000;
504         r.in.unknown = &unknown;
505         r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
506         r.out.handle = handle;
507
508         status = dcerpc_winreg_OpenHKU(p, mem_ctx, &r);
509
510         if (!NT_STATUS_IS_OK(status)) {
511                 printf("OpenHKU failed - %s\n", nt_errstr(status));
512                 return False;
513         }
514
515         if (!W_ERROR_IS_OK(r.out.result)) {
516                 printf("OpenHKU failed - %s\n", win_errstr(r.out.result));
517                 return False;
518         }
519
520         return ret;
521 }
522
523 static BOOL test_OpenHKCR(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
524                           struct policy_handle *handle)
525 {
526         NTSTATUS status;
527         struct winreg_OpenHKCR r;
528         struct winreg_OpenUnknown unknown;
529         BOOL ret = True;
530
531         printf("\ntesting OpenHKCR\n");
532
533         unknown.unknown0 = 0x84e0;
534         unknown.unknown1 = 0x0000;
535         r.in.unknown = &unknown;
536         r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
537         r.out.handle = handle;
538
539         status = dcerpc_winreg_OpenHKCR(p, mem_ctx, &r);
540
541         if (!NT_STATUS_IS_OK(status)) {
542                 printf("OpenHKCR failed - %s\n", nt_errstr(status));
543                 return False;
544         }
545
546         if (!W_ERROR_IS_OK(r.out.result)) {
547                 printf("OpenHKU failed - %s\n", win_errstr(r.out.result));
548                 return False;
549         }
550         return ret;
551 }
552
553 static BOOL test_InitiateSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
554                         const char *msg, uint32_t timeout)
555 {
556         struct winreg_InitiateSystemShutdown r;
557         NTSTATUS status;
558         
559         r.in.hostname = NULL;
560         r.in.message = talloc(mem_ctx, struct winreg_String);
561         init_winreg_String(r.in.message, msg);
562         r.in.force_apps = 1;
563         r.in.timeout = timeout;
564         r.in.reboot = 1;
565
566         status = dcerpc_winreg_InitiateSystemShutdown(p, mem_ctx, &r);
567
568         if (!NT_STATUS_IS_OK(status)) {
569                 printf("InitiateSystemShutdown failed - %s\n", nt_errstr(status));
570                 return False;
571         }
572
573         if (!W_ERROR_IS_OK(r.out.result)) {
574                 printf("InitiateSystemShutdown failed - %s\n", win_errstr(r.out.result));
575                 return False;
576         }
577
578         return True;
579 }
580
581 static BOOL test_InitiateSystemShutdownEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
582                         const char *msg, uint32_t timeout)
583 {
584         struct winreg_InitiateSystemShutdownEx r;
585         NTSTATUS status;
586         
587         r.in.hostname = NULL;
588         r.in.message = talloc(mem_ctx, struct winreg_String);
589         init_winreg_String(r.in.message, msg);
590         r.in.force_apps = 1;
591         r.in.timeout = timeout;
592         r.in.reboot = 1;
593         r.in.reason = 0;
594
595         status = dcerpc_winreg_InitiateSystemShutdownEx(p, mem_ctx, &r);
596
597         if (!NT_STATUS_IS_OK(status)) {
598                 printf("InitiateSystemShutdownEx failed - %s\n", nt_errstr(status));
599                 return False;
600         }
601
602         if (!W_ERROR_IS_OK(r.out.result)) {
603                 printf("InitiateSystemShutdownEx failed - %s\n", win_errstr(r.out.result));
604                 return False;
605         }
606
607         return True;
608 }
609
610 static BOOL test_AbortSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
611 {
612         struct winreg_AbortSystemShutdown r;
613         NTSTATUS status;
614         uint16_t server = 0x0;
615
616         r.in.server = &server;
617         
618         status = dcerpc_winreg_AbortSystemShutdown(p, mem_ctx, &r);
619
620         if (!NT_STATUS_IS_OK(status)) {
621                 printf("AbortSystemShutdown failed - %s\n", nt_errstr(status));
622                 return False;
623         }
624
625         if (!W_ERROR_IS_OK(r.out.result)) {
626                 printf("AbortSystemShutdown failed - %s\n", win_errstr(r.out.result));
627                 return False;
628         }
629
630         return True;
631 }
632
633 static BOOL test_OpenHKCU(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
634                           struct policy_handle *handle)
635 {
636         NTSTATUS status;
637         struct winreg_OpenHKCU r;
638         struct winreg_OpenUnknown unknown;
639         BOOL ret = True;
640
641         printf("\ntesting OpenHKCU\n");
642
643         unknown.unknown0 = 0x84e0;
644         unknown.unknown1 = 0x0000;
645         r.in.unknown = &unknown;
646         r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
647         r.out.handle = handle;
648
649         status = dcerpc_winreg_OpenHKCU(p, mem_ctx, &r);
650
651         if (!NT_STATUS_IS_OK(status)) {
652                 printf("OpenHKCU failed - %s\n", nt_errstr(status));
653                 return False;
654         }
655
656         return ret;
657 }
658
659 #define MAX_DEPTH 2             /* Only go this far down the tree */
660
661 static BOOL test_key(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
662                      struct policy_handle *handle, int depth)
663 {
664         if (depth == MAX_DEPTH)
665                 return True;
666
667         if (!test_QueryInfoKey(p, mem_ctx, handle, NULL)) {
668         }
669
670
671         if (!test_NotifyChangeKeyValue(p, mem_ctx, handle)) {
672         }
673         
674         if (!test_GetKeySecurity(p, mem_ctx, handle)) {
675         }
676
677         if (!test_EnumKey(p, mem_ctx, handle, depth)) {
678         }
679
680         if (!test_EnumValue(p, mem_ctx, handle, 0xFF, 0xFFFF)) {
681         }
682
683
684         test_CloseKey(p, mem_ctx, handle);
685
686         return True;
687 }
688
689 typedef BOOL winreg_open_fn(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
690                             struct policy_handle *handle);
691
692 static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
693 {
694         struct policy_handle handle, newhandle;
695         BOOL ret = True;
696         winreg_open_fn *open_fn = (winreg_open_fn *)fn;
697
698         if (!open_fn(p, mem_ctx, &handle)) {
699                 return False;
700         }
701
702         if (!test_CreateKey(p, mem_ctx, &handle, "spottyfoot", NULL)) {
703                 printf("CreateKey failed\n");
704                 ret = False;
705         }
706
707         if (!test_FlushKey(p, mem_ctx, &handle)) {
708                 printf("FlushKey failed\n");
709                 ret = False;
710         }
711
712         if (!test_OpenKey(p, mem_ctx, &handle, "spottyfoot", &newhandle)) {
713                 printf("CreateKey failed (OpenKey after Create didn't work)\n");
714                 ret = False;
715         }
716
717         if (!test_DeleteKey(p, mem_ctx, &handle, "spottyfoot")) {
718                 printf("DeleteKey failed\n");
719                 ret = False;
720         }
721
722         if (!test_FlushKey(p, mem_ctx, &handle)) {
723                 printf("FlushKey failed\n");
724                 ret = False;
725         }
726
727         if (test_OpenKey(p, mem_ctx, &handle, "spottyfoot", &newhandle)) {
728                 printf("DeleteKey failed (OpenKey after Delete didn't work)\n");
729                 ret = False;
730         }
731
732         if (!test_GetVersion(p, mem_ctx, &handle)) {
733                 printf("GetVersion failed\n");
734                 ret = False;
735         }
736
737         /* The HKCR hive has a very large fanout */
738
739         if (open_fn == test_OpenHKCR) {
740                 if(!test_key(p, mem_ctx, &handle, MAX_DEPTH - 1)) {
741                         ret = False;
742                 }
743         }
744
745         if(!test_key(p, mem_ctx, &handle, 0)) {
746                 ret = False;
747         }
748
749         return ret;
750 }
751
752 BOOL torture_rpc_winreg(void)
753 {
754         NTSTATUS status;
755        struct dcerpc_pipe *p;
756         TALLOC_CTX *mem_ctx;
757         BOOL ret = True;
758         winreg_open_fn *open_fns[] = { test_OpenHKLM, test_OpenHKU,
759                                        test_OpenHKCR, test_OpenHKCU };
760         int i;
761
762         mem_ctx = talloc_init("torture_rpc_winreg");
763
764         status = torture_rpc_connection(&p, 
765                                         DCERPC_WINREG_NAME, 
766                                         DCERPC_WINREG_UUID, 
767                                         DCERPC_WINREG_VERSION);
768
769         if (!NT_STATUS_IS_OK(status)) {
770                 return False;
771         }
772
773         if (!lp_parm_bool(-1, "torture", "dangerous", False)) {
774                 printf("winreg_InitiateShutdown disabled - enable dangerous tests to use\n");
775         } else {
776                 ret &= test_InitiateSystemShutdown(p, mem_ctx, "spottyfood", 30);
777                 ret &= test_AbortSystemShutdown(p, mem_ctx);
778                 ret &= test_InitiateSystemShutdownEx(p, mem_ctx, "spottyfood", 30);
779                 ret &= test_AbortSystemShutdown(p, mem_ctx);
780         }
781
782         for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
783                 if (!test_Open(p, mem_ctx, open_fns[i]))
784                         ret = False;
785         }
786
787         talloc_free(mem_ctx);
788
789         torture_rpc_close(p);
790
791         return ret;
792 }