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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 ask the server what interface IDs are available on this endpoint
28 static BOOL test_inq_if_ids(struct dcerpc_pipe *p,
32 struct mgmt_inq_if_ids r;
35 status = dcerpc_mgmt_inq_if_ids(p, mem_ctx, &r);
36 if (!NT_STATUS_IS_OK(status)) {
37 printf("inq_if_ids failed - %s\n", nt_errstr(status));
41 if (!W_ERROR_IS_OK(r.out.result)) {
42 printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
46 if (!r.out.if_id_vector) {
47 printf("inq_if_ids gave NULL if_id_vector\n");
51 for (i=0;i<r.out.if_id_vector->count;i++) {
53 struct dcerpc_syntax_id *id = r.out.if_id_vector->if_id[i].id;
56 uuid = GUID_string(mem_ctx, &id->uuid);
58 printf("\tuuid %s version 0x%08x '%s'\n",
60 id->if_version, idl_pipe_name(uuid, id->if_version));
66 static BOOL test_inq_stats(struct dcerpc_pipe *p,
70 struct mgmt_inq_stats r;
72 r.in.max_count = MGMT_STATS_ARRAY_MAX_SIZE;
75 status = dcerpc_mgmt_inq_stats(p, mem_ctx, &r);
76 if (!NT_STATUS_IS_OK(status)) {
77 printf("inq_stats failed - %s\n", nt_errstr(status));
81 if (r.out.statistics.count != MGMT_STATS_ARRAY_MAX_SIZE) {
82 printf("Unexpected array size %d\n", r.out.statistics.count);
86 printf("\tcalls_in %6d calls_out %6d\n\tpkts_in %6d pkts_out %6d\n",
87 r.out.statistics.statistics[MGMT_STATS_CALLS_IN],
88 r.out.statistics.statistics[MGMT_STATS_CALLS_OUT],
89 r.out.statistics.statistics[MGMT_STATS_PKTS_IN],
90 r.out.statistics.statistics[MGMT_STATS_PKTS_OUT]);
95 static BOOL test_inq_princ_name(struct dcerpc_pipe *p,
99 struct mgmt_inq_princ_name r;
103 for (i=0;i<100;i++) {
104 r.in.authn_proto = i; /* DCERPC_AUTH_TYPE_* */
105 r.in.princ_name_size = 100;
107 status = dcerpc_mgmt_inq_princ_name(p, mem_ctx, &r);
108 if (!NT_STATUS_IS_OK(status)) {
111 if (W_ERROR_IS_OK(r.out.result)) {
112 const char *name = gensec_get_name_by_authtype(i);
115 printf("\tprinciple name for proto %u (%s) is '%s'\n",
116 i, name, r.out.princ_name);
118 printf("\tprinciple name for proto %u is '%s'\n",
119 i, r.out.princ_name);
125 printf("\tno principle names?\n");
131 static BOOL test_is_server_listening(struct dcerpc_pipe *p,
135 struct mgmt_is_server_listening r;
137 status = dcerpc_mgmt_is_server_listening(p, mem_ctx, &r);
138 if (!NT_STATUS_IS_OK(status)) {
139 printf("is_server_listening failed - %s\n", nt_errstr(status));
143 if (r.out.status != 0 || r.out.result == 0) {
144 printf("\tserver is NOT listening\n");
146 printf("\tserver is listening\n");
152 static BOOL test_stop_server_listening(struct dcerpc_pipe *p,
156 struct mgmt_stop_server_listening r;
158 status = dcerpc_mgmt_stop_server_listening(p, mem_ctx, &r);
159 if (!NT_STATUS_IS_OK(status)) {
160 printf("stop_server_listening failed - %s\n", nt_errstr(status));
164 if (!W_ERROR_IS_OK(r.out.result)) {
165 printf("\tserver refused to stop listening - %s\n", win_errstr(r.out.result));
167 printf("\tserver allowed a stop_server_listening request\n");
175 BOOL torture_rpc_mgmt(int dummy)
178 struct dcerpc_pipe *p;
182 const char *binding = lp_parm_string(-1, "torture", "binding");
183 struct dcerpc_binding b;
185 mem_ctx = talloc_init("torture_rpc_mgmt");
188 printf("You must supply a ncacn binding string\n");
192 status = dcerpc_parse_binding(mem_ctx, binding, &b);
193 if (!NT_STATUS_IS_OK(status)) {
194 printf("Failed to parse binding '%s'\n", binding);
198 b.options = talloc_array_p(mem_ctx, const char *, 2);
204 for (i=0;dcerpc_pipes[i];i++) {
205 /* some interfaces are not mappable */
206 if (dcerpc_pipes[i]->num_calls == 0 ||
207 strcmp(dcerpc_pipes[i]->name, "mgmt") == 0) {
211 printf("\nTesting pipe '%s'\n", dcerpc_pipes[i]->name);
213 if (b.transport == NCACN_IP_TCP) {
215 status = dcerpc_epm_map_tcp_port(b.host,
216 dcerpc_pipes[i]->uuid,
217 dcerpc_pipes[i]->if_version,
219 if (!NT_STATUS_IS_OK(status)) {
220 printf("Failed to map port for uuid %s\n", dcerpc_pipes[i]->uuid);
223 b.options[0] = talloc_asprintf(mem_ctx, "%u", port);
225 b.options[0] = dcerpc_pipes[i]->name;
229 lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, &b));
231 status = torture_rpc_connection(&p,
232 dcerpc_pipes[i]->name,
234 DCERPC_MGMT_VERSION);
235 if (!NT_STATUS_IS_OK(status)) {
240 if (!test_is_server_listening(p, mem_ctx)) {
244 if (!test_stop_server_listening(p, mem_ctx)) {
248 if (!test_inq_stats(p, mem_ctx)) {
252 if (!test_inq_princ_name(p, mem_ctx)) {
256 if (!test_inq_if_ids(p, mem_ctx)) {
260 torture_rpc_close(p);