s3: remove duplicate fsctl fn definitions
[rusty/samba.git] / source4 / torture / smb2 / ioctl.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    test suite for SMB2 ioctl operations
5
6    Copyright (C) David Disseldorp 2011
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 "librpc/gen_ndr/security.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
28
29 #define FNAME "testfsctl.dat"
30
31 /*
32    basic testing of SMB2 shadow copy calls
33 */
34 static bool test_ioctl_get_shadow_copy(struct torture_context *torture,
35                                        struct smb2_tree *tree)
36 {
37         struct smb2_handle h;
38         uint8_t buf[100];
39         NTSTATUS status;
40         union smb_ioctl ioctl;
41         TALLOC_CTX *tmp_ctx = talloc_new(tree);
42
43         smb2_util_unlink(tree, FNAME);
44
45         status = torture_smb2_testfile(tree, FNAME, &h);
46         if (!NT_STATUS_IS_OK(status)) {
47                 printf("create write\n");
48                 return false;
49         }
50
51         ZERO_ARRAY(buf);
52         status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
53         if (!NT_STATUS_IS_OK(status)) {
54                 printf("failed write\n");
55                 return false;
56         }
57
58         ZERO_STRUCT(ioctl);
59         ioctl.smb2.level = RAW_IOCTL_SMB2;
60         ioctl.smb2.in.file.handle = h;
61         ioctl.smb2.in.function = FSCTL_SRV_ENUM_SNAPS;
62         ioctl.smb2.in.max_response_size = 16;
63         ioctl.smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
64
65         status = smb2_ioctl(tree, tmp_ctx, &ioctl.smb2);
66         if (!NT_STATUS_IS_OK(status)) {
67                 printf("FSCTL_SRV_ENUM_SNAPS failed\n");
68                 return false;
69         }
70
71         return true;
72 }
73
74 /*
75    basic testing of SMB2 ioctls
76 */
77 struct torture_suite *torture_smb2_ioctl_init(void)
78 {
79         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "ioctl");
80
81         torture_suite_add_1smb2_test(suite, "shadow_copy", test_ioctl_get_shadow_copy);
82
83         suite->description = talloc_strdup(suite, "SMB2-IOCTL tests");
84
85         return suite;
86 }
87