s4-torture: add test for interface information retrieval for multichannel.
[mimir/samba-autobuild/.git] / source4 / torture / smb2 / multichannel.c
1 /*
2  * Unix SMB/CIFS implementation.
3  *
4  * test SMB2 multichannel operations
5  *
6  * Copyright (C) Guenther Deschner, 2016
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 "torture/torture.h"
26 #include "torture/util.h"
27 #include "torture/smb2/proto.h"
28 #include "libcli/security/security.h"
29 #include "librpc/gen_ndr/ndr_security.h"
30 #include "librpc/gen_ndr/ndr_ioctl.h"
31 #include "../libcli/smb/smbXcli_base.h"
32
33 #define CHECK_STATUS(status, correct) do { \
34         if (!NT_STATUS_EQUAL(status, correct)) { \
35                 torture_result(tctx, TORTURE_FAIL, \
36                         "(%s) Incorrect status %s - should be %s\n", \
37                          __location__, nt_errstr(status), nt_errstr(correct)); \
38                 return false; \
39         } } while (0)
40
41 static bool test_ioctl_network_interface_info(struct torture_context *tctx,
42                                               struct smb2_tree *tree,
43                                               struct fsctl_net_iface_info *info)
44 {
45         union smb_ioctl ioctl;
46         struct smb2_handle fh;
47         uint32_t caps;
48
49         caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
50         if (!(caps & SMB2_CAP_MULTI_CHANNEL)) {
51                 torture_skip(tctx,
52                             "server doesn't support SMB2_CAP_MULTI_CHANNEL\n");
53         }
54
55         ZERO_STRUCT(ioctl);
56
57         ioctl.smb2.level = RAW_IOCTL_SMB2;
58
59         fh.data[0] = UINT64_MAX;
60         fh.data[1] = UINT64_MAX;
61
62         ioctl.smb2.in.file.handle = fh;
63         ioctl.smb2.in.function = FSCTL_QUERY_NETWORK_INTERFACE_INFO;
64         /* Windows client sets this to 64KiB */
65         ioctl.smb2.in.max_output_response = 0x10000;
66         ioctl.smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
67
68         torture_assert_ntstatus_ok(tctx,
69                 smb2_ioctl(tree, tctx, &ioctl.smb2),
70                 "FSCTL_QUERY_NETWORK_INTERFACE_INFO failed");
71
72         torture_assert(tctx,
73                 (ioctl.smb2.out.out.length != 0),
74                 "no interface info returned???");
75
76         torture_assert_ndr_success(tctx,
77                 ndr_pull_struct_blob(&ioctl.smb2.out.out, tctx, info,
78                         (ndr_pull_flags_fn_t)ndr_pull_fsctl_net_iface_info),
79                 "failed to ndr pull");
80
81         if (DEBUGLVL(1)) {
82                 NDR_PRINT_DEBUG(fsctl_net_iface_info, info);
83         }
84
85         return true;
86 }
87
88 static bool test_multichannel_interface_info(struct torture_context *tctx,
89                                              struct smb2_tree *tree)
90 {
91         struct fsctl_net_iface_info info;
92
93         return test_ioctl_network_interface_info(tctx, tree, &info);
94 }
95
96 struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx)
97 {
98         struct torture_suite *suite = torture_suite_create(ctx, "multichannel");
99
100         torture_suite_add_1smb2_test(suite, "interface_info",
101                                      test_multichannel_interface_info);
102
103         suite->description = talloc_strdup(suite, "SMB2 Multichannel tests");
104
105         return suite;
106 }