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 find the number of calls defined by local IDL
28 static const char *find_idl_name(const char *uuid, uint32 if_version)
31 for (i=0;dcerpc_pipes[i];i++) {
32 if (strcasecmp(dcerpc_pipes[i]->uuid, uuid) == 0 &&
33 dcerpc_pipes[i]->if_version == if_version) {
34 return dcerpc_pipes[i]->name;
41 find the number of calls defined by local IDL
43 static int num_idl_calls(const char *uuid, uint32 if_version)
46 for (i=0;dcerpc_pipes[i];i++) {
47 if (strcasecmp(dcerpc_pipes[i]->uuid, uuid) == 0 &&
48 dcerpc_pipes[i]->if_version == if_version) {
49 return dcerpc_pipes[i]->num_calls;
56 work out how many calls there are for an interface
58 static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
60 struct dcerpc_syntax_id *id)
62 struct dcerpc_pipe *p;
66 DATA_BLOB stub_in, stub_out;
69 uuid = GUID_string(mem_ctx, &id->uuid);
71 status = torture_rpc_connection(&p, iface->name,
72 uuid, id->major_version);
73 if (!NT_STATUS_IS_OK(status)) {
74 printf("Failed to connect to '%s' on '%s' - %s\n",
75 uuid, iface->name, nt_errstr(status));
80 stub_in = data_blob(NULL, 0);
82 status = dcerpc_request(p, 10000, mem_ctx, &stub_in, &stub_out);
83 if (NT_STATUS_IS_OK(status) ||
84 p->last_fault_code != DCERPC_FAULT_OP_RNG_ERROR) {
85 printf("unable to determine call count - %s %08x\n",
86 nt_errstr(status), p->last_fault_code);
90 for (i=128;i>=0;i--) {
91 status = dcerpc_request(p, i, mem_ctx, &stub_in, &stub_out);
92 if (NT_STATUS_IS_OK(status) ||
93 p->last_fault_code != DCERPC_FAULT_OP_RNG_ERROR) break;
96 printf("\t%d calls available\n", i+1);
97 idl_calls = num_idl_calls(uuid, id->major_version);
98 if (idl_calls == -1) {
99 printf("\tinterface not known in local IDL\n");
100 } else if (i+1 != idl_calls) {
101 printf("\tWARNING: local IDL defines %u calls\n", idl_calls);
103 printf("\tOK: matches num_calls in local IDL\n");
107 torture_rpc_close(p);
112 ask the server what interface IDs are available on this endpoint
114 static BOOL test_inq_if_ids(struct dcerpc_pipe *p,
116 const struct dcerpc_interface_table *iface)
119 struct mgmt_inq_if_ids r;
122 status = dcerpc_mgmt_inq_if_ids(p, mem_ctx, &r);
123 if (!NT_STATUS_IS_OK(status)) {
124 printf("inq_if_ids failed - %s\n", nt_errstr(status));
128 if (!W_ERROR_IS_OK(r.out.result)) {
129 printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
133 if (!r.out.if_id_vector) {
134 printf("inq_if_ids gave NULL if_id_vector\n");
138 for (i=0;i<r.out.if_id_vector->count;i++) {
140 struct dcerpc_syntax_id *id = r.out.if_id_vector->if_id[i].id;
143 uuid = GUID_string(mem_ctx, &id->uuid),
145 printf("\n\tuuid %s version 0x%04x:0x%04x '%s'\n",
147 id->major_version, id->minor_version,
148 find_idl_name(uuid, id->major_version));
149 test_num_calls(iface, mem_ctx, id);
156 BOOL torture_rpc_scanner(int dummy)
159 struct dcerpc_pipe *p;
163 char *host = lp_parm_string(-1, "torture", "host");
166 mem_ctx = talloc_init("torture_rpc_scanner");
168 for (i=0;dcerpc_pipes[i];i++) {
169 char *transport = lp_parm_string(-1, "torture", "transport");
171 /* some interfaces are not mappable */
172 if (dcerpc_pipes[i]->num_calls == 0 ||
173 strcmp(dcerpc_pipes[i]->name, "mgmt") == 0) {
177 printf("\nTesting pipe '%s'\n", dcerpc_pipes[i]->name);
179 /* on TCP we need to find the right endpoint */
180 if (strcasecmp(transport, "ncacn_ip_tcp") == 0) {
181 status = dcerpc_epm_map_tcp_port(host,
182 dcerpc_pipes[i]->uuid,
183 dcerpc_pipes[i]->if_version,
185 if (!NT_STATUS_IS_OK(status)) {
190 lp_set_cmdline("torture:share",
191 talloc_asprintf(mem_ctx, "%u", port));
194 status = torture_rpc_connection(&p,
195 dcerpc_pipes[i]->name,
197 DCERPC_MGMT_VERSION);
198 if (!NT_STATUS_IS_OK(status)) {
203 if (!test_inq_if_ids(p, mem_ctx, dcerpc_pipes[i])) {
207 torture_rpc_close(p);