~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/torture/rpc/winreg.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
   Copyright (C) Tim Potter 2003
6
6
   Copyright (C) Jelmer Vernooij 2004-2007
7
 
   Copyright (C) Günther Deschner 2007
 
7
   Copyright (C) Günther Deschner 2007,2010
8
8
 
9
9
   This program is free software; you can redistribute it and/or modify
10
10
   it under the terms of the GNU General Public License as published by
21
21
*/
22
22
 
23
23
#include "includes.h"
24
 
#include "torture/torture.h"
25
24
#include "librpc/gen_ndr/ndr_winreg_c.h"
26
25
#include "librpc/gen_ndr/ndr_security.h"
27
26
#include "libcli/security/security.h"
28
 
#include "torture/rpc/rpc.h"
 
27
#include "torture/rpc/torture_rpc.h"
 
28
#include "param/param.h"
 
29
#include "lib/registry/registry.h"
29
30
 
30
 
#define TEST_KEY_BASE "smbtorture test"
31
 
#define TEST_KEY1 TEST_KEY_BASE "\\spottyfoot"
32
 
#define TEST_KEY2 TEST_KEY_BASE "\\with a SD (#1)"
33
 
#define TEST_KEY3 TEST_KEY_BASE "\\with a subkey"
34
 
#define TEST_KEY4 TEST_KEY_BASE "\\sd_tests"
35
 
#define TEST_SUBKEY TEST_KEY3 "\\subkey"
36
 
#define TEST_SUBKEY_SD  TEST_KEY4 "\\subkey_sd"
37
 
#define TEST_SUBSUBKEY_SD TEST_KEY4 "\\subkey_sd\\subsubkey_sd"
 
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"
38
44
 
39
45
#define TEST_SID "S-1-5-21-1234567890-1234567890-1234567890-500"
40
46
 
55
61
        }
56
62
}
57
63
 
58
 
static bool test_GetVersion(struct dcerpc_pipe *p,
 
64
static bool test_GetVersion(struct dcerpc_binding_handle *b,
59
65
                            struct torture_context *tctx,
60
66
                            struct policy_handle *handle)
61
67
{
62
68
        struct winreg_GetVersion r;
63
69
        uint32_t v;
64
70
 
 
71
        torture_comment(tctx, "Testing GetVersion\n");
 
72
 
65
73
        ZERO_STRUCT(r);
66
74
        r.in.handle = handle;
67
75
        r.out.version = &v;
68
76
 
69
 
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_GetVersion(p, tctx, &r),
 
77
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_GetVersion_r(b, tctx, &r),
70
78
                                   "GetVersion failed");
71
79
 
72
80
        torture_assert_werr_ok(tctx, r.out.result, "GetVersion failed");
74
82
        return true;
75
83
}
76
84
 
77
 
static bool test_NotifyChangeKeyValue(struct dcerpc_pipe *p,
 
85
static bool test_NotifyChangeKeyValue(struct dcerpc_binding_handle *b,
78
86
                                      struct torture_context *tctx,
79
87
                                      struct policy_handle *handle)
80
88
{
89
97
        init_winreg_String(&r.in.string2, NULL);
90
98
 
91
99
        torture_assert_ntstatus_ok(tctx,
92
 
                                   dcerpc_winreg_NotifyChangeKeyValue(p, tctx, &r),
 
100
                                   dcerpc_winreg_NotifyChangeKeyValue_r(b, tctx, &r),
93
101
                                   "NotifyChangeKeyValue failed");
94
102
 
95
103
        if (!W_ERROR_IS_OK(r.out.result)) {
102
110
        return true;
103
111
}
104
112
 
105
 
static bool test_CreateKey(struct dcerpc_pipe *p, struct torture_context *tctx,
 
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,
106
159
                           struct policy_handle *handle, const char *name,
107
160
                           const char *kclass)
108
161
{
109
 
        struct winreg_CreateKey r;
110
 
        struct policy_handle newhandle;
111
 
        enum winreg_CreateAction action_taken = 0;
112
 
 
113
 
        ZERO_STRUCT(r);
114
 
        r.in.handle = handle;
115
 
        r.out.new_handle = &newhandle;
116
 
        init_winreg_String(&r.in.name, name);
117
 
        init_winreg_String(&r.in.keyclass, kclass);
118
 
        r.in.options = 0x0;
119
 
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
120
 
        r.in.action_taken = r.out.action_taken = &action_taken;
121
 
        r.in.secdesc = NULL;
122
 
 
123
 
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CreateKey(p, tctx, &r),
124
 
                                   "CreateKey failed");
125
 
 
126
 
        torture_assert_werr_ok(tctx,  r.out.result, "CreateKey failed");
127
 
 
128
 
        return true;
 
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 */);
129
169
}
130
170
 
131
 
 
132
171
/*
133
172
  createkey testing with a SD
134
173
*/
135
 
static bool test_CreateKey_sd(struct dcerpc_pipe *p,
 
174
static bool test_CreateKey_sd(struct dcerpc_binding_handle *b,
136
175
                              struct torture_context *tctx,
137
176
                              struct policy_handle *handle, const char *name,
138
177
                              const char *kclass,
155
194
                                        NULL);
156
195
 
157
196
        torture_assert_ndr_success(tctx,
158
 
                ndr_push_struct_blob(&sdblob, tctx, NULL, sd,
 
197
                ndr_push_struct_blob(&sdblob, tctx, sd,
159
198
                                     (ndr_push_flags_fn_t)ndr_push_security_descriptor),
160
199
                                     "Failed to push security_descriptor ?!\n");
161
200
 
175
214
        r.in.action_taken = r.out.action_taken = &action_taken;
176
215
        r.in.secdesc = &secbuf;
177
216
 
178
 
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CreateKey(p, tctx, &r),
 
217
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CreateKey_r(b, tctx, &r),
179
218
                                   "CreateKey with sd failed");
180
219
 
181
220
        torture_assert_werr_ok(tctx, r.out.result, "CreateKey with sd failed");
194
233
        struct security_descriptor *sd = NULL;
195
234
        uint32_t sec_info;
196
235
        DATA_BLOB sdblob;
 
236
        struct dcerpc_binding_handle *b = p->binding_handle;
197
237
 
198
238
        if (sec_info_ptr) {
199
239
                sec_info = *sec_info_ptr;
209
249
        r.in.sd->size = 0x1000;
210
250
 
211
251
        torture_assert_ntstatus_ok(tctx,
212
 
                                   dcerpc_winreg_GetKeySecurity(p, tctx, &r),
 
252
                                   dcerpc_winreg_GetKeySecurity_r(b, tctx, &r),
213
253
                                   "GetKeySecurity failed");
214
254
 
215
255
        torture_assert_werr_equal(tctx, r.out.result, get_werr,
221
261
        sd = talloc_zero(tctx, struct security_descriptor);
222
262
 
223
263
        torture_assert_ndr_success(tctx,
224
 
                ndr_pull_struct_blob(&sdblob, tctx, NULL, sd,
 
264
                ndr_pull_struct_blob(&sdblob, tctx, sd,
225
265
                                     (ndr_pull_flags_fn_t)ndr_pull_security_descriptor),
226
266
                                     "pull_security_descriptor failed");
227
267
 
257
297
        struct KeySecurityData *sdata = NULL;
258
298
        DATA_BLOB sdblob;
259
299
        uint32_t sec_info;
 
300
        struct dcerpc_binding_handle *b = p->binding_handle;
260
301
 
261
302
        ZERO_STRUCT(r);
262
303
 
265
306
        }
266
307
 
267
308
        torture_assert_ndr_success(tctx,
268
 
                ndr_push_struct_blob(&sdblob, tctx, NULL, sd,
 
309
                ndr_push_struct_blob(&sdblob, tctx, sd,
269
310
                                     (ndr_push_flags_fn_t)ndr_push_security_descriptor),
270
311
                                     "push_security_descriptor failed");
271
312
 
298
339
        r.in.sd = sdata;
299
340
 
300
341
        torture_assert_ntstatus_ok(tctx,
301
 
                                   dcerpc_winreg_SetKeySecurity(p, tctx, &r),
 
342
                                   dcerpc_winreg_SetKeySecurity_r(b, tctx, &r),
302
343
                                   "SetKeySecurity failed");
303
344
 
304
345
        torture_assert_werr_equal(tctx, r.out.result, werr,
315
356
        return _test_SetKeySecurity(p, tctx, handle, NULL, sd, WERR_OK);
316
357
}
317
358
 
318
 
static bool test_CloseKey(struct dcerpc_pipe *p, struct torture_context *tctx,
 
359
static bool test_CloseKey(struct dcerpc_binding_handle *b,
 
360
                          struct torture_context *tctx,
319
361
                          struct policy_handle *handle)
320
362
{
321
363
        struct winreg_CloseKey r;
323
365
        ZERO_STRUCT(r);
324
366
        r.in.handle = r.out.handle = handle;
325
367
 
326
 
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey(p, tctx, &r),
 
368
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey_r(b, tctx, &r),
327
369
                                   "CloseKey failed");
328
370
 
329
371
        torture_assert_werr_ok(tctx, r.out.result, "CloseKey failed");
331
373
        return true;
332
374
}
333
375
 
334
 
static bool test_FlushKey(struct dcerpc_pipe *p, struct torture_context *tctx,
 
376
static bool test_FlushKey(struct dcerpc_binding_handle *b,
 
377
                          struct torture_context *tctx,
335
378
                          struct policy_handle *handle)
336
379
{
337
380
        struct winreg_FlushKey r;
339
382
        ZERO_STRUCT(r);
340
383
        r.in.handle = handle;
341
384
 
342
 
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_FlushKey(p, tctx, &r),
 
385
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_FlushKey_r(b, tctx, &r),
343
386
                                   "FlushKey failed");
344
387
 
345
388
        torture_assert_werr_ok(tctx, r.out.result, "FlushKey failed");
347
390
        return true;
348
391
}
349
392
 
350
 
static bool _test_OpenKey(struct dcerpc_pipe *p, struct torture_context *tctx,
351
 
                          struct policy_handle *hive_handle,
352
 
                          const char *keyname, uint32_t access_mask,
353
 
                          struct policy_handle *key_handle,
354
 
                          WERROR open_werr,
355
 
                          bool *success)
 
393
static bool test_OpenKey_opts(struct torture_context *tctx,
 
394
                              struct dcerpc_binding_handle *b,
 
395
                              struct policy_handle *hive_handle,
 
396
                              const char *keyname,
 
397
                              uint32_t options,
 
398
                              uint32_t access_mask,
 
399
                              struct policy_handle *key_handle,
 
400
                              WERROR expected_result)
356
401
{
357
402
        struct winreg_OpenKey r;
358
403
 
359
404
        ZERO_STRUCT(r);
360
405
        r.in.parent_handle = hive_handle;
361
406
        init_winreg_String(&r.in.keyname, keyname);
362
 
        r.in.unknown = 0x00000000;
 
407
        r.in.options = options;
363
408
        r.in.access_mask = access_mask;
364
409
        r.out.handle = key_handle;
365
410
 
366
 
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey(p, tctx, &r),
 
411
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey_r(b, tctx, &r),
367
412
                                   "OpenKey failed");
368
413
 
369
 
        torture_assert_werr_equal(tctx, r.out.result, open_werr,
 
414
        torture_assert_werr_equal(tctx, r.out.result, expected_result,
370
415
                                  "OpenKey failed");
371
416
 
372
 
        if (success && W_ERROR_EQUAL(r.out.result, WERR_OK)) {
373
 
                *success = true;
374
 
        }
375
 
 
376
417
        return true;
377
418
}
378
419
 
379
 
static bool test_OpenKey(struct dcerpc_pipe *p, struct torture_context *tctx,
 
420
static bool test_OpenKey(struct dcerpc_binding_handle *b,
 
421
                         struct torture_context *tctx,
380
422
                         struct policy_handle *hive_handle,
381
423
                         const char *keyname, struct policy_handle *key_handle)
382
424
{
383
 
        return _test_OpenKey(p, tctx, hive_handle, keyname,
384
 
                             SEC_FLAG_MAXIMUM_ALLOWED, key_handle,
385
 
                             WERR_OK, NULL);
 
425
        return test_OpenKey_opts(tctx, b, hive_handle, keyname,
 
426
                                 REG_OPTION_NON_VOLATILE,
 
427
                                 SEC_FLAG_MAXIMUM_ALLOWED,
 
428
                                 key_handle,
 
429
                                 WERR_OK);
386
430
}
387
431
 
388
 
static bool test_Cleanup(struct dcerpc_pipe *p, struct torture_context *tctx,
 
432
static bool test_Cleanup(struct dcerpc_binding_handle *b,
 
433
                         struct torture_context *tctx,
389
434
                         struct policy_handle *handle, const char *key)
390
435
{
391
436
        struct winreg_DeleteKey r;
394
439
        r.in.handle = handle;
395
440
 
396
441
        init_winreg_String(&r.in.key, key);
397
 
        dcerpc_winreg_DeleteKey(p, tctx, &r);
 
442
        dcerpc_winreg_DeleteKey_r(b, tctx, &r);
398
443
 
399
444
        return true;
400
445
}
425
470
{
426
471
        struct policy_handle new_handle;
427
472
        bool ret = true;
 
473
        struct dcerpc_binding_handle *b = p->binding_handle;
428
474
 
429
475
        torture_comment(tctx, "SecurityDescriptor get & set\n");
430
476
 
431
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
477
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
432
478
                return false;
433
479
        }
434
480
 
437
483
                ret = false;
438
484
        }
439
485
 
440
 
        if (!test_CloseKey(p, tctx, &new_handle)) {
 
486
        if (!test_CloseKey(b, tctx, &new_handle)) {
441
487
                return false;
442
488
        }
443
489
 
455
501
{
456
502
        struct policy_handle new_handle;
457
503
        bool ret = true;
458
 
        bool got_key = false;
459
 
 
460
 
        if (!_test_OpenKey(p, tctx, handle, key, access_mask, &new_handle,
461
 
                           open_werr, &got_key)) {
462
 
                return false;
463
 
        }
464
 
 
465
 
        if (!got_key) {
 
504
        struct dcerpc_binding_handle *b = p->binding_handle;
 
505
 
 
506
        torture_assert(tctx,
 
507
                test_OpenKey_opts(tctx, b, handle, key,
 
508
                                  REG_OPTION_NON_VOLATILE,
 
509
                                  access_mask,
 
510
                                  &new_handle,
 
511
                                  open_werr),
 
512
                "failed to open key");
 
513
 
 
514
        if (!W_ERROR_IS_OK(open_werr)) {
466
515
                return true;
467
516
        }
468
517
 
471
520
                ret = false;
472
521
        }
473
522
 
474
 
        if (!test_CloseKey(p, tctx, &new_handle)) {
 
523
        if (!test_CloseKey(b, tctx, &new_handle)) {
475
524
                return false;
476
525
        }
477
526
 
511
560
{
512
561
        struct policy_handle new_handle;
513
562
        bool ret = true;
 
563
        struct dcerpc_binding_handle *b = p->binding_handle;
514
564
 
515
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
565
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
516
566
                return false;
517
567
        }
518
568
 
519
569
        ret = test_dacl_trustee_present(p, tctx, &new_handle, sid);
520
570
 
521
 
        test_CloseKey(p, tctx, &new_handle);
 
571
        test_CloseKey(b, tctx, &new_handle);
522
572
 
523
573
        return ret;
524
574
}
557
607
{
558
608
        struct policy_handle new_handle;
559
609
        bool ret = true;
 
610
        struct dcerpc_binding_handle *b = p->binding_handle;
560
611
 
561
 
        if (!_test_OpenKey(p, tctx, handle, key, SEC_FLAG_SYSTEM_SECURITY,
562
 
                           &new_handle, WERR_OK, NULL)) {
563
 
                return false;
564
 
        }
 
612
        torture_assert(tctx,
 
613
                test_OpenKey_opts(tctx, b, handle, key,
 
614
                                  REG_OPTION_NON_VOLATILE,
 
615
                                  SEC_FLAG_SYSTEM_SECURITY,
 
616
                                  &new_handle,
 
617
                                  WERR_OK),
 
618
                "failed to open key");
565
619
 
566
620
        ret = test_sacl_trustee_present(p, tctx, &new_handle, sid);
567
621
 
568
 
        test_CloseKey(p, tctx, &new_handle);
 
622
        test_CloseKey(b, tctx, &new_handle);
569
623
 
570
624
        return ret;
571
625
}
597
651
{
598
652
        struct policy_handle new_handle;
599
653
        bool ret = true;
 
654
        struct dcerpc_binding_handle *b = p->binding_handle;
600
655
 
601
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
656
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
602
657
                return false;
603
658
        }
604
659
 
605
660
        ret = test_owner_present(p, tctx, &new_handle, sid);
606
661
 
607
 
        test_CloseKey(p, tctx, &new_handle);
 
662
        test_CloseKey(b, tctx, &new_handle);
608
663
 
609
664
        return ret;
610
665
}
636
691
{
637
692
        struct policy_handle new_handle;
638
693
        bool ret = true;
 
694
        struct dcerpc_binding_handle *b = p->binding_handle;
639
695
 
640
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
696
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
641
697
                return false;
642
698
        }
643
699
 
644
700
        ret = test_group_present(p, tctx, &new_handle, sid);
645
701
 
646
 
        test_CloseKey(p, tctx, &new_handle);
 
702
        test_CloseKey(b, tctx, &new_handle);
647
703
 
648
704
        return ret;
649
705
}
708
764
{
709
765
        struct policy_handle new_handle;
710
766
        bool ret = true;
 
767
        struct dcerpc_binding_handle *b = p->binding_handle;
711
768
 
712
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
769
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
713
770
                return false;
714
771
        }
715
772
 
717
774
                ret = false;
718
775
        }
719
776
 
720
 
        if (!test_CloseKey(p, tctx, &new_handle)) {
 
777
        if (!test_CloseKey(b, tctx, &new_handle)) {
721
778
                ret = false;
722
779
        }
723
780
 
732
789
{
733
790
        struct policy_handle new_handle;
734
791
        bool ret = true;
 
792
        struct dcerpc_binding_handle *b = p->binding_handle;
735
793
 
736
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
794
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
737
795
                return false;
738
796
        }
739
797
 
741
799
                ret = false;
742
800
        }
743
801
 
744
 
        if (!test_CloseKey(p, tctx, &new_handle)) {
 
802
        if (!test_CloseKey(b, tctx, &new_handle)) {
745
803
                ret = false;
746
804
        }
747
805
 
773
831
        struct security_descriptor *sd_orig = NULL;
774
832
        struct security_ace *ace = NULL;
775
833
        struct policy_handle new_handle;
776
 
        NTSTATUS status;
777
834
        bool ret = true;
 
835
        struct dcerpc_binding_handle *b = p->binding_handle;
 
836
        const char *test_subkey_sd;
 
837
        const char *test_subsubkey_sd;
778
838
 
779
839
        torture_comment(tctx, "SecurityDescriptor inheritance\n");
780
840
 
781
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
841
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
782
842
                return false;
783
843
        }
784
844
 
797
857
                                  SEC_STD_REQUIRED,
798
858
                                  SEC_ACE_FLAG_CONTAINER_INHERIT);
799
859
 
800
 
        status = security_descriptor_dacl_add(sd, ace);
801
 
        if (!NT_STATUS_IS_OK(status)) {
802
 
                printf("failed to add ace: %s\n", nt_errstr(status));
803
 
                return false;
804
 
        }
 
860
        torture_assert_ntstatus_ok(tctx,
 
861
                security_descriptor_dacl_add(sd, ace),
 
862
                "failed to add ace");
805
863
 
806
864
        /* FIXME: add further tests for these flags */
807
865
        sd->type |= SEC_DESC_DACL_AUTO_INHERIT_REQ |
811
869
                return false;
812
870
        }
813
871
 
814
 
        if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
815
 
                printf("new ACE not present!\n");
816
 
                return false;
817
 
        }
818
 
 
819
 
        if (!test_CloseKey(p, tctx, &new_handle)) {
820
 
                return false;
821
 
        }
822
 
 
823
 
        if (!test_CreateKey(p, tctx, handle, TEST_SUBKEY_SD, NULL)) {
824
 
                ret = false;
825
 
                goto out;
826
 
        }
827
 
 
828
 
        if (!test_OpenKey(p, tctx, handle, TEST_SUBKEY_SD, &new_handle)) {
829
 
                ret = false;
830
 
                goto out;
831
 
        }
832
 
 
833
 
        if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
834
 
                printf("inherited ACE not present!\n");
835
 
                ret = false;
836
 
                goto out;
837
 
        }
