1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
|
/*
Unix SMB/CIFS implementation.
test suite for File Server Remote VSS Protocol operations
Copyright (C) David Disseldorp 2012-2013
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Windows Server "8" Beta is very picky in how it accepts FSRVP requests, the
* client must be a member of the same AD domain, ndr64 and signing must be
* negotiated for the DCE/RPC bind. E.g.
*
* smbtorture ncacn_np:LUTZE[/pipe/FssagentRpc,smb2,ndr64,sign] \
* -U 'DOM\user%pw' rpc.fsrvp
*
* This test suite requires a snapshotable share named FSHARE (see #def below).
*/
#include "includes.h"
#include "lib/param/param.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "libcli/smb_composite/smb_composite.h"
#include "libcli/resolve/resolve.h"
#include "libcli/util/hresult.h"
#include "libcli/security/dom_sid.h"
#include "libcli/security/security_descriptor.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#include "torture/rpc/torture_rpc.h"
#include "librpc/gen_ndr/ndr_security.h"
#include "librpc/gen_ndr/ndr_srvsvc_c.h"
#include "librpc/gen_ndr/ndr_fsrvp_c.h"
#include "lib/cmdline/cmdline.h"
#define FSHARE "fsrvp_share"
#define FNAME "testfss.dat"
static bool test_fsrvp_is_path_supported(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fss_IsPathSupported r;
struct dcerpc_binding_handle *b = p->binding_handle;
NTSTATUS status;
ZERO_STRUCT(r);
r.in.ShareName = talloc_asprintf(tctx,"\\\\%s\\%s\\",
dcerpc_server_name(p),
FSHARE);
status = dcerpc_fss_IsPathSupported_r(b, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"IsPathSupported failed");
torture_assert(tctx, *r.out.SupportedByThisProvider,
"path not supported");
torture_comment(tctx, "path %s is supported by fsrvp server %s\n",
r.in.ShareName, *r.out.OwnerMachineName);
return true;
}
static bool test_fsrvp_get_version(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fss_GetSupportedVersion r;
struct dcerpc_binding_handle *b = p->binding_handle;
NTSTATUS status;
ZERO_STRUCT(r);
status = dcerpc_fss_GetSupportedVersion_r(b, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"GetSupportedVersion failed");
torture_comment(tctx, "got MinVersion %u\n", *r.out.MinVersion);
torture_comment(tctx, "got MaxVersion %u\n", *r.out.MaxVersion);
return true;
}
static bool test_fsrvp_set_ctx(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fss_SetContext r;
struct dcerpc_binding_handle *b = p->binding_handle;
NTSTATUS status;
ZERO_STRUCT(r);
r.in.Context = FSRVP_CTX_BACKUP;
status = dcerpc_fss_SetContext_r(b, tctx, &r);
torture_assert_ntstatus_ok(tctx, status, "SetContext failed");
return true;
}
enum test_fsrvp_inject {
TEST_FSRVP_TOUT_NONE = 0,
TEST_FSRVP_TOUT_SET_CTX,
TEST_FSRVP_TOUT_START_SET,
TEST_FSRVP_TOUT_ADD_TO_SET,
TEST_FSRVP_TOUT_PREPARE,
TEST_FSRVP_TOUT_COMMIT,
TEST_FSRVP_STOP_B4_EXPOSE,
};
static bool test_fsrvp_sc_create(struct torture_context *tctx,
struct dcerpc_pipe *p,
const char *share,
enum test_fsrvp_inject inject,
struct fssagent_share_mapping_1 **sc_map)
{
struct fss_IsPathSupported r_pathsupport_get;
struct fss_GetSupportedVersion r_version_get;
struct fss_SetContext r_context_set;
struct fss_StartShadowCopySet r_scset_start;
struct fss_AddToShadowCopySet r_scset_add1;
struct fss_AddToShadowCopySet r_scset_add2;
struct fss_PrepareShadowCopySet r_scset_prep;
struct fss_CommitShadowCopySet r_scset_commit;
struct fss_ExposeShadowCopySet r_scset_expose;
struct fss_GetShareMapping r_sharemap_get;
struct dcerpc_binding_handle *b = p->binding_handle;
NTSTATUS status;
time_t start_time;
TALLOC_CTX *tmp_ctx = talloc_new(tctx);
struct fssagent_share_mapping_1 *map = NULL;
int sleep_time;
/*
* PrepareShadowCopySet & CommitShadowCopySet often exceed the default
* 60 second dcerpc request timeout against Windows Server "8" Beta.
*/
dcerpc_binding_handle_set_timeout(b, 240);
ZERO_STRUCT(r_pathsupport_get);
r_pathsupport_get.in.ShareName = share;
status = dcerpc_fss_IsPathSupported_r(b, tmp_ctx, &r_pathsupport_get);
torture_assert_ntstatus_ok(tctx, status,
"IsPathSupported failed");
torture_assert_int_equal(tctx, r_pathsupport_get.out.result, 0,
"failed IsPathSupported response");
torture_assert(tctx, r_pathsupport_get.out.SupportedByThisProvider,
"path not supported");
ZERO_STRUCT(r_version_get);
status = dcerpc_fss_GetSupportedVersion_r(b, tmp_ctx, &r_version_get);
torture_assert_ntstatus_ok(tctx, status,
"GetSupportedVersion failed");
torture_assert_int_equal(tctx, r_version_get.out.result, 0,
"failed GetSupportedVersion response");
ZERO_STRUCT(r_context_set);
r_context_set.in.Context = FSRVP_CTX_BACKUP;
status = dcerpc_fss_SetContext_r(b, tmp_ctx, &r_context_set);
torture_assert_ntstatus_ok(tctx, status, "SetContext failed");
torture_assert_int_equal(tctx, r_context_set.out.result, 0,
"failed SetContext response");
if (inject == TEST_FSRVP_TOUT_SET_CTX) {
sleep_time = lpcfg_parm_int(tctx->lp_ctx, NULL, "fss",
"sequence timeout", 180);
torture_comment(tctx, "sleeping for %d\n", sleep_time);
smb_msleep((sleep_time * 1000) + 500);
}
ZERO_STRUCT(r_scset_start);
r_scset_start.in.ClientShadowCopySetId = GUID_random();
status = dcerpc_fss_StartShadowCopySet_r(b, tmp_ctx, &r_scset_start);
torture_assert_ntstatus_ok(tctx, status,
"StartShadowCopySet failed");
if (inject == TEST_FSRVP_TOUT_SET_CTX) {
/* expect error due to message sequence timeout after set_ctx */
torture_assert_int_equal(tctx, r_scset_start.out.result,
FSRVP_E_BAD_STATE,
"StartShadowCopySet timeout response");
goto done;
}
torture_assert_int_equal(tctx, r_scset_start.out.result, 0,
"failed StartShadowCopySet response");
torture_comment(tctx, "%s: shadow-copy set created\n",
GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId));
if (inject == TEST_FSRVP_TOUT_START_SET) {
sleep_time = lpcfg_parm_int(tctx->lp_ctx, NULL, "fss",
"sequence timeout", 180);
torture_comment(tctx, "sleeping for %d\n", sleep_time);
smb_msleep((sleep_time * 1000) + 500);
}
ZERO_STRUCT(r_scset_add1);
r_scset_add1.in.ClientShadowCopyId = GUID_random();
r_scset_add1.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
r_scset_add1.in.ShareName = share;
status = dcerpc_fss_AddToShadowCopySet_r(b, tmp_ctx, &r_scset_add1);
torture_assert_ntstatus_ok(tctx, status,
"AddToShadowCopySet failed");
if (inject == TEST_FSRVP_TOUT_START_SET) {
torture_assert_int_equal(tctx, r_scset_add1.out.result,
HRES_ERROR_V(HRES_E_INVALIDARG),
"AddToShadowCopySet timeout response");
goto done;
}
torture_assert_int_equal(tctx, r_scset_add1.out.result, 0,
"failed AddToShadowCopySet response");
torture_comment(tctx, "%s(%s): %s added to shadow-copy set\n",
GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
GUID_string(tmp_ctx, r_scset_add1.out.pShadowCopyId),
r_scset_add1.in.ShareName);
/* attempts to add the same share twice should fail */
ZERO_STRUCT(r_scset_add2);
r_scset_add2.in.ClientShadowCopyId = GUID_random();
r_scset_add2.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
r_scset_add2.in.ShareName = share;
status = dcerpc_fss_AddToShadowCopySet_r(b, tmp_ctx, &r_scset_add2);
torture_assert_ntstatus_ok(tctx, status,
"AddToShadowCopySet failed");
torture_assert_int_equal(tctx, r_scset_add2.out.result,
FSRVP_E_OBJECT_ALREADY_EXISTS,
"failed AddToShadowCopySet response");
if (inject == TEST_FSRVP_TOUT_ADD_TO_SET) {
sleep_time = lpcfg_parm_int(tctx->lp_ctx, NULL, "fss",
"sequence timeout", 1800);
torture_comment(tctx, "sleeping for %d\n", sleep_time);
smb_msleep((sleep_time * 1000) + 500);
}
start_time = time_mono(NULL);
ZERO_STRUCT(r_scset_prep);
r_scset_prep.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
// r_scset_prep.in.TimeOutInMilliseconds = (1800 * 1000); /* win8 */
r_scset_prep.in.TimeOutInMilliseconds = (240 * 1000);
status = dcerpc_fss_PrepareShadowCopySet_r(b, tmp_ctx, &r_scset_prep);
torture_assert_ntstatus_ok(tctx, status,
"PrepareShadowCopySet failed");
if (inject == TEST_FSRVP_TOUT_ADD_TO_SET) {
torture_assert_int_equal(tctx, r_scset_prep.out.result,
HRES_ERROR_V(HRES_E_INVALIDARG),
"PrepareShadowCopySet tout response");
goto done;
}
torture_assert_int_equal(tctx, r_scset_prep.out.result, 0,
"failed PrepareShadowCopySet response");
torture_comment(tctx, "%s: prepare completed in %llu secs\n",
GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
(unsigned long long)(time_mono(NULL) - start_time));
if (inject == TEST_FSRVP_TOUT_PREPARE) {
sleep_time = lpcfg_parm_int(tctx->lp_ctx, NULL, "fss",
"sequence timeout", 1800);
torture_comment(tctx, "sleeping for %d\n", sleep_time);
smb_msleep((sleep_time * 1000) + 500);
}
start_time = time_mono(NULL);
ZERO_STRUCT(r_scset_commit);
r_scset_commit.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
r_scset_commit.in.TimeOutInMilliseconds = (180 * 1000); /* win8 */
status = dcerpc_fss_CommitShadowCopySet_r(b, tmp_ctx, &r_scset_commit);
torture_assert_ntstatus_ok(tctx, status,
"CommitShadowCopySet failed");
if (inject == TEST_FSRVP_TOUT_PREPARE) {
torture_assert_int_equal(tctx, r_scset_commit.out.result,
HRES_ERROR_V(HRES_E_INVALIDARG),
"CommitShadowCopySet tout response");
goto done;
}
torture_assert_int_equal(tctx, r_scset_commit.out.result, 0,
"failed CommitShadowCopySet response");
torture_comment(tctx, "%s: commit completed in %llu secs\n",
GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
(unsigned long long)(time_mono(NULL) - start_time));
if (inject == TEST_FSRVP_TOUT_COMMIT) {
sleep_time = lpcfg_parm_int(tctx->lp_ctx, NULL, "fss",
"sequence timeout", 180);
torture_comment(tctx, "sleeping for %d\n", sleep_time);
smb_msleep((sleep_time * 1000) + 500);
} else if (inject == TEST_FSRVP_STOP_B4_EXPOSE) {
/* return partial snapshot information */
map = talloc_zero(tctx, struct fssagent_share_mapping_1);
map->ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
map->ShadowCopyId = *r_scset_add1.out.pShadowCopyId;
goto done;
}
start_time = time_mono(NULL);
ZERO_STRUCT(r_scset_expose);
r_scset_expose.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
r_scset_expose.in.TimeOutInMilliseconds = (120 * 1000); /* win8 */
status = dcerpc_fss_ExposeShadowCopySet_r(b, tmp_ctx, &r_scset_expose);
torture_assert_ntstatus_ok(tctx, status,
"ExposeShadowCopySet failed");
if (inject == TEST_FSRVP_TOUT_COMMIT) {
torture_assert_int_equal(tctx, r_scset_expose.out.result,
HRES_ERROR_V(HRES_E_INVALIDARG),
"ExposeShadowCopySet tout response");
goto done;
}
torture_assert_int_equal(tctx, r_scset_expose.out.result, 0,
"failed ExposeShadowCopySet response");
torture_comment(tctx, "%s: expose completed in %llu secs\n",
GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
(unsigned long long)(time_mono(NULL) - start_time));
ZERO_STRUCT(r_sharemap_get);
r_sharemap_get.in.ShadowCopyId = *r_scset_add1.out.pShadowCopyId;
r_sharemap_get.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
r_sharemap_get.in.ShareName = r_scset_add1.in.ShareName;
r_sharemap_get.in.Level = 1;
status = dcerpc_fss_GetShareMapping_r(b, tmp_ctx, &r_sharemap_get);
torture_assert_ntstatus_ok(tctx, status, "GetShareMapping failed");
torture_assert_int_equal(tctx, r_sharemap_get.out.result, 0,
"failed GetShareMapping response");
torture_comment(tctx, "%s(%s): %s is a snapshot of %s at %s\n",
GUID_string(tmp_ctx, &r_sharemap_get.out.ShareMapping->ShareMapping1->ShadowCopySetId),
GUID_string(tmp_ctx, &r_sharemap_get.out.ShareMapping->ShareMapping1->ShadowCopyId),
r_sharemap_get.out.ShareMapping->ShareMapping1->ShadowCopyShareName,
r_sharemap_get.out.ShareMapping->ShareMapping1->ShareNameUNC,
nt_time_string(tmp_ctx, r_sharemap_get.out.ShareMapping->ShareMapping1->tstamp));
map = talloc_zero(tctx, struct fssagent_share_mapping_1);
map->ShadowCopySetId = r_sharemap_get.out.ShareMapping->ShareMapping1->ShadowCopySetId;
map->ShadowCopyId = r_sharemap_get.out.ShareMapping->ShareMapping1->ShadowCopyId;
map->ShadowCopyShareName
= talloc_strdup(tctx, r_sharemap_get.out.ShareMapping->ShareMapping1->ShadowCopyShareName);
map->ShareNameUNC
= talloc_strdup(tctx, r_sharemap_get.out.ShareMapping->ShareMapping1->ShareNameUNC);
map->tstamp = r_sharemap_get.out.ShareMapping->ShareMapping1->tstamp;
torture_assert(tctx, !GUID_compare(&r_sharemap_get.in.ShadowCopySetId,
&map->ShadowCopySetId),
"sc_set GUID mismatch in GetShareMapping");
torture_assert(tctx, !GUID_compare(&r_sharemap_get.in.ShadowCopyId,
&map->ShadowCopyId),
"sc GUID mismatch in GetShareMapping");
done:
talloc_free(tmp_ctx);
*sc_map = map;
return true;
}
static bool test_fsrvp_sc_delete(struct torture_context *tctx,
struct dcerpc_pipe *p,
struct fssagent_share_mapping_1 *sc_map)
{
struct dcerpc_binding_handle *b = p->binding_handle;
struct fss_DeleteShareMapping r_sharemap_del;
NTSTATUS status;
ZERO_STRUCT(r_sharemap_del);
r_sharemap_del.in.ShadowCopySetId = sc_map->ShadowCopySetId;
r_sharemap_del.in.ShadowCopyId = sc_map->ShadowCopyId;
r_sharemap_del.in.ShareName = sc_map->ShareNameUNC;
status = dcerpc_fss_DeleteShareMapping_r(b, tctx, &r_sharemap_del);
torture_assert_ntstatus_ok(tctx, status, "DeleteShareMapping failed");
torture_assert_int_equal(tctx, r_sharemap_del.out.result, 0,
"failed DeleteShareMapping response");
return true;
}
static bool test_fsrvp_sc_create_simple(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fssagent_share_mapping_1 *sc_map;
/* no trailing backslash - should work. See note in cmd_fss.c */
char *share_unc = talloc_asprintf(tctx, "\\\\%s\\%s",
dcerpc_server_name(p), FSHARE);
torture_assert(tctx, test_fsrvp_sc_create(tctx, p, share_unc, TEST_FSRVP_TOUT_NONE, &sc_map),
"sc create");
torture_assert(tctx, test_fsrvp_sc_delete(tctx, p, sc_map), "sc del");
return true;
}
static bool test_fsrvp_sc_set_abort(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
char *share_unc = talloc_asprintf(tctx, "\\\\%s\\%s\\",
dcerpc_server_name(p), FSHARE);
struct dcerpc_binding_handle *b = p->binding_handle;
struct fss_IsPathSupported r_pathsupport_get;
struct fss_GetSupportedVersion r_version_get;
struct fss_SetContext r_context_set;
struct fss_StartShadowCopySet r_scset_start;
struct fss_AbortShadowCopySet r_scset_abort;
struct fss_AddToShadowCopySet r_scset_add;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tctx);
ZERO_STRUCT(r_pathsupport_get);
r_pathsupport_get.in.ShareName = share_unc;
status = dcerpc_fss_IsPathSupported_r(b, tmp_ctx, &r_pathsupport_get);
torture_assert_ntstatus_ok(tctx, status,
"IsPathSupported failed");
torture_assert(tctx, r_pathsupport_get.out.SupportedByThisProvider,
"path not supported");
ZERO_STRUCT(r_version_get);
status = dcerpc_fss_GetSupportedVersion_r(b, tmp_ctx, &r_version_get);
torture_assert_ntstatus_ok(tctx, status,
"GetSupportedVersion failed");
ZERO_STRUCT(r_context_set);
r_context_set.in.Context = FSRVP_CTX_BACKUP;
status = dcerpc_fss_SetContext_r(b, tmp_ctx, &r_context_set);
torture_assert_ntstatus_ok(tctx, status, "SetContext failed");
ZERO_STRUCT(r_scset_start);
r_scset_start.in.ClientShadowCopySetId = GUID_random();
status = dcerpc_fss_StartShadowCopySet_r(b, tmp_ctx, &r_scset_start);
torture_assert_ntstatus_ok(tctx, status,
"StartShadowCopySet failed");
ZERO_STRUCT(r_scset_abort);
r_scset_abort.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
status = dcerpc_fss_AbortShadowCopySet_r(b, tmp_ctx, &r_scset_abort);
torture_assert_ntstatus_ok(tctx, status,
"AbortShadowCopySet failed");
ZERO_STRUCT(r_scset_add);
r_scset_add.in.ClientShadowCopyId = GUID_random();
r_scset_add.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
r_scset_add.in.ShareName = share_unc;
status = dcerpc_fss_AddToShadowCopySet_r(b, tmp_ctx, &r_scset_add);
torture_assert_ntstatus_ok(tctx, status, "AddToShadowCopySet failed "
"following abort");
/*
* XXX Windows 8 server beta returns FSRVP_E_BAD_STATE here rather than
* FSRVP_E_BAD_ID / HRES_E_INVALIDARG.
*/
torture_assert(tctx, (r_scset_add.out.result != 0),
"incorrect AddToShadowCopySet response following abort");
talloc_free(tmp_ctx);
return true;
}
static bool test_fsrvp_bad_id(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fssagent_share_mapping_1 *sc_map;
struct dcerpc_binding_handle *b = p->binding_handle;
struct fss_DeleteShareMapping r_sharemap_del;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tctx);
char *share_unc = talloc_asprintf(tmp_ctx, "\\\\%s\\%s\\",
dcerpc_server_name(p), FSHARE);
torture_assert(tctx, test_fsrvp_sc_create(tctx, p, share_unc, TEST_FSRVP_TOUT_NONE, &sc_map),
"sc create");
ZERO_STRUCT(r_sharemap_del);
r_sharemap_del.in.ShadowCopySetId = sc_map->ShadowCopySetId;
r_sharemap_del.in.ShadowCopySetId.time_low++; /* bogus */
r_sharemap_del.in.ShadowCopyId = sc_map->ShadowCopyId;
r_sharemap_del.in.ShareName = sc_map->ShareNameUNC;
status = dcerpc_fss_DeleteShareMapping_r(b, tmp_ctx, &r_sharemap_del);
torture_assert_ntstatus_ok(tctx, status,
"DeleteShareMapping failed");
torture_assert_int_equal(tctx, r_sharemap_del.out.result,
FSRVP_E_OBJECT_NOT_FOUND,
"incorrect DeleteShareMapping response");
r_sharemap_del.in.ShadowCopySetId = sc_map->ShadowCopySetId;
r_sharemap_del.in.ShadowCopyId.time_mid++; /* bogus */
status = dcerpc_fss_DeleteShareMapping_r(b, tmp_ctx, &r_sharemap_del);
torture_assert_ntstatus_ok(tctx, status,
"DeleteShareMapping failed");
torture_assert_int_equal(tctx, r_sharemap_del.out.result,
HRES_ERROR_V(HRES_E_INVALIDARG),
"incorrect DeleteShareMapping response");
torture_assert(tctx, test_fsrvp_sc_delete(tctx, p, sc_map), "sc del");
talloc_free(sc_map);
talloc_free(tmp_ctx);
return true;
}
static bool test_fsrvp_sc_share_io(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fssagent_share_mapping_1 *sc_map;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tctx);
char *share_unc = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
dcerpc_server_name(p), FSHARE);
struct smb2_tree *tree_base;
struct smb2_tree *tree_snap;
struct smbcli_options options;
struct smb2_handle base_fh;
struct smb2_read r;
struct smb2_create io;
lpcfg_smbcli_options(tctx->lp_ctx, &options);
status = smb2_connect(tmp_ctx,
dcerpc_server_name(p),
lpcfg_smb_ports(tctx->lp_ctx),
FSHARE,
lpcfg_resolve_context(tctx->lp_ctx),
samba_cmdline_get_creds(),
&tree_base,
tctx->ev,
&options,
lpcfg_socket_options(tctx->lp_ctx),
lpcfg_gensec_settings(tctx, tctx->lp_ctx));
torture_assert_ntstatus_ok(tctx, status,
"Failed to connect to SMB2 share");
smb2_util_unlink(tree_base, FNAME);
status = torture_smb2_testfile(tree_base, FNAME, &base_fh);
torture_assert_ntstatus_ok(tctx, status, "base write open");
status = smb2_util_write(tree_base, base_fh, "pre-snap", 0,
sizeof("pre-snap"));
torture_assert_ntstatus_ok(tctx, status, "src write");
torture_assert(tctx, test_fsrvp_sc_create(tctx, p, share_unc, TEST_FSRVP_TOUT_NONE, &sc_map),
"sc create");
status = smb2_util_write(tree_base, base_fh, "post-snap", 0,
sizeof("post-snap"));
torture_assert_ntstatus_ok(tctx, status, "base write");
/* connect to snapshot share and verify pre-snapshot data */
status = smb2_connect(tmp_ctx,
dcerpc_server_name(p),
lpcfg_smb_ports(tctx->lp_ctx),
sc_map->ShadowCopyShareName,
lpcfg_resolve_context(tctx->lp_ctx),
samba_cmdline_get_creds(),
&tree_snap,
tctx->ev,
&options,
lpcfg_socket_options(tctx->lp_ctx),
lpcfg_gensec_settings(tctx, tctx->lp_ctx));
torture_assert_ntstatus_ok(tctx, status,
"Failed to connect to SMB2 shadow-copy share");
/* Windows server 8 allows RW open to succeed here for a ro snapshot */
ZERO_STRUCT(io);
io.in.desired_access = SEC_RIGHTS_FILE_READ;
io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
io.in.share_access =
NTCREATEX_SHARE_ACCESS_DELETE|
NTCREATEX_SHARE_ACCESS_READ|
NTCREATEX_SHARE_ACCESS_WRITE;
io.in.create_options = 0;
io.in.fname = FNAME;
status = smb2_create(tree_snap, tmp_ctx, &io);
torture_assert_ntstatus_ok(tctx, status, "snap read open");
ZERO_STRUCT(r);
r.in.file.handle = io.out.file.handle;
r.in.length = sizeof("pre-snap");
status = smb2_read(tree_snap, tmp_ctx, &r);
torture_assert_ntstatus_ok(tctx, status, "read");
torture_assert_u64_equal(tctx, r.out.data.length, r.in.length,
"read data len mismatch");
torture_assert_str_equal(tctx, (char *)r.out.data.data, "pre-snap",
"bad snapshot data");
torture_assert(tctx, test_fsrvp_sc_delete(tctx, p, sc_map), "sc del");
talloc_free(sc_map);
talloc_free(tmp_ctx);
return true;
}
static bool test_fsrvp_enum_snaps(struct torture_context *tctx,
TALLOC_CTX *mem_ctx,
struct smb2_tree *tree,
struct smb2_handle fh,
int *_count)
{
struct smb2_ioctl io;
NTSTATUS status;
ZERO_STRUCT(io);
io.level = RAW_IOCTL_SMB2;
io.in.file.handle = fh;
io.in.function = FSCTL_SRV_ENUM_SNAPS;
io.in.max_output_response = 16;
io.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
status = smb2_ioctl(tree, mem_ctx, &io);
torture_assert_ntstatus_ok(tctx, status, "enum ioctl");
*_count = IVAL(io.out.out.data, 0);
/* with max_output_response=16, no labels should be sent */
torture_assert_int_equal(tctx, IVAL(io.out.out.data, 4), 0,
"enum snaps labels");
/* TODO with 0 snaps, needed_data_count should be 0? */
if (*_count != 0) {
torture_assert(tctx, IVAL(io.out.out.data, 8) != 0,
"enum snaps needed non-zero");
}
return true;
}
static bool test_fsrvp_enum_created(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
struct fssagent_share_mapping_1 *sc_map;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tctx);
char *share_unc = talloc_asprintf(tmp_ctx, "\\\\%s\\%s\\",
dcerpc_server_name(p), FSHARE);
struct smb2_tree *tree_base;
struct smbcli_options options;
struct smb2_handle base_fh;
int count;
lpcfg_smbcli_options(tctx->lp_ctx, &options);
status = smb2_connect(tmp_ctx,
dcerpc_server_name(p),
lpcfg_smb_ports(tctx->lp_ctx),
FSHARE,
lpcfg_resolve_context(tctx->lp_ctx),
samba_cmdline_get_creds(),
&tree_base,
tctx->ev,
&options,
lpcfg_socket_options(tctx->lp_ctx),
lpcfg_gensec_settings(tctx, tctx->lp_ctx));
torture_assert_ntstatus_ok(tctx, status,
"Failed to connect to SMB2 share");
smb2_util_unlink(tree_base, FNAME);
status = torture_smb2_testfile(tree_base, FNAME, &base_fh);
torture_assert_ntstatus_ok(tctx, status, "base write open");
status = smb2_util_write(tree_base, base_fh, "pre-snap", 0,
sizeof("pre-snap"));
torture_assert_ntstatus_ok(tctx, status, "src write");
torture_assert(tctx,
test_fsrvp_enum_snaps(tctx, tmp_ctx, tree_base, base_fh,
&count),
"count");
torture_assert_int_equal(tctx, count, 0, "num snaps");
torture_assert(tctx, test_fsrvp_sc_create(tctx, p, share_unc, TEST_FSRVP_TOUT_NONE, &sc_map),
"sc create");
talloc_free(sc_map);
torture_assert(tctx,
test_fsrvp_enum_snaps(tctx, tmp_ctx, tree_base, base_fh,
&count),
"count");
/*
* Snapshots created via FSRVP on Windows Server 2012 are not added to
* the previous versions list, so it will fail here...
*/
torture_assert_int_equal(tctx, count, 1, "num snaps");
smb_msleep(1100); /* @GMT tokens have a 1 second resolution */
torture_assert(tctx, test_fsrvp_sc_create(tctx, p, share_unc, TEST_FSRVP_TOUT_NONE, &sc_map),
"sc create");
talloc_free(sc_map);
torture_assert(tctx,
test_fsrvp_enum_snaps(tctx, tmp_ctx, tree_base, base_fh,
&count),
"count");
torture_assert_int_equal(tctx, count, 2, "num snaps");
talloc_free(tmp_ctx);
return true;
}
static bool test_fsrvp_seq_timeout(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
int i;
struct fssagent_share_mapping_1 *sc_map;
char *share_unc = talloc_asprintf(tctx, "\\\\%s\\%s",
dcerpc_server_name(p), FSHARE);
for (i = TEST_FSRVP_TOUT_NONE; i <= TEST_FSRVP_TOUT_COMMIT; i++) {
torture_assert(tctx, test_fsrvp_sc_create(tctx, p, share_unc,
i, &sc_map),
"sc create");
/* only need to delete if create process didn't timeout */
if (i == TEST_FSRVP_TOUT_NONE) {
torture_assert(tctx, test_fsrvp_sc_delete(tctx, p, sc_map),
"sc del");
}
}
return true;
}
static bool test_fsrvp_share_sd(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
NTSTATUS status;
struct dcerpc_pipe *srvsvc_p;
struct srvsvc_NetShareGetInfo q;
struct srvsvc_NetShareSetInfo s;
struct srvsvc_NetShareInfo502 *info502;
struct fssagent_share_mapping_1 *sc_map;
struct fss_ExposeShadowCopySet r_scset_expose;
struct fss_GetShareMapping r_sharemap_get;
struct security_descriptor *sd_old;
struct security_descriptor *sd_base;
struct security_descriptor *sd_snap;
struct security_ace *ace;
int i;
int aces_found;
char *share_unc = talloc_asprintf(tctx, "\\\\%s\\%s",
dcerpc_server_name(p), FSHARE);
ZERO_STRUCT(q);
q.in.server_unc = dcerpc_server_name(p);
q.in.share_name = FSHARE;
q.in.level = 502;
status = torture_rpc_connection(tctx, &srvsvc_p, &ndr_table_srvsvc);
torture_assert_ntstatus_ok(tctx, status, "srvsvc rpc conn failed");
/* ensure srvsvc out pointers are allocated during unmarshalling */
srvsvc_p->conn->flags |= DCERPC_NDR_REF_ALLOC;
/* obtain the existing DACL for the base share */
status = dcerpc_srvsvc_NetShareGetInfo_r(srvsvc_p->binding_handle,
tctx, &q);
torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
torture_assert_werr_ok(tctx, q.out.result, "NetShareGetInfo failed");
info502 = q.out.info->info502;
/* back up the existing share SD, so it can be restored on completion */
sd_old = info502->sd_buf.sd;
sd_base = security_descriptor_copy(tctx, info502->sd_buf.sd);
torture_assert(tctx, sd_base != NULL, "sd dup");
torture_assert(tctx, sd_base->dacl != NULL, "no existing share DACL");
/* the Builtin_X_Operators placeholder ACEs need to be unique */
for (i = 0; i < sd_base->dacl->num_aces; i++) {
ace = &sd_base->dacl->aces[i];
if (dom_sid_equal(&ace->trustee,
&global_sid_Builtin_Backup_Operators)
|| dom_sid_equal(&ace->trustee,
&global_sid_Builtin_Print_Operators)) {
torture_skip(tctx, "placeholder ACE already exists\n");
}
}
/* add Backup_Operators placeholder ACE and set base share DACL */
ace = talloc_zero(tctx, struct security_ace);
ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace->access_mask = SEC_STD_SYNCHRONIZE;
ace->trustee = global_sid_Builtin_Backup_Operators;
status = security_descriptor_dacl_add(sd_base, ace);
torture_assert_ntstatus_ok(tctx, status,
"failed to add placeholder ACE to DACL");
info502->sd_buf.sd = sd_base;
info502->sd_buf.sd_size = ndr_size_security_descriptor(sd_base, 0);
ZERO_STRUCT(s);
s.in.server_unc = dcerpc_server_name(p);
s.in.share_name = FSHARE;
s.in.level = 502;
s.in.info = q.out.info;
status = dcerpc_srvsvc_NetShareSetInfo_r(srvsvc_p->binding_handle,
tctx, &s);
torture_assert_ntstatus_ok(tctx, status, "NetShareSetInfo failed");
torture_assert_werr_ok(tctx, s.out.result, "NetShareSetInfo failed");
/* create a snapshot, but don't expose yet */
torture_assert(tctx,
test_fsrvp_sc_create(tctx, p, share_unc,
TEST_FSRVP_STOP_B4_EXPOSE, &sc_map),
"sc create");
/*
* Add another unique placeholder ACE.
* By changing the share DACL between snapshot creation and exposure we
* can determine at which point the server clones the base share DACL.
*/
ace = talloc_zero(tctx, struct security_ace);
ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace->access_mask = SEC_STD_SYNCHRONIZE;
ace->trustee = global_sid_Builtin_Print_Operators;
status = security_descriptor_dacl_add(sd_base, ace);
torture_assert_ntstatus_ok(tctx, status,
"failed to add placeholder ACE to DACL");
info502->sd_buf.sd = sd_base;
info502->sd_buf.sd_size = ndr_size_security_descriptor(sd_base, 0);
ZERO_STRUCT(s);
s.in.server_unc = dcerpc_server_name(p);
s.in.share_name = FSHARE;
s.in.level = 502;
s.in.info = q.out.info;
status = dcerpc_srvsvc_NetShareSetInfo_r(srvsvc_p->binding_handle,
tctx, &s);
torture_assert_ntstatus_ok(tctx, status, "NetShareSetInfo failed");
torture_assert_werr_ok(tctx, s.out.result, "NetShareSetInfo failed");
/* expose the snapshot share and get the new share details */
ZERO_STRUCT(r_scset_expose);
r_scset_expose.in.ShadowCopySetId = sc_map->ShadowCopySetId;
r_scset_expose.in.TimeOutInMilliseconds = (120 * 1000); /* win8 */
status = dcerpc_fss_ExposeShadowCopySet_r(p->binding_handle, tctx,
&r_scset_expose);
torture_assert_ntstatus_ok(tctx, status,
"ExposeShadowCopySet failed");
torture_assert_int_equal(tctx, r_scset_expose.out.result, 0,
"failed ExposeShadowCopySet response");
ZERO_STRUCT(r_sharemap_get);
r_sharemap_get.in.ShadowCopyId = sc_map->ShadowCopyId;
r_sharemap_get.in.ShadowCopySetId = sc_map->ShadowCopySetId;
r_sharemap_get.in.ShareName = share_unc;
r_sharemap_get.in.Level = 1;
status = dcerpc_fss_GetShareMapping_r(p->binding_handle, tctx,
&r_sharemap_get);
torture_assert_ntstatus_ok(tctx, status, "GetShareMapping failed");
torture_assert_int_equal(tctx, r_sharemap_get.out.result, 0,
"failed GetShareMapping response");
talloc_free(sc_map);
sc_map = r_sharemap_get.out.ShareMapping->ShareMapping1;
/* restore the original base share ACL */
info502->sd_buf.sd = sd_old;
info502->sd_buf.sd_size = ndr_size_security_descriptor(sd_old, 0);
status = dcerpc_srvsvc_NetShareSetInfo_r(srvsvc_p->binding_handle,
tctx, &s);
torture_assert_ntstatus_ok(tctx, status, "NetShareSetInfo failed");
torture_assert_werr_ok(tctx, s.out.result, "NetShareSetInfo failed");
/* check for placeholder ACEs in the snapshot share DACL */
ZERO_STRUCT(q);
q.in.server_unc = dcerpc_server_name(p);
q.in.share_name = sc_map->ShadowCopyShareName;
q.in.level = 502;
status = dcerpc_srvsvc_NetShareGetInfo_r(srvsvc_p->binding_handle,
tctx, &q);
torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
torture_assert_werr_ok(tctx, q.out.result, "NetShareGetInfo failed");
info502 = q.out.info->info502;
sd_snap = info502->sd_buf.sd;
torture_assert(tctx, sd_snap != NULL, "sd");
torture_assert(tctx, sd_snap->dacl != NULL, "no snap share DACL");
aces_found = 0;
for (i = 0; i < sd_snap->dacl->num_aces; i++) {
ace = &sd_snap->dacl->aces[i];
if (dom_sid_equal(&ace->trustee,
&global_sid_Builtin_Backup_Operators)) {
torture_comment(tctx,
"found share ACE added before snapshot\n");
aces_found++;
} else if (dom_sid_equal(&ace->trustee,
&global_sid_Builtin_Print_Operators)) {
torture_comment(tctx,
"found share ACE added after snapshot\n");
aces_found++;
}
}
/*
* Expect snapshot share to match the base share DACL at the time of
* exposure, not at the time of snapshot creation. This is in line with
* Windows Server 2012 behaviour.
*/
torture_assert_int_equal(tctx, aces_found, 2,
"placeholder ACE missing from snap share DACL");
torture_assert(tctx, test_fsrvp_sc_delete(tctx, p, sc_map), "sc del");
return true;
}
static bool fsrvp_rpc_setup(struct torture_context *tctx, void **data)
{
NTSTATUS status;
struct torture_rpc_tcase *tcase = talloc_get_type(
tctx->active_tcase, struct torture_rpc_tcase);
struct torture_rpc_tcase_data *tcase_data;
*data = tcase_data = talloc_zero(tctx, struct torture_rpc_tcase_data);
tcase_data->credentials = samba_cmdline_get_creds();
status = torture_rpc_connection(tctx,
&(tcase_data->pipe),
tcase->table);
torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
/* XXX required, otherwise ndr out ptrs are not allocated */
tcase_data->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;
return true;
}
/*
testing of FSRVP (FSS agent)
*/
struct torture_suite *torture_rpc_fsrvp(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "fsrvp");
struct torture_rpc_tcase *tcase
= torture_suite_add_rpc_iface_tcase(suite, "fsrvp",
&ndr_table_FileServerVssAgent);
/* override torture_rpc_setup() to set DCERPC_NDR_REF_ALLOC */
tcase->tcase.setup = fsrvp_rpc_setup;
torture_rpc_tcase_add_test(tcase, "share_sd",
test_fsrvp_share_sd);
torture_rpc_tcase_add_test(tcase, "enum_created",
test_fsrvp_enum_created);
torture_rpc_tcase_add_test(tcase, "sc_share_io",
test_fsrvp_sc_share_io);
torture_rpc_tcase_add_test(tcase, "bad_id",
test_fsrvp_bad_id);
torture_rpc_tcase_add_test(tcase, "sc_set_abort",
test_fsrvp_sc_set_abort);
torture_rpc_tcase_add_test(tcase, "create_simple",
test_fsrvp_sc_create_simple);
torture_rpc_tcase_add_test(tcase, "set_ctx",
test_fsrvp_set_ctx);
torture_rpc_tcase_add_test(tcase, "get_version",
test_fsrvp_get_version);
torture_rpc_tcase_add_test(tcase, "is_path_supported",
test_fsrvp_is_path_supported);
torture_rpc_tcase_add_test(tcase, "seq_timeout",
test_fsrvp_seq_timeout);
return suite;
}
|