1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | test suite for various RAP operations
|
---|
4 | Copyright (C) Volker Lendecke 2004
|
---|
5 | Copyright (C) Tim Potter 2005
|
---|
6 | Copyright (C) Jelmer Vernooij 2007
|
---|
7 | Copyright (C) Guenther Deschner 2010
|
---|
8 |
|
---|
9 | This program is free software; you can redistribute it and/or modify
|
---|
10 | it under the terms of the GNU General Public License as published by
|
---|
11 | the Free Software Foundation; either version 3 of the License, or
|
---|
12 | (at your option) any later version.
|
---|
13 |
|
---|
14 | This program is distributed in the hope that it will be useful,
|
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | GNU General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU General Public License
|
---|
20 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 | #include "libcli/libcli.h"
|
---|
25 | #include "torture/smbtorture.h"
|
---|
26 | #include "torture/util.h"
|
---|
27 | #include "param/param.h"
|
---|
28 | #include "libcli/rap/rap.h"
|
---|
29 | #include "torture/rap/proto.h"
|
---|
30 |
|
---|
31 | static bool test_netshareenum(struct torture_context *tctx,
|
---|
32 | struct smbcli_state *cli)
|
---|
33 | {
|
---|
34 | struct rap_NetShareEnum r;
|
---|
35 | int i;
|
---|
36 |
|
---|
37 | r.in.level = 1;
|
---|
38 | r.in.bufsize = 8192;
|
---|
39 |
|
---|
40 | torture_assert_ntstatus_ok(tctx,
|
---|
41 | smbcli_rap_netshareenum(cli->tree, tctx, &r), "");
|
---|
42 |
|
---|
43 | for (i=0; i<r.out.count; i++) {
|
---|
44 | printf("%s %d %s\n", r.out.info[i].info1.share_name,
|
---|
45 | r.out.info[i].info1.share_type,
|
---|
46 | r.out.info[i].info1.comment);
|
---|
47 | }
|
---|
48 |
|
---|
49 | return true;
|
---|
50 | }
|
---|
51 |
|
---|
52 | static bool test_netserverenum(struct torture_context *tctx,
|
---|
53 | struct smbcli_state *cli)
|
---|
54 | {
|
---|
55 | struct rap_NetServerEnum2 r;
|
---|
56 | int i;
|
---|
57 |
|
---|
58 | r.in.level = 0;
|
---|
59 | r.in.bufsize = 8192;
|
---|
60 | r.in.servertype = 0xffffffff;
|
---|
61 | r.in.servertype = 0x80000000;
|
---|
62 | r.in.domain = NULL;
|
---|
63 |
|
---|
64 | torture_assert_ntstatus_ok(tctx,
|
---|
65 | smbcli_rap_netserverenum2(cli->tree, tctx, &r), "");
|
---|
66 |
|
---|
67 | for (i=0; i<r.out.count; i++) {
|
---|
68 | switch (r.in.level) {
|
---|
69 | case 0:
|
---|
70 | printf("%s\n", r.out.info[i].info0.name);
|
---|
71 | break;
|
---|
72 | case 1:
|
---|
73 | printf("%s %x %s\n", r.out.info[i].info1.name,
|
---|
74 | r.out.info[i].info1.servertype,
|
---|
75 | r.out.info[i].info1.comment);
|
---|
76 | break;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | return true;
|
---|
81 | }
|
---|
82 |
|
---|
83 | static bool test_netservergetinfo(struct torture_context *tctx,
|
---|
84 | struct smbcli_state *cli)
|
---|
85 | {
|
---|
86 | struct rap_WserverGetInfo r;
|
---|
87 | bool res = true;
|
---|
88 |
|
---|
89 | r.in.bufsize = 0xffff;
|
---|
90 |
|
---|
91 | r.in.level = 0;
|
---|
92 | torture_assert_ntstatus_ok(tctx,
|
---|
93 | smbcli_rap_netservergetinfo(cli->tree, tctx, &r),
|
---|
94 | "rap_netservergetinfo level 0 failed");
|
---|
95 | torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
|
---|
96 | "rap_netservergetinfo level 0 failed");
|
---|
97 |
|
---|
98 | r.in.level = 1;
|
---|
99 | torture_assert_ntstatus_ok(tctx,
|
---|
100 | smbcli_rap_netservergetinfo(cli->tree, tctx, &r),
|
---|
101 | "rap_netservergetinfo level 1 failed");
|
---|
102 | torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
|
---|
103 | "rap_netservergetinfo level 1 failed");
|
---|
104 |
|
---|
105 | return res;
|
---|
106 | }
|
---|
107 |
|
---|
108 | static bool test_netsessionenum(struct torture_context *tctx,
|
---|
109 | struct smbcli_state *cli)
|
---|
110 | {
|
---|
111 | struct rap_NetSessionEnum r;
|
---|
112 | int i,n;
|
---|
113 | uint16_t levels[] = { 2 };
|
---|
114 |
|
---|
115 | for (i=0; i < ARRAY_SIZE(levels); i++) {
|
---|
116 |
|
---|
117 | r.in.level = levels[i];
|
---|
118 | r.in.bufsize = 8192;
|
---|
119 |
|
---|
120 | torture_comment(tctx,
|
---|
121 | "Testing rap_NetSessionEnum level %d\n", r.in.level);
|
---|
122 |
|
---|
123 | torture_assert_ntstatus_ok(tctx,
|
---|
124 | smbcli_rap_netsessionenum(cli->tree, tctx, &r),
|
---|
125 | "smbcli_rap_netsessionenum failed");
|
---|
126 | torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
|
---|
127 | "smbcli_rap_netsessionenum failed");
|
---|
128 |
|
---|
129 | for (n=0; n < r.out.count; n++) {
|
---|
130 | switch (r.in.level) {
|
---|
131 | case 2:
|
---|
132 | torture_comment(tctx, "ComputerName: %s\n",
|
---|
133 | r.out.info[n].info2.ComputerName);
|
---|
134 |
|
---|
135 | torture_comment(tctx, "UserName: %s\n",
|
---|
136 | r.out.info[n].info2.UserName);
|
---|
137 |
|
---|
138 | torture_assert(tctx, r.out.info[n].info2.ComputerName,
|
---|
139 | "ComputerName empty");
|
---|
140 | torture_assert(tctx, r.out.info[n].info2.UserName,
|
---|
141 | "UserName empty");
|
---|
142 | break;
|
---|
143 | default:
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | return true;
|
---|
150 | }
|
---|
151 |
|
---|
152 | static bool test_netsessiongetinfo_bysession(struct torture_context *tctx,
|
---|
153 | struct smbcli_state *cli,
|
---|
154 | const char *session)
|
---|
155 | {
|
---|
156 | struct rap_NetSessionGetInfo r;
|
---|
157 | int i;
|
---|
158 | uint16_t levels[] = { 2 };
|
---|
159 |
|
---|
160 | if (session && session[0] == '\\' && session[1] == '\\') {
|
---|
161 | r.in.SessionName = session;
|
---|
162 | } else {
|
---|
163 | r.in.SessionName = talloc_asprintf(tctx, "\\\\%s", session);
|
---|
164 | }
|
---|
165 | r.in.bufsize = 0xffff;
|
---|
166 |
|
---|
167 | for (i=0; i < ARRAY_SIZE(levels); i++) {
|
---|
168 |
|
---|
169 | r.in.level = levels[i];
|
---|
170 |
|
---|
171 | torture_assert_ntstatus_ok(tctx,
|
---|
172 | smbcli_rap_netsessiongetinfo(cli->tree, tctx, &r),
|
---|
173 | "rap_netsessiongetinfo failed");
|
---|
174 | torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
|
---|
175 | "rap_netsessiongetinfo failed");
|
---|
176 | }
|
---|
177 |
|
---|
178 | return true;
|
---|
179 | }
|
---|
180 |
|
---|
181 | static bool test_netsessiongetinfo(struct torture_context *tctx,
|
---|
182 | struct smbcli_state *cli)
|
---|
183 | {
|
---|
184 | struct rap_NetSessionEnum r;
|
---|
185 | int i,n;
|
---|
186 | uint16_t levels[] = { 2 };
|
---|
187 |
|
---|
188 | for (i=0; i < ARRAY_SIZE(levels); i++) {
|
---|
189 |
|
---|
190 | r.in.level = levels[i];
|
---|
191 | r.in.bufsize = 8192;
|
---|
192 |
|
---|
193 | torture_assert_ntstatus_ok(tctx,
|
---|
194 | smbcli_rap_netsessionenum(cli->tree, tctx, &r),
|
---|
195 | "smbcli_rap_netsessionenum failed");
|
---|
196 | torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
|
---|
197 | "smbcli_rap_netsessionenum failed");
|
---|
198 |
|
---|
199 | for (n=0; n < r.out.count; n++) {
|
---|
200 | torture_assert(tctx,
|
---|
201 | test_netsessiongetinfo_bysession(tctx, cli, r.out.info[n].info2.ComputerName),
|
---|
202 | "failed to query sessioninfo");
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | return true;
|
---|
207 | }
|
---|
208 |
|
---|
209 | static bool test_netremotetod(struct torture_context *tctx,
|
---|
210 | struct smbcli_state *cli)
|
---|
211 | {
|
---|
212 | struct rap_NetRemoteTOD r;
|
---|
213 |
|
---|
214 | r.in.bufsize = 8192;
|
---|
215 |
|
---|
216 | torture_assert_ntstatus_ok(tctx,
|
---|
217 | smbcli_rap_netremotetod(cli->tree, tctx, &r),
|
---|
218 | "smbcli_rap_netremotetod failed");
|
---|
219 | torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
|
---|
220 | "smbcli_rap_netremotetod failed");
|
---|
221 |
|
---|
222 | return true;
|
---|
223 | }
|
---|
224 |
|
---|
225 | bool torture_rap_scan(struct torture_context *torture, struct smbcli_state *cli)
|
---|
226 | {
|
---|
227 | int callno;
|
---|
228 |
|
---|
229 | for (callno = 0; callno < 0xffff; callno++) {
|
---|
230 | struct rap_call *call = new_rap_cli_call(torture, callno);
|
---|
231 | NTSTATUS result;
|
---|
232 |
|
---|
233 | result = rap_cli_do_call(cli->tree, call);
|
---|
234 |
|
---|
235 | if (!NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PARAMETER))
|
---|
236 | continue;
|
---|
237 |
|
---|
238 | printf("callno %d is RAP call\n", callno);
|
---|
239 | }
|
---|
240 |
|
---|
241 | return true;
|
---|
242 | }
|
---|
243 |
|
---|
244 | NTSTATUS torture_rap_init(void)
|
---|
245 | {
|
---|
246 | struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "rap");
|
---|
247 | struct torture_suite *suite_basic = torture_suite_create(suite, "basic");
|
---|
248 |
|
---|
249 | torture_suite_add_suite(suite, suite_basic);
|
---|
250 | torture_suite_add_suite(suite, torture_rap_rpc(suite));
|
---|
251 | torture_suite_add_suite(suite, torture_rap_printing(suite));
|
---|
252 | torture_suite_add_suite(suite, torture_rap_sam(suite));
|
---|
253 |
|
---|
254 | torture_suite_add_1smb_test(suite_basic, "netserverenum",
|
---|
255 | test_netserverenum);
|
---|
256 | torture_suite_add_1smb_test(suite_basic, "netshareenum",
|
---|
257 | test_netshareenum);
|
---|
258 | torture_suite_add_1smb_test(suite_basic, "netservergetinfo",
|
---|
259 | test_netservergetinfo);
|
---|
260 | torture_suite_add_1smb_test(suite_basic, "netsessionenum",
|
---|
261 | test_netsessionenum);
|
---|
262 | torture_suite_add_1smb_test(suite_basic, "netsessiongetinfo",
|
---|
263 | test_netsessiongetinfo);
|
---|
264 | torture_suite_add_1smb_test(suite_basic, "netremotetod",
|
---|
265 | test_netremotetod);
|
---|
266 |
|
---|
267 | torture_suite_add_1smb_test(suite, "scan", torture_rap_scan);
|
---|
268 |
|
---|
269 | suite->description = talloc_strdup(suite,
|
---|
270 | "Remote Administration Protocol tests");
|
---|
271 |
|
---|
272 | torture_register_suite(suite);
|
---|
273 |
|
---|
274 | return NT_STATUS_OK;
|
---|
275 | }
|
---|