838
 
 
839
 
        test_CloseKey(p, tctx, &new_handle);
840
 
        if (!test_CreateKey(p, tctx, handle, TEST_SUBSUBKEY_SD, NULL)) {
841
 
                ret = false;
842
 
                goto out;
843
 
        }
844
 
 
845
 
        if (!test_OpenKey(p, tctx, handle, TEST_SUBSUBKEY_SD, &new_handle)) {
846
 
                ret = false;
847
 
                goto out;
848
 
        }
849
 
 
850
 
        if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
851
 
                printf("inherited ACE not present!\n");
 
872
        torture_assert(tctx,
 
873
                test_dacl_ace_present(p, tctx, &new_handle, ace),
 
874
                "new ACE not present!");
 
875
 
 
876
        if (!test_CloseKey(b, tctx, &new_handle)) {
 
877
                return false;
 
878
        }
 
879
 
 
880
        test_subkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBKEY_SD);
 
881
 
 
882
        if (!test_CreateKey(b, tctx, handle, test_subkey_sd, NULL)) {
 
883
                ret = false;
 
884
                goto out;
 
885
        }
 
886
 
 
887
        if (!test_OpenKey(b, tctx, handle, test_subkey_sd, &new_handle)) {
 
888
                ret = false;
 
889
                goto out;
 
890
        }
 
891
 
 
892
        if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
 
893
                torture_comment(tctx, "inherited ACE not present!\n");
 
894
                ret = false;
 
895
                goto out;
 
896
        }
 
897
 
 
898
        test_subsubkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBSUBKEY_SD);
 
899
 
 
900
        test_CloseKey(b, tctx, &new_handle);
 
901
        if (!test_CreateKey(b, tctx, handle, test_subsubkey_sd, NULL)) {
 
902
                ret = false;
 
903
                goto out;
 
904
        }
 
905
 
 
906
        if (!test_OpenKey(b, tctx, handle, test_subsubkey_sd, &new_handle)) {
 
907
                ret = false;
 
908
                goto out;
 
909
        }
 
910
 
 
911
        if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
 
912
                torture_comment(tctx, "inherited ACE not present!\n");
852
913
                ret = false;
853
914
                goto out;
854
915
        }
855
916
 
856
917
 out:
857
 
        test_CloseKey(p, tctx, &new_handle);
858
 
        test_Cleanup(p, tctx, handle, TEST_SUBKEY_SD);
 
918
        test_CloseKey(b, tctx, &new_handle);
 
919
        test_Cleanup(b, tctx, handle, test_subkey_sd);
859
920
        test_RestoreSecurity(p, tctx, handle, key, sd_orig);
860
921
 
861
 
        return true;
 
922
        return ret;
862
923
}
863
924
 
864
925
static bool test_SecurityDescriptorBlockInheritance(struct dcerpc_pipe *p,
884
945
        struct security_ace *ace = NULL;
885
946
        struct policy_handle new_handle;
886
947
        struct dom_sid *sid = NULL;
887
 
        NTSTATUS status;
888
948
        bool ret = true;
889
949
        uint8_t ace_flags = 0x0;
 
950
        struct dcerpc_binding_handle *b = p->binding_handle;
 
951
        const char *test_subkey_sd;
 
952
        const char *test_subsubkey_sd;
890
953
 
891
954
        torture_comment(tctx, "SecurityDescriptor inheritance block\n");
892
955
 
893
 
        if (!test_OpenKey(p, tctx, handle, key, &new_handle)) {
 
956
        if (!test_OpenKey(b, tctx, handle, key, &new_handle)) {
894
957
                return false;
895
958
        }
896
959
 
910
973
                                  SEC_ACE_FLAG_CONTAINER_INHERIT |
911
974
                                  SEC_ACE_FLAG_NO_PROPAGATE_INHERIT);
912
975
 
913
 
        status = security_descriptor_dacl_add(sd, ace);
914
 
        if (!NT_STATUS_IS_OK(status)) {
915
 
                printf("failed to add ace: %s\n", nt_errstr(status));
916
 
                return false;
917
 
        }
 
976
        torture_assert_ntstatus_ok(tctx,
 
977
                security_descriptor_dacl_add(sd, ace),
 
978
                "failed to add ace");
918
979
 
919
980
        if (!_test_SetKeySecurity(p, tctx, &new_handle, NULL, sd, WERR_OK)) {
920
981
                return false;
921
982
        }
922
983
 
923
 
        if (!test_dacl_ace_present(p, tctx, &new_handle, ace)) {
924
 
                printf("new ACE not present!\n");
925
 
                return false;
926
 
        }
927
 
 
928
 
        if (!test_CloseKey(p, tctx, &new_handle)) {
929
 
                return false;
930
 
        }
931
 
 
932
 
        if (!test_CreateKey(p, tctx, handle, TEST_SUBSUBKEY_SD, NULL)) {
933
 
                return false;
934
 
        }
935
 
 
936
 
        if (!test_OpenKey(p, tctx, handle, TEST_SUBSUBKEY_SD, &new_handle)) {
 
984
        torture_assert(tctx,
 
985
                test_dacl_ace_present(p, tctx, &new_handle, ace),
 
986
                "new ACE not present!");
 
987
 
 
988
        if (!test_CloseKey(b, tctx, &new_handle)) {
 
989
                return false;
 
990
        }
 
991
 
 
992
        test_subkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBKEY_SD);
 
993
        test_subsubkey_sd = talloc_asprintf(tctx, "%s\\%s", key, TEST_SUBSUBKEY_SD);
 
994
 
 
995
        if (!test_CreateKey(b, tctx, handle, test_subsubkey_sd, NULL)) {
 
996
                return false;
 
997
        }
 
998
 
 
999
        if (!test_OpenKey(b, tctx, handle, test_subsubkey_sd, &new_handle)) {
937
1000
                ret = false;
938
1001
                goto out;
939
1002
        }
940
1003
 
941
1004
        if (test_dacl_ace_present(p, tctx, &new_handle, ace)) {
942
 
                printf("inherited ACE present but should not!\n");
 
1005
                torture_comment(tctx, "inherited ACE present but should not!\n");
943
1006
                ret = false;
944
1007
                goto out;
945
1008
        }
950
1013
        }
951
1014
 
952
1015
        if (test_dacl_trustee_present(p, tctx, &new_handle, sid)) {
953
 
                printf("inherited trustee SID present but should not!\n");
 
1016
                torture_comment(tctx, "inherited trustee SID present but should not!\n");
954
1017
                ret = false;
955
1018
                goto out;
956
1019
        }
957
1020
 
958
 
        test_CloseKey(p, tctx, &new_handle);
 
1021
        test_CloseKey(b, tctx, &new_handle);
959
1022
 
960
 
        if (!test_OpenKey(p, tctx, handle, TEST_SUBKEY_SD, &new_handle)) {
 
1023
        if (!test_OpenKey(b, tctx, handle, test_subkey_sd, &new_handle)) {
961
1024
                ret = false;
962
1025
                goto out;
963
1026
        }
964
1027
 
965
1028
        if (test_dacl_ace_present(p, tctx, &new_handle, ace)) {
966
 
                printf("inherited ACE present but should not!\n");
 
1029
                torture_comment(tctx, "inherited ACE present but should not!\n");
967
1030
                ret = false;
968
1031
                goto out;
969
1032
        }
970
1033
 
971
1034
        if (!test_dacl_trustee_flags_present(p, tctx, &new_handle, sid, ace_flags)) {
972
 
                printf("inherited trustee SID with flags 0x%02x not present!\n",
 
1035
                torture_comment(tctx, "inherited trustee SID with flags 0x%02x not present!\n",
973
1036
                        ace_flags);
974
1037
                ret = false;
975
1038
                goto out;
976
1039
        }
977
1040
 
978
1041
 out:
979
 
        test_CloseKey(p, tctx, &new_handle);
980
 
        test_Cleanup(p, tctx, handle, TEST_SUBKEY_SD);
 
1042
        test_CloseKey(b, tctx, &new_handle);
 
1043
        test_Cleanup(b, tctx, handle, test_subkey_sd);
981
1044
        test_RestoreSecurity(p, tctx, handle, key, sd_orig);
982
1045
 
983
1046
        return ret;
1061
1124
                                               const struct dom_sid *sid)
1062
1125
{
1063
1126
        struct policy_handle new_handle;
1064
 
        bool open_success = false;
 
1127
        struct dcerpc_binding_handle *b = p->binding_handle;
1065
1128
 
1066
1129
        torture_comment(tctx, "SecurityDescriptor (%s) sets for secinfo: "
1067
1130
                        "0x%08x, access_mask: 0x%08x\n",
1068
1131
                        test, sec_info, access_mask);
1069
1132
 
1070
 
        if (!_test_OpenKey(p, tctx, handle, key,
1071
 
                           access_mask,
1072
 
                           &new_handle,
1073
 
                           WERR_OK,
1074
 
                           &open_success)) {
1075
 
                return false;
1076
 
        }
1077
 
 
1078
 
        if (!open_success) {
1079
 
                printf("key did not open\n");
1080
 
                test_CloseKey(p, tctx, &new_handle);
1081
 
                return false;
1082
 
        }
 
1133
        torture_assert(tctx,
 
1134
                test_OpenKey_opts(tctx, b, handle, key,
 
1135
                                  REG_OPTION_NON_VOLATILE,
 
1136
                                  access_mask,
 
1137
                                  &new_handle,
 
1138
                                  WERR_OK),
 
1139
                "failed to open key");
1083
1140
 
1084
1141
        if (!_test_SetKeySecurity(p, tctx, &new_handle, &sec_info,
1085
1142
                                  sd,
1088
1145
                                "SetKeySecurity with secinfo: 0x%08x has failed\n",
1089
1146
                                sec_info);
1090
1147
                smb_panic("");
1091
 
                test_CloseKey(p, tctx, &new_handle);
 
1148
                test_CloseKey(b, tctx, &new_handle);
1092
1149
                return false;
1093
1150
        }
1094
1151
 
1095
 
        test_CloseKey(p, tctx, &new_handle);
 
1152
        test_CloseKey(b, tctx, &new_handle);
1096
1153
 
1097
1154
        if (W_ERROR_IS_OK(set_werr)) {
1098
1155
                bool present;
1254
1311
                                        sec_info_owner_tests[i].fn,
1255
1312
                                        sid))
1256
1313
                        {
1257
 
                                printf("test_SetSecurityDescriptor_SecInfo failed for OWNER\n");
 
1314
                                torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for OWNER\n");
1258
1315
                                ret = false;
1259
1316
                                goto out;
1260
1317
                        }
1278
1335
                                        sec_info_group_tests[i].fn,
1279
1336
                                        sid))
