Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : test suite for mgmt rpc operations
4 :
5 : Copyright (C) Andrew Tridgell 2003
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 "librpc/gen_ndr/ndr_mgmt_c.h"
23 : #include "auth/gensec/gensec.h"
24 : #include "librpc/ndr/ndr_table.h"
25 : #include "torture/rpc/torture_rpc.h"
26 : #include "param/param.h"
27 :
28 :
29 : /*
30 : ask the server what interface IDs are available on this endpoint
31 : */
32 141 : bool test_inq_if_ids(struct torture_context *tctx,
33 : struct dcerpc_binding_handle *b,
34 : TALLOC_CTX *mem_ctx,
35 : bool (*per_id_test)(struct torture_context *,
36 : const struct ndr_interface_table *iface,
37 : TALLOC_CTX *mem_ctx,
38 : struct ndr_syntax_id *id),
39 : const void *priv)
40 : {
41 0 : struct mgmt_inq_if_ids r;
42 0 : struct rpc_if_id_vector_t *vector;
43 0 : int i;
44 :
45 141 : vector = talloc(mem_ctx, struct rpc_if_id_vector_t);
46 141 : r.out.if_id_vector = &vector;
47 :
48 141 : torture_assert_ntstatus_ok(tctx,
49 : dcerpc_mgmt_inq_if_ids_r(b, mem_ctx, &r),
50 : "inq_if_ids failed");
51 :
52 141 : torture_assert_werr_ok(tctx,
53 : r.out.result,
54 : "inq_if_ids gave unexpected error code");
55 :
56 141 : if (!vector) {
57 0 : torture_comment(tctx, "inq_if_ids gave NULL if_id_vector\n");
58 0 : return false;
59 : }
60 :
61 330 : for (i=0;i<vector->count;i++) {
62 189 : struct ndr_syntax_id *id = vector->if_id[i].id;
63 189 : if (!id) continue;
64 :
65 189 : torture_comment(tctx, "\tuuid %s version 0x%08x '%s'\n",
66 189 : GUID_string(mem_ctx, &id->uuid),
67 : id->if_version,
68 189 : ndr_interface_name(&id->uuid, id->if_version));
69 :
70 189 : if (per_id_test) {
71 0 : per_id_test(tctx, priv, mem_ctx, id);
72 : }
73 : }
74 :
75 141 : return true;
76 : }
77 :
78 141 : static bool test_inq_stats(struct torture_context *tctx,
79 : struct dcerpc_binding_handle *b,
80 : TALLOC_CTX *mem_ctx)
81 : {
82 0 : struct mgmt_inq_stats r;
83 0 : struct mgmt_statistics statistics;
84 :
85 141 : r.in.max_count = MGMT_STATS_ARRAY_MAX_SIZE;
86 141 : r.in.unknown = 0;
87 141 : r.out.statistics = &statistics;
88 :
89 141 : torture_assert_ntstatus_ok(tctx,
90 : dcerpc_mgmt_inq_stats_r(b, mem_ctx, &r),
91 : "inq_stats failed");
92 :
93 141 : if (statistics.count != MGMT_STATS_ARRAY_MAX_SIZE) {
94 0 : torture_comment(tctx, "Unexpected array size %d\n", statistics.count);
95 0 : return false;
96 : }
97 :
98 141 : torture_comment(tctx, "\tcalls_in %6d calls_out %6d\n\tpkts_in %6d pkts_out %6d\n",
99 141 : statistics.statistics[MGMT_STATS_CALLS_IN],
100 141 : statistics.statistics[MGMT_STATS_CALLS_OUT],
101 141 : statistics.statistics[MGMT_STATS_PKTS_IN],
102 141 : statistics.statistics[MGMT_STATS_PKTS_OUT]);
103 :
104 141 : return true;
105 : }
106 :
107 106 : static bool test_inq_princ_name_size(struct torture_context *tctx,
108 : struct dcerpc_binding_handle *b,
109 : uint32_t authn_proto,
110 : const char *expected_princ_name)
111 : {
112 0 : struct mgmt_inq_princ_name r;
113 0 : uint32_t len, i;
114 :
115 106 : len = strlen(expected_princ_name);
116 :
117 106 : r.in.authn_proto = authn_proto;
118 :
119 : /*
120 : * 0 gives NT_STATUS_RPC_BAD_STUB_DATA
121 : */
122 106 : r.in.princ_name_size = 0;
123 :
124 106 : torture_assert_ntstatus_equal(tctx,
125 : dcerpc_mgmt_inq_princ_name_r(b, tctx, &r),
126 : NT_STATUS_RPC_BAD_STUB_DATA,
127 : "mgmt_inq_princ_name failed");
128 :
129 1324 : for (i=1; i <= len; i++) {
130 1218 : r.in.princ_name_size = i;
131 :
132 1218 : torture_assert_ntstatus_ok(tctx,
133 : dcerpc_mgmt_inq_princ_name_r(b, tctx, &r),
134 : "mgmt_inq_princ_name failed");
135 1218 : torture_assert_werr_equal(tctx,
136 : r.out.result,
137 : WERR_INSUFFICIENT_BUFFER,
138 : "mgmt_inq_princ_name failed");
139 : }
140 :
141 106 : r.in.princ_name_size = len + 1;
142 :
143 106 : torture_assert_ntstatus_ok(tctx,
144 : dcerpc_mgmt_inq_princ_name_r(b, tctx, &r),
145 : "mgmt_inq_princ_name failed");
146 106 : torture_assert_werr_ok(tctx,
147 : r.out.result,
148 : "mgmt_inq_princ_name failed");
149 :
150 106 : return true;
151 : }
152 :
153 141 : static bool test_inq_princ_name(struct torture_context *tctx,
154 : struct dcerpc_binding_handle *b,
155 : TALLOC_CTX *mem_ctx)
156 : {
157 0 : NTSTATUS status;
158 0 : struct mgmt_inq_princ_name r;
159 0 : int i;
160 141 : bool ret = false;
161 :
162 36237 : for (i=0;i<256;i++) {
163 36096 : r.in.authn_proto = i; /* DCERPC_AUTH_TYPE_* */
164 36096 : r.in.princ_name_size = 100;
165 :
166 36096 : status = dcerpc_mgmt_inq_princ_name_r(b, mem_ctx, &r);
167 36096 : if (!NT_STATUS_IS_OK(status)) {
168 0 : continue;
169 : }
170 36096 : if (W_ERROR_IS_OK(r.out.result)) {
171 118 : const char *name = gensec_get_name_by_authtype(NULL, i);
172 118 : ret = true;
173 118 : if (name) {
174 118 : torture_comment(tctx, "\tprinciple name for proto %u (%s) is '%s'\n",
175 : i, name, r.out.princ_name);
176 : } else {
177 0 : torture_comment(tctx, "\tprinciple name for proto %u is '%s'\n",
178 : i, r.out.princ_name);
179 : }
180 :
181 118 : switch (i) {
182 106 : case DCERPC_AUTH_TYPE_KRB5:
183 : case DCERPC_AUTH_TYPE_NTLMSSP:
184 : case DCERPC_AUTH_TYPE_SPNEGO:
185 106 : torture_assert(tctx,
186 : test_inq_princ_name_size(tctx, b, i, r.out.princ_name),
187 : "failed");
188 106 : break;
189 12 : case DCERPC_AUTH_TYPE_SCHANNEL:
190 : /*
191 : * for some reason schannel behaves differently
192 : *
193 : */
194 : default:
195 12 : break;
196 : }
197 : }
198 : }
199 :
200 141 : if (!ret) {
201 95 : torture_comment(tctx, "\tno principle names?\n");
202 : }
203 :
204 141 : return true;
205 : }
206 :
207 141 : static bool test_is_server_listening(struct torture_context *tctx,
208 : struct dcerpc_binding_handle *b,
209 : TALLOC_CTX *mem_ctx)
210 : {
211 0 : struct mgmt_is_server_listening r;
212 141 : r.out.status = talloc(mem_ctx, uint32_t);
213 :
214 141 : torture_assert_ntstatus_ok(tctx,
215 : dcerpc_mgmt_is_server_listening_r(b, mem_ctx, &r),
216 : "is_server_listening failed");
217 :
218 141 : if (*r.out.status != 0 || r.out.result == 0) {
219 0 : torture_comment(tctx, "\tserver is NOT listening\n");
220 : } else {
221 141 : torture_comment(tctx, "\tserver is listening\n");
222 : }
223 :
224 141 : return true;
225 : }
226 :
227 141 : static bool test_stop_server_listening(struct torture_context *tctx,
228 : struct dcerpc_binding_handle *b,
229 : TALLOC_CTX *mem_ctx)
230 : {
231 0 : struct mgmt_stop_server_listening r;
232 :
233 141 : torture_assert_ntstatus_ok(tctx,
234 : dcerpc_mgmt_stop_server_listening_r(b, mem_ctx, &r),
235 : "stop_server_listening failed");
236 :
237 141 : if (!W_ERROR_IS_OK(r.out.result)) {
238 141 : torture_comment(tctx, "\tserver refused to stop listening - %s\n", win_errstr(r.out.result));
239 : } else {
240 0 : torture_comment(tctx, "\tserver allowed a stop_server_listening request\n");
241 0 : return false;
242 : }
243 :
244 141 : return true;
245 : }
246 :
247 :
248 7 : bool torture_rpc_mgmt(struct torture_context *tctx)
249 : {
250 0 : NTSTATUS status;
251 0 : struct dcerpc_pipe *p;
252 0 : TALLOC_CTX *mem_ctx, *loop_ctx;
253 7 : bool ret = true;
254 0 : const struct ndr_interface_list *l;
255 0 : struct dcerpc_binding *b;
256 :
257 7 : mem_ctx = talloc_init("torture_rpc_mgmt");
258 :
259 7 : status = torture_rpc_binding(tctx, &b);
260 7 : if (!NT_STATUS_IS_OK(status)) {
261 0 : talloc_free(mem_ctx);
262 0 : return false;
263 : }
264 :
265 763 : for (l=ndr_table_list();l;l=l->next) {
266 0 : struct dcerpc_binding_handle *bh;
267 :
268 756 : loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_mgmt loop context");
269 :
270 : /* some interfaces are not mappable */
271 756 : if (l->table->num_calls == 0 ||
272 378 : strcmp(l->table->name, "mgmt") == 0) {
273 385 : talloc_free(loop_ctx);
274 385 : continue;
275 : }
276 :
277 371 : torture_comment(tctx, "\nTesting pipe '%s'\n", l->table->name);
278 :
279 371 : status = dcerpc_epm_map_binding(loop_ctx, b, l->table,
280 : tctx->ev, tctx->lp_ctx);
281 371 : if (!NT_STATUS_IS_OK(status)) {
282 56 : torture_comment(tctx, "Failed to map port for uuid %s\n",
283 56 : GUID_string(loop_ctx, &l->table->syntax_id.uuid));
284 56 : talloc_free(loop_ctx);
285 56 : continue;
286 : }
287 :
288 315 : lpcfg_set_cmdline(tctx->lp_ctx, "torture:binding", dcerpc_binding_string(loop_ctx, b));
289 :
290 315 : status = torture_rpc_connection(tctx, &p, &ndr_table_mgmt);
291 315 : if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
292 174 : torture_comment(tctx, "Interface not available - skipping\n");
293 174 : talloc_free(loop_ctx);
294 174 : continue;
295 : }
296 :
297 141 : if (!NT_STATUS_IS_OK(status)) {
298 0 : talloc_free(loop_ctx);
299 0 : torture_comment(tctx, "Interface not available (%s) - skipping\n", nt_errstr(status));
300 0 : ret = false;
301 0 : continue;
302 : }
303 141 : bh = p->binding_handle;
304 :
305 141 : if (!test_is_server_listening(tctx, bh, loop_ctx)) {
306 0 : ret = false;
307 : }
308 :
309 141 : if (!test_stop_server_listening(tctx, bh, loop_ctx)) {
310 0 : ret = false;
311 : }
312 :
313 141 : if (!test_inq_stats(tctx, bh, loop_ctx)) {
314 0 : ret = false;
315 : }
316 :
317 141 : if (!test_inq_princ_name(tctx, bh, loop_ctx)) {
318 0 : ret = false;
319 : }
320 :
321 141 : if (!test_inq_if_ids(tctx, bh, loop_ctx, NULL, NULL)) {
322 0 : ret = false;
323 : }
324 :
325 : }
326 :
327 7 : return ret;
328 : }
|