s4:torture:smb2: simplify the durable-v2.reopen2 test (using only one i/o struct)
[metze/samba/wip.git] / source4 / torture / smb2 / durable_v2_open.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    test suite for SMB2 version two of durable opens
5
6    Copyright (C) Michael Adam 2012
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "../libcli/smb/smbXcli_base.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
28 #include "librpc/ndr/libndr.h"
29
30 #define CHECK_VAL(v, correct) do { \
31         if ((v) != (correct)) { \
32                 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
33                                 __location__, #v, (int)v, (int)correct); \
34                 ret = false; \
35         }} while (0)
36
37 #define CHECK_STATUS(status, correct) do { \
38         if (!NT_STATUS_EQUAL(status, correct)) { \
39                 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
40                        nt_errstr(status), nt_errstr(correct)); \
41                 ret = false; \
42                 goto done; \
43         }} while (0)
44
45 #define CHECK_CREATED(__io, __created, __attribute)                     \
46         do {                                                            \
47                 CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
48                 CHECK_VAL((__io)->out.alloc_size, 0);                   \
49                 CHECK_VAL((__io)->out.size, 0);                         \
50                 CHECK_VAL((__io)->out.file_attr, (__attribute));        \
51                 CHECK_VAL((__io)->out.reserved2, 0);                    \
52         } while(0)
53
54 /**
55  * basic durable_open test.
56  * durable state should only be granted when requested
57  * along with a batch oplock or a handle lease.
58  *
59  * This test tests durable open with all possible oplock types.
60  */
61
62 struct durable_open_vs_oplock {
63         const char *level;
64         const char *share_mode;
65         bool durable;
66         bool persistent;
67 };
68
69 #define NUM_OPLOCK_TYPES 4
70 #define NUM_SHARE_MODES 8
71 #define NUM_OPLOCK_OPEN_TESTS ( NUM_OPLOCK_TYPES * NUM_SHARE_MODES )
72 static struct durable_open_vs_oplock durable_open_vs_oplock_table[NUM_OPLOCK_OPEN_TESTS] =
73 {
74         { "", "", false, false },
75         { "", "R", false, false },
76         { "", "W", false, false },
77         { "", "D", false, false },
78         { "", "RD", false, false },
79         { "", "RW", false, false },
80         { "", "WD", false, false },
81         { "", "RWD", false, false },
82
83         { "s", "", false, false },
84         { "s", "R", false, false },
85         { "s", "W", false, false },
86         { "s", "D", false, false },
87         { "s", "RD", false, false },
88         { "s", "RW", false, false },
89         { "s", "WD", false, false },
90         { "s", "RWD", false, false },
91
92         { "x", "", false, false },
93         { "x", "R", false, false },
94         { "x", "W", false, false },
95         { "x", "D", false, false },
96         { "x", "RD", false, false },
97         { "x", "RW", false, false },
98         { "x", "WD", false, false },
99         { "x", "RWD", false, false },
100
101         { "b", "", true, false },
102         { "b", "R", true, false },
103         { "b", "W", true, false },
104         { "b", "D", true, false },
105         { "b", "RD", true, false },
106         { "b", "RW", true, false },
107         { "b", "WD", true, false },
108         { "b", "RWD", true, false },
109 };
110
111 static bool test_one_durable_v2_open_oplock(struct torture_context *tctx,
112                                             struct smb2_tree *tree,
113                                             const char *fname,
114                                             bool request_persistent,
115                                             struct durable_open_vs_oplock test)
116 {
117         NTSTATUS status;
118         TALLOC_CTX *mem_ctx = talloc_new(tctx);
119         struct smb2_handle _h;
120         struct smb2_handle *h = NULL;
121         bool ret = true;
122         struct smb2_create io;
123
124         smb2_util_unlink(tree, fname);
125
126         smb2_oplock_create_share(&io, fname,
127                                  smb2_util_share_access(test.share_mode),
128                                  smb2_util_oplock_level(test.level));
129         io.in.durable_open = false;
130         io.in.durable_open_v2 = true;
131         io.in.persistent_open = request_persistent;
132         io.in.create_guid = GUID_random();
133
134         status = smb2_create(tree, mem_ctx, &io);
135         CHECK_STATUS(status, NT_STATUS_OK);
136         _h = io.out.file.handle;
137         h = &_h;
138         CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
139         CHECK_VAL(io.out.durable_open, false);
140         CHECK_VAL(io.out.durable_open_v2, test.durable);
141         CHECK_VAL(io.out.persistent_open, test.persistent);
142         CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level(test.level));
143
144 done:
145         if (h != NULL) {
146                 smb2_util_close(tree, *h);
147         }
148         smb2_util_unlink(tree, fname);
149         talloc_free(mem_ctx);
150
151         return ret;
152 }
153
154 static bool test_durable_v2_open_oplock_table(struct torture_context *tctx,
155                                               struct smb2_tree *tree,
156                                               const char *fname,
157                                               bool request_persistent,
158                                               struct durable_open_vs_oplock *table,
159                                               uint8_t num_tests)
160 {
161         bool ret = true;
162         uint8_t i;
163
164         smb2_util_unlink(tree, fname);
165
166         for (i = 0; i < num_tests; i++) {
167                 ret = test_one_durable_v2_open_oplock(tctx,
168                                                       tree,
169                                                       fname,
170                                                       request_persistent,
171                                                       table[i]);
172                 if (ret == false) {
173                         goto done;
174                 }
175         }
176
177 done:
178         smb2_util_unlink(tree, fname);
179
180         return ret;
181 }
182
183 bool test_durable_v2_open_oplock(struct torture_context *tctx,
184                                  struct smb2_tree *tree)
185 {
186         bool ret;
187         char fname[256];
188
189         /* Choose a random name in case the state is left a little funky. */
190         snprintf(fname, 256, "durable_open_oplock_%s.dat",
191                  generate_random_str(tctx, 8));
192
193         ret = test_durable_v2_open_oplock_table(tctx, tree, fname,
194                                                 false, /* request_persistent */
195                                                 durable_open_vs_oplock_table,
196                                                 NUM_OPLOCK_OPEN_TESTS);
197
198         talloc_free(tree);
199
200         return ret;
201 }
202
203 /**
204  * basic durable handle open test.
205  * persistent state should only be granted when requested
206  * along with a batch oplock or a handle lease.
207  *
208  * This test tests persistent open with all valid lease types.
209  */
210
211 struct durable_open_vs_lease {
212         const char *type;
213         const char *share_mode;
214         bool durable;
215         bool persistent;
216 };
217
218 #define NUM_LEASE_TYPES 5
219 #define NUM_LEASE_OPEN_TESTS ( NUM_LEASE_TYPES * NUM_SHARE_MODES )
220 static struct durable_open_vs_lease durable_open_vs_lease_table[NUM_LEASE_OPEN_TESTS] =
221 {
222         { "", "", false, false },
223         { "", "R", false, false },
224         { "", "W", false, false },
225         { "", "D", false, false },
226         { "", "RW", false, false },
227         { "", "RD", false, false },
228         { "", "WD", false, false },
229         { "", "RWD", false, false },
230
231         { "R", "", false, false },
232         { "R", "R", false, false },
233         { "R", "W", false, false },
234         { "R", "D", false, false },
235         { "R", "RW", false, false },
236         { "R", "RD", false, false },
237         { "R", "DW", false, false },
238         { "R", "RWD", false, false },
239
240         { "RW", "", false, false },
241         { "RW", "R", false, false },
242         { "RW", "W", false, false },
243         { "RW", "D", false, false },
244         { "RW", "RW", false, false },
245         { "RW", "RD", false, false },
246         { "RW", "WD", false, false },
247         { "RW", "RWD", false, false },
248
249         { "RH", "", true, false },
250         { "RH", "R", true, false },
251         { "RH", "W", true, false },
252         { "RH", "D", true, false },
253         { "RH", "RW", true, false },
254         { "RH", "RD", true, false },
255         { "RH", "WD", true, false },
256         { "RH", "RWD", true, false },
257
258         { "RHW", "", true, false },
259         { "RHW", "R", true, false },
260         { "RHW", "W", true, false },
261         { "RHW", "D", true, false },
262         { "RHW", "RW", true, false },
263         { "RHW", "RD", true, false },
264         { "RHW", "WD", true, false },
265         { "RHW", "RWD", true, false },
266 };
267
268 static bool test_one_durable_v2_open_lease(struct torture_context *tctx,
269                                            struct smb2_tree *tree,
270                                            const char *fname,
271                                            bool request_persistent,
272                                            struct durable_open_vs_lease test)
273 {
274         NTSTATUS status;
275         TALLOC_CTX *mem_ctx = talloc_new(tctx);
276         struct smb2_handle _h;
277         struct smb2_handle *h = NULL;
278         bool ret = true;
279         struct smb2_create io;
280         struct smb2_lease ls;
281         uint64_t lease;
282
283         smb2_util_unlink(tree, fname);
284
285         lease = random();
286
287         smb2_lease_create_share(&io, &ls, false /* dir */, fname,
288                                 smb2_util_share_access(test.share_mode),
289                                 lease,
290                                 smb2_util_lease_state(test.type));
291         io.in.durable_open = false;
292         io.in.durable_open_v2 = true;
293         io.in.persistent_open = request_persistent;
294         io.in.create_guid = GUID_random();
295
296         status = smb2_create(tree, mem_ctx, &io);
297         CHECK_STATUS(status, NT_STATUS_OK);
298         _h = io.out.file.handle;
299         h = &_h;
300         CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
301         CHECK_VAL(io.out.durable_open, false);
302         CHECK_VAL(io.out.durable_open_v2, test.durable);
303         CHECK_VAL(io.out.persistent_open, test.persistent);
304         CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
305         CHECK_VAL(io.out.lease_response.lease_key.data[0], lease);
306         CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease);
307         CHECK_VAL(io.out.lease_response.lease_state,
308                   smb2_util_lease_state(test.type));
309 done:
310         if (h != NULL) {
311                 smb2_util_close(tree, *h);
312         }
313         smb2_util_unlink(tree, fname);
314         talloc_free(mem_ctx);
315
316         return ret;
317 }
318
319 static bool test_durable_v2_open_lease_table(struct torture_context *tctx,
320                                              struct smb2_tree *tree,
321                                              const char *fname,
322                                              bool request_persistent,
323                                              struct durable_open_vs_lease *table,
324                                              uint8_t num_tests)
325 {
326         bool ret = true;
327         uint8_t i;
328
329         smb2_util_unlink(tree, fname);
330
331         for (i = 0; i < num_tests; i++) {
332                 ret = test_one_durable_v2_open_lease(tctx,
333                                                      tree,
334                                                      fname,
335                                                      request_persistent,
336                                                      table[i]);
337                 if (ret == false) {
338                         goto done;
339                 }
340         }
341
342 done:
343         smb2_util_unlink(tree, fname);
344
345         return ret;
346 }
347
348 bool test_durable_v2_open_lease(struct torture_context *tctx,
349                                 struct smb2_tree *tree)
350 {
351         char fname[256];
352         bool ret = true;
353         uint32_t caps;
354
355         caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
356         if (!(caps & SMB2_CAP_LEASING)) {
357                 torture_skip(tctx, "leases are not supported");
358         }
359
360         /* Choose a random name in case the state is left a little funky. */
361         snprintf(fname, 256, "durable_open_lease_%s.dat", generate_random_str(tctx, 8));
362
363         ret = test_durable_v2_open_lease_table(tctx, tree, fname,
364                                                false, /* request_persistent */
365                                                durable_open_vs_lease_table,
366                                                NUM_LEASE_OPEN_TESTS);
367
368         talloc_free(tree);
369         return ret;
370 }
371
372 /**
373  * basic test for doing a durable open
374  * and do a durable reopen on the same connection
375  * while the first open is still active (fails)
376  */
377 bool test_durable_v2_open_reopen1(struct torture_context *tctx,
378                                   struct smb2_tree *tree)
379 {
380         NTSTATUS status;
381         TALLOC_CTX *mem_ctx = talloc_new(tctx);
382         char fname[256];
383         struct smb2_handle _h;
384         struct smb2_handle *h = NULL;
385         struct smb2_create io;
386         struct GUID create_guid = GUID_random();
387         bool ret = true;
388
389         /* Choose a random name in case the state is left a little funky. */
390         snprintf(fname, 256, "durable_v2_open_reopen1_%s.dat",
391                  generate_random_str(tctx, 8));
392
393         smb2_util_unlink(tree, fname);
394
395         smb2_oplock_create_share(&io, fname,
396                                  smb2_util_share_access(""),
397                                  smb2_util_oplock_level("b"));
398         io.in.durable_open = false;
399         io.in.durable_open_v2 = true;
400         io.in.persistent_open = false;
401         io.in.create_guid = create_guid;
402         io.in.timeout = UINT32_MAX;
403
404         status = smb2_create(tree, mem_ctx, &io);
405         CHECK_STATUS(status, NT_STATUS_OK);
406         _h = io.out.file.handle;
407         h = &_h;
408         CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
409         CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
410         CHECK_VAL(io.out.durable_open, false);
411         CHECK_VAL(io.out.durable_open_v2, true);
412         CHECK_VAL(io.out.persistent_open, false);
413         CHECK_VAL(io.out.timeout, io.in.timeout);
414
415         /* try a durable reconnect while the file is still open */
416         ZERO_STRUCT(io);
417         io.in.fname = "";
418         io.in.durable_handle_v2 = h;
419         io.in.create_guid = create_guid;
420         status = smb2_create(tree, mem_ctx, &io);
421         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
422
423 done:
424         if (h != NULL) {
425                 smb2_util_close(tree, *h);
426         }
427
428         smb2_util_unlink(tree, fname);
429
430         talloc_free(tree);
431
432         talloc_free(mem_ctx);
433
434         return ret;
435 }
436
437 /**
438  * basic test for doing a durable open
439  * tcp disconnect, reconnect, do a durable reopen (succeeds)
440  */
441 bool test_durable_v2_open_reopen2(struct torture_context *tctx,
442                                   struct smb2_tree *tree)
443 {
444         NTSTATUS status;
445         TALLOC_CTX *mem_ctx = talloc_new(tctx);
446         char fname[256];
447         struct smb2_handle _h;
448         struct smb2_handle *h = NULL;
449         struct smb2_create io;
450         struct GUID create_guid = GUID_random();
451         bool ret = true;
452
453         /* Choose a random name in case the state is left a little funky. */
454         snprintf(fname, 256, "durable_v2_open_reopen2_%s.dat",
455                  generate_random_str(tctx, 8));
456
457         smb2_util_unlink(tree, fname);
458
459         smb2_oplock_create_share(&io, fname,
460                                  smb2_util_share_access(""),
461                                  smb2_util_oplock_level("b"));
462         io.in.durable_open = false;
463         io.in.durable_open_v2 = true;
464         io.in.persistent_open = false;
465         io.in.create_guid = create_guid;
466         io.in.timeout = UINT32_MAX;
467
468         status = smb2_create(tree, mem_ctx, &io);
469         CHECK_STATUS(status, NT_STATUS_OK);
470         _h = io.out.file.handle;
471         h = &_h;
472         CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
473         CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
474         CHECK_VAL(io.out.durable_open, false);
475         CHECK_VAL(io.out.durable_open_v2, true);
476         CHECK_VAL(io.out.persistent_open, false);
477         CHECK_VAL(io.out.timeout, io.in.timeout);
478
479         /* disconnect, reconnect and then do durable reopen */
480         talloc_free(tree);
481         tree = NULL;
482
483         if (!torture_smb2_connection(tctx, &tree)) {
484                 torture_warning(tctx, "couldn't reconnect, bailing\n");
485                 ret = false;
486                 goto done;
487         }
488
489         ZERO_STRUCT(io);
490         io.in.fname = "";
491         io.in.durable_handle_v2 = h;
492         status = smb2_create(tree, mem_ctx, &io);
493         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
494
495         ZERO_STRUCT(io);
496         io.in.fname = "__non_existing_fname__";
497         io.in.durable_handle_v2 = h;
498         status = smb2_create(tree, mem_ctx, &io);
499         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
500
501         ZERO_STRUCT(io);
502         io.in.fname = fname;
503         io.in.durable_handle_v2 = h;
504         status = smb2_create(tree, mem_ctx, &io);
505         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
506
507         ZERO_STRUCT(io);
508         /*
509          * These are completely ignored by the server
510          */
511         io.in.security_flags = 0x78;
512         io.in.oplock_level = 0x78;
513         io.in.impersonation_level = 0x12345678;
514         io.in.create_flags = 0x12345678;
515         io.in.reserved = 0x12345678;
516         io.in.desired_access = 0x12345678;
517         io.in.file_attributes = 0x12345678;
518         io.in.share_access = 0x12345678;
519         io.in.create_disposition = 0x12345678;
520         io.in.create_options = 0x12345678;
521         io.in.fname = "__non_existing_fname__";
522
523         /*
524          * only io.in.durable_handle_v2 and
525          * io.in.create_guid are checked
526          */
527         io.in.durable_open_v2 = false;
528         io.in.durable_handle_v2 = h;
529         io.in.create_guid = create_guid;
530         h = NULL;
531
532         status = smb2_create(tree, mem_ctx, &io);
533         CHECK_STATUS(status, NT_STATUS_OK);
534         CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
535         CHECK_VAL(io.out.durable_open, false);
536         CHECK_VAL(io.out.durable_open_v2, true);
537         CHECK_VAL(io.out.persistent_open, false);
538         CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
539         _h = io.out.file.handle;
540         h = &_h;
541
542 done:
543         if (h != NULL) {
544                 smb2_util_close(tree, *h);
545         }
546
547         smb2_util_unlink(tree, fname);
548
549         talloc_free(tree);
550
551         talloc_free(mem_ctx);
552
553         return ret;
554 }
555
556 /**
557  * basic persistent open test.
558  *
559  * This test tests durable open with all possible oplock types.
560  */
561
562 struct durable_open_vs_oplock persistent_open_oplock_ca_table[NUM_OPLOCK_OPEN_TESTS] =
563 {
564         { "", "", true, true },
565         { "", "R", true, true },
566         { "", "W", true, true },
567         { "", "D", true, true },
568         { "", "RD", true, true },
569         { "", "RW", true, true },
570         { "", "WD", true, true },
571         { "", "RWD", true, true },
572
573         { "s", "", true, true },
574         { "s", "R", true, true },
575         { "s", "W", true, true },
576         { "s", "D", true, true },
577         { "s", "RD", true, true },
578         { "s", "RW", true, true },
579         { "s", "WD", true, true },
580         { "s", "RWD", true, true },
581
582         { "x", "", true, true },
583         { "x", "R", true, true },
584         { "x", "W", true, true },
585         { "x", "D", true, true },
586         { "x", "RD", true, true },
587         { "x", "RW", true, true },
588         { "x", "WD", true, true },
589         { "x", "RWD", true, true },
590
591         { "b", "", true, true },
592         { "b", "R", true, true },
593         { "b", "W", true, true },
594         { "b", "D", true, true },
595         { "b", "RD", true, true },
596         { "b", "RW", true, true },
597         { "b", "WD", true, true },
598         { "b", "RWD", true, true },
599 };
600
601 bool test_persistent_open_oplock(struct torture_context *tctx,
602                                  struct smb2_tree *tree)
603 {
604         char fname[256];
605         bool ret = true;
606         uint32_t share_capabilities;
607         bool share_is_ca = false;
608         struct durable_open_vs_oplock *table;
609
610         /* Choose a random name in case the state is left a little funky. */
611         snprintf(fname, 256, "persistent_open_oplock_%s.dat", generate_random_str(tctx, 8));
612
613         share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli);
614         share_is_ca = share_capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY;
615
616         if (share_is_ca) {
617                 table = persistent_open_oplock_ca_table;
618         } else {
619                 table = durable_open_vs_oplock_table;
620         }
621
622         ret = test_durable_v2_open_oplock_table(tctx, tree, fname,
623                                                 true, /* request_persistent */
624                                                 table,
625                                                 NUM_OPLOCK_OPEN_TESTS);
626
627         talloc_free(tree);
628
629         return ret;
630 }
631
632 /**
633  * basic persistent handle open test.
634  * persistent state should only be granted when requested
635  * along with a batch oplock or a handle lease.
636  *
637  * This test tests persistent open with all valid lease types.
638  */
639
640 struct durable_open_vs_lease persistent_open_lease_ca_table[NUM_LEASE_OPEN_TESTS] =
641 {
642         { "", "", true, true },
643         { "", "R", true, true },
644         { "", "W", true, true },
645         { "", "D", true, true },
646         { "", "RW", true, true },
647         { "", "RD", true, true },
648         { "", "WD", true, true },
649         { "", "RWD", true, true },
650
651         { "R", "", true, true },
652         { "R", "R", true, true },
653         { "R", "W", true, true },
654         { "R", "D", true, true },
655         { "R", "RW", true, true },
656         { "R", "RD", true, true },
657         { "R", "DW", true, true },
658         { "R", "RWD", true, true },
659
660         { "RW", "", true, true },
661         { "RW", "R", true, true },
662         { "RW", "W", true, true },
663         { "RW", "D", true, true },
664         { "RW", "RW", true, true },
665         { "RW", "RD", true, true },
666         { "RW", "WD", true, true },
667         { "RW", "RWD", true, true },
668
669         { "RH", "", true, true },
670         { "RH", "R", true, true },
671         { "RH", "W", true, true },
672         { "RH", "D", true, true },
673         { "RH", "RW", true, true },
674         { "RH", "RD", true, true },
675         { "RH", "WD", true, true },
676         { "RH", "RWD", true, true },
677
678         { "RHW", "", true, true },
679         { "RHW", "R", true, true },
680         { "RHW", "W", true, true },
681         { "RHW", "D", true, true },
682         { "RHW", "RW", true, true },
683         { "RHW", "RD", true, true },
684         { "RHW", "WD", true, true },
685         { "RHW", "RWD", true, true },
686 };
687
688 bool test_persistent_open_lease(struct torture_context *tctx,
689                                 struct smb2_tree *tree)
690 {
691         char fname[256];
692         bool ret = true;
693         uint32_t caps;
694         uint32_t share_capabilities;
695         bool share_is_ca;
696         struct durable_open_vs_lease *table;
697
698         caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
699         if (!(caps & SMB2_CAP_LEASING)) {
700                 torture_skip(tctx, "leases are not supported");
701         }
702
703         /* Choose a random name in case the state is left a little funky. */
704         snprintf(fname, 256, "persistent_open_lease_%s.dat", generate_random_str(tctx, 8));
705
706         share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli);
707         share_is_ca = share_capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY;
708
709         if (share_is_ca) {
710                 table = persistent_open_lease_ca_table;
711         } else {
712                 table = durable_open_vs_lease_table;
713         }
714
715         ret = test_durable_v2_open_lease_table(tctx, tree, fname,
716                                                true, /* request_persistent */
717                                                table,
718                                                NUM_LEASE_OPEN_TESTS);
719
720         talloc_free(tree);
721
722         return ret;
723 }
724
725 struct torture_suite *torture_smb2_durable_v2_open_init(void)
726 {
727         struct torture_suite *suite =
728             torture_suite_create(talloc_autofree_context(), "durable-v2-open");
729
730         torture_suite_add_1smb2_test(suite, "open-oplock", test_durable_v2_open_oplock);
731         torture_suite_add_1smb2_test(suite, "open-lease", test_durable_v2_open_lease);
732         torture_suite_add_1smb2_test(suite, "reopen1", test_durable_v2_open_reopen1);
733         torture_suite_add_1smb2_test(suite, "reopen2", test_durable_v2_open_reopen2);
734         torture_suite_add_1smb2_test(suite, "persistent-open-oplock", test_persistent_open_oplock);
735         torture_suite_add_1smb2_test(suite, "persistent-open-lease", test_persistent_open_lease);
736
737         suite->description = talloc_strdup(suite, "SMB2-DURABLE-V2-OPEN tests");
738
739         return suite;
740 }