1280
1337
                        {
1281
 
                                printf("test_SetSecurityDescriptor_SecInfo failed for GROUP\n");
 
1338
                                torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for GROUP\n");
1282
1339
                                ret = false;
1283
1340
                                goto out;
1284
1341
                        }
1302
1359
                                        sec_info_dacl_tests[i].fn,
1303
1360
                                        sid))
1304
1361
                        {
1305
 
                                printf("test_SetSecurityDescriptor_SecInfo failed for DACL\n");
 
1362
                                torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for DACL\n");
1306
1363
                                ret = false;
1307
1364
                                goto out;
1308
1365
                        }
1326
1383
                                        sec_info_sacl_tests[i].fn,
1327
1384
                                        sid))
1328
1385
                        {
1329
 
                                printf("test_SetSecurityDescriptor_SecInfo failed for SACL\n");
 
1386
                                torture_comment(tctx, "test_SetSecurityDescriptor_SecInfo failed for SACL\n");
1330
1387
                                ret = false;
1331
1388
                                goto out;
1332
1389
                        }
1347
1404
        bool ret = true;
1348
1405
 
1349
1406
        if (!test_SecurityDescriptor(p, tctx, handle, key)) {
1350
 
                printf("test_SecurityDescriptor failed\n");
 
1407
                torture_comment(tctx, "test_SecurityDescriptor failed\n");
1351
1408
                ret = false;
1352
1409
        }
1353
1410
 
1354
1411
        if (!test_SecurityDescriptorInheritance(p, tctx, handle, key)) {
1355
 
                printf("test_SecurityDescriptorInheritance failed\n");
 
1412
                torture_comment(tctx, "test_SecurityDescriptorInheritance failed\n");
1356
1413
                ret = false;
1357
1414
        }
1358
1415
 
1359
1416
        if (!test_SecurityDescriptorBlockInheritance(p, tctx, handle, key)) {
1360
 
                printf("test_SecurityDescriptorBlockInheritance failed\n");
 
1417
                torture_comment(tctx, "test_SecurityDescriptorBlockInheritance failed\n");
1361
1418
                ret = false;
1362
1419
        }
1363
1420
 
1364
1421
        if (!test_SecurityDescriptorsSecInfo(p, tctx, handle, key)) {
1365
 
                printf("test_SecurityDescriptorsSecInfo failed\n");
 
1422
                torture_comment(tctx, "test_SecurityDescriptorsSecInfo failed\n");
1366
1423
                ret = false;
1367
1424
        }
1368
1425
 
1369
1426
        if (!test_SecurityDescriptorsMasks(p, tctx, handle, key)) {
1370
 
                printf("test_SecurityDescriptorsMasks failed\n");
 
1427
                torture_comment(tctx, "test_SecurityDescriptorsMasks failed\n");
1371
1428
                ret = false;
1372
1429
        }
1373
1430
 
1374
1431
        return ret;
1375
1432
}
1376
1433
 
1377
 
static bool test_DeleteKey(struct dcerpc_pipe *p, struct torture_context *tctx,
 
1434
static bool test_DeleteKey_opts(struct dcerpc_binding_handle *b,
 
1435
                                struct torture_context *tctx,
 
1436
                                struct policy_handle *handle,
 
1437
                                const char *key,
 
1438
                                WERROR expected_result)
 
1439
{
 
1440
        struct winreg_DeleteKey r;
 
1441
 
 
1442
        torture_comment(tctx, "Testing DeleteKey(%s)\n", key);
 
1443
 
 
1444
        r.in.handle = handle;
 
1445
        init_winreg_String(&r.in.key, key);
 
1446
 
 
1447
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_DeleteKey_r(b, tctx, &r),
 
1448
                "Delete Key failed");
 
1449
        torture_assert_werr_equal(tctx, r.out.result, expected_result,
 
1450
                "DeleteKey failed");
 
1451
 
 
1452
        return true;
 
1453
}
 
1454
 
 
1455
static bool test_DeleteKey(struct dcerpc_binding_handle *b,
 
1456
                           struct torture_context *tctx,
1378
1457
                           struct policy_handle *handle, const char *key)
1379
1458
{
1380
 
        NTSTATUS status;
1381
 
        struct winreg_DeleteKey r;
1382
 
 
1383
 
        r.in.handle = handle;
1384
 
        init_winreg_String(&r.in.key, key);
1385
 
 
1386
 
        status = dcerpc_winreg_DeleteKey(p, tctx, &r);
1387
 
 
1388
 
        torture_assert_ntstatus_ok(tctx, status, "DeleteKey failed");
1389
 
        torture_assert_werr_ok(tctx, r.out.result, "DeleteKey failed");
1390
 
 
1391
 
        return true;
 
1459
        return test_DeleteKey_opts(b, tctx, handle, key, WERR_OK);
1392
1460
}
1393
1461
 
1394
 
static bool test_QueryInfoKey(struct dcerpc_pipe *p,
 
1462
static bool test_QueryInfoKey(struct dcerpc_binding_handle *b,
1395
1463
                              struct torture_context *tctx,
1396
 
                              struct policy_handle *handle, char *kclass)
 
1464
                              struct policy_handle *handle,
 
1465
                              char *kclass,
 
1466
                              uint32_t *pmax_valnamelen,
 
1467
                              uint32_t *pmax_valbufsize)
1397
1468
{
1398
1469
        struct winreg_QueryInfoKey r;
1399
1470
        uint32_t num_subkeys, max_subkeylen, max_classlen,
1418
1489
        init_winreg_String(r.in.classname, kclass);
1419
1490
 
1420
1491
        torture_assert_ntstatus_ok(tctx,
1421
 
                                   dcerpc_winreg_QueryInfoKey(p, tctx, &r),
 
1492
                                   dcerpc_winreg_QueryInfoKey_r(b, tctx, &r),
1422
1493
                                   "QueryInfoKey failed");
1423
1494
 
1424
1495
        torture_assert_werr_ok(tctx, r.out.result, "QueryInfoKey failed");
1425
1496
 
 
1497
        if (pmax_valnamelen) {
 
1498
                *pmax_valnamelen = max_valnamelen;
 
1499
        }
 
1500
 
 
1501
        if (pmax_valbufsize) {
 
1502
                *pmax_valbufsize = max_valbufsize;
 
1503
        }
 
1504
 
 
1505
        return true;
 
1506
}
 
1507
 
 
1508
static bool test_SetValue(struct dcerpc_binding_handle *b,
 
1509
                          struct torture_context *tctx,
 
1510
                          struct policy_handle *handle,
 
1511
                          const char *value_name,
 
1512
                          enum winreg_Type type,
 
1513
                          uint8_t *data,
 
1514
                          uint32_t size)
 
1515
{
 
1516
        struct winreg_SetValue r;
 
1517
        struct winreg_String name;
 
1518
 
 
1519
        torture_comment(tctx, "Testing SetValue(%s), type: %s, offered: 0x%08x)\n",
 
1520
                value_name, str_regtype(type), size);
 
1521
 
 
1522
        init_winreg_String(&name, value_name);
 
1523
 
 
1524
        r.in.handle = handle;
 
1525
        r.in.name = name;
 
1526
        r.in.type = type;
 
1527
        r.in.data = data;
 
1528
        r.in.size = size;
 
1529
 
 
1530
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_SetValue_r(b, tctx, &r),
 
1531
                "winreg_SetValue failed");
 
1532
        torture_assert_werr_ok(tctx, r.out.result,
 
1533
                "winreg_SetValue failed");
 
1534
 
 
1535
        return true;
 
1536
}
 
1537
 
 
1538
static bool test_DeleteValue(struct dcerpc_binding_handle *b,
 
1539
                             struct torture_context *tctx,
 
1540
                             struct policy_handle *handle,
 
1541
                             const char *value_name)
 
1542
{
 
1543
        struct winreg_DeleteValue r;
 
1544
        struct winreg_String value;
 
1545
 
 
1546
        torture_comment(tctx, "Testing DeleteValue(%s)\n", value_name);
 
1547
 
 
1548
        init_winreg_String(&value, value_name);
 
1549
 
 
1550
        r.in.handle = handle;
 
1551
        r.in.value = value;
 
1552
 
 
1553
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_DeleteValue_r(b, tctx, &r),
 
1554
                "winreg_DeleteValue failed");
 
1555
        torture_assert_werr_ok(tctx, r.out.result,
 
1556
                "winreg_DeleteValue failed");
 
1557
 
1426
1558
        return true;
1427
1559
}
1428
1560
 
1438
1570
        struct winreg_StringBuf kclass, name;
1439
1571
        NTSTATUS status;
1440
1572
        NTTIME t = 0;
 
1573
        struct dcerpc_binding_handle *b = p->binding_handle;
1441
1574
 
1442
1575
        kclass.name   = "";
1443
1576
        kclass.size   = 1024;
1454
1587
                name.name   = NULL;
1455
1588
                name.size   = 1024;
1456
1589
 
1457
 
                status = dcerpc_winreg_EnumKey(p, tctx, &r);
 
1590
                status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
1458
1591
 
1459
1592
                if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
1460
1593
                        struct policy_handle key_handle;
1463
1596
                                        r.in.enum_index,
1464
1597
                                        r.out.name->name);
1465
1598
 
1466
 
                        if (!test_OpenKey(p, tctx, handle, r.out.name->name,
 
1599
                        if (!test_OpenKey(b, tctx, handle, r.out.name->name,
1467
1600
                                          &key_handle)) {
1468
1601
                        } else {
1469
1602
                                test_key(p, tctx, &key_handle,
1485
1618
        return true;
1486
1619
}
1487
1620
 
1488
 
static bool test_QueryMultipleValues(struct dcerpc_pipe *p,
 
1621
static bool test_QueryMultipleValues(struct dcerpc_binding_handle *b,
1489
1622
                                     struct torture_context *tctx,
1490
1623
                                     struct policy_handle *handle,
1491
1624
                                     const char *valuename)
1492
1625
{
1493
1626
        struct winreg_QueryMultipleValues r;
1494
 
        NTSTATUS status;
1495
1627
        uint32_t bufsize=0;
1496
1628
 
1497
1629
        ZERO_STRUCT(r);
 
1630
 
1498
1631
        r.in.key_handle = handle;
1499
 
        r.in.values = r.out.values = talloc_array(tctx, struct QueryMultipleValue, 1);
1500
 
        r.in.values[0].name = talloc(tctx, struct winreg_String);
1501
 
        r.in.values[0].name->name = valuename;
1502
 
        r.in.values[0].offset = 0;
1503
 
        r.in.values[0].length = 0;
1504
 
        r.in.values[0].type = 0;
 
1632
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 1);
 
1633
        r.in.values_in[0].ve_valuename = talloc(tctx, struct winreg_ValNameBuf);
 
1634
        r.in.values_in[0].ve_valuename->name = valuename;
 
1635
        /* size needs to be set manually for winreg_ValNameBuf */
 
1636
        r.in.values_in[0].ve_valuename->size = strlen_m_term(valuename)*2;
1505
1637
 
1506
1638
        r.in.num_values = 1;
1507
1639
        r.in.buffer_size = r.out.buffer_size = talloc(tctx, uint32_t);
1511
1643
                r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t,
1512
1644
                                                               *r.in.buffer_size);
1513
1645
 
1514
 
                status = dcerpc_winreg_QueryMultipleValues(p, tctx, &r);
1515
 
 
1516
 
                if(NT_STATUS_IS_ERR(status))
1517
 
                        torture_fail(tctx, "QueryMultipleValues failed");
 
1646
                torture_assert_ntstatus_ok(tctx,
 
1647
                        dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
 
1648
                        "QueryMultipleValues failed");
1518
1649
 
1519
1650
                talloc_free(r.in.buffer);
1520
1651
                bufsize += 0x20;
1525
1656
        return true;
1526
1657
}
1527
1658
 
1528
 
static bool test_QueryValue(struct dcerpc_pipe *p,
 
1659
static bool test_QueryMultipleValues_full(struct dcerpc_binding_handle *b,
 
1660
                                          struct torture_context *tctx,
 
1661
                                          struct policy_handle *handle,
 
1662
                                          uint32_t num_values,
 
1663
                                          const char * const *valuenames,
 
1664
                                          bool existing_value)
 
1665
{
 
1666
        struct winreg_QueryMultipleValues r;
 
1667
        uint32_t bufsize = 0;
 
1668
        int i;
 
1669
 
 
1670
        torture_comment(tctx, "Testing QueryMultipleValues\n");
 
1671
 
 
1672
        ZERO_STRUCT(r);
 
1673
 
 
1674
        r.in.key_handle = handle;
 
1675
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 0);
 
1676
        r.in.buffer_size = r.out.buffer_size = &bufsize;
 
1677
 
 
1678
        torture_assert_ntstatus_ok(tctx,
 
1679
                dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
 
1680
                "QueryMultipleValues failed");
 
1681
        torture_assert_werr_ok(tctx, r.out.result,
 
1682
                "QueryMultipleValues failed");
 
1683
 
 
1684
        /* this test crashes w2k8 remote registry */
 
1685
#if 0
 
1686
        r.in.num_values = num_values;
 
1687
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
 
1688
 
 
1689
        torture_assert_ntstatus_ok(tctx,
 
1690
                dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
 
1691
                "QueryMultipleValues failed");
 
1692
        torture_assert_werr_ok(tctx, r.out.result,
 
1693
                "QueryMultipleValues failed");
 
1694
#endif
 
1695
        r.in.num_values = num_values;
 
1696
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
 
1697
        for (i=0; i < r.in.num_values; i++) {
 
1698
                r.in.values_in[i].ve_valuename = talloc_zero(tctx, struct winreg_ValNameBuf);
 
1699
                r.in.values_in[i].ve_valuename->name = talloc_strdup(tctx, valuenames[i]);
 
1700
                r.in.values_in[i].ve_valuename->size = strlen_m_term(r.in.values_in[i].ve_valuename->name)*2;
 
1701
        }
 
1702
 
 
1703
        torture_assert_ntstatus_ok(tctx,
 
1704
                dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
 
1705
                "QueryMultipleValues failed");
 
1706
        torture_assert_werr_equal(tctx, r.out.result, existing_value ? WERR_MORE_DATA : WERR_BADFILE,
 
1707
                "QueryMultipleValues failed");
 
1708
 
 
1709
        if (W_ERROR_EQUAL(r.out.result, WERR_BADFILE)) {
 
1710
                return true;
 
1711
        }
 
1712
 
 
1713
        if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
 
1714
                *r.in.buffer_size = 0xff;
 
1715
                r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.buffer_size);
 
1716
 
 
1717
                torture_assert_ntstatus_ok(tctx,
 
1718
                        dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
 
1719
                        "QueryMultipleValues failed");
 
1720
        }
 
1721
 
 
1722
        torture_assert_werr_ok(tctx, r.out.result,
 
1723
                "QueryMultipleValues failed");
 
1724
 
 
1725
        return true;
 
1726
}
 
