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