s3/docs: Raise version number up to 3.5.
[Samba/gebeck_regimport.git] / source4 / torture / rpc / mgmt.c
blob7f618ab7763577425bdad8f61c24e16da5de22c3
1 /*
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/>.
21 #include "includes.h"
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,
38 TALLOC_CTX *mem_ctx,
39 struct ndr_syntax_id *id),
40 const void *priv)
42 NTSTATUS status;
43 struct mgmt_inq_if_ids r;
44 struct rpc_if_id_vector_t *vector;
45 int i;
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));
53 return false;
56 if (!W_ERROR_IS_OK(r.out.result)) {
57 printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
58 return false;
61 if (!vector) {
62 printf("inq_if_ids gave NULL if_id_vector\n");
63 return false;
66 for (i=0;i<vector->count;i++) {
67 struct ndr_syntax_id *id = vector->if_id[i].id;
68 if (!id) continue;
70 printf("\tuuid %s version 0x%08x '%s'\n",
71 GUID_string(mem_ctx, &id->uuid),
72 id->if_version,
73 ndr_interface_name(&id->uuid, id->if_version));
75 if (per_id_test) {
76 per_id_test(tctx, priv, mem_ctx, id);
80 return true;
83 static bool test_inq_stats(struct dcerpc_pipe *p,
84 TALLOC_CTX *mem_ctx)
86 NTSTATUS status;
87 struct mgmt_inq_stats r;
88 struct mgmt_statistics statistics;
90 r.in.max_count = MGMT_STATS_ARRAY_MAX_SIZE;
91 r.in.unknown = 0;
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));
97 return false;
100 if (statistics.count != MGMT_STATS_ARRAY_MAX_SIZE) {
101 printf("Unexpected array size %d\n", statistics.count);
102 return false;
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]);
111 return true;
114 static bool test_inq_princ_name(struct dcerpc_pipe *p,
115 TALLOC_CTX *mem_ctx)
117 NTSTATUS status;
118 struct mgmt_inq_princ_name r;
119 int i;
120 bool ret = false;
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)) {
128 continue;
130 if (W_ERROR_IS_OK(r.out.result)) {
131 const char *name = gensec_get_name_by_authtype(NULL, i);
132 ret = true;
133 if (name) {
134 printf("\tprinciple name for proto %u (%s) is '%s'\n",
135 i, name, r.out.princ_name);
136 } else {
137 printf("\tprinciple name for proto %u is '%s'\n",
138 i, r.out.princ_name);
143 if (!ret) {
144 printf("\tno principle names?\n");
147 return true;
150 static bool test_is_server_listening(struct dcerpc_pipe *p,
151 TALLOC_CTX *mem_ctx)
153 NTSTATUS status;
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));
160 return false;
163 if (*r.out.status != 0 || r.out.result == 0) {
164 printf("\tserver is NOT listening\n");
165 } else {
166 printf("\tserver is listening\n");
169 return true;
172 static bool test_stop_server_listening(struct dcerpc_pipe *p,
173 TALLOC_CTX *mem_ctx)
175 NTSTATUS status;
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));
181 return false;
184 if (!W_ERROR_IS_OK(r.out.result)) {
185 printf("\tserver refused to stop listening - %s\n", win_errstr(r.out.result));
186 } else {
187 printf("\tserver allowed a stop_server_listening request\n");
188 return false;
191 return true;
195 bool torture_rpc_mgmt(struct torture_context *torture)
197 NTSTATUS status;
198 struct dcerpc_pipe *p;
199 TALLOC_CTX *mem_ctx, *loop_ctx;
200 bool ret = true;
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);
209 return false;
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);
219 continue;
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);
229 continue;
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);
238 continue;
241 if (!NT_STATUS_IS_OK(status)) {
242 talloc_free(loop_ctx);
243 ret = false;
244 continue;
247 if (!test_is_server_listening(p, loop_ctx)) {
248 ret = false;
251 if (!test_stop_server_listening(p, loop_ctx)) {
252 ret = false;
255 if (!test_inq_stats(p, loop_ctx)) {
256 ret = false;
259 if (!test_inq_princ_name(p, loop_ctx)) {
260 ret = false;
263 if (!test_inq_if_ids(torture, p, loop_ctx, NULL, NULL)) {
264 ret = false;
269 return ret;