1727
 
 
1728
 
 
1729
static bool test_QueryMultipleValues2_full(struct dcerpc_binding_handle *b,
 
1730
                                           struct torture_context *tctx,
 
1731
                                           struct policy_handle *handle,
 
1732
                                           uint32_t num_values,
 
1733
                                           const char * const *valuenames,
 
1734
                                           bool existing_value)
 
1735
{
 
1736
        struct winreg_QueryMultipleValues2 r;
 
1737
        uint32_t offered = 0, needed;
 
1738
        int i;
 
1739
 
 
1740
        torture_comment(tctx, "Testing QueryMultipleValues2\n");
 
1741
 
 
1742
        ZERO_STRUCT(r);
 
1743
 
 
1744
        r.in.key_handle = handle;
 
1745
        r.in.offered = &offered;
 
1746
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 0);
 
1747
        r.out.needed = &needed;
 
1748
 
 
1749
        torture_assert_ntstatus_ok(tctx,
 
1750
                dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
 
1751
                "QueryMultipleValues2 failed");
 
1752
        torture_assert_werr_ok(tctx, r.out.result,
 
1753
                "QueryMultipleValues2 failed");
 
1754
 
 
1755
        /* this test crashes w2k8 remote registry */
 
1756
#if 0
 
1757
        r.in.num_values = num_values;
 
1758
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
 
1759
 
 
1760
        torture_assert_ntstatus_ok(tctx,
 
1761
                dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
 
1762
                "QueryMultipleValues2 failed");
 
1763
        torture_assert_werr_ok(tctx, r.out.result,
 
1764
                "QueryMultipleValues2 failed");
 
1765
#endif
 
1766
        r.in.num_values = num_values;
 
1767
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
 
1768
        for (i=0; i < r.in.num_values; i++) {
 
1769
                r.in.values_in[i].ve_valuename = talloc_zero(tctx, struct winreg_ValNameBuf);
 
1770
                r.in.values_in[i].ve_valuename->name = talloc_strdup(tctx, valuenames[i]);
 
1771
                r.in.values_in[i].ve_valuename->size = strlen_m_term(r.in.values_in[i].ve_valuename->name)*2;
 
1772
        }
 
1773
 
 
1774
        torture_assert_ntstatus_ok(tctx,
 
1775
                dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
 
1776
                "QueryMultipleValues2 failed");
 
1777
        torture_assert_werr_equal(tctx, r.out.result, existing_value ? WERR_MORE_DATA : WERR_BADFILE,
 
1778
                "QueryMultipleValues2 failed");
 
1779
 
 
1780
        if (W_ERROR_EQUAL(r.out.result, WERR_BADFILE)) {
 
1781
                return true;
 
1782
        }
 
1783
 
 
1784
        if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
 
1785
                *r.in.offered = *r.out.needed;
 
1786
                r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.offered);
 
1787
 
 
1788
                torture_assert_ntstatus_ok(tctx,
 
1789
                        dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
 
1790
                        "QueryMultipleValues2 failed");
 
1791
        }
 
1792
 
 
1793
        torture_assert_werr_ok(tctx, r.out.result,
 
1794
                "QueryMultipleValues2 failed");
 
1795
 
 
1796
        return true;
 
1797
}
 
1798
 
 
1799
static bool test_QueryMultipleValues2(struct dcerpc_binding_handle *b,
 
1800
                                      struct torture_context *tctx,
 
1801
                                      struct policy_handle *handle,
 
1802
                                      const char *valuename)
 
1803
{
 
1804
        struct winreg_QueryMultipleValues2 r;
 
1805
        uint32_t offered = 0, needed;
 
1806
 
 
1807
        ZERO_STRUCT(r);
 
1808
 
 
1809
        r.in.key_handle = handle;
 
1810
        r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 1);
 
1811
        r.in.values_in[0].ve_valuename = talloc(tctx, struct winreg_ValNameBuf);
 
1812
        r.in.values_in[0].ve_valuename->name = valuename;
 
1813
        /* size needs to be set manually for winreg_ValNameBuf */
 
1814
        r.in.values_in[0].ve_valuename->size = strlen_m_term(valuename)*2;
 
1815
 
 
1816
        r.in.num_values = 1;
 
1817
        r.in.offered = &offered;
 
1818
        r.out.needed = &needed;
 
1819
 
 
1820
        torture_assert_ntstatus_ok(tctx,
 
1821
                dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
 
1822
                "QueryMultipleValues2 failed");
 
1823
        if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
 
1824
                *r.in.offered = *r.out.needed;
 
1825
                r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.offered);
 
1826
 
 
1827
                torture_assert_ntstatus_ok(tctx,
 
1828
                        dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
 
1829
                        "QueryMultipleValues2 failed");
 
1830
        }
 
1831
 
 
1832
        torture_assert_werr_ok(tctx, r.out.result,
 
1833
                "QueryMultipleValues2 failed");
 
1834
 
 
1835
        return true;
 
1836
}
 
1837
 
 
1838
static bool test_QueryValue(struct dcerpc_binding_handle *b,
1529
1839
                            struct torture_context *tctx,
1530
1840
                            struct policy_handle *handle,
1531
1841
                            const char *valuename)
1545
1855
        r.in.data_size = &offered;
1546
1856
        r.in.data_length = &zero;
1547
1857
 
1548
 
        status = dcerpc_winreg_QueryValue(p, tctx, &r);
 
1858
        status = dcerpc_winreg_QueryValue_r(b, tctx, &r);
1549
1859
        if (NT_STATUS_IS_ERR(status)) {
1550
1860
                torture_fail(tctx, "QueryValue failed");
1551
1861
        }
1555
1865
        return true;
1556
1866
}
1557
1867
 
1558
 
static bool test_EnumValue(struct dcerpc_pipe *p, struct torture_context *tctx,
 
1868
static bool test_QueryValue_full(struct dcerpc_binding_handle *b,
 
1869
                                 struct torture_context *tctx,
 
1870
                                 struct policy_handle *handle,
 
1871
                                 const char *valuename,
 
1872
                                 bool existing_value)
 
1873
{
 
1874
        struct winreg_QueryValue r;
 
1875
        struct winreg_String value_name;
 
1876
        enum winreg_Type type = REG_NONE;
 
1877
        uint32_t data_size = 0;
 
1878
        uint32_t real_data_size = 0;
 
1879
        uint32_t data_length = 0;
 
1880
        uint8_t *data = NULL;
 
1881
        WERROR expected_error = WERR_BADFILE;
 
1882
        const char *errmsg_nonexisting = "expected WERR_BADFILE for nonexisting value";
 
1883
 
 
1884
        if (valuename == NULL) {
 
1885
                expected_error = WERR_INVALID_PARAM;
 
1886
                errmsg_nonexisting = "expected WERR_INVALID_PARAM for NULL valuename";
 
1887
        }
 
1888
 
 
1889
        ZERO_STRUCT(r);
 
1890
 
 
1891
        init_winreg_String(&value_name, NULL);
 
1892
 
 
1893
        torture_comment(tctx, "Testing QueryValue(%s)\n", valuename);
 
1894
 
 
1895
        r.in.handle = handle;
 
1896
        r.in.value_name = &value_name;
 
1897
 
 
1898
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
 
1899
        torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
 
1900
                "expected WERR_INVALID_PARAM for NULL winreg_String.name");
 
1901
 
 
1902
        init_winreg_String(&value_name, valuename);
 
1903
        r.in.value_name = &value_name;
 
1904
 
 
1905
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
 
1906
                "QueryValue failed");
 
1907
        torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
 
1908
                "expected WERR_INVALID_PARAM for missing type length and size");
 
1909
 
 
1910
        r.in.type = &type;
 
1911
        r.out.type = &type;
 
1912
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
 
1913
                "QueryValue failed");
 
1914
        torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
 
1915
                "expected WERR_INVALID_PARAM for missing length and size");
 
1916
 
 
1917
        r.in.data_length = &data_length;
 
1918
        r.out.data_length = &data_length;
 
1919
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
 
1920
                "QueryValue failed");
 
1921
        torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
 
1922
                "expected WERR_INVALID_PARAM for missing size");
 
1923
 
 
1924
        r.in.data_size = &data_size;
 
1925
        r.out.data_size = &data_size;
 
1926
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
 
1927
                "QueryValue failed");
 
1928
        if (existing_value) {
 
1929
                torture_assert_werr_ok(tctx, r.out.result,
 
1930
                        "QueryValue failed");
 
1931
        } else {
 
1932
                torture_assert_werr_equal(tctx, r.out.result, expected_error,
 
1933
                        errmsg_nonexisting);
 
1934
        }
 
1935
 
 
1936
        real_data_size = *r.out.data_size;
 
1937
 
 
1938
        data = talloc_zero_array(tctx, uint8_t, 0);
 
1939
        r.in.data = data;
 
1940
        r.out.data = data;
 
1941
        *r.in.data_size = 0;
 
1942
        *r.out.data_size = 0;
 
1943
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
 
1944
                "QueryValue failed");
 
1945
        if (existing_value) {
 
1946
                torture_assert_werr_equal(tctx, r.out.result, WERR_MORE_DATA,
 
1947
                        "expected WERR_MORE_DATA for query with too small buffer");
 
1948
        } else {
 
1949
                torture_assert_werr_equal(tctx, r.out.result, expected_error,
 
1950
                        errmsg_nonexisting);
 
1951
        }
 
1952
 
 
1953
        data = talloc_zero_array(tctx, uint8_t, real_data_size);
 
1954
        r.in.data = data;
 
1955
        r.out.data = data;
 
1956
        r.in.data_size = &real_data_size;
 
1957
        r.out.data_size = &real_data_size;
 
1958
        torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r),
 
1959
                "QueryValue failed");
 
1960
        if (existing_value) {
 
1961
                torture_assert_werr_ok(tctx, r.out.result,
 
1962
                        "QueryValue failed");
 
1963
        } else {
 
1964
                torture_assert_werr_equal(tctx, r.out.result, expected_error,
 
1965
                        errmsg_nonexisting);
 
1966
        }
 
1967
 
 
1968
        return true;
 
1969
}
 
1970
 
 
1971
static bool test_EnumValue(struct dcerpc_binding_handle *b,
 
1972
                           struct torture_context *tctx,
1559
1973
                           struct policy_handle *handle, int max_valnamelen,
1560
1974
                           int max_valbufsize)
