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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_mgmt_c.h"
25 #include "librpc/rpc/dcerpc_table.h"
26 #include "torture/rpc/rpc.h"
29 work out how many calls there are for an interface
31 static BOOL test_num_calls(const struct ndr_interface_table *iface,
33 struct ndr_syntax_id *id)
35 struct dcerpc_pipe *p;
38 DATA_BLOB stub_in, stub_out;
40 struct ndr_interface_table tbl;
42 /* FIXME: This should be fixed when torture_rpc_connection
43 * takes a ndr_syntax_id */
44 tbl.name = iface->name;
47 status = torture_rpc_connection(mem_ctx, &p, iface);
48 if (!NT_STATUS_IS_OK(status)) {
49 char *uuid_str = GUID_string(mem_ctx, &id->uuid);
50 printf("Failed to connect to '%s' on '%s' - %s\n",
51 uuid_str, iface->name, nt_errstr(status));
52 talloc_free(uuid_str);
57 stub_in = data_blob(NULL, 1000);
58 memset(stub_in.data, 0xFF, stub_in.length);
61 status = dcerpc_request(p, NULL, i, False, mem_ctx, &stub_in, &stub_out);
62 if (!NT_STATUS_IS_OK(status) &&
63 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
67 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == 5) {
68 printf("\tpipe disconnected at %d\n", i);
72 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == 0x80010111) {
73 printf("\terr 0x80010111 at %d\n", i);
78 printf("\t%d calls available\n", i);
79 idl_calls = idl_num_calls(&id->uuid, id->if_version);
80 if (idl_calls == -1) {
81 printf("\tinterface not known in local IDL\n");
82 } else if (i != idl_calls) {
83 printf("\tWARNING: local IDL defines %u calls\n", idl_calls);
85 printf("\tOK: matches num_calls in local IDL\n");
95 BOOL torture_rpc_scanner(struct torture_context *torture)
98 struct dcerpc_pipe *p;
99 TALLOC_CTX *mem_ctx, *loop_ctx;
101 const struct ndr_interface_list *l;
102 const char *binding = torture_setting_string(torture, "binding", NULL);
103 struct dcerpc_binding *b;
105 mem_ctx = talloc_init("torture_rpc_scanner");
108 talloc_free(mem_ctx);
109 printf("You must supply a ncacn binding string\n");
113 status = dcerpc_parse_binding(mem_ctx, binding, &b);
114 if (!NT_STATUS_IS_OK(status)) {
115 talloc_free(mem_ctx);
116 printf("Failed to parse binding '%s'\n", binding);
120 for (l=librpc_dcerpc_pipes();l;l=l->next) {
121 loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_scanner loop context");
122 /* some interfaces are not mappable */
123 if (l->table->num_calls == 0 ||
124 strcmp(l->table->name, "mgmt") == 0) {
125 talloc_free(loop_ctx);
129 printf("\nTesting pipe '%s'\n", l->table->name);
131 if (b->transport == NCACN_IP_TCP) {
132 status = dcerpc_epm_map_binding(mem_ctx, b, l->table, NULL);
133 if (!NT_STATUS_IS_OK(status)) {
134 printf("Failed to map port for uuid %s\n",
135 GUID_string(loop_ctx, &l->table->syntax_id.uuid));
136 talloc_free(loop_ctx);
140 b->endpoint = talloc_strdup(b, l->table->name);
143 lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, b));
145 status = torture_rpc_connection(loop_ctx, &p, &ndr_table_mgmt);
146 if (!NT_STATUS_IS_OK(status)) {
147 talloc_free(loop_ctx);
152 if (!test_inq_if_ids(p, mem_ctx, test_num_calls, l->table)) {