2 Unix SMB/CIFS implementation.
3 test suite for mgmt rpc operations
5 Copyright (C) Andrew Tridgell 2003
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.
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.
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/>.
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"
30 ask the server what interface IDs are available on this endpoint
32 bool test_inq_if_ids(struct torture_context *tctx,
33 struct dcerpc_binding_handle *b,
35 bool (*per_id_test)(struct torture_context *,
36 const struct ndr_interface_table *iface,
38 struct ndr_syntax_id *id),
42 struct mgmt_inq_if_ids r;
43 struct rpc_if_id_vector_t *vector;
46 vector = talloc(mem_ctx, struct rpc_if_id_vector_t);
47 r.out.if_id_vector = &vector;
49 status = dcerpc_mgmt_inq_if_ids_r(b, mem_ctx, &r);
50 if (!NT_STATUS_IS_OK(status)) {
51 printf("inq_if_ids failed - %s\n", nt_errstr(status));
55 if (!W_ERROR_IS_OK(r.out.result)) {
56 printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
61 printf("inq_if_ids gave NULL if_id_vector\n");
65 for (i=0;i<vector->count;i++) {
66 struct ndr_syntax_id *id = vector->if_id[i].id;
69 printf("\tuuid %s version 0x%08x '%s'\n",
70 GUID_string(mem_ctx, &id->uuid),
72 ndr_interface_name(&id->uuid, id->if_version));
75 per_id_test(tctx, priv, mem_ctx, id);
82 static bool test_inq_stats(struct torture_context *tctx,
83 struct dcerpc_binding_handle *b,
87 struct mgmt_inq_stats r;
88 struct mgmt_statistics statistics;
90 r.in.max_count = MGMT_STATS_ARRAY_MAX_SIZE;
92 r.out.statistics = &statistics;
94 status = dcerpc_mgmt_inq_stats_r(b, mem_ctx, &r);
95 if (!NT_STATUS_IS_OK(status)) {
96 printf("inq_stats failed - %s\n", nt_errstr(status));
100 if (statistics.count != MGMT_STATS_ARRAY_MAX_SIZE) {
101 printf("Unexpected array size %d\n", statistics.count);
105 printf("\tcalls_in %6d calls_out %6d\n\tpkts_in %6d pkts_out %6d\n",
106 statistics.statistics[MGMT_STATS_CALLS_IN],
107 statistics.statistics[MGMT_STATS_CALLS_OUT],
108 statistics.statistics[MGMT_STATS_PKTS_IN],
109 statistics.statistics[MGMT_STATS_PKTS_OUT]);
114 static bool test_inq_princ_name(struct torture_context *tctx,
115 struct dcerpc_binding_handle *b,
119 struct mgmt_inq_princ_name r;
123 for (i=0;i<256;i++) {
124 r.in.authn_proto = i; /* DCERPC_AUTH_TYPE_* */
125 r.in.princ_name_size = 100;
127 status = dcerpc_mgmt_inq_princ_name_r(b, mem_ctx, &r);
128 if (!NT_STATUS_IS_OK(status)) {
131 if (W_ERROR_IS_OK(r.out.result)) {
132 const char *name = gensec_get_name_by_authtype(NULL, i);
135 printf("\tprinciple name for proto %u (%s) is '%s'\n",
136 i, name, r.out.princ_name);
138 printf("\tprinciple name for proto %u is '%s'\n",
139 i, r.out.princ_name);
145 printf("\tno principle names?\n");
151 static bool test_is_server_listening(struct torture_context *tctx,
152 struct dcerpc_binding_handle *b,
156 struct mgmt_is_server_listening r;
157 r.out.status = talloc(mem_ctx, uint32_t);
159 status = dcerpc_mgmt_is_server_listening_r(b, mem_ctx, &r);
160 if (!NT_STATUS_IS_OK(status)) {
161 printf("is_server_listening failed - %s\n", nt_errstr(status));
165 if (*r.out.status != 0 || r.out.result == 0) {
166 printf("\tserver is NOT listening\n");
168 printf("\tserver is listening\n");
174 static bool test_stop_server_listening(struct torture_context *tctx,
175 struct dcerpc_binding_handle *b,
179 struct mgmt_stop_server_listening r;
181 status = dcerpc_mgmt_stop_server_listening_r(b, mem_ctx, &r);
182 if (!NT_STATUS_IS_OK(status)) {
183 printf("stop_server_listening failed - %s\n", nt_errstr(status));
187 if (!W_ERROR_IS_OK(r.out.result)) {
188 printf("\tserver refused to stop listening - %s\n", win_errstr(r.out.result));
190 printf("\tserver allowed a stop_server_listening request\n");
198 bool torture_rpc_mgmt(struct torture_context *tctx)
201 struct dcerpc_pipe *p;
202 TALLOC_CTX *mem_ctx, *loop_ctx;
204 const struct ndr_interface_list *l;
205 struct dcerpc_binding *b;
207 mem_ctx = talloc_init("torture_rpc_mgmt");
209 status = torture_rpc_binding(tctx, &b);
210 if (!NT_STATUS_IS_OK(status)) {
211 talloc_free(mem_ctx);
215 for (l=ndr_table_list();l;l=l->next) {
216 struct dcerpc_binding_handle *bh;
218 loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_mgmt loop context");
220 /* some interfaces are not mappable */
221 if (l->table->num_calls == 0 ||
222 strcmp(l->table->name, "mgmt") == 0) {
223 talloc_free(loop_ctx);
227 printf("\nTesting pipe '%s'\n", l->table->name);
229 status = dcerpc_epm_map_binding(loop_ctx, b, l->table,
230 tctx->ev, tctx->lp_ctx);
231 if (!NT_STATUS_IS_OK(status)) {
232 printf("Failed to map port for uuid %s\n",
233 GUID_string(loop_ctx, &l->table->syntax_id.uuid));
234 talloc_free(loop_ctx);
238 lpcfg_set_cmdline(tctx->lp_ctx, "torture:binding", dcerpc_binding_string(loop_ctx, b));
240 status = torture_rpc_connection(tctx, &p, &ndr_table_mgmt);
241 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
242 printf("Interface not available - skipping\n");
243 talloc_free(loop_ctx);
246 bh = p->binding_handle;
248 if (!NT_STATUS_IS_OK(status)) {
249 talloc_free(loop_ctx);
254 if (!test_is_server_listening(tctx, bh, loop_ctx)) {
258 if (!test_stop_server_listening(tctx, bh, loop_ctx)) {
262 if (!test_inq_stats(tctx, bh, loop_ctx)) {
266 if (!test_inq_princ_name(tctx, bh, loop_ctx)) {
270 if (!test_inq_if_ids(tctx, bh, loop_ctx, NULL, NULL)) {