1561
1975
{
1563
1977
        enum winreg_Type type = 0;
1564
1978
        uint32_t size = max_valbufsize, zero = 0;
1565
1979
        bool ret = true;
1566
 
        uint8_t buf8;
 
1980
        uint8_t *data = NULL;
1567
1981
        struct winreg_ValNameBuf name;
1568
 
 
1569
 
        name.name   = "";
1570
 
        name.size   = 1024;
 
1982
        char n = '\0';
1571
1983
 
1572
1984
        ZERO_STRUCT(r);
1573
1985
        r.in.handle = handle;
1575
1987
        r.in.name = &name;
1576
1988
        r.out.name = &name;
1577
1989
        r.in.type = &type;
1578
 
        r.in.value = &buf8;
1579
1990
        r.in.length = &zero;
1580
1991
        r.in.size = &size;
1581
1992
 
1582
1993
        do {
 
1994
                name.name = &n;
 
1995
                name.size = max_valnamelen + 2;
 
1996
                name.length = 0;
 
1997
 
 
1998
                data = NULL;
 
1999
                if (size) {
 
2000
                        data = (uint8_t *) talloc_array(tctx, uint8_t *, size);
 
2001
                }
 
2002
                r.in.value = data;
 
2003
 
1583
2004
                torture_assert_ntstatus_ok(tctx,
1584
 
                                           dcerpc_winreg_EnumValue(p, tctx, &r),
 
2005
                                           dcerpc_winreg_EnumValue_r(b, tctx, &r),
1585
2006
                                           "EnumValue failed");
1586
2007
 
1587
2008
                if (W_ERROR_IS_OK(r.out.result)) {
1588
 
                        ret &= test_QueryValue(p, tctx, handle,
 
2009
                        ret &= test_QueryValue(b, tctx, handle,
1589
2010
                                               r.out.name->name);
1590
 
                        ret &= test_QueryMultipleValues(p, tctx, handle,
 
2011
                        ret &= test_QueryMultipleValues(b, tctx, handle,
1591
2012
                                                        r.out.name->name);
 
2013
                        ret &= test_QueryMultipleValues2(b, tctx, handle,
 
2014
                                                         r.out.name->name);
1592
2015
                }
1593
2016
 
 
2017
                talloc_free(data);
 
2018
 
1594
2019
                r.in.enum_index++;
1595
2020
        } while (W_ERROR_IS_OK(r.out.result));
1596
2021
 
1600
2025
        return ret;
1601
2026
}
1602
2027
 
1603
 
static bool test_AbortSystemShutdown(struct dcerpc_pipe *p,
 
2028
static bool test_AbortSystemShutdown(struct dcerpc_binding_handle *b,
1604
2029
                                     struct torture_context *tctx)
1605
2030
{
1606
2031
        struct winreg_AbortSystemShutdown r;
1610
2035
        r.in.server = &server;
1611
2036
 
1612
2037
        torture_assert_ntstatus_ok(tctx,
1613
 
                                   dcerpc_winreg_AbortSystemShutdown(p, tctx, &r),
 
2038
                                   dcerpc_winreg_AbortSystemShutdown_r(b, tctx, &r),
1614
2039
                                   "AbortSystemShutdown failed");
1615
2040
 
1616
2041
        torture_assert_werr_ok(tctx, r.out.result,
1624
2049
{
1625
2050
        struct winreg_InitiateSystemShutdown r;
1626
2051
        uint16_t hostname = 0x0;
 
2052
        struct dcerpc_binding_handle *b = p->binding_handle;
1627
2053
 
1628
2054
        ZERO_STRUCT(r);
1629
2055
        r.in.hostname = &hostname;
1634
2060
        r.in.do_reboot = 1;
1635
2061
 
1636
2062
        torture_assert_ntstatus_ok(tctx,
1637
 
                                   dcerpc_winreg_InitiateSystemShutdown(p, tctx, &r),
 
2063
                                   dcerpc_winreg_InitiateSystemShutdown_r(b, tctx, &r),
1638
2064
                                   "InitiateSystemShutdown failed");
1639
2065
 
1640
2066
        torture_assert_werr_ok(tctx, r.out.result,
1641
2067
                               "InitiateSystemShutdown failed");
1642
2068
 
1643
 
        return test_AbortSystemShutdown(p, tctx);
 
2069
        return test_AbortSystemShutdown(b, tctx);
1644
2070
}
1645
2071
 
1646
2072
 
1649
2075
{
1650
2076
        struct winreg_InitiateSystemShutdownEx r;
1651
2077
        uint16_t hostname = 0x0;
 
2078
        struct dcerpc_binding_handle *b = p->binding_handle;
1652
2079
 
1653
2080
        ZERO_STRUCT(r);
1654
2081
        r.in.hostname = &hostname;
1660
2087
        r.in.reason = 0;
1661
2088
 
1662
2089
        torture_assert_ntstatus_ok(tctx,
1663
 
                dcerpc_winreg_InitiateSystemShutdownEx(p, tctx, &r),
 
2090
                dcerpc_winreg_InitiateSystemShutdownEx_r(b, tctx, &r),
1664
2091
                "InitiateSystemShutdownEx failed");
1665
2092
 
1666
2093
        torture_assert_werr_ok(tctx, r.out.result,
1667
2094
                               "InitiateSystemShutdownEx failed");
1668
2095
 
1669
 
        return test_AbortSystemShutdown(p, tctx);
 
2096
        return test_AbortSystemShutdown(b, tctx);
1670
2097
}
1671
2098
#define MAX_DEPTH 2             /* Only go this far down the tree */
1672
2099
 
1674
2101
                     struct policy_handle *handle, int depth,
1675
2102
                     bool test_security)
1676
2103
{
 
2104
        struct dcerpc_binding_handle *b = p->binding_handle;
 
2105
        uint32_t max_valnamelen = 0;
 
2106
        uint32_t max_valbufsize = 0;
 
2107
 
1677
2108
        if (depth == MAX_DEPTH)
1678
2109
                return true;
1679
2110
 
1680
 
        if (!test_QueryInfoKey(p, tctx, handle, NULL)) {
 
2111
        if (!test_QueryInfoKey(b, tctx, handle, NULL,
 
2112
                               &max_valnamelen, &max_valbufsize)) {
1681
2113
        }
1682
2114
 
1683
 
        if (!test_NotifyChangeKeyValue(p, tctx, handle)) {
 
2115
        if (!test_NotifyChangeKeyValue(b, tctx, handle)) {
1684
2116
        }
1685
2117
 
1686
2118
        if (test_security && !test_GetKeySecurity(p, tctx, handle, NULL)) {
1689
2121
        if (!test_EnumKey(p, tctx, handle, depth, test_security)) {
1690
2122
        }
1691
2123
 
1692
 
        if (!test_EnumValue(p, tctx, handle, 0xFF, 0xFFFF)) {
1693
 
        }
1694
 
 
1695
 
        test_CloseKey(p, tctx, handle);
1696
 
 
1697
 
        return true;
1698
 
}
1699
 
 
1700
 
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
1701
 
 
1702
 
static bool test_Open_Security(struct torture_context *tctx,
1703
 
                               struct dcerpc_pipe *p, void *userdata)
1704
 
{
1705
 
        struct policy_handle handle, newhandle;
1706
 
        bool ret = true, created2 = false;
1707
 
        bool created4 = false;
 
2124
        if (!test_EnumValue(b, tctx, handle, max_valnamelen, max_valbufsize)) {
 
2125
        }
 
2126
 
 
2127
        if (!test_EnumValue(b, tctx, handle, max_valnamelen, 0xFFFF)) {
 
2128
        }
 
2129
 
 
2130
        test_CloseKey(b, tctx, handle);
 
2131
 
 
2132
        return true;
 
2133
}
 
2134
 
 
2135
static bool test_SetValue_simple(struct dcerpc_binding_handle *b,
 
2136
                                 struct torture_context *tctx,
 
2137
                                 struct policy_handle *handle)
 
2138
{
 
2139
        const char *value_name = TEST_VALUE;
 
2140
        uint32_t value = 0x12345678;
 
2141
        uint64_t value2 = 0x12345678;
 
2142
        const char *string = "torture";
 
2143
        const char *array[2];
 
2144
        DATA_BLOB blob;
 
2145
        enum winreg_Type types[] = {
 
2146
                REG_DWORD,
 
2147
                REG_DWORD_BIG_ENDIAN,
 
2148
                REG_QWORD,
 
2149
                REG_BINARY,
 
2150
                REG_SZ,
 
2151
                REG_MULTI_SZ
 
2152
        };
 
2153
        int t;
 
2154
 
 
2155
        array[0] = "array0";
 
2156
        array[1] = NULL;
 
2157
 
 
2158
        torture_comment(tctx, "Testing SetValue (standard formats)\n");
 
2159
 
 
2160
        for (t=0; t < ARRAY_SIZE(types); t++) {
 
2161
 
 
2162
                enum winreg_Type w_type;
 
2163
                uint32_t w_size, w_length;
 
2164
                uint8_t *w_data;
 
2165
 
 
2166
                switch (types[t]) {
 
2167
                case REG_DWORD:
 
2168
                case REG_DWORD_BIG_ENDIAN:
 
2169
                        blob = data_blob_talloc_zero(tctx, 4);
 
2170
                        SIVAL(blob.data, 0, value);
 
2171
                        break;
 
2172
                case REG_QWORD:
 
2173
                        blob = data_blob_talloc_zero(tctx, 8);
 
2174
                        SBVAL(blob.data, 0, value2);
 
2175
                        break;
 
2176
                case REG_BINARY:
 
2177
                        blob = data_blob_string_const("binary_blob");
 
2178
                        break;
 
2179
                case REG_SZ:
 
2180
                        torture_assert(tctx, push_reg_sz(tctx, &blob, string), "failed to push REG_SZ");
 
2181
                        break;
 
2182
                case REG_MULTI_SZ:
 
2183
                        torture_assert(tctx, push_reg_multi_sz(tctx, &blob, array), "failed to push REG_MULTI_SZ");
 
2184
                        break;
 
2185
                default:
 
2186
                        break;
 
2187
                }
 
2188
 
 
2189
                torture_assert(tctx,
 
2190
                        test_SetValue(b, tctx, handle, value_name, types[t], blob.data, blob.length),
 
2191
                        "test_SetValue failed");
 
2192
                torture_assert(tctx,
 
2193
                        test_QueryValue_full(b, tctx, handle, value_name, true),
 
2194
                        talloc_asprintf(tctx, "test_QueryValue_full for %s value failed", value_name));
 
2195
                torture_assert(tctx,
 
2196
                        test_winreg_QueryValue(tctx, b, handle, value_name, &w_type, &w_size, &w_length, &w_data),
 
2197
                        "test_winreg_QueryValue failed");
 
2198
                torture_assert(tctx,
 
2199
                        test_DeleteValue(b, tctx, handle, value_name),
 
2200
                        "test_DeleteValue failed");
 
2201
 
 
2202
                torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
 
2203
                torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
 
2204
                torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
 
2205
                torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
 
2206
        }
 
2207
 
 
2208
        torture_comment(tctx, "Testing SetValue (standard formats) succeeded\n");
 
2209
 
 
2210
        return true;
 
2211
}
 
2212
 
 
2213
static bool test_SetValue_values(struct dcerpc_binding_handle *b,
 
2214
                                 struct torture_context *tctx,
 
2215
                                 struct policy_handle *handle)
 
2216
{
 
2217
        DATA_BLOB blob;
 
2218
        const char *values[] = {
 
2219
                "torture_value",
 
2220
                "torture value",
 
2221
                "torture,value",
 
2222
                "torture;value",
 
2223
                "torture/value",
 
2224
                "torture\\value",
 
2225
                "torture_value_name",
 
2226
                "torture value name",
 
2227
                "torture,value,name",
 
2228
                "torture;value;name",
 
2229
                "torture/value/name",
 
2230
                "torture\\value\\name",
 
2231
        };
 
2232
        int i;
 
2233
 
 
2234
        torture_comment(tctx, "Testing SetValue (values)\n");
 
2235
 
 
2236
        for (i=0; i < ARRAY_SIZE(values); i++) {
 
2237
 
 
2238
                enum winreg_Type w_type;
 
2239
                uint32_t w_size, w_length;
 
2240
                uint8_t *w_data;
 
2241
 
 
2242
                blob = data_blob_talloc(tctx, NULL, 32);
 
2243
 
 
2244
                generate_random_buffer(blob.data, 32);
 
2245
 
 
2246
                torture_assert(tctx,
 
2247
                        test_SetValue(b, tctx, handle, values[i], REG_BINARY, blob.data, blob.length),
 
2248
                        "test_SetValue failed");
 
2249
                torture_assert(tctx,
 
2250
                        test_QueryValue_full(b, tctx, handle, values[i], true),
 
2251
                        talloc_asprintf(tctx, "test_QueryValue_full for %s value failed", values[i]));
 
2252
                torture_assert(tctx,
 
2253
                        test_winreg_QueryValue(tctx, b, handle, values[i], &w_type, &w_size, &w_length, &w_data),
 
2254
                        "test_winreg_QueryValue failed");
 
2255
                torture_assert(tctx,
 
2256
                        test_DeleteValue(b, tctx, handle, values[i]),
 
2257
                        "test_DeleteValue failed");
 
2258
 
 
2259
                torture_assert_int_equal(tctx, w_type, REG_BINARY, "winreg type mismatch");
 
2260
                torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
 
2261
                torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
 
2262
                torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
 
2263
        }
 
2264
 
 
2265
        torture_comment(tctx, "Testing SetValue (values) succeeded\n");
 
2266
 
 
2267
        return true;
 
2268
}
 
2269
 
 
2270
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
 
2271
 
 
2272
static bool test_SetValue_extended(struct dcerpc_binding_handle *b,
 
2273
                                   struct torture_context *tctx,
 
2274
                                   struct policy_handle *handle)
 
2275
{
 
2276
        const char *value_name = TEST_VALUE;
 
2277
        enum winreg_Type types[] = {
 
2278
                REG_NONE,
 
2279
                REG_SZ,
 
2280
                REG_EXPAND_SZ,
 
2281
                REG_BINARY,
 
2282
                REG_DWORD,
 
2283
                REG_DWORD_BIG_ENDIAN,
 
2284
                REG_LINK,
 
2285
                REG_MULTI_SZ,
 
2286
                REG_RESOURCE_LIST,
 
2287
                REG_FULL_RESOURCE_DESCRIPTOR,
 
2288
                REG_RESOURCE_REQUIREMENTS_LIST,
 
2289
                REG_QWORD,
 
2290
                12,
 
2291
                13,
 
2292
                14,
 
2293
                55,
 
2294
                123456,
 
2295
                653210,
 
2296
                __LINE__
 
2297
        };
 
2298
        int t, l;
 
2299
 
 
2300
        if (torture_setting_bool(tctx, "samba4", false)) {
 
2301
                torture_skip(tctx, "skipping extended SetValue test against Samba4");
 
2302
        }
 
2303
 
 
2304
        torture_comment(tctx, "Testing SetValue (extended formats)\n");
 
2305
 
 
2306
        for (t=0; t < ARRAY_SIZE(types); t++) {
 
2307
        for (l=0; l < 16; l++) {
 
2308
 
 
2309
                enum winreg_Type w_type;
 
2310
                uint32_t w_size, w_length;
 
2311
                uint8_t *w_data;
 
2312
 
 
2313
                uint32_t size;
 
2314
                uint8_t *data;
 
2315
 
 
2316
                size = l;
 
2317
                data = talloc_array(tctx, uint8_t, size);
 
2318
 
 
2319
                generate_random_buffer(data, size);
 
2320
 
 
2321
                torture_assert(tctx,
 
2322
                        test_SetValue(b, tctx, handle, value_name, types[t], data, size),
 
2323
                        "test_SetValue failed");
 
2324
 
 
2325
                torture_assert(tctx,
 
2326
                        test_winreg_QueryValue(tctx, b, handle, value_name, &w_type, &w_size, &w_length, &w_data),
 
2327
                        "test_winreg_QueryValue failed");
 
2328
 
 
2329
                torture_assert(tctx,
 
2330
                        test_DeleteValue(b, tctx, handle, value_name),
 
2331
                        "test_DeleteValue failed");
 
2332
 
 
2333
                torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
 
2334
                torture_assert_int_equal(tctx, w_size, size, "winreg size mismatch");
 
2335
                torture_assert_int_equal(tctx, w_length, size, "winreg length mismatch");
 
2336
                torture_assert_mem_equal(tctx, w_data, data, size, "winreg buffer mismatch");
 
2337
        }
 
2338
        }
 
2339
 
 
2340
        torture_comment(tctx, "Testing SetValue (extended formats) succeeded\n");
 
2341
 
 
2342
        return true;
 
2343
}
 
2344
 
 
2345
static bool test_create_keynames(struct dcerpc_binding_handle *b,
 
2346
                                 struct torture_context *tctx,
 
2347
                                 struct policy_handle *handle)
 
2348
{
 
2349
        const char *keys[] = {
 
2350
                "torture_key",
 
2351
                "torture key",
 
2352
                "torture,key",
 
2353
                "torture/key",
 
2354
                "torture\\key",
 
2355
        };
 
2356
        int i;
 
2357
 
 
2358
        for (i=0; i < ARRAY_SIZE(keys); i++) {
 
2359
 
 
2360
                enum winreg_CreateAction action_taken;
 
2361
                struct policy_handle new_handle;
 
2362
                char *q, *tmp;
 
2363
 
 
2364
                torture_assert(tctx,
 
2365
                        test_CreateKey_opts(tctx, b, handle, keys[i], NULL,
 
2366
                                            REG_OPTION_NON_VOLATILE,
 
2367
                                            SEC_FLAG_MAXIMUM_ALLOWED,
 
2368
                                            NULL,
 
2369
                                            WERR_OK,
 
2370
                                            &action_taken,
 
2371
                                            &new_handle),
 
2372
                        talloc_asprintf(tctx, "failed to create '%s' key", keys[i]));
 
2373
 
 
2374
                torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
 
2375
 
 
2376
                torture_assert(tctx,
 
2377
                        test_DeleteKey_opts(b, tctx, handle, keys[i], WERR_OK),
 
2378
                        "failed to delete key");
 
2379
 
 
2380
                torture_assert(tctx,
 
2381
                        test_DeleteKey_opts(b, tctx, handle, keys[i], WERR_BADFILE),
 
2382
                        "failed 2nd delete key");
 
2383
 
 
2384
                tmp = talloc_strdup(tctx, keys[i]);
 
2385
 
 
2386
                q = strchr(tmp, '\\');
 
2387
                if (q != NULL) {
 
2388
                        *q = '\0';
 
2389
                        q++;
 
2390
 
 
2391
                        torture_assert(tctx,
 
2392
                                test_DeleteKey_opts(b, tctx, handle, tmp, WERR_OK),
 
2393
                                "failed to delete key");
 
2394
 
 
2395
                        torture_assert(tctx,
 
2396
                                test_DeleteKey_opts(b, tctx, handle, tmp, WERR_BADFILE),
 
2397
                                "failed 2nd delete key");
 
2398
                }
 
2399
        }
 
2400
 
 
2401
        return true;
 
2402
}
 
2403
 
 
2404
#define KEY_CURRENT_VERSION "SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION"
 
2405
#define VALUE_CURRENT_VERSION "CurrentVersion"
 
2406
#define VALUE_SYSTEM_ROOT "SystemRoot"
 
2407
 
 
2408
static const struct {
 
2409
        const char *values[3];
 
2410
        uint32_t num_values;
 
2411
        bool existing_value;
 
2412
        const char *error_message;
 
2413
} multiple_values_tests[] = {
 
2414
        {
 
2415
                .values = { VALUE_CURRENT_VERSION, NULL, NULL },
 
2416
                .num_values = 1,
 
2417
                .existing_value = true,
 
2418
                .error_message = NULL
 
2419
        },{
 
2420
                .values = { VALUE_SYSTEM_ROOT, NULL, NULL },
 
2421
                .num_values = 1,
 
2422
                .existing_value = true,
 
2423
                .error_message = NULL
 
2424
        },{
 
2425
                .values = { VALUE_CURRENT_VERSION, VALUE_SYSTEM_ROOT, NULL },
 
2426
                .num_values = 2,
 
2427
                .existing_value = true,
 
2428
                .error_message = NULL
 
2429
        },{
 
2430
                .values = { VALUE_CURRENT_VERSION, VALUE_SYSTEM_ROOT,
 
2431
                            VALUE_CURRENT_VERSION },
 
2432
                .num_values = 3,
 
2433
                .existing_value = true,
 
2434
                .error_message = NULL
 
2435
        },{
 
2436
                .values = { VALUE_CURRENT_VERSION, NULL, VALUE_SYSTEM_ROOT },
 
2437
                .num_values = 3,
 
2438
                .existing_value = false,
 
2439
                .error_message = NULL
 
2440
        },{
 
2441
                .values = { VALUE_CURRENT_VERSION, "", VALUE_SYSTEM_ROOT },
 
2442
                .num_values = 3,
 
2443
                .existing_value = false,
 
2444
                .error_message = NULL
 
2445
        },{
 
2446
                .values = { "IDoNotExist", NULL, NULL },
 
2447
                .num_values = 1,
 
2448
                .existing_value = false,
 
2449
                .error_message = NULL
 
2450
        },{
 
2451
                .values = { "IDoNotExist", VALUE_CURRENT_VERSION, NULL },
 
2452
                .num_values = 2,
 
2453
                .existing_value = false,
 
2454
                .error_message = NULL
 
2455
        },{
 
2456
                .values = { VALUE_CURRENT_VERSION, "IDoNotExist", NULL },
 
2457
                .num_values = 2,
 
2458
                .existing_value = false,
 
2459
                .error_message = NULL
 
2460
        }
 
2461
};
 
2462
 
 
2463
static bool test_HKLM_wellknown(struct torture_context *tctx,
 
2464
                                struct dcerpc_binding_handle *b,
 
2465
                                struct policy_handle *handle)
 
2466
{
 
2467
        struct policy_handle newhandle;
 
2468
        int i;
 
2469
 
 
2470
        /* FIXME: s3 does not support SEC_FLAG_MAXIMUM_ALLOWED yet */
 
2471
        if (torture_setting_bool(tctx, "samba3", false)) {
 
2472
                torture_assert(tctx, test_OpenKey_opts(tctx, b, handle,
 
2473
                               KEY_CURRENT_VERSION,
 
2474
                               REG_OPTION_NON_VOLATILE,
 
2475
                               KEY_QUERY_VALUE,
 
2476
                               &newhandle,
 
2477
                               WERR_OK),
 
2478
                        "failed to open current version key");
 
2479
        } else {
 
2480
                torture_assert(tctx, test_OpenKey(b, tctx, handle, KEY_CURRENT_VERSION, &newhandle),
 
2481
                        "failed to open current version key");
 
2482
        }
 
2483
 
 
2484
        torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, VALUE_CURRENT_VERSION, true),
 
2485
                "failed to query current version");
 
2486
        torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, "IDoNotExist", false),
 
2487
                "succeeded to query nonexistent value");
 
2488
        torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, NULL, false),
 
2489
                "succeeded to query value with NULL name");
 
2490
        torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, "", false),
 
2491
                "succeeded to query nonexistent default value (\"\")");
 
