2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 work out how many calls there are for an interface
28 static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
30 struct dcerpc_syntax_id *id)
32 struct dcerpc_pipe *p;
36 DATA_BLOB stub_in, stub_out;
39 uuid = GUID_string(mem_ctx, &id->uuid);
41 status = torture_rpc_connection(&p, iface->name,
42 uuid, id->if_version);
43 if (!NT_STATUS_IS_OK(status)) {
44 printf("Failed to connect to '%s' on '%s' - %s\n",
45 uuid, iface->name, nt_errstr(status));
50 stub_in = data_blob(NULL, 1000);
51 memset(stub_in.data, 0xFF, stub_in.length);
54 status = dcerpc_request(p, i, mem_ctx, &stub_in, &stub_out);
55 if (!NT_STATUS_IS_OK(status) &&
56 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
60 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == 5) {
61 printf("\tpipe disconnected at %d\n", i);
65 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == 0x80010111) {
66 printf("\terr 0x80010111 at %d\n", i);
71 printf("\t%d calls available\n", i);
72 idl_calls = idl_num_calls(uuid, id->if_version);
73 if (idl_calls == -1) {
74 printf("\tinterface not known in local IDL\n");
75 } else if (i != idl_calls) {
76 printf("\tWARNING: local IDL defines %u calls\n", idl_calls);
78 printf("\tOK: matches num_calls in local IDL\n");
87 ask the server what interface IDs are available on this endpoint
89 static BOOL test_inq_if_ids(struct dcerpc_pipe *p,
91 const struct dcerpc_interface_table *iface)
94 struct mgmt_inq_if_ids r;
97 status = dcerpc_mgmt_inq_if_ids(p, mem_ctx, &r);
98 if (!NT_STATUS_IS_OK(status)) {
99 printf("inq_if_ids failed - %s\n", nt_errstr(status));
103 if (!W_ERROR_IS_OK(r.out.result)) {
104 printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
108 if (!r.out.if_id_vector) {
109 printf("inq_if_ids gave NULL if_id_vector\n");
113 for (i=0;i<r.out.if_id_vector->count;i++) {
115 struct dcerpc_syntax_id *id = r.out.if_id_vector->if_id[i].id;
118 uuid = GUID_string(mem_ctx, &id->uuid),
120 printf("\n\tuuid %s version 0x%08x '%s'\n",
122 id->if_version, idl_pipe_name(uuid, id->if_version));
123 test_num_calls(iface, mem_ctx, id);
130 BOOL torture_rpc_scanner(void)
133 struct dcerpc_pipe *p;
137 const char *binding = lp_parm_string(-1, "torture", "binding");
138 struct dcerpc_binding b;
140 mem_ctx = talloc_init("torture_rpc_scanner");
143 printf("You must supply a ncacn binding string\n");
147 status = dcerpc_parse_binding(mem_ctx, binding, &b);
148 if (!NT_STATUS_IS_OK(status)) {
149 printf("Failed to parse binding '%s'\n", binding);
153 for (i=0;dcerpc_pipes[i];i++) {
154 /* some interfaces are not mappable */
155 if (dcerpc_pipes[i]->num_calls == 0 ||
156 strcmp(dcerpc_pipes[i]->name, "mgmt") == 0) {
160 printf("\nTesting pipe '%s'\n", dcerpc_pipes[i]->name);
162 if (b.transport == NCACN_IP_TCP) {
163 status = dcerpc_epm_map_binding(mem_ctx, &b,
164 dcerpc_pipes[i]->uuid,
165 dcerpc_pipes[i]->if_version);
166 if (!NT_STATUS_IS_OK(status)) {
167 printf("Failed to map port for uuid %s\n", dcerpc_pipes[i]->uuid);
171 b.endpoint = dcerpc_pipes[i]->name;
174 lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, &b));
176 status = torture_rpc_connection(&p,
177 dcerpc_pipes[i]->name,
179 DCERPC_MGMT_VERSION);
180 if (!NT_STATUS_IS_OK(status)) {
185 if (!test_inq_if_ids(p, mem_ctx, dcerpc_pipes[i])) {
189 torture_rpc_close(p);