2 Unix SMB/CIFS implementation.
3 test suite for winreg rpc operations
5 Copyright (C) Tim Potter 2003
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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_winreg_c.h"
25 #include "librpc/gen_ndr/ndr_security.h"
26 #include "libcli/security/security.h"
27 #include "torture/rpc/rpc.h"
29 #define TEST_KEY_BASE "smbtorture test"
30 #define TEST_KEY1 TEST_KEY_BASE "\\spottyfoot"
31 #define TEST_KEY2 TEST_KEY_BASE "\\with a SD (#1)"
32 #define TEST_KEY3 TEST_KEY_BASE "\\with a subkey"
33 #define TEST_SUBKEY TEST_KEY3 "\\subkey"
35 static void init_initshutdown_String(TALLOC_CTX *mem_ctx, struct initshutdown_String *name, const char *s)
37 name->name = talloc(mem_ctx, struct initshutdown_String_sub);
41 static void init_winreg_String(struct winreg_String *name, const char *s)
45 name->name_len = 2 * (strlen_m(s) + 1);
46 name->name_size = name->name_len;
53 static bool test_GetVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
54 struct policy_handle *handle)
57 struct winreg_GetVersion r;
59 printf("\ntesting GetVersion\n");
65 status = dcerpc_winreg_GetVersion(p, mem_ctx, &r);
67 if (!NT_STATUS_IS_OK(status)) {
68 printf("GetVersion failed - %s\n", nt_errstr(status));
72 if (!W_ERROR_IS_OK(r.out.result)) {
73 printf("GetVersion failed - %s\n", win_errstr(r.out.result));
80 static bool test_NotifyChangeKeyValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
81 struct policy_handle *handle)
83 struct winreg_NotifyChangeKeyValue r;
86 printf("\ntesting NotifyChangeKeyValue\n");
89 r.in.watch_subtree = 1;
90 r.in.notify_filter = 0;
91 r.in.unknown = r.in.unknown2 = 0;
92 init_winreg_String(&r.in.string1, NULL);
93 init_winreg_String(&r.in.string2, NULL);
95 status = dcerpc_winreg_NotifyChangeKeyValue(p, mem_ctx, &r);
97 if (!NT_STATUS_IS_OK(status)) {
98 printf("NotifyChangeKeyValue failed - %s\n", nt_errstr(status));
102 if (!W_ERROR_IS_OK(r.out.result)) {
103 printf("NotifyChangeKeyValue failed - %s - not considering\n", win_errstr(r.out.result));
110 static bool test_CreateKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
111 struct policy_handle *handle, const char *name,
114 struct winreg_CreateKey r;
115 struct policy_handle newhandle;
117 enum winreg_CreateAction action_taken = 0;
119 printf("\ntesting CreateKey\n");
121 r.in.handle = handle;
122 r.out.new_handle = &newhandle;
123 init_winreg_String(&r.in.name, name);
124 init_winreg_String(&r.in.keyclass, class);
126 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
127 r.in.action_taken = r.out.action_taken = &action_taken;
130 status = dcerpc_winreg_CreateKey(p, mem_ctx, &r);
132 if (!NT_STATUS_IS_OK(status)) {
133 printf("CreateKey failed - %s\n", nt_errstr(status));
137 if (!W_ERROR_IS_OK(r.out.result)) {
138 printf("CreateKey failed - %s\n", win_errstr(r.out.result));
147 createkey testing with a SD
149 static bool test_CreateKey_sd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
150 struct policy_handle *handle, const char *name,
151 const char *class, struct policy_handle *newhandle)
153 struct winreg_CreateKey r;
155 enum winreg_CreateAction action_taken = 0;
156 struct security_descriptor *sd;
158 struct winreg_SecBuf secbuf;
160 sd = security_descriptor_create(mem_ctx,
162 SID_NT_AUTHENTICATED_USERS,
163 SEC_ACE_TYPE_ACCESS_ALLOWED,
165 SEC_ACE_FLAG_OBJECT_INHERIT,
168 status = ndr_push_struct_blob(&sdblob, mem_ctx, sd,
169 (ndr_push_flags_fn_t)ndr_push_security_descriptor);
170 if (!NT_STATUS_IS_OK(status)) {
171 printf("Failed to push security_descriptor ?!\n");
175 secbuf.sd.data = sdblob.data;
176 secbuf.sd.len = sdblob.length;
177 secbuf.sd.size = sdblob.length;
178 secbuf.length = sdblob.length-10;
181 printf("\ntesting CreateKey with sd\n");
183 r.in.handle = handle;
184 r.out.new_handle = newhandle;
185 init_winreg_String(&r.in.name, name);
186 init_winreg_String(&r.in.keyclass, class);
188 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
189 r.in.action_taken = r.out.action_taken = &action_taken;
190 r.in.secdesc = &secbuf;
192 status = dcerpc_winreg_CreateKey(p, mem_ctx, &r);
194 if (!NT_STATUS_IS_OK(status)) {
195 printf("CreateKey with sd failed - %s\n", nt_errstr(status));
199 if (!W_ERROR_IS_OK(r.out.result)) {
200 printf("CreateKey with sd failed - %s\n", win_errstr(r.out.result));
207 static bool test_GetKeySecurity(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
208 struct policy_handle *handle)
211 struct winreg_GetKeySecurity r;
212 struct security_descriptor sd;
215 printf("\ntesting GetKeySecurity\n");
219 r.in.handle = handle;
220 r.in.sd = r.out.sd = talloc_zero(mem_ctx, struct KeySecurityData);
221 r.in.sd->size = 0x1000;
222 r.in.sec_info = SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL;
224 status = dcerpc_winreg_GetKeySecurity(p, mem_ctx, &r);
226 if (!NT_STATUS_IS_OK(status)) {
227 printf("GetKeySecurity failed - %s\n", nt_errstr(status));
231 if (!W_ERROR_IS_OK(r.out.result)) {
232 printf("GetKeySecurity failed - %s\n", win_errstr(r.out.result));
236 sdblob.data = r.out.sd->data;
237 sdblob.length = r.out.sd->len;
239 status = ndr_pull_struct_blob(&sdblob, mem_ctx, &sd,
240 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
241 if (!NT_STATUS_IS_OK(status)) {
242 printf("pull_security_descriptor failed - %s\n", nt_errstr(status));
245 if (p->conn->flags & DCERPC_DEBUG_PRINT_OUT) {
246 NDR_PRINT_DEBUG(security_descriptor, &sd);
252 static bool test_CloseKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
253 struct policy_handle *handle)
256 struct winreg_CloseKey r;
258 printf("\ntesting CloseKey\n");
260 r.in.handle = r.out.handle = handle;
262 status = dcerpc_winreg_CloseKey(p, mem_ctx, &r);
264 if (!NT_STATUS_IS_OK(status)) {
265 printf("CloseKey failed - %s\n", nt_errstr(status));
269 if (!W_ERROR_IS_OK(r.out.result)) {
270 printf("CloseKey failed - %s\n", win_errstr(r.out.result));
277 static bool test_FlushKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
278 struct policy_handle *handle)
281 struct winreg_FlushKey r;
283 printf("\ntesting FlushKey\n");
285 r.in.handle = handle;
287 status = dcerpc_winreg_FlushKey(p, mem_ctx, &r);
289 if (!NT_STATUS_IS_OK(status)) {
290 printf("FlushKey failed - %s\n", nt_errstr(status));
294 if (!W_ERROR_IS_OK(r.out.result)) {
295 printf("FlushKey failed - %s\n", win_errstr(r.out.result));
302 static bool test_OpenKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
303 struct policy_handle *hive_handle,
304 const char *keyname, struct policy_handle *key_handle)
307 struct winreg_OpenKey r;
309 printf("\ntesting OpenKey\n");
311 r.in.parent_handle = hive_handle;
312 init_winreg_String(&r.in.keyname, keyname);
313 r.in.unknown = 0x00000000;
314 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
315 r.out.handle = key_handle;
317 status = dcerpc_winreg_OpenKey(p, mem_ctx, &r);
319 if (!NT_STATUS_IS_OK(status)) {
320 printf("OpenKey failed - %s\n", nt_errstr(status));
324 if (!W_ERROR_IS_OK(r.out.result)) {
325 printf("OpenKey failed - %s\n", win_errstr(r.out.result));
333 static bool test_Cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
334 struct policy_handle *handle, const char *key)
336 struct winreg_DeleteKey r;
338 r.in.handle = handle;
340 init_winreg_String(&r.in.key, key);
341 dcerpc_winreg_DeleteKey(p, mem_ctx, &r);
347 static bool test_DeleteKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
348 struct policy_handle *handle, const char *key)
351 struct winreg_DeleteKey r;
353 printf("\ntesting DeleteKey\n");
355 r.in.handle = handle;
356 init_winreg_String(&r.in.key, key);
358 status = dcerpc_winreg_DeleteKey(p, mem_ctx, &r);
360 if (!NT_STATUS_IS_OK(status)) {
361 printf("DeleteKey failed - %s\n", nt_errstr(status));
365 if (!W_ERROR_IS_OK(r.out.result)) {
366 printf("DeleteKey failed - %s\n", win_errstr(r.out.result));
373 /* DeleteKey on a key with subkey(s) should
374 * return WERR_ACCESS_DENIED. */
375 static bool test_DeleteKeyWithSubkey(struct dcerpc_pipe *p,
377 struct policy_handle *handle, const char *key)
380 struct winreg_DeleteKey r;
382 printf("\ntesting DeleteKeyWithSubkey\n");
384 r.in.handle = handle;
385 init_winreg_String(&r.in.key, key);
387 status = dcerpc_winreg_DeleteKey(p, mem_ctx, &r);
389 if (!NT_STATUS_IS_OK(status)) {
390 printf("DeleteKeyWithSubkey failed - %s\n", nt_errstr(status));
394 if (!W_ERROR_EQUAL(r.out.result, WERR_ACCESS_DENIED)) {
395 printf("DeleteKeyWithSubkey failed - %s\n", win_errstr(r.out.result));
402 static bool test_QueryInfoKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
403 struct policy_handle *handle, char *class)
406 struct winreg_QueryInfoKey r;
407 uint32_t num_subkeys, max_subkeylen, max_subkeysize,
408 num_values, max_valnamelen, max_valbufsize,
410 NTTIME last_changed_time;
412 printf("\ntesting QueryInfoKey\n");
415 r.in.handle = handle;
416 r.out.num_subkeys = &num_subkeys;
417 r.out.max_subkeylen = &max_subkeylen;
418 r.out.max_subkeysize = &max_subkeysize;
419 r.out.num_values = &num_values;
420 r.out.max_valnamelen = &max_valnamelen;
421 r.out.max_valbufsize = &max_valbufsize;
422 r.out.secdescsize = &secdescsize;
423 r.out.last_changed_time = &last_changed_time;
425 r.out.classname = talloc(mem_ctx, struct winreg_String);
427 r.in.classname = talloc(mem_ctx, struct winreg_String);
428 init_winreg_String(r.in.classname, class);
430 status = dcerpc_winreg_QueryInfoKey(p, mem_ctx, &r);
432 if (!NT_STATUS_IS_OK(status)) {
433 printf("QueryInfoKey failed - %s\n", nt_errstr(status));
437 if (!W_ERROR_IS_OK(r.out.result)) {
438 printf("QueryInfoKey failed - %s\n", win_errstr(r.out.result));
445 static bool test_key(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
446 struct policy_handle *handle, int depth);
448 static bool test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
449 struct policy_handle *handle, int depth)
451 struct winreg_EnumKey r;
452 struct winreg_StringBuf class, name;
456 printf("Testing EnumKey\n\n");
461 r.in.handle = handle;
464 r.in.keyclass = &class;
466 r.in.last_changed_time = &t;
472 status = dcerpc_winreg_EnumKey(p, mem_ctx, &r);
474 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
475 struct policy_handle key_handle;
477 printf("EnumKey: %d: %s\n", r.in.enum_index, r.out.name->name);
480 p, mem_ctx, handle, r.out.name->name,
483 test_key(p, mem_ctx, &key_handle, depth + 1);
489 } while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result));
491 if (!NT_STATUS_IS_OK(status)) {
492 printf("EnumKey failed - %s\n", nt_errstr(status));
496 if (!W_ERROR_IS_OK(r.out.result) && !W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
497 printf("EnumKey failed - %s\n", win_errstr(r.out.result));
506 static bool test_QueryMultipleValues(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *valuename)
508 struct winreg_QueryMultipleValues r;
512 printf("Testing QueryMultipleValues\n");
514 r.in.key_handle = handle;
515 r.in.values = r.out.values = talloc_array(mem_ctx, struct QueryMultipleValue, 1);
516 r.in.values[0].name = talloc(mem_ctx, struct winreg_String);
517 r.in.values[0].name->name = valuename;
518 r.in.values[0].offset = 0;
519 r.in.values[0].length = 0;
520 r.in.values[0].type = 0;
523 r.in.buffer_size = r.out.buffer_size = talloc(mem_ctx, uint32_t);
524 *r.in.buffer_size = bufsize;
526 *r.in.buffer_size = bufsize;
527 r.in.buffer = r.out.buffer = talloc_zero_array(mem_ctx, uint8_t,
530 status = dcerpc_winreg_QueryMultipleValues(p, mem_ctx, &r);
532 if(NT_STATUS_IS_ERR(status)) {
533 printf("QueryMultipleValues failed - %s\n", nt_errstr(status));
536 talloc_free(r.in.buffer);
538 } while (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA));
540 if (!W_ERROR_IS_OK(r.out.result)) {
541 printf("QueryMultipleValues failed - %s\n", win_errstr(r.out.result));
548 static bool test_QueryValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *valuename)
550 struct winreg_QueryValue r;
552 enum winreg_Type zero_type = 0;
553 uint32_t offered = 0xfff;
556 printf("Testing QueryValue\n");
558 r.in.handle = handle;
560 r.in.value_name.name = valuename;
561 r.in.type = &zero_type;
562 r.in.size = &offered;
565 status = dcerpc_winreg_QueryValue(p, mem_ctx, &r);
566 if(NT_STATUS_IS_ERR(status)) {
567 printf("QueryValue failed - %s\n", nt_errstr(status));
571 if (!W_ERROR_IS_OK(r.out.result)) {
572 printf("QueryValue failed - %s\n", win_errstr(r.out.result));
579 static bool test_EnumValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
580 struct policy_handle *handle, int max_valnamelen, int max_valbufsize)
582 struct winreg_EnumValue r;
583 enum winreg_Type type = 0;
584 uint32_t size = max_valbufsize, zero = 0;
587 struct winreg_StringBuf name;
589 printf("testing EnumValue\n");
594 r.in.handle = handle;
604 NTSTATUS status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
605 if(NT_STATUS_IS_ERR(status)) {
606 printf("EnumValue failed - %s\n", nt_errstr(status));
610 if (W_ERROR_IS_OK(r.out.result)) {
611 ret &= test_QueryValue(p, mem_ctx, handle, r.out.name->name);
612 ret &= test_QueryMultipleValues(p, mem_ctx, handle, r.out.name->name);
616 } while (W_ERROR_IS_OK(r.out.result));
618 if(!W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
619 printf("EnumValue failed - %s\n", win_errstr(r.out.result));
626 static bool test_InitiateSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
627 const char *msg, uint32_t timeout)
629 struct winreg_InitiateSystemShutdown r;
631 uint16_t hostname = 0x0;
633 r.in.hostname = &hostname;
634 r.in.message = talloc(mem_ctx, struct initshutdown_String);
635 init_initshutdown_String(mem_ctx, r.in.message, msg);
637 r.in.timeout = timeout;
640 status = dcerpc_winreg_InitiateSystemShutdown(p, mem_ctx, &r);
642 if (!NT_STATUS_IS_OK(status)) {
643 printf("InitiateSystemShutdown failed - %s\n", nt_errstr(status));
647 if (!W_ERROR_IS_OK(r.out.result)) {
648 printf("InitiateSystemShutdown failed - %s\n", win_errstr(r.out.result));
655 static bool test_InitiateSystemShutdownEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
656 const char *msg, uint32_t timeout)
658 struct winreg_InitiateSystemShutdownEx r;
660 uint16_t hostname = 0x0;
662 r.in.hostname = &hostname;
663 r.in.message = talloc(mem_ctx, struct initshutdown_String);
664 init_initshutdown_String(mem_ctx, r.in.message, msg);
666 r.in.timeout = timeout;
670 status = dcerpc_winreg_InitiateSystemShutdownEx(p, mem_ctx, &r);
672 if (!NT_STATUS_IS_OK(status)) {
673 printf("InitiateSystemShutdownEx failed - %s\n", nt_errstr(status));
677 if (!W_ERROR_IS_OK(r.out.result)) {
678 printf("InitiateSystemShutdownEx failed - %s\n", win_errstr(r.out.result));
685 static bool test_AbortSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
687 struct winreg_AbortSystemShutdown r;
689 uint16_t server = 0x0;
691 r.in.server = &server;
693 status = dcerpc_winreg_AbortSystemShutdown(p, mem_ctx, &r);
695 if (!NT_STATUS_IS_OK(status)) {
696 printf("AbortSystemShutdown failed - %s\n", nt_errstr(status));
700 if (!W_ERROR_IS_OK(r.out.result)) {
701 printf("AbortSystemShutdown failed - %s\n", win_errstr(r.out.result));
708 #define MAX_DEPTH 2 /* Only go this far down the tree */
710 static bool test_key(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
711 struct policy_handle *handle, int depth)
713 if (depth == MAX_DEPTH)
716 if (!test_QueryInfoKey(p, mem_ctx, handle, NULL)) {
719 if (!test_NotifyChangeKeyValue(p, mem_ctx, handle)) {
722 if (!test_GetKeySecurity(p, mem_ctx, handle)) {
725 if (!test_EnumKey(p, mem_ctx, handle, depth)) {
728 if (!test_EnumValue(p, mem_ctx, handle, 0xFF, 0xFFFF)) {
731 test_CloseKey(p, mem_ctx, handle);
736 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
738 static bool test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
739 const char *name, winreg_open_fn open_fn)
741 struct policy_handle handle, newhandle;
742 bool ret = true, created = false, created2 = false, deleted = false;
743 bool created3 = false, created_subkey = false;
744 struct winreg_OpenHKLM r;
747 printf("Testing %s\n", name);
749 r.in.system_name = 0;
750 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
751 r.out.handle = &handle;
753 status = open_fn(p, mem_ctx, &r);
754 if (!NT_STATUS_IS_OK(status)) {
758 test_Cleanup(p, mem_ctx, &handle, TEST_KEY1);
759 test_Cleanup(p, mem_ctx, &handle, TEST_KEY2);
760 test_Cleanup(p, mem_ctx, &handle, TEST_SUBKEY);
761 test_Cleanup(p, mem_ctx, &handle, TEST_KEY3);
762 test_Cleanup(p, mem_ctx, &handle, TEST_KEY_BASE);
764 if (!test_CreateKey(p, mem_ctx, &handle, TEST_KEY1, NULL)) {
765 printf("CreateKey failed - not considering a failure\n");
770 if (created && !test_FlushKey(p, mem_ctx, &handle)) {
771 printf("FlushKey failed\n");
775 if (created && !test_OpenKey(p, mem_ctx, &handle, TEST_KEY1, &newhandle)) {
776 printf("CreateKey failed (OpenKey after Create didn't work)\n");
780 if (created && !test_DeleteKey(p, mem_ctx, &handle, TEST_KEY1)) {
781 printf("DeleteKey failed\n");
787 if (created && !test_FlushKey(p, mem_ctx, &handle)) {
788 printf("FlushKey failed\n");
792 if (created && deleted &&
793 test_OpenKey(p, mem_ctx, &handle, TEST_KEY1, &newhandle)) {
794 printf("DeleteKey failed (OpenKey after Delete worked)\n");
798 if (!test_GetVersion(p, mem_ctx, &handle)) {
799 printf("GetVersion failed\n");
803 if (created && test_CreateKey_sd(p, mem_ctx, &handle, TEST_KEY2,
808 if (created2 && !test_GetKeySecurity(p, mem_ctx, &newhandle)) {
809 printf("GetKeySecurity failed\n");
813 if (created2 && !test_CloseKey(p, mem_ctx, &newhandle)) {
814 printf("CloseKey failed\n");
818 if (created && !test_DeleteKey(p, mem_ctx, &handle, TEST_KEY2)) {
819 printf("DeleteKey failed\n");
823 if (created && test_CreateKey(p, mem_ctx, &handle, TEST_KEY3, NULL)) {
828 test_CreateKey(p, mem_ctx, &handle, TEST_SUBKEY, NULL))
830 created_subkey = true;
833 if (created_subkey &&
834 !test_DeleteKeyWithSubkey(p, mem_ctx, &handle, TEST_KEY3))
836 printf("DeleteKeyWithSubkey failed "
837 "(DeleteKey didn't return ACCESS_DENIED)\n");
841 if (created_subkey &&
842 !test_DeleteKey(p, mem_ctx, &handle, TEST_SUBKEY))
844 printf("DeleteKey failed\n");
849 !test_DeleteKey(p, mem_ctx, &handle, TEST_KEY3))
851 printf("DeleteKey failed\n");
855 /* The HKCR hive has a very large fanout */
857 if (open_fn == (void *)dcerpc_winreg_OpenHKCR) {
858 if(!test_key(p, mem_ctx, &handle, MAX_DEPTH - 1)) {
863 if(!test_key(p, mem_ctx, &handle, 0)) {
867 test_Cleanup(p, mem_ctx, &handle, TEST_KEY_BASE);
872 bool torture_rpc_winreg(struct torture_context *torture)
875 struct dcerpc_pipe *p;
881 } open_fns[] = {{"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM },
882 {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU },
883 {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR },
884 {"OpenHKCU", (winreg_open_fn)dcerpc_winreg_OpenHKCU }};
886 mem_ctx = talloc_init("torture_rpc_winreg");
888 status = torture_rpc_connection(mem_ctx, &p, &ndr_table_winreg);
890 if (!NT_STATUS_IS_OK(status)) {
891 talloc_free(mem_ctx);
895 if (!torture_setting_bool(torture, "dangerous", false)) {
896 printf("winreg_InitiateShutdown disabled - enable dangerous tests to use\n");
898 ret &= test_InitiateSystemShutdown(p, mem_ctx, "spottyfood", 30);
899 ret &= test_AbortSystemShutdown(p, mem_ctx);
900 ret &= test_InitiateSystemShutdownEx(p, mem_ctx, "spottyfood", 30);
901 ret &= test_AbortSystemShutdown(p, mem_ctx);
904 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
905 ret &= test_Open(p, mem_ctx, open_fns[i].name, open_fns[i].fn);
908 talloc_free(mem_ctx);