2492
 
 
2493
        if (torture_setting_bool(tctx, "samba4", false)) {
 
2494
                torture_comment(tctx, "skipping QueryMultipleValues{2} tests against Samba4\n");
 
2495
                goto close_key;
 
2496
        }
 
2497
 
 
2498
        for (i=0; i < ARRAY_SIZE(multiple_values_tests); i++) {
 
2499
                const char *msg;
 
2500
                msg = talloc_asprintf(tctx,
 
2501
                                "failed to query %d %sexisting values\n",
 
2502
                                        multiple_values_tests[i].num_values,
 
2503
                                        multiple_values_tests[i].existing_value ? "":"non");
 
2504
 
 
2505
                torture_assert(tctx,
 
2506
                        test_QueryMultipleValues_full(b, tctx, &newhandle,
 
2507
                                                      multiple_values_tests[i].num_values,
 
2508
                                                      multiple_values_tests[i].values,
 
2509
                                                      multiple_values_tests[i].existing_value),
 
2510
                        msg);
 
2511
                torture_assert(tctx,
 
2512
                        test_QueryMultipleValues2_full(b, tctx, &newhandle,
 
2513
                                                       multiple_values_tests[i].num_values,
 
2514
                                                       multiple_values_tests[i].values,
 
2515
                                                       multiple_values_tests[i].existing_value),
 
2516
                        msg);
 
2517
        }
 
2518
 
 
2519
 close_key:
 
2520
        torture_assert(tctx, test_CloseKey(b, tctx, &newhandle),
 
2521
                "failed to close current version key");
 
2522
 
 
2523
        return true;
 
2524
}
 
2525
 
 
2526
static bool test_OpenHive(struct torture_context *tctx,
 
2527
                          struct dcerpc_binding_handle *b,
 
2528
                          struct policy_handle *handle,
 
2529
                          int hkey)
 
2530
{
1708
2531
        struct winreg_OpenHKLM r;
1709
2532
 
1710
 
        winreg_open_fn open_fn = userdata;
1711
 
 
1712
 
        ZERO_STRUCT(r);
1713
2533
        r.in.system_name = 0;
1714
2534
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1715
 
        r.out.handle = &handle;
1716
 
 
1717
 
        torture_assert_ntstatus_ok(tctx, open_fn(p, tctx, &r),
1718
 
                                   "open");
1719
 
 
1720
 
        test_Cleanup(p, tctx, &handle, TEST_KEY_BASE);
1721
 
 
1722
 
        if (!test_CreateKey(p, tctx, &handle, TEST_KEY_BASE, NULL)) {
1723
 
                torture_comment(tctx,
1724
 
                                "CreateKey (TEST_KEY_BASE) failed\n");
1725
 
        }
1726
 
 
1727
 
        if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY2,
 
2535
        r.out.handle = handle;
 
2536
 
 
2537
        switch (hkey) {
 
2538
        case HKEY_LOCAL_MACHINE:
 
2539
                torture_assert_ntstatus_ok(tctx,
 
2540
                        dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
 
2541
                        "failed to open HKLM");
 
2542
                torture_assert_werr_ok(tctx, r.out.result,
 
2543
                        "failed to open HKLM");
 
2544
                break;
 
2545
        case HKEY_CURRENT_USER:
 
2546
                torture_assert_ntstatus_ok(tctx,
 
2547
                        dcerpc_winreg_OpenHKCU_r(b, tctx, (struct winreg_OpenHKCU *)(void *)&r),
 
2548
                        "failed to open HKCU");
 
2549
                torture_assert_werr_ok(tctx, r.out.result,
 
2550
                        "failed to open HKCU");
 
2551
                break;
 
2552
        case HKEY_USERS:
 
2553
                torture_assert_ntstatus_ok(tctx,
 
2554
                        dcerpc_winreg_OpenHKU_r(b, tctx, (struct winreg_OpenHKU *)(void *)&r),
 
2555
                        "failed to open HKU");
 
2556
                torture_assert_werr_ok(tctx, r.out.result,
 
2557
                        "failed to open HKU");
 
2558
                break;
 
2559
        case HKEY_CLASSES_ROOT:
 
2560
                torture_assert_ntstatus_ok(tctx,
 
2561
                        dcerpc_winreg_OpenHKCR_r(b, tctx, (struct winreg_OpenHKCR *)(void *)&r),
 
2562
                        "failed to open HKCR");
 
2563
                torture_assert_werr_ok(tctx, r.out.result,
 
2564
                        "failed to open HKCR");
 
2565
                break;
 
2566
        default:
 
2567
                torture_warning(tctx, "unsupported hkey: 0x%08x\n", hkey);
 
2568
                return false;
 
2569
        }
 
2570
 
 
2571
        return true;
 
2572
}
 
2573
 
 
2574
static bool test_volatile_keys(struct torture_context *tctx,
 
2575
                               struct dcerpc_binding_handle *b,
 
2576
                               struct policy_handle *handle,
 
2577
                               int hkey)
 
2578
{
 
2579
        struct policy_handle new_handle, hive_handle;
 
2580
        enum winreg_CreateAction action_taken;
 
2581
 
 
2582
        torture_comment(tctx, "Testing VOLATILE key\n");
 
2583
 
 
2584
        test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE);
 
2585
 
 
2586
        torture_assert(tctx,
 
2587
                test_CreateKey_opts(tctx, b, handle, TEST_KEY_VOLATILE, NULL,
 
2588
                                    REG_OPTION_VOLATILE,
 
2589
                                    SEC_FLAG_MAXIMUM_ALLOWED,
 
2590
                                    NULL,
 
2591
                                    WERR_OK,
 
2592
                                    &action_taken,
 
2593
                                    &new_handle),
 
2594
                "failed to create REG_OPTION_VOLATILE type key");
 
2595
 
 
2596
        torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
 
2597
 
 
2598
        torture_assert(tctx,
 
2599
                test_CreateKey_opts(tctx, b, &new_handle, TEST_SUBKEY_VOLATILE, NULL,
 
2600
                                    REG_OPTION_NON_VOLATILE,
 
2601
                                    SEC_FLAG_MAXIMUM_ALLOWED,
 
2602
                                    NULL,
 
2603
                                    WERR_CHILD_MUST_BE_VOLATILE,
 
2604
                                    NULL,
 
2605
                                    NULL),
 
2606
                "failed to fail create REG_OPTION_VOLATILE type key");
 
2607
 
 
2608
        torture_assert(tctx,
 
2609
                test_CloseKey(b, tctx, &new_handle),
 
2610
                "failed to close");
 
2611
 
 
2612
        torture_assert(tctx,
 
2613
                test_OpenKey_opts(tctx, b, handle, TEST_KEY_VOLATILE,
 
2614
                                  REG_OPTION_NON_VOLATILE,
 
2615
                                  SEC_FLAG_MAXIMUM_ALLOWED,
 
2616
                                  &new_handle,
 
2617
                                  WERR_OK),
 
2618
                "failed to open volatile key");
 
2619
 
 
2620
        torture_assert(tctx,
 
2621
                test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE),
 
2622
                "failed to delete key");
 
2623
 
 
2624
        torture_assert(tctx,
 
2625
                test_CreateKey_opts(tctx, b, handle, TEST_KEY_VOLATILE, NULL,
 
2626
                                    REG_OPTION_VOLATILE,
 
2627
                                    SEC_FLAG_MAXIMUM_ALLOWED,
 
2628
                                    NULL,
 
2629
                                    WERR_OK,
 
2630
                                    &action_taken,
 
2631
                                    &new_handle),
 
2632
                "failed to create REG_OPTION_VOLATILE type key");
 
2633
 
 
2634
        torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
 
2635
 
 
2636
        torture_assert(tctx,
 
2637
                test_CloseKey(b, tctx, &new_handle),
 
2638
                "failed to close");
 
2639
 
 
2640
        torture_assert(tctx,
 
2641
                test_OpenKey_opts(tctx, b, handle, TEST_KEY_VOLATILE,
 
2642
                                  REG_OPTION_VOLATILE,
 
2643
                                  SEC_FLAG_MAXIMUM_ALLOWED,
 
2644
                                  &new_handle,
 
2645
                                  WERR_OK),
 
2646
                "failed to open volatile key");
 
2647
 
 
2648
        torture_assert(tctx,
 
2649
                test_CloseKey(b, tctx, &new_handle),
 
2650
                "failed to close");
 
