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 "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_mgmt_c.h"
24 #include "auth/gensec/gensec.h"
25 #include "librpc/ndr/ndr_table.h"
26 #include "torture/rpc/rpc.h"
27 #include "param/param.h"
28 #include "librpc/rpc/dcerpc_proto.h"
32 ask the server what interface IDs are available on this endpoint
34 bool test_inq_if_ids(struct torture_context
*tctx
,
35 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
36 bool (*per_id_test
)(struct torture_context
*,
37 const struct ndr_interface_table
*iface
,
39 struct ndr_syntax_id
*id
),
43 struct mgmt_inq_if_ids r
;
44 struct rpc_if_id_vector_t
*vector
;
47 vector
= talloc(mem_ctx
, struct rpc_if_id_vector_t
);
48 r
.out
.if_id_vector
= &vector
;
50 status
= dcerpc_mgmt_inq_if_ids(p
, mem_ctx
, &r
);
51 if (!NT_STATUS_IS_OK(status
)) {
52 printf("inq_if_ids failed - %s\n", nt_errstr(status
));
56 if (!W_ERROR_IS_OK(r
.out
.result
)) {
57 printf("inq_if_ids gave error code %s\n", win_errstr(r
.out
.result
));
62 printf("inq_if_ids gave NULL if_id_vector\n");
66 for (i
=0;i
<vector
->count
;i
++) {
67 struct ndr_syntax_id
*id
= vector
->if_id
[i
].id
;
70 printf("\tuuid %s version 0x%08x '%s'\n",
71 GUID_string(mem_ctx
, &id
->uuid
),
73 ndr_interface_name(&id
->uuid
, id
->if_version
));
76 per_id_test(tctx
, priv
, mem_ctx
, id
);
83 static bool test_inq_stats(struct dcerpc_pipe
*p
,
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(p
, 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 dcerpc_pipe
*p
,
118 struct mgmt_inq_princ_name r
;
122 for (i
=0;i
<100;i
++) {
123 r
.in
.authn_proto
= i
; /* DCERPC_AUTH_TYPE_* */
124 r
.in
.princ_name_size
= 100;
126 status
= dcerpc_mgmt_inq_princ_name(p
, mem_ctx
, &r
);
127 if (!NT_STATUS_IS_OK(status
)) {
130 if (W_ERROR_IS_OK(r
.out
.result
)) {
131 const char *name
= gensec_get_name_by_authtype(NULL
, i
);
134 printf("\tprinciple name for proto %u (%s) is '%s'\n",
135 i
, name
, r
.out
.princ_name
);
137 printf("\tprinciple name for proto %u is '%s'\n",
138 i
, r
.out
.princ_name
);
144 printf("\tno principle names?\n");
150 static bool test_is_server_listening(struct dcerpc_pipe
*p
,
154 struct mgmt_is_server_listening r
;
155 r
.out
.status
= talloc(mem_ctx
, uint32_t);
157 status
= dcerpc_mgmt_is_server_listening(p
, mem_ctx
, &r
);
158 if (!NT_STATUS_IS_OK(status
)) {
159 printf("is_server_listening failed - %s\n", nt_errstr(status
));
163 if (*r
.out
.status
!= 0 || r
.out
.result
== 0) {
164 printf("\tserver is NOT listening\n");
166 printf("\tserver is listening\n");
172 static bool test_stop_server_listening(struct dcerpc_pipe
*p
,
176 struct mgmt_stop_server_listening r
;
178 status
= dcerpc_mgmt_stop_server_listening(p
, mem_ctx
, &r
);
179 if (!NT_STATUS_IS_OK(status
)) {
180 printf("stop_server_listening failed - %s\n", nt_errstr(status
));
184 if (!W_ERROR_IS_OK(r
.out
.result
)) {
185 printf("\tserver refused to stop listening - %s\n", win_errstr(r
.out
.result
));
187 printf("\tserver allowed a stop_server_listening request\n");
195 bool torture_rpc_mgmt(struct torture_context
*torture
)
198 struct dcerpc_pipe
*p
;
199 TALLOC_CTX
*mem_ctx
, *loop_ctx
;
201 const struct ndr_interface_list
*l
;
202 struct dcerpc_binding
*b
;
204 mem_ctx
= talloc_init("torture_rpc_mgmt");
206 status
= torture_rpc_binding(torture
, &b
);
207 if (!NT_STATUS_IS_OK(status
)) {
208 talloc_free(mem_ctx
);
212 for (l
=ndr_table_list();l
;l
=l
->next
) {
213 loop_ctx
= talloc_named(mem_ctx
, 0, "torture_rpc_mgmt loop context");
215 /* some interfaces are not mappable */
216 if (l
->table
->num_calls
== 0 ||
217 strcmp(l
->table
->name
, "mgmt") == 0) {
218 talloc_free(loop_ctx
);
222 printf("\nTesting pipe '%s'\n", l
->table
->name
);
224 status
= dcerpc_epm_map_binding(loop_ctx
, b
, l
->table
, NULL
, torture
->lp_ctx
);
225 if (!NT_STATUS_IS_OK(status
)) {
226 printf("Failed to map port for uuid %s\n",
227 GUID_string(loop_ctx
, &l
->table
->syntax_id
.uuid
));
228 talloc_free(loop_ctx
);
232 lp_set_cmdline(torture
->lp_ctx
, "torture:binding", dcerpc_binding_string(loop_ctx
, b
));
234 status
= torture_rpc_connection(torture
, &p
, &ndr_table_mgmt
);
235 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
236 printf("Interface not available - skipping\n");
237 talloc_free(loop_ctx
);
241 if (!NT_STATUS_IS_OK(status
)) {
242 talloc_free(loop_ctx
);
247 if (!test_is_server_listening(p
, loop_ctx
)) {
251 if (!test_stop_server_listening(p
, loop_ctx
)) {
255 if (!test_inq_stats(p
, loop_ctx
)) {
259 if (!test_inq_princ_name(p
, loop_ctx
)) {
263 if (!test_inq_if_ids(torture
, p
, loop_ctx
, NULL
, NULL
)) {