Debian Codegraph @

source4/torture/rpc/winreg.c

raw
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-2007
7 Copyright (C) Günther Deschner 2007,2010
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "includes.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/torture_rpc.h"
28 #include "param/param.h"
29 #include "lib/registry/registry.h"
30
31 #define TEST_KEY_BASE "winreg_torture_test"
32 #define TEST_KEY1 "spottyfoot"
33 #define TEST_KEY2 "with a SD (#1)"
34 #define TEST_KEY3 "with a subkey"
35 #define TEST_KEY4 "sd_tests"
36 #define TEST_SUBKEY "subkey"
37 #define TEST_SUBKEY_SD "subkey_sd"
38 #define TEST_SUBSUBKEY_SD "subkey_sd\\subsubkey_sd"
39 #define TEST_VALUE "torture_value_name"
40 #define TEST_KEY_VOLATILE "torture_volatile_key"
41 #define TEST_SUBKEY_VOLATILE "torture_volatile_subkey"
42 #define TEST_KEY_SYMLINK "torture_symlink_key"
43 #define TEST_KEY_SYMLINK_DEST "torture_symlink_dest"
44
45 #define TEST_SID "S-1-5-21-1234567890-1234567890-1234567890-500"
46
47 static void init_lsa_StringLarge(struct lsa_StringLarge *name, const char *s)
48 {
49 name->string = s;
50 }
51
52 static void init_winreg_String(struct winreg_String *name, const char *s)
53 {
54 name->name = s;
55 if (s) {
56 name->name_len = 2 * (strlen_m(s) + 1);
57 name->name_size = name->name_len;
58 } else {
59 name->name_len = 0;
60 name->name_size = 0;
61 }
62 }
63
64 static bool test_GetVersion(struct dcerpc_binding_handle *b,
65 struct torture_context *tctx,
66 struct policy_handle *handle)
67 {
68 struct winreg_GetVersion r;
69 uint32_t v;
70
71 torture_comment(tctx, "Testing GetVersion\n");
72
73 ZERO_STRUCT(r);
74 r.in.handle = handle;
75 r.out.version = &v;
76
77 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_GetVersion_r(b, tctx, &r),
78 "GetVersion failed");
79
80 torture_assert_werr_ok(tctx, r.out.result, "GetVersion failed");
81
82 return true;
83 }
84
85 static bool test_NotifyChangeKeyValue(struct dcerpc_binding_handle *b,
86 struct torture_context *tctx,
87 struct policy_handle *handle)
88 {
89 struct winreg_NotifyChangeKeyValue r;
90
91 ZERO_STRUCT(r);
92 r.in.handle = handle;
93 r.in.watch_subtree = true;
94 r.in.notify_filter = 0;
95 r.in.unknown = r.in.unknown2 = 0;
96 init_winreg_String(&r.in.string1, NULL);
97 init_winreg_String(&r.in.string2, NULL);
98
99 torture_assert_ntstatus_ok(tctx,
100 dcerpc_winreg_NotifyChangeKeyValue_r(b, tctx, &r),
101 "NotifyChangeKeyValue failed");
102
103 if (!W_ERROR_IS_OK(r.out.result)) {
104 torture_comment(tctx,
105 "NotifyChangeKeyValue failed - %s - not considering\n",
106 win_errstr(r.out.result));
107 return true;
108 }
109
110 return true;
111 }
112
113 static bool test_CreateKey_opts(struct torture_context *tctx,
114 struct dcerpc_binding_handle *b,
115 struct policy_handle *handle,
116 const char *name,
117 const char *kclass,
118 uint32_t options,
119 uint32_t access_mask,
120 struct winreg_SecBuf *secdesc,
121 WERROR expected_result,
122 enum winreg_CreateAction *action_taken_p,
123 struct policy_handle *new_handle_p)
124 {
125 struct winreg_CreateKey r;
126 struct policy_handle newhandle;
127 enum winreg_CreateAction action_taken = 0;
128
129 torture_comment(tctx, "Testing CreateKey(%s)\n", name);
130
131 ZERO_STRUCT(r);
132 r.in.handle = handle;
133 init_winreg_String(&r.in.name, name);
134 init_winreg_String(&r.in.keyclass, kclass);
135 r.in.options = options;
136 r.in.access_mask = access_mask;
137 r.in.action_taken = &action_taken;
138 r.in.secdesc = secdesc;
139 r.out.new_handle = &newhandle;
140 r.out.action_taken = &action_taken;
141
142 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CreateKey_r(b, tctx, &r),
143 "CreateKey failed");
144
145 torture_assert_werr_equal(tctx, r.out.result, expected_result, "CreateKey failed");
146
147 if (new_handle_p) {
148 *new_handle_p = newhandle;
149 }
150 if (action_taken_p) {
151 *action_taken_p = *r.out.action_taken;
152 }
153
154 return true;
155 }
156
157 static bool test_CreateKey(struct dcerpc_binding_handle *b,
158 struct torture_context *tctx,
159 struct policy_handle *handle, const char *name,
160 const char *kclass)
161 {
162 return test_CreateKey_opts(tctx, b, handle, name, kclass,
163 REG_OPTION_NON_VOLATILE,
164 SEC_FLAG_MAXIMUM_ALLOWED,
165 NULL, /* secdesc */
166 WERR_OK,
167 NULL, /* action_taken */
168 NULL /* new_handle */);
169 }
170
171 /*
172 createkey testing with a SD
173 */
174 static bool test_CreateKey_sd(struct dcerpc_binding_handle *b,
175 struct torture_context *tctx,
176 struct policy_handle *handle, const char *name,
177 const char *kclass,
178 struct policy_handle *newhandle)
179 {
180 struct winreg_CreateKey r;
181 enum winreg_CreateAction action_taken = 0;
182 struct security_descriptor *sd;
183 DATA_BLOB sdblob;
184 struct winreg_SecBuf secbuf;
185
186 sd = security_descriptor_dacl_create(tctx,
187 0,
188 NULL, NULL,
189 SID_NT_AUTHENTICATED_USERS,
190 SEC_ACE_TYPE_ACCESS_ALLOWED,
191 SEC_GENERIC_ALL,
192 SEC_ACE_FLAG_OBJECT_INHERIT |
193 SEC_ACE_FLAG_CONTAINER_INHERIT,
194 NULL);
195
196 torture_assert_ndr_success(tctx,
197 ndr_push_struct_blob(&sdblob, tctx, sd,
198 (ndr_push_flags_fn_t)ndr_push_security_descriptor),
199 "Failed to push security_descriptor ?!\n");
200
201 secbuf.sd.data = sdblob.data;
202 secbuf.sd.len = sdblob.length;
203 secbuf.sd.size = sdblob.length;
204 secbuf.length = sdblob.length-10;
205 secbuf.inherit = 0;
206
207 ZERO_STRUCT(r);
208 r.in.handle = handle;
209 r.out.new_handle = newhandle;
210 init_winreg_String(&r.in.name, name);
211 init_winreg_String(&r.in.keyclass, kclass);
212 r.in.options = 0x0;
213 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
214 r.in.action_taken = r.out.action_taken = &action_taken;
215 r.in.secdesc = &secbuf;
216
217 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CreateKey_r(b, tctx, &r),
218 "CreateKey with sd failed");
219
220 torture_assert_werr_ok(tctx, r.out.result, "CreateKey with sd failed");
221
222 return true;
223 }
224
225 static bool _test_GetKeySecurity(struct dcerpc_pipe *p,
226 struct torture_context *tctx,
227 struct policy_handle *handle,
228 uint32_t *sec_info_ptr,
229 WERROR get_werr,
230 struct security_descriptor **sd_out)
231 {
232 struct winreg_GetKeySecurity r;
233 struct security_descriptor *sd = NULL;
234 uint32_t sec_info;
235 DATA_BLOB sdblob;
236 struct dcerpc_binding_handle *b = p->binding_handle;
237 const struct dcerpc_binding *binding = dcerpc_binding_handle_get_binding(b);
238 uint16_t flags = dcerpc_binding_get_flags(binding);
239
240 if (sec_info_ptr) {
241 sec_info = *sec_info_ptr;
242 } else {
243 sec_info = SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL;
244 }
245
246 ZERO_STRUCT(r);
247
248 r.in.handle = handle;
249 r.in.sec_info = sec_info;
250 r.in.sd = r.out.sd = talloc_zero(tctx, struct KeySecurityData);
251 r.in.sd->size = 0x1000;
252
253 torture_assert_ntstatus_ok(tctx,
254 dcerpc_winreg_GetKeySecurity_r(b, tctx, &r),
255 "GetKeySecurity failed");
256
257 torture_assert_werr_equal(tctx, r.out.result, get_werr,
258 "GetKeySecurity failed");
259
260 sdblob.data = r.out.sd->data;
261 sdblob.length = r.out.sd->len;
262
263 sd = talloc_zero(tctx, struct security_descriptor);
264
265 torture_assert_ndr_success(tctx,
266 ndr_pull_struct_blob(&sdblob, tctx, sd,
267 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor),
268 "pull_security_descriptor failed");
269
270 if (flags & DCERPC_DEBUG_PRINT_OUT) {
271 NDR_PRINT_DEBUG(security_descriptor, sd);
272 }
273
274 if (sd_out) {
275 *sd_out = sd;
276 } else {
277 talloc_free(sd);
278 }
279
280 return true;
281 }
282
283 static bool test_GetKeySecurity(struct dcerpc_pipe *p,
284 struct torture_context *tctx,
285 struct policy_handle *handle,
286 struct security_descriptor **sd_out)
287 {
288 return _test_GetKeySecurity(p, tctx, handle, NULL, WERR_OK, sd_out);
289 }
290
291 static bool _test_SetKeySecurity(struct dcerpc_pipe *p,
292 struct torture_context *tctx,
293 struct policy_handle *handle,
294 uint32_t *sec_info_ptr,
295 struct security_descriptor *sd,
296 WERROR werr)
297 {
298 struct winreg_SetKeySecurity r;
299 struct KeySecurityData *sdata = NULL;
300 DATA_BLOB sdblob;
301 uint32_t sec_info;
302 struct dcerpc_binding_handle *b = p->binding_handle;
303 const struct dcerpc_binding *binding = dcerpc_binding_handle_get_binding(b);
304 uint16_t flags = dcerpc_binding_get_flags(binding);
305
306 ZERO_STRUCT(r);
307
308 if (sd && (flags & DCERPC_DEBUG_PRINT_OUT)) {
309 NDR_PRINT_DEBUG(security_descriptor, sd);
310 }
311
312 torture_assert_ndr_success(tctx,
313 ndr_push_struct_blob(&sdblob, tctx, sd,
314 (ndr_push_flags_fn_t)ndr_push_security_descriptor),
315 "push_security_descriptor failed");
316
317 sdata = talloc_zero(tctx, struct KeySecurityData);
318 sdata->data = sdblob.data;
319 sdata->size = sdblob.length;
320 sdata->len = sdblob.length;
321
322 if (sec_info_ptr) {
323 sec_info = *sec_info_ptr;
324 } else {
325 sec_info = SECINFO_UNPROTECTED_SACL |
326 SECINFO_UNPROTECTED_DACL;
327 if (sd->owner_sid) {
328 sec_info |= SECINFO_OWNER;
329 }
330 if (sd->group_sid) {
331 sec_info |= SECINFO_GROUP;
332 }
333 if (sd->sacl) {
334 sec_info |= SECINFO_SACL;
335 }
336 if (sd->dacl) {
337 sec_info |= SECINFO_DACL;
338 }
339 }
340
341 r.in.handle = handle;
342 r.in.sec_info = sec_info;
343 r.in.sd = sdata;
344
345 torture_assert_ntstatus_ok(tctx,
346 dcerpc_winreg_SetKeySecurity_r(b, tctx, &r),
347 "SetKeySecurity failed");
348
349 torture_assert_werr_equal(tctx, r.out.result, werr,
350 "SetKeySecurity failed");
351
352 return true;
353 }
354
355 static bool test_SetKeySecurity(struct dcerpc_pipe *p,
356 struct torture_context *tctx,
357 struct policy_handle *handle,
358 struct security_descriptor *sd)
359 {
360 return _test_SetKeySecurity(p, tctx, handle, NULL, sd, WERR_OK);
361 }
362
363 static bool test_CloseKey(struct dcerpc_binding_handle *b,
364 struct torture_context *tctx,
365 struct policy_handle *handle)
366 {
367 struct winreg_CloseKey r;
368
369 ZERO_STRUCT(r);
370 r.in.handle = r.out.handle = handle;
371
372 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey_r(b, tctx, &r),
373 "CloseKey failed");
374
375 torture_assert_werr_ok(tctx, r.out.result, "CloseKey failed");
376
377 return true;
378 }
379
380 static bool test_FlushKey(struct dcerpc_binding_handle *b,
381 struct torture_context *tctx,
382 struct policy_handle *handle)
383 {
384 struct winreg_FlushKey r;
385
386 ZERO_STRUCT(r);
387 r.in.handle = handle;
388
389 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_FlushKey_r(b, tctx, &r),
390 "FlushKey failed");
391
392 torture_assert_werr_ok(tctx, r.out.result, "FlushKey failed");
393
394 return true;
395 }
396
397 static bool test_OpenKey_opts(struct torture_context *tctx,
398 struct dcerpc_binding_handle *b,
399 struct policy_handle *hive_handle,
400 const char *keyname,
401 uint32_t options,
402 uint32_t access_mask,
403 struct policy_handle *key_handle,
404 WERROR expected_result)
405 {
406 struct winreg_OpenKey r;
407
408 ZERO_STRUCT(r);
409 r.in.parent_handle = hive_handle;
410 init_winreg_String(&r.in.keyname, keyname);
411 r.in.options = options;
412 r.in.access_mask = access_mask;
413 r.out.handle = key_handle;
414
415 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey_r(b, tctx, &r),
416 "OpenKey failed");
417
418 torture_assert_werr_equal(tctx, r.out.result, expected_result,
419 "OpenKey failed");
420
421 return true;
422 }
423
424 static bool test_OpenKey(struct dcerpc_binding_handle *b,
425 struct torture_context *tctx,
426 struct policy_handle *hive_handle,
427 const char *keyname, struct policy_handle *key_handle)
428 {
429 return test_OpenKey_opts(tctx, b, hive_handle, keyname,
430 REG_OPTION_NON_VOLATILE,
431 SEC_FLAG_MAXIMUM_ALLOWED,
432 key_handle,
433 WERR_OK);
434 }
435
436 static bool test_Cleanup(struct dcerpc_binding_handle *b,
437 struct torture_context *tctx,
438 struct policy_handle *handle, const char *key)
439 {
440 struct winreg_DeleteKey r;
441
442 ZERO_STRUCT(r);
443 r.in.handle = handle;
444
445 init_winreg_String(&r.in.key, key);
446 dcerpc_winreg_DeleteKey_r(b, tctx, &r);
447
448 return true;
449 }
450
451 static bool _test_GetSetSecurityDescriptor(struct dcerpc_pipe *p,
452 struct torture_context *tctx,
453 struct policy_handle *handle,
454 WERROR get_werr,
455 WERROR set_werr)
456 {
457 struct security_descriptor *sd = NULL;
458
459 if (!_test_GetKeySecurity(p, tctx, handle, NULL, get_werr, &sd)) {
460 return false;
461 }
462
463 if (!_test_SetKeySecurity(p, tctx, handle, NULL, sd, set_werr)) {
464 return false;
465 }
466
467 return true;
468 }
469
470 static bool test_SecurityDescriptor(struct dcerpc_pipe *p,
471 struct torture_context *tctx,
472 struct policy_handle *handle,
473 const char *key)
474 {
475 struct policy_handle new_handle;
476 bool ret = true;
477 struct dcerpc_binding_handle *b = p->binding_handle;
478
479 torture_comment(tctx, "SecurityDescriptor get & set\n");
480
481 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
482 return false;
483 }
484
485 if (!_test_GetSetSecurityDescriptor(p, tctx, &new_handle,
486 WERR_OK, WERR_OK)) {
487 ret = false;
488 }
489
490 if (!test_CloseKey(b, tctx, &new_handle)) {
491 return false;
492 }
493
494 return ret;
495 }
496
497 static bool _test_SecurityDescriptor(struct dcerpc_pipe *p,
498 struct torture_context *tctx,
499 struct policy_handle *handle,
500 uint32_t access_mask,
501 const char *key,
502 WERROR open_werr,
503 WERROR get_werr,
504 WERROR set_werr)
505 {
506 struct policy_handle new_handle;
507 bool ret = true;
508 struct dcerpc_binding_handle *b = p->binding_handle;
509
510 torture_assert(tctx,
511 test_OpenKey_opts(tctx, b, handle, key,
512 REG_OPTION_NON_VOLATILE,
513 access_mask,
514 &new_handle,
515 open_werr),
516 "failed to open key");
517
518 if (!W_ERROR_IS_OK(open_werr)) {
519 return true;
520 }
521
522 if (!_test_GetSetSecurityDescriptor(p, tctx, &new_handle,
523 get_werr, set_werr)) {
524 ret = false;
525 }
526
527 if (!test_CloseKey(b, tctx, &new_handle)) {
528 return false;
529 }
530
531 return ret;
532 }
533
534 static bool test_dacl_trustee_present(struct dcerpc_pipe *p,
535 struct torture_context *tctx,
536 struct policy_handle *handle,
537 const struct dom_sid *sid)
538 {
539 struct security_descriptor *sd = NULL;
540 int i;
541
542 if (!test_GetKeySecurity(p, tctx, handle, &sd)) {
543 return false;
544 }
545
546 if (!sd || !sd->dacl) {
547 return false;
548 }
549
550 for (i = 0; i < sd->dacl->num_aces; i++) {
551 if (dom_sid_equal(&sd->dacl->aces[i].trustee, sid)) {
552 return true;
553 }
554 }
555
556 return false;
557 }
558
559 static bool _test_dacl_trustee_present(struct dcerpc_pipe *p,
560 struct torture_context *tctx,
561 struct policy_handle *handle,
562 const char *key,
563 const struct dom_sid *sid)
564 {
565 struct policy_handle new_handle;
566 bool ret = true;
567 struct dcerpc_binding_handle *b = p->binding_handle;
568
569 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
570 return false;
571 }
572
573 ret = test_dacl_trustee_present(p, tctx, &new_handle, sid);
574
575 test_CloseKey(b, tctx, &new_handle);
576
577 return ret;
578 }
579
580 static bool test_sacl_trustee_present(struct dcerpc_pipe *p,
581 struct torture_context *tctx,
582 struct policy_handle *handle,
583 const struct dom_sid *sid)
584 {
585 struct security_descriptor *sd = NULL;
586 int i;
587 uint32_t sec_info = SECINFO_SACL;
588
589 if (!_test_GetKeySecurity(p, tctx, handle, &sec_info, WERR_OK, &sd)) {
590 return false;
591 }
592
593 if (!sd || !sd->sacl) {
594 return false;
595 }
596
597 for (i = 0; i < sd->sacl->num_aces; i++) {
598 if (dom_sid_equal(&sd->sacl->aces[i].trustee, sid)) {
599 return true;
600 }
601 }
602
603 return false;
604 }
605
606 static bool _test_sacl_trustee_present(struct dcerpc_pipe *p,
607 struct torture_context *tctx,
608 struct policy_handle *handle,
609 const char *key,
610 const struct dom_sid *sid)
611 {
612 struct policy_handle new_handle;
613 bool ret = true;
614 struct dcerpc_binding_handle *b = p->binding_handle;
615
616 torture_assert(tctx,
617 test_OpenKey_opts(tctx, b, handle, key,
618 REG_OPTION_NON_VOLATILE,
619 SEC_FLAG_SYSTEM_SECURITY,
620 &new_handle,
621 WERR_OK),
622 "failed to open key");
623
624 ret = test_sacl_trustee_present(p, tctx, &new_handle, sid);
625
626 test_CloseKey(b, tctx, &new_handle);
627
628 return ret;
629 }
630
631 static bool test_owner_present(struct dcerpc_pipe *p,
632 struct torture_context *tctx,
633 struct policy_handle *handle,
634 const struct dom_sid *sid)
635 {
636 struct security_descriptor *sd = NULL;
637 uint32_t sec_info = SECINFO_OWNER;
638
639 if (!_test_GetKeySecurity(p, tctx, handle, &sec_info, WERR_OK, &sd)) {
640 return false;
641 }
642
643 if (!sd || !sd->owner_sid) {
644 return false;
645 }
646
647 return dom_sid_equal(sd->owner_sid, sid);
648 }
649
650 static bool _test_owner_present(struct dcerpc_pipe *p,
651 struct torture_context *tctx,
652 struct policy_handle *handle,
653 const char *key,
654 const struct dom_sid *sid)
655 {
656 struct policy_handle new_handle;
657 bool ret = true;
658 struct dcerpc_binding_handle *b = p->binding_handle;
659
660 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
661 return false;
662 }
663
664 ret = test_owner_present(p, tctx, &new_handle, sid);
665
666 test_CloseKey(b, tctx, &new_handle);
667
668 return ret;
669 }
670
671 static bool test_group_present(struct dcerpc_pipe *p,
672 struct torture_context *tctx,
673 struct policy_handle *handle,
674 const struct dom_sid *sid)
675 {
676 struct security_descriptor *sd = NULL;
677 uint32_t sec_info = SECINFO_GROUP;
678
679 if (!_test_GetKeySecurity(p, tctx, handle, &sec_info, WERR_OK, &sd)) {
680 return false;
681 }
682
683 if (!sd || !sd->group_sid) {
684 return false;
685 }
686
687 return dom_sid_equal(sd->group_sid, sid);
688 }
689
690 static bool _test_group_present(struct dcerpc_pipe *p,
691 struct torture_context *tctx,
692 struct policy_handle *handle,
693 const char *key,
694 const struct dom_sid *sid)
695 {
696 struct policy_handle new_handle;
697 bool ret = true;
698 struct dcerpc_binding_handle *b = p->binding_handle;
699
700 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
701 return false;
702 }
703
704 ret = test_group_present(p, tctx, &new_handle, sid);
705
706 test_CloseKey(b, tctx, &new_handle);
707
708 return ret;
709 }
710
711 static bool test_dacl_trustee_flags_present(struct dcerpc_pipe *p,
712 struct torture_context *tctx,
713 struct policy_handle *handle,
714 const struct dom_sid *sid,
715 uint8_t flags)
716 {
717 struct security_descriptor *sd = NULL;
718 int i;
719
720 if (!test_GetKeySecurity(p, tctx, handle, &sd)) {
721 return false;
722 }
723
724 if (!sd || !sd->dacl) {
725 return false;
726 }
727
728 for (i = 0; i < sd->dacl->num_aces; i++) {
729 if ((dom_sid_equal(&sd->dacl->aces[i].trustee, sid)) &&
730 (sd->dacl->aces[i].flags == flags)) {
731 return true;
732 }
733 }
734
735 return false;
736 }
737
738 static bool test_dacl_ace_present(struct dcerpc_pipe *p,
739 struct torture_context *tctx,
740 struct policy_handle *handle,
741 const struct security_ace *ace)
742 {
743 struct security_descriptor *sd = NULL;
744 int i;
745
746 if (!test_GetKeySecurity(p, tctx, handle, &sd)) {
747 return false;
748 }
749
750 if (!sd || !sd->dacl) {
751 return false;
752 }
753
754 for (i = 0; i < sd->dacl->num_aces; i++) {
755 if (security_ace_equal(&sd->dacl->aces[i], ace)) {
756 return true;
757 }
758 }
759
760 return false;
761 }
762
763 static bool test_RestoreSecurity(struct dcerpc_pipe *p,
764 struct torture_context *tctx,
765 struct policy_handle *handle,
766 const char *key,
767 struct security_descriptor *sd)
768 {
769 struct policy_handle new_handle;
770 bool ret = true;
771 struct dcerpc_binding_handle *b = p->binding_handle;
772
773 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
774 return false;
775 }
776
777 if (!test_SetKeySecurity(p, tctx, &new_handle, sd)) {
778 ret = false;
779 }
780
781 if (!test_CloseKey(b, tctx, &new_handle)) {
782 ret = false;
783 }
784
785 return ret;
786 }
787
788 static bool test_BackupSecurity(struct dcerpc_pipe *p,
789 struct torture_context *tctx,
790 struct policy_handle *handle,
791 const char *key,
792 struct security_descriptor **sd)
793 {
794 struct policy_handle new_handle;
795 bool ret = true;
796 struct dcerpc_binding_handle *b = p->binding_handle;
797
798 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
799 return false;
800 }
801
802 if (!test_GetKeySecurity(p, tctx, &new_handle, sd)) {
803 ret = false;
804 }
805
806 if (!test_CloseKey(b, tctx, &new_handle)) {
807 ret = false;
808 }
809
810 return ret;
811 }
812
813 static bool test_SecurityDescriptorInheritance(struct dcerpc_pipe *p,
814 struct torture_context *tctx,
815 struct policy_handle *handle,
816 const char *key)
817 {
818 /* get sd
819 add ace SEC_ACE_FLAG_CONTAINER_INHERIT
820 set sd
821 get sd
822 check ace
823 add subkey
824 get sd
825 check ace
826 add subsubkey
827 get sd
828 check ace
829 del subsubkey
830 del subkey
831 reset sd
832 */
833
834 struct security_descriptor *sd = NULL;
835 struct security_descriptor *sd_orig = NULL;
836 struct security_ace *ace = NULL;
837 struct policy_handle new_handle;
838 bool ret = true;
839 struct dcerpc_binding_handle *b = p->binding_handle;
840 const char *test_subkey_sd;
841 const char *test_subsubkey_sd;
842
843 torture_comment(tctx, "SecurityDescriptor inheritance\n");
844
845 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
846 return false;
847 }
848
849 if (!_test_GetKeySecurity(p, tctx, &new_handle, NULL, WERR_OK, &sd)) {
850 return false;
851 }
852
853 sd_orig = security_descriptor_copy(tctx, sd);
854 if (sd_orig == NULL) {
855 return false;
856 }
857
858 ace = security_ace_create(tctx,
859 TEST_SID,
860 SEC_ACE_TYPE_ACCESS_ALLOWED,
861 SEC_STD_REQUIRED,
862 SEC_ACE_FLAG_CONTAINER_INHERIT);
863
864 torture_assert_ntstatus_ok(tctx,
865 security_descriptor_dacl_add(sd, ace),
866 "failed to add ace");
867
868 /* FIXME: add further tests for these flags */
869 sd->type |= SEC_DESC_DACL_AUTO_INHERIT_REQ |
870 SEC_DESC_SACL_AUTO_INHERITED;
871
872 if (!test_SetKeySecurity(p, tctx, &new_handle, sd)) {
873 return false;
874 }
875
876 torture_assert(tctx,
877 test_dacl_ace_present(p, tctx, &new_handle, ace),
878 "new ACE not present!");
879
880 if (!test_CloseKey(b, tctx, &new_handle)) {
881 return false;
882 }
883
884 test_subkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBKEY_SD);
885
886 if (!test_CreateKey(b, tctx, handle, test_subkey_sd, NULL)) {
887 ret = false;
888 goto out;
889 }
890
891 if (!test_OpenKey(b, tctx, handle, test_subkey_sd, &new_handle)) {
892 ret = false;
893 goto out;
894 }
895
896 if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
897 torture_comment(tctx, "inherited ACE not present!\n");
898 ret = false;
899 goto out;
900 }
901
902 test_subsubkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBSUBKEY_SD);
903
904 test_CloseKey(b, tctx, &new_handle);
905 if (!test_CreateKey(b, tctx, handle, test_subsubkey_sd, NULL)) {
906 ret = false;
907 goto out;
908 }
909
910 if (!test_OpenKey(b, tctx, handle, test_subsubkey_sd, &new_handle)) {
911 ret = false;
912 goto out;
913 }
914
915 if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
916 torture_comment(tctx, "inherited ACE not present!\n");
917 ret = false;
918 goto out;
919 }
920
921 out:
922 test_CloseKey(b, tctx, &new_handle);
923 test_Cleanup(b, tctx, handle, test_subkey_sd);
924 test_RestoreSecurity(p, tctx, handle, key, sd_orig);
925
926 return ret;
927 }
928
929 static bool test_SecurityDescriptorBlockInheritance(struct dcerpc_pipe *p,
930 struct torture_context *tctx,
931 struct policy_handle *handle,
932 const char *key)
933 {
934 /* get sd
935 add ace SEC_ACE_FLAG_NO_PROPAGATE_INHERIT
936 set sd
937 add subkey/subkey
938 get sd
939 check ace
940 get sd from subkey
941 check ace
942 del subkey/subkey
943 del subkey
944 reset sd
945 */
946
947 struct security_descriptor *sd = NULL;
948 struct security_descriptor *sd_orig = NULL;
949 struct security_ace *ace = NULL;
950 struct policy_handle new_handle;
951 struct dom_sid *sid = NULL;
952 bool ret = true;
953 uint8_t ace_flags = 0x0;
954 struct dcerpc_binding_handle *b = p->binding_handle;
955 const char *test_subkey_sd;
956 const char *test_subsubkey_sd;
957
958 torture_comment(tctx, "SecurityDescriptor inheritance block\n");
959
960 if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
961 return false;
962 }
963
964 if (!_test_GetKeySecurity(p, tctx, &new_handle, NULL, WERR_OK, &sd)) {
965 return false;
966 }
967
968 sd_orig = security_descriptor_copy(tctx, sd);
969 if (sd_orig == NULL) {
970 return false;
971 }
972
973 ace = security_ace_create(tctx,
974 TEST_SID,
975 SEC_ACE_TYPE_ACCESS_ALLOWED,
976 SEC_STD_REQUIRED,
977 SEC_ACE_FLAG_CONTAINER_INHERIT |
978 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT);
979
980 torture_assert_ntstatus_ok(tctx,
981 security_descriptor_dacl_add(sd, ace),
982 "failed to add ace");
983
984 if (!_test_SetKeySecurity(p, tctx, &new_handle, NULL, sd, WERR_OK)) {
985 return false;
986 }
987
988 torture_assert(tctx,
989 test_dacl_ace_present(p, tctx, &new_handle, ace),
990 "new ACE not present!");
991
992 if (!test_CloseKey(b, tctx, &new_handle)) {
993 return false;
994 }
995
996 test_subkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBKEY_SD);
997 test_subsubkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBSUBKEY_SD);
998
999 if (!test_CreateKey(b, tctx, handle, test_subsubkey_sd, NULL)) {
1000 return false;
1001 }
1002
1003 if (!test_OpenKey(b, tctx, handle, test_subsubkey_sd, &new_handle)) {
1004 ret = false;
1005 goto out;
1006 }
1007
1008 if (test_dacl_ace_present(p, tctx, &new_handle, ace)) {
1009 torture_comment(tctx, "inherited ACE present but should not!\n");
1010 ret = false;
1011 goto out;
1012 }
1013
1014 sid = dom_sid_parse_talloc(tctx, TEST_SID);
1015 if (sid == NULL) {
1016 return false;
1017 }
1018
1019 if (test_dacl_trustee_present(p, tctx, &new_handle, sid)) {
1020 torture_comment(tctx, "inherited trustee SID present but should not!\n");
1021 ret = false;
1022 goto out;
1023 }
1024
1025 test_CloseKey(b, tctx, &new_handle);
1026
1027 if (!test_OpenKey(b, tctx, handle, test_subkey_sd, &new_handle)) {
1028 ret = false;
1029 goto out;
1030 }
1031
1032 if (test_dacl_ace_present(p, tctx, &new_handle, ace)) {
1033 torture_comment(tctx, "inherited ACE present but should not!\n");
1034 ret = false;
1035 goto out;
1036 }
1037
1038 if (!test_dacl_trustee_flags_present(p, tctx, &new_handle, sid, ace_flags)) {
1039 torture_comment(tctx, "inherited trustee SID with flags 0x%02x not present!\n",
1040 ace_flags);
1041 ret = false;
1042 goto out;
1043 }
1044
1045 out:
1046 test_CloseKey(b, tctx, &new_handle);
1047 test_Cleanup(b, tctx, handle, test_subkey_sd);
1048 test_RestoreSecurity(p, tctx, handle, key, sd_orig);
1049
1050 return ret;
1051 }
1052
1053 static bool test_SecurityDescriptorsMasks(struct dcerpc_pipe *p,
1054 struct torture_context *tctx,
1055 struct policy_handle *handle,
1056 const char *key)
1057 {
1058 bool ret = true;
1059 int i;
1060
1061 struct winreg_mask_result_table {
1062 uint32_t access_mask;
1063 WERROR open_werr;
1064 WERROR get_werr;
1065 WERROR set_werr;
1066 } sd_mask_tests[] = {
1067 { 0,
1068 WERR_ACCESS_DENIED, WERR_FILE_NOT_FOUND, WERR_FOOBAR },
1069 { SEC_FLAG_MAXIMUM_ALLOWED,
1070 WERR_OK, WERR_OK, WERR_OK },
1071 { SEC_STD_WRITE_DAC,
1072 WERR_OK, WERR_ACCESS_DENIED, WERR_FOOBAR },
1073 { SEC_FLAG_SYSTEM_SECURITY,
1074 WERR_OK, WERR_ACCESS_DENIED, WERR_FOOBAR }
1075 };
1076
1077 /* FIXME: before this test can ever run successfully we need a way to
1078 * correctly read a NULL security_descritpor in ndr, get the required
1079 * length, requery, etc.
1080 */
1081
1082 return true;
1083
1084 for (i=0; i < ARRAY_SIZE(sd_mask_tests); i++) {
1085
1086 torture_comment(tctx,
1087 "SecurityDescriptor get & set with access_mask: 0x%08x\n",
1088 sd_mask_tests[i].access_mask);
1089 torture_comment(tctx,
1090 "expecting: open %s, get: %s, set: %s\n",
1091 win_errstr(sd_mask_tests[i].open_werr),
1092 win_errstr(sd_mask_tests[i].get_werr),
1093 win_errstr(sd_mask_tests[i].set_werr));
1094
1095 if (_test_SecurityDescriptor(p, tctx, handle,
1096 sd_mask_tests[i].access_mask, key,
1097 sd_mask_tests[i].open_werr,
1098 sd_mask_tests[i].get_werr,
1099 sd_mask_tests[i].set_werr)) {
1100 ret = false;
1101 }
1102 }
1103
1104 return ret;
1105 }
1106
1107 typedef bool (*secinfo_verify_fn)(struct dcerpc_pipe *,
1108 struct torture_context *,
1109 struct policy_handle *,
1110 const char *,
1111 const struct dom_sid *);
1112
1113 static bool test_SetSecurityDescriptor_SecInfo(struct dcerpc_pipe *p,
1114 struct torture_context *tctx,
1115 struct policy_handle *handle,
1116 const char *key,
1117 const char *test,
1118 uint32_t access_mask,
1119 uint32_t sec_info,
1120 struct security_descriptor *sd,
1121 WERROR set_werr,
1122 bool expect_present,
1123 bool (*fn) (struct dcerpc_pipe *,
1124 struct torture_context *,
1125 struct policy_handle *,
1126 const char *,
1127 const struct dom_sid *),
1128 const struct dom_sid *sid)
1129 {
1130 struct policy_handle new_handle;
1131 struct dcerpc_binding_handle *b = p->binding_handle;
1132
1133 torture_comment(tctx, "SecurityDescriptor (%s) sets for secinfo: "
1134 "0x%08x, access_mask: 0x%08x\n",
1135 test, sec_info, access_mask);
1136
1137 torture_assert(tctx,
1138 test_OpenKey_opts(tctx, b, handle, key,
1139 REG_OPTION_NON_VOLATILE,
1140 access_mask,
1141 &new_handle,
1142 WERR_OK),
1143 "failed to open key");
1144
1145 if (!_test_SetKeySecurity(p, tctx, &new_handle, &sec_info,
1146 sd,
1147 set_werr)) {
1148 torture_warning(tctx,
1149 "SetKeySecurity with secinfo: 0x%08x has failed\n",
1150 sec_info);
1151 smb_panic("");
1152 test_CloseKey(b, tctx, &new_handle);
1153 return false;
1154 }
1155
1156 test_CloseKey(b, tctx, &new_handle);
1157
1158 if (W_ERROR_IS_OK(set_werr)) {
1159 bool present;
1160 present = fn(p, tctx, handle, key, sid);
1161 if ((expect_present) && (!present)) {
1162 torture_warning(tctx,
1163 "%s sid is not present!\n",
1164 test);
1165 return false;
1166 }
1167 if ((!expect_present) && (present)) {
1168 torture_warning(tctx,
1169 "%s sid is present but not expected!\n",
1170 test);
1171 return false;
1172 }
1173 }
1174
1175 return true;
1176 }
1177
1178 static bool test_SecurityDescriptorsSecInfo(struct dcerpc_pipe *p,
1179 struct torture_context *tctx,
1180 struct policy_handle *handle,
1181 const char *key)
1182 {
1183 struct security_descriptor *sd_orig = NULL;
1184 struct dom_sid *sid = NULL;
1185 bool ret = true;
1186 int i, a;
1187
1188 struct security_descriptor *sd_owner =
1189 security_descriptor_dacl_create(tctx,
1190 0,
1191 TEST_SID, NULL, NULL);
1192
1193 struct security_descriptor *sd_group =
1194 security_descriptor_dacl_create(tctx,
1195 0,
1196 NULL, TEST_SID, NULL);
1197
1198 struct security_descriptor *sd_dacl =
1199 security_descriptor_dacl_create(tctx,
1200 0,
1201 NULL, NULL,
1202 TEST_SID,
1203 SEC_ACE_TYPE_ACCESS_ALLOWED,
1204 SEC_GENERIC_ALL,
1205 0,
1206 SID_NT_AUTHENTICATED_USERS,
1207 SEC_ACE_TYPE_ACCESS_ALLOWED,
1208 SEC_GENERIC_ALL,
1209 0,
1210 NULL);
1211
1212 struct security_descriptor *sd_sacl =
1213 security_descriptor_sacl_create(tctx,
1214 0,
1215 NULL, NULL,
1216 TEST_SID,
1217 SEC_ACE_TYPE_SYSTEM_AUDIT,
1218 SEC_GENERIC_ALL,
1219 SEC_ACE_FLAG_SUCCESSFUL_ACCESS,
1220 NULL);
1221
1222 struct winreg_secinfo_table {
1223 struct security_descriptor *sd;
1224 uint32_t sec_info;
1225 WERROR set_werr;
1226 bool sid_present;
1227 secinfo_verify_fn fn;
1228 };
1229
1230 struct winreg_secinfo_table sec_info_owner_tests[] = {
1231 {
1232 .sd = sd_owner,
1233 .sec_info = 0,
1234 .set_werr = WERR_OK,
1235 .sid_present = false,
1236 .fn = (secinfo_verify_fn)_test_owner_present,
1237 },
1238 {
1239 .sd = sd_owner,
1240 .sec_info = SECINFO_OWNER,
1241 .set_werr = WERR_OK,
1242 .sid_present = true,
1243 .fn = (secinfo_verify_fn)_test_owner_present,
1244 },
1245 {
1246 .sd = sd_owner,
1247 .sec_info = SECINFO_GROUP,
1248 .set_werr = WERR_INVALID_PARAMETER,
1249 .sid_present = false,
1250 },
1251 {
1252 .sd = sd_owner,
1253 .sec_info = SECINFO_DACL,
1254 .set_werr = WERR_OK,
1255 .sid_present = true,
1256 .fn = (secinfo_verify_fn)_test_owner_present,
1257 },
1258 {
1259 .sd = sd_owner,
1260 .sec_info = SECINFO_SACL,
1261 .set_werr = WERR_ACCESS_DENIED,
1262 .sid_present = false,
1263 },
1264 };
1265
1266 uint32_t sd_owner_good_access_masks[] = {
1267 SEC_FLAG_MAXIMUM_ALLOWED,
1268 /* SEC_STD_WRITE_OWNER, */
1269 };
1270
1271 struct winreg_secinfo_table sec_info_group_tests[] = {
1272 {
1273 .sd = sd_group,
1274 .sec_info = 0,
1275 .set_werr = WERR_OK,
1276 .sid_present = false,
1277 .fn = (secinfo_verify_fn)_test_group_present,
1278 },
1279 {
1280 .sd = sd_group,
1281 .sec_info = SECINFO_OWNER,
1282 .set_werr = WERR_INVALID_PARAMETER,
1283 .sid_present = false,
1284 },
1285 {
1286 .sd = sd_group,
1287 .sec_info = SECINFO_GROUP,
1288 .set_werr = WERR_OK,
1289 .sid_present = true,
1290 .fn = (secinfo_verify_fn)_test_group_present,
1291 },
1292 {
1293 .sd = sd_group,
1294 .sec_info = SECINFO_DACL,
1295 .set_werr = WERR_OK,
1296 .sid_present = true,
1297 .fn = (secinfo_verify_fn)_test_group_present,
1298 },
1299 {
1300 .sd = sd_group,
1301 .sec_info = SECINFO_SACL,
1302 .set_werr = WERR_ACCESS_DENIED,
1303 .sid_present = false,
1304 },
1305 };
1306
1307 uint32_t sd_group_good_access_masks[] = {
1308 SEC_FLAG_MAXIMUM_ALLOWED,
1309 };
1310
1311 struct winreg_secinfo_table sec_info_dacl_tests[] = {
1312 {
1313 .sd = sd_dacl,
1314 .sec_info = 0,
1315 .set_werr = WERR_OK,
1316 .sid_present = false,
1317 .fn = (secinfo_verify_fn)_test_dacl_trustee_present,
1318 },
1319 {
1320 .sd = sd_dacl,
1321 .sec_info = SECINFO_OWNER,
1322 .set_werr = WERR_INVALID_PARAMETER,
1323 .sid_present = false,
1324 },
1325 {
1326 .sd = sd_dacl,
1327 .sec_info = SECINFO_GROUP,
1328 .set_werr = WERR_INVALID_PARAMETER,
1329 .sid_present = false,
1330 },
1331 {
1332 .sd = sd_dacl,
1333 .sec_info = SECINFO_DACL,
1334 .set_werr = WERR_OK,
1335 .sid_present = true,
1336 .fn = (secinfo_verify_fn)_test_dacl_trustee_present
1337 },
1338 {
1339 .sd = sd_dacl,
1340 .sec_info = SECINFO_SACL,
1341 .set_werr = WERR_ACCESS_DENIED,
1342 .sid_present = false,
1343 },
1344 };
1345
1346 uint32_t sd_dacl_good_access_masks[] = {
1347 SEC_FLAG_MAXIMUM_ALLOWED,
1348 SEC_STD_WRITE_DAC,
1349 };
1350
1351 struct winreg_secinfo_table sec_info_sacl_tests[] = {
1352 {
1353 .sd = sd_sacl,
1354 .sec_info = 0,
1355 .set_werr = WERR_OK,
1356 .sid_present = false,
1357 .fn = (secinfo_verify_fn)_test_sacl_trustee_present,
1358 },
1359 {
1360 .sd = sd_sacl,
1361 .sec_info = SECINFO_OWNER,
1362 .set_werr = WERR_INVALID_PARAMETER,
1363 .sid_present = false,
1364 },
1365 {
1366 .sd = sd_sacl,
1367 .sec_info = SECINFO_GROUP,
1368 .set_werr = WERR_INVALID_PARAMETER,
1369 .sid_present = false,
1370 },
1371 {
1372 .sd = sd_sacl,
1373 .sec_info = SECINFO_DACL,
1374 .set_werr = WERR_OK,
1375 .sid_present = false,
1376 .fn = (secinfo_verify_fn)_test_sacl_trustee_present,
1377 },
1378 {
1379 .sd = sd_sacl,
1380 .sec_info = SECINFO_SACL,
1381 .set_werr = WERR_OK,
1382 .sid_present = true,
1383 .fn = (secinfo_verify_fn)_test_sacl_trustee_present,
1384 },
1385 };
1386
1387 uint32_t sd_sacl_good_access_masks[] = {
1388 SEC_FLAG_MAXIMUM_ALLOWED | SEC_FLAG_SYSTEM_SECURITY,
1389 /* SEC_FLAG_SYSTEM_SECURITY, */
1390 };
1391
1392 sid = dom_sid_parse_talloc(tctx, TEST_SID);
1393 if (sid == NULL) {
1394 return false;
1395 }
1396
1397 if (!test_BackupSecurity(p, tctx, handle, key, &sd_orig)) {
1398 return false;
1399 }
1400
1401 /* OWNER */
1402
1403 for (i=0; i < ARRAY_SIZE(sec_info_owner_tests); i++) {
1404
1405 for (a=0; a < ARRAY_SIZE(sd_owner_good_access_masks); a++) {
1406
1407 if (!test_SetSecurityDescriptor_SecInfo(p, tctx, handle,
1408 key,
1409 "OWNER",
1410 sd_owner_good_access_masks[a],
1411 sec_info_owner_tests[i].sec_info,
1412 sec_info_owner_tests[i].sd,
1413 sec_info_owner_tests[i].set_werr,
1414 sec_info_owner_tests[i].sid_present,
1415 sec_info_owner_tests[i].fn,
1416 sid))
1417 {
1418 torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for OWNER\n");
1419 ret = false;
1420 goto out;
1421 }
1422 }
1423 }
1424
1425 /* GROUP */
1426
1427 for (i=0; i < ARRAY_SIZE(sec_info_group_tests); i++) {
1428
1429 for (a=0; a < ARRAY_SIZE(sd_group_good_access_masks); a++) {
1430
1431 if (!test_SetSecurityDescriptor_SecInfo(p, tctx, handle,
1432 key,
1433 "GROUP",
1434 sd_group_good_access_masks[a],
1435 sec_info_group_tests[i].sec_info,
1436 sec_info_group_tests[i].sd,
1437 sec_info_group_tests[i].set_werr,
1438 sec_info_group_tests[i].sid_present,
1439 sec_info_group_tests[i].fn,
1440 sid))
1441 {
1442 torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for GROUP\n");
1443 ret = false;
1444 goto out;
1445 }
1446 }
1447 }
1448
1449 /* DACL */
1450
1451 for (i=0; i < ARRAY_SIZE(sec_info_dacl_tests); i++) {
1452
1453 for (a=0; a < ARRAY_SIZE(sd_dacl_good_access_masks); a++) {
1454
1455 if (!test_SetSecurityDescriptor_SecInfo(p, tctx, handle,
1456 key,
1457 "DACL",
1458 sd_dacl_good_access_masks[a],
1459 sec_info_dacl_tests[i].sec_info,
1460 sec_info_dacl_tests[i].sd,
1461 sec_info_dacl_tests[i].set_werr,
1462 sec_info_dacl_tests[i].sid_present,
1463 sec_info_dacl_tests[i].fn,
1464 sid))
1465 {
1466 torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for DACL\n");
1467 ret = false;
1468 goto out;
1469 }
1470 }
1471 }
1472
1473 /* SACL */
1474
1475 for (i=0; i < ARRAY_SIZE(sec_info_sacl_tests); i++) {
1476
1477 for (a=0; a < ARRAY_SIZE(sd_sacl_good_access_masks); a++) {
1478
1479 if (!test_SetSecurityDescriptor_SecInfo(p, tctx, handle,
1480 key,
1481 "SACL",
1482 sd_sacl_good_access_masks[a],
1483 sec_info_sacl_tests[i].sec_info,
1484 sec_info_sacl_tests[i].sd,
1485 sec_info_sacl_tests[i].set_werr,
1486 sec_info_sacl_tests[i].sid_present,
1487 sec_info_sacl_tests[i].fn,
1488 sid))
1489 {
1490 torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for SACL\n");
1491 ret = false;
1492 goto out;
1493 }
1494 }
1495 }
1496
1497 out:
1498 test_RestoreSecurity(p, tctx, handle, key, sd_orig);
1499
1500 return ret;
1501 }
1502
1503 static bool test_SecurityDescriptors(struct dcerpc_pipe *p,
1504 struct torture_context *tctx,
1505 struct policy_handle *handle,
1506 const char *key)
1507 {
1508 bool ret = true;
1509
1510 if (!test_SecurityDescriptor(p, tctx, handle, key)) {
1511 torture_comment(tctx, "test_SecurityDescriptor failed\n");
1512 ret = false;
1513 }
1514
1515 if (!test_SecurityDescriptorInheritance(p, tctx, handle, key)) {
1516 torture_comment(tctx, "test_SecurityDescriptorInheritance failed\n");
1517 ret = false;
1518 }
1519
1520 if (!test_SecurityDescriptorBlockInheritance(p, tctx, handle, key)) {
1521 torture_comment(tctx, "test_SecurityDescriptorBlockInheritance failed\n");
1522 ret = false;
1523 }
1524
1525 if (!test_SecurityDescriptorsSecInfo(p, tctx, handle, key)) {
1526 torture_comment(tctx, "test_SecurityDescriptorsSecInfo failed\n");
1527 ret = false;
1528 }
1529
1530 if (!test_SecurityDescriptorsMasks(p, tctx, handle, key)) {
1531 torture_comment(tctx, "test_SecurityDescriptorsMasks failed\n");
1532 ret = false;
1533 }
1534
1535 return ret;
1536 }
1537
1538 static bool test_DeleteKey_opts(struct dcerpc_binding_handle *b,
1539 struct torture_context *tctx,
1540 struct policy_handle *handle,
1541 const char *key,
1542 WERROR expected_result)
1543 {
1544 struct winreg_DeleteKey r;
1545
1546 torture_comment(tctx, "Testing DeleteKey(%s)\n", key);
1547
1548 r.in.handle = handle;
1549 init_winreg_String(&r.in.key, key);
1550
1551 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_DeleteKey_r(b, tctx, &r),
1552 "Delete Key failed");
1553 torture_assert_werr_equal(tctx, r.out.result, expected_result,
1554 "DeleteKey failed");
1555
1556 return true;
1557 }
1558
1559 static bool test_DeleteKey(struct dcerpc_binding_handle *b,
1560 struct torture_context *tctx,
1561 struct policy_handle *handle, const char *key)
1562 {
1563 return test_DeleteKey_opts(b, tctx, handle, key, WERR_OK);
1564 }
1565
1566 static bool test_QueryInfoKey(struct dcerpc_binding_handle *b,
1567 struct torture_context *tctx,
1568 struct policy_handle *handle,
1569 char *kclass,
1570 uint32_t *pmax_valnamelen,
1571 uint32_t *pmax_valbufsize)
1572 {
1573 struct winreg_QueryInfoKey r;
1574 uint32_t num_subkeys, max_subkeylen, max_classlen,
1575 num_values, max_valnamelen, max_valbufsize,
1576 secdescsize;
1577 NTTIME last_changed_time;
1578
1579 ZERO_STRUCT(r);
1580 r.in.handle = handle;
1581 r.out.num_subkeys = &num_subkeys;
1582 r.out.max_subkeylen = &max_subkeylen;
1583 r.out.max_classlen = &max_classlen;
1584 r.out.num_values = &num_values;
1585 r.out.max_valnamelen = &max_valnamelen;
1586 r.out.max_valbufsize = &max_valbufsize;
1587 r.out.secdescsize = &secdescsize;
1588 r.out.last_changed_time = &last_changed_time;
1589
1590 r.out.classname = talloc(tctx, struct winreg_String);
1591
1592 r.in.classname = talloc(tctx, struct winreg_String);
1593 init_winreg_String(r.in.classname, kclass);
1594
1595 torture_assert_ntstatus_ok(tctx,
1596 dcerpc_winreg_QueryInfoKey_r(b, tctx, &r),
1597 "QueryInfoKey failed");
1598
1599 torture_assert_werr_ok(tctx, r.out.result, "QueryInfoKey failed");
1600
1601 if (pmax_valnamelen) {
1602 *pmax_valnamelen = max_valnamelen;
1603 }
1604
1605 if (pmax_valbufsize) {
1606 *pmax_valbufsize = max_valbufsize;
1607 }
1608
1609 return true;
1610 }
1611
1612 static bool test_SetValue(struct dcerpc_binding_handle *b,
1613 struct torture_context *tctx,
1614 struct policy_handle *handle,
1615 const char *value_name,
1616 enum winreg_Type type,
1617 uint8_t *data,
1618 uint32_t size)
1619 {
1620 struct winreg_SetValue r;
1621 struct winreg_String name;
1622
1623 torture_comment(tctx, "Testing SetValue(%s), type: %s, offered: 0x%08x)\n",
1624 value_name, str_regtype(type), size);
1625
1626 init_winreg_String(&name, value_name);
1627
1628 r.in.handle = handle;
1629 r.in.name = name;
1630 r.in.type = type;
1631 r.in.data = data;
1632 r.in.size = size;
1633
1634 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_SetValue_r(b, tctx, &r),
1635 "winreg_SetValue failed");
1636 torture_assert_werr_ok(tctx, r.out.result,
1637 "winreg_SetValue failed");
1638
1639 return true;
1640 }
1641
1642 static bool test_DeleteValue(struct dcerpc_binding_handle *b,
1643 struct torture_context *tctx,
1644 struct policy_handle *handle,
1645 const char *value_name)
1646 {
1647 struct winreg_DeleteValue r;
1648 struct winreg_String value;
1649
1650 torture_comment(tctx, "Testing DeleteValue(%s)\n", value_name);
1651
1652 init_winreg_String(&value, value_name);
1653
1654 r.in.handle = handle;
1655 r.in.value = value;
1656
1657 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_DeleteValue_r(b, tctx, &r),
1658 "winreg_DeleteValue failed");
1659 torture_assert_werr_ok(tctx, r.out.result,
1660 "winreg_DeleteValue failed");
1661
1662 return true;
1663 }
1664
1665 static bool test_key(struct dcerpc_pipe *p, struct torture_context *tctx,
1666 struct policy_handle *handle, int depth,
1667 bool test_security);
1668
1669 static bool test_EnumKey(struct dcerpc_pipe *p, struct torture_context *tctx,
1670 struct policy_handle *handle, int depth,
1671 bool test_security)
1672 {
1673 struct winreg_EnumKey r;
1674 struct winreg_StringBuf kclass, name;
1675 NTSTATUS status;
1676 NTTIME t = 0;
1677 struct dcerpc_binding_handle *b = p->binding_handle;
1678
1679 kclass.name = "";
1680 kclass.size = 1024;
1681
1682 ZERO_STRUCT(r);
1683 r.in.handle = handle;
1684 r.in.enum_index = 0;
1685 r.in.name = &name;
1686 r.in.keyclass = &kclass;
1687 r.out.name = &name;
1688 r.in.last_changed_time = &t;
1689
1690 do {
1691 name.name = NULL;
1692 name.size = 1024;
1693
1694 status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
1695
1696 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
1697 struct policy_handle key_handle;
1698
1699 torture_comment(tctx, "EnumKey: %d: %s\n",
1700 r.in.enum_index,
1701 r.out.name->name);
1702
1703 if (!test_OpenKey(b, tctx, handle, r.out.name->name,
1704 &key_handle)) {
1705 } else {
1706 test_key(p, tctx, &key_handle,
1707 depth + 1, test_security);
1708 }
1709 }
1710
1711 r.in.enum_index++;
1712
1713 } while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result));
1714
1715 torture_assert_ntstatus_ok(tctx, status, "EnumKey failed");
1716
1717 if (!W_ERROR_IS_OK(r.out.result) &&
1718 !W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
1719 torture_fail(tctx, "EnumKey failed");
1720 }
1721
1722 return true;
1723 }
1724
1725 static bool test_QueryMultipleValues(struct dcerpc_binding_handle *b,
1726 struct torture_context *tctx,
1727 struct policy_handle *handle,
1728 const char *valuename)
1729 {
1730 struct winreg_QueryMultipleValues r;
1731 uint32_t bufsize=0;
1732
1733 ZERO_STRUCT(r);
1734
1735 r.in.key_handle = handle;
1736 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 1);
1737 r.in.values_in[0].ve_valuename = talloc(tctx, struct winreg_ValNameBuf);
1738 r.in.values_in[0].ve_valuename->name = valuename;
1739 /* size needs to be set manually for winreg_ValNameBuf */
1740 r.in.values_in[0].ve_valuename->size = strlen_m_term(valuename)*2;
1741
1742 r.in.num_values = 1;
1743 r.in.buffer_size = r.out.buffer_size = talloc(tctx, uint32_t);
1744 *r.in.buffer_size = bufsize;
1745 do {
1746 *r.in.buffer_size = bufsize;
1747 r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t,
1748 *r.in.buffer_size);
1749
1750 torture_assert_ntstatus_ok(tctx,
1751 dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1752 "QueryMultipleValues failed");
1753
1754 talloc_free(r.in.buffer);
1755 bufsize += 0x20;
1756 } while (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA));
1757
1758 torture_assert_werr_ok(tctx, r.out.result, "QueryMultipleValues failed");
1759
1760 return true;
1761 }
1762
1763 static bool test_QueryMultipleValues_full(struct dcerpc_binding_handle *b,
1764 struct torture_context *tctx,
1765 struct policy_handle *handle,
1766 uint32_t num_values,
1767 const char * const *valuenames,
1768 bool existing_value)
1769 {
1770 struct winreg_QueryMultipleValues r;
1771 uint32_t bufsize = 0;
1772 int i;
1773
1774 torture_comment(tctx, "Testing QueryMultipleValues\n");
1775
1776 ZERO_STRUCT(r);
1777
1778 r.in.key_handle = handle;
1779 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 0);
1780 r.in.buffer_size = r.out.buffer_size = &bufsize;
1781
1782 torture_assert_ntstatus_ok(tctx,
1783 dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1784 "QueryMultipleValues failed");
1785 torture_assert_werr_ok(tctx, r.out.result,
1786 "QueryMultipleValues failed");
1787
1788 /* this test crashes w2k8 remote registry */
1789 #if 0
1790 r.in.num_values = num_values;
1791 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1792
1793 torture_assert_ntstatus_ok(tctx,
1794 dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1795 "QueryMultipleValues failed");
1796 torture_assert_werr_ok(tctx, r.out.result,
1797 "QueryMultipleValues failed");
1798 #endif
1799 r.in.num_values = num_values;
1800 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1801 for (i=0; i < r.in.num_values; i++) {
1802 r.in.values_in[i].ve_valuename = talloc_zero(tctx, struct winreg_ValNameBuf);
1803 r.in.values_in[i].ve_valuename->name = talloc_strdup(tctx, valuenames[i]);
1804 r.in.values_in[i].ve_valuename->size = strlen_m_term(r.in.values_in[i].ve_valuename->name)*2;
1805 }
1806
1807 torture_assert_ntstatus_ok(tctx,
1808 dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1809 "QueryMultipleValues failed");
1810 torture_assert_werr_equal(tctx, r.out.result, existing_value ? WERR_MORE_DATA : WERR_FILE_NOT_FOUND,
1811 "QueryMultipleValues failed");
1812
1813 if (W_ERROR_EQUAL(r.out.result, WERR_FILE_NOT_FOUND)) {
1814 return true;
1815 }
1816
1817 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1818 *r.in.buffer_size = 0xff;
1819 r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.buffer_size);
1820
1821 torture_assert_ntstatus_ok(tctx,
1822 dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1823 "QueryMultipleValues failed");
1824 }
1825
1826 torture_assert_werr_ok(tctx, r.out.result,
1827 "QueryMultipleValues failed");
1828
1829 return true;
1830 }
1831
1832
1833 static bool test_QueryMultipleValues2_full(struct dcerpc_binding_handle *b,
1834 struct torture_context *tctx,
1835 struct policy_handle *handle,
1836 uint32_t num_values,
1837 const char * const *valuenames,
1838 bool existing_value)
1839 {
1840 struct winreg_QueryMultipleValues2 r;
1841 uint32_t offered = 0, needed;
1842 int i;
1843
1844 torture_comment(tctx, "Testing QueryMultipleValues2\n");
1845
1846 ZERO_STRUCT(r);
1847
1848 r.in.key_handle = handle;
1849 r.in.offered = &offered;
1850 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 0);
1851 r.out.needed = &needed;
1852
1853 torture_assert_ntstatus_ok(tctx,
1854 dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1855 "QueryMultipleValues2 failed");
1856 torture_assert_werr_ok(tctx, r.out.result,
1857 "QueryMultipleValues2 failed");
1858
1859 /* this test crashes w2k8 remote registry */
1860 #if 0
1861 r.in.num_values = num_values;
1862 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1863
1864 torture_assert_ntstatus_ok(tctx,
1865 dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1866 "QueryMultipleValues2 failed");
1867 torture_assert_werr_ok(tctx, r.out.result,
1868 "QueryMultipleValues2 failed");
1869 #endif
1870 r.in.num_values = num_values;
1871 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1872 for (i=0; i < r.in.num_values; i++) {
1873 r.in.values_in[i].ve_valuename = talloc_zero(tctx, struct winreg_ValNameBuf);
1874 r.in.values_in[i].ve_valuename->name = talloc_strdup(tctx, valuenames[i]);
1875 r.in.values_in[i].ve_valuename->size = strlen_m_term(r.in.values_in[i].ve_valuename->name)*2;
1876 }
1877
1878 torture_assert_ntstatus_ok(tctx,
1879 dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1880 "QueryMultipleValues2 failed");
1881 torture_assert_werr_equal(tctx, r.out.result, existing_value ? WERR_MORE_DATA : WERR_FILE_NOT_FOUND,
1882 "QueryMultipleValues2 failed");
1883
1884 if (W_ERROR_EQUAL(r.out.result, WERR_FILE_NOT_FOUND)) {
1885 return true;
1886 }
1887
1888 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1889 *r.in.offered = *r.out.needed;
1890 r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.offered);
1891
1892 torture_assert_ntstatus_ok(tctx,
1893 dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1894 "QueryMultipleValues2 failed");
1895 }
1896
1897 torture_assert_werr_ok(tctx, r.out.result,
1898 "QueryMultipleValues2 failed");
1899
1900 return true;
1901 }
1902
1903 static bool test_QueryMultipleValues2(struct dcerpc_binding_handle *b,
1904 struct torture_context *tctx,
1905 struct policy_handle *handle,
1906 const char *valuename)
1907 {
1908 struct winreg_QueryMultipleValues2 r;
1909 uint32_t offered = 0, needed;
1910
1911 ZERO_STRUCT(r);
1912
1913 r.in.key_handle = handle;
1914 r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 1);
1915 r.in.values_in[0].ve_valuename = talloc(tctx, struct winreg_ValNameBuf);
1916 r.in.values_in[0].ve_valuename->name = valuename;
1917 /* size needs to be set manually for winreg_ValNameBuf */
1918 r.in.values_in[0].ve_valuename->size = strlen_m_term(valuename)*2;
1919
1920 r.in.num_values = 1;
1921 r.in.offered = &offered;
1922 r.out.needed = &needed;
1923
1924 torture_assert_ntstatus_ok(tctx,
1925 dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1926 "QueryMultipleValues2 failed");
1927 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1928 *r.in.offered = *r.out.needed;
1929 r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.offered);
1930
1931 torture_assert_ntstatus_ok(tctx,
1932 dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1933 "QueryMultipleValues2 failed");
1934 }
1935
1936 torture_assert_werr_ok(tctx, r.out.result,
1937 "QueryMultipleValues2 failed");
1938
1939 return true;
1940 }
1941
1942 static bool test_QueryValue(struct dcerpc_binding_handle *b,
1943 struct torture_context *tctx,
1944 struct policy_handle *handle,
1945 const char *valuename)
1946 {
1947 struct winreg_QueryValue r;
1948 NTSTATUS status;
1949 enum winreg_Type zero_type = 0;
1950 uint32_t offered = 0xfff;
1951 uint32_t zero = 0;
1952
1953 ZERO_STRUCT(r);
1954 r.in.handle = handle;
1955 r.in.data = NULL;
1956 r.in.value_name = talloc_zero(tctx, struct winreg_String);
1957 r.in.value_name->name = valuename;
1958 r.in.type = &zero_type;
1959 r.in.data_size = &offered;
1960 r.in.data_length = &zero;
1961
1962 status = dcerpc_winreg_QueryValue_r(b, tctx, &r);
1963 if (NT_STATUS_IS_ERR(status)) {
1964 torture_fail(tctx, "QueryValue failed");
1965 }
1966
1967 torture_assert_werr_ok(tctx, r.out.result, "QueryValue failed");
1968
1969 return true;
1970 }
1971
1972 static bool test_QueryValue_full(struct dcerpc_binding_handle *b,
1973 struct torture_context *tctx,
1974 struct policy_handle *handle,
1975 const char *valuename,
1976 bool existing_value)
1977 {
1978 struct winreg_QueryValue r;
1979 struct winreg_String value_name;
1980 enum winreg_Type type = REG_NONE;
1981 uint32_t data_size = 0;
1982 uint32_t real_data_size = 0;
1983 uint32_t data_length = 0;
1984 uint8_t *data = NULL;
1985 WERROR expected_error = WERR_FILE_NOT_FOUND;
1986 const char *errmsg_nonexisting = "expected WERR_FILE_NOT_FOUND for nonexisting value";
1987
1988 if (valuename == NULL) {
1989 expected_error = WERR_INVALID_PARAMETER;
1990 errmsg_nonexisting = "expected WERR_INVALID_PARAMETER for NULL valuename";
1991 }
1992
1993 ZERO_STRUCT(r);
1994
1995 init_winreg_String(&value_name, NULL);
1996
1997 torture_comment(tctx, "Testing QueryValue(%s)\n", valuename);
1998
1999 r.in.handle = handle;
2000 r.in.value_name = &value_name;
2001
2002 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
2003 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER,
2004 "expected WERR_INVALID_PARAMETER for NULL winreg_String.name");
2005
2006 init_winreg_String(&value_name, valuename);
2007 r.in.value_name = &value_name;
2008
2009 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
2010 "QueryValue failed");
2011 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER,
2012 "expected WERR_INVALID_PARAMETER for missing type length and size");
2013
2014 r.in.type = &type;
2015 r.out.type = &type;
2016 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
2017 "QueryValue failed");
2018 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER,
2019 "expected WERR_INVALID_PARAMETER for missing length and size");
2020
2021 r.in.data_length = &data_length;
2022 r.out.data_length = &data_length;
2023 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
2024 "QueryValue failed");
2025 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER,
2026 "expected WERR_INVALID_PARAMETER for missing size");
2027
2028 r.in.data_size = &data_size;
2029 r.out.data_size = &data_size;
2030 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
2031 "QueryValue failed");
2032 if (existing_value) {
2033 torture_assert_werr_ok(tctx, r.out.result,
2034 "QueryValue failed");
2035 } else {
2036 torture_assert_werr_equal(tctx, r.out.result, expected_error,
2037 errmsg_nonexisting);
2038 }
2039
2040 real_data_size = *r.out.data_size;
2041
2042 data = talloc_zero_array(tctx, uint8_t, 0);
2043 r.in.data = data;
2044 r.out.data = data;
2045 *r.in.data_size = 0;
2046 *r.out.data_size = 0;
2047 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
2048 "QueryValue failed");
2049 if (existing_value) {
2050 torture_assert_werr_equal(tctx, r.out.result, WERR_MORE_DATA,
2051 "expected WERR_MORE_DATA for query with too small buffer");
2052 } else {
2053 torture_assert_werr_equal(tctx, r.out.result, expected_error,
2054 errmsg_nonexisting);
2055 }
2056
2057 data = talloc_zero_array(tctx, uint8_t, real_data_size);
2058 r.in.data = data;
2059 r.out.data = data;
2060 r.in.data_size = &real_data_size;
2061 r.out.data_size = &real_data_size;
2062 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
2063 "QueryValue failed");
2064 if (existing_value) {
2065 torture_assert_werr_ok(tctx, r.out.result,
2066 "QueryValue failed");
2067 } else {
2068 torture_assert_werr_equal(tctx, r.out.result, expected_error,
2069 errmsg_nonexisting);
2070 }
2071
2072 return true;
2073 }
2074
2075 static bool test_EnumValue_one(struct dcerpc_binding_handle *b,
2076 struct torture_context *tctx,
2077 struct policy_handle *handle,
2078 int max_valnamelen)
2079 {
2080 struct winreg_EnumValue r;
2081 bool ret = true;
2082 DATA_BLOB blob;
2083
2084 blob = data_blob_string_const("data_1");
2085 torture_assert_goto(tctx,
2086 test_SetValue(b, tctx, handle, "v1", REG_BINARY, blob.data, blob.length),
2087 ret, done,
2088 "test_SetValue failed");
2089
2090 blob = data_blob_string_const("data_2");
2091 torture_assert_goto(tctx,
2092 test_SetValue(b, tctx, handle, "v2", REG_BINARY, blob.data, blob.length),
2093 ret, done,
2094 "test_SetValue failed");
2095
2096 ZERO_STRUCT(r);
2097
2098 r.in.handle = handle;
2099 r.in.enum_index = 0;
2100
2101 do {
2102 enum winreg_Type type = REG_NONE;
2103 uint32_t size = 0, zero = 0;
2104 struct winreg_ValNameBuf name;
2105 char n = '\0';
2106
2107 r.in.name = &name;
2108 r.in.type = &type;
2109 r.in.length = &zero;
2110 r.in.size = &size;
2111 r.out.name = &name;
2112 r.out.size = &size;
2113
2114 name.name = &n;
2115 name.size = max_valnamelen + 2;
2116 name.length = 0;
2117
2118 r.in.value = talloc_array(tctx, uint8_t, 0);
2119 torture_assert(tctx, r.in.value, "nomem");
2120
2121 torture_assert_ntstatus_ok_goto(tctx,
2122 dcerpc_winreg_EnumValue_r(b, tctx, &r),
2123 ret, done,
2124 "EnumValue failed");
2125 if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
2126 break;
2127 }
2128 torture_assert_werr_equal_goto(tctx,
2129 r.out.result, WERR_MORE_DATA,
2130 ret, done,
2131 "unexpected return code");
2132
2133 *r.in.size = *r.out.size;
2134 r.in.value = talloc_zero_array(tctx, uint8_t, *r.in.size);
2135 torture_assert(tctx, r.in.value, "nomem");
2136
2137 torture_assert_ntstatus_ok_goto(tctx,
2138 dcerpc_winreg_EnumValue_r(b, tctx, &r),
2139 ret, done,
2140 "EnumValue failed");
2141 torture_assert_werr_ok_goto(tctx, r.out.result,
2142 ret, done,
2143 "unexpected return code");
2144
2145 r.in.enum_index++;
2146
2147 } while (W_ERROR_IS_OK(r.out.result));
2148
2149 torture_assert_werr_equal_goto(tctx, r.out.result, WERR_NO_MORE_ITEMS,
2150 ret, done,
2151 "EnumValue failed");
2152 done:
2153 test_DeleteValue(b, tctx, handle, "v1");
2154 test_DeleteValue(b, tctx, handle, "v2");
2155
2156 return ret;
2157 }
2158
2159 static bool test_EnumValue(struct dcerpc_binding_handle *b,
2160 struct torture_context *tctx,
2161 struct policy_handle *handle, int max_valnamelen,
2162 int max_valbufsize)
2163 {
2164 struct winreg_EnumValue r;
2165 enum winreg_Type type = 0;
2166 uint32_t size = max_valbufsize, zero = 0;
2167 bool ret = true;
2168 uint8_t *data = NULL;
2169 struct winreg_ValNameBuf name;
2170 char n = '\0';
2171
2172 ZERO_STRUCT(r);
2173 r.in.handle = handle;
2174 r.in.enum_index = 0;
2175 r.in.name = &name;
2176 r.out.name = &name;
2177 r.in.type = &type;
2178 r.in.length = &zero;
2179 r.in.size = &size;
2180
2181 do {
2182 name.name = &n;
2183 name.size = max_valnamelen + 2;
2184 name.length = 0;
2185
2186 data = NULL;
2187 if (size) {
2188 data = talloc_array(tctx, uint8_t, size);
2189 }
2190 r.in.value = data;
2191
2192 torture_assert_ntstatus_ok(tctx,
2193 dcerpc_winreg_EnumValue_r(b, tctx, &r),
2194 "EnumValue failed");
2195
2196 if (W_ERROR_IS_OK(r.out.result)) {
2197 ret &= test_QueryValue(b, tctx, handle,
2198 r.out.name->name);
2199 ret &= test_QueryMultipleValues(b, tctx, handle,
2200 r.out.name->name);
2201 ret &= test_QueryMultipleValues2(b, tctx, handle,
2202 r.out.name->name);
2203 }
2204
2205 talloc_free(data);
2206
2207 r.in.enum_index++;
2208 } while (W_ERROR_IS_OK(r.out.result));
2209
2210 torture_assert_werr_equal(tctx, r.out.result, WERR_NO_MORE_ITEMS,
2211 "EnumValue failed");
2212
2213 return ret;
2214 }
2215
2216 static bool test_AbortSystemShutdown(struct dcerpc_binding_handle *b,
2217 struct torture_context *tctx)
2218 {
2219 struct winreg_AbortSystemShutdown r;
2220 uint16_t server = 0x0;
2221
2222 ZERO_STRUCT(r);
2223 r.in.server = &server;
2224
2225 torture_assert_ntstatus_ok(tctx,
2226 dcerpc_winreg_AbortSystemShutdown_r(b, tctx, &r),
2227 "AbortSystemShutdown failed");
2228
2229 torture_assert_werr_ok(tctx, r.out.result,
2230 "AbortSystemShutdown failed");
2231
2232 return true;
2233 }
2234
2235 static bool test_InitiateSystemShutdown(struct torture_context *tctx,
2236 struct dcerpc_pipe *p)
2237 {
2238 struct winreg_InitiateSystemShutdown r;
2239 uint16_t hostname = 0x0;
2240 struct dcerpc_binding_handle *b = p->binding_handle;
2241
2242 ZERO_STRUCT(r);
2243 r.in.hostname = &hostname;
2244 r.in.message = talloc(tctx, struct lsa_StringLarge);
2245 init_lsa_StringLarge(r.in.message, "spottyfood");
2246 r.in.force_apps = 1;
2247 r.in.timeout = 30;
2248 r.in.do_reboot = 1;
2249
2250 torture_assert_ntstatus_ok(tctx,
2251 dcerpc_winreg_InitiateSystemShutdown_r(b, tctx, &r),
2252 "InitiateSystemShutdown failed");
2253
2254 torture_assert_werr_ok(tctx, r.out.result,
2255 "InitiateSystemShutdown failed");
2256
2257 return test_AbortSystemShutdown(b, tctx);
2258 }
2259
2260
2261 static bool test_InitiateSystemShutdownEx(struct torture_context *tctx,
2262 struct dcerpc_pipe *p)
2263 {
2264 struct winreg_InitiateSystemShutdownEx r;
2265 uint16_t hostname = 0x0;
2266 struct dcerpc_binding_handle *b = p->binding_handle;
2267
2268 ZERO_STRUCT(r);
2269 r.in.hostname = &hostname;
2270 r.in.message = talloc(tctx, struct lsa_StringLarge);
2271 init_lsa_StringLarge(r.in.message, "spottyfood");
2272 r.in.force_apps = 1;
2273 r.in.timeout = 30;
2274 r.in.do_reboot = 1;
2275 r.in.reason = 0;
2276
2277 torture_assert_ntstatus_ok(tctx,
2278 dcerpc_winreg_InitiateSystemShutdownEx_r(b, tctx, &r),
2279 "InitiateSystemShutdownEx failed");
2280
2281 torture_assert_werr_ok(tctx, r.out.result,
2282 "InitiateSystemShutdownEx failed");
2283
2284 return test_AbortSystemShutdown(b, tctx);
2285 }
2286 #define MAX_DEPTH 2 /* Only go this far down the tree */
2287
2288 static bool test_key(struct dcerpc_pipe *p, struct torture_context *tctx,
2289 struct policy_handle *handle, int depth,
2290 bool test_security)
2291 {
2292 struct dcerpc_binding_handle *b = p->binding_handle;
2293 uint32_t max_valnamelen = 0;
2294 uint32_t max_valbufsize = 0;
2295
2296 if (depth == MAX_DEPTH)
2297 return true;
2298
2299 if (!test_QueryInfoKey(b, tctx, handle, NULL,
2300 &max_valnamelen, &max_valbufsize)) {
2301 }
2302
2303 if (!test_NotifyChangeKeyValue(b, tctx, handle)) {
2304 }
2305
2306 if (test_security && !test_GetKeySecurity(p, tctx, handle, NULL)) {
2307 }
2308
2309 if (!test_EnumKey(p, tctx, handle, depth, test_security)) {
2310 }
2311
2312 if (!test_EnumValue(b, tctx, handle, max_valnamelen, max_valbufsize)) {
2313 }
2314
2315 if (!test_EnumValue(b, tctx, handle, max_valnamelen, 0xFFFF)) {
2316 }
2317
2318 if (!test_EnumValue_one(b, tctx, handle, 0xff)) {
2319 return false;
2320 }
2321
2322 test_CloseKey(b, tctx, handle);
2323
2324 return true;
2325 }
2326
2327 static bool test_SetValue_simple(struct dcerpc_binding_handle *b,
2328 struct torture_context *tctx,
2329 struct policy_handle *handle)
2330 {
2331 const char *value_name = TEST_VALUE;
2332 uint32_t value = 0x12345678;
2333 uint64_t value2 = 0x12345678;
2334 const char *string = "torture";
2335 const char *array[2];
2336 DATA_BLOB blob;
2337 enum winreg_Type types[] = {
2338 REG_DWORD,
2339 REG_DWORD_BIG_ENDIAN,
2340 REG_QWORD,
2341 REG_BINARY,
2342 REG_SZ,
2343 REG_MULTI_SZ
2344 };
2345 int t;
2346
2347 array[0] = "array0";
2348 array[1] = NULL;
2349
2350 torture_comment(tctx, "Testing SetValue (standard formats)\n");
2351
2352 for (t=0; t < ARRAY_SIZE(types); t++) {
2353
2354 enum winreg_Type w_type;
2355 uint32_t w_size, w_length;
2356 uint8_t *w_data;
2357
2358 switch (types[t]) {
2359 case REG_DWORD:
2360 case REG_DWORD_BIG_ENDIAN:
2361 blob = data_blob_talloc_zero(tctx, 4);
2362 SIVAL(blob.data, 0, value);
2363 break;
2364 case REG_QWORD:
2365 blob = data_blob_talloc_zero(tctx, 8);
2366 SBVAL(blob.data, 0, value2);
2367 break;
2368 case REG_BINARY:
2369 blob = data_blob_string_const("binary_blob");
2370 break;
2371 case REG_SZ:
2372 torture_assert(tctx, push_reg_sz(tctx, &blob, string), "failed to push REG_SZ");
2373 break;
2374 case REG_MULTI_SZ:
2375 torture_assert(tctx, push_reg_multi_sz(tctx, &blob, array), "failed to push REG_MULTI_SZ");
2376 break;
2377 default:
2378 break;
2379 }
2380
2381 torture_assert(tctx,
2382 test_SetValue(b, tctx, handle, value_name, types[t], blob.data, blob.length),
2383 "test_SetValue failed");
2384 torture_assert(tctx,
2385 test_QueryValue_full(b, tctx, handle, value_name, true),
2386 talloc_asprintf(tctx, "test_QueryValue_full for %s value failed", value_name));
2387 torture_assert(tctx,
2388 test_winreg_QueryValue(tctx, b, handle, value_name, &w_type, &w_size, &w_length, &w_data),
2389 "test_winreg_QueryValue failed");
2390 torture_assert(tctx,
2391 test_DeleteValue(b, tctx, handle, value_name),
2392 "test_DeleteValue failed");
2393
2394 torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
2395 torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
2396 torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
2397 torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
2398 }
2399
2400 torture_comment(tctx, "Testing SetValue (standard formats) succeeded\n");
2401
2402 return true;
2403 }
2404
2405 static bool test_SetValue_values(struct dcerpc_binding_handle *b,
2406 struct torture_context *tctx,
2407 struct policy_handle *handle)
2408 {
2409 DATA_BLOB blob;
2410 const char *values[] = {
2411 "torture_value",
2412 "torture value",
2413 "torture,value",
2414 "torture;value",
2415 "torture/value",
2416 "torture\\value",
2417 "torture_value_name",
2418 "torture value name",
2419 "torture,value,name",
2420 "torture;value;name",
2421 "torture/value/name",
2422 "torture\\value\\name",
2423 };
2424 int i;
2425
2426 torture_comment(tctx, "Testing SetValue (values)\n");
2427
2428 for (i=0; i < ARRAY_SIZE(values); i++) {
2429
2430 enum winreg_Type w_type;
2431 uint32_t w_size, w_length;
2432 uint8_t *w_data;
2433
2434 blob = data_blob_talloc(tctx, NULL, 32);
2435
2436 generate_random_buffer(blob.data, 32);
2437
2438 torture_assert(tctx,
2439 test_SetValue(b, tctx, handle, values[i], REG_BINARY, blob.data, blob.length),
2440 "test_SetValue failed");
2441 torture_assert(tctx,
2442 test_QueryValue_full(b, tctx, handle, values[i], true),
2443 talloc_asprintf(tctx, "test_QueryValue_full for %s value failed", values[i]));
2444 torture_assert(tctx,
2445 test_winreg_QueryValue(tctx, b, handle, values[i], &w_type, &w_size, &w_length, &w_data),
2446 "test_winreg_QueryValue failed");
2447 torture_assert(tctx,
2448 test_DeleteValue(b, tctx, handle, values[i]),
2449 "test_DeleteValue failed");
2450
2451 torture_assert_int_equal(tctx, w_type, REG_BINARY, "winreg type mismatch");
2452 torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
2453 torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
2454 torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
2455 }
2456
2457 torture_comment(tctx, "Testing SetValue (values) succeeded\n");
2458
2459 return true;
2460 }
2461
2462 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
2463
2464 static bool test_SetValue_extended(struct dcerpc_binding_handle *b,
2465 struct torture_context *tctx,
2466 struct policy_handle *handle)
2467 {
2468 const char *value_name = TEST_VALUE;
2469 enum winreg_Type types[] = {
2470 REG_NONE,
2471 REG_SZ,
2472 REG_EXPAND_SZ,
2473 REG_BINARY,
2474 REG_DWORD,
2475 REG_DWORD_BIG_ENDIAN,
2476 REG_LINK,
2477 REG_MULTI_SZ,
2478 REG_RESOURCE_LIST,
2479 REG_FULL_RESOURCE_DESCRIPTOR,
2480 REG_RESOURCE_REQUIREMENTS_LIST,
2481 REG_QWORD,
2482 12,
2483 13,
2484 14,
2485 55,
2486 123456,
2487 653210,
2488 __LINE__
2489 };
2490 int t, l;
2491
2492 if (torture_setting_bool(tctx, "samba4", false)) {
2493 torture_skip(tctx, "skipping extended SetValue test against Samba4");
2494 }
2495
2496 torture_comment(tctx, "Testing SetValue (extended formats)\n");
2497
2498 for (t=0; t < ARRAY_SIZE(types); t++) {
2499 for (l=0; l < 16; l++) {
2500
2501 enum winreg_Type w_type;
2502 uint32_t w_size, w_length;
2503 uint8_t *w_data;
2504
2505 uint32_t size;
2506 uint8_t *data;
2507
2508 size = l;
2509 data = talloc_array(tctx, uint8_t, size);
2510
2511 generate_random_buffer(data, size);
2512
2513 torture_assert(tctx,
2514 test_SetValue(b, tctx, handle, value_name, types[t], data, size),
2515 "test_SetValue failed");
2516
2517 torture_assert(tctx,
2518 test_winreg_QueryValue(tctx, b, handle, value_name, &w_type, &w_size, &w_length, &w_data),
2519 "test_winreg_QueryValue failed");
2520
2521 torture_assert(tctx,
2522 test_DeleteValue(b, tctx, handle, value_name),
2523 "test_DeleteValue failed");
2524
2525 torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
2526 torture_assert_int_equal(tctx, w_size, size, "winreg size mismatch");
2527 torture_assert_int_equal(tctx, w_length, size, "winreg length mismatch");
2528 torture_assert_mem_equal(tctx, w_data, data, size, "winreg buffer mismatch");
2529 }
2530 }
2531
2532 torture_comment(tctx, "Testing SetValue (extended formats) succeeded\n");
2533
2534 return true;
2535 }
2536
2537 static bool test_create_keynames(struct dcerpc_binding_handle *b,
2538 struct torture_context *tctx,
2539 struct policy_handle *handle)
2540 {
2541 const char *keys[] = {
2542 "torture_key",
2543 "torture key",
2544 "torture,key",
2545 "torture/key",
2546 "torture\\key",
2547 };
2548 int i;
2549
2550 for (i=0; i < ARRAY_SIZE(keys); i++) {
2551
2552 enum winreg_CreateAction action_taken;
2553 struct policy_handle new_handle;
2554 char *q, *tmp;
2555
2556 torture_assert(tctx,
2557 test_CreateKey_opts(tctx, b, handle, keys[i], NULL,
2558 REG_OPTION_NON_VOLATILE,
2559 SEC_FLAG_MAXIMUM_ALLOWED,
2560 NULL,
2561 WERR_OK,
2562 &action_taken,
2563 &new_handle),
2564 talloc_asprintf(tctx, "failed to create '%s' key", keys[i]));
2565
2566 torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2567
2568 torture_assert(tctx,
2569 test_DeleteKey_opts(b, tctx, handle, keys[i], WERR_OK),
2570 "failed to delete key");
2571
2572 torture_assert(tctx,
2573 test_DeleteKey_opts(b, tctx, handle, keys[i], WERR_FILE_NOT_FOUND),
2574 "failed 2nd delete key");
2575
2576 tmp = talloc_strdup(tctx, keys[i]);
2577
2578 q = strchr(tmp, '\\');
2579 if (q != NULL) {
2580 *q = '\0';
2581 q++;
2582
2583 torture_assert(tctx,
2584 test_DeleteKey_opts(b, tctx, handle, tmp, WERR_OK),
2585 "failed to delete key");
2586
2587 torture_assert(tctx,
2588 test_DeleteKey_opts(b, tctx, handle, tmp, WERR_FILE_NOT_FOUND),
2589 "failed 2nd delete key");
2590 }
2591 }
2592
2593 return true;
2594 }
2595
2596 #define KEY_CURRENT_VERSION "SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION"
2597 #define VALUE_CURRENT_VERSION "CurrentVersion"
2598 #define VALUE_SYSTEM_ROOT "SystemRoot"
2599
2600 static const struct {
2601 const char *values[3];
2602 uint32_t num_values;
2603 bool existing_value;
2604 const char *error_message;
2605 } multiple_values_tests[] = {
2606 {
2607 .values = { VALUE_CURRENT_VERSION, NULL, NULL },
2608 .num_values = 1,
2609 .existing_value = true,
2610 .error_message = NULL
2611 },{
2612 .values = { VALUE_SYSTEM_ROOT, NULL, NULL },
2613 .num_values = 1,
2614 .existing_value = true,
2615 .error_message = NULL
2616 },{
2617 .values = { VALUE_CURRENT_VERSION, VALUE_SYSTEM_ROOT, NULL },
2618 .num_values = 2,
2619 .existing_value = true,
2620 .error_message = NULL
2621 },{
2622 .values = { VALUE_CURRENT_VERSION, VALUE_SYSTEM_ROOT,
2623 VALUE_CURRENT_VERSION },
2624 .num_values = 3,
2625 .existing_value = true,
2626 .error_message = NULL
2627 },{
2628 .values = { VALUE_CURRENT_VERSION, NULL, VALUE_SYSTEM_ROOT },
2629 .num_values = 3,
2630 .existing_value = false,
2631 .error_message = NULL
2632 },{
2633 .values = { VALUE_CURRENT_VERSION, "", VALUE_SYSTEM_ROOT },
2634 .num_values = 3,
2635 .existing_value = false,
2636 .error_message = NULL
2637 },{
2638 .values = { "IDoNotExist", NULL, NULL },
2639 .num_values = 1,
2640 .existing_value = false,
2641 .error_message = NULL
2642 },{
2643 .values = { "IDoNotExist", VALUE_CURRENT_VERSION, NULL },
2644 .num_values = 2,
2645 .existing_value = false,
2646 .error_message = NULL
2647 },{
2648 .values = { VALUE_CURRENT_VERSION, "IDoNotExist", NULL },
2649 .num_values = 2,
2650 .existing_value = false,
2651 .error_message = NULL
2652 }
2653 };
2654
2655 static bool test_HKLM_wellknown(struct torture_context *tctx,
2656 struct dcerpc_binding_handle *b,
2657 struct policy_handle *handle)
2658 {
2659 struct policy_handle newhandle;
2660 int i;
2661
2662 /* FIXME: s3 does not support SEC_FLAG_MAXIMUM_ALLOWED yet */
2663 if (torture_setting_bool(tctx, "samba3", false)) {
2664 torture_assert(tctx, test_OpenKey_opts(tctx, b, handle,
2665 KEY_CURRENT_VERSION,
2666 REG_OPTION_NON_VOLATILE,
2667 KEY_QUERY_VALUE,
2668 &newhandle,
2669 WERR_OK),
2670 "failed to open current version key");
2671 } else {
2672 torture_assert(tctx, test_OpenKey(b, tctx, handle, KEY_CURRENT_VERSION, &newhandle),
2673 "failed to open current version key");
2674 }
2675
2676 torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, VALUE_CURRENT_VERSION, true),
2677 "failed to query current version");
2678 torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, "IDoNotExist", false),
2679 "succeeded to query nonexistent value");
2680 torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, NULL, false),
2681 "succeeded to query value with NULL name");
2682 torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, "", false),
2683 "succeeded to query nonexistent default value (\"\")");
2684
2685 if (torture_setting_bool(tctx, "samba4", false)) {
2686 torture_comment(tctx, "skipping QueryMultipleValues{2} tests against Samba4\n");
2687 goto close_key;
2688 }
2689
2690 for (i=0; i < ARRAY_SIZE(multiple_values_tests); i++) {
2691 const char *msg;
2692 msg = talloc_asprintf(tctx,
2693 "failed to query %d %sexisting values\n",
2694 multiple_values_tests[i].num_values,
2695 multiple_values_tests[i].existing_value ? "":"non");
2696
2697 torture_assert(tctx,
2698 test_QueryMultipleValues_full(b, tctx, &newhandle,
2699 multiple_values_tests[i].num_values,
2700 multiple_values_tests[i].values,
2701 multiple_values_tests[i].existing_value),
2702 msg);
2703 torture_assert(tctx,
2704 test_QueryMultipleValues2_full(b, tctx, &newhandle,
2705 multiple_values_tests[i].num_values,
2706 multiple_values_tests[i].values,
2707 multiple_values_tests[i].existing_value),
2708 msg);
2709 }
2710
2711 close_key:
2712 torture_assert(tctx, test_CloseKey(b, tctx, &newhandle),
2713 "failed to close current version key");
2714
2715 return true;
2716 }
2717
2718 static bool test_OpenHive(struct torture_context *tctx,
2719 struct dcerpc_binding_handle *b,
2720 struct policy_handle *handle,
2721 int hkey)
2722 {
2723 struct winreg_OpenHKLM r;
2724
2725 r.in.system_name = 0;
2726 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2727 r.out.handle = handle;
2728
2729 switch (hkey) {
2730 case HKEY_LOCAL_MACHINE:
2731 torture_assert_ntstatus_ok(tctx,
2732 dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
2733 "failed to open HKLM");
2734 torture_assert_werr_ok(tctx, r.out.result,
2735 "failed to open HKLM");
2736 break;
2737 case HKEY_CURRENT_USER:
2738 torture_assert_ntstatus_ok(tctx,
2739 dcerpc_winreg_OpenHKCU_r(b, tctx, (struct winreg_OpenHKCU *)(void *)&r),
2740 "failed to open HKCU");
2741 torture_assert_werr_ok(tctx, r.out.result,
2742 "failed to open HKCU");
2743 break;
2744 case HKEY_USERS:
2745 torture_assert_ntstatus_ok(tctx,
2746 dcerpc_winreg_OpenHKU_r(b, tctx, (struct winreg_OpenHKU *)(void *)&r),
2747 "failed to open HKU");
2748 torture_assert_werr_ok(tctx, r.out.result,
2749 "failed to open HKU");
2750 break;
2751 case HKEY_CLASSES_ROOT:
2752 torture_assert_ntstatus_ok(tctx,
2753 dcerpc_winreg_OpenHKCR_r(b, tctx, (struct winreg_OpenHKCR *)(void *)&r),
2754 "failed to open HKCR");
2755 torture_assert_werr_ok(tctx, r.out.result,
2756 "failed to open HKCR");
2757 break;
2758 default:
2759 torture_warning(tctx, "unsupported hkey: 0x%08x\n", hkey);
2760 return false;
2761 }
2762
2763 return true;
2764 }
2765
2766 static bool test_volatile_keys(struct torture_context *tctx,
2767 struct dcerpc_binding_handle *b,
2768 struct policy_handle *handle,
2769 int hkey)
2770 {
2771 struct policy_handle new_handle, hive_handle;
2772 enum winreg_CreateAction action_taken = REG_ACTION_NONE;
2773
2774 ZERO_STRUCT(new_handle);
2775 ZERO_STRUCT(hive_handle);
2776
2777 torture_comment(tctx, "Testing VOLATILE key\n");
2778
2779 test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE);
2780
2781 torture_assert(tctx,
2782 test_CreateKey_opts(tctx, b, handle, TEST_KEY_VOLATILE, NULL,
2783 REG_OPTION_VOLATILE,
2784 SEC_FLAG_MAXIMUM_ALLOWED,
2785 NULL,
2786 WERR_OK,
2787 &action_taken,
2788 &new_handle),
2789 "failed to create REG_OPTION_VOLATILE type key");
2790
2791 torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2792
2793 torture_assert(tctx,
2794 test_CreateKey_opts(tctx, b, &new_handle, TEST_SUBKEY_VOLATILE, NULL,
2795 REG_OPTION_NON_VOLATILE,
2796 SEC_FLAG_MAXIMUM_ALLOWED,
2797 NULL,
2798 WERR_CHILD_MUST_BE_VOLATILE,
2799 NULL,
2800 NULL),
2801 "failed to fail create REG_OPTION_VOLATILE type key");
2802
2803 torture_assert(tctx,
2804 test_CloseKey(b, tctx, &new_handle),
2805 "failed to close");
2806
2807 torture_assert(tctx,
2808 test_OpenKey_opts(tctx, b, handle, TEST_KEY_VOLATILE,
2809 REG_OPTION_NON_VOLATILE,
2810 SEC_FLAG_MAXIMUM_ALLOWED,
2811 &new_handle,
2812 WERR_OK),
2813 "failed to open volatile key");
2814
2815 torture_assert(tctx,
2816 test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE),
2817 "failed to delete key");
2818
2819 torture_assert(tctx,
2820 test_CreateKey_opts(tctx, b, handle, TEST_KEY_VOLATILE, NULL,
2821 REG_OPTION_VOLATILE,
2822 SEC_FLAG_MAXIMUM_ALLOWED,
2823 NULL,
2824 WERR_OK,
2825 &action_taken,
2826 &new_handle),
2827 "failed to create REG_OPTION_VOLATILE type key");
2828
2829 torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2830
2831 torture_assert(tctx,
2832 test_CloseKey(b, tctx, &new_handle),
2833 "failed to close");
2834
2835 torture_assert(tctx,
2836 test_OpenKey_opts(tctx, b, handle, TEST_KEY_VOLATILE,
2837 REG_OPTION_VOLATILE,
2838 SEC_FLAG_MAXIMUM_ALLOWED,
2839 &new_handle,
2840 WERR_OK),
2841 "failed to open volatile key");
2842
2843 torture_assert(tctx,
2844 test_CloseKey(b, tctx, &new_handle),
2845 "failed to close");
2846
2847 torture_assert(tctx,
2848 test_OpenHive(tctx, b, &hive_handle, hkey),
2849 "failed top open hive");
2850
2851 torture_assert(tctx,
2852 test_OpenKey_opts(tctx, b, &hive_handle, TEST_KEY_VOLATILE,
2853 REG_OPTION_VOLATILE,
2854 SEC_FLAG_MAXIMUM_ALLOWED,
2855 &new_handle,
2856 WERR_FILE_NOT_FOUND),
2857 "failed to open volatile key");
2858
2859 torture_assert(tctx,
2860 test_OpenKey_opts(tctx, b, &hive_handle, TEST_KEY_VOLATILE,
2861 REG_OPTION_NON_VOLATILE,
2862 SEC_FLAG_MAXIMUM_ALLOWED,
2863 &new_handle,
2864 WERR_FILE_NOT_FOUND),
2865 "failed to open volatile key");
2866
2867 torture_assert(tctx,
2868 test_CloseKey(b, tctx, &hive_handle),
2869 "failed to close");
2870
2871 torture_assert(tctx,
2872 test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE),
2873 "failed to delete key");
2874
2875
2876 torture_comment(tctx, "Testing VOLATILE key succeeded\n");
2877
2878 return true;
2879 }
2880
2881 static const char *kernel_mode_registry_path(struct torture_context *tctx,
2882 int hkey,
2883 const char *sid_string,
2884 const char *path)
2885 {
2886 switch (hkey) {
2887 case HKEY_LOCAL_MACHINE:
2888 return talloc_asprintf(tctx, "\\Registry\\MACHINE\\%s", path);
2889 case HKEY_CURRENT_USER:
2890 return talloc_asprintf(tctx, "\\Registry\\USER\\%s\\%s", sid_string, path);
2891 case HKEY_USERS:
2892 return talloc_asprintf(tctx, "\\Registry\\USER\\%s", path);
2893 case HKEY_CLASSES_ROOT:
2894 return talloc_asprintf(tctx, "\\Registry\\MACHINE\\Software\\Classes\\%s", path);
2895 default:
2896 torture_warning(tctx, "unsupported hkey: 0x%08x\n", hkey);
2897 return NULL;
2898 }
2899 }
2900
2901 static bool test_symlink_keys(struct torture_context *tctx,
2902 struct dcerpc_binding_handle *b,
2903 struct policy_handle *handle,
2904 const char *key,
2905 int hkey)
2906 {
2907 struct policy_handle new_handle;
2908 enum winreg_CreateAction action_taken;
2909 DATA_BLOB blob;
2910 uint32_t value = 42;
2911 const char *test_key_symlink_dest;
2912 const char *test_key_symlink;
2913 const char *kernel_mode_path;
2914
2915 /* disable until we know how to delete a symbolic link */
2916 torture_skip(tctx, "symlink test disabled");
2917
2918 torture_comment(tctx, "Testing REG_OPTION_CREATE_LINK key\n");
2919
2920 /* create destination key with testvalue */
2921 test_key_symlink = talloc_asprintf(tctx, "%s\\%s",
2922 key, TEST_KEY_SYMLINK);
2923 test_key_symlink_dest = talloc_asprintf(tctx, "%s\\%s",
2924 key, TEST_KEY_SYMLINK_DEST);
2925
2926 test_DeleteKey(b, tctx, handle, test_key_symlink);
2927
2928 torture_assert(tctx,
2929 test_CreateKey_opts(tctx, b, handle, test_key_symlink_dest, NULL,
2930 0,
2931 SEC_FLAG_MAXIMUM_ALLOWED,
2932 NULL,
2933 WERR_OK,
2934 &action_taken,
2935 &new_handle),
2936 "failed to create symlink destination");
2937
2938 blob = data_blob_talloc_zero(tctx, 4);
2939 SIVAL(blob.data, 0, value);
2940
2941 torture_assert(tctx,
2942 test_SetValue(b, tctx, &new_handle, "TestValue", REG_DWORD, blob.data, blob.length),
2943 "failed to create TestValue");
2944
2945 torture_assert(tctx,
2946 test_CloseKey(b, tctx, &new_handle),
2947 "failed to close");
2948
2949 /* create symlink */
2950
2951 torture_assert(tctx,
2952 test_CreateKey_opts(tctx, b, handle, test_key_symlink, NULL,
2953 REG_OPTION_CREATE_LINK | REG_OPTION_VOLATILE,
2954 SEC_FLAG_MAXIMUM_ALLOWED,
2955 NULL,
2956 WERR_OK,
2957 &action_taken,
2958 &new_handle),
2959 "failed to create REG_OPTION_CREATE_LINK type key");
2960
2961 torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2962
2963 kernel_mode_path = kernel_mode_registry_path(tctx, hkey, NULL, test_key_symlink_dest);
2964
2965 torture_assert(tctx,
2966 convert_string_talloc(tctx, CH_UNIX, CH_UTF16,
2967 kernel_mode_path,
2968 strlen(kernel_mode_path), /* not NULL terminated */
2969 &blob.data, &blob.length),
2970 "failed to convert");
2971
2972 torture_assert(tctx,
2973 test_SetValue(b, tctx, &new_handle, "SymbolicLinkValue", REG_LINK, blob.data, blob.length),
2974 "failed to create SymbolicLinkValue value");
2975
2976 torture_assert(tctx,
2977 test_CloseKey(b, tctx, &new_handle),
2978 "failed to close");
2979
2980 /* test follow symlink */
2981
2982 torture_assert(tctx,
2983 test_OpenKey_opts(tctx, b, handle, test_key_symlink,
2984 0,
2985 SEC_FLAG_MAXIMUM_ALLOWED,
2986 &new_handle,
2987 WERR_OK),
2988 "failed to follow symlink key");
2989
2990 torture_assert(tctx,
2991 test_QueryValue(b, tctx, &new_handle, "TestValue"),
2992 "failed to query value");
2993
2994 torture_assert(tctx,
2995 test_CloseKey(b, tctx, &new_handle),
2996 "failed to close");
2997
2998 /* delete link */
2999
3000 torture_assert(tctx,
3001 test_OpenKey_opts(tctx, b, handle, test_key_symlink,
3002 REG_OPTION_OPEN_LINK | REG_OPTION_VOLATILE,
3003 SEC_FLAG_MAXIMUM_ALLOWED,
3004 &new_handle,
3005 WERR_OK),
3006 "failed to open symlink key");
3007
3008 torture_assert(tctx,
3009 test_DeleteValue(b, tctx, &new_handle, "SymbolicLinkValue"),
3010 "failed to delete value SymbolicLinkValue");
3011
3012 torture_assert(tctx,
3013 test_CloseKey(b, tctx, &new_handle),
3014 "failed to close");
3015
3016 torture_assert(tctx,
3017 test_DeleteKey(b, tctx, handle, test_key_symlink),
3018 "failed to delete key");
3019
3020 /* delete destination */
3021
3022 torture_assert(tctx,
3023 test_DeleteKey(b, tctx, handle, test_key_symlink_dest),
3024 "failed to delete key");
3025
3026 return true;
3027 }
3028
3029 static bool test_CreateKey_keytypes(struct torture_context *tctx,
3030 struct dcerpc_binding_handle *b,
3031 struct policy_handle *handle,
3032 const char *key,
3033 int hkey)
3034 {
3035
3036 if (torture_setting_bool(tctx, "samba3", false) ||
3037 torture_setting_bool(tctx, "samba4", false)) {
3038 torture_skip(tctx, "skipping CreateKey keytypes test against Samba");
3039 }
3040
3041 torture_assert(tctx,
3042 test_volatile_keys(tctx, b, handle, hkey),
3043 "failed to test volatile keys");
3044
3045 torture_assert(tctx,
3046 test_symlink_keys(tctx, b, handle, key, hkey),
3047 "failed to test symlink keys");
3048
3049 return true;
3050 }
3051
3052 static bool test_key_base(struct torture_context *tctx,
3053 struct dcerpc_binding_handle *b,
3054 struct policy_handle *handle,
3055 const char *base_key,
3056 int hkey)
3057 {
3058 struct policy_handle newhandle;
3059 bool ret = true, created = false, deleted = false;
3060 bool created3 = false;
3061 const char *test_key1;
3062 const char *test_key3;
3063 const char *test_subkey;
3064
3065 test_Cleanup(b, tctx, handle, base_key);
3066
3067 if (!test_CreateKey(b, tctx, handle, base_key, NULL)) {
3068 torture_comment(tctx,
3069 "CreateKey(%s) failed\n", base_key);
3070 }
3071
3072 test_key1 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY1);
3073
3074 if (!test_CreateKey(b, tctx, handle, test_key1, NULL)) {
3075 torture_comment(tctx,
3076 "CreateKey failed - not considering a failure\n");
3077 } else {
3078 created = true;
3079 }
3080
3081 if (created) {
3082 if (!test_FlushKey(b, tctx, handle)) {
3083 torture_comment(tctx, "FlushKey failed\n");
3084 ret = false;
3085 }
3086
3087 if (!test_OpenKey(b, tctx, handle, test_key1, &newhandle)) {
3088 torture_fail(tctx,
3089 "CreateKey failed (OpenKey after Create didn't work)\n");
3090 }
3091
3092 if (hkey == HKEY_CURRENT_USER) {
3093 torture_assert(tctx, test_SetValue_simple(b, tctx, &newhandle),
3094 "simple SetValue test failed");
3095 torture_assert(tctx, test_SetValue_values(b, tctx, &newhandle),
3096 "values SetValue test failed");
3097 torture_assert(tctx, test_SetValue_extended(b, tctx, &newhandle),
3098 "extended SetValue test failed");
3099 torture_assert(tctx, test_create_keynames(b, tctx, &newhandle),
3100 "keyname CreateKey test failed");
3101 } else {
3102 torture_assert(tctx, test_CreateKey_keytypes(tctx, b, &newhandle, test_key1, hkey),
3103 "keytype test failed");
3104 torture_assert(tctx, test_EnumValue_one(b, tctx, &newhandle, 0xff),
3105 "simple EnumValue test failed");
3106 }
3107
3108 if (!test_CloseKey(b, tctx, &newhandle)) {
3109 torture_fail(tctx,
3110 "CreateKey failed (CloseKey after Open didn't work)\n");
3111 }
3112
3113 if (!test_DeleteKey(b, tctx, handle, test_key1)) {
3114 torture_comment(tctx, "DeleteKey(%s) failed\n",
3115 test_key1);
3116 ret = false;
3117 } else {
3118 deleted = true;
3119 }
3120
3121 if (!test_FlushKey(b, tctx, handle)) {
3122 torture_comment(tctx, "FlushKey failed\n");
3123 ret = false;
3124 }
3125
3126 if (deleted) {
3127 if (!test_OpenKey_opts(tctx, b, handle, test_key1,
3128 REG_OPTION_NON_VOLATILE,
3129 SEC_FLAG_MAXIMUM_ALLOWED,
3130 &newhandle,
3131 WERR_FILE_NOT_FOUND)) {
3132 torture_comment(tctx,
3133 "DeleteKey failed (OpenKey after Delete "
3134 "did not return WERR_FILE_NOT_FOUND)\n");
3135 ret = false;
3136 }
3137 }
3138
3139 test_key3 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY3);
3140
3141 if (test_CreateKey(b, tctx, handle, test_key3, NULL)) {
3142 created3 = true;
3143 }
3144
3145 test_subkey = talloc_asprintf(tctx, "%s\\%s", test_key3, TEST_SUBKEY);
3146
3147 if (created3) {
3148 if (test_CreateKey(b, tctx, handle, test_subkey, NULL)) {
3149 if (!test_DeleteKey(b, tctx, handle, test_subkey)) {
3150 torture_comment(tctx, "DeleteKey(%s) failed\n", test_subkey);
3151 ret = false;
3152 }
3153 }
3154
3155 if (!test_DeleteKey(b, tctx, handle, test_key3)) {
3156 torture_comment(tctx, "DeleteKey(%s) failed\n", test_key3);
3157 ret = false;
3158 }
3159 }
3160 }
3161
3162 test_Cleanup(b, tctx, handle, base_key);
3163
3164 return ret;
3165 }
3166
3167 static bool test_key_base_sd(struct torture_context *tctx,
3168 struct dcerpc_pipe *p,
3169 struct policy_handle *handle,
3170 const char *base_key)
3171 {
3172 struct policy_handle newhandle;
3173 bool ret = true, created2 = false, created4 = false;
3174 struct dcerpc_binding_handle *b = p->binding_handle;
3175 const char *test_key2;
3176 const char *test_key4;
3177
3178 torture_skip(tctx, "security descriptor test disabled\n");
3179
3180 if (torture_setting_bool(tctx, "samba3", false) ||
3181 torture_setting_bool(tctx, "samba4", false)) {
3182 torture_skip(tctx, "skipping security descriptor tests against Samba");
3183 }
3184
3185 test_Cleanup(b, tctx, handle, base_key);
3186
3187 if (!test_CreateKey(b, tctx, handle, base_key, NULL)) {
3188 torture_comment(tctx,
3189 "CreateKey(%s) failed\n", base_key);
3190 }
3191
3192 test_key2 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY2);
3193
3194 if (test_CreateKey_sd(b, tctx, handle, test_key2,
3195 NULL, &newhandle)) {
3196 created2 = true;
3197 }
3198
3199 if (created2 && !test_CloseKey(b, tctx, &newhandle)) {
3200 torture_comment(tctx, "CloseKey failed\n");
3201 ret = false;
3202 }
3203
3204 test_key4 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY4);
3205
3206 if (test_CreateKey_sd(b, tctx, handle, test_key4, NULL, &newhandle)) {
3207 created4 = true;
3208 }
3209
3210 if (created4 && !test_CloseKey(b, tctx, &newhandle)) {
3211 torture_comment(tctx, "CloseKey failed\n");
3212 ret = false;
3213 }
3214
3215 if (created4 && !test_SecurityDescriptors(p, tctx, handle, test_key4)) {
3216 ret = false;
3217 }
3218
3219 if (created4 && !test_DeleteKey(b, tctx, handle, test_key4)) {
3220 torture_comment(tctx, "DeleteKey(%s) failed\n", test_key4);
3221 ret = false;
3222 }
3223
3224 if (created2 && !test_DeleteKey(b, tctx, handle, test_key4)) {
3225 torture_comment(tctx, "DeleteKey(%s) failed\n", test_key4);
3226 ret = false;
3227 }
3228
3229 test_Cleanup(b, tctx, handle, base_key);
3230
3231 return ret;
3232 }
3233
3234 static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p,
3235 void *userdata)
3236 {
3237 struct policy_handle handle;
3238 bool ret = true;
3239 struct winreg_OpenHKLM r;
3240 struct dcerpc_binding_handle *b = p->binding_handle;
3241 const char *torture_base_key;
3242 int hkey = 0;
3243
3244 winreg_open_fn open_fn = (winreg_open_fn)userdata;
3245
3246 r.in.system_name = 0;
3247 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3248 r.out.handle = &handle;
3249
3250 torture_assert_ntstatus_ok(tctx, open_fn(b, tctx, &r),
3251 "open");
3252
3253 if (!test_GetVersion(b, tctx, &handle)) {
3254 torture_comment(tctx, "GetVersion failed\n");
3255 ret = false;
3256 }
3257
3258 if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKLM_r) {
3259 hkey = HKEY_LOCAL_MACHINE;
3260 torture_base_key = "SOFTWARE\\Samba\\" TEST_KEY_BASE;
3261 } else if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKU_r) {
3262 hkey = HKEY_USERS;
3263 torture_base_key = TEST_KEY_BASE;
3264 } else if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKCR_r) {
3265 hkey = HKEY_CLASSES_ROOT;
3266 torture_base_key = TEST_KEY_BASE;
3267 } else if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKCU_r) {
3268 hkey = HKEY_CURRENT_USER;
3269 torture_base_key = TEST_KEY_BASE;
3270 } else {
3271 torture_fail(tctx, "unsupported hkey");
3272 }
3273
3274 if (hkey == HKEY_LOCAL_MACHINE) {
3275 torture_assert(tctx,
3276 test_HKLM_wellknown(tctx, b, &handle),
3277 "failed to test HKLM wellknown keys");
3278 }
3279
3280 if (!test_key_base(tctx, b, &handle, torture_base_key, hkey)) {
3281 torture_warning(tctx, "failed to test TEST_KEY_BASE(%s)",
3282 torture_base_key);
3283 ret = false;
3284 }
3285
3286 if (!test_key_base_sd(tctx, p, &handle, torture_base_key)) {
3287 torture_warning(tctx, "failed to test TEST_KEY_BASE(%s) sd",
3288 torture_base_key);
3289 ret = false;
3290 }
3291
3292 /* The HKCR hive has a very large fanout */
3293 if (hkey == HKEY_CLASSES_ROOT) {
3294 if(!test_key(p, tctx, &handle, MAX_DEPTH - 1, false)) {
3295 ret = false;
3296 }
3297 } else if (hkey == HKEY_LOCAL_MACHINE) {
3298 /* FIXME we are not allowed to enum values in the HKLM root */
3299 } else {
3300 if (!test_key(p, tctx, &handle, 0, false)) {
3301 ret = false;
3302 }
3303 }
3304
3305 return ret;
3306 }
3307
3308 struct torture_suite *torture_rpc_winreg(TALLOC_CTX *mem_ctx)
3309 {
3310 struct torture_rpc_tcase *tcase;
3311 struct torture_suite *suite = torture_suite_create(mem_ctx, "winreg");
3312 struct torture_test *test;
3313
3314 tcase = torture_suite_add_rpc_iface_tcase(suite, "winreg",
3315 &ndr_table_winreg);
3316
3317 test = torture_rpc_tcase_add_test(tcase, "InitiateSystemShutdown",
3318 test_InitiateSystemShutdown);
3319 test->dangerous = true;
3320
3321 test = torture_rpc_tcase_add_test(tcase, "InitiateSystemShutdownEx",
3322 test_InitiateSystemShutdownEx);
3323 test->dangerous = true;
3324
3325 torture_rpc_tcase_add_test_ex(tcase, "HKLM",
3326 test_Open,
3327 (void *)dcerpc_winreg_OpenHKLM_r);
3328 torture_rpc_tcase_add_test_ex(tcase, "HKU",
3329 test_Open,
3330 (void *)dcerpc_winreg_OpenHKU_r);
3331 torture_rpc_tcase_add_test_ex(tcase, "HKCR",
3332 test_Open,
3333 (void *)dcerpc_winreg_OpenHKCR_r);
3334 torture_rpc_tcase_add_test_ex(tcase, "HKCU",
3335 test_Open,
3336 (void *)dcerpc_winreg_OpenHKCU_r);
3337
3338 return suite;
3339 }