2651
 
 
2652
        torture_assert(tctx,
 
2653
                test_OpenHive(tctx, b, &hive_handle, hkey),
 
2654
                "failed top open hive");
 
2655
 
 
2656
        torture_assert(tctx,
 
2657
                test_OpenKey_opts(tctx, b, &hive_handle, TEST_KEY_VOLATILE,
 
2658
                                  REG_OPTION_VOLATILE,
 
2659
                                  SEC_FLAG_MAXIMUM_ALLOWED,
 
2660
                                  &new_handle,
 
2661
                                  WERR_BADFILE),
 
2662
                "failed to open volatile key");
 
2663
 
 
2664
        torture_assert(tctx,
 
2665
                test_OpenKey_opts(tctx, b, &hive_handle, TEST_KEY_VOLATILE,
 
2666
                                  REG_OPTION_NON_VOLATILE,
 
2667
                                  SEC_FLAG_MAXIMUM_ALLOWED,
 
2668
                                  &new_handle,
 
2669
                                  WERR_BADFILE),
 
2670
                "failed to open volatile key");
 
2671
 
 
2672
        torture_assert(tctx,
 
2673
                test_CloseKey(b, tctx, &hive_handle),
 
2674
                "failed to close");
 
2675
 
 
2676
        torture_assert(tctx,
 
2677
                test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE),
 
2678
                "failed to delete key");
 
2679
 
 
2680
 
 
2681
        torture_comment(tctx, "Testing VOLATILE key succeeded\n");
 
2682
 
 
2683
        return true;
 
2684
}
 
2685
 
 
2686
static const char *kernel_mode_registry_path(struct torture_context *tctx,
 
2687
                                             int hkey,
 
2688
                                             const char *sid_string,
 
2689
                                             const char *path)
 
2690
{
 
2691
        switch (hkey) {
 
2692
        case HKEY_LOCAL_MACHINE:
 
2693
                return talloc_asprintf(tctx, "\\Registry\\MACHINE\\%s", path);
 
2694
        case HKEY_CURRENT_USER:
 
2695
                return talloc_asprintf(tctx, "\\Registry\\USER\\%s\\%s", sid_string, path);
 
2696
        case HKEY_USERS:
 
2697
                return talloc_asprintf(tctx, "\\Registry\\USER\\%s", path);
 
2698
        case HKEY_CLASSES_ROOT:
 
2699
                return talloc_asprintf(tctx, "\\Registry\\MACHINE\\Software\\Classes\\%s", path);
 
2700
        default:
 
2701
                torture_warning(tctx, "unsupported hkey: 0x%08x\n", hkey);
 
2702
                return NULL;
 
2703
        }
 
2704
}
 
2705
 
 
2706
static bool test_symlink_keys(struct torture_context *tctx,
 
2707
                              struct dcerpc_binding_handle *b,
 
2708
                              struct policy_handle *handle,
 
2709
                              const char *key,
 
2710
                              int hkey)
 
2711
{
 
2712
        struct policy_handle new_handle;
 
2713
        enum winreg_CreateAction action_taken;
 
2714
        DATA_BLOB blob;
 
2715
        uint32_t value = 42;
 
2716
        const char *test_key_symlink_dest;
 
2717
        const char *test_key_symlink;
 
2718
        const char *kernel_mode_path;
 
2719
 
 
2720
        /* disable until we know how to delete a symbolic link */
 
2721
        torture_skip(tctx, "symlink test disabled");
 
2722
 
 
2723
        torture_comment(tctx, "Testing REG_OPTION_CREATE_LINK key\n");
 
2724
 
 
2725
        /* create destination key with testvalue */
 
2726
        test_key_symlink = talloc_asprintf(tctx, "%s\\%s",
 
2727
                        key, TEST_KEY_SYMLINK);
 
2728
        test_key_symlink_dest = talloc_asprintf(tctx, "%s\\%s",
 
2729
                        key, TEST_KEY_SYMLINK_DEST);
 
2730
 
 
2731
        test_DeleteKey(b, tctx, handle, test_key_symlink);
 
2732
 
 
2733
        torture_assert(tctx,
 
2734
                test_CreateKey_opts(tctx, b, handle, test_key_symlink_dest, NULL,
 
2735
                                    0,
 
2736
                                    SEC_FLAG_MAXIMUM_ALLOWED,
 
2737
                                    NULL,
 
2738
                                    WERR_OK,
 
2739
                                    &action_taken,
 
2740
                                    &new_handle),
 
2741
                "failed to create symlink destination");
 
2742
 
 
2743
        blob = data_blob_talloc_zero(tctx, 4);
 
2744
        SIVAL(blob.data, 0, value);
 
2745
 
 
2746
        torture_assert(tctx,
 
2747
                test_SetValue(b, tctx, &new_handle, "TestValue", REG_DWORD, blob.data, blob.length),
 
2748
                "failed to create TestValue");
 
2749
 
 
2750
        torture_assert(tctx,
 
2751
                test_CloseKey(b, tctx, &new_handle),
 
2752
                "failed to close");
 
2753
 
 
2754
        /* create symlink */
 
2755
 
 
2756
        torture_assert(tctx,
 
2757
                test_CreateKey_opts(tctx, b, handle, test_key_symlink, NULL,
 
2758
                                    REG_OPTION_CREATE_LINK | REG_OPTION_VOLATILE,
 
2759
                                    SEC_FLAG_MAXIMUM_ALLOWED,
 
2760
                                    NULL,
 
2761
                                    WERR_OK,
 
2762
                                    &action_taken,
 
2763
                                    &new_handle),
 
2764
                "failed to create REG_OPTION_CREATE_LINK type key");
 
2765
 
 
2766
        torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
 
2767
 
 
2768
        kernel_mode_path = kernel_mode_registry_path(tctx, hkey, NULL, test_key_symlink_dest);
 
2769
 
 
2770
        torture_assert(tctx,
 
2771
                convert_string_talloc(tctx, CH_UNIX, CH_UTF16,
 
2772
                                      kernel_mode_path,
 
2773
                                      strlen(kernel_mode_path), /* not NULL terminated */
 
2774
                                      &blob.data, &blob.length,
 
2775
                                      false),
 
2776
                "failed to convert");
 
2777
 
 
2778
        torture_assert(tctx,
 
2779
                test_SetValue(b, tctx, &new_handle, "SymbolicLinkValue", REG_LINK, blob.data, blob.length),
 
2780
                "failed to create SymbolicLinkValue value");
 
2781
 
 
2782
        torture_assert(tctx,
 
2783
                test_CloseKey(b, tctx, &new_handle),
 
2784
                "failed to close");
 
2785
 
 
2786
        /* test follow symlink */
 
2787
 
 
2788
        torture_assert(tctx,
 
2789
                test_OpenKey_opts(tctx, b, handle, test_key_symlink,
 
2790
                                  0,
 
2791
                                  SEC_FLAG_MAXIMUM_ALLOWED,
 
2792
                                  &new_handle,
 
2793
                                  WERR_OK),
 
2794
                "failed to follow symlink key");
 
2795
 
 
2796
        torture_assert(tctx,
 
2797
                test_QueryValue(b, tctx, &new_handle, "TestValue"),
 
2798
                "failed to query value");
 
2799
 
 
2800
        torture_assert(tctx,
 
2801
                test_CloseKey(b, tctx, &new_handle),
 
2802
                "failed to close");
 
2803
 
 
2804
        /* delete link */
 
2805
 
 
2806
        torture_assert(tctx,
 
2807
                test_OpenKey_opts(tctx, b, handle, test_key_symlink,
 
2808
                                  REG_OPTION_OPEN_LINK | REG_OPTION_VOLATILE,
 
2809
                                  SEC_FLAG_MAXIMUM_ALLOWED,
 
2810
                                  &new_handle,
 
2811
                                  WERR_OK),
 
2812
                "failed to open symlink key");
 
2813
 
 
2814
        torture_assert(tctx,
 
2815
                test_DeleteValue(b, tctx, &new_handle, "SymbolicLinkValue"),
 
2816
                "failed to delete value SymbolicLinkValue");
 
2817
 
 
2818
        torture_assert(tctx,
 
2819
                test_CloseKey(b, tctx, &new_handle),
 
2820
                "failed to close");
 
2821
 
 
2822
        torture_assert(tctx,
 
2823
                test_DeleteKey(b, tctx, handle, test_key_symlink),
 
2824
                "failed to delete key");
 
2825
 
 
2826
        /* delete destination */
 
2827
 
 
2828
        torture_assert(tctx,
 
2829
                test_DeleteKey(b, tctx, handle, test_key_symlink_dest),
 
2830
                "failed to delete key");
 
2831
 
 
2832
        return true;
 
2833
}
 
2834
 
 
2835
static bool test_CreateKey_keytypes(struct torture_context *tctx,
 
2836
                                    struct dcerpc_binding_handle *b,
 
2837
                                    struct policy_handle *handle,
 
2838
                                    const char *key,
 
2839
                                    int hkey)
 
2840
{
 
2841
 
 
2842
        if (torture_setting_bool(tctx, "samba3", false) ||
 
2843
            torture_setting_bool(tctx, "samba4", false)) {
 
2844
                torture_skip(tctx, "skipping CreateKey keytypes test against Samba");
 
2845
        }
 
2846
 
 
2847
        torture_assert(tctx,
 
2848
                test_volatile_keys(tctx, b, handle, hkey),
 
2849
                "failed to test volatile keys");
 
2850
 
 
2851
        torture_assert(tctx,
 
2852
                test_symlink_keys(tctx, b, handle, key, hkey),
 
2853
                "failed to test symlink keys");
 
2854
 
 
2855
        return true;
 
2856
}
 
2857
 
 
2858
static bool test_key_base(struct torture_context *tctx,
 
2859
                          struct dcerpc_binding_handle *b,
 
2860
                          struct policy_handle *handle,
 
2861
                          const char *base_key,
 
2862
                          int hkey)
 
2863
{
 
2864
        struct policy_handle newhandle;
 
2865
        bool ret = true, created = false, deleted = false;
 
2866
        bool created3 = false;
 
2867
        const char *test_key1;
 
2868
        const char *test_key3;
 
2869
        const char *test_subkey;
 
2870
 
 
2871
        test_Cleanup(b, tctx, handle, base_key);
 
2872
 
 
2873
        if (!test_CreateKey(b, tctx, handle, base_key, NULL)) {
 
2874
                torture_comment(tctx,
 
2875
                                "CreateKey(%s) failed\n", base_key);
 
2876
        }
 
2877
 
 
2878
        test_key1 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY1);
 
2879
 
 
2880
        if (!test_CreateKey(b, tctx, handle, test_key1, NULL)) {
 
2881
                torture_comment(tctx,
 
2882
                                "CreateKey failed - not considering a failure\n");
 
2883
        } else {
 
2884
                created = true;
 
2885
        }
 
2886
 
 
2887
        if (created) {
 
2888
                if (!test_FlushKey(b, tctx, handle)) {
 
2889
                        torture_comment(tctx, "FlushKey failed\n");
 
2890
                        ret = false;
 
2891
                }
 
2892
 
 
2893
                if (!test_OpenKey(b, tctx, handle, test_key1, &newhandle)) {
 
2894
                        torture_fail(tctx,
 
2895
                                     "CreateKey failed (OpenKey after Create didn't work)\n");
 
2896
                }
 
2897
 
 
2898
                if (hkey == HKEY_CURRENT_USER) {
 
2899
                        torture_assert(tctx, test_SetValue_simple(b, tctx, &newhandle),
 
2900
                                "simple SetValue test failed");
 
2901
                        torture_assert(tctx, test_SetValue_values(b, tctx, &newhandle),
 
2902
                                "values SetValue test failed");
 
2903
                        torture_assert(tctx, test_SetValue_extended(b, tctx, &newhandle),
 
2904
                                "extended SetValue test failed");
 
2905
                        torture_assert(tctx, test_create_keynames(b, tctx, &newhandle),
 
2906
                                "keyname CreateKey test failed");
 
2907
                } else {
 
2908
                        torture_assert(tctx, test_CreateKey_keytypes(tctx, b, &newhandle, test_key1, hkey),
 
2909
                                "keytype test failed");
 
2910
                }
 
2911
 
 
2912
                if (!test_CloseKey(b, tctx, &newhandle)) {
 
2913
                        torture_fail(tctx,
 
2914
                                     "CreateKey failed (CloseKey after Open didn't work)\n");
 
2915
                }
 
2916
 
 
2917
                if (!test_DeleteKey(b, tctx, handle, test_key1)) {
 
2918
                        torture_comment(tctx, "DeleteKey(%s) failed\n",
 
2919
                                              test_key1);
 
2920
                        ret = false;
 
2921
                } else {
 
2922
                        deleted = true;
 
2923
                }
 
2924
 
 
2925
                if (!test_FlushKey(b, tctx, handle)) {
 
2926
                        torture_comment(tctx, "FlushKey failed\n");
 
2927
                        ret = false;
 
2928
                }
 
2929
 
 
2930
                if (deleted) {
 
2931
                        if (!test_OpenKey_opts(tctx, b, handle, test_key1,
 
2932
                                               REG_OPTION_NON_VOLATILE,
 
2933
                                               SEC_FLAG_MAXIMUM_ALLOWED,
 
2934
                                               &newhandle,
 
2935
                                               WERR_BADFILE)) {
 
2936
                                torture_comment(tctx,
 
2937
                                                "DeleteKey failed (OpenKey after Delete "
 
2938
                                                "did not return WERR_BADFILE)\n");
 
2939
                                ret = false;
 
2940
                        }
 
2941
                }
 
2942
 
 
2943
                test_key3 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY3);
 
2944
 
 
2945
                if (test_CreateKey(b, tctx, handle, test_key3, NULL)) {
 
2946
                        created3 = true;
 
2947
                }
 
2948
 
 
2949
                test_subkey = talloc_asprintf(tctx, "%s\\%s", test_key3, TEST_SUBKEY);
 
2950
 
 
2951
                if (created3) {
 
2952
                        if (test_CreateKey(b, tctx, handle, test_subkey, NULL)) {
 
2953
                                if (!test_DeleteKey(b, tctx, handle, test_subkey)) {
 
2954
                                        torture_comment(tctx, "DeleteKey(%s) failed\n", test_subkey);
 
2955
                                        ret = false;
 
2956
                                }
 
2957
                        }
 
2958
 
 
2959
                        if (!test_DeleteKey(b, tctx, handle, test_key3)) {
 
2960
                                torture_comment(tctx, "DeleteKey(%s) failed\n", test_key3);
 
2961
                                ret = false;
 
2962
                        }
 
2963
                }
 
2964
        }
 
2965
 
 
2966
        test_Cleanup(b, tctx, handle, base_key);
 
