1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | ioctl individual test suite
|
---|
4 | Copyright (C) Andrew Tridgell 2003
|
---|
5 | Copyright (C) James J Myers 2003 <myersjj@samba.org>
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 3 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 | #include "libcli/raw/ioctl.h"
|
---|
23 | #include "libcli/raw/libcliraw.h"
|
---|
24 | #include "libcli/raw/raw_proto.h"
|
---|
25 | #include "libcli/libcli.h"
|
---|
26 | #include "torture/util.h"
|
---|
27 |
|
---|
28 | #define BASEDIR "\\rawioctl"
|
---|
29 |
|
---|
30 | #define CHECK_STATUS(status, correct) do { \
|
---|
31 | if (!NT_STATUS_EQUAL(status, correct)) { \
|
---|
32 | printf("(%d) Incorrect status %s - should be %s\n", \
|
---|
33 | __LINE__, nt_errstr(status), nt_errstr(correct)); \
|
---|
34 | ret = false; \
|
---|
35 | goto done; \
|
---|
36 | }} while (0)
|
---|
37 |
|
---|
38 |
|
---|
39 | /* test some ioctls */
|
---|
40 | static bool test_ioctl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
|
---|
41 | {
|
---|
42 | union smb_ioctl ctl;
|
---|
43 | int fnum;
|
---|
44 | NTSTATUS status;
|
---|
45 | bool ret = true;
|
---|
46 | const char *fname = BASEDIR "\\test.dat";
|
---|
47 |
|
---|
48 | printf("TESTING IOCTL FUNCTIONS\n");
|
---|
49 |
|
---|
50 | fnum = create_complex_file(cli, mem_ctx, fname);
|
---|
51 | if (fnum == -1) {
|
---|
52 | printf("Failed to create test.dat - %s\n", smbcli_errstr(cli->tree));
|
---|
53 | ret = false;
|
---|
54 | goto done;
|
---|
55 | }
|
---|
56 |
|
---|
57 | printf("Trying 0xFFFF\n");
|
---|
58 | ctl.ioctl.level = RAW_IOCTL_IOCTL;
|
---|
59 | ctl.ioctl.in.file.fnum = fnum;
|
---|
60 | ctl.ioctl.in.request = 0xFFFF;
|
---|
61 |
|
---|
62 | status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
|
---|
63 | CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
|
---|
64 |
|
---|
65 | printf("Trying QUERY_JOB_INFO\n");
|
---|
66 | ctl.ioctl.level = RAW_IOCTL_IOCTL;
|
---|
67 | ctl.ioctl.in.file.fnum = fnum;
|
---|
68 | ctl.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
|
---|
69 |
|
---|
70 | status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
|
---|
71 | CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
|
---|
72 |
|
---|
73 | printf("Trying bad handle\n");
|
---|
74 | ctl.ioctl.in.file.fnum = fnum+1;
|
---|
75 | status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
|
---|
76 | CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
|
---|
77 |
|
---|
78 | done:
|
---|
79 | smbcli_close(cli->tree, fnum);
|
---|
80 | return ret;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /* test some filesystem control functions */
|
---|
84 | static bool test_fsctl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
|
---|
85 | {
|
---|
86 | int fnum;
|
---|
87 | NTSTATUS status;
|
---|
88 | bool ret = true;
|
---|
89 | const char *fname = BASEDIR "\\test.dat";
|
---|
90 | union smb_ioctl nt;
|
---|
91 |
|
---|
92 | printf("\nTESTING FSCTL FUNCTIONS\n");
|
---|
93 |
|
---|
94 | fnum = create_complex_file(cli, mem_ctx, fname);
|
---|
95 | if (fnum == -1) {
|
---|
96 | printf("Failed to create test.dat - %s\n", smbcli_errstr(cli->tree));
|
---|
97 | ret = false;
|
---|
98 | goto done;
|
---|
99 | }
|
---|
100 |
|
---|
101 | printf("Trying FSCTL_FIND_FILES_BY_SID\n");
|
---|
102 | nt.ioctl.level = RAW_IOCTL_NTIOCTL;
|
---|
103 | nt.ntioctl.in.function = FSCTL_FIND_FILES_BY_SID;
|
---|
104 | nt.ntioctl.in.file.fnum = fnum;
|
---|
105 | nt.ntioctl.in.fsctl = true;
|
---|
106 | nt.ntioctl.in.filter = 0;
|
---|
107 | nt.ntioctl.in.max_data = 0;
|
---|
108 | nt.ntioctl.in.blob = data_blob(NULL, 1024);
|
---|
109 | /* definitely not a sid... */
|
---|
110 | generate_random_buffer(nt.ntioctl.in.blob.data,
|
---|
111 | nt.ntioctl.in.blob.length);
|
---|
112 | nt.ntioctl.in.blob.data[1] = 15+1;
|
---|
113 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
---|
114 | if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
|
---|
115 | !NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED) &&
|
---|
116 | !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
|
---|
117 | printf("Got unexpected error code: %s\n",
|
---|
118 | nt_errstr(status));
|
---|
119 | ret = false;
|
---|
120 | goto done;
|
---|
121 | }
|
---|
122 |
|
---|
123 | printf("trying sparse file\n");
|
---|
124 | nt.ioctl.level = RAW_IOCTL_NTIOCTL;
|
---|
125 | nt.ntioctl.in.function = FSCTL_SET_SPARSE;
|
---|
126 | nt.ntioctl.in.file.fnum = fnum;
|
---|
127 | nt.ntioctl.in.fsctl = true;
|
---|
128 | nt.ntioctl.in.filter = 0;
|
---|
129 | nt.ntioctl.in.max_data = 0;
|
---|
130 | nt.ntioctl.in.blob = data_blob(NULL, 0);
|
---|
131 |
|
---|
132 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
---|
133 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
134 |
|
---|
135 | printf("trying batch oplock\n");
|
---|
136 | nt.ioctl.level = RAW_IOCTL_NTIOCTL;
|
---|
137 | nt.ntioctl.in.function = FSCTL_REQUEST_BATCH_OPLOCK;
|
---|
138 | nt.ntioctl.in.file.fnum = fnum;
|
---|
139 | nt.ntioctl.in.fsctl = true;
|
---|
140 | nt.ntioctl.in.filter = 0;
|
---|
141 | nt.ntioctl.in.max_data = 0;
|
---|
142 | nt.ntioctl.in.blob = data_blob(NULL, 0);
|
---|
143 |
|
---|
144 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
---|
145 | if (NT_STATUS_IS_OK(status)) {
|
---|
146 | printf("Server supports batch oplock upgrades on open files\n");
|
---|
147 | } else {
|
---|
148 | printf("Server does not support batch oplock upgrades on open files\n");
|
---|
149 | }
|
---|
150 |
|
---|
151 | printf("Trying bad handle\n");
|
---|
152 | nt.ntioctl.in.file.fnum = fnum+1;
|
---|
153 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
---|
154 | CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
|
---|
155 |
|
---|
156 | #if 0
|
---|
157 | nt.ntioctl.in.file.fnum = fnum;
|
---|
158 | for (i=0;i<100;i++) {
|
---|
159 | nt.ntioctl.in.function = FSCTL_FILESYSTEM + (i<<2);
|
---|
160 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
---|
161 | if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
|
---|
162 | printf("filesystem fsctl 0x%x - %s\n",
|
---|
163 | i, nt_errstr(status));
|
---|
164 | }
|
---|
165 | }
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | done:
|
---|
169 | smbcli_close(cli->tree, fnum);
|
---|
170 | return ret;
|
---|
171 | }
|
---|
172 |
|
---|
173 | /*
|
---|
174 | basic testing of some ioctl calls
|
---|
175 | */
|
---|
176 | bool torture_raw_ioctl(struct torture_context *torture,
|
---|
177 | struct smbcli_state *cli)
|
---|
178 | {
|
---|
179 | bool ret = true;
|
---|
180 |
|
---|
181 | if (!torture_setup_dir(cli, BASEDIR)) {
|
---|
182 | return false;
|
---|
183 | }
|
---|
184 |
|
---|
185 | ret &= test_ioctl(cli, torture);
|
---|
186 | ret &= test_fsctl(cli, torture);
|
---|
187 |
|
---|
188 | smb_raw_exit(cli->session);
|
---|
189 | smbcli_deltree(cli->tree, BASEDIR);
|
---|
190 |
|
---|
191 | return ret;
|
---|
192 | }
|
---|