2967
 
 
2968
        return ret;
 
2969
}
 
2970
 
 
2971
static bool test_key_base_sd(struct torture_context *tctx,
 
2972
                             struct dcerpc_pipe *p,
 
2973
                             struct policy_handle *handle,
 
2974
                             const char *base_key)
 
2975
{
 
2976
        struct policy_handle newhandle;
 
2977
        bool ret = true, created2 = false, created4 = false;
 
2978
        struct dcerpc_binding_handle *b = p->binding_handle;
 
2979
        const char *test_key2;
 
2980
        const char *test_key4;
 
2981
 
 
2982
        torture_skip(tctx, "security descriptor test disabled\n");
 
2983
 
 
2984
        if (torture_setting_bool(tctx, "samba3", false) ||
 
2985
            torture_setting_bool(tctx, "samba4", false)) {
 
2986
                torture_skip(tctx, "skipping security descriptor tests against Samba");
 
2987
        }
 
2988
 
 
2989
        test_Cleanup(b, tctx, handle, base_key);
 
2990
 
 
2991
        if (!test_CreateKey(b, tctx, handle, base_key, NULL)) {
 
2992
                torture_comment(tctx,
 
2993
                                "CreateKey(%s) failed\n", base_key);
 
2994
        }
 
2995
 
 
2996
        test_key2 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY2);
 
2997
 
 
2998
        if (test_CreateKey_sd(b, tctx, handle, test_key2,
1728
2999
                              NULL, &newhandle)) {
1729
3000
                created2 = true;
1730
3001
        }
1731
3002
 
1732
 
        if (created2 && !test_CloseKey(p, tctx, &newhandle)) {
1733
 
                printf("CloseKey failed\n");
 
3003
        if (created2 && !test_CloseKey(b, tctx, &newhandle)) {
 
3004
                torture_comment(tctx, "CloseKey failed\n");
1734
3005
                ret = false;
1735
3006
        }
1736
3007
 
1737
 
        if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY4, NULL, &newhandle)) {
 
3008
        test_key4 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY4);
 
3009
 
 
3010
        if (test_CreateKey_sd(b, tctx, handle, test_key4, NULL, &newhandle)) {
1738
3011
                created4 = true;
1739
3012
        }
1740
3013
 
1741
 
        if (created4 && !test_CloseKey(p, tctx, &newhandle)) {
1742
 
                printf("CloseKey failed\n");
1743
 
                ret = false;
1744
 
        }
1745
 
 
1746
 
        if (created4 && !test_SecurityDescriptors(p, tctx, &handle, TEST_KEY4)) {
1747
 
                ret = false;
1748
 
        }
1749
 
 
1750
 
        if (created4 && !test_DeleteKey(p, tctx, &handle, TEST_KEY4)) {
1751
 
                printf("DeleteKey failed\n");
1752
 
                ret = false;
1753
 
        }
1754
 
 
1755
 
        if (created2 && !test_DeleteKey(p, tctx, &handle, TEST_KEY2)) {
1756
 
                printf("DeleteKey failed\n");
1757
 
                ret = false;
1758
 
        }
1759
 
 
1760
 
        /* The HKCR hive has a very large fanout */
1761
 
        if (open_fn == (void *)dcerpc_winreg_OpenHKCR) {
1762
 
                if(!test_key(p, tctx, &handle, MAX_DEPTH - 1, true)) {
1763
 
                        ret = false;
1764
 
                }
1765
 
        } else {
1766
 
                if (!test_key(p, tctx, &handle, 0, true)) {
1767
 
                        ret = false;
1768
 
                }
1769
 
        }
1770
 
 
1771
 
        test_Cleanup(p, tctx, &handle, TEST_KEY_BASE);
 
3014
        if (created4 && !test_CloseKey(b, tctx, &newhandle)) {
 
3015
                torture_comment(tctx, "CloseKey failed\n");
 
3016
                ret = false;
 
3017
        }
 
3018
 
 
3019
        if (created4 && !test_SecurityDescriptors(p, tctx, handle, test_key4)) {
 
3020
                ret = false;
 
3021
        }
 
3022
 
 
3023
        if (created4 && !test_DeleteKey(b, tctx, handle, test_key4)) {
 
3024
                torture_comment(tctx, "DeleteKey(%s) failed\n", test_key4);
 
3025
                ret = false;
 
3026
        }
 
3027
 
 
3028
        if (created2 && !test_DeleteKey(b, tctx, handle, test_key4)) {
 
3029
                torture_comment(tctx, "DeleteKey(%s) failed\n", test_key4);
 
3030
                ret = false;
 
3031
        }
 
3032
 
 
3033
        test_Cleanup(b, tctx, handle, base_key);
1772
3034
 
1773
3035
        return ret;
1774
3036
}
1776
3038
static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p,
1777
3039
                      void *userdata)
1778
3040
{
1779
 
        struct policy_handle handle, newhandle;
1780
 
        bool ret = true, created = false, deleted = false;
1781
 
        bool created3 = false, created_subkey = false;
 
3041
        struct policy_handle handle;
 
3042
        bool ret = true;
1782
3043
        struct winreg_OpenHKLM r;
1783
 
 
1784
 
        winreg_open_fn open_fn = userdata;
1785
 
 
1786
 
        ZERO_STRUCT(r);
 
3044
        struct dcerpc_binding_handle *b = p->binding_handle;
 
3045
        const char *torture_base_key;
 
3046
        int hkey = 0;
 
3047
 
 
3048
        winreg_open_fn open_fn = (winreg_open_fn)userdata;
 
3049
 
1787
3050
        r.in.system_name = 0;
1788
3051
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1789
3052
        r.out.handle = &handle;
1790
3053
 
1791
 
        torture_assert_ntstatus_ok(tctx, open_fn(p, tctx, &r),
 
3054
        torture_assert_ntstatus_ok(tctx, open_fn(b, tctx, &r),
1792
3055
                                   "open");
1793
3056
 
1794
 
        test_Cleanup(p, tctx, &handle, TEST_KEY_BASE);
1795
 
 
1796
 
        if (!test_CreateKey(p, tctx, &handle, TEST_KEY_BASE, NULL)) {
1797
 
                torture_comment(tctx,
1798
 
                                "CreateKey (TEST_KEY_BASE) failed\n");
1799
 
        }
1800
 
 
1801
 
        if (!test_CreateKey(p, tctx, &handle, TEST_KEY1, NULL)) {
1802
 
                torture_comment(tctx,
1803
 
                                "CreateKey failed - not considering a failure\n");
1804
 
        } else {
1805
 
                created = true;
1806
 
        }
1807
 
 
1808
 
        if (created && !test_FlushKey(p, tctx, &handle)) {
1809
 
                torture_comment(tctx, "FlushKey failed\n");
1810
 
                ret = false;
1811
 
        }
1812
 
 
1813
 
        if (created && !test_OpenKey(p, tctx, &handle, TEST_KEY1, &newhandle))
1814
 
                torture_fail(tctx,
1815
 
                             "CreateKey failed (OpenKey after Create didn't work)\n");
1816
 
 
1817
 
        if (created && !test_CloseKey(p, tctx, &newhandle))
1818
 
                torture_fail(tctx,
1819
 
                             "CreateKey failed (CloseKey after Open didn't work)\n");
1820
 
 
1821
 
        if (created && !test_DeleteKey(p, tctx, &handle, TEST_KEY1)) {
1822
 
                torture_comment(tctx, "DeleteKey failed\n");
1823
 
                ret = false;
1824
 
        } else {
1825
 
                deleted = true;
1826
 
        }
1827
 
 
1828
 
        if (created && !test_FlushKey(p, tctx, &handle)) {
1829
 
                torture_comment(tctx, "FlushKey failed\n");
1830
 
                ret = false;
1831
 
        }
1832
 
 
1833
 
        if (created && deleted &&
1834
 
            !_test_OpenKey(p, tctx, &handle, TEST_KEY1,
1835
 
                           SEC_FLAG_MAXIMUM_ALLOWED, &newhandle,
1836
 
                           WERR_BADFILE, NULL)) {
1837
 
                torture_comment(tctx,
1838
 
                                "DeleteKey failed (OpenKey after Delete "
1839
 
                                "did not return WERR_BADFILE)\n");
1840
 
                ret = false;
1841
 
        }
1842
 
 
1843
 
        if (!test_GetVersion(p, tctx, &handle)) {
 
3057
        if (!test_GetVersion(b, tctx, &handle)) {
1844
3058
                torture_comment(tctx, "GetVersion failed\n");
1845
3059
                ret = false;
1846
3060
        }
1847
3061
 
1848
 
        if (created && test_CreateKey(p, tctx, &handle, TEST_KEY3, NULL)) {
1849
 
                created3 = true;
1850
 
        }
1851
 
 
1852
 
        if (created3 &&
1853
 
            test_CreateKey(p, tctx, &handle, TEST_SUBKEY, NULL)) {
1854
 
                created_subkey = true;
1855
 
        }
1856
 
 
1857
 
        if (created_subkey &&
1858
 
            !test_DeleteKey(p, tctx, &handle, TEST_KEY3)) {
1859
 
                printf("DeleteKey failed\n");
 
3062
        if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKLM_r) {
 
3063
                hkey = HKEY_LOCAL_MACHINE;
 
3064
                torture_base_key = "SOFTWARE\\Samba\\" TEST_KEY_BASE;
 
3065
        } else if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKU_r) {
 
3066
                hkey = HKEY_USERS;
 
3067
                torture_base_key = TEST_KEY_BASE;
 
3068
        } else if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKCR_r) {
 
3069
                hkey = HKEY_CLASSES_ROOT;
 
3070
                torture_base_key = TEST_KEY_BASE;
 
3071
        } else if (open_fn == (winreg_open_fn)dcerpc_winreg_OpenHKCU_r) {
 
3072
                hkey = HKEY_CURRENT_USER;
 
3073
                torture_base_key = TEST_KEY_BASE;
 
3074
        } else {
 
3075
                torture_fail(tctx, "unsupported hkey");
 
3076
        }
 
3077
 
 
3078
        if (hkey == HKEY_LOCAL_MACHINE) {
 
3079
                torture_assert(tctx,
 
3080
                        test_HKLM_wellknown(tctx, b, &handle),
 
3081
                        "failed to test HKLM wellknown keys");
 
3082
        }
 
3083
 
 
3084
        if (!test_key_base(tctx, b, &handle, torture_base_key, hkey)) {
 
3085
                torture_warning(tctx, "failed to test TEST_KEY_BASE(%s)",
 
3086
                                torture_base_key);
 
3087
                ret = false;
 
3088
        }
 
3089
 
 
3090
        if (!test_key_base_sd(tctx, p, &handle, torture_base_key)) {
 
3091
                torture_warning(tctx, "failed to test TEST_KEY_BASE(%s) sd",
 
3092
                                torture_base_key);
1860
3093
                ret = false;
1861
3094
        }
1862
3095
 
1863
3096
        /* The HKCR hive has a very large fanout */
1864
 
        if (open_fn == (void *)dcerpc_winreg_OpenHKCR) {
 
3097
        if (hkey == HKEY_CLASSES_ROOT) {
1865
3098
                if(!test_key(p, tctx, &handle, MAX_DEPTH - 1, false)) {
1866
3099
                        ret = false;
1867
3100
                }
 
3101
        } else if (hkey == HKEY_LOCAL_MACHINE) {
 
3102
                /* FIXME we are not allowed to enum values in the HKLM root */
1868
3103
        } else {
1869
3104
                if (!test_key(p, tctx, &handle, 0, false)) {
1870
3105
                        ret = false;
1871
3106
                }
1872
3107
        }
1873
3108
 
1874
 
        test_Cleanup(p, tctx, &handle, TEST_KEY_BASE);
1875
 
 
1876
3109
        return ret;
1877
3110
}
1878
3111
 
1879
3112
struct torture_suite *torture_rpc_winreg(TALLOC_CTX *mem_ctx)
1880
3113
{
1881
3114
        struct torture_rpc_tcase *tcase;
1882
 
        struct torture_suite *suite = torture_suite_create(mem_ctx, "WINREG");
 
3115
        struct torture_suite *suite = torture_suite_create(mem_ctx, "winreg");
1883
3116
        struct torture_test *test;
1884
3117
 
1885
3118
        tcase = torture_suite_add_rpc_iface_tcase(suite, "winreg",
1893
3126
                                          test_InitiateSystemShutdownEx);
1894
3127
        test->dangerous = true;
1895
3128
 
1896
 
        /* Basic tests without security descriptors */
1897
 
        torture_rpc_tcase_add_test_ex(tcase, "HKLM-basic",
1898
 
                                      test_Open,
1899
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKLM);
1900
 
        torture_rpc_tcase_add_test_ex(tcase, "HKU-basic",
1901
 
                                      test_Open,
1902
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKU);
1903
 
        torture_rpc_tcase_add_test_ex(tcase, "HKCR-basic",
1904
 
                                      test_Open,
1905
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKCR);
1906
 
        torture_rpc_tcase_add_test_ex(tcase, "HKCU-basic",
1907
 
                                      test_Open,
1908
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKCU);
1909
 
 
1910
 
        /* Security descriptor tests */
1911
 
        torture_rpc_tcase_add_test_ex(tcase, "HKLM-security",
1912
 
                                      test_Open_Security,
1913
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKLM);
1914
 
        torture_rpc_tcase_add_test_ex(tcase, "HKU-security",
1915
 
                                      test_Open_Security,
1916
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKU);
1917
 
        torture_rpc_tcase_add_test_ex(tcase, "HKCR-security",
1918
 
                                      test_Open_Security,
1919
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKCR);
1920
 
        torture_rpc_tcase_add_test_ex(tcase, "HKCU-security",
1921
 
                                      test_Open_Security,
1922
 
                                      (winreg_open_fn)dcerpc_winreg_OpenHKCU);
 
3129
        torture_rpc_tcase_add_test_ex(tcase, "HKLM",
 
3130
                                      test_Open,
 
3131
                                      (void *)dcerpc_winreg_OpenHKLM_r);
 
3132
        torture_rpc_tcase_add_test_ex(tcase, "HKU",
 
3133
                                      test_Open,
 
3134
                                      (void *)dcerpc_winreg_OpenHKU_r);
 
3135
        torture_rpc_tcase_add_test_ex(tcase, "HKCR",
 
3136
                                      test_Open,
 
3137
                                      (void *)dcerpc_winreg_OpenHKCR_r);
 
3138
        torture_rpc_tcase_add_test_ex(tcase, "HKCU",
 
3139
                                      test_Open,
 
3140
                                      (void *)dcerpc_winreg_OpenHKCU_r);
1923
3141
 
1924
3142
        return suite;
1925
3143
}